From d1f671e053864d0bf54d04a855761b43a7f5a9c4 Mon Sep 17 00:00:00 2001 From: Jacobo Aragunde Pérez Date: Wed, 10 Jun 2015 19:04:22 +0200 Subject: tdf#87434: android: system back key to go one level up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Change-Id: I26827113a41070aa8188fa616ba8fe53742329b3 Reviewed-on: https://gerrit.libreoffice.org/16245 Tested-by: Jenkins Reviewed-by: Jacobo Aragunde Pérez --- android/source/res/values/strings.xml | 1 + .../org/libreoffice/ui/LibreOfficeUIActivity.java | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'android') diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 94ba49f7b148..e2afccaf9f85 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -14,6 +14,7 @@ Show License Show Notice More Info + Press back again to quit LibreOffice Browser Search diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index a8f42765a873..8ceca05938c2 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -20,6 +20,7 @@ import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; import android.preference.PreferenceManager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; @@ -96,6 +97,7 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa ListView lv; private final LOAbout mAbout; + private boolean canQuit = false; public LibreOfficeUIActivity() { mAbout = new LOAbout(this, true); @@ -197,6 +199,31 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa drawerLayout.closeDrawer(drawerList); } + @Override + public void onBackPressed() { + if (!currentDirectory.equals(homeDirectory)) { + // navigate upwards in directory hierarchy + openParentDirectory(); + } 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); + } + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { -- cgit