More CryptKeeper UI work.

* Implemented failure case.
* More pixel perfect
* Remove the animation
* Display the encroid on the blank screen
* Remove the back button.
* Fix portrait mode screens

Bug: 3384231
Bug: 3394103
Bug: 3388721
Bug: 3381450
Bug: 3406278
Bug: 3351832
Change-Id: Ib763c8b577198deb45255acc767bc6d5409efc0c
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 26c7cc5..e94dfcb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1079,7 +1079,7 @@
         <activity android:name=".CryptKeeper"
                   android:immersive="true"
                   android:launchMode="singleTop"
-                  android:theme="@style/CryptKeeperTheme"
+                  android:theme="@android:style/Theme.Holo.NoActionBar"
                   android:windowSoftInputMode="stateAlwaysHidden">
             <intent-filter android:priority="10">
                 <action android:name="android.intent.action.MAIN" />
diff --git a/res/anim/crypt_keeper_exit.xml b/res/anim/crypt_keeper_exit.xml
deleted file mode 100644
index 3ab34e9..0000000
--- a/res/anim/crypt_keeper_exit.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 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.
--->
-
-<set xmlns:android="http://schemas.android.com/apk/res/android"
-    android:interpolator="@android:anim/accelerate_interpolator"
->
-
-    <scale
-        android:fromXScale="1.0"
-        android:toXScale="0.0"
-        android:fromYScale="1.0"
-        android:toYScale="0.0"
-        android:pivotX="50%"
-        android:pivotY="50%"
-        android:fillAfter="false"
-        android:duration="500"
-    />
-
-</set>
-
diff --git a/res/drawable-xlarge-hdpi/encroid_complete.png b/res/drawable-xlarge-hdpi/encroid_complete.png
new file mode 100644
index 0000000..89e45b5
--- /dev/null
+++ b/res/drawable-xlarge-hdpi/encroid_complete.png
Binary files differ
diff --git a/res/drawable-xlarge-hdpi/encroid_progress.png b/res/drawable-xlarge-hdpi/encroid_progress.png
new file mode 100644
index 0000000..5e73dad
--- /dev/null
+++ b/res/drawable-xlarge-hdpi/encroid_progress.png
Binary files differ
diff --git a/res/drawable-xlarge-hdpi/encroid_resignin.png b/res/drawable-xlarge-hdpi/encroid_resignin.png
new file mode 100644
index 0000000..ac470f3
--- /dev/null
+++ b/res/drawable-xlarge-hdpi/encroid_resignin.png
Binary files differ
diff --git a/res/drawable-xlarge-hdpi/encroid_waiting.png b/res/drawable-xlarge-hdpi/encroid_waiting.png
new file mode 100644
index 0000000..1090b86
--- /dev/null
+++ b/res/drawable-xlarge-hdpi/encroid_waiting.png
Binary files differ
diff --git a/res/drawable-xlarge-hdpi/encryption_bg_complete.png b/res/drawable-xlarge-hdpi/encryption_bg_complete.png
deleted file mode 100644
index aad2f08..0000000
--- a/res/drawable-xlarge-hdpi/encryption_bg_complete.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xlarge-hdpi/encryption_bg_waiting.png b/res/drawable-xlarge-hdpi/encryption_bg_waiting.png
deleted file mode 100644
index 9e4bbf9..0000000
--- a/res/drawable-xlarge-hdpi/encryption_bg_waiting.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encroid_complete.png b/res/drawable-xlarge-mdpi/encroid_complete.png
new file mode 100644
index 0000000..89e45b5
--- /dev/null
+++ b/res/drawable-xlarge-mdpi/encroid_complete.png
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encroid_progress.png b/res/drawable-xlarge-mdpi/encroid_progress.png
new file mode 100644
index 0000000..5e73dad
--- /dev/null
+++ b/res/drawable-xlarge-mdpi/encroid_progress.png
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encroid_resignin.png b/res/drawable-xlarge-mdpi/encroid_resignin.png
new file mode 100644
index 0000000..ac470f3
--- /dev/null
+++ b/res/drawable-xlarge-mdpi/encroid_resignin.png
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encroid_waiting.png b/res/drawable-xlarge-mdpi/encroid_waiting.png
new file mode 100644
index 0000000..1090b86
--- /dev/null
+++ b/res/drawable-xlarge-mdpi/encroid_waiting.png
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encryption_bg_complete.png b/res/drawable-xlarge-mdpi/encryption_bg_complete.png
deleted file mode 100644
index f53cb23..0000000
--- a/res/drawable-xlarge-mdpi/encryption_bg_complete.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xlarge-mdpi/encryption_bg_waiting.png b/res/drawable-xlarge-mdpi/encryption_bg_waiting.png
deleted file mode 100644
index b8e6ded..0000000
--- a/res/drawable-xlarge-mdpi/encryption_bg_waiting.png
+++ /dev/null
Binary files differ
diff --git a/res/layout-xlarge-land/crypt_keeper_password_entry.xml b/res/layout-xlarge-land/crypt_keeper_password_entry.xml
index ffbdf89..f6cbecf 100644
--- a/res/layout-xlarge-land/crypt_keeper_password_entry.xml
+++ b/res/layout-xlarge-land/crypt_keeper_password_entry.xml
@@ -16,57 +16,67 @@
 ** limitations under the License.
 */
 -->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
 >
