Skip to content

Commit bd39ca7

Browse files
committed
Make prompt for headset while typing a password if accessibilbity is on less verbose.
If accessibility is enabled and there is no headset we do not speak the pressed keys. In such a case we provide a prompt to the blind user to use a headset. This was announced on every keypress which is quite annoying. Now this is announced only once. bug:5342234 Change-Id: Ibe55ad991ad2153d09cde57b030544948fa0d73b
1 parent b11d09c commit bd39ca7

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

core/java/android/inputmethodservice/KeyboardView.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ public interface OnKeyboardActionListener {
248248
private AccessibilityManager mAccessibilityManager;
249249
/** The audio manager for accessibility support */
250250
private AudioManager mAudioManager;
251+
/** Whether the requirement of a headset to hear passwords if accessibility is enabled is announced. */
252+
private boolean mHeadsetRequiredToHearPasswordsAnnounced;
251253

252254
Handler mHandler = new Handler() {
253255
@Override
@@ -852,13 +854,15 @@ private void showPreview(int keyIndex) {
852854
Key oldKey = keys[oldKeyIndex];
853855
oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
854856
invalidateKey(oldKeyIndex);
855-
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, oldKey.codes[0]);
857+
sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
858+
oldKey.codes[0]);
856859
}
857860
if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
858861
Key newKey = keys[mCurrentKeyIndex];
859862
newKey.onPressed();
860863
invalidateKey(mCurrentKeyIndex);
861-
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, newKey.codes[0]);
864+
sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER,
865+
newKey.codes[0]);
862866
}
863867
}
864868
// If key changed and preview is on ...
@@ -958,13 +962,13 @@ private void showKey(final int keyIndex) {
958962
mPreviewText.setVisibility(VISIBLE);
959963
}
960964

961-
private void sendAccessibilityEvent(int eventType, int code) {
965+
private void sendAccessibilityEventForUnicodeCharacter(int eventType, int code) {
962966
if (mAccessibilityManager.isEnabled()) {
963967
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
964968
onInitializeAccessibilityEvent(event);
969+
String text = null;
965970
// Add text only if headset is used to avoid leaking passwords.
966971
if (mAudioManager.isBluetoothA2dpOn() || mAudioManager.isWiredHeadsetOn()) {
967-
String text = null;
968972
switch (code) {
969973
case Keyboard.KEYCODE_ALT:
970974
text = mContext.getString(R.string.keyboardview_keycode_alt);
@@ -990,11 +994,17 @@ private void sendAccessibilityEvent(int eventType, int code) {
990994
default:
991995
text = String.valueOf((char) code);
992996
}
993-
event.getText().add(text);
997+
} else if (!mHeadsetRequiredToHearPasswordsAnnounced) {
998+
// We want the waring for required head set to be send with both the
999+
// hover enter and hover exit event, so set the flag after the exit.
1000+
if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
1001+
mHeadsetRequiredToHearPasswordsAnnounced = true;
1002+
}
1003+
text = mContext.getString(R.string.keyboard_headset_required_to_hear_password);
9941004
} else {
995-
event.getText().add(mContext.getString(
996-
R.string.keyboard_headset_required_to_hear_password));
1005+
text = mContext.getString(R.string.keyboard_password_character_no_headset);
9971006
}
1007+
event.getText().add(text);
9981008
mAccessibilityManager.sendAccessibilityEvent(event);
9991009
}
10001010
}
@@ -1134,15 +1144,13 @@ public void onRelease(int primaryCode) {
11341144
}
11351145

11361146
@Override
1137-
protected boolean dispatchHoverEvent(MotionEvent event) {
1147+
public boolean onHoverEvent(MotionEvent event) {
11381148
// If touch exploring is enabled we ignore touch events and transform
11391149
// the stream of hover events as touch events. This allows one consistent
11401150
// event stream to drive the keyboard since during touch exploring the
11411151
// first touch generates only hover events and tapping on the same
11421152
// location generates hover and touch events.
1143-
if (mAccessibilityManager.isEnabled()
1144-
&& mAccessibilityManager.isTouchExplorationEnabled()
1145-
&& event.getPointerCount() == 1) {
1153+
if (mAccessibilityManager.isTouchExplorationEnabled() && event.getPointerCount() == 1) {
11461154
final int action = event.getAction();
11471155
switch (action) {
11481156
case MotionEvent.ACTION_HOVER_ENTER:
@@ -1156,9 +1164,9 @@ protected boolean dispatchHoverEvent(MotionEvent event) {
11561164
break;
11571165
}
11581166
onTouchEventInternal(event);
1159-
return true;
1167+
event.setAction(action);
11601168
}
1161-
return super.dispatchHoverEvent(event);
1169+
return super.onHoverEvent(event);
11621170
}
11631171

11641172
@Override
@@ -1168,8 +1176,7 @@ public boolean onTouchEvent(MotionEvent event) {
11681176
// event stream to drive the keyboard since during touch exploring the
11691177
// first touch generates only hover events and tapping on the same
11701178
// location generates hover and touch events.
1171-
if (mAccessibilityManager.isEnabled()
1172-
&& mAccessibilityManager.isTouchExplorationEnabled()) {
1179+
if (mAccessibilityManager.isTouchExplorationEnabled()) {
11731180
return true;
11741181
}
11751182
return onTouchEventInternal(event);

core/res/res/values/strings.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,8 +3206,9 @@
32063206
<string name="description_target_soundon">Sound on</string>
32073207

32083208
<!-- Announce that a headset is required to hear keyboard keys while typing a password. [CHAR LIMIT=NONE] -->
3209-
<string name="keyboard_headset_required_to_hear_password">Key. Headset required to hear
3210-
keys while typing a password.</string>
3209+
<string name="keyboard_headset_required_to_hear_password">Plug in a headset to hear password keys spoken aloud.</string>
3210+
<!-- The value of a keyboard key announced when accessibility is enabled and no headsed is used. [CHAR LIMIT=NONE] -->
3211+
<string name="keyboard_password_character_no_headset">Dot.</string>
32113212

32123213
<!-- Content description for the action bar "home" affordance. [CHAR LIMIT=NONE] -->
32133214
<string name="action_bar_home_description">Navigate home</string>
@@ -3306,4 +3307,4 @@
33063307
<!-- Delimeter used between each item in a textual list; for example "Alpha, Beta". [CHAR LIMIT=3] -->
33073308
<string name="list_delimeter">", "</string>
33083309

3309-
</resources>
3310+
</resources>

0 commit comments

Comments
 (0)