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=aea9bf3ef13c3734169347b9df1a4751a57c1740;hp=76dacba62a4edb4634e2de011e6ca7baedb11725;hb=c712e2ddec063fb29676a2df99786b262d8c4bfe;hpb=b4fc354bee486a2df17b3aae6760a3c61eba1e97 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 76dacba6..aea9bf3e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2018 Soren Stoutner . + * Copyright © 2017-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -27,10 +27,11 @@ import android.database.Cursor; 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; @@ -92,12 +93,12 @@ public class DomainSettingsFragment extends Fragment { 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); @@ -140,7 +141,8 @@ public class DomainSettingsFragment extends Fragment { 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); @@ -150,7 +152,8 @@ public class DomainSettingsFragment extends Fragment { 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); @@ -341,7 +344,7 @@ public class DomainSettingsFragment extends Fragment { }); // 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) { @@ -744,7 +747,7 @@ public class DomainSettingsFragment extends Fragment { 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)); @@ -753,7 +756,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -807,7 +810,7 @@ public class DomainSettingsFragment extends Fragment { 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)); @@ -816,7 +819,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -871,7 +874,7 @@ public class DomainSettingsFragment extends Fragment { 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)); @@ -880,7 +883,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -1068,41 +1071,62 @@ public class DomainSettingsFragment extends Fragment { 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. @@ -1480,7 +1504,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -1538,7 +1562,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -1584,7 +1608,7 @@ public class DomainSettingsFragment extends Fragment { } // 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) { @@ -1653,7 +1677,7 @@ public class DomainSettingsFragment extends Fragment { // 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)); @@ -1718,34 +1742,61 @@ public class DomainSettingsFragment extends Fragment { // 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); } @@ -1758,8 +1809,8 @@ public class DomainSettingsFragment extends Fragment { } // 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. @@ -1768,24 +1819,76 @@ public class DomainSettingsFragment extends Fragment { } }); - 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;