X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FAboutTabFragment.java;h=8c48825469861e614119463028bda7c1ed602195;hb=f0393ca22075be3e5fe9199c7db87381256236fa;hp=9f627b6c0e42d946a086034075626953f413a2bb;hpb=ba632a37a66aad3feeac8fcf12afdbe38032049d;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java index 9f627b6c..8c488254 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2018 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -21,12 +21,12 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.Signature; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; +import android.preference.PreferenceManager; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; @@ -36,6 +36,9 @@ import android.view.ViewGroup; import android.webkit.WebView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + import com.stoutner.privacybrowser.BuildConfig; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.MainWebViewActivity; @@ -51,6 +54,7 @@ import java.text.DateFormat; import java.util.Date; public class AboutTabFragment extends Fragment { + // Track the current tab number. private int tabNumber; // Store the tab number in the arguments bundle. @@ -82,7 +86,7 @@ public class AboutTabFragment extends Fragment { } @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) { // Create a tab layout view. View tabLayout; @@ -90,10 +94,16 @@ public class AboutTabFragment extends Fragment { Context context = getContext(); assert context != null; + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + + // Get the theme preference. + boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + // Load the tabs. Tab numbers start at 0. if (tabNumber == 0) { // Load the about tab. // 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. - tabLayout = inflater.inflate(R.layout.about_tab_version, container, false); + tabLayout = layoutInflater.inflate(R.layout.about_tab_version, container, false); // Get handles for the `TextViews`. TextView versionTextView = tabLayout.findViewById(R.id.version); @@ -146,7 +156,7 @@ public class AboutTabFragment extends Fragment { String signatureAlgorithmLabel = getString(R.string.signature_algorithm) + " "; // `webViewLayout` is only used to get the default user agent from `bare_webview`. It is not used to render content on the screen. - View webViewLayout = inflater.inflate(R.layout.bare_webview, container, false); + View webViewLayout = layoutInflater.inflate(R.layout.bare_webview, container, false); WebView tabLayoutWebView = webViewLayout.findViewById(R.id.bare_webview); String userAgentString = tabLayoutWebView.getSettings().getUserAgentString(); @@ -199,7 +209,7 @@ public class AboutTabFragment extends Fragment { ForegroundColorSpan blueColorSpan; // Set `blueColorSpan` according to the theme. We have to use the deprecated `getColor()` until API >= 23. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { //noinspection deprecation blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400)); } else { @@ -249,7 +259,7 @@ public class AboutTabFragment extends Fragment { securityPatchTextView.setVisibility(View.GONE); } - // Only populate the radio TextView if there is a radio in the device. + // Only populate the radio text view if there is a radio in the device. if (!radio.isEmpty()) { String radioLabel = getString(R.string.radio) + " "; SpannableStringBuilder radioStringBuilder = new SpannableStringBuilder(radioLabel + radio); @@ -259,7 +269,7 @@ public class AboutTabFragment extends Fragment { radioTextView.setVisibility(View.GONE); } - // Only populate the Orbot TextView if it is installed. + // Only populate the Orbot text view if it is installed. if (!orbot.isEmpty()) { String orbotLabel = getString(R.string.orbot) + " "; SpannableStringBuilder orbotStringBuilder = new SpannableStringBuilder(orbotLabel + orbot); @@ -269,11 +279,11 @@ public class AboutTabFragment extends Fragment { orbotTextView.setVisibility(View.GONE); } - // Only populate the EasyKeychain TextView if it is installed. + // Only populate the OpenKeychain text view if it is installed. if (!openKeychain.isEmpty()) { - String openKeychainlabel = getString(R.string.open_keychain) + " "; - SpannableStringBuilder openKeychainStringBuilder = new SpannableStringBuilder(openKeychainlabel + openKeychain); - openKeychainStringBuilder.setSpan(blueColorSpan, openKeychainlabel.length(), openKeychainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + String openKeychainLabel = getString(R.string.openkeychain) + " "; + SpannableStringBuilder openKeychainStringBuilder = new SpannableStringBuilder(openKeychainLabel + openKeychain); + openKeychainStringBuilder.setSpan(blueColorSpan, openKeychainLabel.length(), openKeychainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); openKeychainTextView.setText(openKeychainStringBuilder); } else { //OpenKeychain is not installed. openKeychainTextView.setVisibility(View.GONE); @@ -338,14 +348,14 @@ public class AboutTabFragment extends Fragment { } } else { // load a `WebView` for all the other tabs. Tab numbers start at 0. // 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. - tabLayout = inflater.inflate(R.layout.bare_webview, container, false); + tabLayout = layoutInflater.inflate(R.layout.bare_webview, container, false); // Get a handle for `tabWebView`. WebView tabWebView = (WebView) tabLayout; // Load the tabs according to the theme. - if (MainWebViewActivity.darkTheme) { // The dark theme is applied. - // Set the background color. We have to use the deprecated `.getColor()` until API >= 23. + if (darkTheme) { // The dark theme is applied. + // Set the background color. The deprecated `.getColor()` must be used until the minimum API >= 23. //noinspection deprecation tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));