3232import android .os .Parcel ;
3333import android .os .Parcelable ;
3434import android .os .SystemClock ;
35- import android .os .Vibrator ;
3635import android .util .AttributeSet ;
3736import android .util .Log ;
37+ import android .view .HapticFeedbackConstants ;
3838import android .view .MotionEvent ;
3939import android .view .View ;
4040import android .view .accessibility .AccessibilityEvent ;
@@ -59,9 +59,6 @@ public class LockPatternView extends View {
5959 private static final int ASPECT_LOCK_WIDTH = 1 ; // Fixed width; height will be minimum of (w,h)
6060 private static final int ASPECT_LOCK_HEIGHT = 2 ; // Fixed height; width will be minimum of (w,h)
6161
62- // Vibrator pattern for creating a tactile bump
63- private static final long [] DEFAULT_VIBE_PATTERN = {0 , 1 , 40 , 41 };
64-
6562 private static final boolean PROFILE_DRAWING = false ;
6663 private boolean mDrawingProfilingStarted = false ;
6764
@@ -102,7 +99,7 @@ public class LockPatternView extends View {
10299 private DisplayMode mPatternDisplayMode = DisplayMode .Correct ;
103100 private boolean mInputEnabled = true ;
104101 private boolean mInStealthMode = false ;
105- private boolean mTactileFeedbackEnabled = true ;
102+ private boolean mEnableHapticFeedback = true ;
106103 private boolean mPatternInProgress = false ;
107104
108105 private float mDiameterFactor = 0.10f ; // TODO: move to attrs
@@ -127,11 +124,6 @@ public class LockPatternView extends View {
127124 private int mBitmapWidth ;
128125 private int mBitmapHeight ;
129126
130-
131- private Vibrator vibe ; // Vibrator for creating tactile feedback
132-
133- private long [] mVibePattern ;
134-
135127 private int mAspect ;
136128 private final Matrix mArrowMatrix = new Matrix ();
137129 private final Matrix mCircleMatrix = new Matrix ();
@@ -250,7 +242,6 @@ public LockPatternView(Context context) {
250242
251243 public LockPatternView (Context context , AttributeSet attrs ) {
252244 super (context , attrs );
253- vibe = new Vibrator ();
254245
255246 TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .LockPatternView );
256247
@@ -295,26 +286,6 @@ public LockPatternView(Context context, AttributeSet attrs) {
295286 mBitmapHeight = Math .max (mBitmapHeight , bitmap .getHeight ());
296287 }
297288
298- // allow vibration pattern to be customized
299- mVibePattern = loadVibratePattern (com .android .internal .R .array .config_virtualKeyVibePattern );
300- }
301-
302- private long [] loadVibratePattern (int id ) {
303- int [] pattern = null ;
304- try {
305- pattern = getResources ().getIntArray (id );
306- } catch (Resources .NotFoundException e ) {
307- Log .e (TAG , "Vibrate pattern missing, using default" , e );
308- }
309- if (pattern == null ) {
310- return DEFAULT_VIBE_PATTERN ;
311- }
312-
313- long [] tmpPattern = new long [pattern .length ];
314- for (int i = 0 ; i < pattern .length ; i ++) {
315- tmpPattern [i ] = pattern [i ];
316- }
317- return tmpPattern ;
318289 }
319290
320291 private Bitmap getBitmapFor (int resId ) {
@@ -332,7 +303,7 @@ public boolean isInStealthMode() {
332303 * @return Whether the view has tactile feedback enabled.
333304 */
334305 public boolean isTactileFeedbackEnabled () {
335- return mTactileFeedbackEnabled ;
306+ return mEnableHapticFeedback ;
336307 }
337308
338309 /**
@@ -352,7 +323,7 @@ public void setInStealthMode(boolean inStealthMode) {
352323 * @param tactileFeedbackEnabled Whether tactile feedback is enabled
353324 */
354325 public void setTactileFeedbackEnabled (boolean tactileFeedbackEnabled ) {
355- mTactileFeedbackEnabled = tactileFeedbackEnabled ;
326+ mEnableHapticFeedback = tactileFeedbackEnabled ;
356327 }
357328
358329 /**
@@ -573,8 +544,10 @@ private Cell detectAndAddHit(float x, float y) {
573544 addCellToPattern (fillInGapCell );
574545 }
575546 addCellToPattern (cell );
576- if (mTactileFeedbackEnabled ){
577- vibe .vibrate (mVibePattern , -1 ); // Generate tactile feedback
547+ if (mEnableHapticFeedback ) {
548+ performHapticFeedback (HapticFeedbackConstants .VIRTUAL_KEY ,
549+ HapticFeedbackConstants .FLAG_IGNORE_VIEW_SETTING
550+ | HapticFeedbackConstants .FLAG_IGNORE_GLOBAL_SETTING );
578551 }
579552 return cell ;
580553 }
@@ -1114,7 +1087,7 @@ protected Parcelable onSaveInstanceState() {
11141087 return new SavedState (superState ,
11151088 LockPatternUtils .patternToString (mPattern ),
11161089 mPatternDisplayMode .ordinal (),
1117- mInputEnabled , mInStealthMode , mTactileFeedbackEnabled );
1090+ mInputEnabled , mInStealthMode , mEnableHapticFeedback );
11181091 }
11191092
11201093 @ Override
@@ -1127,7 +1100,7 @@ protected void onRestoreInstanceState(Parcelable state) {
11271100 mPatternDisplayMode = DisplayMode .values ()[ss .getDisplayMode ()];
11281101 mInputEnabled = ss .isInputEnabled ();
11291102 mInStealthMode = ss .isInStealthMode ();
1130- mTactileFeedbackEnabled = ss .isTactileFeedbackEnabled ();
1103+ mEnableHapticFeedback = ss .isTactileFeedbackEnabled ();
11311104 }
11321105
11331106 /**
0 commit comments