android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 4 ++++ android/source/src/java/org/libreoffice/ui/FileUtilities.java | 5 +++++ 2 files changed, 9 insertions(+)
New commits: commit 83f8685504168574f00c24e6ef5d50026c1fda5f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Nov 25 22:09:34 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Nov 29 13:51:51 2023 +0100 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.wegh...@posteo.de> (cherry picked from commit 872d26d4a859ff72e1e13068b798854185960de0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160031 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> 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.