Update gesture mode state when dictionary gets available

Bug: 6860204
Change-Id: I840b7bf1983ab92fa4e0b180129176539e96409f
This commit is contained in:
Tadashi G. Takaoka 2012-07-23 14:59:19 +09:00
parent 42208100d8
commit 0657b9698a
5 changed files with 44 additions and 30 deletions

View file

@ -74,7 +74,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
private MainKeyboardView mKeyboardView; private MainKeyboardView mKeyboardView;
private LatinIME mLatinIME; private LatinIME mLatinIME;
private Resources mResources; private Resources mResources;
private SettingsValues mCurrentSettingsValues;
private KeyboardState mState; private KeyboardState mState;
@ -136,7 +135,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
} }
public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) { public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) {
mCurrentSettingsValues = settingsValues;
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mThemeContext, editorInfo); mThemeContext, editorInfo);
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation, builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
@ -171,20 +169,20 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
} }
private void setKeyboard(final Keyboard keyboard) { private void setKeyboard(final Keyboard keyboard) {
final Keyboard oldKeyboard = mKeyboardView.getKeyboard(); final MainKeyboardView keyboardView = mKeyboardView;
mKeyboardView.setGestureInputEnabled(mCurrentSettingsValues.mGestureInputEnabled); final Keyboard oldKeyboard = keyboardView.getKeyboard();
mKeyboardView.setKeyboard(keyboard); keyboardView.setKeyboard(keyboard);
mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding); mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding);
mKeyboardView.setKeyPreviewPopupEnabled( keyboardView.setKeyPreviewPopupEnabled(
SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources), SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources),
SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources)); SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources));
mKeyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive); keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
final boolean subtypeChanged = (oldKeyboard == null) final boolean subtypeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale); || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage( final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage(
keyboard.mId.mLocale); keyboard.mId.mLocale);
mKeyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage, keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage,
ImfUtils.hasMultipleEnabledIMEsOrSubtypes(mLatinIME, true)); ImfUtils.hasMultipleEnabledIMEsOrSubtypes(mLatinIME, true));
} }

View file

@ -111,8 +111,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private int mDelayAfterPreview; private int mDelayAfterPreview;
private ViewGroup mPreviewPlacer; private ViewGroup mPreviewPlacer;
/** True if the gesture input is enabled. */ /** True if {@link KeyboardView} should handle gesture events. */
protected boolean mGestureInputEnabled; protected boolean mShouldHandleGesture;
// Drawing // Drawing
/** True if the entire keyboard needs to be dimmed. */ /** True if the entire keyboard needs to be dimmed. */
@ -443,8 +443,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return mShowKeyPreviewPopup; return mShowKeyPreviewPopup;
} }
public void setGestureInputEnabled(boolean gestureInputEnabled) { public void setGestureHandlingMode(boolean shouldHandleGesture) {
mGestureInputEnabled = gestureInputEnabled; mShouldHandleGesture = shouldHandleGesture;
} }
@Override @Override

View file

