am 88e079ae: Cleanup redundant methods of KeyboardSet

* commit '88e079ae6bbff1093b28f60e81d2befce1030495':
  Cleanup redundant methods of KeyboardSet
main
Tadashi G. Takaoka 2012-01-31 01:33:04 -08:00 committed by Android Git Automerger
commit 1b568bd4d1
3 changed files with 26 additions and 23 deletions

View File

@ -59,6 +59,14 @@ public class KeyboardSet {
private final Params mParams; private final Params mParams;
private final KeysCache mKeysCache = new KeysCache(); private final KeysCache mKeysCache = new KeysCache();
public static class KeyboardSetException extends RuntimeException {
public final KeyboardId mKeyboardId;
public KeyboardSetException(Throwable cause, KeyboardId keyboardId) {
super(cause);
mKeyboardId = keyboardId;
}
}
public static class KeysCache { public static class KeysCache {
private final Map<Key, Key> mMap; private final Map<Key, Key> mMap;
@ -107,11 +115,6 @@ public class KeyboardSet {
mParams = params; mParams = params;
} }
// TODO: Remove this method, use {@link #getKeyboard} directly.
public Keyboard getMainKeyboard() {
return getKeyboard(KeyboardId.ELEMENT_ALPHABET);
}
public Keyboard getKeyboard(int baseKeyboardSetElementId) { public Keyboard getKeyboard(int baseKeyboardSetElementId) {
final int keyboardSetElementId; final int keyboardSetElementId;
switch (mParams.mMode) { switch (mParams.mMode) {
@ -134,8 +137,11 @@ public class KeyboardSet {
KeyboardId.ELEMENT_ALPHABET); KeyboardId.ELEMENT_ALPHABET);
} }
final KeyboardId id = getKeyboardId(keyboardSetElementId); final KeyboardId id = getKeyboardId(keyboardSetElementId);
final Keyboard keyboard = getKeyboard(mContext, keyboardXmlId, id); try {
return keyboard; return getKeyboard(mContext, keyboardXmlId, id);
} catch (RuntimeException e) {
throw new KeyboardSetException(e, id);
}
} }
private Keyboard getKeyboard(Context context, int keyboardXmlId, KeyboardId id) { private Keyboard getKeyboard(Context context, int keyboardXmlId, KeyboardId id) {
@ -169,11 +175,10 @@ public class KeyboardSet {
return keyboard; return keyboard;
} }
// TODO: Make this method private.
// Note: The keyboard for each locale, shift state, and mode are represented as KeyboardSet // Note: The keyboard for each locale, shift state, and mode are represented as KeyboardSet
// element id that is a key in keyboard_set.xml. Also that file specifies which XML layout // element id that is a key in keyboard_set.xml. Also that file specifies which XML layout
// should be used for each keyboard. The KeyboardId is an internal key for Keyboard object. // should be used for each keyboard. The KeyboardId is an internal key for Keyboard object.
public KeyboardId getKeyboardId(int keyboardSetElementId) { private KeyboardId getKeyboardId(int keyboardSetElementId) {
final Params params = mParams; final Params params = mParams;
final boolean isSymbols = (keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS final boolean isSymbols = (keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS
|| keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED); || keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED);

View File

@ -27,6 +27,7 @@ import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.KeyboardSet.KeyboardSetException;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardState; import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.DebugSettings; import com.android.inputmethod.latin.DebugSettings;
@ -138,11 +139,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mKeyboardSet = builder.build(); mKeyboardSet = builder.build();
try { try {
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols)); mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
} catch (RuntimeException e) { } catch (KeyboardSetException e) {
Log.w(TAG, "loading keyboard failed: " + mKeyboardSet.getKeyboardId( Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
KeyboardId.ELEMENT_ALPHABET), e); LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
LatinImeLogger.logOnException(mKeyboardSet.getKeyboardId(
KeyboardId.ELEMENT_ALPHABET).toString(), e);
return; return;
} }
} }

View File

@ -21,6 +21,7 @@ import android.text.TextUtils;
import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSet; import com.android.inputmethod.keyboard.KeyboardSet;
import java.io.File; import java.io.File;
@ -35,22 +36,20 @@ public class SuggestHelper {
public SuggestHelper(Context context, int dictionaryId, KeyboardSet keyboardSet) { public SuggestHelper(Context context, int dictionaryId, KeyboardSet keyboardSet) {
// Use null as the locale for Suggest so as to force it to use the internal dictionary // 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) // (and not try to find a dictionary provider for a specified locale)
mSuggest = new Suggest(context, dictionaryId, null); this(new Suggest(context, dictionaryId, null), keyboardSet);
mKeyboard = keyboardSet.getMainKeyboard();
mKeyDetector = new KeyDetector(0);
init();
} }
protected SuggestHelper(final Context context, final File dictionaryPath, protected SuggestHelper(final Context context, final File dictionaryPath,
final long startOffset, final long length, final KeyboardSet keyboardSet, final long startOffset, final long length, final KeyboardSet keyboardSet,
final Locale locale) { final Locale locale) {
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale); this(new Suggest(context, dictionaryPath, startOffset, length, null, locale), keyboardSet);
mKeyboard = keyboardSet.getMainKeyboard();
mKeyDetector = new KeyDetector(0);
init();
} }
private void init() { private SuggestHelper(final Suggest suggest, final KeyboardSet keyboardSet) {
mSuggest = suggest;
mKeyboard = keyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET);
mKeyDetector = new KeyDetector(0);
setCorrectionMode(Suggest.CORRECTION_FULL); setCorrectionMode(Suggest.CORRECTION_FULL);
mKeyDetector.setKeyboard(mKeyboard, 0, 0); mKeyDetector.setKeyboard(mKeyboard, 0, 0);
mKeyDetector.setProximityCorrectionEnabled(true); mKeyDetector.setProximityCorrectionEnabled(true);