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

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

Merge "Integrate new PIN pad." into jb-mr1-lockscreen-dev

parents f33ff923 69bdee7c
Loading
Loading
Loading
Loading
+193 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 2012, 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.internal.policy.impl.keyguard.KeyguardPINView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyguard_pin_view"
    android:layout_width="350dp"
    android:layout_height="350dp"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1"
        >
        <EditText android:id="@+id/passwordEntry"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="@*android:dimen/keyguard_lockscreen_pin_margin_left"
            android:singleLine="true"
            android:textStyle="normal"
            android:inputType="textPassword"
            android:cursorVisible="false"
            android:textSize="36sp"
            android:background="@null"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ffffffff"
            android:imeOptions="flagForceAscii|actionDone"
            />

        <ImageButton android:id="@+id/delete_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:src="@*android:drawable/ic_input_delete"
            android:clickable="true"
            android:padding="8dip"
            android:background="?android:attr/selectableItemBackground"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key1"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="1"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key2"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="2"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key3"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="3"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key4"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="4"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key5"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="5"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key6"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="6"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1"
        >
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key7"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="7"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key8"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="8"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key9"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="9"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <Space
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
        <view class="com.android.internal.policy.impl.keyguard.NumPadKey"
            android:id="@+id/key0"
            style="@android:style/Widget.Button.NumPadKey"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textView="@+id/passwordEntry"
            android:digit="0"
            />
        <Button
            android:id="@+id/key_enter"
            style="@android:style/Widget.Button.NumPadKey"
            android:gravity="center"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@android:string/ok"
            />
    </LinearLayout>
</com.android.internal.policy.impl.keyguard.KeyguardPINView>
+5 −0
Original line number Diff line number Diff line
@@ -5788,4 +5788,9 @@
        <attr name="gravity" />
    </declare-styleable>

    <!-- Keyguard PIN entry -->
    <declare-styleable name="NumPadKey">
        <attr name="digit" format="integer" />
        <attr name="textView" format="reference" />
    </declare-styleable>
</resources>
+23 −0
Original line number Diff line number Diff line
@@ -2478,4 +2478,27 @@ please see styles_device_defaults.xml.
        <item name="android:contentDescription">@android:string/media_route_button_content_description</item>
    </style>

    <!-- Keyguard PIN pad styles -->
    <style name="Widget.Button.NumPadKey">
        <item name="android:singleLine">true</item>
        <item name="android:padding">6dip</item>
        <item name="android:gravity">left|center_vertical</item>
        <item name="android:background">?android:attr/selectableItemBackground</item>
        <item name="android:textSize">34dp</item>
        <item name="android:fontFamily">sans-serif</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#ffffff</item>
    </style>
    <style name="TextAppearance.NumPadKey">
        <item name="android:textSize">34dp</item>
        <item name="android:fontFamily">sans-serif</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#ffffff</item>
    </style>
    <style name="TextAppearance.NumPadKey.Klondike">
        <item name="android:textSize">20dp</item>
        <item name="android:fontFamily">sans-serif-condensed</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#80ffffff</item>
    </style>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -1289,6 +1289,7 @@
  <java-symbol type="id" name="keyguard_selector_view" />
  <java-symbol type="id" name="keyguard_pattern_view" />
  <java-symbol type="id" name="keyguard_password_view" />
  <java-symbol type="id" name="keyguard_pin_view" />
  <java-symbol type="id" name="keyguard_face_unlock_view" />
  <java-symbol type="id" name="keyguard_sim_pin_view" />
  <java-symbol type="id" name="keyguard_sim_puk_view" />
@@ -1319,6 +1320,7 @@
  <java-symbol type="id" name="keyguard_add_widget" />
  <java-symbol type="id" name="keyguard_add_widget_view" />
  <java-symbol type="id" name="sliding_layout" />
  <java-symbol type="id" name="key_enter" />
  <java-symbol type="integer" name="config_carDockRotation" />
  <java-symbol type="integer" name="config_defaultUiModeType" />
  <java-symbol type="integer" name="config_deskDockRotation" />
@@ -1343,6 +1345,7 @@
  <java-symbol type="layout" name="keyguard_selector_view" />
  <java-symbol type="layout" name="keyguard_pattern_view" />
  <java-symbol type="layout" name="keyguard_password_view" />
  <java-symbol type="layout" name="keyguard_pin_view" />
  <java-symbol type="layout" name="keyguard_face_unlock_view" />
  <java-symbol type="layout" name="keyguard_sim_pin_view" />
  <java-symbol type="layout" name="keyguard_sim_puk_view" />
@@ -1412,6 +1415,8 @@
  <java-symbol type="style" name="Animation.LockScreen" />
  <java-symbol type="style" name="Theme.Dialog.RecentApplications" />
  <java-symbol type="style" name="Theme.ExpandedMenu" />
  <java-symbol type="style" name="Widget.Button.NumPadKey" />
  <java-symbol type="style" name="TextAppearance.NumPadKey.Klondike" />
  <java-symbol type="string" name="kg_emergency_call_label" />
  <java-symbol type="string" name="kg_forgot_pattern_button_text" />
  <java-symbol type="string" name="kg_wrong_pattern" />
