Skip to content
Snippets Groups Projects
Commit 91db602b authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Use shouldOfferSwitchingToNextInputMethod when available"

parents 0b42851e 8ba4f337
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,12 @@ public final class InputMethodManagerCompatWrapper { ...@@ -28,6 +28,12 @@ public final class InputMethodManagerCompatWrapper {
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod( private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE); InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
// Note that InputMethodManager.shouldOfferSwitchingToNextInputMethod() has been introduced
// in API level 19 (Build.VERSION_CODES.KITKAT).
private static final Method METHOD_shouldOfferSwitchingToNextInputMethod =
CompatUtils.getMethod(InputMethodManager.class,
"shouldOfferSwitchingToNextInputMethod", IBinder.class);
public final InputMethodManager mImm; public final InputMethodManager mImm;
public InputMethodManagerCompatWrapper(final Context context) { public InputMethodManagerCompatWrapper(final Context context) {
...@@ -38,4 +44,9 @@ public final class InputMethodManagerCompatWrapper { ...@@ -38,4 +44,9 @@ public final class InputMethodManagerCompatWrapper {
return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */, return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */,
METHOD_switchToNextInputMethod, token, onlyCurrentIme); METHOD_switchToNextInputMethod, token, onlyCurrentIme);
} }
public boolean shouldOfferSwitchingToNextInputMethod(final IBinder token) {
return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */,
METHOD_shouldOfferSwitchingToNextInputMethod, token);
}
} }
...@@ -123,7 +123,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { ...@@ -123,7 +123,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setOptions( builder.setOptions(
mSubtypeSwitcher.isShortcutImeEnabled(), mSubtypeSwitcher.isShortcutImeEnabled(),
settingsValues.mShowsVoiceInputKey, settingsValues.mShowsVoiceInputKey,
settingsValues.isLanguageSwitchKeyEnabled()); mLatinIME.shouldSwitchToOtherInputMethods());
mKeyboardLayoutSet = builder.build(); mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues; mCurrentSettingsValues = settingsValues;
try { try {
......
...@@ -1229,7 +1229,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen ...@@ -1229,7 +1229,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable. // TODO: Revise the language switch key behavior to make it much smarter and more reasonable.
public void switchToNextSubtype() { public void switchToNextSubtype() {
final IBinder token = getWindow().getWindow().getAttributes().token; final IBinder token = getWindow().getWindow().getAttributes().token;
if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) { if (shouldSwitchToOtherInputMethods()) {
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return; return;
} }
...@@ -1799,4 +1799,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen ...@@ -1799,4 +1799,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
p.println(settingsValues.dump()); p.println(settingsValues.dump());
// TODO: Dump all settings values // TODO: Dump all settings values
} }
public boolean shouldSwitchToOtherInputMethods() {
// TODO: Revisit here to reorganize the settings. Probably we can/should use different
// strategy once the implementation of
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
final boolean fallbackValue = mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList;
final IBinder token = getWindow().getWindow().getAttributes().token;
if (token == null) {
return fallbackValue;
}
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
}
public boolean shouldShowLanguageSwitchKey() {
// TODO: Revisit here to reorganize the settings. Probably we can/should use different
// strategy once the implementation of
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
final boolean fallbackValue = mSettings.getCurrent().isLanguageSwitchKeyEnabled();
final IBinder token = getWindow().getWindow().getAttributes().token;
if (token == null) {
return fallbackValue;
}
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
}
} }
...@@ -20,6 +20,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; ...@@ -20,6 +20,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
...@@ -406,4 +407,15 @@ public final class RichInputMethodManager { ...@@ -406,4 +407,15 @@ public final class RichInputMethodManager {
mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear(); mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
mInputMethodInfoCache.clear(); mInputMethodInfoCache.clear();
} }
public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder,
boolean defaultValue) {
// Use the default value instead on Jelly Bean MR2 and previous where
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available
// and on KitKat where the API is still just a stub to return true always.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
return defaultValue;
}
return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment