Merge "Refactor KeyboardTheme as top-level class"
commit
3568fca95f
|
@ -45,28 +45,6 @@ import com.android.inputmethod.latin.utils.ResourceUtils;
|
||||||
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
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 SubtypeSwitcher mSubtypeSwitcher;
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
|
|
||||||
|
@ -88,7 +66,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
* what user actually typed. */
|
* what user actually typed. */
|
||||||
private boolean mIsAutoCorrectionActive;
|
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 Context mThemeContext;
|
||||||
|
|
||||||
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||||
|
@ -127,13 +106,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
final SharedPreferences prefs) {
|
final SharedPreferences prefs) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
final int index = Settings.readKeyboardThemeIndex(prefs, res);
|
final int index = Settings.readKeyboardThemeIndex(prefs, res);
|
||||||
if (index >= 0 && index < KEYBOARD_THEMES.length) {
|
if (index >= 0 && index < KeyboardTheme.KEYBOARD_THEMES.length) {
|
||||||
return KEYBOARD_THEMES[index];
|
return KeyboardTheme.KEYBOARD_THEMES[index];
|
||||||
}
|
}
|
||||||
final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
|
final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
|
||||||
Log.w(TAG, "Illegal keyboard theme in preference: " + index + ", default to "
|
Log.w(TAG, "Illegal keyboard theme in preference: " + index + ", default to "
|
||||||
+ defaultThemeIndex);
|
+ defaultThemeIndex);
|
||||||
return KEYBOARD_THEMES[defaultThemeIndex];
|
return KeyboardTheme.KEYBOARD_THEMES[defaultThemeIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,7 @@ import android.content.res.Resources;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
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.AudioAndHapticFeedbackManager;
|
||||||
import com.android.inputmethod.latin.InputAttributes;
|
import com.android.inputmethod.latin.InputAttributes;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
@ -292,7 +292,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(defaultThemeIndexString);
|
return Integer.parseInt(defaultThemeIndexString);
|
||||||
} catch (final NumberFormatException e) {
|
} 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
|
Log.e(TAG, "Corrupted default keyoard theme in resource: " + defaultThemeIndexString
|
||||||
+ ", default to " + defaultThemeIndex, e);
|
+ ", default to " + defaultThemeIndex, e);
|
||||||
return defaultThemeIndex;
|
return defaultThemeIndex;
|
||||||
|
|
|
@ -27,7 +27,6 @@ import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
||||||
import com.android.inputmethod.keyboard.KeyboardLayoutSet.Builder;
|
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.Constants;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
||||||
|
@ -42,7 +41,7 @@ import java.util.Locale;
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
private static final KeyboardTheme DEFAULT_KEYBOARD_THEME =
|
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.
|
// All input method subtypes of LatinIME.
|
||||||
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
|
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
|
||||||
|
|
Loading…
Reference in New Issue