[Libreoffice-commits] core.git: android/source
Michael Weghorn (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 1 15:19:24 UTC 2021
android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 25 ---------
android/source/src/java/org/libreoffice/ui/FileUtilities.java | 27 ++++++++++
2 files changed, 29 insertions(+), 23 deletions(-)
New commits:
commit af56d15d6bbe92c7df0248ec72dc4d759580c378
Author: Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Thu Apr 1 14:34:23 2021 +0200
Commit: Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Thu Apr 1 17:18:38 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.weghorn at posteo.de>
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: */
More information about the Libreoffice-commits
mailing list