File tree Expand file tree Collapse file tree
source-code/app/src/main/java/org/buildmlearn/toolkit/activity Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import android .app .FragmentTransaction ;
66import android .content .Intent ;
77import android .os .Bundle ;
8+ import android .os .Handler ;
89import android .support .v4 .widget .DrawerLayout ;
910import android .support .v7 .app .AppCompatActivity ;
1011import android .support .v7 .widget .Toolbar ;
12+ import android .widget .Toast ;
1113
1214import org .buildmlearn .toolkit .R ;
1315import org .buildmlearn .toolkit .constant .Constants ;
@@ -25,6 +27,8 @@ public class HomeActivity extends AppCompatActivity
2527
2628 private Section currentSection ;
2729 private NavigationDrawerFragment mNavigationDrawerFragment ;
30+ private boolean atHome = true ;
31+ private boolean backPressedOnce = false ;
2832
2933 /**
3034 * {@inheritDoc}
@@ -130,9 +134,24 @@ public void onBackPressed() {
130134 mNavigationDrawerFragment .closeDrawer ();
131135 return ;
132136 }
133- if (getFragmentManager ().getBackStackEntryCount () <= 1 ) {
134- finish ();
137+ if (atHome ){
138+ if (backPressedOnce ){
139+ finish ();
140+ }
141+ backPressedOnce =true ;
142+ Toast .makeText (this , "Tap back once more to exit." , Toast .LENGTH_SHORT ).show ();
143+ new Handler ().postDelayed (new Runnable ()
144+ {
145+ @ Override
146+ public void run ()
147+ {
148+ backPressedOnce = false ;
149+ }
150+ }, 2000 );
151+ }
152+ else if (!atHome ){
153+ onNavigationDrawerItemSelected (0 );
154+ atHome = true ;
135155 }
136- super .onBackPressed ();
137156 }
138157}
You can’t perform that action at this time.
0 commit comments