+ @Override
+ public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
+ // Check to see if the fragment is being restarted.
+ if (savedInstanceState == null) { // The fragment is not being restarted. Load and configure a new fragment.
+ // Get the arguments.
+ Bundle arguments = getArguments();
+
+ // Remove the incorrect lint warning that the arguments might be null.
+ assert arguments != null;
+
+ // Check to see if a new page is being created.
+ if (arguments.getBoolean(CREATE_NEW_PAGE)) { // A new page is being created.
+ // Get the variables from the arguments
+ int pageNumber = arguments.getInt(PAGE_NUMBER);
+ String url = arguments.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.
+ View newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false);
+
+ // Get handles for the views.
+ nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview);
+ ProgressBar progressBar = newPageView.findViewById(R.id.progress_bar);
+
+ // Store the WebView fragment ID in the nested scroll WebView.
+ nestedScrollWebView.setWebViewFragmentId(fragmentId);
+
+ // Request the main activity initialize the WebView.
+ newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar, url, false);
+
+ // Return the new page view.
+ return newPageView;
+ } else { // A page is being restored.
+ // Get the saved states from the arguments.
+ Bundle savedState = arguments.getBundle(SAVED_STATE);
+ Bundle savedNestedScrollWebViewState = arguments.getBundle(SAVED_NESTED_SCROLL_WEBVIEW_STATE);
+
+ // Remove the incorrect lint warning below that the saved nested scroll WebView state might be null.
+ assert savedNestedScrollWebViewState != null;
+
+ // 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 newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false);
+
+ // Get handles for the views.
+ nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview);
+ ProgressBar progressBar = newPageView.findViewById(R.id.progress_bar);
+
+ // Store the WebView fragment ID in the nested scroll WebView.
+ nestedScrollWebView.setWebViewFragmentId(fragmentId);
+
+ // Restore the nested scroll WebView state.
+ nestedScrollWebView.restoreNestedScrollWebViewState(savedNestedScrollWebViewState);
+
+ // Restore the WebView state.
+ nestedScrollWebView.restoreState(savedState);
+
+ // Initialize the WebView.
+ newTabListener.initializeWebView(nestedScrollWebView, 0, progressBar, null, true);
+
+ // Return the new page view.
+ return newPageView;
+ }
+ } else { // The fragment is being restarted.
+ // Return null. Otherwise, the fragment will be inflated and initialized by the OS on a restart, discarded, and then recreated with saved settings by Privacy Browser.
+ return null;
+ }