From 0464850e6c27eaad642b9dacad44e654cab120ae Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Jun 2011 18:33:49 +0900 Subject: Add key description for "fullwidth asterisk" used on phone/number layout This change also removes non-ASCII comment from strings.xml to suppress resource compiler warning. Change-Id: I96d3e8e2c7072816f32a15564745f8cdc3f91ee9 --- .../com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java | 1 + 1 file changed, 1 insertion(+) (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index a31911d60..d196c8955 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -85,6 +85,7 @@ public class KeyCodeDescriptionMapper { mKeyCodeMap.put((int) '\u2105', R.string.spoken_description_care_of); mKeyCodeMap.put((int) '\u2026', R.string.spoken_description_ellipsis); mKeyCodeMap.put((int) '\u201E', R.string.spoken_description_low_double_quote); + mKeyCodeMap.put((int) '\uFF0A', R.string.spoken_description_star); // Special non-character codes defined in Keyboard mKeyCodeMap.put(Keyboard.CODE_DELETE, R.string.spoken_description_delete); -- cgit v1.2.3-83-g751a From 60ccbe16eea5ce9a874835850f257b3c88295022 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 26 Jul 2011 17:22:58 -0700 Subject: Clean up keyboard loading and switching Bug: 4311428 Change-Id: Ia72de23634f824d82b7b5f2267d439ce922a3b57 --- java/res/xml-sw600dp/kbd_phone_shift.xml | 133 ++++++++++++++++++ java/res/xml-sw600dp/kbd_phone_symbols.xml | 133 ------------------ java/res/xml-sw768dp/kbd_phone_shift.xml | 156 +++++++++++++++++++++ java/res/xml-sw768dp/kbd_phone_symbols.xml | 156 --------------------- java/res/xml/kbd_numkey_styles.xml | 4 +- java/res/xml/kbd_phone_shift.xml | 88 ++++++++++++ java/res/xml/kbd_phone_symbols.xml | 88 ------------ .../accessibility/KeyCodeDescriptionMapper.java | 2 +- .../android/inputmethod/keyboard/KeyboardId.java | 10 +- .../inputmethod/keyboard/KeyboardSwitcher.java | 146 ++++++++----------- .../com/android/inputmethod/latin/Settings.java | 16 +-- 11 files changed, 449 insertions(+), 483 deletions(-) create mode 100644 java/res/xml-sw600dp/kbd_phone_shift.xml delete mode 100644 java/res/xml-sw600dp/kbd_phone_symbols.xml create mode 100644 java/res/xml-sw768dp/kbd_phone_shift.xml delete mode 100644 java/res/xml-sw768dp/kbd_phone_symbols.xml create mode 100644 java/res/xml/kbd_phone_shift.xml delete mode 100644 java/res/xml/kbd_phone_symbols.xml (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/res/xml-sw600dp/kbd_phone_shift.xml b/java/res/xml-sw600dp/kbd_phone_shift.xml new file mode 100644 index 000000000..483964526 --- /dev/null +++ b/java/res/xml-sw600dp/kbd_phone_shift.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml-sw600dp/kbd_phone_symbols.xml b/java/res/xml-sw600dp/kbd_phone_symbols.xml deleted file mode 100644 index 483964526..000000000 --- a/java/res/xml-sw600dp/kbd_phone_symbols.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml-sw768dp/kbd_phone_shift.xml b/java/res/xml-sw768dp/kbd_phone_shift.xml new file mode 100644 index 000000000..693400e67 --- /dev/null +++ b/java/res/xml-sw768dp/kbd_phone_shift.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml-sw768dp/kbd_phone_symbols.xml b/java/res/xml-sw768dp/kbd_phone_symbols.xml deleted file mode 100644 index 693400e67..000000000 --- a/java/res/xml-sw768dp/kbd_phone_symbols.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/kbd_numkey_styles.xml b/java/res/xml/kbd_numkey_styles.xml index a40acaf55..c6ba23d39 100644 --- a/java/res/xml/kbd_numkey_styles.xml +++ b/java/res/xml/kbd_numkey_styles.xml @@ -91,12 +91,12 @@ latin:parentStyle="numKeyStyle" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_phone_symbols.xml b/java/res/xml/kbd_phone_symbols.xml deleted file mode 100644 index 89a9bd058..000000000 --- a/java/res/xml/kbd_phone_symbols.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index d196c8955..ec4287dda 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -164,7 +164,7 @@ public class KeyCodeDescriptionMapper { return context.getString(R.string.spoken_description_to_symbol); } else if (id.isSymbolsKeyboard()) { return context.getString(R.string.spoken_description_to_alpha); - } else if (id.isPhoneSymbolsKeyboard()) { + } else if (id.isPhoneShiftKeyboard()) { return context.getString(R.string.spoken_description_to_numeric); } else if (id.isPhoneKeyboard()) { return context.getString(R.string.spoken_description_to_symbol); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index a71e31ec6..3f30165aa 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -119,12 +119,6 @@ public class KeyboardId { mWidth, mMode, mAttribute, false, F2KEY_MODE_NONE, false, false, false, false); } - public KeyboardId cloneWithNewLayout(String xmlName, int xmlId) { - return new KeyboardId(xmlName, xmlId, mLocale, mOrientation, mWidth, mMode, mAttribute, - mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, - mEnableShiftLock); - } - public KeyboardId cloneWithNewGeometry(int orientation, int width) { if (mWidth == width) return this; @@ -153,8 +147,8 @@ public class KeyboardId { return mMode == MODE_PHONE; } - public boolean isPhoneSymbolsKeyboard() { - return mXmlId == R.xml.kbd_phone_symbols; + public boolean isPhoneShiftKeyboard() { + return mXmlId == R.xml.kbd_phone_shift; } public boolean isNumberKeyboard() { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 088c9d140..552a3cd30 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -67,20 +67,17 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift"); private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol"); - private KeyboardId mSymbolsId; - private KeyboardId mSymbolsShiftedId; + private KeyboardId mMainKeyboardId; + private KeyboardId mSymbolsKeyboardId; + private KeyboardId mSymbolsShiftedKeyboardId; private KeyboardId mCurrentId; private final HashMap> mKeyboardCache = new HashMap>(); - private EditorInfo mAttribute; - private boolean mIsSymbols; /** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of * what user actually typed. */ private boolean mIsAutoCorrectionActive; - private boolean mVoiceKeyEnabled; - private boolean mVoiceButtonOnPrimary; // TODO: Encapsulate these state handling to separate class and combine with ShiftKeyState // and ModifierKeyState. @@ -94,8 +91,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final int SWITCH_STATE_CHORDING_SYMBOL = 6; private int mSwitchState = SWITCH_STATE_ALPHA; - // Indicates whether or not we have the settings key in option of settings - private boolean mSettingsKeyEnabledInSettings; private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto; private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show; @@ -151,42 +146,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void loadKeyboard(EditorInfo attribute, Settings.Values settings) { mSwitchState = SWITCH_STATE_ALPHA; try { - loadKeyboardInternal(attribute, settings.isVoiceButtonEnabled(attribute), - settings.isVoiceButtonOnPrimary(), false); + final boolean voiceKeyEnabled = settings.isVoiceKeyEnabled(attribute); + final boolean voiceKeyOnMain = settings.isVoiceKeyOnMain(); + mMainKeyboardId = getKeyboardId( + attribute, false, false, voiceKeyEnabled, voiceKeyOnMain); + mSymbolsKeyboardId = getKeyboardId( + attribute, true, false, voiceKeyEnabled, voiceKeyOnMain); + mSymbolsShiftedKeyboardId = getKeyboardId( + attribute, true, true, voiceKeyEnabled, voiceKeyOnMain); + setKeyboard(getKeyboard(mMainKeyboardId)); } catch (RuntimeException e) { - // Get KeyboardId to record which keyboard has been failed to load. - final KeyboardId id = getKeyboardId(attribute, false); - Log.w(TAG, "loading keyboard failed: " + id, e); - LatinImeLogger.logOnException(id.toString(), e); + Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e); + LatinImeLogger.logOnException(mMainKeyboardId.toString(), e); } } - private void loadKeyboardInternal(EditorInfo attribute, boolean voiceButtonEnabled, - boolean voiceButtonOnPrimary, boolean isSymbols) { - if (mKeyboardView == null) return; - - mAttribute = attribute; - mVoiceKeyEnabled = voiceButtonEnabled; - mVoiceButtonOnPrimary = voiceButtonOnPrimary; - mIsSymbols = isSymbols; - // Update the settings key state because number of enabled IMEs could have been changed - mSettingsKeyEnabledInSettings = getSettingsKeyMode(mPrefs, mInputMethodService); - final KeyboardId id = getKeyboardId(attribute, isSymbols); - - // Note: This comment is only applied for phone number keyboard layout. - // On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch - // between "phone keyboard" and "phone symbols keyboard". But on xlarge device, - // "@integer/key_shift" key code is used for that purpose in order to properly display - // "more" and "locked more" key labels. To achieve these behavior, we should initialize - // mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard" - // respectively here for xlarge device's layout switching. - mSymbolsId = makeSiblingKeyboardId(id, R.xml.kbd_symbols, R.xml.kbd_phone); - mSymbolsShiftedId = makeSiblingKeyboardId( - id, R.xml.kbd_symbols_shift, R.xml.kbd_phone_symbols); - - setKeyboard(getKeyboard(id)); - } - @SuppressWarnings("unused") public void onSizeChanged(int w, int h, int oldw, int oldh) { final int width = mInputMethodService.getWindow().getWindow().getDecorView().getWidth(); @@ -255,45 +229,40 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return keyboard; } - private boolean hasVoiceKey(boolean isSymbols) { - return mVoiceKeyEnabled && (isSymbols != mVoiceButtonOnPrimary); - } - - private boolean hasSettingsKey(EditorInfo attribute) { - return mSettingsKeyEnabledInSettings - && !Utils.inPrivateImeOptions(mInputMethodService.getPackageName(), + private static boolean hasSettingsKey(SharedPreferences prefs, Context context, + EditorInfo attribute) { + return getSettingsKeyMode(prefs, context) + && !Utils.inPrivateImeOptions(context.getPackageName(), LatinIME.IME_OPTION_NO_SETTINGS_KEY, attribute); } - private KeyboardId getKeyboardId(EditorInfo attribute, boolean isSymbols) { + private KeyboardId getKeyboardId(EditorInfo attribute, final boolean isSymbols, + final boolean isShift, final boolean voiceKeyEnabled, final boolean voiceKeyOnMain) { final int mode = Utils.getKeyboardMode(attribute); - final boolean hasVoiceKey = hasVoiceKey(isSymbols); + final boolean hasVoiceKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain); final int xmlId; final boolean enableShiftLock; - if (isSymbols) { - if (mode == KeyboardId.MODE_PHONE) { - xmlId = R.xml.kbd_phone_symbols; - } else if (mode == KeyboardId.MODE_NUMBER) { - // Note: MODE_NUMBER keyboard layout has no "switch alpha symbol" key. - xmlId = R.xml.kbd_number; - } else { - xmlId = R.xml.kbd_symbols; - } + switch (mode) { + case KeyboardId.MODE_PHONE: + xmlId = (isSymbols && isShift) ? R.xml.kbd_phone_shift : R.xml.kbd_phone; + enableShiftLock = true; + break; + case KeyboardId.MODE_NUMBER: + xmlId = R.xml.kbd_number; enableShiftLock = false; - } else { - if (mode == KeyboardId.MODE_PHONE) { - xmlId = R.xml.kbd_phone; - enableShiftLock = false; - } else if (mode == KeyboardId.MODE_NUMBER) { - xmlId = R.xml.kbd_number; - enableShiftLock = false; + break; + default: + if (isSymbols) { + xmlId = isShift ? R.xml.kbd_symbols_shift : R.xml.kbd_symbols; } else { xmlId = R.xml.kbd_qwerty; - enableShiftLock = true; } + enableShiftLock = true; + break; } - final boolean hasSettingsKey = hasSettingsKey(attribute); + + final boolean hasSettingsKey = hasSettingsKey(mPrefs, mInputMethodService, attribute); final int f2KeyMode = getF2KeyMode(mPrefs, mInputMethodService, attribute); final boolean clobberSettingsKey = Utils.inPrivateImeOptions( mInputMethodService.getPackageName(), LatinIME.IME_OPTION_NO_SETTINGS_KEY, @@ -305,16 +274,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Locale locale = mSubtypeSwitcher.getInputLocale(); return new KeyboardId( res.getResourceEntryName(xmlId), xmlId, locale, orientation, mWindowWidth, - mode, attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, mVoiceKeyEnabled, + mode, attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, voiceKeyEnabled, hasVoiceKey, enableShiftLock); } - private KeyboardId makeSiblingKeyboardId(KeyboardId base, int alphabet, int phone) { - final int xmlId = base.mMode == KeyboardId.MODE_PHONE ? phone : alphabet; - final String xmlName = mInputMethodService.getResources().getResourceEntryName(xmlId); - return base.cloneWithNewLayout(xmlName, xmlId); - } - public int getKeyboardMode() { return mCurrentId != null ? mCurrentId.mMode : KeyboardId.MODE_TEXT; } @@ -602,13 +565,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (isAlphabetMode()) return; final LatinKeyboard keyboard; - if (mCurrentId.equals(mSymbolsId) || !mCurrentId.equals(mSymbolsShiftedId)) { - keyboard = getKeyboard(mSymbolsShiftedId); - // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To - // enable the indicator, we need to call setShiftLocked(true). - keyboard.setShiftLocked(true); + if (mCurrentId.equals(mSymbolsKeyboardId) + || !mCurrentId.equals(mSymbolsShiftedKeyboardId)) { + keyboard = getKeyboard(mSymbolsShiftedKeyboardId); + // Symbol keyboard may have an ALT key that has a caps lock style indicator (a.k.a. + // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked() + // that takes care of the current keyboard having such ALT key or not. + keyboard.setShiftLocked(hasStickyShiftKey(keyboard)); } else { - keyboard = getKeyboard(mSymbolsId); + keyboard = getKeyboard(mSymbolsKeyboardId); // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the // indicator, we need to call setShiftLocked(false). keyboard.setShiftLocked(false); @@ -616,6 +581,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha setKeyboard(keyboard); } + private static boolean hasStickyShiftKey(Keyboard keyboard) { + for (final Key shiftKey : keyboard.getShiftKeys()) { + if (shiftKey.mSticky) + return true; + } + return false; + } + public boolean isInMomentarySwitchState() { return mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL || mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE; @@ -630,10 +603,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } private void toggleKeyboardMode() { - loadKeyboardInternal(mAttribute, mVoiceKeyEnabled, mVoiceButtonOnPrimary, !mIsSymbols); - if (mIsSymbols) { + if (mCurrentId.equals(mMainKeyboardId)) { + setKeyboard(getKeyboard(mSymbolsKeyboardId)); mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; } else { + setKeyboard(getKeyboard(mMainKeyboardId)); mSwitchState = SWITCH_STATE_ALPHA; } } @@ -684,10 +658,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // {@link #SWITCH_STATE_MOMENTARY}. if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { // Detected only the mode change key has been pressed, and then released. - if (mIsSymbols) { - mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; - } else { + if (mCurrentId.equals(mMainKeyboardId)) { mSwitchState = SWITCH_STATE_ALPHA; + } else { + mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; } } else if (getPointerCount() == 1) { // Snap back to the previous keyboard mode if the user pressed the mode change key @@ -800,8 +774,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final int layoutId = getKeyboardThemeIndex(mInputMethodService, sharedPreferences); postSetInputView(createInputView(layoutId, false)); } else if (Settings.PREF_SETTINGS_KEY.equals(key)) { - mSettingsKeyEnabledInSettings = getSettingsKeyMode(sharedPreferences, - mInputMethodService); postSetInputView(createInputView(mThemeIndex, true)); } } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index dbab227db..e44ae29d9 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -118,8 +118,8 @@ public class Settings extends InputMethodSettingsActivity public final boolean mBigramPredictionEnabled; public final boolean mUseContactsDict; - private final boolean mVoiceButtonEnabled; - private final boolean mVoiceButtonOnPrimary; + private final boolean mVoiceKeyEnabled; + private final boolean mVoiceKeyOnMain; public Values(final SharedPreferences prefs, final Context context, final String localeStr) { @@ -183,8 +183,8 @@ public class Settings extends InputMethodSettingsActivity final String voiceModeMain = res.getString(R.string.voice_mode_main); final String voiceModeOff = res.getString(R.string.voice_mode_off); final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, voiceModeMain); - mVoiceButtonEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); - mVoiceButtonOnPrimary = voiceMode != null && voiceMode.equals(voiceModeMain); + mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); + mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); Utils.setSystemLocale(res, savedLocale); } @@ -284,15 +284,15 @@ public class Settings extends InputMethodSettingsActivity return builder.setIsPunctuationSuggestions().build(); } - public boolean isVoiceButtonEnabled(EditorInfo attribute) { + public boolean isVoiceKeyEnabled(EditorInfo attribute) { final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final int inputType = (attribute != null) ? attribute.inputType : 0; - return shortcutImeEnabled && mVoiceButtonEnabled + return shortcutImeEnabled && mVoiceKeyEnabled && !InputTypeCompatUtils.isPasswordInputType(inputType); } - public boolean isVoiceButtonOnPrimary() { - return mVoiceButtonOnPrimary; + public boolean isVoiceKeyOnMain() { + return mVoiceKeyOnMain; } } -- cgit v1.2.3-83-g751a From 58e3f1065ef47e7116299b9d5087ba2a2b6065a2 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 8 Aug 2011 11:05:04 -0700 Subject: Fixed speaking keys when editing password fields Bug: 5042681 Change-Id: Ic4523ec38b0faa2b6a91d476ea7af7e69404861c --- .../accessibility/AccessibleKeyboardViewProxy.java | 47 +++++++++++++++---- .../accessibility/KeyCodeDescriptionMapper.java | 27 ++++++++--- .../compat/AudioManagerCompatWrapper.java | 54 ++++++++++++++++++++++ 3 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 java/src/com/android/inputmethod/compat/AudioManagerCompatWrapper.java (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 86a56308a..1619451f0 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -20,12 +20,18 @@ import android.content.Context; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Paint; +import android.inputmethodservice.InputMethodService; +import android.media.AudioManager; import android.util.Log; import android.view.MotionEvent; import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; +import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.AccessibilityEventCompatUtils; +import com.android.inputmethod.compat.AudioManagerCompatWrapper; +import com.android.inputmethod.compat.EditorInfoCompatUtils; +import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.MotionEventCompatUtils; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; @@ -39,17 +45,19 @@ public class AccessibleKeyboardViewProxy { // Delay in milliseconds between key press DOWN and UP events private static final long DELAY_KEY_PRESS = 10; - private int mScaledEdgeSlop; + private InputMethodService mInputMethod; + private FlickGestureDetector mGestureDetector; private LatinKeyboardBaseView mView; private AccessibleKeyboardActionListener mListener; - private FlickGestureDetector mGestureDetector; + private AudioManagerCompatWrapper mAudioManager; + private int mScaledEdgeSlop; private int mLastHoverKeyIndex = KeyDetector.NOT_A_KEY; private int mLastX = -1; private int mLastY = -1; - public static void init(Context context, SharedPreferences prefs) { - sInstance.initInternal(context, prefs); + public static void init(InputMethodService inputMethod, SharedPreferences prefs) { + sInstance.initInternal(inputMethod, prefs); sInstance.mListener = AccessibleInputMethodServiceProxy.getInstance(); } @@ -65,15 +73,36 @@ public class AccessibleKeyboardViewProxy { // Not publicly instantiable. } - private void initInternal(Context context, SharedPreferences prefs) { + private void initInternal(InputMethodService inputMethod, SharedPreferences prefs) { final Paint paint = new Paint(); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(14.0f); paint.setAntiAlias(true); paint.setColor(Color.YELLOW); - mGestureDetector = new KeyboardFlickGestureDetector(context); - mScaledEdgeSlop = ViewConfiguration.get(context).getScaledEdgeSlop(); + mInputMethod = inputMethod; + mGestureDetector = new KeyboardFlickGestureDetector(inputMethod); + mScaledEdgeSlop = ViewConfiguration.get(inputMethod).getScaledEdgeSlop(); + + final AudioManager audioManager = (AudioManager) inputMethod + .getSystemService(Context.AUDIO_SERVICE); + mAudioManager = new AudioManagerCompatWrapper(audioManager); + } + + /** + * @return {@code true} if the device should not speak text (eg. non-control) characters + */ + private boolean shouldObscureInput() { + // Always speak if the user is listening through headphones. + if (mAudioManager.isWiredHeadsetOn() || mAudioManager.isBluetoothA2dpOn()) + return false; + + final EditorInfo info = mInputMethod.getCurrentInputEditorInfo(); + if (info == null) + return false; + + // Don't speak if the IME is connected to a password field. + return InputTypeCompatUtils.isPasswordInputType(info.inputType); } public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event, @@ -90,8 +119,10 @@ public class AccessibleKeyboardViewProxy { if (key == null) break; + final boolean shouldObscure = shouldObscureInput(); final CharSequence description = KeyCodeDescriptionMapper.getInstance() - .getDescriptionForKey(mView.getContext(), mView.getKeyboard(), key); + .getDescriptionForKey(mView.getContext(), mView.getKeyboard(), key, + shouldObscure); if (description == null) return false; diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index ec4287dda..7302830d4 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -28,6 +28,9 @@ import com.android.inputmethod.latin.R; import java.util.HashMap; public class KeyCodeDescriptionMapper { + // The resource ID of the string spoken for obscured keys + private static final int OBSCURED_KEY_RES_ID = R.string.spoken_description_dot; + private static KeyCodeDescriptionMapper sInstance = new KeyCodeDescriptionMapper(); // Map of key labels to spoken description resource IDs @@ -118,10 +121,12 @@ public class KeyCodeDescriptionMapper { * @param context The package's context. * @param keyboard The keyboard on which the key resides. * @param key The key from which to obtain a description. + * @param shouldObscure {@true} if text (e.g. non-control) characters should be obscured. * @return a character sequence describing the action performed by pressing * the key */ - public CharSequence getDescriptionForKey(Context context, Keyboard keyboard, Key key) { + public CharSequence getDescriptionForKey(Context context, Keyboard keyboard, Key key, + boolean shouldObscure) { if (key.mCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { final CharSequence description = getDescriptionForSwitchAlphaSymbol(context, keyboard); if (description != null) @@ -136,12 +141,12 @@ public class KeyCodeDescriptionMapper { } else if (label.length() == 1 || (keyboard.isManualTemporaryUpperCase() && !TextUtils .isEmpty(key.mHintLabel))) { - return getDescriptionForKeyCode(context, keyboard, key); + return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); } else { return label; } } else if (key.mCode != Keyboard.CODE_DUMMY) { - return getDescriptionForKeyCode(context, keyboard, key); + return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); } return null; @@ -206,19 +211,29 @@ public class KeyCodeDescriptionMapper { * @param context The package's context. * @param keyboard The keyboard on which the key resides. * @param key The key from which to obtain a description. + * @param shouldObscure {@true} if text (e.g. non-control) characters should be obscured. * @return a character sequence describing the action performed by pressing * the key */ - private CharSequence getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key) { + private CharSequence getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key, + boolean shouldObscure) { final int code = getCorrectKeyCode(keyboard, key); if (keyboard.isShiftLocked() && mShiftLockedKeyCodeMap.containsKey(code)) { return context.getString(mShiftLockedKeyCodeMap.get(code)); } else if (keyboard.isShiftedOrShiftLocked() && mShiftedKeyCodeMap.containsKey(code)) { return context.getString(mShiftedKeyCodeMap.get(code)); - } else if (mKeyCodeMap.containsKey(code)) { + } + + // If the key description should be obscured, now is the time to do it. + final boolean isDefinedNonCtrl = Character.isDefined(code) && !Character.isISOControl(code); + if (shouldObscure && isDefinedNonCtrl) { + return context.getString(OBSCURED_KEY_RES_ID); + } + + if (mKeyCodeMap.containsKey(code)) { return context.getString(mKeyCodeMap.get(code)); - } else if (Character.isDefined(code) && !Character.isISOControl(code)) { + } else if (isDefinedNonCtrl) { return Character.toString((char) code); } else { return context.getString(R.string.spoken_description_unknown, code); diff --git a/java/src/com/android/inputmethod/compat/AudioManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/AudioManagerCompatWrapper.java new file mode 100644 index 000000000..b6c3e2a88 --- /dev/null +++ b/java/src/com/android/inputmethod/compat/AudioManagerCompatWrapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.compat; + +import android.media.AudioManager; + +import java.lang.reflect.Method; + +public class AudioManagerCompatWrapper { + private static final Method METHOD_isWiredHeadsetOn = CompatUtils.getMethod( + AudioManager.class, "isWiredHeadsetOn"); + private static final Method METHOD_isBluetoothA2dpOn = CompatUtils.getMethod( + AudioManager.class, "isBluetoothA2dpOn"); + + private final AudioManager mManager; + + public AudioManagerCompatWrapper(AudioManager manager) { + mManager = manager; + } + + /** + * Checks whether audio routing to the wired headset is on or off. + * + * @return true if audio is being routed to/from wired headset; + * false if otherwise + */ + public boolean isWiredHeadsetOn() { + return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isWiredHeadsetOn); + } + + /** + * Checks whether A2DP audio routing to the Bluetooth headset is on or off. + * + * @return true if A2DP audio is being routed to/from Bluetooth headset; + * false if otherwise + */ + public boolean isBluetoothA2dpOn() { + return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isBluetoothA2dpOn); + } +} -- cgit v1.2.3-83-g751a From e87fd4d2826734a931d7d6f019ee36212b5b060a Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 21 Nov 2011 17:56:03 -0800 Subject: Fixed typing uppercase letters when touch exploration is enabled. Bug: 5652774 Change-Id: Id8cd37b3ff93b45f4f18198bbbb827aadf945b02 --- .../accessibility/KeyCodeDescriptionMapper.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index 7302830d4..e01262c20 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -136,16 +136,14 @@ public class KeyCodeDescriptionMapper { if (!TextUtils.isEmpty(key.mLabel)) { final String label = key.mLabel.toString().trim(); + // First, attempt to map the label to a pre-defined description. if (mKeyLabelMap.containsKey(label)) { return context.getString(mKeyLabelMap.get(label)); - } else if (label.length() == 1 - || (keyboard.isManualTemporaryUpperCase() && !TextUtils - .isEmpty(key.mHintLabel))) { - return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); - } else { - return label; } - } else if (key.mCode != Keyboard.CODE_DUMMY) { + } + + // Just attempt to speak the description. + if (key.mCode != Keyboard.CODE_DUMMY) { return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); } @@ -187,11 +185,14 @@ public class KeyCodeDescriptionMapper { * @return the key code for the specified key */ private int getCorrectKeyCode(Keyboard keyboard, Key key) { - if (keyboard.isManualTemporaryUpperCase() && !TextUtils.isEmpty(key.mHintLabel)) { + // If keyboard is in manual temporary upper case state and key has + // manual temporary uppercase letter as key hint letter, alternate + // character code should be sent. + if (keyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter() + && !TextUtils.isEmpty(key.mHintLabel)) { return key.mHintLabel.charAt(0); - } else { - return key.mCode; } + return key.mCode; } /** -- cgit v1.2.3-83-g751a From 2ac5988f84b5c38d313951a3d7faddebf5f25e04 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 15 Dec 2011 19:32:11 +0900 Subject: Cleanup unused variables and parameters Change-Id: Iad756a7a775c93f3344c6962e7b3456ef8339490 --- .../accessibility/AccessibilityUtils.java | 13 ++++++------- .../AccessibleInputMethodServiceProxy.java | 9 +++------ .../accessibility/AccessibleKeyboardViewProxy.java | 16 +++++++--------- .../accessibility/FlickGestureDetector.java | 1 - .../accessibility/KeyCodeDescriptionMapper.java | 7 +++---- .../inputmethod/keyboard/LatinKeyboardView.java | 8 +++----- .../src/com/android/inputmethod/latin/LatinIME.java | 6 +++--- .../android/inputmethod/latin/SettingsValues.java | 21 ++++++++++++--------- .../android/inputmethod/latin/SuggestionsView.java | 7 ------- .../inputmethod/latin/UserUnigramDictionary.java | 6 +++--- 10 files changed, 40 insertions(+), 54 deletions(-) (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index 1836f27b3..9caed00c9 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.SystemClock; @@ -55,15 +54,15 @@ public class AccessibilityUtils { */ private static final boolean ENABLE_ACCESSIBILITY = true; - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { + public static void init(InputMethodService inputMethod) { if (!ENABLE_ACCESSIBILITY) return; // These only need to be initialized if the kill switch is off. - sInstance.initInternal(inputMethod, prefs); - KeyCodeDescriptionMapper.init(inputMethod, prefs); - AccessibleInputMethodServiceProxy.init(inputMethod, prefs); - AccessibleKeyboardViewProxy.init(inputMethod, prefs); + sInstance.initInternal(inputMethod); + KeyCodeDescriptionMapper.init(); + AccessibleInputMethodServiceProxy.init(inputMethod); + AccessibleKeyboardViewProxy.init(inputMethod); } public static AccessibilityUtils getInstance() { @@ -74,7 +73,7 @@ public class AccessibilityUtils { // This class is not publicly instantiable. } - private void initInternal(Context context, SharedPreferences prefs) { + private void initInternal(Context context) { mContext = context; mAccessibilityManager = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java index 4ab9cb898..d834dd10b 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.Looper; @@ -82,8 +81,8 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi } } - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { - sInstance.initInternal(inputMethod, prefs); + public static void init(InputMethodService inputMethod) { + sInstance.initInternal(inputMethod); } public static AccessibleInputMethodServiceProxy getInstance() { @@ -94,7 +93,7 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi // Not publicly instantiable. } - private void initInternal(InputMethodService inputMethod, SharedPreferences prefs) { + private void initInternal(InputMethodService inputMethod) { mInputMethod = inputMethod; mVibrator = (Vibrator) inputMethod.getSystemService(Context.VIBRATOR_SERVICE); mAudioManager = (AudioManager) inputMethod.getSystemService(Context.AUDIO_SERVICE); @@ -125,8 +124,6 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi */ @Override public void onFlickGesture(int direction) { - final int keyEventCode; - switch (direction) { case FlickGestureDetector.FLICK_LEFT: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT); diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 4cb2f20b9..9141daaee 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Paint; import android.inputmethodservice.InputMethodService; @@ -43,8 +42,8 @@ public class AccessibleKeyboardViewProxy { private Key mLastHoverKey = null; - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { - sInstance.initInternal(inputMethod, prefs); + public static void init(InputMethodService inputMethod) { + sInstance.initInternal(inputMethod); sInstance.mListener = AccessibleInputMethodServiceProxy.getInstance(); } @@ -60,7 +59,7 @@ public class AccessibleKeyboardViewProxy { // Not publicly instantiable. } - private void initInternal(InputMethodService inputMethod, SharedPreferences prefs) { + private void initInternal(InputMethodService inputMethod) { final Paint paint = new Paint(); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(14.0f); @@ -71,8 +70,7 @@ public class AccessibleKeyboardViewProxy { mGestureDetector = new KeyboardFlickGestureDetector(inputMethod); } - public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event, - PointerTracker tracker) { + public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (mView == null) { Log.e(TAG, "No keyboard view set!"); return false; @@ -132,9 +130,9 @@ public class AccessibleKeyboardViewProxy { final Key key = tracker.getKeyOn(x, y); if (key != mLastHoverKey) { - fireKeyHoverEvent(tracker, mLastHoverKey, false); + fireKeyHoverEvent(mLastHoverKey, false); mLastHoverKey = key; - fireKeyHoverEvent(tracker, mLastHoverKey, true); + fireKeyHoverEvent(mLastHoverKey, true); } return true; @@ -143,7 +141,7 @@ public class AccessibleKeyboardViewProxy { return false; } - private void fireKeyHoverEvent(PointerTracker tracker, Key key, boolean entering) { + private void fireKeyHoverEvent(Key key, boolean entering) { if (mListener == null) { Log.e(TAG, "No accessible keyboard action listener set!"); return; diff --git a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java index 9d99e3131..db12f76ad 100644 --- a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java +++ b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java @@ -126,7 +126,6 @@ public abstract class FlickGestureDetector { } final float distanceSquare = calculateDistanceSquare(mCachedHoverEnter, event); - final long timeout = event.getEventTime() - mCachedHoverEnter.getEventTime(); switch (event.getAction()) { case MotionEventCompatUtils.ACTION_HOVER_MOVE: diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index e01262c20..3d5ab05c3 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.text.TextUtils; import com.android.inputmethod.keyboard.Key; @@ -45,8 +44,8 @@ public class KeyCodeDescriptionMapper { // Map of shift-locked key codes to spoken description resource IDs private final HashMap mShiftLockedKeyCodeMap; - public static void init(Context context, SharedPreferences prefs) { - sInstance.initInternal(context, prefs); + public static void init() { + sInstance.initInternal(); } public static KeyCodeDescriptionMapper getInstance() { @@ -60,7 +59,7 @@ public class KeyCodeDescriptionMapper { mShiftLockedKeyCodeMap = new HashMap(); } - private void initInternal(Context context, SharedPreferences prefs) { + private void initInternal() { // Manual label substitutions for key labels with no string resource mKeyLabelMap.put(":-)", R.string.spoken_description_smiley); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index e56f2ea84..7f2c6c501 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -206,7 +206,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // Detected a double tap on shift key. If we are in the ignoring double tap // mode, it means we have already turned off caps lock in // {@link KeyboardSwitcher#onReleaseShift} . - onDoubleTapShiftKey(tracker, mKeyTimerHandler.isIgnoringDoubleTap()); + onDoubleTapShiftKey(mKeyTimerHandler.isIgnoringDoubleTap()); return true; } // Otherwise these events should not be handled as double tap. @@ -342,8 +342,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke return onLongPress(parentKey, tracker); } - private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker, - final boolean ignore) { + private void onDoubleTapShiftKey(final boolean ignore) { // When shift key is double tapped, the first tap is correctly processed as usual tap. And // the second tap is treated as this double tap event, so that we need not mark tracker // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. @@ -633,9 +632,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - final PointerTracker tracker = getPointerTracker(0); return AccessibleKeyboardViewProxy.getInstance().dispatchPopulateAccessibilityEvent( - event, tracker) || super.dispatchPopulateAccessibilityEvent(event); + event) || super.dispatchPopulateAccessibilityEvent(event); } return super.dispatchPopulateAccessibilityEvent(event); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 98fea1b5b..943361c73 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -489,7 +489,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar InputMethodManagerCompatWrapper.init(this); SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); - AccessibilityUtils.init(this, prefs); + AccessibilityUtils.init(this); super.onCreate(); @@ -758,7 +758,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar loadSettings(); updateCorrectionMode(); - updateSuggestionVisibility(mPrefs, mResources); + updateSuggestionVisibility(mResources); if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); @@ -2415,7 +2415,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode; } - private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { + private void updateSuggestionVisibility(final Resources res) { final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { if (suggestionVisiblityStr.equals(res.getString(visibility))) { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0ad1c1529..651d90ca4 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -52,7 +52,9 @@ public class SettingsValues { private final String mVoiceMode; private final String mAutoCorrectionThresholdRawValue; public final String mShowSuggestionsSetting; + @SuppressWarnings("unused") // TODO: Use this private final boolean mUsabilityStudyMode; + @SuppressWarnings("unused") // TODO: Use this private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary @@ -60,7 +62,9 @@ public class SettingsValues { // Prediction: use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; public final boolean mEnableSuggestionSpanInsertion; + @SuppressWarnings("unused") // TODO: Use this private final int mVibrationDurationSettingsRawValue; + @SuppressWarnings("unused") // TODO: Use this private final float mKeypressSoundVolumeRawValue; // Deduced settings @@ -111,12 +115,12 @@ public class SettingsValues { res.getString(R.string.auto_correction_threshold_mode_index_modest)); mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING, res.getString(R.string.prefs_suggestion_visibility_default_value)); - mUsabilityStudyMode = getUsabilityStudyMode(prefs, res); + mUsabilityStudyMode = getUsabilityStudyMode(prefs); mKeyPreviewPopupDismissDelayRawValue = prefs.getString( Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(res.getInteger(R.integer.config_delay_after_preview))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); - mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res, mAutoCorrectionThresholdRawValue); + mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); mBigramPredictionEnabled = mBigramSuggestionEnabled @@ -131,7 +135,7 @@ public class SettingsValues { mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); mFxVolume = getCurrentKeypressSoundVolume(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); - mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res, + mAutoCorrectionThreshold = getAutoCorrectionThreshold(res, mAutoCorrectionThresholdRawValue); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); @@ -202,8 +206,8 @@ public class SettingsValues { return mMagicSpaceSwappers.contains(String.valueOf((char)code)); } - private static boolean isAutoCorrectEnabled(final SharedPreferences sp, - final Resources resources, final String currentAutoCorrectionSetting) { + private static boolean isAutoCorrectEnabled(final Resources resources, + final String currentAutoCorrectionSetting) { final String autoCorrectionOff = resources.getString( R.string.auto_correction_threshold_mode_index_off); return !currentAutoCorrectionSetting.equals(autoCorrectionOff); @@ -244,8 +248,8 @@ public class SettingsValues { R.bool.config_default_bigram_prediction)); } - private static double getAutoCorrectionThreshold(final SharedPreferences sp, - final Resources resources, final String currentAutoCorrectionSetting) { + private static double getAutoCorrectionThreshold(final Resources resources, + final String currentAutoCorrectionSetting) { final String[] autoCorrectionThresholdValues = resources.getStringArray( R.array.auto_correction_threshold_values); // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. @@ -321,8 +325,7 @@ public class SettingsValues { } // Likewise - public static boolean getUsabilityStudyMode(final SharedPreferences prefs, - final Resources res) { + public static boolean getUsabilityStudyMode(final SharedPreferences prefs) { // TODO: use mUsabilityStudyMode instead of reading it again here return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); } diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 10f5ec9db..883bb57f0 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -100,8 +100,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private static class UiHandler extends StaticInnerHandlerWrapper { private static final int MSG_HIDE_PREVIEW = 0; - private static final long DELAY_HIDE_PREVIEW = 1300; - public UiHandler(SuggestionsView outerInstance) { super(outerInstance); } @@ -116,11 +114,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - public void postHidePreview() { - cancelHidePreview(); - sendMessageDelayed(obtainMessage(MSG_HIDE_PREVIEW), DELAY_HIDE_PREVIEW); - } - public void cancelHidePreview() { removeMessages(MSG_HIDE_PREVIEW); } diff --git a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java index 6af20c754..a7f57ae46 100644 --- a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java @@ -172,7 +172,7 @@ public class UserUnigramDictionary extends ExpandableDictionary { // Nothing pending? Return if (mPendingWrites.isEmpty()) return; // Create a background thread to write the pending entries - new UpdateDbTask(getContext(), sOpenHelper, mPendingWrites, mLocale).execute(); + new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale).execute(); // Create a new map for writing new entries into while the old one is written to db mPendingWrites = new HashMap(); } @@ -227,8 +227,8 @@ public class UserUnigramDictionary extends ExpandableDictionary { private final DatabaseHelper mDbHelper; private final String mLocale; - public UpdateDbTask(@SuppressWarnings("unused") Context context, DatabaseHelper openHelper, - HashMap pendingWrites, String locale) { + public UpdateDbTask(DatabaseHelper openHelper, HashMap pendingWrites, + String locale) { mMap = pendingWrites; mLocale = locale; mDbHelper = openHelper; -- cgit v1.2.3-83-g751a From 8cab0b56eb8db311f158b18a361d9ceb85cff482 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 10 Jan 2012 17:24:00 +0900 Subject: Get rid of Keyboard.CODE_DUMMY Change-Id: Id2320f4d9b5f22f0ac844ab20ce42b0c4e7c6880 --- java/res/values/keycodes.xml | 4 +- java/res/xml-sw600dp/kbd_key_styles.xml | 2 - java/res/xml-sw768dp/kbd_key_styles.xml | 2 - java/res/xml/kbd_settings_or_tab.xml | 4 +- .../accessibility/KeyCodeDescriptionMapper.java | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 14 ++-- .../com/android/inputmethod/keyboard/Keyboard.java | 13 ++-- .../inputmethod/keyboard/PointerTracker.java | 10 ++- .../keyboard/internal/KeyboardState.java | 3 +- .../keyboard/internal/MoreKeySpecParser.java | 4 +- .../com/android/inputmethod/latin/LatinIME.java | 2 +- .../keyboard/internal/MoreKeySpecParserTests.java | 82 +++++++++++----------- 12 files changed, 70 insertions(+), 72 deletions(-) (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/res/values/keycodes.xml b/java/res/values/keycodes.xml index 4f8bfed58..b3f71d2bb 100644 --- a/java/res/values/keycodes.xml +++ b/java/res/values/keycodes.xml @@ -23,10 +23,12 @@ 9 10 32 - 0 -1 -2 + -3 + -4 -5 -6 -7 + -9 diff --git a/java/res/xml-sw600dp/kbd_key_styles.xml b/java/res/xml-sw600dp/kbd_key_styles.xml index 1dd0307c7..ab90c9894 100644 --- a/java/res/xml-sw600dp/kbd_key_styles.xml +++ b/java/res/xml-sw600dp/kbd_key_styles.xml @@ -78,14 +78,12 @@ latin:keyIcon="iconShortcutKey" latin:keyIconDisabled="iconDisabledShortcutKey" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping" - latin:altCode="@integer/key_dummy" latin:parentStyle="f2PopupStyle" /> + just ignored while typing (altCode=CODE_UNSPECIFIED). --> diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index 3d5ab05c3..efaf58fc2 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -142,7 +142,7 @@ public class KeyCodeDescriptionMapper { } // Just attempt to speak the description. - if (key.mCode != Keyboard.CODE_DUMMY) { + if (key.mCode != Keyboard.CODE_UNSPECIFIED) { return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); } diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index e1e74fc9a..ebd61505d 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -198,7 +198,7 @@ public class Key { mLabel = label; mOutputText = outputText; mCode = code; - mAltCode = Keyboard.CODE_DUMMY; + mAltCode = Keyboard.CODE_UNSPECIFIED; mIcon = icon; mDisabledIcon = null; mPreviewIcon = null; @@ -299,13 +299,13 @@ public class Key { } final int firstChar = mLabel.charAt(0); mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard); - } else if (code != Keyboard.CODE_UNSPECIFIED) { - mCode = code; + } else if (code == Keyboard.CODE_UNSPECIFIED && mOutputText != null) { + mCode = Keyboard.CODE_OUTPUT_TEXT; } else { - mCode = Keyboard.CODE_DUMMY; + mCode = code; } mAltCode = style.getInt(keyAttr, - R.styleable.Keyboard_Key_altCode, Keyboard.CODE_DUMMY); + R.styleable.Keyboard_Key_altCode, Keyboard.CODE_UNSPECIFIED); mHashCode = hashCode(this); keyAttr.recycle(); @@ -508,7 +508,7 @@ public class Key { * @param y the y-coordinate of the point * @return whether or not the point falls on the key. If the key is attached to an edge, it * will assume that all points between the key and the edge are considered to be on the key. - * @see #markAsLeftEdge(KeyboardParams) etc. + * @see #markAsLeftEdge(Keyboard.Params) etc. */ public boolean isOnKey(int x, int y) { return mHitBox.contains(x, y); @@ -615,7 +615,7 @@ public class Key { * This constructor is being used only for divider in more keys keyboard. */ public Spacer(Keyboard.Params params, Drawable icon, int x, int y, int width, int height) { - super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height); + super(params, null, null, icon, Keyboard.CODE_UNSPECIFIED, null, x, y, width, height); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index fad12cc1f..c1d024cef 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -86,19 +86,20 @@ public class Keyboard { public static final int CODE_CLOSING_ANGLE_BRACKET = '>'; public static final int CODE_DIGIT0 = '0'; public static final int CODE_PLUS = '+'; + private static final int MINIMUM_LETTER_CODE = CODE_TAB; - /** Special keys code. Must be non-positive. + /** Special keys code. Must be negative. * These should be aligned with values/keycodes.xml */ - public static final int CODE_DUMMY = 0; public static final int CODE_SHIFT = -1; public static final int CODE_SWITCH_ALPHA_SYMBOL = -2; public static final int CODE_CAPSLOCK = -3; + public static final int CODE_OUTPUT_TEXT = -4; public static final int CODE_DELETE = -5; public static final int CODE_SETTINGS = -6; public static final int CODE_SHORTCUT = -7; // Code value representing the code is not specified. - public static final int CODE_UNSPECIFIED = -99; + public static final int CODE_UNSPECIFIED = -9; public final KeyboardId mId; public final int mThemeId; @@ -167,7 +168,7 @@ public class Keyboard { } public Key getKey(int code) { - if (code == CODE_DUMMY) { + if (code == CODE_UNSPECIFIED) { return null; } final Integer keyCode = code; @@ -253,7 +254,7 @@ public class Keyboard { } public static boolean isLetterCode(int code) { - return code > CODE_DUMMY; + return code >= MINIMUM_LETTER_CODE; } public static class Params { @@ -428,9 +429,9 @@ public class Keyboard { case CODE_SHIFT: return "shift"; case CODE_SWITCH_ALPHA_SYMBOL: return "symbol"; case CODE_CAPSLOCK: return "capslock"; + case CODE_OUTPUT_TEXT: return "text"; case CODE_DELETE: return "delete"; case CODE_SHORTCUT: return "shortcut"; - case CODE_DUMMY: return "dummy"; case CODE_UNSPECIFIED: return "unspec"; default: if (code < 0) Log.w(TAG, "Unknow negative key code=" + code); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 7c14b5888..2183e8ed6 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -262,10 +262,8 @@ public class PointerTracker { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); final boolean alterCode = key.altCodeWhileTyping() && mTimerProxy.isTyping(); final int code = alterCode ? key.mAltCode : primaryCode; - // If code is CODE_DUMMY here, this key will be ignored or generate text. - final CharSequence text = (code != Keyboard.CODE_DUMMY) ? null : key.mOutputText; if (DEBUG_LISTENER) { - Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + text + Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + key.mOutputText + " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode + " enabled=" + key.isEnabled()); @@ -274,10 +272,10 @@ public class PointerTracker { return; } if (key.isEnabled()) { - if (code != Keyboard.CODE_DUMMY) { + if (code == Keyboard.CODE_OUTPUT_TEXT) { + mListener.onTextInput(key.mOutputText); + } else if (code != Keyboard.CODE_UNSPECIFIED) { mListener.onCodeInput(code, keyCodes, x, y); - } else if (text != null) { - mListener.onTextInput(text); } if (!key.altCodeWhileTyping() && !key.isModifier()) { mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index c0adf970a..f54bdbb05 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -434,7 +434,8 @@ public class KeyboardState { } break; case SWITCH_STATE_SYMBOL_BEGIN: - if (!isSpaceCharacter(code) && code >= 0) { + if (!isSpaceCharacter(code) && (Keyboard.isLetterCode(code) + || code == Keyboard.CODE_OUTPUT_TEXT)) { mSwitchState = SWITCH_STATE_SYMBOL; } // Snap back to alpha keyboard mode immediately if user types a quote character. diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java index a490b0ad6..93be31ed9 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java @@ -148,12 +148,12 @@ public class MoreKeySpecParser { return code; } if (indexOfLabelEnd(moreKeySpec, 0) > 0) - return Keyboard.CODE_DUMMY; + return Keyboard.CODE_UNSPECIFIED; final String label = getLabel(moreKeySpec); // Code is automatically generated for one letter label. if (label != null && label.length() == 1) return label.charAt(0); - return Keyboard.CODE_DUMMY; + return Keyboard.CODE_UNSPECIFIED; } public static int getIconId(String moreKeySpec) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e6478b683..4cb60558c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1305,7 +1305,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ic.commitText(text, 1); ic.endBatchEdit(); mKeyboardSwitcher.updateShiftState(); - mKeyboardSwitcher.onCodeInput(Keyboard.CODE_DUMMY); + mKeyboardSwitcher.onCodeInput(Keyboard.CODE_OUTPUT_TEXT); mSpaceState = SPACE_STATE_NONE; mEnteredText = text; mWordComposer.reset(); diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java index 798fca0f5..0eb324234 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java @@ -89,78 +89,78 @@ public class MoreKeySpecParserTests extends AndroidTestCase { assertParser("Single escaped at", "\\@", "@", null, ICON_UNDEFINED, '@'); assertParser("Single letter with outputText", "a|abc", - "a", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with escaped outputText", "a|a\\|c", - "a", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "a|c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with comma outputText", "a|a,b", - "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with escaped comma outputText", "a|a\\,b", - "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with outputText starts with at", "a|@bc", - "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with outputText contains at", "a|a@c", - "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with escaped at outputText", "a|\\@bc", - "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single escaped escape with outputText", "\\\\|\\\\", - "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single escaped bar with outputText", "\\||\\|", - "|", "|", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "|", "|", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, ICON_UNDEFINED, mCodeSettings); } public void testLabel() { assertParser("Simple label", "abc", - "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped bar", "a\\|c", - "a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped escape", "a\\\\c", - "a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with comma", "a,c", - "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped comma", "a\\,c", - "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label starts with at", "@bc", - "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label contains at", "a@c", - "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped at", "\\@bc", - "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped letter", "\\abc", - "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with outputText", "abc|def", - "abc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with comma and outputText", "a,c|def", - "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Escaped comma label with outputText", "a\\,c|def", - "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Escaped label with outputText", "a\\|c|def", - "a|c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a|c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped bar outputText", "abc|d\\|f", - "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Escaped escape label with outputText", "a\\\\|def", - "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label starts with at and outputText", "@bc|def", - "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label contains at label and outputText", "a@c|def", - "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Escaped at label with outputText", "\\@bc|def", - "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with comma outputText", "abc|a,b", - "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped comma outputText", "abc|a\\,b", - "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with outputText starts with at", "abc|@bc", - "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with outputText contains at", "abc|a@c", - "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped at outputText", "abc|\\@bc", - "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with escaped bar outputText", "abc|d\\|f", - "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", - "a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + "a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParser("Label with code", "abc|" + CODE_SETTINGS, "abc", null, ICON_UNDEFINED, mCodeSettings); assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, @@ -169,13 +169,13 @@ public class MoreKeySpecParserTests extends AndroidTestCase { public void testIconAndCode() { assertParser("Icon with outputText", ICON_SETTINGS + "|abc", - null, "abc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + null, "abc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", - null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", - null, "a@c", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + null, "a@c", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", - null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, "@bc", null, ICON_UNDEFINED, mCodeSettings); assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, @@ -190,7 +190,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase { assertParserError("Empty spec", "", null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParserError("Empty label with outputText", "|a", - null, "a", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + null, "a", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, ICON_UNDEFINED, mCodeSettings); assertParserError("Empty outputText with label", "a|", @@ -200,9 +200,9 @@ public class MoreKeySpecParserTests extends AndroidTestCase { assertParserError("Empty icon and code", "|", null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParserError("Icon without code", ICON_SETTINGS, - null, null, ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + null, null, ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); assertParser("Non existing icon", ICON_NON_EXISTING + "|abc", - null, "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + null, "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); assertParserError("Third bar at end", "a|b|", -- cgit v1.2.3-83-g751a From ca2f051cc173acc3bce384ebfe08068564bc8e07 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 26 Jan 2012 18:03:30 +0900 Subject: Auto generate various shift states alphabet keyboard automatically If any shift state variants of alphabet keyboard layout is not specified in KeyboardSet.Element, it will be automatically generated from base alphabet keyboard definition. This change also * Eliminates KeyboardShiftState object from Keyboard. * Removes various set shift state methods from Keyboard. * Removes KeyboardSet.Element.elementAutoGenerate attribute. * Separates "sticky" Key.backgroundType to "stickyOff" and "stickyOn" * Add preserveCase flag to smiley, .com, and labeled special keys. * Rename KeyboardShiftState class to AlphabetShiftState. * Rename some attributes from *UppercaseLetter* to *ShiftedLetterHint*. * Introduce shiftedLetterActivated to Key.keyLabelFlags Change-Id: I01a0a8efeeaa76820ae728a5bdfa8d02b6ce74b7 --- java/res/values/attrs.xml | 28 ++--- java/res/values/styles.xml | 16 +-- java/res/xml-sw600dp/key_smiley.xml | 8 +- java/res/xml-sw600dp/key_styles_common.xml | 58 +++++++-- java/res/xml-sw600dp/keys_apostrophe_dash.xml | 12 +- java/res/xml-sw600dp/row_qwerty4.xml | 4 +- java/res/xml-sw768dp/key_styles_common.xml | 64 ++++++++-- java/res/xml-sw768dp/keys_apostrophe_dash.xml | 12 +- java/res/xml-sw768dp/row_qwerty4.xml | 8 +- java/res/xml-sw768dp/rows_azerty.xml | 2 +- java/res/xml/key_styles_common.xml | 54 +++++++-- java/res/xml/keyboard_set.xml | 19 +-- java/res/xml/keys_comma_period.xml | 8 +- .../accessibility/KeyCodeDescriptionMapper.java | 21 +--- java/src/com/android/inputmethod/keyboard/Key.java | 107 +++++++++-------- .../com/android/inputmethod/keyboard/Keyboard.java | 74 +----------- .../android/inputmethod/keyboard/KeyboardId.java | 16 +++ .../android/inputmethod/keyboard/KeyboardSet.java | 115 +++++++----------- .../inputmethod/keyboard/KeyboardSwitcher.java | 88 +++----------- .../android/inputmethod/keyboard/KeyboardView.java | 70 +++++------ .../inputmethod/keyboard/LatinKeyboardView.java | 1 - .../inputmethod/keyboard/MiniKeyboardView.java | 7 -- .../inputmethod/keyboard/MoreKeysPanel.java | 3 - .../inputmethod/keyboard/PointerTracker.java | 9 +- .../keyboard/internal/AlphabetShiftState.java | 131 +++++++++++++++++++++ .../keyboard/internal/KeyboardShiftState.java | 131 --------------------- .../keyboard/internal/KeyboardState.java | 12 +- .../com/android/inputmethod/latin/LatinIME.java | 32 +---- .../latin/suggestions/MoreSuggestionsView.java | 5 - 29 files changed, 502 insertions(+), 613 deletions(-) create mode 100644 java/src/com/android/inputmethod/keyboard/internal/AlphabetShiftState.java delete mode 100644 java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java (limited to 'java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 8d00f7aa5..a5bf6f69a 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -60,16 +60,16 @@ - - + + - - + + @@ -79,9 +79,9 @@ - - - + + + @@ -240,7 +240,8 @@ - + + @@ -267,7 +268,7 @@ - + @@ -275,10 +276,9 @@ - - - - + + @@ -407,7 +407,5 @@ - - diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 69637d75a..f69078288 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -39,18 +39,18 @@ @fraction/key_label_ratio @fraction/key_hint_letter_ratio @fraction/key_hint_label_ratio - @fraction/key_uppercase_letter_ratio + @fraction/key_uppercase_letter_ratio normal #FFFFFFFF #FFFFFFFF #80000000 #E0E0E4E5 - #66E0E4E5 - #CCE0E4E5 + #66E0E4E5 + #CCE0E4E5 @dimen/key_label_horizontal_padding @dimen/key_hint_letter_padding @dimen/key_popup_hint_letter_padding - @dimen/key_uppercase_letter_padding + @dimen/key_uppercase_letter_padding @layout/key_preview @drawable/keyboard_key_feedback @null @@ -181,8 +181,8 @@ #FF808080 #80000000 #E0000000 - #66000000 - #CC000000 + #66000000 + #CC000000 #FFFFFFFF