am 874a600d: Add audio and haptic feedback for Emoji and Suggestions

* commit '874a600dc805b6ab9fe92fccddfe4765b8d29a35':
  Add audio and haptic feedback for Emoji and Suggestions
This commit is contained in:
Tadashi G. Takaoka 2014-06-10 00:25:19 +00:00 committed by Android Git Automerger
commit 0ec60573ef
8 changed files with 79 additions and 37 deletions

View file

@ -19,6 +19,8 @@
--> -->
<!-- Note: contentDescription will be added programatically in {@link EmojiPalettesView}. --> <!-- Note: contentDescription will be added programatically in {@link EmojiPalettesView}. -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="1.0" android:layout_weight="1.0"
@ -26,4 +28,6 @@
android:gravity="center" android:gravity="center"
android:scaleType="center" android:scaleType="center"
android:contentDescription="@null" android:contentDescription="@null"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false"
/> />

View file

@ -62,11 +62,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/suggestions_strip_divider" /> android:background="@drawable/suggestions_strip_divider" />
<!-- TODO: Implement KeyView and replace this. --> <!-- TODO: Implement KeyView and replace this. -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<ImageButton <ImageButton
android:id="@+id/emoji_keyboard_delete" android:id="@+id/emoji_keyboard_delete"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="12.5" android:layout_weight="12.5"
android:layout_height="match_parent" android:layout_height="match_parent"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false"
android:contentDescription="@string/spoken_description_delete" /> android:contentDescription="@string/spoken_description_delete" />
</LinearLayout> </LinearLayout>
<android.support.v4.view.ViewPager <android.support.v4.view.ViewPager
@ -85,18 +89,26 @@
android:layout_weight="1" android:layout_weight="1"
> >
<!-- TODO: Implement a KeyView and replace this. --> <!-- TODO: Implement a KeyView and replace this. -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<TextView <TextView
android:id="@+id/emoji_keyboard_alphabet_left" android:id="@+id/emoji_keyboard_alphabet_left"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.15" android:layout_weight="0.15"
android:gravity="center" android:gravity="center"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" />
<!-- TODO: Implement KeyView and replace this. --> <!-- TODO: Implement KeyView and replace this. -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<RelativeLayout <RelativeLayout
android:id="@+id/emoji_keyboard_space" android:id="@+id/emoji_keyboard_space"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.70" android:layout_weight="0.70"
android:layout_height="match_parent" android:layout_height="match_parent"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false"
android:contentDescription="@string/spoken_description_space"> android:contentDescription="@string/spoken_description_space">
<!-- WORKAROUND: Show the spacebar icon as a bacground of this View. --> <!-- WORKAROUND: Show the spacebar icon as a bacground of this View. -->
<View <View
@ -108,11 +120,15 @@
android:layout_centerInParent="true" /> android:layout_centerInParent="true" />
</RelativeLayout> </RelativeLayout>
<!-- TODO: Implement KeyView and replace this. --> <!-- TODO: Implement KeyView and replace this. -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<TextView <TextView
android:id="@+id/emoji_keyboard_alphabet_right" android:id="@+id/emoji_keyboard_alphabet_right"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.15" android:layout_weight="0.15"
android:gravity="center" android:gravity="center"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" />
</LinearLayout> </LinearLayout>
</com.android.inputmethod.keyboard.emoji.EmojiPalettesView> </com.android.inputmethod.keyboard.emoji.EmojiPalettesView>

View file

@ -18,13 +18,17 @@
*/ */
--> -->
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<ImageView <ImageView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="0dp"
android:gravity="center"
android:src="@drawable/suggestions_strip_divider" android:src="@drawable/suggestions_strip_divider"
android:contentDescription="@null"
android:clickable="false" android:clickable="false"
android:longClickable="false" android:longClickable="false"
android:contentDescription="@null" android:hapticFeedbackEnabled="false"
android:padding="0dp" android:soundEffectsEnabled="false" />
android:gravity="center" />

View file

