Finish creating the bookmark drawer. https://redmine.stoutner.com/issues/132
[PrivacyBrowser.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     // Store the tab number in the arguments bundle.
38     public static GuideTabFragment createTab (int tab) {
39         // Create a bundle.
40         Bundle bundle = new Bundle();
41
42         // Store the tab number in the bundle.
43         bundle.putInt("Tab", tab);
44
45         // Add the bundle to the fragment.
46         GuideTabFragment guideTabFragment = new GuideTabFragment();
47         guideTabFragment.setArguments(bundle);
48
49         // Return the new fragment.
50         return guideTabFragment;
51     }
52
53     @Override
54     public void onCreate(Bundle savedInstanceState) {
55         // Run the default commands.
56         super.onCreate(savedInstanceState);
57
58         // Store the tab number in a class variable.
59         tabNumber = getArguments().getInt("Tab");
60     }
61
62     @SuppressLint("SetJavaScriptEnabled")
63     @Override
64     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
65         // 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.
66         View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
67
68         // Get a handle for `tabWebView`.
69         WebView tabWebView = (WebView) tabLayout;
70
71         // Load the tabs according to the theme.
72         if (MainWebViewActivity.darkTheme) {  // The dark theme is applied.
73             // Set the background color.  We have to use the deprecated `.getColor()` until API >= 23.
74             //noinspection deprecation
75             tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
76
77             // Tab numbers start at 0.
78             switch (tabNumber) {
79                 case 0:
80                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_dark.html");
81                     break;
82
83                 case 1:
84                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_dark.html");
85                     break;
86
87                 case 2:
88                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_dark.html");
89                     break;
90
91                 case 3:
92                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_dark.html");
93                     break;
94
95                 case 4:
96                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html");
97                     break;
98
99                 case 5:
100                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html");
101                     break;
102
103                 case 6:
104                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html");
105                     break;
106
107                 case 7:
108                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html");
109                     break;
110             }
111         } else {  // The light theme is applied.
112             // Tab numbers start at 0.
113             switch (tabNumber) {
114                 case 0:
115                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_light.html");
116                     break;
117
118                 case 1:
119                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_light.html");
120                     break;
121
122                 case 2:
123                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_light.html");
124                     break;
125
126                 case 3:
127                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_light.html");
128                     break;
129
130                 case 4:
131                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html");
132                     break;
133
134                 case 5:
135                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html");
136                     break;
137
138                 case 6:
139                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html");
140                     break;
141
142                 case 7:
143                     tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html");
144                     break;
145             }
146         }
147
148         // Return the formatted `tabLayout`.
149         return tabLayout;
150     }
151 }