Remove LatinKeyboard class

Change-Id: I68c667b00dadf2ed9f1c62fb7da37d2cf499cd81
This commit is contained in:
Tadashi G. Takaoka 2011-12-18 08:36:16 +09:00
parent 4112dc0500
commit 3708787fe9
8 changed files with 69 additions and 123 deletions

View file

@ -24,6 +24,8 @@ import android.util.Log;
import android.util.Xml;
import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.keyboard.internal.XmlParseUtils;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
@ -72,8 +74,8 @@ public class KeyboardSet {
Params() {}
}
private static final HashMap<KeyboardId, SoftReference<LatinKeyboard>> sKeyboardCache =
new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();
private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
new HashMap<KeyboardId, SoftReference<Keyboard>>();
public static void clearKeyboardCache() {
sKeyboardCache.clear();
@ -84,16 +86,16 @@ public class KeyboardSet {
mParams = params;
}
public LatinKeyboard getMainKeyboard() {
public Keyboard getMainKeyboard() {
return getKeyboard(false, false);
}
public LatinKeyboard getSymbolsKeyboard() {
public Keyboard getSymbolsKeyboard() {
return getKeyboard(true, false);
}
public LatinKeyboard getSymbolsShiftedKeyboard() {
final LatinKeyboard keyboard = getKeyboard(true, true);
public Keyboard getSymbolsShiftedKeyboard() {
final Keyboard keyboard = getKeyboard(true, true);
// TODO: Remove this logic once we introduce initial keyboard shift state attribute.
// Symbol shift keyboard may have a shift 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()
@ -102,11 +104,11 @@ public class KeyboardSet {
return keyboard;
}
private LatinKeyboard getKeyboard(boolean isSymbols, boolean isShift) {
private Keyboard getKeyboard(boolean isSymbols, boolean isShift) {
final int elementState = Builder.getElementState(mParams.mMode, isSymbols, isShift);
final int xmlId = mParams.mElementKeyboards.get(elementState);
final KeyboardId id = Builder.getKeyboardId(elementState, isSymbols, mParams);
final LatinKeyboard keyboard = getKeyboard(mContext, xmlId, id);
final Keyboard keyboard = getKeyboard(mContext, xmlId, id);
return keyboard;
}
@ -115,15 +117,16 @@ public class KeyboardSet {
return Builder.getKeyboardId(elementState, false, mParams);
}
private static LatinKeyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
private static Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
final Resources res = context.getResources();
final SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
final SoftReference<LatinKeyboard> ref = sKeyboardCache.get(id);
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
Keyboard keyboard = (ref == null) ? null : ref.get();
if (keyboard == null) {
final Locale savedLocale = LocaleUtils.setSystemLocale(res, id.mLocale);
try {
final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(context);
final KeyboardBuilder<KeyboardParams> builder =
new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams());
builder.load(xmlId, id);
builder.setTouchPositionCorrectionEnabled(
subtypeSwitcher.currentSubtypeContainsExtraValueKey(
@ -132,7 +135,7 @@ public class KeyboardSet {
} finally {
LocaleUtils.setSystemLocale(res, savedLocale);
}
sKeyboardCache.put(id, new SoftReference<LatinKeyboard>(keyboard));
sKeyboardCache.put(id, new SoftReference<Keyboard>(keyboard));
if (DEBUG_CACHE) {
Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": "

View file

@ -171,7 +171,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
}
public boolean isAlphabetMode() {
final Keyboard keyboard = getLatinKeyboard();
final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.mId.isAlphabetKeyboard();
}
@ -180,12 +180,12 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
}
public boolean isShiftedOrShiftLocked() {
final Keyboard keyboard = getLatinKeyboard();
final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.isShiftedOrShiftLocked();
}
public boolean isManualTemporaryUpperCase() {
final Keyboard keyboard = getLatinKeyboard();
final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.isManualTemporaryUpperCase();
}
@ -195,11 +195,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
return false;
}
public LatinKeyboard getLatinKeyboard() {
public Keyboard getKeyboard() {
if (mKeyboardView != null) {
final Keyboard keyboard = mKeyboardView.getKeyboard();
if (keyboard instanceof LatinKeyboard)
return (LatinKeyboard)keyboard;
return mKeyboardView.getKeyboard();
}
return null;
}
@ -208,11 +206,11 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
@Override
public void setShifted(int shiftMode) {
mInputMethodService.mHandler.cancelUpdateShiftState();
LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard == null)
Keyboard keyboard = getKeyboard();
if (keyboard == null)
return;
if (shiftMode == AUTOMATIC_SHIFT) {
latinKeyboard.setAutomaticTemporaryUpperCase();
keyboard.setAutomaticTemporaryUpperCase();
} else {
final boolean shifted = (shiftMode == MANUAL_SHIFT);
// On non-distinct multi touch panel device, we should also turn off the shift locked
@ -220,9 +218,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
// On the other hand, on distinct multi touch panel device, turning off the shift
// locked state with shift key pressing is handled by onReleaseShift().
if (!hasDistinctMultitouch() && !shifted && mState.isShiftLocked()) {
latinKeyboard.setShiftLocked(false);
keyboard.setShiftLocked(false);
}
latinKeyboard.setShifted(shifted);
keyboard.setShifted(shifted);
}
mKeyboardView.invalidateAllKeys();
}
@ -231,10 +229,10 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
@Override
public void setShiftLocked(boolean shiftLocked) {
mInputMethodService.mHandler.cancelUpdateShiftState();
LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard == null)
Keyboard keyboard = getKeyboard();
if (keyboard == null)
return;
latinKeyboard.setShiftLocked(shiftLocked);
keyboard.setShiftLocked(shiftLocked);
mKeyboardView.invalidateAllKeys();
if (!shiftLocked) {
// To be able to turn off caps lock by "double tap" on shift key, we should ignore

View file

@ -1,53 +0,0 @@
/*
* Copyright (C) 2008 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.keyboard;
import android.content.Context;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
// TODO: We should remove this class
public class LatinKeyboard extends Keyboard {
private LatinKeyboard(KeyboardParams params) {
super(params);
}
public static class Builder extends KeyboardBuilder<KeyboardParams> {
public Builder(Context context) {
super(context, new KeyboardParams());
}
@Override
public Builder load(int xmlId, KeyboardId id) {
super.load(xmlId, id);
return this;
}
@Override
public LatinKeyboard build() {
return new LatinKeyboard(mParams);
}
}
@Override
public Key[] getNearestKeys(int x, int y) {
// Avoid dead pixels at edges of the keyboard
return super.getNearestKeys(Math.max(0, Math.min(x, mOccupiedWidth - 1)),
Math.max(0, Math.min(y, mOccupiedHeight - 1)));
}
}

View file

@ -220,8 +220,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
@Override
public boolean onDoubleTap(MotionEvent firstDown) {
final Keyboard keyboard = getKeyboard();
if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
&& ((LatinKeyboard) keyboard).mId.isAlphabetKeyboard()) {
if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard.mId.isAlphabetKeyboard()) {
final int pointerIndex = firstDown.getActionIndex();
final int id = firstDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
@ -452,29 +451,26 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
final int primaryCode = parentKey.mCode;
final Keyboard keyboard = getKeyboard();
if (keyboard instanceof LatinKeyboard) {
final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.mId.isPhoneKeyboard()) {
if (primaryCode == Keyboard.CODE_DIGIT0 && keyboard.mId.isPhoneKeyboard()) {
tracker.onLongPressed();
// Long pressing on 0 in phone number keypad gives you a '+'.
invokeCodeInput(Keyboard.CODE_PLUS);
invokeReleaseKey(primaryCode);
return true;
}
if (primaryCode == Keyboard.CODE_SHIFT && keyboard.mId.isAlphabetKeyboard()) {
tracker.onLongPressed();
invokeCodeInput(Keyboard.CODE_CAPSLOCK);
invokeReleaseKey(primaryCode);
return true;
}
if (primaryCode == Keyboard.CODE_SPACE) {
// Long pressing the space key invokes IME switcher dialog.
if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
tracker.onLongPressed();
// Long pressing on 0 in phone number keypad gives you a '+'.
invokeCodeInput(Keyboard.CODE_PLUS);
invokeReleaseKey(primaryCode);
return true;
}
if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.mId.isAlphabetKeyboard()) {
tracker.onLongPressed();
invokeCodeInput(Keyboard.CODE_CAPSLOCK);
invokeReleaseKey(primaryCode);
return true;
}
if (primaryCode == Keyboard.CODE_SPACE) {
// Long pressing the space key invokes IME switcher dialog.
if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
tracker.onLongPressed();
invokeReleaseKey(primaryCode);
return true;
}
}
}
return openMoreKeysPanel(parentKey, tracker);
}

View file

@ -65,7 +65,6 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.latin.suggestions.SuggestionsView;
@ -293,13 +292,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
setSpacebarTextFadeFactor(inputView,
(1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
(LatinKeyboard)msg.obj);
(Keyboard)msg.obj);
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
mDurationOfFadeoutLanguageOnSpacebar);
break;
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
(LatinKeyboard)msg.obj);
(Keyboard)msg.obj);
break;
}
}
@ -340,10 +339,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
float fadeFactor, LatinKeyboard oldKeyboard) {
float fadeFactor, Keyboard oldKeyboard) {
if (inputView == null) return;
final Keyboard keyboard = inputView.getKeyboard();
if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
if (keyboard == oldKeyboard) {
inputView.updateSpacebar(fadeFactor,
SubtypeSwitcher.getInstance().needsToDisplayLanguage(
keyboard.mId.mLocale));
@ -356,7 +355,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView();
if (inputView != null) {
final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard();
final Keyboard keyboard = latinIme.mKeyboardSwitcher.getKeyboard();
// The language is always displayed when the delay is negative.
final boolean needsToDisplayLanguage = localeChanged
|| mDelayBeforeFadeoutLanguageOnSpacebar < 0;
@ -1718,7 +1717,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
// getSuggestedWordBuilder handles gracefully a null value of prevWord
final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
&& mSuggest.hasAutoCorrection();
@ -1867,7 +1866,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// pressed space on purpose of displaying the suggestion strip punctuation.
final int rawPrimaryCode = suggestion.charAt(0);
// Maybe apply the "bidi mirrored" conversions for parentheses
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);
@ -1969,7 +1968,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
mSettingsValues.mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer,
prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
if (builder.size() > 0) {
// Explicitly supply an empty typed word (the no-second-arg version of
@ -2095,7 +2094,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// "ic" must not be null
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
final CharSequence word) {
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard());
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
mComposingStateManager.onStartComposingText();
ic.deleteSurroundingText(word.length(), 0);
ic.setComposingText(word, 1);
@ -2436,7 +2435,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :");
final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode);
p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);

View file

@ -16,10 +16,9 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.Keyboard;
import java.util.ArrayList;
import java.util.Arrays;
@ -174,7 +173,7 @@ public class WordComposer {
/**
* Internal method to retrieve reasonable proximity info for a character.
*/
private void addKeyInfo(final int codePoint, final LatinKeyboard keyboard,
private void addKeyInfo(final int codePoint, final Keyboard keyboard,
final KeyDetector keyDetector) {
for (final Key key : keyboard.mKeys) {
if (key.mCode == codePoint) {
@ -194,7 +193,7 @@ public class WordComposer {
* Set the currently composing word to the one passed as an argument.
* This will register NOT_A_COORDINATE for X and Ys, and use the passed keyboard for proximity.
*/
public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard,
public void setComposingWord(final CharSequence word, final Keyboard keyboard,
final KeyDetector keyDetector) {
reset();
final int length = word.length();
@ -208,7 +207,7 @@ public class WordComposer {
/**
* Shortcut for the above method, this will create a new KeyDetector for the passed keyboard.
*/
public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard) {
public void setComposingWord(final CharSequence word, final Keyboard keyboard) {
final KeyDetector keyDetector = new KeyDetector(0);
keyDetector.setKeyboard(keyboard, 0, 0);
keyDetector.setProximityCorrectionEnabled(true);

View file

@ -179,7 +179,7 @@ public class MoreSuggestions extends Keyboard {
public Builder layout(SuggestedWords suggestions, int fromPos, int maxWidth,
int minWidth, int maxRow) {
final Keyboard keyboard = KeyboardSwitcher.getInstance().getLatinKeyboard();
final Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard();
final int xmlId = R.xml.kbd_suggestions_pane_template;
load(xmlId, keyboard.mId);
mParams.mVerticalGap = mParams.mTopPadding = keyboard.mVerticalGap / 2;

View file

@ -20,8 +20,10 @@ import android.content.Context;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import java.io.File;
import java.util.Locale;
@ -29,7 +31,7 @@ import java.util.Locale;
public class SuggestHelper {
protected final Suggest mSuggest;
protected int mCorrectionMode;
protected final LatinKeyboard mKeyboard;
protected final Keyboard mKeyboard;
private final KeyDetector mKeyDetector;
public static final int ALPHABET_KEYBOARD = com.android.inputmethod.latin.R.xml.kbd_qwerty;
@ -38,7 +40,8 @@ public class SuggestHelper {
// Use null as the locale for Suggest so as to force it to use the internal dictionary
// (and not try to find a dictionary provider for a specified locale)
mSuggest = new Suggest(context, dictionaryId, null);
mKeyboard = new LatinKeyboard.Builder(context).load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyboard = new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams())
.load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyDetector = new KeyDetector(0);
init();
}
@ -47,7 +50,8 @@ public class SuggestHelper {
final long startOffset, final long length, final KeyboardId keyboardId,
final Locale locale) {
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale);
mKeyboard = new LatinKeyboard.Builder(context).load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyboard = new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams())
.load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyDetector = new KeyDetector(0);
init();
}