X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FSslCertificateError.java;h=388a09bdf4d0d2d095ba703e59ae2841342a9d5c;hb=7d632afdd10cad5b4d62fce37707eaceebe260cb;hp=52826504de985fbe3584103b5d562a7988984c48;hpb=e4e45c521ade9eb2f87a97eecffed7e852b09df7;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java index 52826504..388a09bd 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java +++ b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java @@ -1,5 +1,5 @@ /** - * Copyright 2015-2016 Soren Stoutner . + * Copyright 2016 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -19,14 +19,16 @@ package com.stoutner.privacybrowser; -import android.app.Activity; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; +import android.content.Context; import android.content.DialogInterface; import android.net.http.SslCertificate; import android.net.http.SslError; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatDialogFragment; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; @@ -35,7 +37,8 @@ import android.widget.TextView; import java.util.Date; -public class SslCertificateError extends DialogFragment{ +public class SslCertificateError extends AppCompatDialogFragment { + private String primaryError; private String urlWithError; private String issuedToCName; @@ -74,12 +77,13 @@ public class SslCertificateError extends DialogFragment{ argumentsBundle.putString("StartDate", startDateForBundle.toString()); argumentsBundle.putString("EndDate", endDateForBundle.toString()); - // Add the `Bundle` to this instance of `SslCertificateError`. + // Add `argumentsBundle` to this instance of `SslCertificateError`. SslCertificateError thisSslCertificateErrorDialog = new SslCertificateError(); thisSslCertificateErrorDialog.setArguments(argumentsBundle); return thisSslCertificateErrorDialog; } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -134,17 +138,20 @@ public class SslCertificateError extends DialogFragment{ private SslCertificateErrorListener sslCertificateErrorListener; // Check to make sure that the parent activity implements the listener. - public void onAttach(Activity parentActivity) { - super.onAttach(parentActivity); + public void onAttach(Context context) { + super.onAttach(context); try { - sslCertificateErrorListener = (SslCertificateErrorListener) parentActivity; + sslCertificateErrorListener = (SslCertificateErrorListener) context; } catch(ClassCastException exception) { - throw new ClassCastException(parentActivity.toString() + " must implement SslCertificateErrorListener"); + throw new ClassCastException(context.toString() + " must implement SslCertificateErrorListener"); } } + // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. + @SuppressLint("InflateParams") @Override + @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { // Get the activity's layout inflater. LayoutInflater layoutInflater = getActivity().getLayoutInflater(); @@ -210,7 +217,7 @@ public class SslCertificateError extends DialogFragment{ SpannableStringBuilder endDateStringBuilder = new SpannableStringBuilder((endDateLabel + endDate)); // Create a blue `ForegroundColorSpan`. We have to use the deprecated `getColor` until API >= 23. - ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue)); + @SuppressWarnings("deprecation") ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700)); // Setup the spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. urlStringBuilder.setSpan(blueColorSpan, urlLabel.length(), urlStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);