]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Create separate progress bars for each tab.
authorSoren Stoutner <soren@stoutner.com>
Wed, 20 Mar 2019 21:12:46 +0000 (14:12 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 20 Mar 2019 21:12:46 +0000 (14:12 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java
app/src/main/res/layout/main_framelayout.xml
app/src/main/res/layout/nestedscroll_webview.xml [deleted file]
app/src/main/res/layout/webview_framelayout.xml [new file with mode: 0644]
app/src/main/res/values-v21/styles.xml
app/src/main/res/values/attrs.xml
app/src/main/res/values/styles.xml

index a174230d851af1cd9444184b5769d182a51f81ca..1ec5a020037e08504db735b8d43fc6ecd1c00184 100644 (file)
@@ -707,8 +707,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 // Get the current WebView fragment.  Instantiate item returns the current item if it already exists.
                 Fragment webViewFragment = (Fragment) webViewPagerAdapter.instantiateItem(webViewPager, position);
 
+                // Remove the lint error below that the WebView fragment might be null.
+                assert webViewFragment.getView() != null;
+
                 // Store the current WebView.
-                currentWebView = (NestedScrollWebView) webViewFragment.getView();
+                currentWebView = webViewFragment.getView().findViewById(R.id.nestedscroll_webview);
 
                 // Select the corresponding tab if it does not match the currently selected page.  This will happen if the page was scrolled via swiping in the view pager.
                 if (tabLayout.getSelectedTabPosition() != position) {
@@ -835,10 +838,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
         // Set the swipe to refresh color according to the theme.
         if (darkTheme) {
-            swipeRefreshLayout.setColorSchemeResources(R.color.blue_600);
+            swipeRefreshLayout.setColorSchemeResources(R.color.blue_800);
             swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_850);
         } else {
-            swipeRefreshLayout.setColorSchemeResources(R.color.blue_700);
+            swipeRefreshLayout.setColorSchemeResources(R.color.blue_500);
         }
 
         // `DrawerTitle` identifies the `DrawerLayouts` in accessibility mode.
@@ -4444,7 +4447,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     }
 
     @Override
-    public void initializeWebView(NestedScrollWebView nestedScrollWebView, int tabNumber) {
+    public void initializeWebView(int tabNumber, ProgressBar progressBar, NestedScrollWebView nestedScrollWebView) {
         // Get handles for the activity views.
         final FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout);
         final DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
@@ -4487,10 +4490,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         ImageView tabFavoriteIconImageView = currentTabView.findViewById(R.id.favorite_icon_imageview);
         TextView tabTitleTextView = currentTabView.findViewById(R.id.title_textview);
 
-
-        //TODO
-        final ProgressBar progressBar = findViewById(R.id.progress_bar);
-
         // Get a handle for the shared preferences.
         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
 
index 8ad76d7cbed9eb854614efd7775df19c9adeda17..ce7e1a43eb924a1f78bca6bbdd25f3e35d5e26f6 100644 (file)
@@ -24,6 +24,7 @@ import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ProgressBar;
 
 import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
@@ -34,7 +35,7 @@ import com.stoutner.privacybrowser.views.NestedScrollWebView;
 public class WebViewTabFragment extends Fragment {
     // The public interface is used to send information back to the parent activity.
     public interface NewTabListener {
-        void initializeWebView(NestedScrollWebView nestedScrollWebView, int tabNumber);
+        void initializeWebView(int tabNumber, ProgressBar progressBar, NestedScrollWebView nestedScrollWebView);
     }
 
     // The new tab listener is used in `onAttach()` and `onCreateView()`.
@@ -78,13 +79,14 @@ public class WebViewTabFragment extends Fragment {
         int tabNumber = arguments.getInt("tab_number");
 
         // Inflate the tab's WebView.  Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
-        View tabView = layoutInflater.inflate(R.layout.nestedscroll_webview, container, false);
+        View tabView = layoutInflater.inflate(R.layout.webview_framelayout, container, false);
 
         // Get a handle for the nested scroll WebView.
         NestedScrollWebView nestedScrollWebView = tabView.findViewById(R.id.nestedscroll_webview);
+        ProgressBar progressBar = tabView.findViewById(R.id.progress_bar);
 
         // Request the main activity initialize the WebView.
-        newTabListener.initializeWebView(nestedScrollWebView, tabNumber);
+        newTabListener.initializeWebView(tabNumber, progressBar, nestedScrollWebView);
 
         // Return the tab view.
         return tabView;
index b04c6bc86641f9de7c42d567a3a1c404a0cac63c..070eb559e53700fb724658c8f62ccf46fe74fd8f 100644 (file)
@@ -86,7 +86,7 @@
                                 android:paddingStart="15dp"
                                 android:paddingEnd="15dp"
                                 android:src="@drawable/add_light"
-                                android:tint="@color/gray_700"
+                                android:tint="?attr/addTabIconTintColor"
                                 android:onClick="addTab"
                                 android:contentDescription="@string/add_tab" />
                         </LinearLayout>
                     android:layout_height="match_parent"
                     app:layout_behavior="@string/appbar_scrolling_view_behavior" >
 
-                    <!-- The frame layout allows the progress bar to float above the WebView. -->
-                    <FrameLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent">
-
                         <androidx.viewpager.widget.ViewPager
                             android:id="@+id/webviewpager"
                             android:layout_width="match_parent"
                             android:layout_height="match_parent" />
-
-                        <!-- `android:max` changes the maximum `ProgressBar` value from 10000 to 100 to match progress percentage.
-                            `android:layout_height="2dp"` works best for API >= 23, but `3dp` is required for visibility on API <= 22.
-                            `tools:ignore="UnusedAttribute"` removes the lint warning about `progressTint` and `progressBackgroundTint` not applying to API < 21. -->
-                        <ProgressBar
-                            android:id="@+id/progress_bar"
-                            style="?android:attr/progressBarStyleHorizontal"
-                            android:layout_height="3dp"
-                            android:layout_width="match_parent"
-                            android:max="100"
-                            android:progressTint="?attr/progressTintColor"
-                            android:progressBackgroundTint="@color/transparent"
-                            android:visibility="gone"
-                            tools:ignore="UnusedAttribute" />
-                    </FrameLayout>
                 </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
             </androidx.coordinatorlayout.widget.CoordinatorLayout>
         </RelativeLayout>
diff --git a/app/src/main/res/layout/nestedscroll_webview.xml b/app/src/main/res/layout/nestedscroll_webview.xml
deleted file mode 100644 (file)
index 3ece03d..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  Copyright © 2019 Soren Stoutner <soren@stoutner.com>.
-
-  This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>>.
-
-  Privacy Browser is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  Privacy Browser is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
-
-<com.stoutner.privacybrowser.views.NestedScrollWebView
-    android:id="@+id/nestedscroll_webview"
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_height="match_parent"
-    android:layout_width="match_parent"
-    android:focusable="true"
-    android:focusableInTouchMode="true" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/webview_framelayout.xml b/app/src/main/res/layout/webview_framelayout.xml
new file mode 100644 (file)
index 0000000..27e6277
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright © 2019 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>>.
+
+  Privacy Browser is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Privacy Browser is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
+
+<!-- The frame layout allows the progress bar to float above the WebView. -->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <com.stoutner.privacybrowser.views.NestedScrollWebView
+        android:id="@+id/nestedscroll_webview"
+        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:focusable="true"
+        android:focusableInTouchMode="true" />
+
+    <!-- `android:max` changes the maximum `ProgressBar` value from 10000 to 100 to match progress percentage.
+        `android:layout_height="2dp"` works best for API >= 23, but `3dp` is required for visibility on API <= 22.
+        `tools:ignore="UnusedAttribute"` removes the lint warning about `progressTint` and `progressBackgroundTint` not applying to API < 21. -->
+    <ProgressBar
+        android:id="@+id/progress_bar"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_height="3dp"
+        android:layout_width="match_parent"
+        android:max="100"
+        android:progressTint="?attr/progressTintColor"
+        android:progressBackgroundTint="@color/transparent"
+        android:visibility="gone"
+        tools:ignore="UnusedAttribute" />
+</FrameLayout>
\ No newline at end of file
index a22b10c348609923db2f1a80d7ce6f2a82c71b02..d884248c673897bd69aab6999ffcff1d79063369 100644 (file)
     <!-- `android:windowTranslucentStatus` makes the system status bar translucent.  When it is specified the root layout should include `android:fitsSystemWindows="true"`. -->
     <style name="PrivacyBrowserLight" parent="Theme.AppCompat.Light.NoActionBar" >
         <item name="android:windowTranslucentStatus">true</item>
-        <item name="mainStatusBarBackground">@color/gray_500</item>
+        <item name="addTabIconTintColor">@color/gray_700</item>
         <item name="android:textColorPrimary">@color/primary_text_color_selector_light</item>
         <item name="colorAccent">@color/blue_700</item>
         <item name="android:textColorHighlight">@color/blue_200</item>
+        <item name="mainStatusBarBackground">@color/gray_500</item>
         <item name="navigationHeaderBackground">@color/blue_700</item>
         <item name="navigationHeaderTextColor">@color/white</item>
         <item name="appBarTheme">@style/PrivacyBrowserAppBarLight</item>
-        <item name="progressTintColor">@color/blue_700</item>
+        <item name="progressTintColor">@color/blue_500</item>
         <item name="navigationIconTintColor">@color/blue_800</item>
         <item name="findOnPageIconTintColor">@color/blue_800</item>
         <item name="viewSourceIconTintColor">@color/black</item>
     <!-- `android:windowTranslucentStatus` makes the system status bar translucent.  When it is specified the root layout should include `android:fitsSystemWindows="true"`. -->
     <style name="PrivacyBrowserDark" parent="Theme.AppCompat.NoActionBar" >
         <item name="android:windowTranslucentStatus">true</item>
-        <item name="mainStatusBarBackground">@color/black</item>
+        <item name="addTabIconTintColor">@color/gray_400</item>
         <item name="android:textColorPrimary">@color/primary_text_color_selector_dark</item>
         <item name="colorAccent">@color/blue_600</item>
         <item name="android:textColorHighlight">@color/blue_800</item>
+        <item name="mainStatusBarBackground">@color/black</item>
         <item name="navigationHeaderBackground">@color/blue_800</item>
         <item name="navigationHeaderTextColor">@color/gray_300</item>
         <item name="appBarTheme">@style/PrivacyBrowserAppBarDark</item>
-        <item name="progressTintColor">@color/blue_600</item>
+        <item name="progressTintColor">@color/blue_800</item>
         <item name="navigationIconTintColor">@color/blue_600</item>
         <item name="findOnPageIconTintColor">@color/blue_600</item>
         <item name="viewSourceIconTintColor">@color/gray_300</item>
index c673ba65fc6e5391fd8a7afab10000265135cdd1..c933225ea9430b4512871e813d66cd7f4644757a 100644 (file)
     <attr name="navigationHeaderBackground" format="reference" />
     <attr name="navigationHeaderTextColor" format="reference" />
 
-    <attr name="progressTintColor" format="reference" />
-    <attr name="navigationIconTintColor" format="reference" />
-    <attr name="findOnPageIconTintColor" format="reference" />
+    <attr name="addTabIconTintColor" format="reference" />
     <attr name="domainSettingsIconTintColor" format="reference" />
+    <attr name="findOnPageIconTintColor" format="reference" />
+    <attr name="navigationIconTintColor" format="reference" />
+    <attr name="progressTintColor" format="reference" />
     <attr name="viewSourceIconTintColor" format="reference" />
 
     <attr name="listSelectorDrawable" format="reference" />
index 40c8ba4756bdedcef90a6e5374157a7bba54d84d..1615f1278308428f9d5f5d4df111fe7d1f1a7b4f 100644 (file)
     <!-- `android:windowTranslucentStatus` makes the system status bar translucent.  When it is specified the root layout should include `android:fitsSystemWindows="true"`. -->
     <style name="PrivacyBrowserLight" parent="Theme.AppCompat.Light.NoActionBar" >
         <item name="android:windowTranslucentStatus">true</item>
-        <item name="mainStatusBarBackground">@color/gray_500</item>
+        <item name="addTabIconTintColor">@color/gray_700</item>
         <item name="android:textColorPrimary">@color/primary_text_color_selector_light</item>
         <item name="colorAccent">@color/blue_700</item>
         <item name="android:textColorHighlight">@color/blue_200</item>
+        <item name="mainStatusBarBackground">@color/gray_500</item>
         <item name="navigationHeaderBackground">@color/blue_700</item>
         <item name="navigationHeaderTextColor">@color/white</item>
         <item name="appBarTheme">@style/PrivacyBrowserAppBarLight</item>
-        <item name="progressTintColor">@color/blue_700</item>
+        <item name="progressTintColor">@color/blue_500</item>
         <item name="navigationIconTintColor">@color/blue_800</item>
         <item name="findOnPageIconTintColor">@color/blue_800</item>
         <item name="viewSourceIconTintColor">@color/black</item>
     <!-- `android:windowTranslucentStatus` makes the system status bar translucent.  When it is specified the root layout should include `android:fitsSystemWindows="true"`. -->
     <style name="PrivacyBrowserDark" parent="Theme.AppCompat.NoActionBar" >
         <item name="android:windowTranslucentStatus">true</item>
-        <item name="mainStatusBarBackground">@color/black</item>
+        <item name="addTabIconTintColor">@color/gray_400</item>
         <item name="android:textColorPrimary">@color/primary_text_color_selector_dark</item>
         <item name="colorAccent">@color/blue_600</item>
         <item name="android:textColorHighlight">@color/blue_800</item>
+        <item name="mainStatusBarBackground">@color/black</item>
         <item name="navigationHeaderBackground">@color/blue_800</item>
         <item name="navigationHeaderTextColor">@color/gray_300</item>
         <item name="appBarTheme">@style/PrivacyBrowserAppBarDark</item>
-        <item name="progressTintColor">@color/blue_600</item>
+        <item name="progressTintColor">@color/blue_800</item>
         <item name="navigationIconTintColor">@color/blue_600</item>
         <item name="findOnPageIconTintColor">@color/blue_600</item>
         <item name="viewSourceIconTintColor">@color/gray_300</item>