Merge "Make prompt for headset while typing a password if accessibilbity is on less verbose."

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

View File

@@ -248,6 +248,8 @@ public class KeyboardView extends View implements View.OnClickListener {
private AccessibilityManager mAccessibilityManager; private AccessibilityManager mAccessibilityManager;
/** The audio manager for accessibility support */ /** The audio manager for accessibility support */
private AudioManager mAudioManager; private AudioManager mAudioManager;
/** Whether the requirement of a headset to hear passwords if accessibility is enabled is announced. */
private boolean mHeadsetRequiredToHearPasswordsAnnounced;
Handler mHandler = new Handler() { Handler mHandler = new Handler() {
@Override @Override
@@ -852,13 +854,15 @@ public class KeyboardView extends View implements View.OnClickListener {
Key oldKey = keys[oldKeyIndex]; Key oldKey = keys[oldKeyIndex];
oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY); oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
invalidateKey(oldKeyIndex); invalidateKey(oldKeyIndex);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, oldKey.codes[0]); sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
oldKey.codes[0]);
} }
if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) { if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
Key newKey = keys[mCurrentKeyIndex]; Key newKey = keys[mCurrentKeyIndex];
newKey.onPressed(); newKey.onPressed();
invalidateKey(mCurrentKeyIndex); invalidateKey(mCurrentKeyIndex);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, newKey.codes[0]); sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER,
newKey.codes[0]);
} }
} }
// If key changed and preview is on ... // If key changed and preview is on ...
@@ -958,13 +962,13 @@ public class KeyboardView extends View implements View.OnClickListener {
mPreviewText.setVisibility(VISIBLE); mPreviewText.setVisibility(VISIBLE);
} }
private void sendAccessibilityEvent(int eventType, int code) { private void sendAccessibilityEventForUnicodeCharacter(int eventType, int code) {
if (mAccessibilityManager.isEnabled()) { if (mAccessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType); AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
onInitializeAccessibilityEvent(event); onInitializeAccessibilityEvent(event);
String text = null;
// Add text only if headset is used to avoid leaking passwords. // Add text only if headset is used to avoid leaking passwords.
if (mAudioManager.isBluetoothA2dpOn() || mAudioManager.isWiredHeadsetOn()) { if (mAudioManager.isBluetoothA2dpOn() || mAudioManager.isWiredHeadsetOn()) {
String text = null;
switch (code) { switch (code) {
case Keyboard.KEYCODE_ALT: case Keyboard.KEYCODE_ALT:
text = mContext.getString(R.string.keyboardview_keycode_alt); text = mContext.getString(R.string.keyboardview_keycode_alt);
@@ -990,11 +994,17 @@ public class KeyboardView extends View implements View.OnClickListener {
default: default:
text = String.valueOf((char) code); text = String.valueOf((char) code);
} }
event.getText().add(text); } else if (!mHeadsetRequiredToHearPasswordsAnnounced) {
// We want the waring for required head set to be send with both the
// hover enter and hover exit event, so set the flag after the exit.
if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
mHeadsetRequiredToHearPasswordsAnnounced = true;
}
text = mContext.getString(R.string.keyboard_headset_required_to_hear_password);
} else { } else {
event.getText().add(mContext.getString( text = mContext.getString(R.string.keyboard_password_character_no_headset);
R.string.keyboard_headset_required_to_hear_password));
} }
event.getText().add(text);
mAccessibilityManager.sendAccessibilityEvent(event); mAccessibilityManager.sendAccessibilityEvent(event);
} }
} }
@@ -1134,15 +1144,13 @@ public class KeyboardView extends View implements View.OnClickListener {
} }
@Override @Override
protected boolean dispatchHoverEvent(MotionEvent event) { public boolean onHoverEvent(MotionEvent event) {
// If touch exploring is enabled we ignore touch events and transform // If touch exploring is enabled we ignore touch events and transform
// the stream of hover events as touch events. This allows one consistent // the stream of hover events as touch events. This allows one consistent
// event stream to drive the keyboard since during touch exploring the // event stream to drive the keyboard since during touch exploring the
// first touch generates only hover events and tapping on the same // first touch generates only hover events and tapping on the same
// location generates hover and touch events. // location generates hover and touch events.
if (mAccessibilityManager.isEnabled() if (mAccessibilityManager.isTouchExplorationEnabled() && event.getPointerCount() == 1) {
&& mAccessibilityManager.isTouchExplorationEnabled()
&& event.getPointerCount() == 1) {
final int action = event.getAction(); final int action = event.getAction();
switch (action) { switch (action) {
case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_ENTER:
@@ -1156,9 +1164,9 @@ public class KeyboardView extends View implements View.OnClickListener {
break; break;
} }
onTouchEventInternal(event); onTouchEventInternal(event);
return true; event.setAction(action);
} }
return super.dispatchHoverEvent(event); return super.onHoverEvent(event);
} }
@Override @Override
@@ -1168,8 +1176,7 @@ public class KeyboardView extends View implements View.OnClickListener {
// event stream to drive the keyboard since during touch exploring the // event stream to drive the keyboard since during touch exploring the
// first touch generates only hover events and tapping on the same // first touch generates only hover events and tapping on the same
// location generates hover and touch events. // location generates hover and touch events.
if (mAccessibilityManager.isEnabled() if (mAccessibilityManager.isTouchExplorationEnabled()) {
&& mAccessibilityManager.isTouchExplorationEnabled()) {
return true; return true;
} }
return onTouchEventInternal(event); return onTouchEventInternal(event);

View File

@@ -3229,8 +3229,9 @@
<string name="description_target_soundon">Sound on</string> <string name="description_target_soundon">Sound on</string>
<!-- Announce that a headset is required to hear keyboard keys while typing a password. [CHAR LIMIT=NONE] --> <!-- Announce that a headset is required to hear keyboard keys while typing a password. [CHAR LIMIT=NONE] -->
<string name="keyboard_headset_required_to_hear_password">Key. Headset required to hear <string name="keyboard_headset_required_to_hear_password">Plug in a headset to hear password keys spoken aloud.</string>
keys while typing a password.</string> <!-- The value of a keyboard key announced when accessibility is enabled and no headsed is used. [CHAR LIMIT=NONE] -->
<string name="keyboard_password_character_no_headset">Dot.</string>
<!-- Content description for the action bar "home" affordance. [CHAR LIMIT=NONE] --> <!-- Content description for the action bar "home" affordance. [CHAR LIMIT=NONE] -->
<string name="action_bar_home_description">Navigate home</string> <string name="action_bar_home_description">Navigate home</string>