Security warning dialog update

 Bug: 5222843

Change-Id: I0d387a0564c82e1234ea14dee723a52e1ba9cade
diff --git a/res/layout/ssl_warning.xml b/res/layout/ssl_warning.xml
index 749629d..a54dfb8 100644
--- a/res/layout/ssl_warning.xml
+++ b/res/layout/ssl_warning.xml
@@ -14,27 +14,18 @@
      limitations under the License.
 -->
 
-<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:shrinkColumns="1"
-        android:orientation="horizontal" >
-    
-    <TableRow>
-        <ImageView
-            android:scaleType="center"
-            android:src="@drawable/ic_dialog_browser_security_bad"
-            android:layout_marginLeft="20dip"
-            android:layout_marginBottom="12dip" />
-            
-        <TextView 
-            android:id="@+id/warning"
-            android:gravity="left"
-            android:layout_weight="1"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:layout_marginLeft="10dip"
-            android:layout_marginRight="20dip"
-            android:layout_marginBottom="12dip" />
-    </TableRow>
+<TextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/warning"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:drawableLeft="@drawable/ic_dialog_browser_security_bad"
+    android:drawablePadding="6dip"
+    android:textAppearance="?android:attr/textAppearanceSmall"
+    android:layout_marginLeft="12dip"
+    android:layout_marginRight="12dip"
+    android:minHeight="32dip"
+    android:gravity="center_vertical"
+    android:layout_marginBottom="4dip"
+    android:layout_marginTop="4dip" />
 
-</TableLayout>
diff --git a/res/layout/ssl_warnings.xml b/res/layout/ssl_warnings.xml
deleted file mode 100644
index 3fe73d3..0000000
--- a/res/layout/ssl_warnings.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<ScrollView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="vertical">
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical">
-
-        <!-- Warnings header -->
-        <TextView
-            android:id="@+id/warnings_header"
-            android:layout_height="wrap_content"
-            android:layout_width="match_parent"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:gravity="left"
-            android:text="@string/ssl_warnings_header"
-            android:layout_marginRight="20dip"
-            android:layout_marginLeft="20dip"
-            android:layout_marginTop="12dip" />
-   
-        <!-- Placeholder for one or more warnings -->
-        <LinearLayout
-            android:id="@+id/placeholder"
-            android:layout_height="wrap_content"
-            android:layout_width="match_parent"
-            android:layout_marginTop="12dip"
-            android:orientation="vertical" />
-
-    </LinearLayout>
-
-</ScrollView>
diff --git a/src/com/android/browser/PageDialogsHandler.java b/src/com/android/browser/PageDialogsHandler.java
index 3f64758..14373cb 100644
--- a/src/com/android/browser/PageDialogsHandler.java
+++ b/src/com/android/browser/PageDialogsHandler.java
@@ -284,6 +284,13 @@
                 .show();
     }
 
+    private void addError(LayoutInflater inflater, LinearLayout parent, int error) {
+        TextView textView = (TextView) inflater.inflate(R.layout.ssl_warning,
+                parent, false);
+        textView.setText(error);
+        parent.addView(textView);
+    }
+
     /**
      * Displays the SSL error certificate dialog.
      * @param view The target web-view.
@@ -306,23 +313,26 @@
         final LinearLayout placeholder =
                 (LinearLayout)certificateView.findViewById(com.android.internal.R.id.placeholder);
 
-        LinearLayout ll = (LinearLayout)factory.inflate(R.layout.ssl_warning, placeholder);
-        TextView textView = (TextView)ll.findViewById(R.id.warning);
-
         if (error.hasError(SslError.SSL_UNTRUSTED)) {
-            textView.setText(R.string.ssl_untrusted);
-        } else if (error.hasError(SslError.SSL_IDMISMATCH)) {
-            textView.setText(R.string.ssl_mismatch);
-        } else if (error.hasError(SslError.SSL_EXPIRED)) {
-            textView.setText(R.string.ssl_expired);
-        } else if (error.hasError(SslError.SSL_NOTYETVALID)) {
-            textView.setText(R.string.ssl_not_yet_valid);
-        } else if (error.hasError(SslError.SSL_DATE_INVALID)) {
-            textView.setText(R.string.ssl_date_invalid);
-        } else if (error.hasError(SslError.SSL_INVALID)) {
-            textView.setText(R.string.ssl_invalid);
-        } else {
-            textView.setText(R.string.ssl_unknown);
+            addError(factory, placeholder, R.string.ssl_untrusted);
+        }
+        if (error.hasError(SslError.SSL_IDMISMATCH)) {
+            addError(factory, placeholder, R.string.ssl_mismatch);
+        }
+        if (error.hasError(SslError.SSL_EXPIRED) || true) {
+            addError(factory, placeholder, R.string.ssl_expired);
+        }
+        if (error.hasError(SslError.SSL_NOTYETVALID)) {
+            addError(factory, placeholder, R.string.ssl_not_yet_valid);
+        }
+        if (error.hasError(SslError.SSL_DATE_INVALID) || true) {
+            addError(factory, placeholder, R.string.ssl_date_invalid);
+        }
+        if (error.hasError(SslError.SSL_INVALID)) {
+            addError(factory, placeholder, R.string.ssl_invalid);
+        }
+        if (placeholder.getChildCount() == 0) {
+            addError(factory, placeholder, R.string.ssl_unknown);
         }
 
         mSSLCertificateOnErrorHandler = handler;
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index d6106a5..c519c91 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -744,75 +744,45 @@
                 return;
             }
             if (mSettings.showSecurityWarnings()) {
-                final LayoutInflater factory =
-                    LayoutInflater.from(mContext);
-                final View warningsView =
-                    factory.inflate(R.layout.ssl_warnings, null);
-                final LinearLayout placeholder =
-                    (LinearLayout)warningsView.findViewById(R.id.placeholder);
-
-                if (error.hasError(SslError.SSL_UNTRUSTED)) {
-                    LinearLayout ll = (LinearLayout)factory
-                        .inflate(R.layout.ssl_warning, null);
-                    ((TextView)ll.findViewById(R.id.warning))
-                        .setText(R.string.ssl_untrusted);
-                    placeholder.addView(ll);
-                }
-
-                if (error.hasError(SslError.SSL_IDMISMATCH)) {
-                    LinearLayout ll = (LinearLayout)factory
-                        .inflate(R.layout.ssl_warning, null);
-                    ((TextView)ll.findViewById(R.id.warning))
-                        .setText(R.string.ssl_mismatch);
-                    placeholder.addView(ll);
-                }
-
-                if (error.hasError(SslError.SSL_EXPIRED)) {
-                    LinearLayout ll = (LinearLayout)factory
-                        .inflate(R.layout.ssl_warning, null);
-                    ((TextView)ll.findViewById(R.id.warning))
-                        .setText(R.string.ssl_expired);
-                    placeholder.addView(ll);
-                }
-
-                if (error.hasError(SslError.SSL_NOTYETVALID)) {
-                    LinearLayout ll = (LinearLayout)factory
-                        .inflate(R.layout.ssl_warning, null);
-                    ((TextView)ll.findViewById(R.id.warning))
-                        .setText(R.string.ssl_not_yet_valid);
-                    placeholder.addView(ll);
-                }
-
-                new AlertDialog.Builder(mContext).setTitle(
-                        R.string.security_warning).setIcon(
-                        android.R.drawable.ic_dialog_alert).setView(
-                        warningsView).setPositiveButton(R.string.ssl_continue,
+                new AlertDialog.Builder(mContext)
+                    .setTitle(R.string.security_warning)
+                    .setMessage(R.string.ssl_warnings_header)
+                    .setIcon(android.R.drawable.ic_dialog_alert)
+                    .setPositiveButton(R.string.ssl_continue,
                         new DialogInterface.OnClickListener() {
+                            @Override
                             public void onClick(DialogInterface dialog,
                                     int whichButton) {
                                 handler.proceed();
                             }
-                        }).setNeutralButton(R.string.view_certificate,
+                        })
+                    .setNeutralButton(R.string.view_certificate,
                         new DialogInterface.OnClickListener() {
+                            @Override
                             public void onClick(DialogInterface dialog,
                                     int whichButton) {
-                                mWebViewController.showSslCertificateOnError(view,
-                                        handler, error);
+                                mWebViewController.showSslCertificateOnError(
+                                        view, handler, error);
                             }
-                        }).setNegativeButton(R.string.ssl_go_back,
+                        })
+                    .setNegativeButton(R.string.ssl_go_back,
                         new DialogInterface.OnClickListener() {
+                            @Override
                             public void onClick(DialogInterface dialog,
                                     int whichButton) {
                                 dialog.cancel();
                             }
-                        }).setOnCancelListener(
+                        })
+                    .setOnCancelListener(
                         new DialogInterface.OnCancelListener() {
+                            @Override
                             public void onCancel(DialogInterface dialog) {
                                 handler.cancel();
                                 setLockIconType(LockIcon.LOCK_ICON_UNSECURE);
                                 mWebViewController.onUserCanceledSsl(Tab.this);
                             }
-                        }).show();
+                        })
+                    .show();
             } else {
                 handler.proceed();
             }