From 07bd732034fbf4ce0e51b99c7199edf20dff1565 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 2 Jun 2014 15:32:59 +0900 Subject: Reenable DynamicRotationList for language-switching-aware IMEs In order to reenable DynamicRotationList for language-switching-aware IMEs, this CL reverts I84291fd4a7d6192b3bd0c366c49 with fixing a bug that the dynamic rotation state is reset even when the list of input methods is not changed. With this CL, the dynamic rotation state is preserved when the enabled input methods is not changed actually. BUG: 7043015 Change-Id: I506828c7a363e79f1c767eeb28f0d3746ff1cb0d --- .../InputMethodSubtypeSwitchingController.java | 91 ++++++++++++++++++---- 1 file changed, 74 insertions(+), 17 deletions(-) (limited to 'core/java/com') diff --git a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java index df96488..7dbde69 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java +++ b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.TreeMap; /** @@ -117,6 +118,24 @@ public class InputMethodSubtypeSwitchingController { + " mIsSystemLanguage=" + mIsSystemLanguage + "}"; } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ImeSubtypeListItem) { + final ImeSubtypeListItem that = (ImeSubtypeListItem)o; + if (!Objects.equals(this.mImi, that.mImi)) { + return false; + } + if (this.mSubtypeId != that.mSubtypeId) { + return false; + } + return true; + } + return false; + } } private static class InputMethodAndSubtypeList { @@ -276,7 +295,7 @@ public class InputMethodSubtypeSwitchingController { private final List mImeSubtypeList; private final int[] mUsageHistoryOfSubtypeListItemIndex; - public DynamicRotationList(final List imeSubtypeListItems) { + private DynamicRotationList(final List imeSubtypeListItems) { mImeSubtypeList = imeSubtypeListItems; mUsageHistoryOfSubtypeListItemIndex = new int[mImeSubtypeList.size()]; final int N = mImeSubtypeList.size(); @@ -347,15 +366,53 @@ public class InputMethodSubtypeSwitchingController { @VisibleForTesting public static class ControllerImpl { - // TODO: Switch to DynamicRotationList for smarter rotation. - private final StaticRotationList mSwitchingAwareSubtypeList; - private final StaticRotationList mSwitchingUnawareSubtypeList; - - public ControllerImpl(final List sortedItems) { - mSwitchingAwareSubtypeList = new StaticRotationList(filterImeSubtypeList(sortedItems, - true /* supportsSwitchingToNextInputMethod */)); - mSwitchingUnawareSubtypeList = new StaticRotationList(filterImeSubtypeList(sortedItems, - false /* supportsSwitchingToNextInputMethod */)); + private final DynamicRotationList mSwitchingAwareRotationList; + private final StaticRotationList mSwitchingUnawareRotationList; + + public static ControllerImpl createFrom(final ControllerImpl currentInstance, + final List sortedEnabledItems) { + DynamicRotationList switchingAwareRotationList = null; + { + final List switchingAwareImeSubtypes = + filterImeSubtypeList(sortedEnabledItems, + true /* supportsSwitchingToNextInputMethod */); + if (currentInstance != null && + currentInstance.mSwitchingAwareRotationList != null && + Objects.equals(currentInstance.mSwitchingAwareRotationList.mImeSubtypeList, + switchingAwareImeSubtypes)) { + // Can reuse the current instance. + switchingAwareRotationList = currentInstance.mSwitchingAwareRotationList; + } + if (switchingAwareRotationList == null) { + switchingAwareRotationList = new DynamicRotationList(switchingAwareImeSubtypes); + } + } + + StaticRotationList switchingUnawareRotationList = null; + { + final List switchingUnawareImeSubtypes = filterImeSubtypeList( + sortedEnabledItems, false /* supportsSwitchingToNextInputMethod */); + if (currentInstance != null && + currentInstance.mSwitchingUnawareRotationList != null && + Objects.equals( + currentInstance.mSwitchingUnawareRotationList.mImeSubtypeList, + switchingUnawareImeSubtypes)) { + // Can reuse the current instance. + switchingUnawareRotationList = currentInstance.mSwitchingUnawareRotationList; + } + if (switchingUnawareRotationList == null) { + switchingUnawareRotationList = + new StaticRotationList(switchingUnawareImeSubtypes); + } + } + + return new ControllerImpl(switchingAwareRotationList, switchingUnawareRotationList); + } + + private ControllerImpl(final DynamicRotationList switchingAwareRotationList, + final StaticRotationList switchingUnawareRotationList) { + mSwitchingAwareRotationList = switchingAwareRotationList; + mSwitchingUnawareRotationList = switchingUnawareRotationList; } public ImeSubtypeListItem getNextInputMethod(boolean onlyCurrentIme, InputMethodInfo imi, @@ -364,10 +421,10 @@ public class InputMethodSubtypeSwitchingController { return null; } if (imi.supportsSwitchingToNextInputMethod()) { - return mSwitchingAwareSubtypeList.getNextInputMethodLocked(onlyCurrentIme, imi, + return mSwitchingAwareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi, subtype); } else { - return mSwitchingUnawareSubtypeList.getNextInputMethodLocked(onlyCurrentIme, imi, + return mSwitchingUnawareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi, subtype); } } @@ -376,10 +433,9 @@ public class InputMethodSubtypeSwitchingController { if (imi == null) { return; } - // TODO: Enable the following code when DynamicRotationList is enabled. - // if (imi.supportsSwitchingToNextInputMethod()) { - // mSwitchingAwareSubtypeList.onUserAction(imi, subtype); - // } + if (imi.supportsSwitchingToNextInputMethod()) { + mSwitchingAwareRotationList.onUserAction(imi, subtype); + } } private static List filterImeSubtypeList( @@ -424,7 +480,8 @@ public class InputMethodSubtypeSwitchingController { public void resetCircularListLocked(Context context) { mSubtypeList = new InputMethodAndSubtypeList(context, mSettings); - mController = new ControllerImpl(mSubtypeList.getSortedInputMethodAndSubtypeList()); + mController = ControllerImpl.createFrom(mController, + mSubtypeList.getSortedInputMethodAndSubtypeList()); } public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, InputMethodInfo imi, -- cgit v1.1