2 * Copyright 2016 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
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.
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.
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/>.
20 package com.stoutner.privacybrowser;
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;
31 public class AboutTabFragment extends Fragment {
32 private int tabNumber;
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);
39 AboutTabFragment thisTab = new AboutTabFragment();
40 thisTab.setArguments(thisTabArguments);
45 public void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
48 // Store the tab number in tabNumber.
49 tabNumber = getArguments().getInt("Tab");
53 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56 // Load the about tab layout. Tab numbers start at 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);
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);
68 TextView versionBrandText = (TextView) tabLayout.findViewById(R.id.about_version_brand_text);
69 versionBrandText.setText(Build.BRAND);
72 TextView versionManufacturerText = (TextView) tabLayout.findViewById(R.id.about_version_manufacturer_text);
73 versionManufacturerText.setText(Build.MANUFACTURER);
76 TextView versionModelText = (TextView) tabLayout.findViewById(R.id.about_version_model_text);
77 versionModelText.setText(Build.MODEL);
80 TextView versionDeviceText = (TextView) tabLayout.findViewById(R.id.about_version_device_text);
81 versionDeviceText.setText(Build.DEVICE);
84 TextView versionBootloaderText = (TextView) tabLayout.findViewById(R.id.about_version_bootloader_text);
85 versionBootloaderText.setText(Build.BOOTLOADER);
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());
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);
104 TextView versionBuildText = (TextView) tabLayout.findViewById(R.id.about_version_build_text);
105 versionBuildText.setText(Build.DISPLAY);
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);
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();
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);
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;
142 tabWebView.loadUrl("file:///android_asset/about_permissions.html");
146 tabWebView.loadUrl("file:///android_asset/about_privacy_policy.html");
150 tabWebView.loadUrl("file:///android_asset/about_changelog.html");
154 tabWebView.loadUrl("file:///android_asset/about_license.html");
158 tabWebView.loadUrl("file:///android_asset/about_contributors.html");
162 tabWebView.loadUrl("file:///android_asset/about_links.html");