From 899d59d38fa1020f1c44be2ac5667db2974683db Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 15 Jun 2013 13:06:53 +0200 Subject: [PATCH] added back "press twice to exit" (fixes #356) - there is no reason why we shouldn't do it this way --- .../src/com/cradle/iitc_mobile/IITC_Mobile.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 0f72fbe6..ada5ac09 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -19,6 +19,7 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.os.StrictMode; import android.preference.PreferenceManager; import android.util.Log; @@ -54,6 +55,7 @@ public class IITC_Mobile extends Activity { private ArrayList backStack = new ArrayList(); private boolean backStack_push = true; private int currentPane = android.R.id.home; + private boolean back_button_pressed = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -285,7 +287,19 @@ public class IITC_Mobile extends Activity { // Pop last item from backStack and pretend the relevant menu item was clicked backStackPop(); } else { - super.onBackPressed(); + if (back_button_pressed) + super.onBackPressed(); + else { + back_button_pressed = true; + Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show(); + // reset back button after 2 seconds + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + back_button_pressed=false; + } + }, 2000); + } } }