Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 575c6710 authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fix 2373088: Cleanup and minor fixes to PasswordKeyboard*."

parents 102d05fa 280b6023
Loading
Loading
Loading
Loading
+0 −55
Original line number Diff line number Diff line
@@ -216,61 +216,6 @@ public class PasswordEntryKeyboard extends Keyboard {
        }
    }

    /**
     * Sets keyboard extension. Keyboard extension is shown when input is detected above keyboard
     * while keyboard has focus.
     *
     * @param resId
     */
    public void setExtension(int resId) {
        mExtensionResId = resId;
    }

    /**
     * Get current extesion resource id.
     *
     * @return resource id, 0 if not set.
     */
    public int getExtension() {
        return mExtensionResId;
    }

    private void updateSpaceBarForLocale() {
        if (mLocale != null) {
            // Create the graphic for spacebar
            Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(buffer);
            canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            // TODO: Make the text size a customizable attribute
            paint.setTextSize(22);
            paint.setTextAlign(Align.CENTER);
            // Draw a drop shadow for the text
            paint.setShadowLayer(1f, 0, 0, 0xFF000000);
            paint.setColor(0x80C0C0C0);
            canvas.drawText(mLocale.getDisplayLanguage(mLocale),
                    buffer.getWidth() / 2, - paint.ascent() + 2, paint);
            int x = (buffer.getWidth() - mSpaceIcon.getIntrinsicWidth()) / 2;
            int y = buffer.getHeight() - mSpaceIcon.getIntrinsicHeight();
            mSpaceIcon.setBounds(x, y,
                    x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight());
            mSpaceIcon.draw(canvas);
            mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
            mSpaceKey.repeatable = false;
        } else {
            mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
            mSpaceKey.repeatable = true;
        }
    }

    public void setLanguage(Locale locale) {
        if (mLocale != null && mLocale.equals(locale)) return;
        mLocale = locale;
        updateSpaceBarForLocale();
    }

    static class LatinKey extends Keyboard.Key {
        private boolean mShiftLockEnabled;
        private boolean mEnabled = true;
+7 −8
Original line number Diff line number Diff line
@@ -22,15 +22,11 @@ import android.inputmethodservice.KeyboardView;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
import android.text.Selection;
import android.util.Log;
import android.provider.Settings;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewRoot;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;
import com.android.internal.R;

public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
@@ -40,7 +36,6 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
    private static final int KEYBOARD_STATE_NORMAL = 0;
    private static final int KEYBOARD_STATE_SHIFTED = 1;
    private static final int KEYBOARD_STATE_CAPSLOCK = 2;
    private static final String TAG = "PasswordEntryKeyboardHelper";
    private int mKeyboardMode = KEYBOARD_MODE_ALPHA;
    private int mKeyboardState = KEYBOARD_STATE_NORMAL;
    private PasswordEntryKeyboard mQwertyKeyboard;
@@ -90,10 +85,15 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
            case KEYBOARD_MODE_ALPHA:
                mKeyboardView.setKeyboard(mQwertyKeyboard);
                mKeyboardState = KEYBOARD_STATE_NORMAL;
                final boolean visiblePassword = Settings.System.getInt(
                        mContext.getContentResolver(),
                        Settings.System.TEXT_SHOW_PASSWORD, 1) != 0;
                mKeyboardView.setPreviewEnabled(visiblePassword);
                break;
            case KEYBOARD_MODE_NUMERIC:
                mKeyboardView.setKeyboard(mNumericKeyboard);
                mKeyboardState = KEYBOARD_STATE_NORMAL;
                mKeyboardView.setPreviewEnabled(false); // never show popup for numeric keypad
                break;
        }
        mKeyboardMode = mode;
