From 46a20095d8a1ee1c950b0deddef124d991ccbe2d Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 11 Oct 2016 23:44:48 +0200 Subject: [PATCH] require a double Back press to exit the app --- .../filemanager/activities/MainActivity.java | 17 ++++++++++++++++- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index c24446f6..e39c662d 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; import android.support.v4.app.ActivityCompat; import android.view.Menu; import android.view.MenuItem; @@ -24,8 +25,11 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn @BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs; private static final int STORAGE_PERMISSION = 1; + private static final int BACK_PRESS_TIMEOUT = 5000; + private static boolean mShowFullPath; private static Config mConfig; + private static boolean mWasBackJustPressed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -108,7 +112,18 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn @Override public void onBackPressed() { if (mBreadcrumbs.getChildCount() <= 1) { - finish(); + if (!mWasBackJustPressed) { + mWasBackJustPressed = true; + Utils.showToast(getApplicationContext(), R.string.press_back_again); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + mWasBackJustPressed = false; + } + }, BACK_PRESS_TIMEOUT); + } else { + finish(); + } } else { mBreadcrumbs.removeBreadcrumb(); final FileDirItem item = (FileDirItem) mBreadcrumbs.getChildAt(mBreadcrumbs.getChildCount() - 1).getTag(); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 8553d0c4..3743473e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -34,6 +34,7 @@ home OK Abbrechen + Press back again to exit File properties diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 66d2f690..c39891b4 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -34,6 +34,7 @@ home OK Annulla + Press back again to exit Proprietà file diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1fc47c67..363a1bed 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -34,6 +34,7 @@ ホーム OK Cancel + Press back again to exit File properties diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index e490a16d..035459d4 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -34,6 +34,7 @@ início OK Cancelar + Press back again to exit Propriedades do ficheiro diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 6a09b641..16b869c0 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -34,6 +34,7 @@ home OK Cancel + Press back again to exit File properties diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 754e8238..0baec469 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,6 +34,7 @@ home OK Cancel + Press back again to exit File properties