/*
- * Copyright © 2017-2018 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2017-2019 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
import android.net.http.SslCertificate;
import android.os.Build;
import android.os.Bundle;
-// We have to use `android.support.v4.app.Fragment` until minimum API >= 23. Otherwise we cannot call `getContext()`.
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
+// `android.support.v4.app.Fragment` must be used until minimum API >= 23. Otherwise `getContext()` does not work.
import android.support.v4.app.Fragment;
+import android.support.v7.widget.CardView;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
// Store the default settings.
- final String defaultUserAgentName = sharedPreferences.getString("user_agent", "Privacy Browser");
- final String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0");
- String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100");
- boolean defaultSwipeToRefreshBoolean = sharedPreferences.getBoolean("swipe_to_refresh", true);
- final boolean defaultNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
- final boolean defaultDisplayWebpageImagesBoolean = sharedPreferences.getBoolean("display_website_images", true);
+ final String defaultUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
+ final String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value));
+ String defaultFontSizeString = sharedPreferences.getString("font_size", getString(R.string.font_size_default_value));
+ boolean defaultSwipeToRefresh = sharedPreferences.getBoolean("swipe_to_refresh", true);
+ final boolean defaultNightMode = sharedPreferences.getBoolean("night_mode", false);
+ final boolean defaultDisplayWebpageImages = sharedPreferences.getBoolean("display_webpage_images", true);
// Get handles for the views in the fragment.
final EditText domainNameEditText = domainSettingsView.findViewById(R.id.domain_settings_name_edittext);
final TextView displayImagesTextView = domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_textview);
final ImageView pinnedSslCertificateImageView = domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_imageview);
Switch pinnedSslCertificateSwitch = domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
- final LinearLayout savedSslCertificateLinearLayout = domainSettingsView.findViewById(R.id.saved_ssl_certificate_linearlayout);
+ final CardView savedSslCertificateCardView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_cardview);
+ LinearLayout savedSslCertificateLinearLayout = domainSettingsView.findViewById(R.id.saved_ssl_certificate_linearlayout);
final RadioButton savedSslCertificateRadioButton = domainSettingsView.findViewById(R.id.saved_ssl_certificate_radiobutton);
final TextView savedSslCertificateIssuedToCNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_cname);
TextView savedSslCertificateIssuedToONameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_oname);
TextView savedSslCertificateIssuedByUNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_uname);
TextView savedSslCertificateStartDateTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_start_date);
TextView savedSslCertificateEndDateTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_end_date);
- final LinearLayout currentWebsiteCertificateLinearLayout = domainSettingsView.findViewById(R.id.current_website_certificate_linearlayout);
+ final CardView currentWebsiteCertificateCardView = domainSettingsView.findViewById(R.id.current_website_certificate_cardview);
+ LinearLayout currentWebsiteCertificateLinearLayout = domainSettingsView.findViewById(R.id.current_website_certificate_linearlayout);
final RadioButton currentWebsiteCertificateRadioButton = domainSettingsView.findViewById(R.id.current_website_certificate_radiobutton);
final TextView currentWebsiteCertificateIssuedToCNameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_cname);
TextView currentWebsiteCertificateIssuedToONameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_oname);
});
// Create a `boolean` to track if night mode is enabled.
- boolean nightModeEnabled = (nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightModeBoolean);
+ boolean nightModeEnabled = (nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightMode);
// Disable the JavaScript switch if night mode is enabled.
if (nightModeEnabled) {
swipeToRefreshSpinner.setSelection(swipeToRefreshInt);
// Set the swipe to refresh text.
- if (defaultSwipeToRefreshBoolean) {
+ if (defaultSwipeToRefresh) {
swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.SWIPE_TO_REFRESH_ENABLED));
} else {
swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.SWIPE_TO_REFRESH_DISABLED));
// Set the swipe to refresh icon and TextView settings. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
switch (swipeToRefreshInt) {
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_SYSTEM_DEFAULT:
- if (defaultSwipeToRefreshBoolean) { // Swipe to refresh is enabled by default.
+ if (defaultSwipeToRefresh) { // Swipe to refresh is enabled by default.
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
nightModeSpinner.setSelection(nightModeInt);
// Set the default night mode text.
- if (defaultNightModeBoolean) {
+ if (defaultNightMode) {
nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.NIGHT_MODE_ENABLED));
} else {
nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.NIGHT_MODE_DISABLED));
// Set the night mode icon and TextView settings. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
switch (nightModeInt) {
case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT:
- if (defaultNightModeBoolean) { // Night mode enabled by default.
+ if (defaultNightMode) { // Night mode enabled by default.
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
displayWebpageImagesSpinner.setSelection(displayImagesInt);
// Set the default display images text.
- if (defaultDisplayWebpageImagesBoolean) {
+ if (defaultDisplayWebpageImages) {
displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED));
} else {
displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED));
// Set the display website images icon and TextView settings. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
switch (displayImagesInt) {
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
- if (defaultDisplayWebpageImagesBoolean) { // Display webpage images enabled by default.
+ if (defaultDisplayWebpageImages) { // Display webpage images enabled by default.
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
if (pinnedSslCertificateSwitch.isChecked()) {
// Set the visibility of the saved SSL certificate.
if (savedSslCertificateIssuedToCNameString == null) {
- savedSslCertificateLinearLayout.setVisibility(View.GONE);
+ savedSslCertificateCardView.setVisibility(View.GONE);
} else {
- savedSslCertificateLinearLayout.setVisibility(View.VISIBLE);
+ savedSslCertificateCardView.setVisibility(View.VISIBLE);
}
// Set the visibility of the current website SSL certificate.
if (currentWebsiteSslCertificate == null) {
// Hide the SSL certificate.
- currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+ currentWebsiteCertificateCardView.setVisibility(View.GONE);
// Show the instruction.
noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
} else {
// Show the SSL certificate.
- currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE);
+ currentWebsiteCertificateCardView.setVisibility(View.VISIBLE);
// Hide the instruction.
noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
}
// Set the status of the radio buttons.
- if (savedSslCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ if (savedSslCertificateCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ // Check the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(false);
- } else if (currentWebsiteCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ } else if (currentWebsiteCertificateCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+ // Check the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(false);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
} else { // Neither SSL certificate is visible.
+ // Uncheck both radio buttons.
savedSslCertificateRadioButton.setChecked(false);
currentWebsiteCertificateRadioButton.setChecked(false);
}
} else { // `pinnedSslCertificateSwitch` is not checked.
// Hide the SSl certificates and instructions.
- savedSslCertificateLinearLayout.setVisibility(View.GONE);
- currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+ savedSslCertificateCardView.setVisibility(View.GONE);
+ currentWebsiteCertificateCardView.setVisibility(View.GONE);
noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
// Uncheck the radio buttons.
// Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
switch (position) {
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_SYSTEM_DEFAULT:
- if (defaultSwipeToRefreshBoolean) { // Swipe to refresh enabled by default.
+ if (defaultSwipeToRefresh) { // Swipe to refresh enabled by default.
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
// Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
switch (position) {
case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT:
- if (defaultNightModeBoolean) { // Night mode enabled by default.
+ if (defaultNightMode) { // Night mode enabled by default.
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
}
// Create a `boolean` to store the current night mode setting.
- boolean currentNightModeEnabled = (position == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((position == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightModeBoolean);
+ boolean currentNightModeEnabled = (position == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((position == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightMode);
// Disable the JavaScript `Switch` if night mode is enabled.
if (currentNightModeEnabled) {
// Update the icon and the visibility of `displayImagesTextView`.
switch (position) {
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
- if (defaultDisplayWebpageImagesBoolean) {
+ if (defaultDisplayWebpageImages) {
// Set the icon according to the theme.
if (MainWebViewActivity.darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
// Update the visibility of the saved SSL certificate.
if (savedSslCertificateIssuedToCNameString == null) {
- savedSslCertificateLinearLayout.setVisibility(View.GONE);
+ savedSslCertificateCardView.setVisibility(View.GONE);
} else {
- savedSslCertificateLinearLayout.setVisibility(View.VISIBLE);
+ savedSslCertificateCardView.setVisibility(View.VISIBLE);
}
// Update the visibility of the current website SSL certificate.
if (currentWebsiteSslCertificate == null) {
// Hide the SSL certificate.
- currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+ currentWebsiteCertificateCardView.setVisibility(View.GONE);
// Show the instruction.
noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
} else {
// Show the SSL certificate.
- currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE);
+ currentWebsiteCertificateCardView.setVisibility(View.VISIBLE);
// Hide the instruction.
noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
}
// Set the status of the radio buttons.
- if (savedSslCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ if (savedSslCertificateCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ // Check the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(false);
- } else if (currentWebsiteCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ } else if (currentWebsiteCertificateCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+ // Check the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
} else { // Neither SSL certificate is visible.
+ // Uncheck both radio buttons.
savedSslCertificateRadioButton.setChecked(false);
currentWebsiteCertificateRadioButton.setChecked(false);
}
}
// Hide the SSl certificates and instructions.
- savedSslCertificateLinearLayout.setVisibility(View.GONE);
- currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+ savedSslCertificateCardView.setVisibility(View.GONE);
+ currentWebsiteCertificateCardView.setVisibility(View.GONE);
noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
// Uncheck the radio buttons.
}
});
- savedSslCertificateLinearLayout.setOnClickListener((View v) -> {
+ savedSslCertificateCardView.setOnClickListener((View v) -> {
+ // Check the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
});
savedSslCertificateRadioButton.setOnClickListener((View v) -> {
+ // Check the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
});
- currentWebsiteCertificateLinearLayout.setOnClickListener((View v) -> {
+ currentWebsiteCertificateCardView.setOnClickListener((View v) -> {
+ // Check the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
});
currentWebsiteCertificateRadioButton.setOnClickListener((View v) -> {
+ // Check the current website SSL certificate radio button.
currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
});
return domainSettingsView;