-
     <RelativeLayout
-        android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_marginTop="206dip"
     >
-        <!-- left side: status -->
-        <include layout="@layout/crypt_keeper_status"
+        <ImageView android:id="@+id/encroid"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginLeft="102dip"
-            android:layout_marginTop="20dip"
-            android:gravity="left"
-            android:paddingTop="50dip"
-            android:layout_centerVertical="true"
-            android:layout_alignParentLeft="true"
+            android:layout_alignParentTop="true"
+            android:src="@drawable/encroid_resignin"
+        />
+
+        <TextView android:id="@+id/passwordLabel"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_toRightOf="@+id/encroid"
+            android:layout_marginTop="37dip"
+            android:paddingRight="17dip"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:text="@string/crypt_keeper_enter_password"
         />
 
         <!-- Password entry field -->
         <EditText android:id="@+id/passwordEntry"
             android:layout_height="wrap_content"
-            android:layout_width="450dip"
-            android:layout_marginRight="155dip"
-            android:layout_alignParentRight="true"
+            android:layout_width="320dip"
+            android:layout_toRightOf="@+id/passwordLabel"
+            android:layout_marginTop="26dip"
             android:singleLine="true"
-            android:textStyle="normal"
             android:inputType="textPassword"
-            android:gravity="center"
-            android:layout_gravity="center"
-            android:textSize="24sp"
-            android:layout_marginTop="120dip"
-            android:layout_marginBottom="5dip"
             android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textColor="#ffffffff"
             android:editable="false"
         />
 
+        <TextView android:id="@+id/status"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_toRightOf="@+id/passwordLabel"
+            android:layout_below="@+id/passwordEntry"
+            android:paddingTop="8dip"
+            android:singleLine="true"
+            android:textSize="17sp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:drawableLeft="@*android:drawable/ic_lock_idle_lock"
+            android:visibility="gone"
+        />
     </RelativeLayout>
 
     <com.android.internal.widget.PasswordEntryKeyboardView android:id="@+id/keyboard"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
         android:background="#00000000"
         android:keyBackground="@*android:drawable/btn_keyboard_key_fulltrans"
         android:visibility="visible"
     />
 
-</LinearLayout>
\ No newline at end of file
+</RelativeLayout>
\ No newline at end of file
diff --git a/res/layout-xlarge/crypt_keeper_password_entry.xml b/res/layout-xlarge/crypt_keeper_password_entry.xml
index b67eed0..2da2534 100644
--- a/res/layout-xlarge/crypt_keeper_password_entry.xml
+++ b/res/layout-xlarge/crypt_keeper_password_entry.xml
@@ -16,42 +16,59 @@
 ** limitations under the License.
 */
 -->
-
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:gravity="center_horizontal"
 >
-
-    <!-- left side: status -->
-    <include layout="@layout/crypt_keeper_status"
+    <RelativeLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="134dip"
-        android:paddingTop="50dip"
-        android:layout_alignParentTop="true"
-        android:layout_gravity="center_horizontal"
         android:layout_centerHorizontal="true"
-    />
+        android:layout_marginTop="318dip"
+    >
+        <ImageView android:id="@+id/encroid"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:src="@drawable/encroid_resignin"
+        />
 
