Always reset the `SYSTEM_UI` flags in `applySettings();`
authorSoren Stoutner <soren@stoutner.com>
Thu, 23 Feb 2017 05:14:28 +0000 (22:14 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 23 Feb 2017 05:14:28 +0000 (22:14 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java
app/src/main/res/layout-w900dp/domains_list.xml
app/src/main/res/layout/navigation_header.xml
app/src/main/res/menu/webview_navigation_menu.xml

index eb6392b2ad97d8fda4f0aac8ccbfeb8567cede16..19397117fe5a271fc91412b9fb3d2bd27381f615 100644 (file)
@@ -189,7 +189,7 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
     // `fullScreenBrowsingModeEnabled` is used in `onCreate()` and `applySettings()`.
     private boolean fullScreenBrowsingModeEnabled;
 
-    // `inFullScreenBrowsingMode` is used in `onCreate()` and `applySettings()`.
+    // `inFullScreenBrowsingMode` is used in `onCreate()`, `onConfigurationChanged()`, and `applySettings()`.
     private boolean inFullScreenBrowsingMode;
 
     // `hideSystemBarsOnFullscreen` is used in `onCreate()` and `applySettings()`.
@@ -765,11 +765,17 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
             formattedUrlString = intentUriData.toString();
         }
 
+        // Initialize `inFullScreenBrowsingMode`, which is always false at this point because Privacy Browser never starts in full screen browsing mode.
+        inFullScreenBrowsingMode = false;
+
+        // Initialize AdView for the free flavor.
+        adView = findViewById(R.id.adView);
+
         // Apply the settings from the shared preferences.
         applySettings();
 
         // Load `formattedUrlString` if we are not proxying through Orbot and waiting for Orbot to connect.
-        if (!(proxyThroughOrbot & !orbotStatus.equals("ON"))) {
+        if (!(proxyThroughOrbot && !orbotStatus.equals("ON"))) {
             mainWebView.loadUrl(formattedUrlString, customHeaders);
         }
 
@@ -780,13 +786,6 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
             BitmapDrawable favoriteIconBitmapDrawable = (BitmapDrawable) favoriteIconDrawable;
             favoriteIcon = favoriteIconBitmapDrawable.getBitmap();
         }
-
-        // Initialize `inFullScreenBrowsingMode`, which is always false at this point because Privacy Browser never starts in full screen browsing mode.
-        inFullScreenBrowsingMode = false;
-
-        // Initialize AdView for the free flavor and request an ad.  If this is not the free flavor BannerAd.requestAd() does nothing.
-        adView = findViewById(R.id.adView);
-        BannerAd.requestAd(adView);
     }
 
 
@@ -1236,13 +1235,11 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
                 startActivity(settingsIntent);
                 break;
 
-            /*
             case R.id.domains:
                 // Launch `DomainsList`.
                 Intent domainsIntent = new Intent(this, DomainsList.class);
                 startActivity(domainsIntent);
                 break;
-            */
 
             case R.id.guide:
                 // Launch `Guide`.
@@ -1335,7 +1332,7 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
         super.onConfigurationChanged(newConfig);
 
         // Reload the ad for the free flavor if we are not in full screen mode.
-        if (BuildConfig.FLAVOR.contentEquals("free") && adView.isShown() && !fullScreenVideoFrameLayout.isShown()) {
+        if (BuildConfig.FLAVOR.contentEquals("free") && !inFullScreenBrowsingMode) {
             // Reload the ad.
             BannerAd.reloadAfterRotate(adView, getApplicationContext(), getString(R.string.ad_id));
 
@@ -1950,8 +1947,8 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
             customHeaders.remove("DNT");
         }
 
-        // Update the `SYSTEM_UI` flags if we are in full screen mode.
-        if (inFullScreenBrowsingMode) {
+        // Apply the appropriate full screen mode the `SYSTEM_UI` flags.
+        if (fullScreenBrowsingModeEnabled && inFullScreenBrowsingMode) {
             if (hideSystemBarsOnFullscreen) {  // Hide everything.
                 // Remove the translucent navigation setting if it is currently flagged.
                 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
@@ -1979,6 +1976,33 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
                     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                 }
             }
+        } else {  // Switch to normal viewing mode.
+            // Reset `inFullScreenBrowsingMode` to `false`.
+            inFullScreenBrowsingMode = false;
+
+            // Show the `appBar`.
+            appBar.show();
+
+            // Show the `BannerAd` in the free flavor.
+            if (BuildConfig.FLAVOR.contentEquals("free")) {
+                // Reload the ad.  Because the screen may have rotated, we need to use `reloadAfterRotate`.
+                BannerAd.reloadAfterRotate(adView, getApplicationContext(), getString(R.string.ad_id));
+
+                // Reinitialize the `adView` variable, as the `View` will have been removed and re-added by `BannerAd.reloadAfterRotate()`.
+                adView = findViewById(R.id.adView);
+            }
+
+            // Remove the translucent navigation bar flag if it is set.
+            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+
+            // Add the translucent status flag if it is unset.  This also resets `drawerLayout's` `View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN`.
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+
+            // Remove any `SYSTEM_UI` flags from `rootCoordinatorLayout`.
+            rootCoordinatorLayout.setSystemUiVisibility(0);
+
+            // Constrain `rootCoordinatorLayout` inside the status and navigation bars.
+            rootCoordinatorLayout.setFitsSystemWindows(true);
         }
     }
 
index 0dca2cc884f9ae9797d77ac1af1d10bbd624d52e..5a7d407b05ec02bd7a10dfb652260ab1a05c26c8 100644 (file)
   You should have received a copy of the GNU General Public License
   along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:orientation="vertical"
-              android:layout_width="match_parent"
-              android:layout_height="match_parent">
+<!-- `android:baselineAligned="False"` reduces unneeded computational overhead with `RecyclerViews`. -->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal"
+    android:baselineAligned="false"
+    android:divider="?android:attr/dividerHorizontal"
+    android:showDividers="middle"
+    tools:context=".activities.DomainsList">
 
+    <android.support.v7.widget.RecyclerView
+        android:layout_height="match_parent"
+        android:layout_width="200dp"
+        app:layoutManager="LinearLayoutManager" />
 </LinearLayout>
\ No newline at end of file
index 13d390b3aea2f6f7d948e46f7fd46e43c385d0cf..dbe3190a621a5e4655e6a8815b68d6de614f3882 100644 (file)
@@ -24,7 +24,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:text="@string/navigation"
-    android:paddingTop="60dp"
+    android:paddingTop="35dp"
     android:paddingBottom="8dp"
     android:paddingStart="15dp"
     android:paddingEnd="15dp"
index d33c0e0df3106a813f8157e20270f2b8f4dca8e2..f8ebc9ffd804c14cf8c21238019c78e74946cfe9 100644 (file)
@@ -69,8 +69,6 @@
             android:icon="@drawable/settings"
             android:orderInCategory="70" />
 
-        <!--
-
         <item
             android:id="@+id/domains"
             android:title="@string/domains"
@@ -78,9 +76,9 @@
             android:orderInCategory="80" />
     </group>
 
-    <!- If a group has an id, a line is drawn above it in the navigation view. -
+    <!-- If a group has an id, a line is drawn above it in the navigation view. -->
     <group
-        android:id="@+id/navigationGroup3" > -->
+        android:id="@+id/navigationGroup3" >
         <item
             android:id="@+id/guide"
             android:title="@string/guide"