@ -461,7 +461,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mKeyDetector.setKeyboard( mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection);
PointerTracker.setKeyDetector(mKeyDetector, mGestureInputEnabled); PointerTracker.setKeyDetector(mKeyDetector, mShouldHandleGesture);
mTouchScreenRegulator.setKeyboard(keyboard); mTouchScreenRegulator.setKeyboard(keyboard);
mMoreKeysPanelCache.clear(); mMoreKeysPanelCache.clear();
@ -479,6 +479,12 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard); AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard);
} }
@Override
public void setGestureHandlingMode(final boolean shouldHandleGesture) {
super.setGestureHandlingMode(shouldHandleGesture);
PointerTracker.setKeyDetector(mKeyDetector, shouldHandleGesture);
}
/** /**
* Returns whether the device has distinct multi-touch panel. * Returns whether the device has distinct multi-touch panel.
* @return true if the device has distinct multi-touch panel. * @return true if the device has distinct multi-touch panel.

View file

@ -42,8 +42,8 @@ public class PointerTracker {
private static final boolean DEBUG_LISTENER = false; private static final boolean DEBUG_LISTENER = false;
private static boolean DEBUG_MODE = LatinImeLogger.sDBG; private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
// TODO: There should be an option to turn on/off the gesture input. /** True if {@link PointerTracker}s should handle gesture events. */
private static boolean sIsGestureEnabled = true; private static boolean sShouldHandleGesture = false;
private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
@ -199,7 +199,7 @@ public class PointerTracker {
sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack;
setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT); setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT);
updateGestureInputEnabledState(null, false /* gestureInputEnabled */); updateGestureHandlingMode(null, false /* shouldHandleGesture */);
} }
public static void setParameters(MainKeyboardView.PointerTrackerParams params) { public static void setParameters(MainKeyboardView.PointerTrackerParams params) {
@ -208,14 +208,13 @@ public class PointerTracker {
params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance);
} }
private static void updateGestureInputEnabledState(Keyboard keyboard, private static void updateGestureHandlingMode(Keyboard keyboard, boolean shouldHandleGesture) {
boolean gestureInputEnabled) { if (!shouldHandleGesture
if (!gestureInputEnabled
|| AccessibilityUtils.getInstance().isTouchExplorationEnabled() || AccessibilityUtils.getInstance().isTouchExplorationEnabled()
|| (keyboard != null && keyboard.mId.passwordInput())) { || (keyboard != null && keyboard.mId.passwordInput())) {
sIsGestureEnabled = false; sShouldHandleGesture = false;
} else { } else {
sIsGestureEnabled = true; sShouldHandleGesture = true;
} }
} }
@ -243,7 +242,7 @@ public class PointerTracker {
} }
} }
public static void setKeyDetector(KeyDetector keyDetector, boolean gestureInputEnabledByUser) { public static void setKeyDetector(KeyDetector keyDetector, boolean shouldHandleGesture) {
final int trackersSize = sTrackers.size(); final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) { for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i); final PointerTracker tracker = sTrackers.get(i);
@ -252,7 +251,7 @@ public class PointerTracker {
tracker.mKeyboardLayoutHasBeenChanged = true; tracker.mKeyboardLayoutHasBeenChanged = true;
} }
final Keyboard keyboard = keyDetector.getKeyboard(); final Keyboard keyboard = keyDetector.getKeyboard();
updateGestureInputEnabledState(keyboard, gestureInputEnabledByUser); updateGestureHandlingMode(keyboard, shouldHandleGesture);
} }
public static void dismissAllKeyPreviews() { public static void dismissAllKeyPreviews() {
@ -669,8 +668,8 @@ public class PointerTracker {
if (queue != null && queue.size() == 1) { if (queue != null && queue.size() == 1) {
mIsPossibleGesture = false; mIsPossibleGesture = false;
// A gesture should start only from the letter key. // A gesture should start only from the letter key.
if (sIsGestureEnabled && mIsAlphabetKeyboard && !mIsShowingMoreKeysPanel && key != null if (sShouldHandleGesture && mIsAlphabetKeyboard && !mIsShowingMoreKeysPanel
&& Keyboard.isLetterCode(key.mCode)) { && key != null && Keyboard.isLetterCode(key.mCode)) {
mIsPossibleGesture = true; mIsPossibleGesture = true;
// TODO: pointer times should be relative to first down even in entire batch input // TODO: pointer times should be relative to first down even in entire batch input
// instead of resetting to 0 for each new down event. // instead of resetting to 0 for each new down event.
@ -714,7 +713,7 @@ public class PointerTracker {
private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime, private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime,
boolean isHistorical, Key key) { boolean isHistorical, Key key) {
final int gestureTime = (int)(eventTime - tracker.getDownTime()); final int gestureTime = (int)(eventTime - tracker.getDownTime());
if (sIsGestureEnabled && mIsPossibleGesture) { if (sShouldHandleGesture && mIsPossibleGesture) {
final GestureStroke stroke = mGestureStroke; final GestureStroke stroke = mGestureStroke;
stroke.addPoint(x, y, gestureTime, isHistorical); stroke.addPoint(x, y, gestureTime, isHistorical);
if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) { if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) {

View file

@ -430,7 +430,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable) { public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable) {
mIsMainDictionaryAvailable = isMainDictionaryAvailable; mIsMainDictionaryAvailable = isMainDictionaryAvailable;
// TODO: Update gesture input enable state. updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
} }
private void initSuggest() { private void initSuggest() {
@ -681,6 +681,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
switcher.loadKeyboard(editorInfo, mCurrentSettings); switcher.loadKeyboard(editorInfo, mCurrentSettings);
updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
if (mSuggestionStripView != null) if (mSuggestionStripView != null)
mSuggestionStripView.clear(); mSuggestionStripView.clear();
@ -2052,18 +2053,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onRefreshKeyboard() { public void onRefreshKeyboard() {
// When the device locale is changed in SetupWizard etc., this method may get called via // When the device locale is changed in SetupWizard etc., this method may get called via
// onConfigurationChanged before SoftInputWindow is shown. // onConfigurationChanged before SoftInputWindow is shown.
initSuggest();
loadSettings();
if (mKeyboardSwitcher.getKeyboardView() != null) { if (mKeyboardSwitcher.getKeyboardView() != null) {
// Reload keyboard because the current language has been changed. // Reload keyboard because the current language has been changed.
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings); mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings);
updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
} }
initSuggest();
loadSettings();
// Since we just changed languages, we should re-evaluate suggestions with whatever word // Since we just changed languages, we should re-evaluate suggestions with whatever word
// we are currently composing. If we are not composing anything, we may want to display // we are currently composing. If we are not composing anything, we may want to display
// predictions or punctuation signs (which is done by the updateSuggestionStrip anyway). // predictions or punctuation signs (which is done by the updateSuggestionStrip anyway).
mHandler.postUpdateSuggestionStrip(); mHandler.postUpdateSuggestionStrip();
} }
private void updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability() {
final MainKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
if (keyboardView != null) {
final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled
&& mIsMainDictionaryAvailable;
keyboardView.setGestureHandlingMode(shouldHandleGesture);
}
}
// TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to // TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to
// {@link KeyboardSwitcher}. Called from KeyboardSwitcher // {@link KeyboardSwitcher}. Called from KeyboardSwitcher
public void hapticAndAudioFeedback(final int primaryCode) { public void hapticAndAudioFeedback(final int primaryCode) {