-    <!-- Password entry field -->
-    <EditText android:id="@+id/passwordEntry"
-        android:layout_above="@id/keyboard"
-        android:layout_height="wrap_content"
-        android:layout_width="450dip"
-        android:singleLine="true"
-        android:textStyle="normal"
-        android:inputType="textPassword"
-        android:gravity="center"
-        android:layout_gravity="center_horizontal"
-        android:layout_centerHorizontal="true"
-        android:textSize="24sp"
-        android:layout_marginTop="120dip"
-        android:layout_marginBottom="5dip"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textColor="#ffffffff"
-        android:editable="false"
-    />
+        <TextView android:id="@+id/passwordLabel"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_toRightOf="@+id/encroid"
+            android:layout_marginTop="37dip"
+            android:paddingRight="17dip"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:text="@string/crypt_keeper_enter_password"
+        />
+
+        <!-- Password entry field -->
+        <EditText android:id="@+id/passwordEntry"
+            android:layout_height="wrap_content"
+            android:layout_width="320dip"
+            android:layout_toRightOf="@+id/passwordLabel"
+            android:layout_marginTop="26dip"
+            android:singleLine="true"
+            android:inputType="textPassword"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:editable="false"
+        />
+
+        <TextView android:id="@+id/status"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_toRightOf="@+id/passwordLabel"
+            android:layout_below="@+id/passwordEntry"
+            android:paddingTop="8dip"
+            android:singleLine="true"
+            android:textSize="17sp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:drawableLeft="@*android:drawable/ic_lock_idle_lock"
+            android:visibility="gone"
+        />
+    </RelativeLayout>
 
     <com.android.internal.widget.PasswordEntryKeyboardView android:id="@+id/keyboard"
         android:layout_width="match_parent"
diff --git a/res/layout-xlarge/crypt_keeper_progress.xml b/res/layout-xlarge/crypt_keeper_progress.xml
index 5a33a9e..7bad7ba 100644
--- a/res/layout-xlarge/crypt_keeper_progress.xml
+++ b/res/layout-xlarge/crypt_keeper_progress.xml
@@ -14,24 +14,33 @@
      limitations under the License.
   -->
 
-<LinearLayout
+<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingTop="154dip"
     android:paddingLeft="128dip"
     android:paddingRight="128dip"
-    android:paddingBottom="0dip" 
-    android:orientation="vertical"
-    android:background="@drawable/encryption_bg_waiting"
+    android:paddingBottom="16dip"
 >
 
+    <ImageView
+        android:id="@+id/encroid"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentBottom="true"
+        android:paddingRight="65dip"
+        android:src="@drawable/encroid_waiting"
+    />
+
     <TextView
+        android:id="@+id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:minHeight="48dip"
+        android:layout_alignParentTop="true"
         android:layout_alignParentLeft="true"
-        android:layout_centerVertical="true"
         android:layout_marginLeft="16dip"
         android:textSize="30dip"
         android:textColor="#ff99cc00"
@@ -44,6 +53,7 @@
         android:id="@+id/top_divider"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_below="@+id/title"
     >
         <ProgressBar
             android:id="@+id/progress_bar"
@@ -52,17 +62,41 @@
             style="?android:attr/progressBarStyleHorizontal"
         />
     </RelativeLayout>
-    
+
     <TextView
         android:id="@+id/status"
         android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/top_divider"
         android:paddingLeft="152dip"
         android:paddingTop="21dip"
-        android:textSize="18dip"
-        android:textColor="#ffffffff"
-        android:text="@string/crypt_keeper_setup_description"
+        android:textAppearance="?android:attr/textAppearanceMedium"
     />
 
-</LinearLayout>
+    <!-- Divider -->
+    <RelativeLayout
+        android:id="@+id/bottom_divider"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingLeft="152dip"
+        android:layout_above="@+id/factory_reset"
+        android:visibility="gone"
+    >
+        <ProgressBar
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            style="?android:attr/progressBarStyleHorizontal"
+        />
+    </RelativeLayout>
+
+    <Button
+        android:id="@+id/factory_reset"
+        android:layout_width="208dip"
+        android:layout_height="48dip"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentBottom="true"
+        android:layout_marginBottom="80dip"
+        android:text="@string/master_clear_button_text"
+        android:visibility="gone"
+    />
+</RelativeLayout>
\ No newline at end of file
diff --git a/res/layout/crypt_keeper_blank.xml b/res/layout/crypt_keeper_blank.xml
new file mode 100644
index 0000000..1c880c2
--- /dev/null
+++ b/res/layout/crypt_keeper_blank.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:gravity="center_vertical"
+>
+
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:src="@drawable/encroid_progress"
+    />
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ea9f6ca..131fe6b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -111,7 +111,6 @@
     <!-- Title for a notification shown. -->
     <string name="sdcard_setting" product="default">SD card</string>
 
