diff options
Diffstat (limited to 'java/src/com/android/inputmethod/compat')
6 files changed, 3 insertions, 293 deletions
diff --git a/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java b/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java deleted file mode 100644 index 011473bef..000000000 --- a/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2011 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.util.Log; - -import java.lang.reflect.Method; -import java.util.Arrays; - -public class ArraysCompatUtils { - private static final String TAG = ArraysCompatUtils.class.getSimpleName(); - - private static final Method METHOD_Arrays_binarySearch = CompatUtils - .getMethod(Arrays.class, "binarySearch", int[].class, int.class, int.class, int.class); - - public static int binarySearch(int[] array, int startIndex, int endIndex, int value) { - if (METHOD_Arrays_binarySearch != null) { - final Object index = CompatUtils.invoke(null, 0, METHOD_Arrays_binarySearch, - array, startIndex, endIndex, value); - return (Integer)index; - } else { - return compatBinarySearch(array, startIndex, endIndex, value); - } - } - - // TODO: Implement fast binary search - /* package for testing */ - static int compatBinarySearch(int[] array, int startIndex, int endIndex, int value) { - // Output error log because this method has strict performance penalty. - // Note that this method has been called only from spell checker and spell checker exists - // only from IceCreamSandwich and after, so that there is no chance on pre-ICS device to - // invoke this method. - Log.e(TAG, "Invoked expensive binarySearch"); - - if (startIndex > endIndex) throw new IllegalArgumentException(); - if (startIndex < 0 || endIndex > array.length) throw new ArrayIndexOutOfBoundsException(); - - final int work[] = new int[endIndex - startIndex]; - System.arraycopy(array, startIndex, work, 0, work.length); - final int index = Arrays.binarySearch(work, value); - if (index >= 0) { - return index + startIndex; - } else { - return ~(~index + startIndex); - } - } -} diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java index b42633cd9..ba82a06ac 100644 --- a/java/src/com/android/inputmethod/compat/CompatUtils.java +++ b/java/src/com/android/inputmethod/compat/CompatUtils.java @@ -32,8 +32,6 @@ public class CompatUtils { // TODO: Can these be constants instead of literal String constants? private static final String INPUT_METHOD_SUBTYPE_SETTINGS = "android.settings.INPUT_METHOD_SUBTYPE_SETTINGS"; - private static final String INPUT_LANGUAGE_SELECTION = - "com.android.inputmethod.latin.INPUT_LANGUAGE_SELECTION"; public static Intent getInputLanguageSelectionIntent(String inputMethodId, int flagsForSubtypeSettings) { @@ -51,11 +49,9 @@ public class CompatUtils { if (flagsForSubtypeSettings > 0) { intent.setFlags(flagsForSubtypeSettings); } - } else { - action = INPUT_LANGUAGE_SELECTION; - intent = new Intent(action); + return intent; } - return intent; + throw new RuntimeException("Language selection doesn't supported on this platform"); } public static Class<?> getClass(String className) { diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index a4ff8238c..3df6bea4b 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -29,7 +29,6 @@ import android.util.Log; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeUtils; @@ -68,14 +67,6 @@ public class InputMethodManagerCompatWrapper { private static final InputMethodManagerCompatWrapper sInstance = new InputMethodManagerCompatWrapper(); - public static final boolean SUBTYPE_SUPPORTED; - - static { - // This static initializer guarantees that METHOD_getShortcutInputMethodsAndSubtypes is - // already instantiated. - SUBTYPE_SUPPORTED = METHOD_getShortcutInputMethodsAndSubtypes != null; - } - // For the compatibility, IMM will create dummy subtypes if subtypes are not found. // This is required to be false if the current behavior is broken. For now, it's ok to be true. public static final boolean FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES = @@ -87,7 +78,6 @@ public class InputMethodManagerCompatWrapper { private InputMethodManager mImm; private PackageManager mPackageManager; private ApplicationInfo mApplicationInfo; - private LanguageSwitcherProxy mLanguageSwitcherProxy; private String mLatinImePackageName; public static InputMethodManagerCompatWrapper getInstance() { @@ -103,39 +93,20 @@ public class InputMethodManagerCompatWrapper { sInstance.mLatinImePackageName = service.getPackageName(); sInstance.mPackageManager = service.getPackageManager(); sInstance.mApplicationInfo = service.getApplicationInfo(); - sInstance.mLanguageSwitcherProxy = LanguageSwitcherProxy.getInstance(); } public InputMethodSubtypeCompatWrapper getCurrentInputMethodSubtype() { - if (!SUBTYPE_SUPPORTED) { - return new InputMethodSubtypeCompatWrapper( - 0, 0, mLanguageSwitcherProxy.getInputLocale().toString(), KEYBOARD_MODE, ""); - } Object o = CompatUtils.invoke(mImm, null, METHOD_getCurrentInputMethodSubtype); return new InputMethodSubtypeCompatWrapper(o); } public InputMethodSubtypeCompatWrapper getLastInputMethodSubtype() { - if (!SUBTYPE_SUPPORTED) { - return new InputMethodSubtypeCompatWrapper( - 0, 0, mLanguageSwitcherProxy.getInputLocale().toString(), KEYBOARD_MODE, ""); - } Object o = CompatUtils.invoke(mImm, null, METHOD_getLastInputMethodSubtype); return new InputMethodSubtypeCompatWrapper(o); } public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList( InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { - if (!SUBTYPE_SUPPORTED) { - String[] languages = mLanguageSwitcherProxy.getEnabledLanguages( - allowsImplicitlySelectedSubtypes); - List<InputMethodSubtypeCompatWrapper> subtypeList = - new ArrayList<InputMethodSubtypeCompatWrapper>(); - for (String lang: languages) { - subtypeList.add(new InputMethodSubtypeCompatWrapper(0, 0, lang, KEYBOARD_MODE, "")); - } - return subtypeList; - } Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList, (imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes); if (retval == null || !(retval instanceof List<?>) || ((List<?>)retval).isEmpty()) { @@ -228,16 +199,10 @@ public class InputMethodManagerCompatWrapper { } public boolean switchToLastInputMethod(IBinder token) { - if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) { - return true; - } return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToLastInputMethod, token); } public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { - if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) { - return true; - } return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token, onlyCurrentIme); } @@ -253,88 +218,6 @@ public class InputMethodManagerCompatWrapper { public void showInputMethodPicker() { if (mImm == null) return; - if (SUBTYPE_SUPPORTED) { - mImm.showInputMethodPicker(); - return; - } - - // The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}. - - final InputMethodInfoCompatWrapper myImi = SubtypeUtils.getInputMethodInfo( - mLatinImePackageName); - final List<InputMethodSubtypeCompatWrapper> myImsList = getEnabledInputMethodSubtypeList( - myImi, true); - final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype(); - final List<InputMethodInfoCompatWrapper> imiList = getEnabledInputMethodList(); - imiList.remove(myImi); - final PackageManager pm = mPackageManager; - Collections.sort(imiList, new Comparator<InputMethodInfoCompatWrapper>() { - @Override - public int compare(InputMethodInfoCompatWrapper imi1, - InputMethodInfoCompatWrapper imi2) { - final CharSequence imiId1 = imi1.loadLabel(pm) + "/" + imi1.getId(); - final CharSequence imiId2 = imi2.loadLabel(pm) + "/" + imi2.getId(); - return imiId1.toString().compareTo(imiId2.toString()); - } - }); - - final int myImsCount = myImsList.size(); - final int imiCount = imiList.size(); - final CharSequence[] items = new CharSequence[myImsCount + imiCount]; - - int checkedItem = 0; - int index = 0; - final CharSequence myImiLabel = myImi.loadLabel(mPackageManager); - for (int i = 0; i < myImsCount; i++) { - InputMethodSubtypeCompatWrapper ims = myImsList.get(i); - if (currentIms.equals(ims)) - checkedItem = index; - final CharSequence title = TextUtils.concat( - ims.getDisplayName(mService, mLatinImePackageName, mApplicationInfo), - " (" + myImiLabel, ")"); - items[index] = title; - index++; - } - - for (int i = 0; i < imiCount; i++) { - final InputMethodInfoCompatWrapper imi = imiList.get(i); - final CharSequence title = imi.loadLabel(mPackageManager); - items[index] = title; - index++; - } - - final InputMethodServiceCompatWrapper service = mService; - final OnClickListener buttonListener = new OnClickListener() { - @Override - public void onClick(DialogInterface di, int whichButton) { - final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS"); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - service.startActivity(intent); - } - }; - final IBinder token = service.getWindow().getWindow().getAttributes().token; - final OnClickListener selectionListener = new OnClickListener() { - @Override - public void onClick(DialogInterface di, int which) { - di.dismiss(); - if (which < myImsCount) { - final int imsIndex = which; - final InputMethodSubtypeCompatWrapper ims = myImsList.get(imsIndex); - service.notifyOnCurrentInputMethodSubtypeChanged(ims); - } else { - final int imiIndex = which - myImsCount; - final InputMethodInfoCompatWrapper imi = imiList.get(imiIndex); - setInputMethodAndSubtype(token, imi.getId(), null); - } - } - }; - - final AlertDialog.Builder builder = new AlertDialog.Builder(mService) - .setTitle(mService.getString(R.string.selectInputMethod)) - .setNeutralButton(R.string.configure_input_method, buttonListener) - .setSingleChoiceItems(items, checkedItem, selectionListener); - mService.showOptionDialogInternal(builder.create()); + mImm.showInputMethodPicker(); } } diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index 8e2ee0f7a..7c15be300 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -23,7 +23,6 @@ import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodSubtype; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher; @@ -87,9 +86,6 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { if (subtype != null) { if (!InputMethodManagerCompatWrapper.FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES && !subtype.isDummy()) return; - if (!InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) { - LanguageSwitcherProxy.getInstance().setLocale(subtype.getLocale()); - } SubtypeSwitcher.getInstance().updateSubtype(subtype); } } diff --git a/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java b/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java deleted file mode 100644 index 38736f3a1..000000000 --- a/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 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.content.SharedPreferences; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Reflection utils to call SharedPreferences$Editor.apply when possible, - * falling back to commit when apply isn't available. - */ -public class SharedPreferencesCompat { - private static final Method sApplyMethod = findApplyMethod(); - - private static Method findApplyMethod() { - try { - return SharedPreferences.Editor.class.getMethod("apply"); - } catch (NoSuchMethodException unused) { - // fall through - } - return null; - } - - public static void apply(SharedPreferences.Editor editor) { - if (sApplyMethod != null) { - try { - sApplyMethod.invoke(editor); - return; - } catch (InvocationTargetException unused) { - // fall through - } catch (IllegalAccessException unused) { - // fall through - } - } - editor.commit(); - } -} diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java deleted file mode 100644 index 2fb8b8710..000000000 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 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.content.Context; -import android.os.Vibrator; - -import java.lang.reflect.Method; - -public class VibratorCompatWrapper { - private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class, - "hasVibrator"); - - private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper(); - private Vibrator mVibrator; - - private VibratorCompatWrapper() { - } - - public static VibratorCompatWrapper getInstance(Context context) { - if (sInstance.mVibrator == null) { - sInstance.mVibrator = - (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - } - return sInstance; - } - - public boolean hasVibrator() { - if (mVibrator == null) - return false; - return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator); - } - - public void vibrate(long milliseconds) { - mVibrator.vibrate(milliseconds); - } -} |