Merge "Fix 5444675: Fix vibrate regression on Pattern and PIN unlock screens." into ics-mr0

This commit is contained in:
Jim Miller
2011-10-12 18:49:25 -07:00
committed by Android (Google) Code Review
3 changed files with 30 additions and 44 deletions

View File

@ -32,9 +32,9 @@ import android.os.Debug;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
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_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 boolean mDrawingProfilingStarted = false;
@ -102,7 +99,7 @@ public class LockPatternView extends View {
private DisplayMode mPatternDisplayMode = DisplayMode.Correct;
private boolean mInputEnabled = true;
private boolean mInStealthMode = false;
private boolean mTactileFeedbackEnabled = true;
private boolean mEnableHapticFeedback = true;
private boolean mPatternInProgress = false;
private float mDiameterFactor = 0.10f; // TODO: move to attrs
@ -127,11 +124,6 @@ public class LockPatternView extends View {
private int mBitmapWidth;
private int mBitmapHeight;
private Vibrator vibe; // Vibrator for creating tactile feedback
private long[] mVibePattern;
private int mAspect;
private final Matrix mArrowMatrix = new Matrix();
private final Matrix mCircleMatrix = new Matrix();
@ -250,7 +242,6 @@ public class LockPatternView extends View {
public LockPatternView(Context context, AttributeSet attrs) {
super(context, attrs);
vibe = new Vibrator();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LockPatternView);
@ -295,26 +286,6 @@ public class LockPatternView extends View {
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) {
@ -332,7 +303,7 @@ public class LockPatternView extends View {
* @return Whether the view has tactile feedback enabled.
*/
public boolean isTactileFeedbackEnabled() {
return mTactileFeedbackEnabled;
return mEnableHapticFeedback;
}
/**
@ -352,7 +323,7 @@ public class LockPatternView extends View {
* @param tactileFeedbackEnabled Whether tactile feedback is enabled
*/
public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) {
mTactileFeedbackEnabled = tactileFeedbackEnabled;
mEnableHapticFeedback = tactileFeedbackEnabled;
}
/**
@ -573,8 +544,10 @@ public class LockPatternView extends View {
addCellToPattern(fillInGapCell);
}
addCellToPattern(cell);
if (mTactileFeedbackEnabled){
vibe.vibrate(mVibePattern, -1); // Generate tactile feedback
if (mEnableHapticFeedback) {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
return cell;
}
@ -1114,7 +1087,7 @@ public class LockPatternView extends View {
return new SavedState(superState,
LockPatternUtils.patternToString(mPattern),
mPatternDisplayMode.ordinal(),
mInputEnabled, mInStealthMode, mTactileFeedbackEnabled);
mInputEnabled, mInStealthMode, mEnableHapticFeedback);
}
@Override
@ -1127,7 +1100,7 @@ public class LockPatternView extends View {
mPatternDisplayMode = DisplayMode.values()[ss.getDisplayMode()];
mInputEnabled = ss.isInputEnabled();
mInStealthMode = ss.isInStealthMode();
mTactileFeedbackEnabled = ss.isTactileFeedbackEnabled();
mEnableHapticFeedback = ss.isTactileFeedbackEnabled();
}
/**

View File

@ -26,6 +26,7 @@ import android.os.SystemClock;
import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
@ -52,7 +53,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
private final View mTargetView;
private final KeyboardView mKeyboardView;
private long[] mVibratePattern;
private final Vibrator mVibrator;
private boolean mEnableHaptics = false;
public PasswordEntryKeyboardHelper(Context context, KeyboardView keyboardView, View targetView) {
this(context, keyboardView, targetView, true);
@ -71,7 +72,10 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
mKeyboardView.getLayoutParams().height);
}
mKeyboardView.setOnKeyboardActionListener(this);
mVibrator = new Vibrator();
}
public void setEnableHaptics(boolean enabled) {
mEnableHaptics = enabled;
}
public boolean isAlpha() {
@ -230,6 +234,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
public void handleBackspace() {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
performHapticFeedback();
}
private void handleShift() {
@ -272,8 +277,14 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
}
public void onPress(int primaryCode) {
if (mVibratePattern != null) {
mVibrator.vibrate(mVibratePattern, -1);
performHapticFeedback();
}
private void performHapticFeedback() {
if (mEnableHaptics) {
mKeyboardView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
}

View File

@ -28,6 +28,7 @@ import com.android.internal.widget.PasswordEntryKeyboardView;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.provider.Settings;
import android.security.KeyStore;
import android.text.Editable;
import android.text.InputType;
@ -109,6 +110,10 @@ public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen
mPasswordEntry.setOnEditorActionListener(this);
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) {
// We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
@ -150,9 +155,6 @@ public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen
//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
mPasswordEntry.setOnClickListener(new OnClickListener() {
public void onClick(View v) {