-
     <!-- Battery Info screen. Label for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="battery_info_status_label">Battery status:</string>
     <!-- Battery Info screen. Label for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
@@ -141,7 +140,6 @@
     <!-- Battery Info screen. Label for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="battery_info_screen_on">Screen ON time:</string>
 
-
     <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="battery_info_status_unknown">Unknown</string>
     <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
@@ -493,7 +491,6 @@
     <!-- Main Settings screen settings summary text for the "Wireless controls" setting -->
     <string name="radio_controls_summary">Manage Wi-Fi, Bluetooth, airplane mode, mobile networks, &amp; VPNs</string>
 
-
     <!-- mobile network settings screen, setting check box title -->
     <string name="roaming">Data roaming</string>
     <!-- mobile network settings screen, setting option summary text when check box is selected -->
@@ -619,7 +616,7 @@
     an hour or more. You must start with a charged battery and keep your phone plugged in
     until encryption is complete. If you interrupt the encryption process, you will lose
     some or all of your data.</string>
-    
+
     <!-- Button text to start encryption process -->
     <string name="crypt_keeper_button_text" product="tablet">Encrypt tablet</string>
     <!-- Button text to start encryption process -->
@@ -659,9 +656,29 @@
     <string name="crypt_keeper_setup_description" product="default">Please wait while your phone
     is being encrypted. ^1% complete.</string>
 
-    <!-- Informational text on the progress screen when encrypting the device has a problem -->
+    <!-- Informational text on the password entry screen when password entry fails-->
     <string name="crypt_keeper_cooldown">Try again in ^1 seconds.</string>
-    
+
+    <!-- Informational text on the password entry screen prompting the user for their password -->
+    <string name="crypt_keeper_enter_password">Enter your password</string>
+
+    <!-- Title of the encryption screen when encrypting the device failed -->
+    <string name="crypt_keeper_failed_title">Encryption failed</string>
+
+    <!-- Informational text when encryption fails -->
+    <string name="crypt_keeper_failed_summary" product="tablet">
+    Encryption was interrupted and can\'t complete. You must perform a factory data reset (erasing
+    all your data) before you can resume using your tablet. You can try encrypting your tablet
+    again after the reset is complete.
+    </string>
+
+    <!-- Informational text when encryption fails -->
+    <string name="crypt_keeper_failed_summary" product="default">
+    Encryption was interrupted and can\'t complete. You must perform a factory data reset (erasing
+    all your data) before you can resume using your phone. You can try encrypting your phone
+    again after the reset is complete.
+    </string>
+
     <!-- Unlock Picker Settings --><skip />
 
     <!-- Security Picker --><skip />
@@ -1160,7 +1177,6 @@
     <!-- Default access point SSID used for tethering -->
     <string name="wifi_tether_configure_ssid_default">AndroidHotspot</string>
 
-
     <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
          Wi-Fi Testing on the diagnostic screen-->
     <string name="testing_wifi_info" translatable="false">Wifi information</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index eb39aa2..1a6380f 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -121,18 +121,10 @@
         <item name="android:windowIsFloating">true</item>
     </style>
 
-    <style name="CryptKeeperTheme" parent="@android:style/Theme.Holo.NoActionBar">
-        <item name="android:windowAnimationStyle">@style/CryptKeeperAnimation</item>
-    </style>
-
     <style name="CryptKeeperBlankTheme" parent="@android:style/Theme.Holo.NoActionBar">
         <item name="android:background">#ff000000</item>
     </style>
 
-    <style name="CryptKeeperAnimation">
-        <item name="android:windowExitAnimation">@anim/crypt_keeper_exit</item>
-    </style>
-
     <style name="SecurityPreferenceButtonContainer" parent="@android:style/Holo.SegmentedButton">
         <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">wrap_content</item>
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index 6f847f3..cbad3f0 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -35,16 +35,16 @@
 import android.os.SystemProperties;
 import android.os.storage.IMountService;
 import android.text.TextUtils;
-import android.text.format.DateFormat;
 import android.util.Log;
 import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.inputmethod.EditorInfo;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
-import java.util.Date;
-
 public class CryptKeeper extends Activity implements TextView.OnEditorActionListener {
     private static final String TAG = "CryptKeeper";
 
@@ -59,6 +59,11 @@
 
     // This activity is used to fade the screen to black after the password is entered.
     public static class Blank extends Activity {
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            setContentView(R.layout.crypt_keeper_blank);
+        }
     }
 
     private Handler mHandler = new Handler() {
@@ -105,9 +110,12 @@
 
         // Disable the status bar
         StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE);
