2 * Copyright © 2016-2018 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.fragments;
22 import android.annotation.SuppressLint;
23 import android.os.Bundle;
24 import android.support.annotation.NonNull;
25 import android.support.v4.app.Fragment;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.webkit.WebView;
31 import com.stoutner.privacybrowser.R;
32 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
34 public class GuideTabFragment extends Fragment {
35 // `tabNumber` is used in `onCreate()` and `onCreateView()`.
36 private int tabNumber;
38 // Store the tab number in the arguments bundle.
39 public static GuideTabFragment createTab (int tab) {
41 Bundle bundle = new Bundle();
43 // Store the tab number in the bundle.
44 bundle.putInt("Tab", tab);
46 // Add the bundle to the fragment.
47 GuideTabFragment guideTabFragment = new GuideTabFragment();
48 guideTabFragment.setArguments(bundle);
50 // Return the new fragment.
51 return guideTabFragment;
55 public void onCreate(Bundle savedInstanceState) {
56 // Run the default commands.
57 super.onCreate(savedInstanceState);
59 // Remove the lint warning that `getArguments()` might be null.
60 assert getArguments() != null;
62 // Store the tab number in a class variable.
63 tabNumber = getArguments().getInt("Tab");
66 @SuppressLint("SetJavaScriptEnabled")
68 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
69 // 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.
70 View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
72 // Get a handle for `tabWebView`.
73 WebView tabWebView = (WebView) tabLayout;
75 // Load the tabs according to the theme.
76 if (MainWebViewActivity.darkTheme) { // The dark theme is applied.
77 // Set the background color. The deprecated `.getColor()` must be used until API >= 23.
78 //noinspection deprecation
79 tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
81 // Tab numbers start at 0.
84 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_dark.html");
88 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_dark.html");
92 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_dark.html");
96 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_dark.html");
100 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_dark.html");
104 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html");
108 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html");
112 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html");
116 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html");
120 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_dark.html");
123 } else { // The light theme is applied.
124 // Tab numbers start at 0.
127 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_light.html");
131 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_light.html");
135 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_light.html");
139 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_light.html");
143 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_light.html");
147 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html");
151 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html");
155 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html");
159 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html");
163 tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_light.html");
167 // Return the formatted `tabLayout`.