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

Commit acb60fb5 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Haptics for PIN keys.

Change-Id: I65b12a614f344faef140334658ec1e627094e05e
parent d5692742
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.policy.impl.keyguard;

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

@@ -61,6 +62,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
    protected TextView mPasswordEntry;
    protected LockPatternUtils mLockPatternUtils;
    protected SecurityMessageDisplay mSecurityMessageDisplay;
    protected boolean mEnableHaptics;

    // 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.
@@ -80,6 +82,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout

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

    @Override
@@ -110,7 +113,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
        // We always set a dummy NavigationManager to avoid null checks
        mSecurityMessageDisplay = new KeyguardNavigationManager(null);

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

        mPasswordEntry = (TextView) findViewById(R.id.passwordEntry);
        mPasswordEntry.setOnEditorActionListener(this);
@@ -240,5 +243,14 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
        mSecurityMessageDisplay = display;
        reset();
    }

    // Cause a VIRTUAL_KEY vibration
    public void doHapticKeyClick() {
        if (mEnableHaptics) {
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
                    | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
        }
    }
}
+9 −2
Original line number Diff line number Diff line
@@ -103,6 +103,14 @@ public class KeyguardPINView extends KeyguardAbsKeyInputView
                    if (str.length() > 0) {
                        mPasswordEntry.setText(str.subSequence(0, str.length()-1));
                    }
                    doHapticKeyClick();
                }
            });
            pinDelete.setOnLongClickListener(new View.OnLongClickListener() {
                public boolean onLongClick(View v) {
                    mPasswordEntry.setText("");
                    doHapticKeyClick();
                    return true;
                }
            });
        }
@@ -118,4 +126,3 @@ public class KeyguardPINView extends KeyguardAbsKeyInputView
    public void showUsabilityHint() {
    }
}
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ import android.content.res.TypedArray;
import android.text.SpannableStringBuilder;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.internal.R;
import com.android.internal.widget.LockPatternUtils;

public class NumPadKey extends Button {
    // list of "ABC", etc per digit, starting with '0'
@@ -35,6 +37,7 @@ public class NumPadKey extends Button {
    int mDigit = -1;
    int mTextViewResId;
    TextView mTextView = null;
    boolean mEnableHaptics;

    private View.OnClickListener mListener = new View.OnClickListener() {
        @Override
@@ -50,6 +53,7 @@ public class NumPadKey extends Button {
            if (mTextView != null) {
                mTextView.append(String.valueOf(mDigit));
            }
            doHapticKeyClick();
        }
    };

@@ -70,6 +74,8 @@ public class NumPadKey extends Button {

        setOnClickListener(mListener);

        mEnableHaptics = new LockPatternUtils(context).isTactileFeedbackEnabled();

        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append(String.valueOf(mDigit));
        if (mDigit >= 0) {
@@ -99,4 +105,13 @@ public class NumPadKey extends Button {
        mTextView = null;
        mTextViewResId = resId;
    }

    // Cause a VIRTUAL_KEY vibration
    public void doHapticKeyClick() {
        if (mEnableHaptics) {
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
                    | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
        }
    }
}