android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 32 +++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
New commits: commit a7c0039542fb015e34c56ec25f92f59a4c6ba1fa Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 17 14:52:26 2021 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Mar 18 10:20:34 2021 +0100 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.wegh...@posteo.de> 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; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits