1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.inputmethod.compat; 18 19 import android.os.Build; 20 import android.view.inputmethod.InputMethodSubtype; 21 22 import java.lang.reflect.Constructor; 23 24 public final class InputMethodSubtypeCompatUtils { 25 private static final String TAG = InputMethodSubtypeCompatUtils.class.getSimpleName(); 26 // Note that InputMethodSubtype(int nameId, int iconId, String locale, String mode, 27 // String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, int id) 28 // has been introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). 29 private static final Constructor<?> CONSTRUCTOR_INPUT_METHOD_SUBTYPE = 30 CompatUtils.getConstructor(InputMethodSubtype.class, 31 Integer.TYPE, Integer.TYPE, String.class, String.class, String.class, 32 Boolean.TYPE, Boolean.TYPE, Integer.TYPE); 33 static { 34 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 35 if (CONSTRUCTOR_INPUT_METHOD_SUBTYPE == null) { 36 android.util.Log.w(TAG, "Warning!!! Constructor is not defined."); 37 } 38 } 39 } 40 private InputMethodSubtypeCompatUtils() { 41 // This utility class is not publicly instantiable. 42 } 43 44 public static InputMethodSubtype newInputMethodSubtype(int nameId, int iconId, String locale, 45 String mode, String extraValue, boolean isAuxiliary, 46 boolean overridesImplicitlyEnabledSubtype, int id) { 47 if (CONSTRUCTOR_INPUT_METHOD_SUBTYPE == null 48 || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 49 return new InputMethodSubtype(nameId, iconId, locale, mode, extraValue, isAuxiliary, 50 overridesImplicitlyEnabledSubtype); 51 } 52 return (InputMethodSubtype) CompatUtils.newInstance(CONSTRUCTOR_INPUT_METHOD_SUBTYPE, 53 nameId, iconId, locale, mode, extraValue, isAuxiliary, 54 overridesImplicitlyEnabledSubtype, id); 55 } 56 } 57