android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 25 -- android/source/src/java/org/libreoffice/PresentationActivity.java | 19 - android/source/src/java/org/libreoffice/ui/FileUtilities.java | 27 ++ android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 102 +++++----- android/source/src/java/org/libreoffice/ui/RecentFile.java | 25 ++ android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java | 12 - 6 files changed, 122 insertions(+), 88 deletions(-)
New commits: commit 1bce9854282b1ee63564d1807f881656678332ca Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Apr 1 16:50:34 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 18:08:46 2021 +0200 android: Actually show recently used in "Recent files" list Previously, a set was used to store the recently used files, meaning the order was lost when restoring from the prefs. Use a space-delimited string to store the entries in prefs instead, and convert that into an (ordered) list. This way, it's possible to always drop the oldest entry (instead of a random one) when inserting a new one and the max count has been reached, so the list of recently used files shows those that are actually the (up to 4) most recently used ones. Change the key used for the preference (variable 'RECENT_DOCUMENTS_KEY') to a different value, so there is no problem about trying to read old values stored as a Set<String> as a plain String. Change-Id: I95cc3627cd2975f0463f5ecb94292a26fe714066 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113462 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 2bbb2943845a8b580d1f6d009209e5f0a6cd09d4) diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index e968f97b3a32..3236b53e7dc5 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -44,6 +44,7 @@ import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.text.TextUtils; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -125,7 +126,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings public static final String EXPLORER_VIEW_TYPE_KEY = "EXPLORER_VIEW_TYPE"; public static final String EXPLORER_PREFS_KEY = "EXPLORER_PREFS"; public static final String SORT_MODE_KEY = "SORT_MODE"; - private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENTS"; + private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENT_URIS"; + // delimiter used for storing multiple URIs in a string + private static final String RECENT_DOCUMENTS_DELIMITER = " "; private static final String ENABLE_SHOW_HIDDEN_FILES_KEY = "ENABLE_SHOW_HIDDEN_FILES"; private static final String DISPLAY_LANGUAGE = "DISPLAY_LANGUAGE"; @@ -263,7 +266,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings recentRecyclerView = findViewById(R.id.list_recent); - Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()); + String recentPref = prefs.getString(RECENT_DOCUMENTS_KEY, ""); + List<String> recentFileStrings = Arrays.asList(recentPref.split(RECENT_DOCUMENTS_DELIMITER)); final List<RecentFile> recentFiles = new ArrayList(); for (String recentFileString : recentFileStrings) { @@ -1088,7 +1092,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings // ContentResolver#takePersistableUriPermission only available from SDK level 19 on Log.i(LOGTAG, "Recently used files not supported, requires SDK version >= 19."); // drop potential entries - prefs.edit().putStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()).apply(); + prefs.edit().putString(RECENT_DOCUMENTS_KEY, "").apply(); return; } @@ -1097,17 +1101,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings getContentResolver().takePersistableUriPermission(fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); String newRecent = fileUri.toString(); - Set<String> recentsSet = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()); + List<String> recentsList = new ArrayList(Arrays.asList(prefs.getString(RECENT_DOCUMENTS_KEY, "").split(RECENT_DOCUMENTS_DELIMITER))); - //create array to work with - ArrayList<String> recentsArrayList = new ArrayList<String>(recentsSet); - - //remove string if present, so that it doesn't appear multiple times - recentsSet.remove(newRecent); - - //put the new value in the first place - recentsArrayList.add(0, newRecent); + // remove string if present, so that it doesn't appear multiple times + recentsList.remove(newRecent); + // put the new value in the first place + recentsList.add(0, newRecent); /* * 4 because the number of recommended items in App Shortcuts is 4, and also @@ -1115,14 +1115,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings */ final int RECENTS_SIZE = 4; - while (recentsArrayList.size() > RECENTS_SIZE) { - recentsArrayList.remove(RECENTS_SIZE); + while (recentsList.size() > RECENTS_SIZE) { + recentsList.remove(RECENTS_SIZE); } - //switch to Set, so that it could be inserted into prefs - recentsSet = new HashSet<String>(recentsArrayList); - - prefs.edit().putStringSet(RECENT_DOCUMENTS_KEY, recentsSet).apply(); + // serialize to String that can be set for pref + String value = TextUtils.join(RECENT_DOCUMENTS_DELIMITER, recentsList); + prefs.edit().putString(RECENT_DOCUMENTS_KEY, value).apply(); //update app shortcuts (7.0 and above) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { @@ -1132,7 +1131,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings shortcutManager.removeAllDynamicShortcuts(); ArrayList<ShortcutInfo> shortcuts = new ArrayList<ShortcutInfo>(); - for (String recentDoc : recentsArrayList) { + for (String recentDoc : recentsList) { Uri docUri = Uri.parse(recentDoc); String filename = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), docUri); if (filename.isEmpty()) { commit a6c6a4b0b6f33f119c60a91335dc668fb633bdba Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Apr 1 09:45:13 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 18:08:38 2021 +0200 android: Show files opened using system picker for recently used Switch the list of recently used documents in LibreOffice Android Viewer to show the documents opened using the system file picker instead of those shown using the custom UI elements for file selection. This way, files provided by DocumentsProviders, like Nextcloud, can also be handled. As described at [1], this requires persisting permissions in order to be able to access the files after a device reboot. The corresponding method to do this, 'ContentResolver#takePersistableUriPermission', is only available from SDK level 19 on, so drop entries for older SDK levels (current minSdkVersion is 16). [1] https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions Change-Id: Ifbf7148cda687a8a2e3f0c14fe66651509b2f19a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113459 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 2611b5c25551c38d047d8be058177bc7fbfc672d) diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index f9afa9578d56..e968f97b3a32 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -21,6 +21,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; +import android.database.Cursor; import android.graphics.drawable.Icon; import android.hardware.usb.UsbManager; import android.net.Uri; @@ -28,6 +29,7 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; +import android.provider.OpenableColumns; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.NavigationView; @@ -263,15 +265,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()); - final ArrayList<IFile> recentFiles = new ArrayList<IFile>(); + final List<RecentFile> recentFiles = new ArrayList(); for (String recentFileString : recentFileStrings) { - try { - if(documentProvider != null) - recentFiles.add(documentProvider.createFromUri(this, new URI(recentFileString))); - } catch (URISyntaxException e) { - e.printStackTrace(); - } catch (RuntimeException e){ - e.printStackTrace(); + Uri uri = Uri.parse(recentFileString); + String filename = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), uri); + if (!filename.isEmpty()) { + recentFiles.add(new RecentFile(uri, filename)); } } @@ -615,7 +614,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } public void open(final IFile document) { - addDocumentToRecents(document); new AsyncTask<IFile, Void, File>() { @Override protected File doInBackground(IFile... document) { @@ -659,10 +657,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings }.execute(document); } - private void openDocument(final Uri documentUri) { + public void openDocument(final Uri documentUri) { // "forward" to LibreOfficeMainActivity to open the file Intent intent = new Intent(Intent.ACTION_VIEW, documentUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + + addDocumentToRecents(documentUri); + String packageName = getApplicationContext().getPackageName(); ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName()); @@ -1082,8 +1083,20 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings return (int) (dp * scale + 0.5f); } - private void addDocumentToRecents(IFile iFile) { - String newRecent = iFile.getUri().toString(); + private void addDocumentToRecents(Uri fileUri) { + if (Build.VERSION.SDK_INT < 19) { + // ContentResolver#takePersistableUriPermission only available from SDK level 19 on + Log.i(LOGTAG, "Recently used files not supported, requires SDK version >= 19."); + // drop potential entries + prefs.edit().putStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()).apply(); + return; + } + + // preserve permissions across device reboots, + // s. https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions + getContentResolver().takePersistableUriPermission(fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + + String newRecent = fileUri.toString(); Set<String> recentsSet = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>()); //create array to work with @@ -1111,7 +1124,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings prefs.edit().putStringSet(RECENT_DOCUMENTS_KEY, recentsSet).apply(); - //update app shortcuts (7.0 and above) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); @@ -1120,11 +1132,16 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings shortcutManager.removeAllDynamicShortcuts(); ArrayList<ShortcutInfo> shortcuts = new ArrayList<ShortcutInfo>(); - for (String pathString : recentsArrayList) { + for (String recentDoc : recentsArrayList) { + Uri docUri = Uri.parse(recentDoc); + String filename = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), docUri); + if (filename.isEmpty()) { + continue; + } //find the appropriate drawable int drawable = 0; - switch (FileUtilities.getType(pathString)) { + switch (FileUtilities.getType(filename)) { case FileUtilities.DOC: drawable = R.drawable.writer; break; @@ -1139,12 +1156,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings break; } - File file = new File(pathString); - - //for some reason, getName uses %20 instead of space - String filename = file.getName().replace("%20", " "); - - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file)); + Intent intent = new Intent(Intent.ACTION_VIEW, docUri); String packageName = this.getApplicationContext().getPackageName(); ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName()); intent.setComponent(componentName); diff --git a/android/source/src/java/org/libreoffice/ui/RecentFile.java b/android/source/src/java/org/libreoffice/ui/RecentFile.java new file mode 100644 index 000000000000..77cf3c1b116d --- /dev/null +++ b/android/source/src/java/org/libreoffice/ui/RecentFile.java @@ -0,0 +1,25 @@ +package org.libreoffice.ui; + +import android.net.Uri; + +/** + * An entry for a recently used file in the RecentFilesAdapter. + */ +public class RecentFile { + + private Uri uri; + private String displayName; + + public RecentFile(Uri docUri, String name) { + uri = docUri; + displayName = name; + } + + public Uri getUri() { + return uri; + } + + public String getDisplayName() { + return displayName; + } +} diff --git a/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java b/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java index fc16d06a48d7..c25fa8270f69 100644 --- a/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java +++ b/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java @@ -18,16 +18,15 @@ import android.widget.ImageView; import android.widget.TextView; import org.libreoffice.R; -import org.libreoffice.storage.IFile; import java.util.List; class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHolder> { private LibreOfficeUIActivity mActivity; - private List<IFile> recentFiles; + private List<RecentFile> recentFiles; - RecentFilesAdapter(LibreOfficeUIActivity activity, List<IFile> recentFiles) { + RecentFilesAdapter(LibreOfficeUIActivity activity, List<RecentFile> recentFiles) { this.mActivity = activity; this.recentFiles = recentFiles; } @@ -41,17 +40,16 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol @Override public void onBindViewHolder(ViewHolder holder, int position) { - final IFile iFile = recentFiles.get(position); + final RecentFile entry = recentFiles.get(position); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - mActivity.open(iFile); + mActivity.openDocument(entry.getUri()); } }); - String filename = iFile.getName(); - + final String filename = entry.getDisplayName(); holder.textView.setText(filename); int compoundDrawableInt = 0; commit 0deac9fece306d99e743cad150ee78d477cf65f6 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Apr 1 15:11:51 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 18:08:26 2021 +0200 android: Drop check for SDK version < 16 This is unnecessary, since minSdkVersion was bumped to 16 in commit a7f6338875931d8afff55cb39ead8f6600af04cb Date: Wed Aug 7 12:06:25 2019 +0200 android: support NDK 19 and above (20 as of this commit) support for targeting API 14 and 15 was removed in NDK 18, so set minimum version to 16 [...] Change-Id: I70573f9e5e24b211ee7e84be5824d69e4f2b9f81 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113458 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 4003042af09d8335003c6b9faf3696221a44916c) diff --git a/android/source/src/java/org/libreoffice/PresentationActivity.java b/android/source/src/java/org/libreoffice/PresentationActivity.java index 3308e6884fe9..0fd3950f55d4 100644 --- a/android/source/src/java/org/libreoffice/PresentationActivity.java +++ b/android/source/src/java/org/libreoffice/PresentationActivity.java @@ -25,19 +25,10 @@ public class PresentationActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // First we hide the status bar - if (Build.VERSION.SDK_INT < 16) { - // If the Android version is lower than Jellybean, use this call to hide - // the status bar. - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } else { - // If higher than Jellybean - View decorView = getWindow().getDecorView(); - // Hide the status bar. - int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; - decorView.setSystemUiVisibility(uiOptions); - } + View decorView = getWindow().getDecorView(); + // Hide the status bar. + int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; + decorView.setSystemUiVisibility(uiOptions); setContentView(R.layout.presentation_mode); @@ -185,4 +176,4 @@ public class PresentationActivity extends AppCompatActivity { private void pageRight() { mWebView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT)); } -} \ No newline at end of file +} commit 52390e06925cf003b3408cb574f55171acd19c58 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Apr 1 14:34:23 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 18:08:03 2021 +0200 android: Move code to get doc's display name from URI to static helper Will be used in LibreOfficeUIActivity as well. Change-Id: Ie1b99f0d31dba1be263459d135ee7fcb36613a7b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113457 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit af56d15d6bbe92c7df0248ec72dc4d759580c378) diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index cfdc81000f51..aed1cf946a69 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -40,6 +40,7 @@ import org.libreoffice.overlay.CalcHeadersController; import org.libreoffice.overlay.DocumentOverlay; import org.libreoffice.storage.DocumentProviderFactory; import org.libreoffice.storage.IFile; +import org.libreoffice.ui.FileUtilities; import org.libreoffice.ui.LibreOfficeUIActivity; import org.mozilla.gecko.gfx.GeckoLayerClient; import org.mozilla.gecko.gfx.LayerView; @@ -202,7 +203,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin mbISReadOnlyMode = !isExperimentalMode() || isReadOnlyDoc; Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + getIntent().getData().getPath()); - String displayName = extractDisplayNameFromIntent(); + String displayName = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), getIntent().getData()); if (displayName.isEmpty()) { // fall back to using temp file name displayName = mInputFile.getName(); @@ -569,28 +570,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } - /** - * Tries to retrieve display name for data in Intent, - * which should be the file name. - */ - private String extractDisplayNameFromIntent() { - String displayName = ""; - // try to retrieve original file name - Cursor cursor = null; - try { - String[] columns = {OpenableColumns.DISPLAY_NAME}; - cursor = getContentResolver().query(getIntent().getData(), columns, null, null); - if (cursor != null && cursor.moveToFirst()) { - displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return displayName; - } - public List<DocumentPartView> getDocumentPartView() { return mDocumentPartView; } diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java index 28f1906a6369..5a4224f2ceb9 100644 --- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java +++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java @@ -19,6 +19,11 @@ import java.util.Collections; import java.util.List; import java.util.HashMap; import java.util.Comparator; + +import android.content.ContentResolver; +import android.database.Cursor; +import android.net.Uri; +import android.provider.OpenableColumns; import android.util.Log; import android.webkit.MimeTypeMap; @@ -274,6 +279,28 @@ public class FileUtilities { static String getThumbnailName(File file) { return "." + file.getName().split("[.]")[0] + ".png" ; } + + /** + * Tries to retrieve the display (which should be the document name) + * for the given URI using the given resolver. + */ + public static String retrieveDisplayNameForDocumentUri(ContentResolver resolver, Uri docUri) { + String displayName = ""; + // try to retrieve original file name + Cursor cursor = null; + try { + String[] columns = {OpenableColumns.DISPLAY_NAME}; + cursor = resolver.query(docUri, columns, null, null); + if (cursor != null && cursor.moveToFirst()) { + displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return displayName; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit b49d07a99109b8978e3af9292404e768378076ba Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Apr 1 09:38:55 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 18:07:57 2021 +0200 android: Extract opening of file to separate method 'openDocument' The method will also be used from elsewhere in a follow-up commit. Change-Id: I94cbdfa9faf54fcb655233f43d13ced8740b88a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113456 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 40115df50102bd5314a93f54042ae6d035c1f685) diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 539b355cc932..f9afa9578d56 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -467,15 +467,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_OPEN_FILECHOOSER && resultCode == RESULT_OK) { final Uri fileUri = data.getData(); - - // "forward" to LibreOfficeMainActivity to open the file - Intent intent = new Intent(Intent.ACTION_VIEW, fileUri); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - String packageName = getApplicationContext().getPackageName(); - ComponentName componentName = new ComponentName(packageName, - LibreOfficeMainActivity.class.getName()); - intent.setComponent(componentName); - startActivity(intent); + openDocument(fileUri); } else if (requestCode == REQUEST_CODE_CREATE_NEW_DOCUMENT) { // "forward" to LibreOfficeMainActivity to create + open the file final Uri fileUri = data.getData(); @@ -667,6 +659,17 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings }.execute(document); } + private void openDocument(final Uri documentUri) { + // "forward" to LibreOfficeMainActivity to open the file + Intent intent = new Intent(Intent.ACTION_VIEW, documentUri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + String packageName = getApplicationContext().getPackageName(); + ComponentName componentName = new ComponentName(packageName, + LibreOfficeMainActivity.class.getName()); + intent.setComponent(componentName); + startActivity(intent); + } + private void createNewFileDialog() { final String extension; if (newDocType == DocumentType.WRITER) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits