summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2021-03-17 14:52:26 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2021-03-18 10:21:38 +0100
commite2d2c38d06dc514ee417ed006ed0f13173d186d6 (patch)
tree5369ccc79cc3f4e6226fa24f15dcd0c1d9e2c78c
parent985a9551f47aac55b60ef452869c2b411313ef11 (diff)
android: Show original instead of temp file name
When a temporary file is created in Android Viewer (e.g. when a file is passed from another app, like a file explorer or an email app), still show the original file name in the toolbar, instead of the name of the temporary file (like "LibreOffice1588848072959345750.tmp"). Change-Id: I86f5cebfa8e2986fe812ace16c0df324d1420955 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112643 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit a7c0039542fb015e34c56ec25f92f59a4c6ba1fa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112621 Tested-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index cbc628e94e48..a9a192099008 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -11,12 +11,14 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
+import android.database.Cursor;
import android.graphics.RectF;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.provider.OpenableColumns;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
@@ -192,7 +194,13 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
if (copyFileToTemp() && mTempFile != null) {
mInputFile = mTempFile;
Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + getIntent().getData().getPath());
- toolbarTop.setTitle(mInputFile.getName());
+
+ String displayName = extractDisplayNameFromIntent();
+ if (displayName.isEmpty()) {
+ // fall back to using temp file name
+ displayName = mInputFile.getName();
+ }
+ toolbarTop.setTitle(displayName);
} else {
// TODO: can't open the file
Log.e(LOGTAG, "couldn't create temporary file from " + getIntent().getData());
@@ -490,6 +498,28 @@ 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;
}