summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMert Tumer <merttumer@outlook.com>2016-12-21 12:48:53 +0200
committerjan iversen <jani@documentfoundation.org>2016-12-24 08:24:42 +0000
commit45f75e2909ccf47c8615b5adf1bfda4cd6247879 (patch)
tree503515917008886f754e4bc65b7f767ca8266568
parent1c6993e6d7d04c42c6bd48da6afb6305eb608c11 (diff)
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@documentfoundation.org> Tested-by: jan iversen <jani@documentfoundation.org>
-rw-r--r--android/source/res/values/strings.xml6
-rwxr-xr-xandroid/source/src/java/org/libreoffice/LibreOfficeMainActivity.java52
2 files changed, 58 insertions, 0 deletions
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index 9ac37bed035c..5cf731100dd0 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 c04742a238e9..0eb326bef925 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;