@@ -210,10 +210,11 @@ public void onConfigurationChanged(Configuration newConfig) {
210
210
@ Override
211
211
public boolean onOptionsItemSelected (MenuItem item ) {
212
212
if (item .getItemId () == android .R .id .home ){
213
- if (!mDrawerLayout . isDrawerOpen ( mNavigationView ))
213
+ if (!isNavigationViewOpen ()) {
214
214
mDrawerLayout .openDrawer (mNavigationView );
215
- else
216
- mDrawerLayout .closeDrawer (mNavigationView );
215
+ } else {
216
+ closeNavigationView ();
217
+ }
217
218
return true ;
218
219
}
219
220
@@ -286,7 +287,7 @@ protected void onDrawerMenuItemClicked(int itemId) {
286
287
UserVoice .launchUserVoice (this );
287
288
break ;
288
289
}
289
- mDrawerLayout . closeDrawer ( mNavigationView );
290
+ closeNavigationView ( );
290
291
}
291
292
292
293
@ Override
@@ -319,7 +320,7 @@ public boolean onMenuItemClick(MenuItem item) {
319
320
Intent intent = new Intent (this , PreferenceActivity .class );
320
321
intent .setAction (PreferenceActivity .ACTION_MANAGE_BOOKS );
321
322
startActivity (intent );
322
- mDrawerLayout . closeDrawer ( mNavigationView );
323
+ closeNavigationView ( );
323
324
return true ;
324
325
}
325
326
BooksDbAdapter booksDbAdapter = BooksDbAdapter .getInstance ();
@@ -332,9 +333,17 @@ public boolean onMenuItemClick(MenuItem item) {
332
333
return true ;
333
334
}
334
335
335
- public void onClickAppTitle (View view ){
336
+ protected void onClickAppTitle (View view ) {
337
+
338
+ closeNavigationView ();
339
+
340
+ // Do not launch AccountsActivity to stay on current Activity
341
+ // AccountsActivity.start(this);
342
+ }
343
+
344
+ protected void closeNavigationView () {
345
+
336
346
mDrawerLayout .closeDrawer (mNavigationView );
337
- AccountsActivity .start (this );
338
347
}
339
348
340
349
public void onClickBook (View view ){
@@ -354,4 +363,32 @@ public void onClickBook(View view){
354
363
355
364
popup .show ();
356
365
}
366
+
367
+ @ Override
368
+ public void onBackPressed () {
369
+
370
+ if (isNavigationViewOpen ()) {
371
+ // The main navigation menu is open
372
+
373
+ // Close the main navigation menu
374
+ // mDrawerLayout.closeDrawer(mNavigationView);
375
+ onClickAppTitle (getCurrentFocus ());
376
+
377
+ } else {
378
+ // The main navigation menu is closed
379
+
380
+ // Close the Activity
381
+ super .onBackPressed ();
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Return true if main navigation menu is open
387
+ *
388
+ * @return true if main navigation menu is open
389
+ */
390
+ protected boolean isNavigationViewOpen () {
391
+
392
+ return mDrawerLayout .isDrawerOpen (mNavigationView );
393
+ }
357
394
}
0 commit comments