Fix 2402303: Split Keyboard widget from LatinIME into reusable PasswordEntryKeyboardView

- Added new PasswordEntryKeyboardView to internal/widgets.  Widget supports:
    - alpha mode with symbols (latin-1 only).
    - a numeric keyboard
    - IME emulation that applies keyboard input to arbitrary top-level view widget.
- Added new transparent assets to framework resources.
- Modified Keyguard and Keyguard layouts to use new PasswordEntryKeyboardView.
diff --git a/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java b/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java
index 1a250b8..4006683 100644
--- a/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java
+++ b/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java
@@ -20,22 +20,29 @@
 
 import com.android.internal.telephony.IccCard.State;
 import com.android.internal.widget.LockPatternUtils;
+import com.android.internal.widget.PasswordEntryKeyboardView;
 
 import android.text.Editable;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.inputmethod.EditorInfo;
 import android.widget.Button;
+import android.widget.EditText;
 import android.widget.LinearLayout;
 import android.widget.TextView;
+import android.widget.TextView.OnEditorActionListener;
+
 import com.android.internal.R;
+import com.android.internal.widget.PasswordEntryKeyboardHelper;
 
 /**
  * Displays a dialer-like interface or alphanumeric (latin-1) key entry for the user to enter
  * an unlock password
  */
 public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen, View.OnClickListener,
-        KeyguardUpdateMonitor.ConfigurationChangeCallback, KeyguardUpdateMonitor.InfoCallback {
+        KeyguardUpdateMonitor.ConfigurationChangeCallback, OnEditorActionListener {
 
     private static final int DIGIT_PRESS_WAKE_MILLIS = 5000;
 
@@ -44,15 +51,11 @@
 
     private final boolean mCreatedWithKeyboardOpen;
 
-    private TextView mPasswordTextView;
-    private TextView mOkButton;
+    private EditText mPasswordEntry;
     private TextView mEmergencyCallButton;
-    private View mBackSpaceButton;
-    private TextView mCarrier;
     private LockPatternUtils mLockPatternUtils;
-    private Button mCancelButton;
-
-    private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+    private PasswordEntryKeyboardView mKeyboardView;
+    private PasswordEntryKeyboardHelper mKeyboardHelper;
 
     // To avoid accidental lockout due to events while the device in in the pocket, ignore
     // any passwords with length less than or equal to this length.
@@ -70,44 +73,29 @@
             layoutInflater.inflate(R.layout.keyguard_screen_password_landscape, this, true);
         } else {
             layoutInflater.inflate(R.layout.keyguard_screen_password_portrait, this, true);
-            new TouchInput();
         }
 
-        mPasswordTextView = (TextView) findViewById(R.id.pinDisplay);
-        mBackSpaceButton = findViewById(R.id.backspace);
-        mBackSpaceButton.setOnClickListener(this);
-
-        // The cancel button is not used on this screen.
-        mCancelButton = (Button) findViewById(R.id.cancel);
-        if (mCancelButton != null) {
-            mCancelButton.setText("");
-        }
-
+        boolean isAlpha = lockPatternUtils.getPasswordMode() == LockPatternUtils.MODE_PASSWORD;
+        mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
+        mPasswordEntry = (EditText) findViewById(R.id.passwordEntry);
+        mPasswordEntry.setOnEditorActionListener(this);
         mEmergencyCallButton = (TextView) findViewById(R.id.emergencyCall);
-        mOkButton = (TextView) findViewById(R.id.ok);
-
-        mPasswordTextView.setFocusable(false);
-
         mEmergencyCallButton.setOnClickListener(this);
-        mOkButton.setOnClickListener(this);
-
         mUpdateMonitor.registerConfigurationChangeCallback(this);
-
         mLockPatternUtils = lockPatternUtils;
-        mCarrier = (TextView) findViewById(R.id.carrier);
-        // until we get an update...
-        mCarrier.setText(LockScreen.getCarrierString(mUpdateMonitor.getTelephonyPlmn(),
-                        mUpdateMonitor.getTelephonySpn()));
 
-        updateMonitor.registerInfoCallback(this);
+        mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this);
+        mKeyboardHelper.setKeyboardMode(isAlpha ? PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
+                : PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
+
         updateMonitor.registerConfigurationChangeCallback(this);
-
         setFocusableInTouchMode(true);
+        mPasswordEntry.requestFocus();
     }
 
     /** {@inheritDoc} */
     public boolean needsInput() {
-        return true;
+        return false;
     }
 
     /** {@inheritDoc} */