+247 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

package com.android.internal.policy.impl.keyguard;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewParent;

import com.android.internal.widget.LockPatternUtils;
import java.util.List;

import android.app.admin.DevicePolicyManager;
import android.content.res.Configuration;
import android.graphics.Rect;

import com.android.internal.widget.PasswordEntryKeyboardView;

import android.os.CountDownTimer;
import android.os.SystemClock;
import android.text.Editable;
import android.text.InputType;
import android.text.SpannableStringBuilder;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.text.method.TextKeyListener;
import android.text.style.TextAppearanceSpan;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
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;

/**
 * Base class for PIN and password unlock screens.
 */
public abstract class KeyguardAbsKeyInputView extends LinearLayout
        implements KeyguardSecurityView, OnEditorActionListener, TextWatcher {
    protected KeyguardSecurityCallback mCallback;
    protected EditText mPasswordEntry;
    protected LockPatternUtils mLockPatternUtils;
    protected SecurityMessageDisplay mSecurityMessageDisplay;

    // 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.
    protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;

    // Enable this if we want to hide the on-screen PIN keyboard when a physical one is showing
    protected static final boolean ENABLE_HIDE_KEYBOARD = false;

    public KeyguardAbsKeyInputView(Context context) {
        this(context, null);
    }

    public KeyguardAbsKeyInputView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setKeyguardCallback(KeyguardSecurityCallback callback) {
        mCallback = callback;
    }

    public void setLockPatternUtils(LockPatternUtils utils) {
        mLockPatternUtils = utils;
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        if (hasWindowFocus) {
            reset();
        }
    }

    public void reset() {
        // start fresh
        mPasswordEntry.setText("");
        mPasswordEntry.requestFocus();

        // if the user is currently locked out, enforce it.
        long deadline = mLockPatternUtils.getLockoutAttemptDeadline();
        if (deadline != 0) {
            handleAttemptLockout(deadline);
        } else {
            resetState();
        }
    }

    protected abstract void resetState();

    @Override
    protected void onFinishInflate() {
        // We always set a dummy NavigationManager to avoid null checks
        mSecurityMessageDisplay = new KeyguardNavigationManager(null);

        mLockPatternUtils = new LockPatternUtils(mContext); // TODO: use common one

        mPasswordEntry = (EditText) findViewById(R.id.passwordEntry);
        mPasswordEntry.setOnEditorActionListener(this);
        mPasswordEntry.addTextChangedListener(this);

        // Poke the wakelock any time the text is selected or modified
        mPasswordEntry.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mCallback.userActivity(0); // TODO: customize timeout for text?
            }
        });

        mPasswordEntry.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void afterTextChanged(Editable s) {
                if (mCallback != null) {
                    mCallback.userActivity(0);
                }
            }
        });
    }

    @Override
    protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
        // send focus to the password field
        return mPasswordEntry.requestFocus(direction, previouslyFocusedRect);
    }

    protected void verifyPasswordAndUnlock() {
        String entry = mPasswordEntry.getText().toString();
        if (mLockPatternUtils.checkPassword(entry)) {
            mCallback.reportSuccessfulUnlockAttempt();
            mCallback.dismiss(true);
        } else if (entry.length() > MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT ) {
            // to avoid accidental lockout, only count attempts that are long enough to be a
            // real password. This may require some tweaking.
            mCallback.reportFailedUnlockAttempt();
            if (0 == (mCallback.getFailedAttempts()
                    % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) {
                long deadline = mLockPatternUtils.setLockoutAttemptDeadline();
                handleAttemptLockout(deadline);
            }
            mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pin, true);
        }
        mPasswordEntry.setText("");
    }

    // Prevent user from using the PIN/Password entry until scheduled deadline.
    protected void handleAttemptLockout(long elapsedRealtimeDeadline) {
        mPasswordEntry.setEnabled(false);
        long elapsedRealtime = SystemClock.elapsedRealtime();
        new CountDownTimer(elapsedRealtimeDeadline - elapsedRealtime, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {
                int secondsRemaining = (int) (millisUntilFinished / 1000);
                mSecurityMessageDisplay.setMessage(
                        R.string.kg_too_many_failed_attempts_countdown, true, secondsRemaining);
            }

            @Override
            public void onFinish() {
                resetState();
            }
        }.start();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        mCallback.userActivity(0);
        return false;
    }

    @Override
    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 || actionId == EditorInfo.IME_ACTION_DONE
                || actionId == EditorInfo.IME_ACTION_NEXT) {
            verifyPasswordAndUnlock();
            return true;
        }
        return false;
    }

    @Override
    public boolean needsInput() {
        return false;
    }

    @Override
    public void onPause() {

    }

    @Override
    public void onResume() {
        reset();
    }

    @Override
    public KeyguardSecurityCallback getCallback() {
        return mCallback;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        if (mCallback != null) {
            mCallback.userActivity(KeyguardViewManager.DIGIT_PRESS_WAKE_MILLIS);
        }
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void afterTextChanged(Editable s) {
    }

    @Override
    public void setSecurityMessageDisplay(SecurityMessageDisplay display) {
        mSecurityMessageDisplay = display;
        reset();
    }
}
Loading