]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java
Add the Guide.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / AboutTabFragment.java
1 /**
2  * Copyright 2016 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;
21
22 import android.os.Build;
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 import android.widget.TextView;
30
31 public class AboutTabFragment extends Fragment {
32     private int tabNumber;
33
34     // AboutTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate().
35     public static AboutTabFragment createTab(int tab) {
36         Bundle thisTabArguments = new Bundle();
37         thisTabArguments.putInt("Tab", tab);
38
39         AboutTabFragment thisTab = new AboutTabFragment();
40         thisTab.setArguments(thisTabArguments);
41         return thisTab;
42     }
43
44     @Override
45     public void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47
48         // Store the tab number in tabNumber.
49         tabNumber = getArguments().getInt("Tab");
50     }
51
52     @Override
53     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
54         View tabLayout;
55
56         // Load the about tab layout.  Tab numbers start at 0.
57         if (tabNumber == 0) {
58             // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.
59             // The fragment will take care of attaching the root automatically.
60             tabLayout = inflater.inflate(R.layout.about_tab_version, container, false);
61
62             // Version.
63             TextView versionNumberText = (TextView) tabLayout.findViewById(R.id.about_version_number_text);
64             String version = getString(R.string.version) + " " + BuildConfig.VERSION_NAME + " (" + getString(R.string.version_code) + " " + Integer.toString(BuildConfig.VERSION_CODE) + ")";
65             versionNumberText.setText(version);
66
67             // Brand.
68             TextView versionBrandText = (TextView) tabLayout.findViewById(R.id.about_version_brand_text);
69             versionBrandText.setText(Build.BRAND);
70
71             // Manufacturer.
72             TextView versionManufacturerText = (TextView) tabLayout.findViewById(R.id.about_version_manufacturer_text);
73             versionManufacturerText.setText(Build.MANUFACTURER);
74
75             // Model.
76             TextView versionModelText = (TextView) tabLayout.findViewById(R.id.about_version_model_text);
77             versionModelText.setText(Build.MODEL);
78
79             // Device.
80             TextView versionDeviceText = (TextView) tabLayout.findViewById(R.id.about_version_device_text);
81             versionDeviceText.setText(Build.DEVICE);
82
83             // Bootloader.
84             TextView versionBootloaderText = (TextView) tabLayout.findViewById(R.id.about_version_bootloader_text);
85             versionBootloaderText.setText(Build.BOOTLOADER);
86
87             // Radio.
88             TextView versionRadioText = (TextView) tabLayout.findViewById(R.id.about_version_radio_text);
89             // Hide versionRadioTextView if there is no radio.
90             if (Build.getRadioVersion().equals("")) {
91                 TextView versionRadioTitle = (TextView) tabLayout.findViewById(R.id.about_version_radio_title);
92                 versionRadioTitle.setVisibility(View.GONE);
93                 versionRadioText.setVisibility(View.GONE);
94             } else { // Else, set the text.
95                 versionRadioText.setText(Build.getRadioVersion());
96             }
97
98             // Android.
99             TextView versionAndroidText = (TextView) tabLayout.findViewById(R.id.about_version_android_text);
100             String android = Build.VERSION.RELEASE + " (" + getString(R.string.api) + " " + Integer.toString(Build.VERSION.SDK_INT) + ")";
101             versionAndroidText.setText(android);
102
103             // Build.
104             TextView versionBuildText = (TextView) tabLayout.findViewById(R.id.about_version_build_text);
105             versionBuildText.setText(Build.DISPLAY);
106
107             // Security Patch.
108             TextView versionSecurityPatchText = (TextView) tabLayout.findViewById(R.id.about_version_securitypatch_text);
109             // Build.VERSION.SECURITY_PATCH is only available for SDK_INT >= 23.
110             if (Build.VERSION.SDK_INT >= 23) {
111                 versionSecurityPatchText.setText(Build.VERSION.SECURITY_PATCH);
112             } else { // Hide versionSecurityPatchTextView.
113                 TextView versionSecurityPatchTitle = (TextView) tabLayout.findViewById(R.id.about_version_securitypatch_title);
114                 versionSecurityPatchTitle.setVisibility(View.GONE);
115                 versionSecurityPatchText.setVisibility(View.GONE);
116             }
117
118             // webViewLayout is only used to get the default user agent from about_tab_webview.  It is not used to render content on the screen.
119             View webViewLayout = inflater.inflate(R.layout.about_tab_webview, container, false);
120             WebView tabLayoutWebView = (WebView) webViewLayout.findViewById(R.id.about_tab_webview);
121             String userAgentString =  tabLayoutWebView.getSettings().getUserAgentString();
122
123             // WebKit.
124             TextView versionWebKitText = (TextView) tabLayout.findViewById(R.id.about_version_webkit_text);
125             // Select the substring that begins after "Safari/" and goes to the end of the string.
126             String webkitVersion = userAgentString.substring(userAgentString.indexOf("Safari/") + 7);
127             versionWebKitText.setText(webkitVersion);
128
129             // Chrome.
130             TextView versionChromeText = (TextView) tabLayout.findViewById(R.id.about_version_chrome_text);
131             // Select the substring that begins after "Chrome/" and goes until the next " ".
132             String chromeVersion = userAgentString.substring(userAgentString.indexOf("Chrome/") + 7, userAgentString.indexOf(" ", userAgentString.indexOf("Chrome/")));
133             versionChromeText.setText(chromeVersion);
134         } else { // load a WebView for all the other tabs.  Tab numbers start at 0.
135             // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.
136             // The fragment will take care of attaching the root automatically.
137             tabLayout = inflater.inflate(R.layout.about_tab_webview, container, false);
138             WebView tabWebView = (WebView) tabLayout;
139
140             switch (tabNumber) {
141                 case 1:
142                     tabWebView.loadUrl("file:///android_asset/about_permissions.html");
143                     break;
144
145                 case 2:
146                     tabWebView.loadUrl("file:///android_asset/about_privacy_policy.html");
147                     break;
148
149                 case 3:
150                     tabWebView.loadUrl("file:///android_asset/about_changelog.html");
151                     break;
152
153                 case 4:
154                     tabWebView.loadUrl("file:///android_asset/about_license.html");
155                     break;
156
157                 case 5:
158                     tabWebView.loadUrl("file:///android_asset/about_contributors.html");
159                     break;
160
161                 case 6:
162                     tabWebView.loadUrl("file:///android_asset/about_links.html");
163                     break;
164
165                 default:
166                     break;
167             }
168         }
169
170         return tabLayout;
171     }
172 }