mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Cache subtype lists reasonably."
This commit is contained in:
commit
27d9c6f795
@ -844,8 +844,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||||||
}
|
}
|
||||||
// Remove pending messages related to update suggestions
|
// Remove pending messages related to update suggestions
|
||||||
mHandler.cancelUpdateSuggestionStrip();
|
mHandler.cancelUpdateSuggestionStrip();
|
||||||
|
// Should do the following in onFinishInputInternal but until JB MR2 it's not called :(
|
||||||
if (mWordComposer.isComposingWord()) mConnection.finishComposingText();
|
if (mWordComposer.isComposingWord()) mConnection.finishComposingText();
|
||||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
|
mRichImm.clearSubtypeCaches();
|
||||||
// Notify ResearchLogger
|
// Notify ResearchLogger
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||||
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput, mLastSelectionStart,
|
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput, mLastSelectionStart,
|
||||||
|
@ -30,6 +30,7 @@ import android.view.inputmethod.InputMethodSubtype;
|
|||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +47,10 @@ public final class RichInputMethodManager {
|
|||||||
|
|
||||||
private InputMethodManagerCompatWrapper mImmWrapper;
|
private InputMethodManagerCompatWrapper mImmWrapper;
|
||||||
private InputMethodInfo mInputMethodInfoOfThisIme;
|
private InputMethodInfo mInputMethodInfoOfThisIme;
|
||||||
|
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
|
||||||
|
mSubtypeListCacheWithImplicitlySelectedSubtypes = CollectionUtils.newHashMap();
|
||||||
|
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
|
||||||
|
mSubtypeListCacheWithoutImplicitlySelectedSubtypes = CollectionUtils.newHashMap();
|
||||||
|
|
||||||
private static final int INDEX_NOT_FOUND = -1;
|
private static final int INDEX_NOT_FOUND = -1;
|
||||||
|
|
||||||
@ -102,8 +107,8 @@ public final class RichInputMethodManager {
|
|||||||
|
|
||||||
public List<InputMethodSubtype> getMyEnabledInputMethodSubtypeList(
|
public List<InputMethodSubtype> getMyEnabledInputMethodSubtypeList(
|
||||||
boolean allowsImplicitlySelectedSubtypes) {
|
boolean allowsImplicitlySelectedSubtypes) {
|
||||||
return mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
|
return getEnabledInputMethodSubtypeList(mInputMethodInfoOfThisIme,
|
||||||
mInputMethodInfoOfThisIme, allowsImplicitlySelectedSubtypes);
|
allowsImplicitlySelectedSubtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
|
public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
|
||||||
@ -151,8 +156,8 @@ public final class RichInputMethodManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
|
final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
|
||||||
final List<InputMethodSubtype> enabledSubtypes = imm.getEnabledInputMethodSubtypeList(
|
final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi,
|
||||||
nextImi, true /* allowsImplicitlySelectedSubtypes */);
|
true /* allowsImplicitlySelectedSubtypes */);
|
||||||
if (enabledSubtypes.isEmpty()) {
|
if (enabledSubtypes.isEmpty()) {
|
||||||
// The next IME has no subtype.
|
// The next IME has no subtype.
|
||||||
imm.setInputMethod(token, nextImi.getId());
|
imm.setInputMethod(token, nextImi.getId());
|
||||||
@ -227,9 +232,8 @@ public final class RichInputMethodManager {
|
|||||||
|
|
||||||
public boolean checkIfSubtypeBelongsToImeAndEnabled(final InputMethodInfo imi,
|
public boolean checkIfSubtypeBelongsToImeAndEnabled(final InputMethodInfo imi,
|
||||||
final InputMethodSubtype subtype) {
|
final InputMethodSubtype subtype) {
|
||||||
return checkIfSubtypeBelongsToList(
|
return checkIfSubtypeBelongsToList(subtype, getEnabledInputMethodSubtypeList(imi,
|
||||||
subtype, mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
|
true /* allowsImplicitlySelectedSubtypes */));
|
||||||
imi, true /* allowsImplicitlySelectedSubtypes */));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkIfSubtypeBelongsToList(final InputMethodSubtype subtype,
|
private static boolean checkIfSubtypeBelongsToList(final InputMethodSubtype subtype,
|
||||||
@ -290,8 +294,7 @@ public final class RichInputMethodManager {
|
|||||||
for (InputMethodInfo imi : imiList) {
|
for (InputMethodInfo imi : imiList) {
|
||||||
// We can return true immediately after we find two or more filtered IMEs.
|
// We can return true immediately after we find two or more filtered IMEs.
|
||||||
if (filteredImisCount > 1) return true;
|
if (filteredImisCount > 1) return true;
|
||||||
final List<InputMethodSubtype> subtypes =
|
final List<InputMethodSubtype> subtypes = getEnabledInputMethodSubtypeList(imi, true);
|
||||||
mImmWrapper.mImm.getEnabledInputMethodSubtypeList(imi, true);
|
|
||||||
// IMEs that have no subtypes should be counted.
|
// IMEs that have no subtypes should be counted.
|
||||||
if (subtypes.isEmpty()) {
|
if (subtypes.isEmpty()) {
|
||||||
++filteredImisCount;
|
++filteredImisCount;
|
||||||
@ -354,5 +357,26 @@ public final class RichInputMethodManager {
|
|||||||
public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
|
public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
|
||||||
mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
|
mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
|
||||||
mInputMethodInfoOfThisIme.getId(), subtypes);
|
mInputMethodInfoOfThisIme.getId(), subtypes);
|
||||||
|
// Clear the cache so that we go read the subtypes again next time.
|
||||||
|
clearSubtypeCaches();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<InputMethodSubtype> getEnabledInputMethodSubtypeList(final InputMethodInfo imi,
|
||||||
|
final boolean allowsImplicitlySelectedSubtypes) {
|
||||||
|
final HashMap<InputMethodInfo, List<InputMethodSubtype>> cache =
|
||||||
|
allowsImplicitlySelectedSubtypes
|
||||||
|
? mSubtypeListCacheWithImplicitlySelectedSubtypes
|
||||||
|
: mSubtypeListCacheWithoutImplicitlySelectedSubtypes;
|
||||||
|
final List<InputMethodSubtype> cachedList = cache.get(imi);
|
||||||
|
if (null != cachedList) return cachedList;
|
||||||
|
final List<InputMethodSubtype> result = mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
|
||||||
|
imi, allowsImplicitlySelectedSubtypes);
|
||||||
|
cache.put(imi, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSubtypeCaches() {
|
||||||
|
mSubtypeListCacheWithImplicitlySelectedSubtypes.clear();
|
||||||
|
mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user