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,27 +339,26 @@ 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 // Pop last item from backstack and pretend the relevant menu item was clicked
if (mFullscreenMode && (mBackStack.isEmpty() || mNavigationHelper.hideInFullscreen())) { if (!mBackStack.isEmpty()) {
this.toggleFullscreen();
} else if (!mBackStack.isEmpty()) {
// Pop last item from backstack and pretend the relevant menu item was clicked
backStackPop(); backStackPop();
return;
}
if (mBackButtonPressed || !mSharedPrefs.getBoolean("pref_press_twice_to_exit", false)) {
super.onBackPressed();
return;
} else { } else {
if (mBackButtonPressed || !mSharedPrefs.getBoolean("pref_press_twice_to_exit", false)) mBackButtonPressed = true;
super.onBackPressed(); Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
else { // reset back button after 2 seconds
mBackButtonPressed = true; new Handler().postDelayed(new Runnable() {
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show(); @Override
// reset back button after 2 seconds public void run() {
new Handler().postDelayed(new Runnable() { mBackButtonPressed = false;
@Override }
public void run() { }, 2000);
mBackButtonPressed = false;
}
}, 2000);
}
} }
} }

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;
} }