]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
Hide the keyboard when the navigation menu opens. Fixes https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / MainWebViewActivity.java
index 1c20c46d8f92534cf1e09f949aa235ad36c8206c..69ac5441e4831e920c61ba67aa27b8630e0616fd 100644 (file)
@@ -283,13 +283,43 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
         // Create the navigation drawer.
         drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
-        // The DrawerTitle identifies the drawer in accessibility mode.
+        // `DrawerTitle` identifies the drawer in accessibility mode.
         drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer));
 
         // Listen for touches on the navigation menu.
         final NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
         navigationView.setNavigationItemSelectedListener(this);
 
+        // Get handles for `navigationMenu` and the back and forward menu items.  The menu is zero-based, so item 1 and 2 and the second and third items in the menu.
+        final Menu navigationMenu = navigationView.getMenu();
+        final MenuItem navigationBackMenuItem = navigationMenu.getItem(1);
+        final MenuItem navigationForwardMenuItem = navigationMenu.getItem(2);
+
+        // The `DrawerListener` allows us to update the Navigation Menu.
+        drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
+            @Override
+            public void onDrawerSlide(View drawerView, float slideOffset) {
+            }
+
+            @Override
+            public void onDrawerOpened(View drawerView) {
+            }
+
+            @Override
+            public void onDrawerClosed(View drawerView) {
+            }
+
+            @Override
+            public void onDrawerStateChanged(int newState) {
+                // Update the back and forward menu items every time the drawer opens.
+                navigationBackMenuItem.setEnabled(mainWebView.canGoBack());
+                navigationForwardMenuItem.setEnabled(mainWebView.canGoForward());
+
+                // Hide the keyboard so we can see the navigation menu.  `0` indicates no additional flags.
+                inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0);
+            }
+        });
+
         // drawerToggle creates the hamburger icon at the start of the AppBar.
         drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, supportAppBar, R.string.open_navigation, R.string.close_navigation);
 
@@ -1331,7 +1361,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
         mainWebView.loadUrl(formattedUrlString, customHeaders);
 
-        // Hides the keyboard so we can see the webpage.  `0` indicates no additional flags.
+        // Hide the keyboard so we can see the webpage.  `0` indicates no additional flags.
         inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0);
     }
 
@@ -1360,7 +1390,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         Toolbar appBarToolbar = (Toolbar) findViewById(R.id.appBar);
         appBarToolbar.setVisibility(View.VISIBLE);
 
-        // Hides the keyboard so we can see the webpage.  `0` indicates no additional flags.
+        // Hide the keyboard so we can see the webpage.  `0` indicates no additional flags.
         inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0);
     }