From 37dac3b1977818e6b93df07bd04cc2d57eac84ac Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 25 May 2013 15:37:49 +0200 Subject: [PATCH] * display backstack correctly on home button * clear backstack on home button pressed --- .../com/cradle/iitc_mobile/IITC_Mobile.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index bdf4de98..c76eb16c 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -130,7 +130,7 @@ public class IITC_Mobile extends Activity { // Clear the back stack backStack.clear(); - SetActionBarHomeEnabledWithUp(false); + setActionBarHomeEnabledWithUp(false); handleIntent(getIntent(), true); } @@ -253,16 +253,18 @@ public class IITC_Mobile extends Activity { } } - private void SetActionBarHomeEnabledWithUp(boolean enabled) { + private void setActionBarHomeEnabledWithUp(boolean enabled) { actionBar.setDisplayHomeAsUpEnabled(enabled); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) actionBar.setHomeButtonEnabled(enabled); } public void backStackPop() { + // shouldn't be called when back stack is empty + // catch wrong usage if (backStack.isEmpty()) { // Empty back stack means we should be at home (ie map) screen - SetActionBarHomeEnabledWithUp(false); + setActionBarHomeEnabledWithUp(false); actionBar.setTitle(getString(R.string.app_name)); iitc_view.loadUrl("javascript: window.show('map');"); return; @@ -271,13 +273,18 @@ public class IITC_Mobile extends Activity { int itemId = backStack.remove(index); currentPane = itemId; handleMenuItemSelected(itemId, false); + // if we popped our last item from stack...illustrate it on home button + if (backStack.isEmpty()) { + // Empty back stack means we should be at home (ie map) screen + setActionBarHomeEnabledWithUp(false); + } } public void backStackUpdate(int itemId) { if (itemId == currentPane) return; backStack.add(currentPane); currentPane = itemId; - if (backStack.size() == 1) SetActionBarHomeEnabledWithUp(true); + if (backStack.size() == 1) setActionBarHomeEnabledWithUp(true); } @Override @@ -307,16 +314,15 @@ public class IITC_Mobile extends Activity { public boolean handleMenuItemSelected(int itemId, boolean addToBackStack) { switch (itemId) { case android.R.id.home: - if (!backStack.isEmpty()) { - backStackPop(); - } iitc_view.loadUrl("javascript: window.show('map');"); actionBar.setTitle(getString(R.string.app_name)); + this.backStack.clear(); + setActionBarHomeEnabledWithUp(false); return true; case R.id.reload_button: actionBar.setTitle(getString(R.string.app_name)); backStack.clear(); - SetActionBarHomeEnabledWithUp(false); + setActionBarHomeEnabledWithUp(false); this.loadUrl(intel_url); return true; case R.id.toggle_fullscreen: