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);
38 AboutTabFragment thisTab = new AboutTabFragment();
39 thisTab.setArguments(thisTabArguments);
44 public void onCreate (Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
47 // Store the tab number in tabNumber.
48 tabNumber = getArguments().getInt("Tab");
52 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55 // Load the about tab layout. Tab numbers start at 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);
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);
67 TextView versionBrandText = (TextView) tabLayout.findViewById(R.id.about_version_brand_text);
68 versionBrandText.setText(Build.BRAND);
71 TextView versionManufacturerText = (TextView) tabLayout.findViewById(R.id.about_version_manufacturer_text);
72 versionManufacturerText.setText(Build.MANUFACTURER);
75 TextView versionModelText = (TextView) tabLayout.findViewById(R.id.about_version_model_text);
76 versionModelText.setText(Build.MODEL);
79 TextView versionDeviceText = (TextView) tabLayout.findViewById(R.id.about_version_device_text);
80 versionDeviceText.setText(Build.DEVICE);
83 TextView versionBootloaderText = (TextView) tabLayout.findViewById(R.id.about_version_bootloader_text);
84 versionBootloaderText.setText(Build.BOOTLOADER);
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());
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);
103 TextView versionBuildText = (TextView) tabLayout.findViewById(R.id.about_version_build_text);
104 versionBuildText.setText(Build.DISPLAY);
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);
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();
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);
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;
141 tabWebView.loadUrl("file:///android_asset/about_permissions.html");
145 tabWebView.loadUrl("file:///android_asset/about_privacy_policy.html");
149 tabWebView.loadUrl("file:///android_asset/about_changelog.html");
153 tabWebView.loadUrl("file:///android_asset/about_license.html");
157 tabWebView.loadUrl("file:///android_asset/about_contributors.html");