[Libreoffice-commits] core.git: android/source

Mert Tumer merttumer at outlook.com
Sat Dec 24 08:25:03 UTC 2016


 android/source/res/values/strings.xml                                |    6 +
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java |   52 ++++++++++
 2 files changed, 58 insertions(+)

New commits:
commit 45f75e2909ccf47c8615b5adf1bfda4cd6247879
Author: Mert Tumer <merttumer at outlook.com>
Date:   Wed Dec 21 12:48:53 2016 +0200

    tdf#104856 - Fix for closing the document without asking for saving
    
    Change-Id: I37b6fbf2639439a57c6d162b7817d009d1d49023
    Reviewed-on: https://gerrit.libreoffice.org/32332
    Reviewed-by: jan iversen <jani at documentfoundation.org>
    Tested-by: jan iversen <jani at documentfoundation.org>

diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index 9ac37be..5cf7311 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -100,5 +100,11 @@
     <string name="directory_browser_label">Choose Directory</string>
     <string name="bad_directory">Invalid directory path</string>
 
+    <!-- Closing alert dialog strings -->
+    <string name="save_alert_dialog_title">Save the document before closing?</string>
+    <string name="save_document">SAVE</string>
+    <string name="cancel_save_document">CANCEL</string>
+    <string name="no_save_document">NO</string>
+
 
 </resources>
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index c04742a..0eb326b 100755
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -18,6 +18,7 @@ import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
 import android.util.Log;
+import android.view.KeyEvent;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView;
@@ -99,6 +100,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
     private boolean isKeyboardOpen = false;
     private boolean isFormattingToolbarOpen = false;
     private boolean isSearchToolbarOpen = false;
+    private boolean isDocumentChanged = false;
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Log.w(LOGTAG, "onCreate..");
@@ -181,6 +183,16 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
         layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
         mLayerClient.notifyReady();
 
+        layerView.setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View view, int i, KeyEvent keyEvent) {
+                if(keyEvent.getKeyCode() != KeyEvent.KEYCODE_BACK){
+                    isDocumentChanged=true;
+                }
+                return false;
+            }
+        });
+
         // create TextCursorLayer
         mDocumentOverlay = new DocumentOverlay(mAppContext, layerView);
 
@@ -269,6 +281,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
             protected void onPostExecute(Void param) {
                 Toast.makeText(activity, R.string.message_saved,
                         Toast.LENGTH_SHORT).show();
+                isDocumentChanged=false;
             }
         };
         // Delay the call to document provider save operation and check the
@@ -344,6 +357,45 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
             }
         }
     }
+    @Override
+    public void onBackPressed() {
+        if (!isDocumentChanged) {
+            super.onBackPressed();
+            return;
+        }
+
+
+        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                switch (which){
+                    case DialogInterface.BUTTON_POSITIVE:
+                        //SAVE
+                        saveDocument();
+                        isDocumentChanged=false;
+                        onBackPressed();
+                        break;
+
+                    case DialogInterface.BUTTON_NEGATIVE:
+                        //CANCEL
+                        break;
+                    case DialogInterface.BUTTON_NEUTRAL:
+                        //NO
+                        isDocumentChanged=false;
+                        onBackPressed();
+                        break;
+                }
+            }
+        };
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(mAppContext);
+        builder.setMessage(R.string.save_alert_dialog_title)
+                .setPositiveButton(R.string.save_document, dialogClickListener)
+                .setNegativeButton(R.string.cancel_save_document, dialogClickListener)
+                .setNeutralButton(R.string.no_save_document, dialogClickListener)
+                .show();
+
+    }
 
     public LOKitThread getLOKitThread() {
         return sLOKitThread;


More information about the Libreoffice-commits mailing list