Track overridden subtypes when auto-switching due to HintLocales

This commit is contained in:
unlair 2025-03-07 17:48:01 -05:00
parent 631ab60eb9
commit 5868063316
No known key found for this signature in database
GPG key ID: 221ADE60BA750A31

View file

@ -153,6 +153,12 @@ public class LatinIME extends InputMethodService implements
@Nullable @Nullable
private Context mDisplayContext; private Context mDisplayContext;
// When HintLocales causes a subtype override, we store
// the overridden subtype here in order to restore it when
// we switch to another input context that has no HintLocales.
@Nullable
private InputMethodSubtype mOverriddenByHintLocale;
// Object for reacting to adding/removing a dictionary pack. // Object for reacting to adding/removing a dictionary pack.
private final BroadcastReceiver mDictionaryPackInstallReceiver = private final BroadcastReceiver mDictionaryPackInstallReceiver =
new DictionaryPackInstallBroadcastReceiver(this); new DictionaryPackInstallBroadcastReceiver(this);
@ -858,6 +864,13 @@ public class LatinIME extends InputMethodService implements
return; return;
} }
InputMethodSubtype oldSubtype = mRichImm.getCurrentSubtype().getRawSubtype(); InputMethodSubtype oldSubtype = mRichImm.getCurrentSubtype().getRawSubtype();
if (mOverriddenByHintLocale != oldSubtype) {
// Clear tracking the subtype that is overridden by a HintLocale
// when subtypes are changed in any way other than the initial automatic change.
mOverriddenByHintLocale = null;
}
StatsUtils.onSubtypeChanged(oldSubtype, subtype); StatsUtils.onSubtypeChanged(oldSubtype, subtype);
mRichImm.onSubtypeChanged(subtype); mRichImm.onSubtypeChanged(subtype);
mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype), mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype),
@ -877,6 +890,10 @@ public class LatinIME extends InputMethodService implements
final List<Locale> hintLocales = EditorInfoCompatUtils.getHintLocales(editorInfo); final List<Locale> hintLocales = EditorInfoCompatUtils.getHintLocales(editorInfo);
if (hintLocales == null) { if (hintLocales == null) {
if (mOverriddenByHintLocale != null) {
mHandler.postSwitchLanguage(mOverriddenByHintLocale);
mOverriddenByHintLocale = null;
}
return; return;
} }
// Try switching to a subtype matching the hint language. // Try switching to a subtype matching the hint language.
@ -888,6 +905,10 @@ public class LatinIME extends InputMethodService implements
if (newSubtype == null) continue; if (newSubtype == null) continue;
if (newSubtype.equals(mRichImm.getCurrentSubtype().getRawSubtype())) if (newSubtype.equals(mRichImm.getCurrentSubtype().getRawSubtype()))
return; // no need to switch, we already use the correct locale return; // no need to switch, we already use the correct locale
if (mOverriddenByHintLocale == null) {
mOverriddenByHintLocale = mRichImm.getCurrentSubtype().getRawSubtype();
}
mHandler.postSwitchLanguage(newSubtype); mHandler.postSwitchLanguage(newSubtype);
break; break;
} }