android: Offer 'Save As' in readonly mode

Provide the "Save As..." menu entry in Android
Viewer also if read-only mode is used, either
because the experimental editing mode is disabled
or there is no write access to the document.

This way, a copy of the original document
can be saved elsewhere.

In case experimental mode is enabled, editing
is allowed after saving the document.

Call 'ToolbarController#setEditMode' in
'ToolbarController#switchToEditMode' right away instead
of posting it to the main handler in a Runnable along
with the other commands (that change the UI), so the new state
is already taken into account in
'LibreOfficeMainActivity#onResume' and the toolbar
isn't switched back to view mode there right away.

Change-Id: I321e42d0833463b31c7b39336d66b29bd51d9890
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114539
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml
index 0570a77..168817f 100644
--- a/android/source/res/menu/main.xml
+++ b/android/source/res/menu/main.xml
@@ -38,16 +38,17 @@
        <item android:id="@+id/action_save"
            android:title="@string/action_save"
            android:orderInCategory="100" />

        <item android:id="@+id/action_save_as"
            android:title="@string/action_save_as"
            android:orderInCategory="100" />
    </group>

    <group android:id="@+id/group_misc_actions"
           tools:visible="true"
           android:visible="false">

        <item android:id="@+id/action_save_as"
            android:title="@string/action_save_as"
            android:orderInCategory="100"
            android:visible="true" />

        <item android:id="@+id/action_exportToPDF"
            android:title="@string/action_exportToPDF"
            android:orderInCategory="100"
diff --git a/android/source/res/values-de/strings.xml b/android/source/res/values-de/strings.xml
index 36effc9..5342cf7 100644
--- a/android/source/res/values-de/strings.xml
+++ b/android/source/res/values-de/strings.xml
@@ -9,7 +9,7 @@
    <string name="app_description">LibreOffice Viewer ist ein Dokumentenbetrachter, der auf LibreOffice basiert.</string>
    <string name="app_credits">https://www.libreoffice.org</string>
    <string name="app_vendor">Dieses Release wurde bereitgestellt durch $VENDOR.</string>
    <string name="temp_file_saving_disabled">Diese Datei ist schreibgeschützt, Speichern ist deaktiviert.</string>
    <string name="readonly_file">Diese Datei ist schreibgeschützt.</string>

    <string name="about_license">Lizenz anzeigen</string>
    <string name="about_notice">Hinweise anzeigen</string>
diff --git a/android/source/res/values-tr/strings.xml b/android/source/res/values-tr/strings.xml
index a780a59..ec7274c 100644
--- a/android/source/res/values-tr/strings.xml
+++ b/android/source/res/values-tr/strings.xml
@@ -9,7 +9,7 @@
    <string name="app_description">LibreOffice Görüntüleyici LibreOffice tabanlı bir belge görüntüleyicisidir.</string>
    <string name="app_credits">https://www.libreoffice.org</string>
    <string name="app_vendor">Bu sürüm $VENDOR tarafından derlenmiştir.</string>
    <string name="temp_file_saving_disabled">Bu dosya salt okunabilir haldedir. Kaydetme devredışı.</string>
    <string name="readonly_file">Bu dosya salt okunabilir haldedir.</string>

    <string name="about_license">Lisansı Görüntüle</string>
    <string name="about_notice">Bildiriyi Görüntüle</string>
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index 6b3db68..49eea9f 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -9,7 +9,7 @@
    <string name="app_description">LibreOffice Viewer is a document viewer based on LibreOffice.</string>
    <string name="app_credits">https://www.libreoffice.org</string>
    <string name="app_vendor">This release was supplied by $VENDOR.</string>
    <string name="temp_file_saving_disabled">This file is read-only, saving is disabled.</string>
    <string name="readonly_file">This file is read-only.</string>

    <string name="about_license">Show License</string>
    <string name="about_notice">Show Notice</string>
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index f7f5f6ae..28427b5 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -339,7 +339,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin

        String displayName = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), mDocumentUri);
        toolbarTop.setTitle(displayName);
        // make sure that "Save" menu item is enabled
        mbISReadOnlyMode = !isExperimentalMode();
        getToolbarController().setupToolbars();
    }

diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index d4985ae..c97d84f 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -72,6 +72,8 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
    void switchToEditMode() {
        if (!LOKitShell.isEditingEnabled())
            return;

        setEditModeOn(true);
        // Ensure the change is done on UI thread
        LOKitShell.getMainHandler().post(new Runnable() {
            @Override
@@ -89,7 +91,6 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
                }
                mToolbarTop.setNavigationIcon(R.drawable.ic_check);
                mToolbarTop.setLogo(null);
                setEditModeOn(true);
            }
        });
    }
@@ -251,7 +252,7 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
            if (LibreOfficeMainActivity.isReadOnlyMode()) {
                // show message in case experimental mode is enabled (i.e. editing is supported in general),
                // but current document is readonly
                Toast.makeText(mContext, mContext.getString(R.string.temp_file_saving_disabled), Toast.LENGTH_LONG).show();
                Toast.makeText(mContext, mContext.getString(R.string.readonly_file), Toast.LENGTH_LONG).show();
            }
        }
        mMainMenu.findItem(R.id.action_parts).setVisible(mContext.isDrawerEnabled());