am 9395014e
: Don\'t resume suggestions with H/W keyboard
* commit '9395014e76877fc9ef060a3fe54a9e06f0036d6d': Don't resume suggestions with H/W keyboard
This commit is contained in:
commit
5e3b3ab809
1 changed files with 72 additions and 41 deletions
|
@ -713,11 +713,27 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(final Configuration conf) {
|
public void onConfigurationChanged(final Configuration conf) {
|
||||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
SettingsValues settingsValues = mSettings.getCurrent();
|
||||||
if (settingsValues.mDisplayOrientation != conf.orientation) {
|
if (settingsValues.mDisplayOrientation != conf.orientation) {
|
||||||
mHandler.startOrientationChanging();
|
mHandler.startOrientationChanging();
|
||||||
mInputLogic.onOrientationChange(mSettings.getCurrent());
|
mInputLogic.onOrientationChange(mSettings.getCurrent());
|
||||||
}
|
}
|
||||||
|
if (settingsValues.mHasHardwareKeyboard != Settings.readHasHardwareKeyboard(conf)) {
|
||||||
|
// If the state of having a hardware keyboard changed, then we want to reload the
|
||||||
|
// settings to adjust for that.
|
||||||
|
// TODO: we should probably do this unconditionally here, rather than only when we
|
||||||
|
// have a change in hardware keyboard configuration.
|
||||||
|
loadSettings();
|
||||||
|
settingsValues = mSettings.getCurrent();
|
||||||
|
if (settingsValues.mHasHardwareKeyboard) {
|
||||||
|
// We call cleanupInternalStateForFinishInput() because it's the right thing to do;
|
||||||
|
// however, it seems at the moment the framework is passing us a seemingly valid
|
||||||
|
// but actually non-functional InputConnection object. So if this bug ever gets
|
||||||
|
// fixed we'll be able to remove the composition, but until it is this code is
|
||||||
|
// actually not doing much.
|
||||||
|
cleanupInternalStateForFinishInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: Remove this test.
|
// TODO: Remove this test.
|
||||||
if (!conf.locale.equals(mPersonalizationDictionaryUpdater.getLocale())) {
|
if (!conf.locale.equals(mPersonalizationDictionaryUpdater.getLocale())) {
|
||||||
refreshPersonalizationDictionarySession(settingsValues);
|
refreshPersonalizationDictionarySession(settingsValues);
|
||||||
|
@ -843,40 +859,52 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// Note: This call should be done by InputMethodService?
|
// Note: This call should be done by InputMethodService?
|
||||||
updateFullscreenMode();
|
updateFullscreenMode();
|
||||||
|
|
||||||
// The app calling setText() has the effect of clearing the composing
|
// ALERT: settings have not been reloaded and there is a chance they may be stale.
|
||||||
// span, so we should reset our state unconditionally, even if restarting is true.
|
// In the practice, if it is, we should have gotten onConfigurationChanged so it should
|
||||||
// We also tell the input logic about the combining rules for the current subtype, so
|
// be fine, but this is horribly confusing and must be fixed AS SOON AS POSSIBLE.
|
||||||
// it can adjust its combiners if needed.
|
|
||||||
mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(),
|
|
||||||
currentSettingsValues);
|
|
||||||
|
|
||||||
// Note: the following does a round-trip IPC on the main thread: be careful
|
// In some cases the input connection has not been reset yet and we can't access it. In
|
||||||
final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
// this case we will need to call loadKeyboard() later, when it's accessible, so that we
|
||||||
|
// can go into the correct mode, so we need to do some housekeeping here.
|
||||||
|
final boolean needToCallLoadKeyboardLater;
|
||||||
final Suggest suggest = mInputLogic.mSuggest;
|
final Suggest suggest = mInputLogic.mSuggest;
|
||||||
if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) {
|
if (!currentSettingsValues.mHasHardwareKeyboard) {
|
||||||
// TODO: Do this automatically.
|
// The app calling setText() has the effect of clearing the composing
|
||||||
resetSuggest();
|
// span, so we should reset our state unconditionally, even if restarting is true.
|
||||||
}
|
// We also tell the input logic about the combining rules for the current subtype, so
|
||||||
|
// it can adjust its combiners if needed.
|
||||||
|
mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(),
|
||||||
|
currentSettingsValues);
|
||||||
|
|
||||||
// TODO[IL]: Can the following be moved to InputLogic#startInput?
|
// Note: the following does a round-trip IPC on the main thread: be careful
|
||||||
final boolean canReachInputConnection;
|
final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
||||||
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) {
|
||||||
editorInfo.initialSelStart, editorInfo.initialSelEnd,
|
// TODO: Do this automatically.
|
||||||
false /* shouldFinishComposition */)) {
|
resetSuggest();
|
||||||
// Sometimes, while rotating, for some reason the framework tells the app we are not
|
}
|
||||||
// connected to it and that means we can't refresh the cache. In this case, schedule a
|
|
||||||
// refresh later.
|
// TODO[IL]: Can the following be moved to InputLogic#startInput?
|
||||||
// We try resetting the caches up to 5 times before giving up.
|
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
||||||
mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
|
editorInfo.initialSelStart, editorInfo.initialSelEnd,
|
||||||
// mLastSelection{Start,End} are reset later in this method, don't need to do it here
|
false /* shouldFinishComposition */)) {
|
||||||
canReachInputConnection = false;
|
// Sometimes, while rotating, for some reason the framework tells the app we are not
|
||||||
|
// connected to it and that means we can't refresh the cache. In this case, schedule
|
||||||
|
// a refresh later.
|
||||||
|
// We try resetting the caches up to 5 times before giving up.
|
||||||
|
mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
|
||||||
|
// mLastSelection{Start,End} are reset later in this method, no need to do it here
|
||||||
|
needToCallLoadKeyboardLater = true;
|
||||||
|
} else {
|
||||||
|
// When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
|
||||||
|
// effort to work around this bug.
|
||||||
|
mInputLogic.mConnection.tryFixLyingCursorPosition();
|
||||||
|
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
|
||||||
|
true /* shouldDelay */);
|
||||||
|
needToCallLoadKeyboardLater = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
|
// If we have a hardware keyboard we don't need to call loadKeyboard later anyway.
|
||||||
// effort to work around this bug.
|
needToCallLoadKeyboardLater = false;
|
||||||
mInputLogic.mConnection.tryFixLyingCursorPosition();
|
|
||||||
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
|
|
||||||
true /* shouldDelay */);
|
|
||||||
canReachInputConnection = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDifferentTextField ||
|
if (isDifferentTextField ||
|
||||||
|
@ -894,9 +922,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
|
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
|
||||||
getCurrentRecapitalizeState());
|
getCurrentRecapitalizeState());
|
||||||
if (!canReachInputConnection) {
|
if (needToCallLoadKeyboardLater) {
|
||||||
// If we can't reach the input connection, we will call loadKeyboard again later,
|
// If we need to call loadKeyboard again later, we need to save its state now. The
|
||||||
// so we need to save its state now. The call will be done in #retryResetCaches.
|
// later call will be done in #retryResetCaches.
|
||||||
switcher.saveKeyboardState();
|
switcher.saveKeyboardState();
|
||||||
}
|
}
|
||||||
} else if (restarting) {
|
} else if (restarting) {
|
||||||
|
@ -953,6 +981,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private void onFinishInputViewInternal(final boolean finishingInput) {
|
private void onFinishInputViewInternal(final boolean finishingInput) {
|
||||||
super.onFinishInputView(finishingInput);
|
super.onFinishInputView(finishingInput);
|
||||||
|
cleanupInternalStateForFinishInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupInternalStateForFinishInput() {
|
||||||
mKeyboardSwitcher.deallocateMemory();
|
mKeyboardSwitcher.deallocateMemory();
|
||||||
// Remove pending messages related to update suggestions
|
// Remove pending messages related to update suggestions
|
||||||
mHandler.cancelUpdateSuggestionStrip();
|
mHandler.cancelUpdateSuggestionStrip();
|
||||||
|
@ -972,13 +1004,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
+ ", cs=" + composingSpanStart + ", ce=" + composingSpanEnd);
|
+ ", cs=" + composingSpanStart + ", ce=" + composingSpanEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the keyboard is not visible, we don't need to do all the housekeeping work, as it
|
// This call happens when we have a hardware keyboard as well as when we don't. While we
|
||||||
// will be reset when the keyboard shows up anyway.
|
// don't support hardware keyboards yet we should avoid doing the processing associated
|
||||||
// TODO: revisit this when LatinIME supports hardware keyboards.
|
// with cursor movement when we have a hardware keyboard since we are not in charge.
|
||||||
// NOTE: the test harness subclasses LatinIME and overrides isInputViewShown().
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||||
// TODO: find a better way to simulate actual execution.
|
if ((!settingsValues.mHasHardwareKeyboard || ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED)
|
||||||
if (isInputViewShown() &&
|
&& mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd)) {
|
||||||
mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd)) {
|
|
||||||
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
||||||
getCurrentRecapitalizeState());
|
getCurrentRecapitalizeState());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue