am 4c8a96cf: Merge "Fix additional subtype id calculation"

* commit '4c8a96cf88c9883a10216337801ec219e48d7689':
  Fix additional subtype id calculation
main
Tadashi G. Takaoka 2013-11-14 01:42:19 -08:00 committed by Android Git Automerger
commit f534954e14
2 changed files with 26 additions and 22 deletions

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.utils; package com.android.inputmethod.latin.utils;
import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE; import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME; import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME;
@ -27,10 +28,10 @@ import android.util.Log;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils; import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
public final class AdditionalSubtypeUtils { public final class AdditionalSubtypeUtils {
private static final String TAG = AdditionalSubtypeUtils.class.getSimpleName(); private static final String TAG = AdditionalSubtypeUtils.class.getSimpleName();
@ -146,31 +147,36 @@ public final class AdditionalSubtypeUtils {
return sb.toString(); return sb.toString();
} }
private static InputMethodSubtype buildInputMethodSubtype(int nameId, String localeString, private static InputMethodSubtype buildInputMethodSubtype(final int nameId,
String layoutExtraValue, String additionalSubtypeExtraValue) { final String localeString, final String layoutExtraValue,
// CAVEAT! If you want to change subtypeId after changing the extra values, final String additionalSubtypeExtraValue) {
// you must change "getInputMethodSubtypeId". But it will remove the additional keyboard // To preserve additional subtype settings and user's selection across OS updates, subtype
// from the current users. So, you should be really careful to change it. // id shouldn't be changed. New attributes, such as emojiCapable, are carefully excluded
final int subtypeId = getInputMethodSubtypeId(nameId, localeString, layoutExtraValue, // from the calculation of subtype id.
additionalSubtypeExtraValue); final String compatibleExtraValue = StringUtils.joinCommaSplittableText(
layoutExtraValue, additionalSubtypeExtraValue);
final int compatibleSubtypeId = getInputMethodSubtypeId(localeString, compatibleExtraValue);
final String extraValue; final String extraValue;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // Color Emoji is supported from KitKat.
extraValue = layoutExtraValue + "," + additionalSubtypeExtraValue if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE extraValue = StringUtils.appendToCommaSplittableTextIfNotExists(
+ "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE; EMOJI_CAPABLE, compatibleExtraValue);
} else { } else {
extraValue = layoutExtraValue + "," + additionalSubtypeExtraValue; extraValue = compatibleExtraValue;
} }
return InputMethodSubtypeCompatUtils.newInputMethodSubtype(nameId, return InputMethodSubtypeCompatUtils.newInputMethodSubtype(nameId,
R.drawable.ic_ime_switcher_dark, localeString, KEYBOARD_MODE, extraValue, R.drawable.ic_ime_switcher_dark, localeString, KEYBOARD_MODE, extraValue,
false, false, subtypeId); false, false, compatibleSubtypeId);
} }
private static int getInputMethodSubtypeId(int nameId, String localeString, private static int getInputMethodSubtypeId(final String localeString, final String extraValue) {
String layoutExtraValue, String additionalSubtypeExtraValue) { // From the compatibility point of view, the calculation of subtype id has been copied from
// TODO: Use InputMethodSubtypeBuilder once we use SDK version 19. // {@link InputMethodSubtype} of JellyBean MR2.
return (new InputMethodSubtype(nameId, R.drawable.ic_ime_switcher_dark, return Arrays.hashCode(new Object[] {
localeString, KEYBOARD_MODE, layoutExtraValue + "," + additionalSubtypeExtraValue, localeString,
false, false)).hashCode(); KEYBOARD_MODE,
extraValue,
false /* isAuxiliary */,
false /* overrideImplicitlyEnabledSubtype */ });
} }
} }

View File

@ -82,8 +82,6 @@ public final class StringUtils {
return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT)); return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT));
} }
// Remove @UsedForTesting annotation once this method is used in the production code.
@UsedForTesting
public static String joinCommaSplittableText(final String head, final String tail) { public static String joinCommaSplittableText(final String head, final String tail) {
if (TextUtils.isEmpty(head) && TextUtils.isEmpty(tail)) { if (TextUtils.isEmpty(head) && TextUtils.isEmpty(tail)) {
return EMPTY_STRING; return EMPTY_STRING;