am 78cff10f: Add BuildCompatUtils to get an effective platfrom API version

* commit '78cff10f8d317641dd3531cce04e74502be8ad44':
  Add BuildCompatUtils to get an effective platfrom API version
main
Tadashi G. Takaoka 2014-08-13 07:48:25 +00:00 committed by Android Git Automerger
commit bdb05cc89f
5 changed files with 52 additions and 23 deletions

View File

@ -0,0 +1,43 @@
/*
* 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.compat;
import android.os.Build;
public final class BuildCompatUtils {
private BuildCompatUtils() {
// This utility class is not publicly instantiable.
}
private static final boolean IS_RELEASE_BUILD = Build.VERSION.CODENAME.equals("REL");
/**
* The "effective" API version.
* {@link android.os.Build.VERSION#SDK_INT} if the platform is a release build.
* {@link android.os.Build.VERSION#SDK_INT} plus 1 if the platform is a development build.
*/
public static final int EFFECTIVE_SDK_INT = IS_RELEASE_BUILD
? Build.VERSION.SDK_INT
: Build.VERSION.SDK_INT + 1;
/**
* API version for L-release.
*/
// TODO: Substitute this constant reference with Build.VERSION_CODES.L* once the *next* version
// becomes available.
public static final int VERSION_CODES_LXX = 21;
}

View File

@ -17,11 +17,11 @@
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.annotations.UsedForTesting;
import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.latin.R;
import java.util.Arrays;
@ -47,8 +47,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
VERSION_CODES.ICE_CREAM_SANDWICH),
new KeyboardTheme(THEME_ID_LXX_LIGHT, R.style.KeyboardTheme_LXX_Light,
// Default theme for LXX.
// TODO: Update this constant once the *next* version becomes available.
VERSION_CODES.CUR_DEVELOPMENT),
BuildCompatUtils.VERSION_CODES_LXX),
new KeyboardTheme(THEME_ID_LXX_DARK, R.style.KeyboardTheme_LXX_Dark,
VERSION_CODES.BASE),
};
@ -99,15 +98,6 @@ public final class KeyboardTheme implements Comparable<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) {
return VERSION_CODES.CUR_DEVELOPMENT;
}
return sdkVersion;
}
@UsedForTesting
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
final int sdkVersion) {
@ -140,7 +130,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
public static void saveKeyboardThemeId(final String themeIdString,
final SharedPreferences prefs) {
saveKeyboardThemeId(themeIdString, prefs, getSdkVersion());
saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
}
@UsedForTesting
@ -159,7 +149,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
}
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
return getKeyboardTheme(prefs, getSdkVersion());
return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
}
@UsedForTesting

View File

@ -24,6 +24,7 @@ import android.os.Build;
import android.util.Log;
import android.util.Pair;
import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
@ -121,9 +122,7 @@ final class EmojiCategory {
sCategoryTabIconAttr[i], 0);
}
addShownCategoryId(EmojiCategory.ID_RECENTS);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2
|| android.os.Build.VERSION.CODENAME.equalsIgnoreCase("KeyLimePie")
|| android.os.Build.VERSION.CODENAME.equalsIgnoreCase("KitKat")) {
if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.KITKAT) {
addShownCategoryId(EmojiCategory.ID_PEOPLE);
addShownCategoryId(EmojiCategory.ID_OBJECTS);
addShownCategoryId(EmojiCategory.ID_NATURE);

View File

@ -24,6 +24,7 @@ import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
@ -68,9 +69,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_BLOCK_POTENTIALLY_OFFENSIVE =
"pref_key_block_potentially_offensive";
public static final boolean ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS =
(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
|| (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT
&& Build.VERSION.CODENAME.equals("REL"));
BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
"pref_show_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.keyboard;
import static com.android.inputmethod.compat.BuildCompatUtils.VERSION_CODES_LXX;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_ICS;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_KLP;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_DARK;
@ -31,9 +32,6 @@ import android.test.suitebuilder.annotation.SmallTest;
public class KeyboardThemeTests extends AndroidTestCase {
private SharedPreferences mPrefs;
// TODO: Remove this constant once the *next* version becomes available.
private static final int VERSION_CODES_LXX = VERSION_CODES.CUR_DEVELOPMENT;
private static final int THEME_ID_NULL = -1;
private static final int THEME_ID_UNKNOWN = -2;
private static final int THEME_ID_ILLEGAL = -3;