Skip to content

Commit 63f5e09

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Make prompt for headset while typing a password if accessibilbity is on less verbose."
2 parents df5d7c8 + bd39ca7 commit 63f5e09

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,8 +3229,9 @@
32293229
<string name="description_target_soundon">Sound on</string>
32303230

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

32353236
<!-- Content description for the action bar "home" affordance. [CHAR LIMIT=NONE] -->
32363237
<string name="action_bar_home_description">Navigate home</string>

0 commit comments

Comments
 (0)