Skip to content

Commit

Permalink
Merge branch '#855_v2_doubleBackButtonPressed' into tw_develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed Jan 6, 2020
2 parents b189c1f + 21b6e9f commit 844269e
Showing 1 changed file with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,45 +431,55 @@ protected void onDestroy() {
@Override
public void onBackPressed() {

// Get Preference about double back button press to exit
boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.key_use_double_back_button_press_to_quit),
true);
if (isNavigationViewOpen()) {
// The main navigation menu is open

if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) {
// BackPress button has already been pressed recently OR shall not use double back press to exit
// Close the main navigation menu
super.onBackPressed();

} else {
// The main navigation menu is closed

//
// Do not show the Toast anymore
//
// Get Preference about double back button press to exit
boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.key_use_double_back_button_press_to_quit),
true);

if (mToast != null) {
// There is a Toast
if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) {
// BackPress button has already been pressed recently OR shall not use double back press to exit

//
// Do not show the Toast anymore
mToast.cancel();
//

} else {
// There is no Toast
if (mToast != null) {
// There is a Toast

// NTD
}
// Do not show the Toast anymore
mToast.cancel();

// Perform BackPress
super.onBackPressed();
} else {
// There is no Toast

} else {
// BackPress button has been pressed for the first time AND shall use double back press to exit
// NTD
}

// Perform BackPress
super.onBackPressed();

// Notice that button has been pressed once
this.mDoubleBackButtonPressedOnce = true;
} else {
// BackPress button has been pressed for the first time AND shall use double back press to exit

// Notice that button has been pressed once
this.mDoubleBackButtonPressedOnce = true;

// Show a message to explain that user must press again to exit
mToast.show();
// Show a message to explain that user must press again to exit
mToast.show();

// After two seconds, it is not more considered as already pressed
mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable,
2000);
// After two seconds, it is not more considered as already pressed
mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable,
2000);
}
}
}

Expand Down

0 comments on commit 844269e

Please sign in to comment.