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