Merge "Fix 5444675: Fix vibrate regression on Pattern and PIN unlock screens." into ics-mr0
This commit is contained in:
@ -32,9 +32,9 @@ import android.os.Debug;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.Vibrator;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
@ -59,9 +59,6 @@ public class LockPatternView extends View {
|
|||||||
private static final int ASPECT_LOCK_WIDTH = 1; // Fixed width; height will be minimum of (w,h)
|
private static final int ASPECT_LOCK_WIDTH = 1; // Fixed width; height will be minimum of (w,h)
|
||||||
private static final int ASPECT_LOCK_HEIGHT = 2; // Fixed height; width will be minimum of (w,h)
|
private static final int ASPECT_LOCK_HEIGHT = 2; // Fixed height; width will be minimum of (w,h)
|
||||||
|
|
||||||
// Vibrator pattern for creating a tactile bump
|
|
||||||
private static final long[] DEFAULT_VIBE_PATTERN = {0, 1, 40, 41};
|
|
||||||
|
|
||||||
private static final boolean PROFILE_DRAWING = false;
|
private static final boolean PROFILE_DRAWING = false;
|
||||||
private boolean mDrawingProfilingStarted = false;
|
private boolean mDrawingProfilingStarted = false;
|
||||||
|
|
||||||
@ -102,7 +99,7 @@ public class LockPatternView extends View {
|
|||||||
private DisplayMode mPatternDisplayMode = DisplayMode.Correct;
|
private DisplayMode mPatternDisplayMode = DisplayMode.Correct;
|
||||||
private boolean mInputEnabled = true;
|
private boolean mInputEnabled = true;
|
||||||
private boolean mInStealthMode = false;
|
private boolean mInStealthMode = false;
|
||||||
private boolean mTactileFeedbackEnabled = true;
|
private boolean mEnableHapticFeedback = true;
|
||||||
private boolean mPatternInProgress = false;
|
private boolean mPatternInProgress = false;
|
||||||
|
|
||||||
private float mDiameterFactor = 0.10f; // TODO: move to attrs
|
private float mDiameterFactor = 0.10f; // TODO: move to attrs
|
||||||
@ -127,11 +124,6 @@ public class LockPatternView extends View {
|
|||||||
private int mBitmapWidth;
|
private int mBitmapWidth;
|
||||||
private int mBitmapHeight;
|
private int mBitmapHeight;
|
||||||
|
|
||||||
|
|
||||||
private Vibrator vibe; // Vibrator for creating tactile feedback
|
|
||||||
|
|
||||||
private long[] mVibePattern;
|
|
||||||
|
|
||||||
private int mAspect;
|
private int mAspect;
|
||||||
private final Matrix mArrowMatrix = new Matrix();
|
private final Matrix mArrowMatrix = new Matrix();
|
||||||
private final Matrix mCircleMatrix = new Matrix();
|
private final Matrix mCircleMatrix = new Matrix();
|
||||||
@ -250,7 +242,6 @@ public class LockPatternView extends View {
|
|||||||
|
|
||||||
public LockPatternView(Context context, AttributeSet attrs) {
|
public LockPatternView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
vibe = new Vibrator();
|
|
||||||
|
|
||||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LockPatternView);
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LockPatternView);
|
||||||
|
|
||||||
@ -295,26 +286,6 @@ public class LockPatternView extends View {
|
|||||||
mBitmapHeight = Math.max(mBitmapHeight, bitmap.getHeight());
|
mBitmapHeight = Math.max(mBitmapHeight, bitmap.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// allow vibration pattern to be customized
|
|
||||||
mVibePattern = loadVibratePattern(com.android.internal.R.array.config_virtualKeyVibePattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long[] loadVibratePattern(int id) {
|
|
||||||
int[] pattern = null;
|
|
||||||
try {
|
|
||||||
pattern = getResources().getIntArray(id);
|
|
||||||
} catch (Resources.NotFoundException e) {
|
|
||||||
Log.e(TAG, "Vibrate pattern missing, using default", e);
|
|
||||||
}
|
|
||||||
if (pattern == null) {
|
|
||||||
return DEFAULT_VIBE_PATTERN;
|
|
||||||
}
|
|
||||||
|
|
||||||
long[] tmpPattern = new long[pattern.length];
|
|
||||||
for (int i = 0; i < pattern.length; i++) {
|
|
||||||
tmpPattern[i] = pattern[i];
|
|
||||||
}
|
|
||||||
return tmpPattern;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getBitmapFor(int resId) {
|
private Bitmap getBitmapFor(int resId) {
|
||||||
@ -332,7 +303,7 @@ public class LockPatternView extends View {
|
|||||||
* @return Whether the view has tactile feedback enabled.
|
* @return Whether the view has tactile feedback enabled.
|
||||||
*/
|
*/
|
||||||
public boolean isTactileFeedbackEnabled() {
|
public boolean isTactileFeedbackEnabled() {
|
||||||
return mTactileFeedbackEnabled;
|
return mEnableHapticFeedback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -352,7 +323,7 @@ public class LockPatternView extends View {
|
|||||||
* @param tactileFeedbackEnabled Whether tactile feedback is enabled
|
* @param tactileFeedbackEnabled Whether tactile feedback is enabled
|
||||||
*/
|
*/
|
||||||
public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) {
|
public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) {
|
||||||
mTactileFeedbackEnabled = tactileFeedbackEnabled;
|
mEnableHapticFeedback = tactileFeedbackEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -573,8 +544,10 @@ public class LockPatternView extends View {
|
|||||||
addCellToPattern(fillInGapCell);
|
addCellToPattern(fillInGapCell);
|
||||||
}
|
}
|
||||||
addCellToPattern(cell);
|
addCellToPattern(cell);
|
||||||
if (mTactileFeedbackEnabled){
|
if (mEnableHapticFeedback) {
|
||||||
vibe.vibrate(mVibePattern, -1); // Generate tactile feedback
|
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
|
||||||
|
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
|
||||||
|
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||||
}
|
}
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
@ -1114,7 +1087,7 @@ public class LockPatternView extends View {
|
|||||||
return new SavedState(superState,
|
return new SavedState(superState,
|
||||||
LockPatternUtils.patternToString(mPattern),
|
LockPatternUtils.patternToString(mPattern),
|
||||||
mPatternDisplayMode.ordinal(),
|
mPatternDisplayMode.ordinal(),
|
||||||
mInputEnabled, mInStealthMode, mTactileFeedbackEnabled);
|
mInputEnabled, mInStealthMode, mEnableHapticFeedback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1127,7 +1100,7 @@ public class LockPatternView extends View {
|
|||||||
mPatternDisplayMode = DisplayMode.values()[ss.getDisplayMode()];
|
mPatternDisplayMode = DisplayMode.values()[ss.getDisplayMode()];
|
||||||
mInputEnabled = ss.isInputEnabled();
|
mInputEnabled = ss.isInputEnabled();
|
||||||
mInStealthMode = ss.isInStealthMode();
|
mInStealthMode = ss.isInStealthMode();
|
||||||
mTactileFeedbackEnabled = ss.isTactileFeedbackEnabled();
|
mEnableHapticFeedback = ss.isTactileFeedbackEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +26,7 @@ import android.os.SystemClock;
|
|||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -52,7 +53,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
|
|||||||
private final View mTargetView;
|
private final View mTargetView;
|
||||||
private final KeyboardView mKeyboardView;
|
private final KeyboardView mKeyboardView;
|
||||||
private long[] mVibratePattern;
|
private long[] mVibratePattern;
|
||||||
private final Vibrator mVibrator;
|
private boolean mEnableHaptics = false;
|
||||||
|
|
||||||
public PasswordEntryKeyboardHelper(Context context, KeyboardView keyboardView, View targetView) {
|
public PasswordEntryKeyboardHelper(Context context, KeyboardView keyboardView, View targetView) {
|
||||||
this(context, keyboardView, targetView, true);
|
this(context, keyboardView, targetView, true);
|
||||||
@ -71,7 +72,10 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
|
|||||||
mKeyboardView.getLayoutParams().height);
|
mKeyboardView.getLayoutParams().height);
|
||||||
}
|
}
|
||||||
mKeyboardView.setOnKeyboardActionListener(this);
|
mKeyboardView.setOnKeyboardActionListener(this);
|
||||||
mVibrator = new Vibrator();
|
}
|
||||||
|
|
||||||
|
public void setEnableHaptics(boolean enabled) {
|
||||||
|
mEnableHaptics = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlpha() {
|
public boolean isAlpha() {
|
||||||
@ -230,6 +234,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
|
|||||||
|
|
||||||
public void handleBackspace() {
|
public void handleBackspace() {
|
||||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
||||||
|
performHapticFeedback();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleShift() {
|
private void handleShift() {
|
||||||
@ -272,8 +277,14 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onPress(int primaryCode) {
|
public void onPress(int primaryCode) {
|
||||||
if (mVibratePattern != null) {
|
performHapticFeedback();
|
||||||
mVibrator.vibrate(mVibratePattern, -1);
|
}
|
||||||
|
|
||||||
|
private void performHapticFeedback() {
|
||||||
|
if (mEnableHaptics) {
|
||||||
|
mKeyboardView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
|
||||||
|
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
|
||||||
|
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import com.android.internal.widget.PasswordEntryKeyboardView;
|
|||||||
|
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
@ -109,6 +110,10 @@ public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen
|
|||||||
mPasswordEntry.setOnEditorActionListener(this);
|
mPasswordEntry.setOnEditorActionListener(this);
|
||||||
|
|
||||||
mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this, false);
|
mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this, false);
|
||||||
|
mKeyboardHelper.setEnableHaptics(
|
||||||
|
Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, 0)
|
||||||
|
!= 0);
|
||||||
if (mIsAlpha) {
|
if (mIsAlpha) {
|
||||||
// We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
|
// We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
|
||||||
mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
|
mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
|
||||||
@ -150,9 +155,6 @@ public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen
|
|||||||
//KeyguardStatusViewManager.LOCK_ICON);
|
//KeyguardStatusViewManager.LOCK_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
mKeyboardHelper.setVibratePattern(mLockPatternUtils.isTactileFeedbackEnabled() ?
|
|
||||||
com.android.internal.R.array.config_virtualKeyVibePattern : 0);
|
|
||||||
|
|
||||||
// Poke the wakelock any time the text is selected or modified
|
// Poke the wakelock any time the text is selected or modified
|
||||||
mPasswordEntry.setOnClickListener(new OnClickListener() {
|
mPasswordEntry.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
Reference in New Issue
Block a user