Change handling of back key

1. quit full screen
2. close drawer
3. close dialogs
4. regular back stack
5. close IITC

dialogs can always be closed via [OK], the drawer still reacts on the left edge
This commit is contained in:
fkloft 2013-09-23 11:21:23 +02:00
parent 4234ee15b4
commit e06f8f87d9
2 changed files with 39 additions and 20 deletions

View File

@ -318,7 +318,19 @@ public class IITC_Mobile extends Activity {
// we want a self defined behavior for the back button // we want a self defined behavior for the back button
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// first kill all open iitc dialogs // exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty
if (mFullscreenMode && (mBackStack.isEmpty() || mNavigationHelper.hideInFullscreen())) {
toggleFullscreen();
return;
}
// close drawer if opened
if (mNavigationHelper.isDrawerOpened()) {
mNavigationHelper.closeDrawer();
return;
}
// kill all open iitc dialogs
if (!mDialogStack.isEmpty()) { if (!mDialogStack.isEmpty()) {
String id = mDialogStack.pop(); String id = mDialogStack.pop();
mIitcWebView.loadUrl("javascript: " + mIitcWebView.loadUrl("javascript: " +
@ -327,17 +339,17 @@ public class IITC_Mobile extends Activity {
"selector.remove();"); "selector.remove();");
return; return;
} }
// exit fullscreen mode if it is enabled and action bar is disabled
// or the back stack is empty
if (mFullscreenMode && (mBackStack.isEmpty() || mNavigationHelper.hideInFullscreen())) {
this.toggleFullscreen();
} else if (!mBackStack.isEmpty()) {
// Pop last item from backstack and pretend the relevant menu item was clicked // Pop last item from backstack and pretend the relevant menu item was clicked
if (!mBackStack.isEmpty()) {
backStackPop(); backStackPop();
} else { return;
if (mBackButtonPressed || !mSharedPrefs.getBoolean("pref_press_twice_to_exit", false)) }
if (mBackButtonPressed || !mSharedPrefs.getBoolean("pref_press_twice_to_exit", false)) {
super.onBackPressed(); super.onBackPressed();
else { return;
} else {
mBackButtonPressed = true; mBackButtonPressed = true;
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
// reset back button after 2 seconds // reset back button after 2 seconds
@ -349,7 +361,6 @@ public class IITC_Mobile extends Activity {
}, 2000); }, 2000);
} }
} }
}
public void backStackPop() { public void backStackPop() {
// shouldn't be called when back stack is empty // shouldn't be called when back stack is empty

View File

@ -223,6 +223,10 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
updateActionBar(); updateActionBar();
} }
public void closeDrawer() {
mDrawerLayout.closeDrawers();
}
public String getPaneTitle(Pane pane) public String getPaneTitle(Pane pane)
{ {
switch (pane) { switch (pane) {
@ -243,6 +247,10 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
} }
} }
public boolean isDrawerOpened() {
return mDrawerOpened;
}
public boolean hideInFullscreen() { public boolean hideInFullscreen() {
return mHideInFullscreen; return mHideInFullscreen;
} }