Merge "Adding accessibility support to the pattern lock."

This commit is contained in:
Svetoslav Ganov
2011-10-10 17:39:54 -07:00
committed by Android (Google) Code Review
2 changed files with 79 additions and 17 deletions

View File

@@ -17,8 +17,6 @@
package com.android.internal.widget; package com.android.internal.widget;
import com.android.internal.R;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@@ -39,6 +37,10 @@ import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
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.AccessibilityManager;
import com.android.internal.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -401,6 +403,34 @@ public class LockPatternView extends View {
invalidate(); invalidate();
} }
private void notifyCellAdded() {
if (mOnPatternListener != null) {
mOnPatternListener.onPatternCellAdded(mPattern);
}
sendAccessEvent(R.string.lockscreen_access_pattern_cell_added);
}
private void notifyPatternStarted() {
if (mOnPatternListener != null) {
mOnPatternListener.onPatternStart();
}
sendAccessEvent(R.string.lockscreen_access_pattern_start);
}
private void notifyPatternDetected() {
if (mOnPatternListener != null) {
mOnPatternListener.onPatternDetected(mPattern);
}
sendAccessEvent(R.string.lockscreen_access_pattern_detected);
}
private void notifyPatternCleared() {
if (mOnPatternListener != null) {
mOnPatternListener.onPatternCleared();
}
sendAccessEvent(R.string.lockscreen_access_pattern_cleared);
}
/** /**
* Clear the pattern. * Clear the pattern.
*/ */
@@ -554,9 +584,7 @@ public class LockPatternView extends View {
private void addCellToPattern(Cell newCell) { private void addCellToPattern(Cell newCell) {
mPatternDrawLookup[newCell.getRow()][newCell.getColumn()] = true; mPatternDrawLookup[newCell.getRow()][newCell.getColumn()] = true;
mPattern.add(newCell); mPattern.add(newCell);
if (mOnPatternListener != null) { notifyCellAdded();
mOnPatternListener.onPatternCellAdded(mPattern);
}
} }
// helper method to find which cell a point maps to // helper method to find which cell a point maps to
@@ -618,6 +646,27 @@ public class LockPatternView extends View {
return -1; return -1;
} }
@Override
public boolean onHoverEvent(MotionEvent event) {
if (AccessibilityManager.getInstance(mContext).isTouchExplorationEnabled()) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_HOVER_ENTER:
event.setAction(MotionEvent.ACTION_DOWN);
break;
case MotionEvent.ACTION_HOVER_MOVE:
event.setAction(MotionEvent.ACTION_MOVE);
break;
case MotionEvent.ACTION_HOVER_EXIT:
event.setAction(MotionEvent.ACTION_UP);
break;
}
onTouchEvent(event);
event.setAction(action);
}
return super.onHoverEvent(event);
}
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if (!mInputEnabled || !isEnabled()) { if (!mInputEnabled || !isEnabled()) {
@@ -636,10 +685,8 @@ public class LockPatternView extends View {
return true; return true;
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
resetPattern(); resetPattern();
if (mOnPatternListener != null) { mPatternInProgress = false;
mPatternInProgress = false; notifyPatternCleared();
mOnPatternListener.onPatternCleared();
}
if (PROFILE_DRAWING) { if (PROFILE_DRAWING) {
if (mDrawingProfilingStarted) { if (mDrawingProfilingStarted) {
Debug.stopMethodTracing(); Debug.stopMethodTracing();
@@ -661,9 +708,9 @@ public class LockPatternView extends View {
final int patternSizePreHitDetect = mPattern.size(); final int patternSizePreHitDetect = mPattern.size();
Cell hitCell = detectAndAddHit(x, y); Cell hitCell = detectAndAddHit(x, y);
final int patternSize = mPattern.size(); final int patternSize = mPattern.size();
if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) { if (hitCell != null && patternSize == 1) {
mPatternInProgress = true; mPatternInProgress = true;
mOnPatternListener.onPatternStart(); notifyPatternStarted();
} }
// note current x and y for rubber banding of in progress patterns // note current x and y for rubber banding of in progress patterns
final float dx = Math.abs(x - mInProgressX); final float dx = Math.abs(x - mInProgressX);
@@ -778,11 +825,17 @@ public class LockPatternView extends View {
} }
} }
private void sendAccessEvent(int resId) {
setContentDescription(mContext.getString(resId));
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
setContentDescription(null);
}
private void handleActionUp(MotionEvent event) { private void handleActionUp(MotionEvent event) {
// report pattern detected // report pattern detected
if (!mPattern.isEmpty() && mOnPatternListener != null) { if (!mPattern.isEmpty()) {
mPatternInProgress = false; mPatternInProgress = false;
mOnPatternListener.onPatternDetected(mPattern); notifyPatternDetected();
invalidate(); invalidate();
} }
if (PROFILE_DRAWING) { if (PROFILE_DRAWING) {
@@ -798,13 +851,13 @@ public class LockPatternView extends View {
final float x = event.getX(); final float x = event.getX();
final float y = event.getY(); final float y = event.getY();
final Cell hitCell = detectAndAddHit(x, y); final Cell hitCell = detectAndAddHit(x, y);
if (hitCell != null && mOnPatternListener != null) { if (hitCell != null) {
mPatternInProgress = true; mPatternInProgress = true;
mPatternDisplayMode = DisplayMode.Correct; mPatternDisplayMode = DisplayMode.Correct;
mOnPatternListener.onPatternStart(); notifyPatternStarted();
} else if (mOnPatternListener != null) { } else {
mPatternInProgress = false; mPatternInProgress = false;
mOnPatternListener.onPatternCleared(); notifyPatternCleared();
} }
if (hitCell != null) { if (hitCell != null) {
final float startX = getCenterXForColumn(hitCell.column); final float startX = getCenterXForColumn(hitCell.column);

View File

@@ -1958,6 +1958,15 @@
<!-- Displayed on lock screen's right tab - turn sound off --> <!-- Displayed on lock screen's right tab - turn sound off -->
<string name="lockscreen_sound_off_label">Sound off</string> <string name="lockscreen_sound_off_label">Sound off</string>
<!-- Accessibility description sent when user starts drawing a lock pattern. [CHAR LIMIT=NONE] -->
<string name="lockscreen_access_pattern_start">Pattern started</string>
<!-- Accessibility description sent when the pattern times out and is cleared. [CHAR LIMIT=NONE] -->
<string name="lockscreen_access_pattern_cleared">Pattern cleared</string>
<!-- Accessibility description sent when user adds a cell to the pattern. [CHAR LIMIT=NONE] -->
<string name="lockscreen_access_pattern_cell_added">Cell added</string>
<!-- Accessibility description sent when user completes drawing a pattern. [CHAR LIMIT=NONE] -->
<string name="lockscreen_access_pattern_detected">Pattern completed</string>
<!-- Password keyboard strings. Used by LockScreen and Settings --><skip /> <!-- Password keyboard strings. Used by LockScreen and Settings --><skip />
<!-- Label for "switch to symbols" key. Must be short to fit on key! --> <!-- Label for "switch to symbols" key. Must be short to fit on key! -->
<string name="password_keyboard_label_symbol_key">\?123</string> <string name="password_keyboard_label_symbol_key">\?123</string>