@@ -118,7 +106,8 @@
     /** {@inheritDoc} */
     public void onResume() {
         // start fresh
-        mPasswordTextView.setText("");
+        mPasswordEntry.setText("");
+        mPasswordEntry.requestFocus();
     }
 
     /** {@inheritDoc} */
@@ -127,22 +116,14 @@
     }
 
     public void onClick(View v) {
-        if (v == mBackSpaceButton) {
-            final Editable digits = mPasswordTextView.getEditableText();
-            final int len = digits.length();
-            if (len > 0) {
-                digits.delete(len-1, len);
-            }
-        } else if (v == mEmergencyCallButton) {
+        if (v == mEmergencyCallButton) {
             mCallback.takeEmergencyCallAction();
-        } else if (v == mOkButton) {
-            verifyPasswordAndUnlock();
         }
         mCallback.pokeWakelock();
     }
 
     private void verifyPasswordAndUnlock() {
-        String entry = mPasswordTextView.getText().toString();
+        String entry = mPasswordEntry.getText().toString();
         if (mLockPatternUtils.checkPassword(entry)) {
             mCallback.keyguardDone(true);
             mCallback.reportSuccessfulUnlockAttempt();
@@ -151,37 +132,15 @@
             // real password. This may require some tweaking.
             mCallback.reportFailedUnlockAttempt();
         }
-        mPasswordTextView.setText("");
+        mPasswordEntry.setText("");
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        if (keyCode == KeyEvent.KEYCODE_BACK) {
-            return true;
-        }
-
-        final char match = event.getMatch(DIGITS);
-        if (match != 0) {
-            reportDigit(match - '0');
-            return true;
-        }
-        if (keyCode == KeyEvent.KEYCODE_DEL) {
-            mPasswordTextView.onKeyDown(keyCode, event);
-            return true;
-        }
-
-        if (keyCode == KeyEvent.KEYCODE_ENTER) {
-            verifyPasswordAndUnlock();
-            return true;
-        }
-
+        mCallback.pokeWakelock();
         return false;
     }
 
-    private void reportDigit(int digit) {
-        mPasswordTextView.append(Integer.toString(digit));
-    }
-
     public void onOrientationChange(boolean inPortrait) {
 
     }
@@ -192,71 +151,13 @@
         }
     }
 
-    /**
-     * Helper class to handle input from touch dialer.  Only relevant when
-     * the keyboard is shut.
-     */
-    private class TouchInput implements View.OnClickListener {
-        private int mDigitIds[] = { R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
-                R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine };
-        private TextView mCancelButton;
-        private TouchInput() {
-            for (int i = 0; i < mDigitIds.length; i++) {
-                Button button = (Button) findViewById(mDigitIds[i]);
-                button.setOnClickListener(this);
-                button.setText(Integer.toString(i));
-            }
-            mCancelButton = (TextView) findViewById(R.id.cancel);
-            mCancelButton.setOnClickListener(this);
-            mOkButton = (TextView) findViewById(R.id.ok);
-            mOkButton.setOnClickListener(this);
+    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+        // Check if this was the result of hitting the enter key
+        if (actionId == EditorInfo.IME_NULL) {
+            verifyPasswordAndUnlock();
+            return true;
         }
-
-        public void onClick(View v) {
-            if (v == mCancelButton) {
-                return;
-            }
-            if (v == mOkButton) {
-                verifyPasswordAndUnlock();
-            }
-
-            final int digit = checkDigit(v);
-            if (digit >= 0) {
-                mCallback.pokeWakelock(DIGIT_PRESS_WAKE_MILLIS);
-                reportDigit(digit);
-            }
-        }
-
-        private int checkDigit(View v) {
-            int digit = -1;
-            for (int i = 0; i < mDigitIds.length; i++) {
-                if (v.getId() == mDigitIds[i]) {
-                    digit = i;
-                    break;
-                }
-            }
-            return digit;
-        }
+        return false;
     }
 
-    /** {@inheritDoc} */
-    public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
-        mCarrier.setText(LockScreen.getCarrierString(plmn, spn));
-    }
-
-    public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel) {
-
-    }
-
-    public void onRingerModeChanged(int state) {
-
-    }
-
-    public void onTimeChanged() {
-
-    }
-
-    public void onSimStateChanged(State simState) {
-
-    }
 }