Add the Sec-Fetch headers to View Source. https://redmine.stoutner.com/issues/503
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / GuideTabFragment.java
1 /*
2  * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacybrowser.fragments;
21
22 import android.annotation.SuppressLint;
23 import android.content.SharedPreferences;
24 import android.os.Bundle;
25 import android.preference.PreferenceManager;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.webkit.WebView;
30
31 import androidx.annotation.NonNull;
32 import androidx.fragment.app.Fragment;
33
34 import com.stoutner.privacybrowser.R;
35
36 public class GuideTabFragment extends Fragment {
37     // `tabNumber` is used in `onCreate()` and `onCreateView()`.
38     private int tabNumber;
39
40     // Store the tab number in the arguments bundle.
41     public static GuideTabFragment createTab (int tab) {
42         // Create a bundle.
43         Bundle bundle = new Bundle();
44
45         // Store the tab number in the bundle.
46         bundle.putInt("Tab", tab);
47
48         // Add the bundle to the fragment.
49         GuideTabFragment guideTabFragment = new GuideTabFragment();
50         guideTabFragment.setArguments(bundle);
51
52         // Return the new fragment.
53         return guideTabFragment;
54     }
55
56     @Override
57     public void onCreate(Bundle savedInstanceState) {
58         // Run the default commands.
59         super.onCreate(savedInstanceState);
60
61         // Remove the lint warning that `getArguments()` might be null.
62         assert getArguments() != null;
63
64         // Store the tab number in a class variable.
65         tabNumber = getArguments().getInt("Tab");
66     }
67
68     @SuppressLint("SetJavaScriptEnabled")
69     @Override
70     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
71         // Get a handle for the shared preferences.
72         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
73
74         // Get the theme preference.
75         boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
76
77         // 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.
78         View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
79
80         // Get a handle for `tabWebView`.
81         WebView tabWebView = (WebView) tabLayout;
82
83         // Load the tabs according to the theme.
84         if (darkTheme) {  // The dark theme is applied.
85             // Set the background color.  The deprecated `.getColor()` must be used until API >= 23.
86             //noinspection deprecation
87             tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
88
89             // Tab numbers start at 0.
90             switch (tabNumber) {
91                 case 0:
92                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_dark.html");
93                     break;
94
95                 case 1:
96                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_dark.html");
97                     break;
98
99                 case 2:
100                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_dark.html");
101                     break;
102
103                 case 3:
104                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_dark.html");
105                     break;
106
107                 case 4:
108                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_dark.html");
109                     break;
110
111                 case 5:
112                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html");
113                     break;
114
115                 case 6:
116                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html");
117                     break;
118
119                 case 7:
120                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html");
121                     break;
122
123                 case 8:
124                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html");
125                     break;
126
127                 case 9:
128                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_dark.html");
129                     break;
130             }
131         } else {  // The light theme is applied.
132             // Tab numbers start at 0.
133             switch (tabNumber) {
134                 case 0:
135                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_light.html");
136                     break;
137
138                 case 1:
139                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_light.html");
140                     break;
141
142                 case 2:
143                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_light.html");
144                     break;
145
146                 case 3:
147                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_light.html");
148                     break;
149
150                 case 4:
151                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_light.html");
152                     break;
153
154                 case 5:
155                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html");
156                     break;
157
158                 case 6:
159                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html");
160                     break;
161
162                 case 7:
163                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html");
164                     break;
165
166                 case 8:
167                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html");
168                     break;
169
170                 case 9:
171                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_light.html");
172             }
173         }
174
175         // Return the formatted `tabLayout`.
176         return tabLayout;
177     }
178 }