Cleanup redundant methods of KeyboardSet
Change-Id: I69fa1b5661695d0323222c2969679f4792b6ef0d
This commit is contained in:
parent
0ed2d3a449
commit
88e079ae6b
3 changed files with 26 additions and 23 deletions
|
@ -59,6 +59,14 @@ public class KeyboardSet {
|
|||
private final Params mParams;
|
||||
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 {
|
||||
private final Map<Key, Key> mMap;
|
||||
|
||||
|
@ -107,11 +115,6 @@ public class KeyboardSet {
|
|||
mParams = params;
|
||||
}
|
||||
|
||||
// TODO: Remove this method, use {@link #getKeyboard} directly.
|
||||
public Keyboard getMainKeyboard() {
|
||||
return getKeyboard(KeyboardId.ELEMENT_ALPHABET);
|
||||
}
|
||||
|
||||
public Keyboard getKeyboard(int baseKeyboardSetElementId) {
|
||||
final int keyboardSetElementId;
|
||||
switch (mParams.mMode) {
|
||||
|
@ -134,8 +137,11 @@ public class KeyboardSet {
|
|||
KeyboardId.ELEMENT_ALPHABET);
|
||||
}
|
||||
final KeyboardId id = getKeyboardId(keyboardSetElementId);
|
||||
final Keyboard keyboard = getKeyboard(mContext, keyboardXmlId, id);
|
||||
return keyboard;
|
||||
try {
|
||||
return getKeyboard(mContext, keyboardXmlId, id);
|
||||
} catch (RuntimeException e) {
|
||||
throw new KeyboardSetException(e, id);
|
||||
}
|
||||
}
|
||||
|
||||
private Keyboard getKeyboard(Context context, int keyboardXmlId, KeyboardId id) {
|
||||
|
@ -169,11 +175,10 @@ public class KeyboardSet {
|
|||
return keyboard;
|
||||
}
|
||||
|
||||
// TODO: Make this method private.
|
||||
// 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
|
||||
// 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 boolean isSymbols = (keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS
|
||||
|| keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED);
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.view.View;
|
|||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
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.internal.KeyboardState;
|
||||
import com.android.inputmethod.latin.DebugSettings;
|
||||
|
@ -138,11 +139,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
mKeyboardSet = builder.build();
|
||||
try {
|
||||
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(TAG, "loading keyboard failed: " + mKeyboardSet.getKeyboardId(
|
||||
KeyboardId.ELEMENT_ALPHABET), e);
|
||||
LatinImeLogger.logOnException(mKeyboardSet.getKeyboardId(
|
||||
KeyboardId.ELEMENT_ALPHABET).toString(), e);
|
||||
} catch (KeyboardSetException e) {
|
||||
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
||||
LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ 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.KeyboardSet;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -35,22 +36,20 @@ public class SuggestHelper {
|
|||
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
|
||||
// (and not try to find a dictionary provider for a specified locale)
|
||||
mSuggest = new Suggest(context, dictionaryId, null);
|
||||
mKeyboard = keyboardSet.getMainKeyboard();
|
||||
mKeyDetector = new KeyDetector(0);
|
||||
init();
|
||||
this(new Suggest(context, dictionaryId, null), keyboardSet);
|
||||
}
|
||||
|
||||
protected SuggestHelper(final Context context, final File dictionaryPath,
|
||||
final long startOffset, final long length, final KeyboardSet keyboardSet,
|
||||
final Locale locale) {
|
||||
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale);
|
||||
mKeyboard = keyboardSet.getMainKeyboard();
|
||||
mKeyDetector = new KeyDetector(0);
|
||||
init();
|
||||
this(new Suggest(context, dictionaryPath, startOffset, length, null, locale), keyboardSet);
|
||||
}
|
||||
|
||||
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);
|
||||
mKeyDetector.setKeyboard(mKeyboard, 0, 0);
|
||||
mKeyDetector.setProximityCorrectionEnabled(true);
|
||||
|
|
Loading…
Reference in a new issue