X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FSslCertificateErrorDialog.java;h=8bde8de0f198e978bf58ca8b760e32ff12903b8c;hb=0a5d2eabceeafb49a957598538aa74d4f11dfce0;hp=f0d5a69f860846f963b4162eb72e06107713740f;hpb=5bcf4ca90f27512b94fb7aca4fad37b4e4774655;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.java index f0d5a69f..8bde8de0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 Soren Stoutner . + * Copyright © 2016-2018 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -28,12 +28,13 @@ import android.net.http.SslCertificate; import android.net.http.SslError; import android.os.Bundle; import android.support.annotation.NonNull; -// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <= 22. +// `AppCompatDialogFragment` is used instead of `DialogFragment` to avoid an error on API <=22. import android.support.v7.app.AppCompatDialogFragment; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; +import android.view.WindowManager; import android.widget.TextView; import com.stoutner.privacybrowser.R; @@ -44,6 +45,7 @@ import java.util.Date; public class SslCertificateErrorDialog extends AppCompatDialogFragment { + // The private variables are used in `onCreate()` and `onCreateDialog()`. private int primaryErrorInt; private String urlWithError; private String issuedToCName; @@ -92,6 +94,9 @@ public class SslCertificateErrorDialog extends AppCompatDialogFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // Remove the incorrect lint warning that `getArguments()` might be null. + assert getArguments() != null; + // Save the components of the SSL error message in class variables. primaryErrorInt = getArguments().getInt("PrimaryErrorInt"); urlWithError = getArguments().getString("UrlWithError"); @@ -132,17 +137,28 @@ public class SslCertificateErrorDialog extends AppCompatDialogFragment { @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { + // Remove the incorrect lint warning that `getActivity()` might be null. + assert getActivity() != null; + // Get the activity's layout inflater. LayoutInflater layoutInflater = getActivity().getLayoutInflater(); - // Use `AlertDialog.Builder` to create the `AlertDialog`. + // Use an alert dialog builder to create the alert dialog. AlertDialog.Builder dialogBuilder; - // Set the style according to the theme. + // Set the style and icon according to the theme. if (MainWebViewActivity.darkTheme) { + // Set the style. dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark); + + // Set the icon. + dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_dark); } else { + // Set the style. dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight); + + // Set the icon. + dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_light); } // Set the title. @@ -151,42 +167,41 @@ public class SslCertificateErrorDialog extends AppCompatDialogFragment { // Set the view. The parent view is `null` because it will be assigned by `AlertDialog`. dialogBuilder.setView(layoutInflater.inflate(R.layout.ssl_certificate_error, null)); - // Set an `onClick` listener on the negative button. `null` doesn't do anything extra when the button is pressed. The `Dialog` will automatically close. - dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - sslCertificateErrorListener.onSslErrorCancel(); - } - }); + // Set a listener on the negative button. + dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> sslCertificateErrorListener.onSslErrorCancel()); - // Set an `onClick` listener on the positive button. - dialogBuilder.setPositiveButton(R.string.proceed, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - sslCertificateErrorListener.onSslErrorProceed(); - } - }); + // Set a listener on the positive button. + dialogBuilder.setPositiveButton(R.string.proceed, (DialogInterface dialog, int which) -> sslCertificateErrorListener.onSslErrorProceed()); - // Create an `AlertDialog` from the `AlertDialog.Builder`. + // Create an alert dialog from the alert dialog builder. AlertDialog alertDialog = dialogBuilder.create(); - // We have to show the `AlertDialog` before we can modify the content. + // Disable screenshots if not allowed. + if (!MainWebViewActivity.allowScreenshots) { + // Remove the warning below that `getWindow()` might be null. + assert alertDialog.getWindow() != null; + + // Disable screenshots. + alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + + // We have to show the alert dialog before we can modify the content. alertDialog.show(); // Get handles for the `TextViews` - TextView primaryErrorTextView = (TextView) alertDialog.findViewById(R.id.primary_error); - TextView urlTextView = (TextView) alertDialog.findViewById(R.id.url_error_dialog); - TextView issuedToCNameTextView = (TextView) alertDialog.findViewById(R.id.issued_to_cname_error_dialog); - TextView issuedToONameTextView = (TextView) alertDialog.findViewById(R.id.issued_to_oname_error_dialog); - TextView issuedToUNameTextView = (TextView) alertDialog.findViewById(R.id.issued_to_uname_error_dialog); - TextView issuedByTextView = (TextView) alertDialog.findViewById(R.id.issued_by_textview); - TextView issuedByCNameTextView = (TextView) alertDialog.findViewById(R.id.issued_by_cname_error_dialog); - TextView issuedByONameTextView = (TextView) alertDialog.findViewById(R.id.issued_by_oname_error_dialog); - TextView issuedByUNameTextView = (TextView) alertDialog.findViewById(R.id.issued_by_uname_error_dialog); - TextView validDatesTextView = (TextView) alertDialog.findViewById(R.id.valid_dates_textview); - TextView startDateTextView = (TextView) alertDialog.findViewById(R.id.start_date_error_dialog); - TextView endDateTextView = (TextView) alertDialog.findViewById(R.id.end_date_error_dialog); + TextView primaryErrorTextView = alertDialog.findViewById(R.id.primary_error); + TextView urlTextView = alertDialog.findViewById(R.id.url_error_dialog); + TextView issuedToCNameTextView = alertDialog.findViewById(R.id.issued_to_cname_error_dialog); + TextView issuedToONameTextView = alertDialog.findViewById(R.id.issued_to_oname_error_dialog); + TextView issuedToUNameTextView = alertDialog.findViewById(R.id.issued_to_uname_error_dialog); + TextView issuedByTextView = alertDialog.findViewById(R.id.issued_by_textview); + TextView issuedByCNameTextView = alertDialog.findViewById(R.id.issued_by_cname_error_dialog); + TextView issuedByONameTextView = alertDialog.findViewById(R.id.issued_by_oname_error_dialog); + TextView issuedByUNameTextView = alertDialog.findViewById(R.id.issued_by_uname_error_dialog); + TextView validDatesTextView = alertDialog.findViewById(R.id.valid_dates_textview); + TextView startDateTextView = alertDialog.findViewById(R.id.start_date_error_dialog); + TextView endDateTextView = alertDialog.findViewById(R.id.end_date_error_dialog); // Setup the common strings. String urlLabel = getString(R.string.url_label) + " ";