drawerLayout.visibility = View.GONE
// Initialize the WebView state adapter.
- webViewStateAdapter = WebViewStateAdapter(this)
+ webViewStateAdapter = WebViewStateAdapter(this, bottomAppBar)
// Set the pager adapter on the web view pager.
webViewViewPager2.adapter = webViewStateAdapter
import java.util.LinkedList
-class WebViewStateAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
+class WebViewStateAdapter(fragmentActivity: FragmentActivity, private val bottomAppBar: Boolean) : FragmentStateAdapter(fragmentActivity) {
// Define the class variables.
private val webViewFragmentsList = LinkedList<WebViewTabFragment>()
fun addPage(pagePosition: Int, url: String) {
// Add a new page.
- webViewFragmentsList.add(pagePosition, WebViewTabFragment.createPage(pagePosition, url))
+ webViewFragmentsList.add(pagePosition, WebViewTabFragment.createPage(pagePosition, url, bottomAppBar))
// Update the view pager.
notifyItemInserted(pagePosition)
fun restorePage(savedState: Bundle, savedNestedScrollWebViewState: Bundle) {
// Restore the page.
- webViewFragmentsList.add(WebViewTabFragment.restorePage(savedState, savedNestedScrollWebViewState))
+ webViewFragmentsList.add(WebViewTabFragment.restorePage(savedState, savedNestedScrollWebViewState, bottomAppBar))
// Update the view pager. The position is zero indexed.
notifyItemInserted(webViewFragmentsList.size - 1)
// Define the class constants.
private const val CREATE_NEW_PAGE = "A"
-private const val PAGE_POSITION = "B"
-private const val URL = "C"
-private const val SAVED_STATE = "D"
-private const val SAVED_NESTED_SCROLL_WEBVIEW_STATE = "E"
+private const val BOTTOM_APP_BAR = "B"
+private const val PAGE_POSITION = "C"
+private const val SAVED_NESTED_SCROLL_WEBVIEW_STATE = "D"
+private const val SAVED_STATE = "E"
+private const val URL = "F"
class WebViewTabFragment : Fragment() {
// Define the public variables.
private lateinit var nestedScrollWebView: NestedScrollWebView
companion object {
- fun createPage(pageNumber: Int, url: String?): WebViewTabFragment {
+ fun createPage(pageNumber: Int, url: String?, bottomAppBar: Boolean): WebViewTabFragment {
// Create an arguments bundle.
val argumentsBundle = Bundle()
argumentsBundle.putBoolean(CREATE_NEW_PAGE, true)
argumentsBundle.putInt(PAGE_POSITION, pageNumber)
argumentsBundle.putString(URL, url)
+ argumentsBundle.putBoolean(BOTTOM_APP_BAR, bottomAppBar)
// Create a new instance of the WebView tab fragment.
val webViewTabFragment = WebViewTabFragment()
return webViewTabFragment
}
- fun restorePage(savedState: Bundle, savedNestedScrollWebViewState: Bundle): WebViewTabFragment {
+ fun restorePage(savedState: Bundle, savedNestedScrollWebViewState: Bundle, bottomAppBar: Boolean): WebViewTabFragment {
// Create an arguments bundle
val argumentsBundle = Bundle()
// Store the saved states in the arguments bundle.
argumentsBundle.putBundle(SAVED_STATE, savedState)
argumentsBundle.putBundle(SAVED_NESTED_SCROLL_WEBVIEW_STATE, savedNestedScrollWebViewState)
+ argumentsBundle.putBoolean(BOTTOM_APP_BAR, bottomAppBar)
// Create a new instance of the WebView tab fragment.
val webViewTabFragment = WebViewTabFragment()
}
override fun onCreateView(layoutInflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ // Get the bottom app bar status from the arguments.
+ val bottomAppBar = requireArguments().getBoolean(BOTTOM_APP_BAR)
+
+ // Inflate the tab's WebView according to the app bar position. 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.
+ val newPageView = if (bottomAppBar)
+ layoutInflater.inflate(R.layout.webview_framelayout_bottom_appbar, container, false)
+ else
+ layoutInflater.inflate(R.layout.webview_framelayout_top_appbar, container, false)
+
+ // Get handles for the views.
+ nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview)
+ val progressBar = newPageView.findViewById<ProgressBar>(R.id.progress_bar)
+
+ // Store the WebView fragment ID in the nested scroll WebView.
+ nestedScrollWebView.webViewFragmentId = fragmentId
+
// Check to see if the fragment is being restarted without the app being killed.
return if (savedInstanceState == null) { // The fragment is not being restarted. It is either new or is being restored after the app was killed.
// Check to see if a new page is being created.
val pagePosition = requireArguments().getInt(PAGE_POSITION)
val url = requireArguments().getString(URL)!!
- // 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.
- val newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false)
-
- // Get handles for the views.
- nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview)
- val progressBar = newPageView.findViewById<ProgressBar>(R.id.progress_bar)
-
- // Store the WebView fragment ID in the nested scroll WebView.
- nestedScrollWebView.webViewFragmentId = fragmentId
-
// Request the main activity initialize the WebView.
newTabListener.initializeWebView(nestedScrollWebView, pagePosition, progressBar, url, false)
val savedState = requireArguments().getBundle(SAVED_STATE)!!
val savedNestedScrollWebViewState = requireArguments().getBundle(SAVED_NESTED_SCROLL_WEBVIEW_STATE)!!
- // 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.
- val newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false)
-
- // Get handles for the views.
- nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview)
- val progressBar = newPageView.findViewById<ProgressBar>(R.id.progress_bar)
-
- // Store the WebView fragment ID in the nested scroll WebView.
- nestedScrollWebView.webViewFragmentId = fragmentId
-
// Restore the nested scroll WebView state.
nestedScrollWebView.restoreNestedScrollWebViewState(savedNestedScrollWebViewState)
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
- Copyright © 2019-2020,2022 Soren Stoutner <soren@stoutner.com>.
-
- This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
-
- Privacy Browser Android 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 Android 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 Android. 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" >
-
- <!-- The nested scroll WebView is created with `visibility="invisible"` to prevent a white background splash in night mode because there is a delay in setting the background color.
- It is set visible in `initializeWebView()` or `onProgressChanged()` in `MainWebViewActivity`. -->
- <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:background="?android:attr/colorBackground"
- android:visibility="invisible" />
-
- <!-- `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
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright 2019-2020,2022-2023 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+
+ Privacy Browser Android 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 Android 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 Android. 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"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <!-- The nested scroll WebView is created with `visibility="invisible"` to prevent a white background splash in night mode because there is a delay in setting the background color.
+ It is set visible in `initializeWebView()` or `onProgressChanged()` in `MainWebViewActivity`. -->
+ <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:background="?android:attr/colorBackground"
+ android:visibility="invisible" />
+
+ <!-- `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.-->
+ <ProgressBar
+ android:id="@+id/progress_bar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_height="3dp"
+ android:layout_width="match_parent"
+ android:layout_gravity="bottom"
+ android:max="100"
+ android:progressTint="?attr/progressTintColor"
+ android:progressBackgroundTint="@color/transparent"
+ android:visibility="gone" />
+</FrameLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright 2019-2020,2022-2023 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+
+ Privacy Browser Android 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 Android 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 Android. 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"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <!-- The nested scroll WebView is created with `visibility="invisible"` to prevent a white background splash in night mode because there is a delay in setting the background color.
+ It is set visible in `initializeWebView()` or `onProgressChanged()` in `MainWebViewActivity`. -->
+ <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:background="?android:attr/colorBackground"
+ android:visibility="invisible" />
+
+ <!-- `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.-->
+ <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" />
+</FrameLayout>