From 874a600dc805b6ab9fe92fccddfe4765b8d29a35 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 9 Jun 2014 23:25:02 +0900 Subject: [PATCH] Add audio and haptic feedback for Emoji and Suggestions Bug: 15378862 Change-Id: Ia14929bd9eb63ad5735cae0ad98ad0e2ad301128 --- java/res/layout/emoji_keyboard_tab_icon.xml | 4 ++ java/res/layout/emoji_palettes_view.xml | 20 ++++++- java/res/layout/suggestion_divider.xml | 10 +++- java/res/layout/suggestions_strip.xml | 17 +++++- java/res/values/themes-common.xml | 5 +- .../keyboard/emoji/EmojiPalettesView.java | 3 + .../latin/AudioAndHapticFeedbackManager.java | 55 ++++++++++--------- .../suggestions/SuggestionStripView.java | 2 + 8 files changed, 79 insertions(+), 37 deletions(-) diff --git a/java/res/layout/emoji_keyboard_tab_icon.xml b/java/res/layout/emoji_keyboard_tab_icon.xml index 13bb41ca2..15f9c3a3e 100644 --- a/java/res/layout/emoji_keyboard_tab_icon.xml +++ b/java/res/layout/emoji_keyboard_tab_icon.xml @@ -19,6 +19,8 @@ --> + diff --git a/java/res/layout/emoji_palettes_view.xml b/java/res/layout/emoji_palettes_view.xml index 06a937bff..9ff090aad 100644 --- a/java/res/layout/emoji_palettes_view.xml +++ b/java/res/layout/emoji_palettes_view.xml @@ -62,11 +62,15 @@ android:layout_height="match_parent" android:background="@drawable/suggestions_strip_divider" /> + + + android:layout_height="match_parent" + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false" /> + + + android:layout_height="match_parent" + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false" /> diff --git a/java/res/layout/suggestion_divider.xml b/java/res/layout/suggestion_divider.xml index be97eae5a..563599d82 100644 --- a/java/res/layout/suggestion_divider.xml +++ b/java/res/layout/suggestion_divider.xml @@ -18,13 +18,17 @@ */ --> + + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false" /> diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml index 3d2f07f7b..489477990 100644 --- a/java/res/layout/suggestions_strip.xml +++ b/java/res/layout/suggestions_strip.xml @@ -20,13 +20,19 @@ + + android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin" + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false" /> + + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false"> + + android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin" + android:hapticFeedbackEnabled="false" + android:soundEffectsEnabled="false" > 0dp @dimen/config_suggestion_text_horizontal_padding 0dp - + false + false false false true diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java index abed5208b..e37cd2369 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java @@ -46,6 +46,7 @@ import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.internal.KeyDrawParams; import com.android.inputmethod.keyboard.internal.KeyVisualAttributes; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; @@ -240,6 +241,8 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange @Override public void onTabChanged(final String tabId) { + AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( + Constants.CODE_UNSPECIFIED, this); final int categoryId = mEmojiCategory.getCategoryId(tabId); setCurrentCategoryId(categoryId, false /* force */); updateEmojiCategoryPageIdView(); diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java index 54bc29559..eb8b34ccd 100644 --- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java +++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java @@ -16,14 +16,14 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.latin.settings.SettingsValues; - import android.content.Context; import android.media.AudioManager; import android.os.Vibrator; import android.view.HapticFeedbackConstants; import android.view.View; +import com.android.inputmethod.latin.settings.SettingsValues; + /** * This class gathers audio feedback and haptic feedback functions. * @@ -86,40 +86,41 @@ public final class AudioAndHapticFeedbackManager { if (mAudioManager == null) { return; } - if (mSoundOn) { - final int sound; - switch (code) { - case Constants.CODE_DELETE: - sound = AudioManager.FX_KEYPRESS_DELETE; - break; - case Constants.CODE_ENTER: - sound = AudioManager.FX_KEYPRESS_RETURN; - break; - case Constants.CODE_SPACE: - sound = AudioManager.FX_KEYPRESS_SPACEBAR; - break; - default: - sound = AudioManager.FX_KEYPRESS_STANDARD; - break; - } - mAudioManager.playSoundEffect(sound, mSettingsValues.mKeypressSoundVolume); + if (!mSoundOn) { + return; } + final int sound; + switch (code) { + case Constants.CODE_DELETE: + sound = AudioManager.FX_KEYPRESS_DELETE; + break; + case Constants.CODE_ENTER: + sound = AudioManager.FX_KEYPRESS_RETURN; + break; + case Constants.CODE_SPACE: + sound = AudioManager.FX_KEYPRESS_SPACEBAR; + break; + default: + sound = AudioManager.FX_KEYPRESS_STANDARD; + break; + } + mAudioManager.playSoundEffect(sound, mSettingsValues.mKeypressSoundVolume); } public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) { if (!mSettingsValues.mVibrateOn) { return; } - if (mSettingsValues.mKeypressVibrationDuration < 0) { - // Go ahead with the system default - if (viewToPerformHapticFeedbackOn != null) { - viewToPerformHapticFeedbackOn.performHapticFeedback( - HapticFeedbackConstants.KEYBOARD_TAP, - HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); - } + if (mSettingsValues.mKeypressVibrationDuration >= 0) { + vibrate(mSettingsValues.mKeypressVibrationDuration); return; } - vibrate(mSettingsValues.mKeypressVibrationDuration); + // Go ahead with the system default + if (viewToPerformHapticFeedbackOn != null) { + viewToPerformHapticFeedbackOn.performHapticFeedback( + HapticFeedbackConstants.KEYBOARD_TAP, + HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } } public void onSettingsChanged(final SettingsValues settingsValues) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 8ce863578..3be933ff7 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -428,6 +428,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick @Override public void onClick(final View view) { + AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( + Constants.CODE_UNSPECIFIED, this); if (view == mImportantNoticeStrip) { mListener.showImportantNoticeContents(); return;