From d39ae854820edebe3f1cb8580117c451ffa5c4ec Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Sun, 10 Apr 2016 20:28:40 -0700 Subject: Shift+Meta+Space should reverse-rotate subtypes. This is a follow up CL to my previous CL [1], which added a new key binding Meta+Space to rotate enabled IME subtypes. With this CL, Shift+Meta+Space starts reverse-rotating enabled IME subtypes as originally planed. [1]: I4005692215edfcf8bed3e86b1e07000148f986f5 ae61f7118a92e097e854c840d5726c0920f5db0e Bug: 25753404 Bug: 28103839 Change-Id: I3694edd80be6dfe18b90360e24ae4d451b331928 --- .../InputMethodSubtypeSwitchingController.java | 20 +++++---- .../InputMethodSubtypeSwitchingControllerTest.java | 50 ++++++++++++---------- .../android/server/InputMethodManagerService.java | 9 ++-- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java index 85cc841379cf..46b49de7fc80 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java +++ b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java @@ -285,7 +285,7 @@ public class InputMethodSubtypeSwitchingController { } public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, - InputMethodInfo imi, InputMethodSubtype subtype) { + InputMethodInfo imi, InputMethodSubtype subtype, boolean forward) { if (imi == null) { return null; } @@ -297,8 +297,9 @@ public class InputMethodSubtypeSwitchingController { return null; } final int N = mImeSubtypeList.size(); - for (int offset = 1; offset < N; ++offset) { + for (int i = 1; i < N; ++i) { // Start searching the next IME/subtype from the next of the current index. + final int offset = forward ? i : N - i; final int candidateIndex = (currentIndex + offset) % N; final ImeSubtypeListItem candidate = mImeSubtypeList.get(candidateIndex); // Skip if searching inside the current IME only, but the candidate is not @@ -371,7 +372,7 @@ public class InputMethodSubtypeSwitchingController { } public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, - InputMethodInfo imi, InputMethodSubtype subtype) { + InputMethodInfo imi, InputMethodSubtype subtype, boolean forward) { int currentUsageRank = getUsageRank(imi, subtype); if (currentUsageRank < 0) { if (DEBUG) { @@ -381,7 +382,8 @@ public class InputMethodSubtypeSwitchingController { } final int N = mUsageHistoryOfSubtypeListItemIndex.length; for (int i = 1; i < N; i++) { - final int subtypeListItemRank = (currentUsageRank + i) % N; + final int offset = forward ? i : N - i; + final int subtypeListItemRank = (currentUsageRank + offset) % N; final int subtypeListItemIndex = mUsageHistoryOfSubtypeListItemIndex[subtypeListItemRank]; final ImeSubtypeListItem subtypeListItem = @@ -455,16 +457,16 @@ public class InputMethodSubtypeSwitchingController { } public ImeSubtypeListItem getNextInputMethod(boolean onlyCurrentIme, InputMethodInfo imi, - InputMethodSubtype subtype) { + InputMethodSubtype subtype, boolean forward) { if (imi == null) { return null; } if (imi.supportsSwitchingToNextInputMethod()) { return mSwitchingAwareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi, - subtype); + subtype, forward); } else { return mSwitchingUnawareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi, - subtype); + subtype, forward); } } @@ -532,14 +534,14 @@ public class InputMethodSubtypeSwitchingController { } public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, InputMethodInfo imi, - InputMethodSubtype subtype) { + InputMethodSubtype subtype, boolean forward) { if (mController == null) { if (DEBUG) { Log.e(TAG, "mController shouldn't be null."); } return null; } - return mController.getNextInputMethod(onlyCurrentIme, imi, subtype); + return mController.getNextInputMethod(onlyCurrentIme, imi, subtype, forward); } public List getSortedInputMethodAndSubtypeListLocked( diff --git a/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java index ec5220f243b1..ba5206adeb77 100644 --- a/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java @@ -27,7 +27,6 @@ import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder; import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl; import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; -import com.android.internal.inputmethod.InputMethodUtils; import java.util.ArrayList; import java.util.Arrays; @@ -68,7 +67,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe ri.serviceInfo = si; List subtypes = null; if (subtypeLocales != null) { - subtypes = new ArrayList(); + subtypes = new ArrayList<>(); for (String subtypeLocale : subtypeLocales) { subtypes.add(createDummySubtype(subtypeLocale)); } @@ -89,7 +88,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe } private static List createEnabledImeSubtypes() { - final List items = new ArrayList(); + final List items = new ArrayList<>(); addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme", Arrays.asList("en_US", "fr"), true /* supportsSwitchingToNextInputMethod*/); addDummyImeSubtypeListItems(items, "switchUnawareLatinIme", "switchUnawareLatinIme", @@ -105,7 +104,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe } private static List createDisabledImeSubtypes() { - final List items = new ArrayList(); + final List items = new ArrayList<>(); addDummyImeSubtypeListItems(items, "UnknownIme", "UnknownIme", Arrays.asList("en_US", "hi"), @@ -121,15 +120,18 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe } private void assertNextInputMethod(final ControllerImpl controller, - final boolean onlyCurrentIme, - final ImeSubtypeListItem currentItem, final ImeSubtypeListItem nextItem) { + final boolean onlyCurrentIme, final ImeSubtypeListItem currentItem, + final ImeSubtypeListItem nextItem, final ImeSubtypeListItem prevItem) { InputMethodSubtype subtype = null; if (currentItem.mSubtypeName != null) { subtype = createDummySubtype(currentItem.mSubtypeName.toString()); } final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme, - currentItem.mImi, subtype); + currentItem.mImi, subtype, true /* forward */); assertEquals(nextItem, nextIme); + final ImeSubtypeListItem prevIme = controller.getNextInputMethod(onlyCurrentIme, + currentItem.mImi, subtype, false /* forward */); + assertEquals(prevItem, prevIme); } private void assertRotationOrder(final ControllerImpl controller, @@ -138,11 +140,13 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe final int N = expectedRotationOrderOfImeSubtypeList.length; for (int i = 0; i < N; i++) { final int currentIndex = i; + final int prevIndex = (currentIndex + N - 1) % N; final int nextIndex = (currentIndex + 1) % N; final ImeSubtypeListItem currentItem = expectedRotationOrderOfImeSubtypeList[currentIndex]; final ImeSubtypeListItem nextItem = expectedRotationOrderOfImeSubtypeList[nextIndex]; - assertNextInputMethod(controller, onlyCurrentIme, currentItem, nextItem); + final ImeSubtypeListItem prevItem = expectedRotationOrderOfImeSubtypeList[prevIndex]; + assertNextInputMethod(controller, onlyCurrentIme, currentItem, nextItem, prevItem); } } @@ -190,29 +194,29 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe assertRotationOrder(controller, true /* onlyCurrentIme */, switchingUnawarelatinIme_en_UK, switchingUnawarelatinIme_hi); assertNextInputMethod(controller, true /* onlyCurrentIme */, - subtypeUnawareIme, null); + subtypeUnawareIme, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - japaneseIme_ja_JP, null); + japaneseIme_ja_JP, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - switchUnawareJapaneseIme_ja_JP, null); + switchUnawareJapaneseIme_ja_JP, null, null); // Make sure that disabled IMEs are not accepted. assertNextInputMethod(controller, false /* onlyCurrentIme */, - disabledIme_en_US, null); + disabledIme_en_US, null, null); assertNextInputMethod(controller, false /* onlyCurrentIme */, - disabledIme_hi, null); + disabledIme_hi, null, null); assertNextInputMethod(controller, false /* onlyCurrentIme */, - disabledSwitchingUnawareIme, null); + disabledSwitchingUnawareIme, null, null); assertNextInputMethod(controller, false /* onlyCurrentIme */, - disabledSubtypeUnawareIme, null); + disabledSubtypeUnawareIme, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - disabledIme_en_US, null); + disabledIme_en_US, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - disabledIme_hi, null); + disabledIme_hi, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - disabledSwitchingUnawareIme, null); + disabledSwitchingUnawareIme, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - disabledSubtypeUnawareIme, null); + disabledSubtypeUnawareIme, null, null); } @SmallTest @@ -246,7 +250,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe japaneseIme_ja_JP, latinIme_fr, latinIme_en_US); // Check onlyCurrentIme == true. assertNextInputMethod(controller, true /* onlyCurrentIme */, - japaneseIme_ja_JP, null); + japaneseIme_ja_JP, null, null); assertRotationOrder(controller, true /* onlyCurrentIme */, latinIme_fr, latinIme_en_US); assertRotationOrder(controller, true /* onlyCurrentIme */, @@ -270,9 +274,9 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe assertRotationOrder(controller, true /* onlyCurrentIme */, switchingUnawarelatinIme_en_UK, switchingUnawarelatinIme_hi); assertNextInputMethod(controller, true /* onlyCurrentIme */, - subtypeUnawareIme, null); + subtypeUnawareIme, null, null); assertNextInputMethod(controller, true /* onlyCurrentIme */, - switchUnawareJapaneseIme_ja_JP, null); + switchUnawareJapaneseIme_ja_JP, null, null); // Rotation order should be preserved when created with the same subtype list. final List sameEnabledItems = createEnabledImeSubtypes(); @@ -298,7 +302,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe @SmallTest public void testImeSubtypeListItem() throws Exception { - final List items = new ArrayList(); + final List items = new ArrayList<>(); addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme", Arrays.asList("en_US", "fr", "en", "en_uk", "enn", "e", "EN_US"), true /* supportsSwitchingToNextInputMethod*/); diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index ac7872a94bf8..58e3674c59f3 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -2546,7 +2546,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return false; } final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( - onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype); + onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype, + true /* forward */); if (nextSubtype == null) { return false; } @@ -2569,7 +2570,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return false; } final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( - false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype); + false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype, + true /* forward */); if (nextSubtype == null) { return false; } @@ -2963,9 +2965,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private void handleSwitchInputMethod(final boolean forwardDirection) { synchronized (mMethodMap) { - // TODO: Support forwardDirection. final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( - false, mMethodMap.get(mCurMethodId), mCurrentSubtype); + false, mMethodMap.get(mCurMethodId), mCurrentSubtype, forwardDirection); if (nextSubtype == null) { return; } -- cgit v1.2.3-59-g8ed1b