-        sbm.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ICONS
+        sbm.disable(StatusBarManager.DISABLE_EXPAND
+                | StatusBarManager.DISABLE_NOTIFICATION_ICONS
                 | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
-                | StatusBarManager.DISABLE_SYSTEM_INFO | StatusBarManager.DISABLE_NAVIGATION);
+                | StatusBarManager.DISABLE_SYSTEM_INFO
+                | StatusBarManager.DISABLE_NAVIGATION
+                | StatusBarManager.DISABLE_BACK);
     }
 
     @Override
@@ -139,9 +147,38 @@
         updateProgress();
     }
 
+    private void showFactoryReset() {
+        // Hide the encryption-bot to make room for the "factory reset" button
+        findViewById(R.id.encroid).setVisibility(View.GONE);
+
+        // Show the reset button, failure text, and a divider
+        Button button = (Button) findViewById(R.id.factory_reset);
+        button.setVisibility(View.VISIBLE);
+        button.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                // Factory reset the device.
+                sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
+            }
+        });
+
+        TextView tv = (TextView) findViewById(R.id.title);
+        tv.setText(R.string.crypt_keeper_failed_title);
+
+        tv = (TextView) findViewById(R.id.status);
+        tv.setText(R.string.crypt_keeper_failed_summary);
+
+        View view = findViewById(R.id.bottom_divider);
+        view.setVisibility(View.VISIBLE);
+    }
+
     private void updateProgress() {
         String state = SystemProperties.get("vold.encrypt_progress");
 
+        if ("error_partially_encrypted".equals(state)) {
+            showFactoryReset();
+            return;
+        }
+
         int progress = 0;
         try {
             progress = Integer.parseInt(state);
@@ -160,16 +197,18 @@
 
     private void cooldown() {
         TextView tv = (TextView) findViewById(R.id.status);
+
         if (mCooldown <= 0) {
             // Re-enable the password entry
             EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
             passwordEntry.setEnabled(true);
 
-            tv.setText(R.string.try_again);
-
+            tv.setVisibility(View.GONE);
         } else {
-            CharSequence tempalte = getText(R.string.crypt_keeper_cooldown);
-            tv.setText(TextUtils.expandTemplate(tempalte, Integer.toString(mCooldown)));
+            CharSequence template = getText(R.string.crypt_keeper_cooldown);
+            tv.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown)));
+
+            tv.setVisibility(View.VISIBLE);
 
             mCooldown--;
             mHandler.removeMessages(COOLDOWN);
@@ -186,14 +225,6 @@
         PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this,
                 keyboardView, passwordEntry, false);
         keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
-
-
-        passwordEntry.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_lock_idle_lock,
-                0, 0, 0);
-
-        String dateFormatString = getString(com.android.internal.R.string.full_wday_month_day_no_year);
-        TextView date = (TextView) findViewById(R.id.date);
-        date.setText(DateFormat.format(dateFormatString, new Date()));
     }
 
     private IMountService getMountService() {
@@ -240,6 +271,7 @@
                 } else {
                     TextView tv = (TextView) findViewById(R.id.status);
                     tv.setText(R.string.try_again);
+                    tv.setVisibility(View.VISIBLE);
                 }
             } catch (Exception e) {
                 Log.e(TAG, "Error while decrypting...", e);
diff --git a/src/com/android/settings/CryptKeeperConfirm.java b/src/com/android/settings/CryptKeeperConfirm.java
index 0269c2b..53688f4 100644
--- a/src/com/android/settings/CryptKeeperConfirm.java
+++ b/src/com/android/settings/CryptKeeperConfirm.java
@@ -41,6 +41,8 @@
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
 
+            setContentView(R.layout.crypt_keeper_blank);
+
             if (Utils.isMonkeyRunning()) {
                 finish();
             }
@@ -50,7 +52,8 @@
                     | StatusBarManager.DISABLE_NOTIFICATION_ICONS
                     | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
                     | StatusBarManager.DISABLE_SYSTEM_INFO
-                    | StatusBarManager.DISABLE_NAVIGATION);
+                    | StatusBarManager.DISABLE_NAVIGATION
+                    | StatusBarManager.DISABLE_BACK);
 
             // Post a delayed message in 700 milliseconds to enable encryption.
             // NOTE: The animation on this activity is set for 500 milliseconds