]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTabFragment.java
9e5f568d0d2d0af4ecf1c0c1a94efc96d55bb579
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / GuideTabFragment.java
1 /*
2  * Copyright © 2016-2017 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.os.Bundle;
24 import android.support.v4.app.Fragment;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.webkit.WebView;
29
30 import com.stoutner.privacybrowser.R;
31 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
32
33 public class GuideTabFragment extends Fragment {
34     // `tabNumber` is used in `onCreate()` and `onCreateView()`.
35     private int tabNumber;
36
37     // GuideTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate().
38     public static GuideTabFragment createTab (int tab) {
39         Bundle thisTabArguments = new Bundle();
40         thisTabArguments.putInt("Tab", tab);
41
42         GuideTabFragment thisTab = new GuideTabFragment();
43         thisTab.setArguments(thisTabArguments);
44         return thisTab;
45     }
46
47     @Override
48     public void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50
51         // Store the tab number in `tabNumber`.
52         tabNumber = getArguments().getInt("Tab");
53     }
54
55     @SuppressLint("SetJavaScriptEnabled")
56     @Override
57     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
58         // 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.
59         View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
60
61         // Get a handle for `tabWebView`.
62         WebView tabWebView = (WebView) tabLayout;
63
64         // Load the tabs according to the theme.
65         if (MainWebViewActivity.darkTheme) {  // The dark theme is applied.
66             // Set the background color.  We have to use the deprecated `.getColor()` until API >= 23.
67             //noinspection deprecation
68             tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
69
70             // Tab numbers start at 0.
71             switch (tabNumber) {
72                 case 0:
73                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_dark.html");
74                     break;
75
76                 case 1:
77                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_dark.html");
78                     break;
79
80                 case 2:
81                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_dark.html");
82                     break;
83
84                 case 3:
85                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_dark.html");
86                     break;
87
88                 case 4:
89                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html");
90                     break;
91
92                 case 5:
93                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html");
94                     break;
95
96                 case 6:
97                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html");
98                     break;
99
100                 case 7:
101                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html");
102                     break;
103             }
104         } else {  // The light theme is applied.
105             // Tab numbers start at 0.
106             switch (tabNumber) {
107                 case 0:
108                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_light.html");
109                     break;
110
111                 case 1:
112                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_light.html");
113                     break;
114
115                 case 2:
116                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_light.html");
117                     break;
118
119                 case 3:
120                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_light.html");
121                     break;
122
123                 case 4:
124                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html");
125                     break;
126
127                 case 5:
128                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html");
129                     break;
130
131                 case 6:
132                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html");
133                     break;
134
135                 case 7:
136                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html");
137                     break;
138             }
139         }
140
141         // Return the formatted `tabLayout`.
142         return tabLayout;
143     }
144 }