]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java
Refactor the code to make all the Java files lint free.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / SslCertificateError.java
index 80c9c1e71f86614cfd1165a10df142abaee39635..c8f3945dfe2a05ed0306c45f28ab57fbdaa4f823 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
 
 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.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
 import android.net.http.SslCertificate;
 import android.net.http.SslError;
 import android.os.Bundle;
-import android.support.v4.content.ContextCompat;
-import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
 import android.text.style.ForegroundColorSpan;
 import android.view.LayoutInflater;
 import android.widget.TextView;
 
-import org.w3c.dom.Text;
-
 import java.util.Date;
 
-public class SslCertificateError extends DialogFragment{
+public class SslCertificateError extends DialogFragment {
+
     private String primaryError;
     private String urlWithError;
     private String issuedToCName;
@@ -80,12 +76,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);
 
@@ -140,16 +137,18 @@ 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
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         // Get the activity's layout inflater.
@@ -204,7 +203,7 @@ public class SslCertificateError extends DialogFragment{
         String startDateLabel = getString(R.string.start_date) + "  ";
         String endDateLabel = getString(R.string.end_date) + "  ";
 
-        // Create a `SpannableStringBuilder` for each item.
+        // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text.
         SpannableStringBuilder urlStringBuilder = new SpannableStringBuilder(urlLabel + urlWithError);
         SpannableStringBuilder issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedToCName);
         SpannableStringBuilder issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedToOName);
@@ -216,10 +215,9 @@ 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.
+        // 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);
         issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
         issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);