diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 0aed5068c..d35948bad 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -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 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); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index d5ea76a2f..df7296bb9 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -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; } } diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java index 2e362458b..0c023bd78 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java @@ -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);