diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2023-11-25 22:09:34 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-11-26 18:07:37 +0100 |
commit | 872d26d4a859ff72e1e13068b798854185960de0 (patch) | |
tree | 265337d11ff7f64ed95e7eb0842a0cb80a50a70b /android | |
parent | 3ff66d4361c3394d8669f3a367f41d4bad9914e7 (diff) |
android: Suggest file name for PDF export
When using the PDF export feature in Android Viewer,
suggest a file name for the PDF file that matches
the current display name (which is usually the
file name, or "untitled" for a newly created doc
that hasn't been saved yet).
This can be achieved by setting `Intent.EXTRA_TITLE`
for the `ACTION_CREATE_DOCUMENT`. [1]
The `DocumentsContract.EXTRA_INITIAL_URI` already
set previously already results in the same
directory as the doc being preselected in the
file chooser:
> Callers can set a document URI through
> DocumentsContract#EXTRA_INITIAL_URI to indicate the initial location of
> documents navigator. System will do its best to launch the navigator in
> the specified document if it's a folder, or the folder that contains the
> specified document if not.
Filling in the current file name was suggested
in a Google Play review comment for the app.
[1] https://developer.android.com/reference/android/content/Intent#ACTION_CREATE_DOCUMENT
Change-Id: Idbd4a89416089f927e0232ce65161b43059ca46d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159959
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
-rw-r--r-- | android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 4 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/ui/FileUtilities.java | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index b21ad02383d7..ba371bfd9c8a 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -350,7 +350,11 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(FileUtilities.MIMETYPE_PDF); + // suggest directory and file name based on the doc intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, mDocumentUri); + final String displayName = toolbarTop.getTitle().toString(); + final String suggestedFileName = FileUtilities.stripExtensionFromFileName(displayName) + ".pdf"; + intent.putExtra(Intent.EXTRA_TITLE, suggestedFileName); startActivityForResult(intent, REQUEST_CODE_EXPORT_TO_PDF); } diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java index 902b30ed7794..7fc8c3c84eb1 100644 --- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java +++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java @@ -124,6 +124,11 @@ public class FileUtilities { return mimeType != null && mimeType.endsWith("template"); } + public static String stripExtensionFromFileName(final String fileName) + { + return fileName.split("\\.[A-Za-z0-9]*$")[0]; + } + /** * Tries to retrieve the display (which should be the document name) * for the given URI using the given resolver. |