@@ -122,7 +122,6 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
    }

    public void onKey(int primaryCode, int[] keyCodes) {
        Log.v(TAG, "Key code = " + Integer.toHexString(primaryCode));
        if (primaryCode == Keyboard.KEYCODE_DELETE) {
            handleBackspace();
        } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
@@ -201,7 +200,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
    }

    public void onPress(int primaryCode) {

        // TODO: vibration support.
    }

    public void onRelease(int primaryCode) {
+1 −114
Original line number Diff line number Diff line
@@ -17,27 +17,17 @@
package com.android.internal.widget;

import android.content.Context;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.PopupWindow;
import com.android.internal.R;

public class PasswordEntryKeyboardView extends KeyboardView {

    public static final int KEYCODE_OPTIONS = -100;
    static final int KEYCODE_OPTIONS = -100;
    static final int KEYCODE_SHIFT_LONGPRESS = -101;
    static final int KEYCODE_VOICE = -102;
    static final int KEYCODE_F1 = -103;
    static final int KEYCODE_NEXT_LANGUAGE = -104;

    private boolean mExtensionVisible;
    private PasswordEntryKeyboardView mExtension;
    private PopupWindow mExtensionPopup;
    private boolean mFirstEvent;

    public PasswordEntryKeyboardView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
@@ -46,107 +36,4 @@ public class PasswordEntryKeyboardView extends KeyboardView {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent me) {
        if (((PasswordEntryKeyboard) getKeyboard()).getExtension() == 0) {
            return super.onTouchEvent(me);
        }
        if (me.getY() < 0) {
            if (mExtensionVisible) {
                int action = me.getAction();
                if (mFirstEvent) action = MotionEvent.ACTION_DOWN;
                mFirstEvent = false;
                MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(),
                        action,
                        me.getX(), me.getY() + mExtension.getHeight(), me.getMetaState());
                boolean result = mExtension.onTouchEvent(translated);
                translated.recycle();
                if (me.getAction() == MotionEvent.ACTION_UP
                        || me.getAction() == MotionEvent.ACTION_CANCEL) {
                    closeExtension();
                }
                return result;
            } else {
                if (openExtension()) {
                    MotionEvent cancel = MotionEvent.obtain(me.getDownTime(), me.getEventTime(),
                            MotionEvent.ACTION_CANCEL, me.getX() - 100, me.getY() - 100, 0);
                    super.onTouchEvent(cancel);
                    cancel.recycle();
                    if (mExtension.getHeight() > 0) {
                        MotionEvent translated = MotionEvent.obtain(me.getEventTime(),
                                me.getEventTime(),
                                MotionEvent.ACTION_DOWN,
                                me.getX(), me.getY() + mExtension.getHeight(),
                                me.getMetaState());
                        mExtension.onTouchEvent(translated);
                        translated.recycle();
                    } else {
                        mFirstEvent = true;
                    }
                }
                return true;
            }
        } else if (mExtensionVisible) {
            closeExtension();
            // Send a down event into the main keyboard first
            MotionEvent down = MotionEvent.obtain(me.getEventTime(), me.getEventTime(),
                    MotionEvent.ACTION_DOWN, me.getX(), me.getY(), me.getMetaState());
            super.onTouchEvent(down);
            down.recycle();
            // Send the actual event
            return super.onTouchEvent(me);
        } else {
            return super.onTouchEvent(me);
        }
    }

    private boolean openExtension() {
        if (((PasswordEntryKeyboard) getKeyboard()).getExtension() == 0) return false;
        makePopupWindow();
        mExtensionVisible = true;
        return true;
    }

    private void makePopupWindow() {
        if (mExtensionPopup == null) {
            int[] windowLocation = new int[2];
            mExtensionPopup = new PopupWindow(getContext());
            mExtensionPopup.setBackgroundDrawable(null);
            LayoutInflater li = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            mExtension = (PasswordEntryKeyboardView) li.inflate(
                    R.layout.password_keyboard_input, null);
            mExtension.setOnKeyboardActionListener(getOnKeyboardActionListener());
            mExtension.setPopupParent(this);
            mExtension.setPopupOffset(0, -windowLocation[1]);
            Keyboard keyboard;
            mExtension.setKeyboard(keyboard = new PasswordEntryKeyboard(getContext(),
                    ((PasswordEntryKeyboard) getKeyboard()).getExtension()));
            mExtensionPopup.setContentView(mExtension);
            mExtensionPopup.setWidth(getWidth());
            mExtensionPopup.setHeight(keyboard.getHeight());
            getLocationInWindow(windowLocation);
            // TODO: Fix the "- 30".
            mExtension.setPopupOffset(0, -windowLocation[1] - 30);
            mExtensionPopup.showAtLocation(this, 0, 0, -keyboard.getHeight()
                    + windowLocation[1]);
        } else {
            mExtension.setVisibility(VISIBLE);
        }
    }

    @Override
    public void closing() {
        super.closing();
        if (mExtensionPopup != null && mExtensionPopup.isShowing()) {
            mExtensionPopup.dismiss();
            mExtensionPopup = null;
        }
    }

    private void closeExtension() {
        mExtension.setVisibility(INVISIBLE);
        mExtension.closing();
        mExtensionVisible = false;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
            android:layout_marginLeft="6dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:gravity="center"
            android:gravity="left"
            android:ellipsize="marquee"
            android:text="@android:string/keyguard_password_enter_password_code"
            android:textAppearance="?android:attr/textAppearanceLarge"
@@ -53,7 +53,7 @@
            android:inputType="textPassword"
            android:gravity="center"
            android:layout_gravity="center"
            android:textSize="32sp"
            android:textSize="24sp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:background="@drawable/password_field_default"
            android:textColor="#ffffffff"
+0 −29
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 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.
*/
-->

<com.android.passwordunlockdemo.LatinKeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/keyboardView"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:keyBackground="@drawable/btn_keyboard_key_fulltrans"
        />
Loading