Announce keyboard language when TalkBack is on

Bug: 13013501
Change-Id: I0595abafbc177f776676cb3560f3990da9328db2
This commit is contained in:
Tadashi G. Takaoka 2014-04-22 12:14:08 -07:00
parent 5179608e19
commit 3cf759074a

View file

@ -34,6 +34,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat { public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
private static final AccessibleKeyboardViewProxy sInstance = new AccessibleKeyboardViewProxy(); private static final AccessibleKeyboardViewProxy sInstance = new AccessibleKeyboardViewProxy();
@ -66,8 +67,8 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
private int mEdgeSlop; private int mEdgeSlop;
/** The most recently set keyboard mode. */ /** The most recently set keyboard mode. */
private int mLastKeyboardMode; private int mLastKeyboardMode = KEYBOARD_IS_HIDDEN;
private static final int NOT_A_KEYBOARD_MODE = -1; private static final int KEYBOARD_IS_HIDDEN = -1;
public static void init(final InputMethodService inputMethod) { public static void init(final InputMethodService inputMethod) {
sInstance.initInternal(inputMethod); sInstance.initInternal(inputMethod);
@ -123,20 +124,27 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
if (keyboard == null) { if (keyboard == null) {
return; return;
} }
mKeyboard = keyboard;
if (mAccessibilityNodeProvider != null) { if (mAccessibilityNodeProvider != null) {
mAccessibilityNodeProvider.setKeyboard(keyboard); mAccessibilityNodeProvider.setKeyboard(keyboard);
} }
final int keyboardMode = keyboard.mId.mMode; final Keyboard lastKeyboard = mKeyboard;
final int lastKeyboardMode = mLastKeyboardMode;
mKeyboard = keyboard;
mLastKeyboardMode = keyboard.mId.mMode;
// Since this method is called even when accessibility is off, make sure // Since this method is called even when accessibility is off, make sure
// to check the state before announcing anything. Also, don't announce // to check the state before announcing anything.
// changes within the same mode. if (!AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
if (AccessibilityUtils.getInstance().isAccessibilityEnabled() return;
&& (mLastKeyboardMode != keyboardMode)) { }
announceKeyboardMode(keyboardMode); // Announce the language name only when the language is changed.
if (lastKeyboard == null || !lastKeyboard.mId.mSubtype.equals(keyboard.mId.mSubtype)) {
announceKeyboardLanguage(keyboard);
}
// Announce the mode only when the mode is changed.
if (lastKeyboardMode != keyboard.mId.mMode) {
announceKeyboardMode(keyboard);
} }
mLastKeyboardMode = keyboardMode;
} }
/** /**
@ -147,23 +155,35 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
return; return;
} }
announceKeyboardHidden(); announceKeyboardHidden();
mLastKeyboardMode = NOT_A_KEYBOARD_MODE; mLastKeyboardMode = KEYBOARD_IS_HIDDEN;
} }
/** /**
* Announces which type of keyboard is being displayed. If the keyboard type * Announces which language of keyboard is being displayed.
* is unknown, no announcement is made.
* *
* @param mode The new keyboard mode. * @param keyboard The new keyboard.
*/ */
private void announceKeyboardMode(final int mode) { private void announceKeyboardLanguage(final Keyboard keyboard) {
final int resId = KEYBOARD_MODE_RES_IDS.get(mode); final String languageText = SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(
if (resId == 0) { keyboard.mId.mSubtype);
sendWindowStateChanged(languageText);
}
/**
* Announces which type of keyboard is being displayed.
* If the keyboard type is unknown, no announcement is made.
*
* @param keyboard The new keyboard.
*/
private void announceKeyboardMode(final Keyboard keyboard) {
final int mode = keyboard.mId.mMode;
final Context context = mView.getContext();
final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(mode);
if (modeTextResId == 0) {
return; return;
} }
final Context context = mView.getContext(); final String modeText = context.getString(modeTextResId);
final String keyboardMode = context.getString(resId); final String text = context.getString(R.string.announce_keyboard_mode, modeText);
final String text = context.getString(R.string.announce_keyboard_mode, keyboardMode);
sendWindowStateChanged(text); sendWindowStateChanged(text);
} }