Skip to content

Commit

Permalink
Make handleLanguageSwitch() compatible with lower API levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansche committed Sep 6, 2016
1 parent 1eb2fe2 commit 74ea58a
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -630,7 +632,34 @@ private IBinder getToken() {
}

private void handleLanguageSwitch() {
mInputMethodManager.switchToNextInputMethod(getToken(), false /* onlyCurrentIme */);
try {
Method m =
InputMethodManager.class
.getMethod(
"switchToNextInputMethod",
new Class[] {android.os.IBinder.class, boolean.class});
m.invoke(mInputMethodManager, getToken(), false /* onlyCurrentIme */);
return;
} catch (NoSuchMethodException e) {
// Android API level < 14. Do nothing.
} catch (IllegalAccessException | InvocationTargetException e) {
// This cannot happen.
throw new AssertionError(e);
}
try {
Method m =
InputMethodManager.class
.getMethod(
"switchToLastInputMethod",
new Class[] {android.os.IBinder.class});
m.invoke(mInputMethodManager, getToken());
return;
} catch (NoSuchMethodException e) {
// Android API level < 11. Do nothing.
} catch (IllegalAccessException | InvocationTargetException e) {
// This cannot happen.
throw new AssertionError(e);
}
}

private void checkToggleCapsLock() {
Expand All @@ -644,7 +673,7 @@ private void checkToggleCapsLock() {
}

public boolean isSeparator(int code) {
return SEPARATORS.contains(String.valueOf((char)code));
return SEPARATORS.contains(String.valueOf((char) code));
}

public void pickDefaultCandidate() {
Expand Down

0 comments on commit 74ea58a

Please sign in to comment.