@@ -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 );
0 commit comments