X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FDomainSettingsFragment.java;h=71d6f484be3cd94ff0e3a359c80b4099933b8965;hp=e26853c856e63ea162e87c22e8958c14c56417f6;hb=8142ac5fc2489de735de4b6fa21a1eae733ccfce;hpb=484f0b0f0143c53a4722cee3a31e714df0c8c49a diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java index e26853c8..71d6f484 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -1,20 +1,20 @@ /* - * Copyright © 2017-2021 Soren Stoutner . + * Copyright © 2017-2022 Soren Stoutner . * - * This file is part of Privacy Browser . + * This file is part of Privacy Browser Android . * - * Privacy Browser is free software: you can redistribute it and/or modify + * Privacy Browser Android is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Privacy Browser is distributed in the hope that it will be useful, + * Privacy Browser Android is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . + * along with Privacy Browser Android. If not, see . */ package com.stoutner.privacybrowser.fragments; @@ -303,13 +303,13 @@ public class DomainSettingsFragment extends Fragment { final ForegroundColorSpan blueColorSpan; final ForegroundColorSpan redColorSpan; - // Set the color spans according to the theme. The deprecated `getColor()` must be used until the minimum API >= 23. + // Set the color spans according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.blue_700)); - redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_a700)); + blueColorSpan = new ForegroundColorSpan(context.getColor(R.color.blue_700)); + redColorSpan = new ForegroundColorSpan(context.getColor(R.color.red_a700)); } else { - blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.violet_700)); - redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_900)); + blueColorSpan = new ForegroundColorSpan(context.getColor(R.color.violet_700)); + redColorSpan = new ForegroundColorSpan(context.getColor(R.color.red_900)); } // Set the domain name from the the database cursor. @@ -834,100 +834,91 @@ public class DomainSettingsFragment extends Fragment { appWebViewThemeEntryNumber = 0; } - // Set the WebView theme visibility. - if (Build.VERSION.SDK_INT < 21) { // The WebView theme cannot be set on API 19. - // Get a handle for the webView theme linear layout. - LinearLayout webViewThemeLinearLayout = domainSettingsView.findViewById(R.id.webview_theme_linearlayout); + // Select the WebView theme in the spinner. + webViewThemeSpinner.setSelection(webViewThemeInt); - // Hide the WebView theme linear layout. - webViewThemeLinearLayout.setVisibility(View.GONE); - } else { // The WebView theme can be set on API >= 21. - // Select the WebView theme in the spinner. - webViewThemeSpinner.setSelection(webViewThemeInt); - - // Set the WebView theme text. - if (appWebViewThemeEntryNumber == DomainsDatabaseHelper.SYSTEM_DEFAULT) { // The app WebView theme is system default. - // Set the text according to the current UI theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.LIGHT_THEME]); - } else { - webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.DARK_THEME]); - } - } else { // The app WebView theme is not system default. - // Set the text according to the app WebView theme. - webViewThemeTextView.setText(webViewThemeStringArray[appWebViewThemeEntryNumber]); - } - - // Set the WebView theme icon and text visibility. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - switch (webViewThemeInt) { - case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The domain WebView theme is system default. - // Set the icon according to the app WebView theme. - switch (appWebViewThemeEntryNumber) { - case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The default WebView theme is system default. - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - // Set the light mode icon. - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); - } else { - // Set the dark theme icon. - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); - } - break; + // Set the WebView theme text. + if (appWebViewThemeEntryNumber == DomainsDatabaseHelper.SYSTEM_DEFAULT) { // The app WebView theme is system default. + // Set the text according to the current UI theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.LIGHT_THEME]); + } else { + webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.DARK_THEME]); + } + } else { // The app WebView theme is not system default. + // Set the text according to the app WebView theme. + webViewThemeTextView.setText(webViewThemeStringArray[appWebViewThemeEntryNumber]); + } - case DomainsDatabaseHelper.LIGHT_THEME: // the default WebView theme is light. - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); - } else { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); - } - break; + // Set the WebView theme icon and text visibility. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + switch (webViewThemeInt) { + case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The domain WebView theme is system default. + // Set the icon according to the app WebView theme. + switch (appWebViewThemeEntryNumber) { + case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The default WebView theme is system default. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + // Set the light mode icon. + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + // Set the dark theme icon. + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } + break; - case DomainsDatabaseHelper.DARK_THEME: // the default WebView theme is dark. - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); - } else { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } - break; - } + case DomainsDatabaseHelper.LIGHT_THEME: // the default WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); + } + break; - // Show the WebView theme text view. - webViewThemeTextView.setVisibility(View.VISIBLE); - break; + case DomainsDatabaseHelper.DARK_THEME: // the default WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } + break; + } - case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light. - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); - } else { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); - } + // Show the WebView theme text view. + webViewThemeTextView.setVisibility(View.VISIBLE); + break; - // Hide the WebView theme text view. - webViewThemeTextView.setVisibility(View.GONE); - break; + case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); + } - case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark. - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); - } else { - webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); - } + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; - // Hide the WebView theme text view. - webViewThemeTextView.setVisibility(View.GONE); - break; - } + case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } - // Open the WebView theme spinner when the text view is clicked. - webViewThemeTextView.setOnClickListener((View v) -> { - // Open the WebView theme spinner. - webViewThemeSpinner.performClick(); - }); + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; } + // Open the WebView theme spinner when the text view is clicked. + webViewThemeTextView.setOnClickListener((View v) -> { + // Open the WebView theme spinner. + webViewThemeSpinner.performClick(); + }); + // Select the wide viewport in the spinner. wideViewportSpinner.setSelection(wideViewportInt);