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/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