Refactor KeyboardTheme as top-level class

This CL should be checked in together with I63e33388f9.

Bug: 14042743
Change-Id: I13f0a45bac6f19e006bf1280a36173e52d6d7160
main
Tadashi G. Takaoka 2014-04-14 17:09:12 +09:00
parent da498229f4
commit d6aa94e6b5
4 changed files with 50 additions and 30 deletions

View File

@ -45,28 +45,6 @@ import com.android.inputmethod.latin.utils.ResourceUtils;
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
public static final class KeyboardTheme {
public final int mThemeId;
public final int mStyleId;
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
// in values/style.xml.
public KeyboardTheme(final int themeId, final int styleId) {
mThemeId = themeId;
mStyleId = styleId;
}
}
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 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),
new KeyboardTheme(THEME_INDEX_KLP, R.style.KeyboardTheme_KLP),
};
private SubtypeSwitcher mSubtypeSwitcher;
private SharedPreferences mPrefs;
@ -88,7 +66,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
* what user actually typed. */
private boolean mIsAutoCorrectionActive;
private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[DEFAULT_THEME_INDEX];
private KeyboardTheme mKeyboardTheme =
KeyboardTheme.KEYBOARD_THEMES[KeyboardTheme.DEFAULT_THEME_INDEX];
private Context mThemeContext;
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
@ -127,13 +106,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final SharedPreferences prefs) {
final Resources res = context.getResources();
final int index = Settings.readKeyboardThemeIndex(prefs, res);
if (index >= 0 && index < KEYBOARD_THEMES.length) {
return KEYBOARD_THEMES[index];
if (index >= 0 && index < KeyboardTheme.KEYBOARD_THEMES.length) {
return KeyboardTheme.KEYBOARD_THEMES[index];
}
final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
Log.w(TAG, "Illegal keyboard theme in preference: " + index + ", default to "
+ defaultThemeIndex);
return KEYBOARD_THEMES[defaultThemeIndex];
return KeyboardTheme.KEYBOARD_THEMES[defaultThemeIndex];
}
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.R;
public final class KeyboardTheme {
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 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),
new KeyboardTheme(THEME_INDEX_KLP, R.style.KeyboardTheme_KLP),
};
public final int mThemeId;
public final int mStyleId;
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
// in values/style.xml.
public KeyboardTheme(final int themeId, final int styleId) {
mThemeId = themeId;
mStyleId = styleId;
}
}

View File

@ -23,7 +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.keyboard.KeyboardTheme;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
@ -292,7 +292,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
try {
return Integer.parseInt(defaultThemeIndexString);
} catch (final NumberFormatException e) {
final int defaultThemeIndex = KeyboardSwitcher.DEFAULT_THEME_INDEX;
final int defaultThemeIndex = KeyboardTheme.DEFAULT_THEME_INDEX;
Log.e(TAG, "Corrupted default keyoard theme in resource: " + defaultThemeIndexString
+ ", default to " + defaultThemeIndex, e);
return defaultThemeIndex;

View File

@ -27,7 +27,6 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.Builder;
import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardTheme;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
@ -42,7 +41,7 @@ import java.util.Locale;
@SmallTest
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
private static final KeyboardTheme DEFAULT_KEYBOARD_THEME =
KeyboardSwitcher.KEYBOARD_THEMES[KeyboardSwitcher.DEFAULT_THEME_INDEX];
KeyboardTheme.KEYBOARD_THEMES[KeyboardTheme.DEFAULT_THEME_INDEX];
// All input method subtypes of LatinIME.
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();