android/source/res/values-de/strings.xml | 9 android/source/res/values-tr/strings.xml | 7 android/source/res/values/strings.xml | 9 android/source/src/java/org/libreoffice/LOKitTileProvider.java | 13 - android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 81 ++---- android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 120 +++++----- 6 files changed, 107 insertions(+), 132 deletions(-)
New commits: commit 2d2e8414cbc0e52359d9b0440f06d4c99135a227 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 15:04:36 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:18:38 2021 +0200 android: Don't mark doc changed on keypress in readonly mode Since input etc. is otherwise ignored in readonly mode, also don't mark the document as changed on keypress. This e.g. avoids an unnecessary dialog whether or not to save the document after opening a document with experimental editing mode disabled, then pressing a key (on hardware keyboard, soft keyboard isn't shown in readonly mode) and then pressing the "Back" button to close the document again. Change-Id: I095c79549719d3760666605e1c642c58e6b1bb9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113417 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 441342654e5b4c61317b9a596396a1d817dd8547) diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 960e3374a97a..cfdc81000f51 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -168,8 +168,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin layerView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { - if(keyEvent.getKeyCode() != KeyEvent.KEYCODE_BACK){ - isDocumentChanged=true; + if(!isReadOnlyMode() && keyEvent.getKeyCode() != KeyEvent.KEYCODE_BACK){ + setDocumentChanged(true); } return false; } commit f6d174c66025ad21829aa3e7f65a75ce6fa0074d Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 14:55:15 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:18:33 2021 +0200 android: Drop some unused imports Change-Id: If72949f949cba23397d87c8f67b9434861f9bb7c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113414 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 51f6e11aee50cc429021be27bd33875593425683) diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index a070c292009c..960e3374a97a 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -40,7 +40,6 @@ 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; diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index f05bcae58a49..539b355cc932 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -11,12 +11,10 @@ package org.libreoffice.ui; import android.Manifest; import android.app.Activity; -import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -29,7 +27,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; @@ -45,7 +42,6 @@ import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.text.InputType; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -60,7 +56,6 @@ import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.OvershootInterpolator; -import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; commit d8e357bbe7d1d17c958d856b0bd6668d63d7a478 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 14:32:32 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:18:16 2021 +0200 android: Don't require that user presses 'Back' twice to exit Drop the "Press back again to quit" info shown when pressing "Back" in the file selection dialog in Android Viewer and just quit the app right away. It was originally added in commit d1f671e053864d0bf54d04a855761b43a7f5a9c4 Date: Wed Jun 10 19:04:22 2015 +0200 tdf#87434: android: system back key to go one level up Added an additional check so back has to be pressed twice on the root folder to actually leave the application. It's a check seen in many other apps. but I don't really see any need to bother the user about pressing "Back" again. Nothing is lost at this stage when quitting the app, and I haven't seen anything similar in many current apps myself (but have rather seen some extra confirmation dialogs disappear from desktop applications over the last years). The original request in tdf#87434 to go one level up in the directory hierarchy is unaffected by this, though this only applies for the custom widgets to browse the file system, which will potentially be dropped in the future anyway, now that support for the system file picker has been added in commit d678ee309b02b4cc8af29a097bf5053b8b1b4e06 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Fri Mar 19 14:29:36 2021 +0100 tdf#129833 android: Allow opening files using system file picker Change-Id: Ib324b7f0b82427b04c7708665ff7492a758eec9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113413 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 1477401805e2a88cddb1df259456359398fa2b7d) diff --git a/android/source/res/values-de/strings.xml b/android/source/res/values-de/strings.xml index 6828066524c9..53854e94929d 100644 --- a/android/source/res/values-de/strings.xml +++ b/android/source/res/values-de/strings.xml @@ -14,7 +14,6 @@ <string name="about_license">Lizenz anzeigen</string> <string name="about_notice">Hinweise anzeigen</string> <string name="about_moreinfo">Weitere Informationen</string> - <string name="back_again_to_quit">Zum Beenden noch einmal \'zurück\' drücken</string> <string name="new_textdocument">Neues Textdokument</string> <string name="new_presentation">Neue Präsentation</string> diff --git a/android/source/res/values-tr/strings.xml b/android/source/res/values-tr/strings.xml index 357f441a8e86..494e0575d0d1 100644 --- a/android/source/res/values-tr/strings.xml +++ b/android/source/res/values-tr/strings.xml @@ -14,7 +14,6 @@ <string name="about_license">Lisansı Görüntüle</string> <string name="about_notice">Bildiriyi Görüntüle</string> <string name="about_moreinfo">Daha Fazla Bilgi</string> - <string name="back_again_to_quit">Çıkış için geri tuşuna tekrar basınız.</string> <string name="new_textdocument">Yeni Kelime İşlemci</string> <string name="new_presentation">Yeni Sunum</string> diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 5cd2c978cef5..ddb396555dfc 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -14,7 +14,6 @@ <string name="about_license">Show License</string> <string name="about_notice">Show Notice</string> <string name="about_moreinfo">More Info</string> - <string name="back_again_to_quit">Press back again to quit</string> <string name="new_textdocument">New Text Document</string> <string name="new_presentation">New Presentation</string> diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 517aa158035d..f05bcae58a49 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -191,8 +191,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private RecyclerView fileRecyclerView; private RecyclerView recentRecyclerView; - private boolean canQuit = false; - private Animation fabOpenAnimation; private Animation fabCloseAnimation; private boolean isFabMenuOpen = false; @@ -440,22 +438,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } else if (isFabMenuOpen) { collapseFabMenu(); } else { - // only exit if warning has been shown - if (canQuit) { - super.onBackPressed(); - return; - } - - // show warning about leaving the app and set a timer - Toast.makeText(this, R.string.back_again_to_quit, - Toast.LENGTH_SHORT).show(); - canQuit = true; - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - canQuit = false; - } - }, 3000); + super.onBackPressed(); } } commit e60c9c62b7df7b15006658546e9a533d1be61175 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 10:58:01 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:18:07 2021 +0200 android: Use system file picker to create new docs Similar to the way that existing documents can be opened from within the Android Viewer app using the system file picker by using 'Intent.ACTION_OPEN_DOCUMENT', use the system file picker via 'Intent.ACTION_CREATE_DOCUMENT' to create new docs as well, instead of providing a custom dialog to insert a file name. As described at [1], this allows to save files in locations supported by any existing DocumentsProvider (e.g. a Nextcloud share, if the Nextcloud app is installed and set up), not just locally. This also allows to further unify the handling in LOMainActivity. Just like for the cases where an existing document is opened using the system file picker or a document is passed from a third-party app, the document URI is now set in the Intent, a temporary file is used and writing back to the actual URI happens on save. Drop LibreOfficeMainActivity's method 'showSaveStatusMessage', which was only meant to be used when a new file was created, but was called from the more generic 'LOKitTileProvider::saveDocumentAs'. Change that to show a more general error message when saving fails. Since the actual file is now created by the DocumentsProvider, LOKitTileProvider only operates on the temporary copy anyway. Side note: With this change in place, overwriting existing files also no longer just happens silently, as used to be the case when typing the name of an existing file in the custom dialog for creating new files earlier. Since 'Intent.ACTION_OPEN_DOCUMENT' was introduced in SDK version 19 (Android 4.4), restrict creating new docs to corresponding devices. [1] https://developer.android.com/training/data-storage/shared/documents-files Change-Id: I8932cb892ca8ac97a04d15cbd1540d0ee68350da Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113408 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 4b8540911bc8fabee0729b31780a1ba8b4663121) diff --git a/android/source/res/values-de/strings.xml b/android/source/res/values-de/strings.xml index 4c6e25342ef7..6828066524c9 100644 --- a/android/source/res/values-de/strings.xml +++ b/android/source/res/values-de/strings.xml @@ -100,8 +100,6 @@ <string name="message_saving">Dokument wird gespeichert…</string> <string name="message_save_incomplete">Speichern unvollständig. Gab es Änderungen?</string> <string name="message_saving_failed">Speichern des Dokuments ist fehlgeschlagen.</string> - <string name="create_new_file_success">"Neue Datei angelegt - "</string> - <string name="create_new_file_error">Neue Datei konnte nicht angelegt weden, bitte Prüfen Sie den eingegeben Dateinamen.</string> <!-- Document provider settings --> <string name="storage_provider_settings">Speicheranbieter-Einstellungen</string> @@ -128,10 +126,6 @@ <string name="action_cancel">Abbrechen</string> <string name="no_save_document">NEIN</string> - <!-- Create New Document Dialog Strings --> - <string name="create_new_document_title">Dateiname eingeben</string> - <string name="action_create">ANLEGEN</string> - <!-- Presentation Mode Strings --> <string name="action_presentation">Präsentation</string> <string name="action_add_slide">Folie hinzufügen</string> @@ -223,8 +217,10 @@ <string name="display_language">Anzeigesprache</string> <string name="display_language_summary">Wählen Sie die Standard-Anzeigesprache</string> <string name="unable_to_export_pdf">PDF-Export nicht möglich</string> + <string name="unable_to_save">Speichern nicht möglich</string> <string name="pdf_exported_at">PDF exportiert nach</string> <string name="printing_not_supported">Ihr Gerät unterstützt Drucken nicht</string> + <string name="creating_new_files_not_supported">Erstellen neuer Dokumente auf diesem Gerät nicht verfügbar, benötigt Android-SDK-Version >= 19.</string> <string name="error">Fehler</string> <string name="enter_part_name">Name für Abschnitt eingeben</string> <string name="bmp_null">Bmp ist null!</string> diff --git a/android/source/res/values-tr/strings.xml b/android/source/res/values-tr/strings.xml index 4ce70e91607d..357f441a8e86 100644 --- a/android/source/res/values-tr/strings.xml +++ b/android/source/res/values-tr/strings.xml @@ -96,8 +96,6 @@ <string name="message_saved">Kaydetme tamamlandı.</string> <string name="message_saving">Belge kaydediliyor…</string> <string name="message_save_incomplete">Kayıt tamamlanmadı. Değişiklik yapıldı mı?</string> - <string name="create_new_file_success">"Yeni dosya oluşturuldu - "</string> - <string name="create_new_file_error">Yeni dosya oluşturma başarısız. Lütfen dosya ismini kontrol ediniz.</string> <!-- Document provider settings --> <string name="storage_provider_settings">Depolama sağlayıcısı ayarları</string> @@ -124,10 +122,6 @@ <string name="action_cancel">İptal</string> <string name="no_save_document">Hayır</string> - <!-- Create New Document Dialog Strings --> - <string name="create_new_document_title">Dosya ismi girin</string> - <string name="action_create">OLUŞTUR</string> - <!-- Presentation Mode Strings --> <string name="action_presentation">Slayt Gösterisi</string> <string name="action_add_slide">Slayt Ekle</string> diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 8205176df685..5cd2c978cef5 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -100,8 +100,6 @@ <string name="message_saving">Saving the document…</string> <string name="message_saving_failed">Saving the document failed.</string> <string name="message_save_incomplete">Save incomplete. Were there any changes?</string> - <string name="create_new_file_success">"Created new file - "</string> - <string name="create_new_file_error">Unable to create new file, please check entered file name.</string> <!-- Document provider settings --> <string name="storage_provider_settings">Storage provider settings</string> @@ -128,10 +126,6 @@ <string name="action_cancel">Cancel</string> <string name="no_save_document">NO</string> - <!-- Create New Document Dialog Strings --> - <string name="create_new_document_title">Enter file name</string> - <string name="action_create">CREATE</string> - <!-- Presentation Mode Strings --> <string name="action_presentation">Slide show</string> <string name="action_add_slide">Add Slide</string> @@ -223,8 +217,10 @@ <string name="display_language">Display Language</string> <string name="display_language_summary">Set the default display language</string> <string name="unable_to_export_pdf">Unable to export to pdf</string> + <string name="unable_to_save">Unable to save file</string> <string name="pdf_exported_at">Exported to PDF at</string> <string name="printing_not_supported">Your device does not support printing</string> + <string name="creating_new_files_not_supported">Creating new files not supported on this device, requires Android SDK version >= 19.</string> <string name="error">Error</string> <string name="enter_part_name">Enter a part name</string> <string name="bmp_null">Bmp is null!</string> diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index 85eda566bae3..aafdbff311c1 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -295,8 +295,6 @@ class LOKitTileProvider implements TileProvider { } } - - @Override public void saveDocumentAs(final String filePath, String format, boolean takeOwnership) { String options = ""; @@ -327,7 +325,7 @@ class LOKitTileProvider implements TileProvider { @Override public void run() { // There was some error - mContext.showSaveStatusMessage(true); + mContext.showCustomStatusMessage(mContext.getString(R.string.unable_to_save)); } }); } @@ -348,17 +346,8 @@ class LOKitTileProvider implements TileProvider { mContext.showCustomStatusMessage(mContext.getString(R.string.pdf_exported_at)+filePath); } }); - } else { - if (takeOwnership) { - mInputFile = filePath; - } - LOKitShell.getMainHandler().post(new Runnable() { - @Override - public void run() { - // There was no error - mContext.showSaveStatusMessage(false); - } - }); + } else if (takeOwnership) { + mInputFile = filePath; } } LOKitShell.hideProgressSpinner(mContext); diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 6db06d155322..a070c292009c 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -58,6 +58,7 @@ import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.List; +import java.util.UUID; /** * Main activity of the LibreOffice App. It is started in the UI thread. @@ -127,7 +128,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin private boolean isSearchToolbarOpen = false; private static boolean isDocumentChanged = false; private boolean isUNOCommandsToolbarOpen = false; - public boolean isNewDocument = false; + private boolean isNewDocument = false; private long lastModified = 0; @Override @@ -180,31 +181,35 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin mbISReadOnlyMode = !isExperimentalMode(); - if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) { - // New document type string is not null, meaning we want to open a new document - String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY); - String newFilePath = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_FILE_PATH_KEY); - - // Load the new document - loadNewDocument(newFilePath, newDocumentType); - } else if (getIntent().getData() != null) { + if (getIntent().getData() != null) { if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) { - if (copyFileToTemp() && mTempFile != null) { + final boolean isReadOnlyDoc; + if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) { + // New document type string is not null, meaning we want to open a new document + String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY); + // create a temporary local file, will be copied to the actual URI when saving + loadNewDocument(newDocumentType); mInputFile = mTempFile; - boolean isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0; - mbISReadOnlyMode = !isExperimentalMode() || isReadOnlyDoc; - Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + getIntent().getData().getPath()); - - String displayName = extractDisplayNameFromIntent(); - if (displayName.isEmpty()) { - // fall back to using temp file name - displayName = mInputFile.getName(); - } - toolbarTop.setTitle(displayName); + isReadOnlyDoc = false; + } else if (copyFileToTemp() && mTempFile != null) { + mInputFile = mTempFile; + isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0; } else { // TODO: can't open the file Log.e(LOGTAG, "couldn't create temporary file from " + getIntent().getData()); + return; + } + + mbISReadOnlyMode = !isExperimentalMode() || isReadOnlyDoc; + Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + getIntent().getData().getPath()); + + String displayName = extractDisplayNameFromIntent(); + if (displayName.isEmpty()) { + // fall back to using temp file name + displayName = mInputFile.getName(); } + toolbarTop.setTitle(displayName); + } else if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_FILE)) { mInputFile = new File(getIntent().getData().getPath()); Log.d(LOGTAG, "SCHEME_FILE: getPath(): " + getIntent().getData().getPath()); @@ -280,12 +285,12 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } } - // Loads a new Document - private void loadNewDocument(String newFilePath, String newDocumentType) { - mInputFile = new File(newFilePath); - LOKitShell.sendNewDocumentLoadEvent(newFilePath, newDocumentType); + // Loads a new Document and saves it to a temporary file + private void loadNewDocument(String newDocumentType) { + String tempFileName = "LibreOffice_" + UUID.randomUUID().toString(); + mTempFile = new File(this.getCacheDir(), tempFileName); + LOKitShell.sendNewDocumentLoadEvent(mTempFile.getPath(), newDocumentType); isNewDocument = true; - toolbarTop.setTitle(mInputFile.getName()); } public RectF getCurrentCursorPosition() { @@ -376,19 +381,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin if (documentUri != null) { // case where file was opened using IDocumentProvider from within LO app saveFilesToCloud(); - } else if (isNewDocument) { - // nothing to do for actual save, the actual (local) file is already handled - // by LOKitTileProvider - runOnUiThread(new Runnable() { - @Override - public void run() { - Toast.makeText(LibreOfficeMainActivity.this, R.string.message_saved, - Toast.LENGTH_SHORT).show(); - } - }); - setDocumentChanged(false); } else { - // case where file was passed via Intent + // case where file URI was passed via Intent if (isReadOnlyMode() || mInputFile == null || getIntent().getData() == null || !getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) return; @@ -1035,13 +1029,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } } - // This method is used in LOKitTileProvider.java to show status of new file creation. - public void showSaveStatusMessage(boolean error) { - if (!error) - Snackbar.make(mDrawerLayout, getString(R.string.create_new_file_success) + mInputFile.getName(), Snackbar.LENGTH_LONG).show(); - else - Snackbar.make(mDrawerLayout, getString(R.string.create_new_file_error) + mInputFile.getName(), Snackbar.LENGTH_LONG).show(); } - public void showCustomStatusMessage(String message){ Snackbar.make(mDrawerLayout, message, Snackbar.LENGTH_LONG).show(); } diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 8e84868dbda5..517aa158035d 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -27,6 +27,7 @@ import android.graphics.drawable.Icon; import android.hardware.usb.UsbManager; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; @@ -91,6 +92,14 @@ import java.util.List; import java.util.Set; public class LibreOfficeUIActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener, View.OnClickListener{ + public enum DocumentType { + WRITER, + CALC, + IMPRESS, + DRAW, + INVALID + } + private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName(); private SharedPreferences prefs; private int filterMode = FileUtilities.ALL; @@ -111,6 +120,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private IFile currentDirectory; private int currentlySelectedFile; + private DocumentType newDocType = DocumentType.INVALID; + private static final String CURRENT_DIRECTORY_KEY = "CURRENT_DIRECTORY"; private static final String DOC_PROVIDER_KEY = "CURRENT_DOCUMENT_PROVIDER"; private static final String FILTER_MODE_KEY = "FILTER_MODE"; @@ -121,7 +132,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private static final String ENABLE_SHOW_HIDDEN_FILES_KEY = "ENABLE_SHOW_HIDDEN_FILES"; private static final String DISPLAY_LANGUAGE = "DISPLAY_LANGUAGE"; - public static final String NEW_FILE_PATH_KEY = "NEW_FILE_PATH_KEY"; public static final String NEW_DOC_TYPE_KEY = "NEW_DOC_TYPE_KEY"; public static final String NEW_WRITER_STRING_KEY = "private:factory/swriter"; public static final String NEW_IMPRESS_STRING_KEY = "private:factory/simpress"; @@ -172,6 +182,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings public static final int LIST_VIEW = 1; private static final int REQUEST_CODE_OPEN_FILECHOOSER = 12345; + private static final int REQUEST_CODE_CREATE_NEW_DOCUMENT = 12346; private DrawerLayout drawerLayout; private NavigationView navigationDrawer; @@ -487,6 +498,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings LibreOfficeMainActivity.class.getName()); intent.setComponent(componentName); startActivity(intent); + } else if (requestCode == REQUEST_CODE_CREATE_NEW_DOCUMENT) { + // "forward" to LibreOfficeMainActivity to create + open the file + final Uri fileUri = data.getData(); + loadNewDocument(newDocType, fileUri); } } @@ -674,37 +689,50 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings }.execute(document); } - // Opens an Input dialog to get the name of new file - private void createNewFileInputDialog(final String defaultFileName, final String newDocumentType) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.create_new_document_title); - final EditText input = new EditText(this); - input.setInputType(InputType.TYPE_CLASS_TEXT); - input.setText(defaultFileName); - builder.setView(input); + private void createNewFileDialog() { + final String extension; + if (newDocType == DocumentType.WRITER) { + extension = FileUtilities.DEFAULT_WRITER_EXTENSION; + } else if (newDocType == DocumentType.CALC) { + extension = FileUtilities.DEFAULT_SPREADSHEET_EXTENSION; + } else if (newDocType == DocumentType.IMPRESS) { + extension = FileUtilities.DEFAULT_IMPRESS_EXTENSION; + } else if (newDocType == DocumentType.DRAW) { + extension = FileUtilities.DEFAULT_DRAWING_EXTENSION; + } else { + Log.e(LOGTAG, "Invalid document type passed."); + return; + } - builder.setPositiveButton(R.string.action_create, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - final String newFilePath = currentDirectory.getUri().getPath() + input.getText().toString(); - loadNewDocument(newDocumentType, newFilePath); - } - }); + String defaultFileName = getString(R.string.default_document_name) + extension; + String mimeType = FileUtilities.getMimeType(defaultFileName); - builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(mimeType); + intent.putExtra(Intent.EXTRA_TITLE, defaultFileName); - builder.show(); + startActivityForResult(intent, REQUEST_CODE_CREATE_NEW_DOCUMENT); } - private void loadNewDocument(String newDocumentType, String newFilePath) { + private void loadNewDocument(DocumentType docType, Uri newFileUri) { + final String newDocumentType; + if (docType == DocumentType.WRITER) { + newDocumentType = NEW_WRITER_STRING_KEY; + } else if (docType == DocumentType.CALC) { + newDocumentType = NEW_CALC_STRING_KEY; + } else if (docType == DocumentType.IMPRESS) { + newDocumentType = NEW_IMPRESS_STRING_KEY; + } else if (docType == DocumentType.DRAW) { + newDocumentType = NEW_DRAW_STRING_KEY; + } else { + Log.w(LOGTAG, "invalid document type passed to loadNewDocument method. Ignoring request"); + return; + } + Intent intent = new Intent(LibreOfficeUIActivity.this, LibreOfficeMainActivity.class); intent.putExtra(NEW_DOC_TYPE_KEY, newDocumentType); - intent.putExtra(NEW_FILE_PATH_KEY, newFilePath); + intent.setData(newFileUri); startActivity(intent); } @@ -1158,6 +1186,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings int id = v.getId(); switch (id){ case R.id.editFAB: + // Intent.ACTION_CREATE_DOCUMENT, used in 'createNewFileDialog' requires SDK version 19 + if (Build.VERSION.SDK_INT < 19) { + Toast.makeText(this, + getString(R.string.creating_new_files_not_supported), Toast.LENGTH_SHORT).show(); + return; + } if (isFabMenuOpen) { collapseFabMenu(); } else { @@ -1168,16 +1202,20 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings showSystemFilePickerAndOpenFile(); break; case R.id.newWriterFAB: - createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_WRITER_EXTENSION, NEW_WRITER_STRING_KEY); + newDocType = DocumentType.WRITER; + createNewFileDialog(); break; case R.id.newImpressFAB: - createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_IMPRESS_EXTENSION, NEW_IMPRESS_STRING_KEY); + newDocType = DocumentType.IMPRESS; + createNewFileDialog(); break; case R.id.newCalcFAB: - createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_SPREADSHEET_EXTENSION, NEW_CALC_STRING_KEY); + newDocType = DocumentType.CALC; + createNewFileDialog(); break; case R.id.newDrawFAB: - createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_DRAWING_EXTENSION, NEW_DRAW_STRING_KEY); + newDocType = DocumentType.DRAW; + createNewFileDialog(); break; } } commit 05b7f6f4e85c44997d3b5603d5a61f64eed2c88c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 11:22:30 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:17:55 2021 +0200 android: Only update file path for "real Save As" Follow-up for commit a1abf2c865228e6ed33e99ab73b94357ddbc590f (tdf#139350 android: Add param to allow a "real" "Save As"). The file path should only be updated when the newly saved doc is actually used (i.e. 'takeOwnership=true'), not when just saving a copy or exporting to a different file format. Change-Id: Ia3120a94b7fcc79c1a740a10bade8721f6771d78 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113404 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 19e1f3723d4bfb91dadf77b398261da0e8237a8b) diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index 0a9ad6a90685..85eda566bae3 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -349,7 +349,9 @@ class LOKitTileProvider implements TileProvider { } }); } else { - mInputFile = filePath; + if (takeOwnership) { + mInputFile = filePath; + } LOKitShell.getMainHandler().post(new Runnable() { @Override public void run() { commit f5378effe6a6a654be03f2d3942fa4d48e21e494 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Mar 31 10:11:20 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Apr 1 07:17:49 2021 +0200 android: Drop unused 'newDocumentType' member It appears to have been unused since it was added in commit 78098b8494be7123bc4a8b50faa13445e5afd8ce Date: Mon Mar 27 22:26:47 2017 +0530 Add BottomSheetBehavior to formatting toolbar Change-Id: I43cc75e0b7a1bcebd01bd77fc7132a39510c70ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113400 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 05a3ce9abb329969e7edaafd0a2e9057c73d0fbb) diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index b9896c3c046c..6db06d155322 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -93,7 +93,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin private DocumentOverlay mDocumentOverlay; private File mTempFile = null; private File mTempSlideShowFile = null; - private String newDocumentType = null; public boolean firstStart = true; BottomSheetBehavior bottomToolbarSheetBehavior; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits