diff options
Diffstat (limited to 'java/src')
6 files changed, 33 insertions, 41 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index ad08d6477..c5bd62431 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -32,6 +32,7 @@ import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetExcep import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.internal.KeyboardState; import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; +import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.InputView; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; @@ -68,8 +69,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { new KeyboardTheme(5, R.style.KeyboardTheme_IceCreamSandwich), }; - private final AudioAndHapticFeedbackManager mFeedbackManager = - AudioAndHapticFeedbackManager.getInstance(); private SubtypeSwitcher mSubtypeSwitcher; private SharedPreferences mPrefs; @@ -151,7 +150,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mKeyboardLayoutSet = builder.build(); try { mState.onLoadKeyboard(); - mFeedbackManager.onSettingsChanged(settingsValues); } catch (KeyboardLayoutSetException e) { Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause()); @@ -159,10 +157,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } } - public void onRingerModeChanged() { - mFeedbackManager.onRingerModeChanged(); - } - public void saveKeyboardState() { if (getKeyboard() != null) { mState.onSaveKeyboardState(); @@ -217,9 +211,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } public void onPressKey(final int code, final boolean isSinglePointer) { - if (isVibrateAndSoundFeedbackRequired()) { - mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView); - } + hapticAndAudioFeedback(code); mState.onPressKey(code, isSinglePointer, mLatinIME.getCurrentAutoCapsState()); } @@ -328,24 +320,25 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } } - // Implements {@link KeyboardState.SwitchActions}. - @Override - public void hapticAndAudioFeedback(final int code) { - mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView); + private void hapticAndAudioFeedback(final int code) { + if (mKeyboardView == null || mKeyboardView.isInSlidingKeyInput()) { + return; + } + AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, mKeyboardView); } public void onLongPressTimeout(final int code) { mState.onLongPressTimeout(code); + final Keyboard keyboard = getKeyboard(); + if (keyboard != null && keyboard.mId.isAlphabetKeyboard() && code == Constants.CODE_SHIFT) { + hapticAndAudioFeedback(code); + } } public boolean isInMomentarySwitchState() { return mState.isInMomentarySwitchState(); } - private boolean isVibrateAndSoundFeedbackRequired() { - return mKeyboardView != null && !mKeyboardView.isInSlidingKeyInput(); - } - /** * Updates state machine to figure out when to automatically switch back to the previous mode. */ diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 6c6fc6157..34464f690 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -57,6 +57,7 @@ import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview; import com.android.inputmethod.keyboard.internal.TouchScreenRegulator; +import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.CoordinateUtils; @@ -240,7 +241,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack case MSG_REPEAT_KEY: final Key currentKey = tracker.getKey(); if (currentKey != null && currentKey.mCode == msg.arg1) { - tracker.onRegisterKey(currentKey); + tracker.onRepeatKey(currentKey); + AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback( + currentKey.mCode, keyboardView); startKeyRepeatTimer(tracker, mKeyRepeatInterval); } break; @@ -987,16 +990,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack /** * Called when a key is long pressed. * @param tracker the pointer tracker which pressed the parent key - * @return true if the long press is handled, false otherwise. Subclasses should call the - * method on the base class if the subclass doesn't wish to handle the call. */ - private boolean onLongPress(final PointerTracker tracker) { + private void onLongPress(final PointerTracker tracker) { if (isShowingMoreKeysPanel()) { - return false; + return; } final Key key = tracker.getKey(); if (key == null) { - return false; + return; } if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.mainKeyboardView_onLongPress(); @@ -1007,18 +1008,18 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack tracker.onLongPressed(); invokeCodeInput(embeddedCode); invokeReleaseKey(code); - KeyboardSwitcher.getInstance().hapticAndAudioFeedback(code); - return true; + AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, this); + return; } if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) { // Long pressing the space key invokes IME switcher dialog. if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { tracker.onLongPressed(); invokeReleaseKey(code); - return true; + return; } } - return openMoreKeysPanel(key, tracker); + openMoreKeysPanel(key, tracker); } private boolean invokeCustomRequest(final int requestCode) { @@ -1034,10 +1035,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mKeyboardActionListener.onReleaseKey(code, false); } - private boolean openMoreKeysPanel(final Key key, final PointerTracker tracker) { + private void openMoreKeysPanel(final Key key, final PointerTracker tracker) { final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext()); if (moreKeysPanel == null) { - return false; + return; } final int[] lastCoords = CoordinateUtils.newInstance(); @@ -1059,7 +1060,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack final int translatedX = moreKeysPanel.translateX(CoordinateUtils.x(lastCoords)); final int translatedY = moreKeysPanel.translateY(CoordinateUtils.y(lastCoords)); tracker.onShowMoreKeysPanel(translatedX, translatedY, moreKeysPanel); - return true; } public boolean isInSlidingKeyInput() { diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 174239325..5df7011cb 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -1266,15 +1266,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element { if (!key.isRepeatable()) return; // Don't start key repeat when we are in sliding input mode. if (mIsInSlidingKeyInput) return; - onRegisterKey(key); + onRepeatKey(key); mTimerProxy.startKeyRepeatTimer(this); } - public void onRegisterKey(final Key key) { - if (key != null) { - detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis()); - mTimerProxy.startTypingStateTimer(key); - } + public void onRepeatKey(final Key key) { + detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis()); + mTimerProxy.startTypingStateTimer(key); } private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 6af1bd75f..f18d5edff 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -58,7 +58,6 @@ public final class KeyboardState { public void cancelDoubleTapTimer(); public void startLongPressTimer(int code); public void cancelLongPressTimer(); - public void hapticAndAudioFeedback(int code); } private final SwitchActions mSwitchActions; @@ -387,7 +386,6 @@ public final class KeyboardState { } if (mIsAlphabetMode && code == Constants.CODE_SHIFT) { mLongPressShiftLockFired = true; - mSwitchActions.hapticAndAudioFeedback(code); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f85c16be3..6bf9f3ab5 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -480,6 +480,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final InputAttributes inputAttributes = new InputAttributes(getCurrentInputEditorInfo(), isFullscreenMode()); mSettings.loadSettings(locale, inputAttributes); + AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(mSettings.getCurrent()); // May need to reset the contacts dictionary depending on the user settings. resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } @@ -2701,7 +2702,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { mSubtypeSwitcher.onNetworkStateChanged(intent); } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { - mKeyboardSwitcher.onRingerModeChanged(); + AudioAndHapticFeedbackManager.getInstance().onRingerModeChanged(); } } }; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index ad350a02f..1113939d1 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -54,6 +54,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MoreKeysPanel; import com.android.inputmethod.keyboard.ViewLayoutUtils; +import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.AutoCorrection; import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.Constants; @@ -689,7 +690,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick @Override public boolean onLongClick(final View view) { - KeyboardSwitcher.getInstance().hapticAndAudioFeedback(Constants.NOT_A_CODE); + AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback( + Constants.NOT_A_CODE, this); return showMoreSuggestions(); } |