@ -20,13 +20,19 @@
<merge <merge
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<LinearLayout <LinearLayout
android:id="@+id/suggestions_strip" android:id="@+id/suggestions_strip"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin" android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin"
android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin" /> android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" />
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<LinearLayout <LinearLayout
android:id="@+id/add_to_dictionary_strip" android:id="@+id/add_to_dictionary_strip"
android:orientation="horizontal" android:orientation="horizontal"
@ -34,7 +40,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin" android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin"
android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin" android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin"
android:visibility="invisible"> android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false">
<TextView <TextView
android:id="@+id/word_to_save" android:id="@+id/word_to_save"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -49,13 +56,17 @@
android:textAlignment="viewStart" android:textAlignment="viewStart"
style="?attr/suggestionWordStyle" /> style="?attr/suggestionWordStyle" />
</LinearLayout> </LinearLayout>
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<LinearLayout <LinearLayout
android:id="@+id/important_notice_strip" android:id="@+id/important_notice_strip"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin" android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin"
android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin"> android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" >
<TextView <TextView
android:id="@+id/important_notice_title" android:id="@+id/important_notice_title"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -124,9 +124,10 @@
<item name="android:paddingTop">0dp</item> <item name="android:paddingTop">0dp</item>
<item name="android:paddingRight">@dimen/config_suggestion_text_horizontal_padding</item> <item name="android:paddingRight">@dimen/config_suggestion_text_horizontal_padding</item>
<item name="android:paddingBottom">0dp</item> <item name="android:paddingBottom">0dp</item>
<!-- Provide a haptic feedback by ourselves based on the keyboard settings. <!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's haptic feedback settings. --> We just need to ignore the system's audio and haptic feedback settings. -->
<item name="android:hapticFeedbackEnabled">false</item> <item name="android:hapticFeedbackEnabled">false</item>
<item name="android:soundEffectsEnabled">false</item>
<item name="android:focusable">false</item> <item name="android:focusable">false</item>
<item name="android:clickable">false</item> <item name="android:clickable">false</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>

View file

@ -46,6 +46,7 @@ import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.internal.KeyDrawParams; import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes; import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
@ -240,6 +241,8 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
@Override @Override
public void onTabChanged(final String tabId) { public void onTabChanged(final String tabId) {
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
Constants.CODE_UNSPECIFIED, this);
final int categoryId = mEmojiCategory.getCategoryId(tabId); final int categoryId = mEmojiCategory.getCategoryId(tabId);
setCurrentCategoryId(categoryId, false /* force */); setCurrentCategoryId(categoryId, false /* force */);
updateEmojiCategoryPageIdView(); updateEmojiCategoryPageIdView();

View file

@ -16,14 +16,14 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.settings.SettingsValues;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.View; import android.view.View;
import com.android.inputmethod.latin.settings.SettingsValues;
/** /**
* This class gathers audio feedback and haptic feedback functions. * This class gathers audio feedback and haptic feedback functions.
* *
@ -86,40 +86,41 @@ public final class AudioAndHapticFeedbackManager {
if (mAudioManager == null) { if (mAudioManager == null) {
return; return;
} }
if (mSoundOn) { if (!mSoundOn) {
final int sound; return;
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);
} }
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) { public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) {
if (!mSettingsValues.mVibrateOn) { if (!mSettingsValues.mVibrateOn) {
return; return;
} }
if (mSettingsValues.mKeypressVibrationDuration < 0) { if (mSettingsValues.mKeypressVibrationDuration >= 0) {
// Go ahead with the system default vibrate(mSettingsValues.mKeypressVibrationDuration);
if (viewToPerformHapticFeedbackOn != null) {
viewToPerformHapticFeedbackOn.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
return; 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) { public void onSettingsChanged(final SettingsValues settingsValues) {

View file

@ -428,6 +428,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override @Override
public void onClick(final View view) { public void onClick(final View view) {
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
Constants.CODE_UNSPECIFIED, this);
if (view == mImportantNoticeStrip) { if (view == mImportantNoticeStrip) {
mListener.showImportantNoticeContents(); mListener.showImportantNoticeContents();
return; return;