summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2021-04-01 14:34:23 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2021-04-01 18:08:03 +0200
commit52390e06925cf003b3408cb574f55171acd19c58 (patch)
treec520a3cd4b56ebff83333518205c09330e15b02d
parentb49d07a99109b8978e3af9292404e768378076ba (diff)
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.weghorn@posteo.de> (cherry picked from commit af56d15d6bbe92c7df0248ec72dc4d759580c378)
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java25
-rw-r--r--android/source/src/java/org/libreoffice/ui/FileUtilities.java27
2 files changed, 29 insertions, 23 deletions
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: */