aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2014-05-09 11:28:19 +0000
committerKen Wakasa <kwakasa@google.com>2014-05-09 11:28:19 +0000
commitd47dca429e74b47cfbf4200dd23c8f5a1e5791ec (patch)
treee8b0e730da7a0d46cd21fe62ea23cd499a310a17 /java/src/com/android/inputmethod
parent19688b584bb903192559196a0e3836bc4c957696 (diff)
downloadlatinime-d47dca429e74b47cfbf4200dd23c8f5a1e5791ec.tar.gz
latinime-d47dca429e74b47cfbf4200dd23c8f5a1e5791ec.tar.xz
latinime-d47dca429e74b47cfbf4200dd23c8f5a1e5791ec.zip
Revert "Refactor KeyboardTheme"
This reverts commit 19688b584bb903192559196a0e3836bc4c957696. Build breakage. Change-Id: I95d4be1578824eaee5a2fb08ec277250727ac668
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java7
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardTheme.java126
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsFragment.java25
4 files changed, 24 insertions, 136 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 4a46a4a46..1cd6ef249 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -64,7 +64,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
* what user actually typed. */
private boolean mIsAutoCorrectionActive;
- private KeyboardTheme mKeyboardTheme;
+ private KeyboardTheme mKeyboardTheme = KeyboardTheme.getDefaultKeyboardTheme();
private Context mThemeContext;
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
@@ -101,7 +101,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
final KeyboardTheme keyboardTheme) {
- if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) {
+ if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
KeyboardLayoutSet.clearKeyboardCache();
@@ -342,8 +342,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mKeyboardView.closing();
}
- updateKeyboardThemeAndContextThemeWrapper(
- mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs));
+ updateKeyboardThemeAndContextThemeWrapper(mLatinIME, mKeyboardTheme);
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
R.layout.input_view, null);
mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
index 5034540cf..4db72ad4d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
@@ -17,86 +17,34 @@
package com.android.inputmethod.keyboard;
import android.content.SharedPreferences;
-import android.os.Build;
-import android.os.Build.VERSION_CODES;
import android.util.Log;
import com.android.inputmethod.latin.R;
-
-import java.util.Arrays;
-import java.util.Comparator;
+import com.android.inputmethod.latin.settings.Settings;
public final class KeyboardTheme {
private static final String TAG = KeyboardTheme.class.getSimpleName();
- static final String KITKAT_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916";
- static final String KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509";
-
- static final int THEME_ID_ICS = 0;
- static final int THEME_ID_KLP = 2;
- static final int THEME_ID_LMP = 3;
- static final int DEFAULT_THEME_ID = THEME_ID_KLP;
+ public static final int THEME_ID_ICS = 0;
+ public static final int THEME_ID_KLP = 2;
+ private static final int DEFAULT_THEME_ID = THEME_ID_KLP;
private static final KeyboardTheme[] KEYBOARD_THEMES = {
- new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS,
- VERSION_CODES.ICE_CREAM_SANDWICH),
- new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP,
- VERSION_CODES.KITKAT),
- // TODO: Update to LMP style.
- new KeyboardTheme(THEME_ID_LMP, R.style.KeyboardTheme_KLP,
- // TODO: Update this constant once the *next* version becomes available.
- VERSION_CODES.CUR_DEVELOPMENT),
+ new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS),
+ new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP),
};
- static {
- // Sort {@link #KEYBOARD_THEME} by descending order of {@link #mMinApiVersion}.
- Arrays.sort(KEYBOARD_THEMES, new Comparator<KeyboardTheme>() {
- @Override
- public int compare(final KeyboardTheme lhs, final KeyboardTheme rhs) {
- if (lhs.mMinApiVersion > rhs.mMinApiVersion) return -1;
- if (lhs.mMinApiVersion < rhs.mMinApiVersion) return 1;
- return 0;
- }
- });
- }
public final int mThemeId;
public final int mStyleId;
- final int mMinApiVersion;
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
- // in values/themes-<style>.xml.
- private KeyboardTheme(final int themeId, final int styleId, final int minApiVersion) {
+ // in values/style.xml.
+ public KeyboardTheme(final int themeId, final int styleId) {
mThemeId = themeId;
mStyleId = styleId;
- mMinApiVersion = minApiVersion;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (o == this) return true;
- return (o instanceof KeyboardTheme) && ((KeyboardTheme)o).mThemeId == mThemeId;
}
- @Override
- public int hashCode() {
- return mThemeId;
- }
-
- // TODO: This method should be removed when {@link LatinImeLogger} is removed.
- public int getCompatibleThemeIdForLogging() {
- switch (mThemeId) {
- case THEME_ID_ICS:
- return 5;
- case THEME_ID_KLP:
- return 9;
- case THEME_ID_LMP:
- return 10;
- default: // Invalid theme
- return -1;
- }
- }
-
- private static KeyboardTheme searchKeyboardThemeById(final int themeId) {
+ private static KeyboardTheme searchKeyboardTheme(final int themeId) {
// TODO: This search algorithm isn't optimal if there are many themes.
for (final KeyboardTheme theme : KEYBOARD_THEMES) {
if (theme.mThemeId == themeId) {
@@ -106,57 +54,18 @@ public final class KeyboardTheme {
return null;
}
- private static int getSdkVersion() {
- final int sdkVersion = Build.VERSION.SDK_INT;
- // TODO: Consider to remove this check once the *next* version becomes available.
- if (sdkVersion == VERSION_CODES.KITKAT && Build.VERSION.CODENAME.startsWith("L")) {
- return VERSION_CODES.CUR_DEVELOPMENT;
- }
- return sdkVersion;
- }
-
- static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
- final int sdkVersion) {
- final String obsoleteIdString = prefs.getString(KITKAT_KEYBOARD_THEME_KEY, null);
- if (obsoleteIdString != null) {
- // Remove old preference.
- prefs.edit().remove(KITKAT_KEYBOARD_THEME_KEY).apply();
- if (sdkVersion <= VERSION_CODES.KITKAT) {
- try {
- final int themeId = Integer.parseInt(obsoleteIdString);
- final KeyboardTheme theme = searchKeyboardThemeById(themeId);
- if (theme != null) {
- return theme;
- }
- Log.w(TAG, "Unknown keyboard theme in preference: " + obsoleteIdString);
- } catch (final NumberFormatException e) {
- Log.w(TAG, "Illegal keyboard theme in preference: " + obsoleteIdString);
- }
- }
- }
- // TODO: This search algorithm isn't optimal if there are many themes.
- for (final KeyboardTheme theme : KEYBOARD_THEMES) {
- if (sdkVersion >= theme.mMinApiVersion) {
- return theme;
- }
- }
- return searchKeyboardThemeById(DEFAULT_THEME_ID);
- }
-
- public static void saveKeyboardThemeId(final String themeIdString,
- final SharedPreferences prefs) {
- prefs.edit().putString(KEYBOARD_THEME_KEY, themeIdString).apply();
+ public static KeyboardTheme getDefaultKeyboardTheme() {
+ return searchKeyboardTheme(DEFAULT_THEME_ID);
}
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
- final int sdkVersion = getSdkVersion();
- final String themeIdString = prefs.getString(KEYBOARD_THEME_KEY, null);
+ final String themeIdString = prefs.getString(Settings.PREF_KEYBOARD_LAYOUT, null);
if (themeIdString == null) {
- return getDefaultKeyboardTheme(prefs, sdkVersion);
+ return getDefaultKeyboardTheme();
}
try {
final int themeId = Integer.parseInt(themeIdString);
- final KeyboardTheme theme = searchKeyboardThemeById(themeId);
+ final KeyboardTheme theme = searchKeyboardTheme(themeId);
if (theme != null) {
return theme;
}
@@ -164,8 +73,9 @@ public final class KeyboardTheme {
} catch (final NumberFormatException e) {
Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString);
}
- // Remove preference.
- prefs.edit().remove(KEYBOARD_THEME_KEY).apply();
- return getDefaultKeyboardTheme(prefs, sdkVersion);
+ // Reset preference to default value.
+ final String defaultThemeIdString = Integer.toString(DEFAULT_THEME_ID);
+ prefs.edit().putString(Settings.PREF_KEYBOARD_LAYOUT, defaultThemeIdString).apply();
+ return getDefaultKeyboardTheme();
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 4e4c8885c..a3aae8cb3 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -64,7 +64,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
"pref_show_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
"pref_include_other_imes_in_language_switch_list";
- public static final String PREF_KEYBOARD_THEME = "pref_keyboard_theme";
+ public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
// TODO: consolidate key preview dismiss delay with the key preview animation parameters.
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
index e1d38e7c4..22cbd204c 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
@@ -37,7 +37,6 @@ import android.util.Log;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
-import com.android.inputmethod.keyboard.KeyboardTheme;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher;
@@ -254,31 +253,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
}
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- final ListPreference keyboardThemePref = (ListPreference)findPreference(
- Settings.PREF_KEYBOARD_THEME);
- if (keyboardThemePref != null) {
- final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
- final String value = Integer.toString(keyboardTheme.mThemeId);
- final CharSequence entries[] = keyboardThemePref.getEntries();
- final int entryIndex = keyboardThemePref.findIndexOfValue(value);
- keyboardThemePref.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
- keyboardThemePref.setValue(value);
- }
+ updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
updateCustomInputStylesSummary(prefs, res);
}
@Override
- public void onPause() {
- super.onPause();
- final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- final ListPreference keyboardThemePref = (ListPreference)findPreference(
- Settings.PREF_KEYBOARD_THEME);
- if (keyboardThemePref != null) {
- KeyboardTheme.saveKeyboardThemeId(keyboardThemePref.getValue(), prefs);
- }
- }
-
- @Override
public void onDestroy() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
this);
@@ -308,7 +287,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
ensureConsistencyOfAutoCorrectionSettings();
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME);
+ updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}