am e2651aa4: Merge "Announce keyboard language when TalkBack is on"

* commit 'e2651aa450c7cf81406a943ea361809b27331535':
  Announce keyboard language when TalkBack is on
main
Tadashi G. Takaoka 2014-04-24 20:42:41 +00:00 committed by Android Git Automerger
commit 847eda529b
1 changed files with 40 additions and 20 deletions

View File

@ -35,6 +35,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();
@ -67,8 +68,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);
@ -124,20 +125,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;
} }
/** /**
@ -148,23 +156,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);
} }