am 1325ddba: Merge "Guard possible NumberFormatException"
* commit '1325ddbae318d75b62f59beb09b989291838be48': Guard possible NumberFormatExceptionmain
commit
79ff39fccd
|
@ -60,7 +60,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
public static final int THEME_INDEX_ICS = 0;
|
||||
public static final int THEME_INDEX_GB = 1;
|
||||
public static final int THEME_INDEX_KLP = 2;
|
||||
public static final int THEME_INDEX_DEFAULT = THEME_INDEX_KLP;
|
||||
public static final int DEFAULT_THEME_INDEX = THEME_INDEX_KLP;
|
||||
public static final KeyboardTheme[] KEYBOARD_THEMES = {
|
||||
new KeyboardTheme(THEME_INDEX_ICS, R.style.KeyboardTheme_ICS),
|
||||
new KeyboardTheme(THEME_INDEX_GB, R.style.KeyboardTheme_GB),
|
||||
|
@ -88,7 +88,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
* what user actually typed. */
|
||||
private boolean mIsAutoCorrectionActive;
|
||||
|
||||
private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[THEME_INDEX_DEFAULT];
|
||||
private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[DEFAULT_THEME_INDEX];
|
||||
private Context mThemeContext;
|
||||
|
||||
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.res.Resources;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
||||
import com.android.inputmethod.latin.InputAttributes;
|
||||
import com.android.inputmethod.latin.R;
|
||||
|
@ -270,25 +271,36 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
}
|
||||
|
||||
public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
|
||||
final String defaultThemeIndex = res.getString(
|
||||
R.string.config_default_keyboard_theme_index);
|
||||
final String themeIndex = prefs.getString(PREF_KEYBOARD_LAYOUT, defaultThemeIndex);
|
||||
final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
|
||||
final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
|
||||
try {
|
||||
return Integer.valueOf(themeIndex);
|
||||
return Integer.parseInt(themeIndexString);
|
||||
} catch (final NumberFormatException e) {
|
||||
// Format error, returns default keyboard theme index.
|
||||
Log.e(TAG, "Illegal keyboard theme in preference: " + themeIndex + ", default to "
|
||||
Log.e(TAG, "Illegal keyboard theme in preference: " + themeIndexString + ", default to "
|
||||
+ defaultThemeIndex, e);
|
||||
return Integer.valueOf(defaultThemeIndex);
|
||||
}
|
||||
return defaultThemeIndex;
|
||||
}
|
||||
|
||||
private static int readDefaultKeyboardThemeIndex(final Resources res) {
|
||||
final String defaultThemeIndexString = res.getString(
|
||||
R.string.config_default_keyboard_theme_index);
|
||||
try {
|
||||
return Integer.parseInt(defaultThemeIndexString);
|
||||
} catch (final NumberFormatException e) {
|
||||
final int defaultThemeIndex = KeyboardSwitcher.DEFAULT_THEME_INDEX;
|
||||
Log.e(TAG, "Corrupted default keyoard theme in resource: " + defaultThemeIndexString
|
||||
+ ", default to " + defaultThemeIndex, e);
|
||||
return defaultThemeIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public static int resetAndGetDefaultKeyboardThemeIndex(final SharedPreferences prefs,
|
||||
final Resources res) {
|
||||
final String defaultThemeIndex = res.getString(
|
||||
R.string.config_default_keyboard_theme_index);
|
||||
prefs.edit().putString(PREF_KEYBOARD_LAYOUT, defaultThemeIndex).apply();
|
||||
return Integer.valueOf(defaultThemeIndex);
|
||||
final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
|
||||
prefs.edit().putString(PREF_KEYBOARD_LAYOUT, Integer.toString(defaultThemeIndex)).apply();
|
||||
return defaultThemeIndex;
|
||||
}
|
||||
|
||||
public static String readPrefAdditionalSubtypes(final SharedPreferences prefs,
|
||||
|
|
|
@ -285,7 +285,7 @@ public final class SettingsValues {
|
|||
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
|
||||
final float autoCorrectionThreshold;
|
||||
try {
|
||||
final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
|
||||
final int arrayIndex = Integer.parseInt(currentAutoCorrectionSetting);
|
||||
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
|
||||
final String val = autoCorrectionThresholdValues[arrayIndex];
|
||||
if (FLOAT_MAX_VALUE_MARKER_STRING.equals(val)) {
|
||||
|
|
|
@ -42,7 +42,7 @@ import java.util.Locale;
|
|||
@SmallTest
|
||||
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||
private static final KeyboardTheme DEFAULT_KEYBOARD_THEME =
|
||||
KeyboardSwitcher.KEYBOARD_THEMES[KeyboardSwitcher.THEME_INDEX_DEFAULT];
|
||||
KeyboardSwitcher.KEYBOARD_THEMES[KeyboardSwitcher.DEFAULT_THEME_INDEX];
|
||||
|
||||
// All input method subtypes of LatinIME.
|
||||
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
|
||||
|
|
Loading…
Reference in New Issue