Set default audio and haptic feedback settings

- Default keypress volume is set to 0.2f in resource.
- Default keypress vibration duration is set to 10 msec in resource.

Bug: 7055329
Change-Id: I83bd6288d171d9787d52e2b02e4e5305f1435681
main
Tadashi G. Takaoka 2012-12-27 14:48:47 +09:00
parent a2982dd5a7
commit fa7f08b373
11 changed files with 92 additions and 48 deletions

View File

@ -33,5 +33,7 @@
<!-- Preferable keyboard height in absolute scale: 48.0mm --> <!-- Preferable keyboard height in absolute scale: 48.0mm -->
<!-- Xoom --> <!-- Xoom -->
<item>stingray,283.1337</item> <item>stingray,283.1337</item>
<!-- Default value for unknown device: empty string -->
<item>DEFAULT,</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -24,5 +24,7 @@
<item>tuna,5</item> <item>tuna,5</item>
<item>mako,5</item> <item>mako,5</item>
<item>manta,16</item> <item>manta,16</item>
<!-- Default value for unknown device -->
<item>DEFAULT,10</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -20,11 +20,13 @@
<resources> <resources>
<string-array name="keypress_volumes" translatable="false"> <string-array name="keypress_volumes" translatable="false">
<!-- Build.HARDWARE,volume --> <!-- Build.HARDWARE,volume -->
<item>herring,0.5</item> <item>herring,0.5f</item>
<item>tuna,0.5</item> <item>tuna,0.5f</item>
<item>stingray,0.4</item> <item>stingray,0.4f</item>
<item>grouper,0.3</item> <item>grouper,0.3f</item>
<item>mako,0.3</item> <item>mako,0.3f</item>
<item>manta,0.2</item> <item>manta,0.2f</item>
<!-- Default value for unknown device -->
<item>DEFAULT,0.2f</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -21,6 +21,9 @@
<string-array name="phantom_sudden_move_event_device_list" translatable="false"> <string-array name="phantom_sudden_move_event_device_list" translatable="false">
<!-- "Build.HARDWARE,true" that needs "phantom sudden move event" hack. <!-- "Build.HARDWARE,true" that needs "phantom sudden move event" hack.
See {@link com.android.inputmethod.keyboard.PointerTracker}. --> See {@link com.android.inputmethod.keyboard.PointerTracker}. -->
<item>stingray,true</item> <!-- Xoom --> <!-- Xoom -->
<item>stingray,true</item>
<!-- Default value for unknown device -->
<item>DEFAULT,false</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -21,7 +21,11 @@
<string-array name="sudden_jumping_touch_event_device_list" translatable="false"> <string-array name="sudden_jumping_touch_event_device_list" translatable="false">
<!-- "Build.HARDWARE,true" that needs "sudden jump touch event" hack. <!-- "Build.HARDWARE,true" that needs "sudden jump touch event" hack.
See {@link com.android.inputmethod.keyboard.SuddenJumpingTouchEventHandler}. --> See {@link com.android.inputmethod.keyboard.SuddenJumpingTouchEventHandler}. -->
<item>mahimahi,true</item> <!-- Nexus One --> <!-- Nexus One -->
<item>sholes,true</item> <!-- Droid --> <item>mahimahi,true</item>
<!-- Droid -->
<item>sholes,true</item>
<!-- Default value for unknown device -->
<item>DEFAULT,false</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -393,8 +393,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mHasDistinctMultitouch = hasDistinctMultitouch && !forceNonDistinctMultitouch; mHasDistinctMultitouch = hasDistinctMultitouch && !forceNonDistinctMultitouch;
final Resources res = getResources(); final Resources res = getResources();
final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
ResourceUtils.getDeviceOverrideValue(res, ResourceUtils.getDeviceOverrideValue(
R.array.phantom_sudden_move_event_device_list, "false")); res, R.array.phantom_sudden_move_event_device_list));
PointerTracker.init(needsPhantomSuddenMoveEventHack); PointerTracker.init(needsPhantomSuddenMoveEventHack);
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -240,14 +241,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
try { try {
final int displayHeight = mDisplayMetrics.heightPixels; final int displayHeight = mDisplayMetrics.heightPixels;
final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue( final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
mResources, R.array.keyboard_heights, null); mResources, R.array.keyboard_heights);
final float keyboardHeight; final float keyboardHeight;
if (keyboardHeightString != null) { if (TextUtils.isEmpty(keyboardHeightString)) {
keyboardHeight = Float.parseFloat(keyboardHeightString)
* mDisplayMetrics.density;
} else {
keyboardHeight = keyboardAttr.getDimension( keyboardHeight = keyboardAttr.getDimension(
R.styleable.Keyboard_keyboardHeight, displayHeight / 2); R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
} else {
keyboardHeight = Float.parseFloat(keyboardHeightString)
* mDisplayMetrics.density;
} }
final float maxKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr, final float maxKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2); R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);

View File

@ -55,7 +55,7 @@ public final class TouchScreenRegulator {
public TouchScreenRegulator(final Context context, final ProcessMotionEvent view) { public TouchScreenRegulator(final Context context, final ProcessMotionEvent view) {
mView = view; mView = view;
mNeedsSuddenJumpingHack = Boolean.parseBoolean(ResourceUtils.getDeviceOverrideValue( mNeedsSuddenJumpingHack = Boolean.parseBoolean(ResourceUtils.getDeviceOverrideValue(
context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false")); context.getResources(), R.array.sudden_jumping_touch_event_device_list));
} }
public void setKeyboardGeometry(final int keyboardWidth) { public void setKeyboardGeometry(final int keyboardWidth) {

View File

@ -19,11 +19,15 @@ package com.android.inputmethod.latin;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import java.util.HashMap; import java.util.HashMap;
public final class ResourceUtils { public final class ResourceUtils {
private static final String TAG = ResourceUtils.class.getSimpleName();
private static final boolean DEBUG = false;
public static final float UNDEFINED_RATIO = -1.0f; public static final float UNDEFINED_RATIO = -1.0f;
public static final int UNDEFINED_DIMENSION = -1; public static final int UNDEFINED_DIMENSION = -1;
@ -31,24 +35,44 @@ public final class ResourceUtils {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }
private static final String DEFAULT_PREFIX = "DEFAULT,";
private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; private static final String HARDWARE_PREFIX = Build.HARDWARE + ",";
private static final HashMap<String, String> sDeviceOverrideValueMap = private static final HashMap<String, String> sDeviceOverrideValueMap =
CollectionUtils.newHashMap(); CollectionUtils.newHashMap();
public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { public static String getDeviceOverrideValue(final Resources res, final int overrideResId) {
final int orientation = res.getConfiguration().orientation; final int orientation = res.getConfiguration().orientation;
final String key = overrideResId + "-" + orientation; final String key = overrideResId + "-" + orientation;
if (!sDeviceOverrideValueMap.containsKey(key)) { if (sDeviceOverrideValueMap.containsKey(key)) {
String overrideValue = defValue; return sDeviceOverrideValueMap.get(key);
for (final String element : res.getStringArray(overrideResId)) { }
if (element.startsWith(HARDWARE_PREFIX)) {
overrideValue = element.substring(HARDWARE_PREFIX.length()); final String[] overrideArray = res.getStringArray(overrideResId);
break; final String overrideValue = StringUtils.findPrefixedString(HARDWARE_PREFIX, overrideArray);
} // The overrideValue might be an empty string.
if (overrideValue != null) {
if (DEBUG) {
Log.d(TAG, "Find override value:"
+ " resource="+ res.getResourceEntryName(overrideResId)
+ " Build.HARDWARE=" + Build.HARDWARE + " override=" + overrideValue);
} }
sDeviceOverrideValueMap.put(key, overrideValue); sDeviceOverrideValueMap.put(key, overrideValue);
return overrideValue;
} }
return sDeviceOverrideValueMap.get(key);
final String defaultValue = StringUtils.findPrefixedString(DEFAULT_PREFIX, overrideArray);
// The defaultValue might be an empty string.
if (defaultValue == null) {
Log.w(TAG, "Couldn't find override value nor default value:"
+ " resource="+ res.getResourceEntryName(overrideResId)
+ " Build.HARDWARE=" + Build.HARDWARE);
} else if (DEBUG) {
Log.d(TAG, "Found default value:"
+ " resource="+ res.getResourceEntryName(overrideResId)
+ " Build.HARDWARE=" + Build.HARDWARE + " default=" + defaultValue);
}
sDeviceOverrideValueMap.put(key, defaultValue);
return defaultValue;
} }
public static boolean isValidFraction(final float fraction) { public static boolean isValidFraction(final float fraction) {
@ -85,8 +109,8 @@ public final class ResourceUtils {
return a.getDimensionPixelSize(index, ResourceUtils.UNDEFINED_DIMENSION); return a.getDimensionPixelSize(index, ResourceUtils.UNDEFINED_DIMENSION);
} }
public static float getDimensionOrFraction(TypedArray a, int index, int base, public static float getDimensionOrFraction(final TypedArray a, final int index, final int base,
float defValue) { final float defValue) {
final TypedValue value = a.peekValue(index); final TypedValue value = a.peekValue(index);
if (value == null) { if (value == null) {
return defValue; return defValue;
@ -99,7 +123,7 @@ public final class ResourceUtils {
return defValue; return defValue;
} }
public static int getEnumValue(TypedArray a, int index, int defValue) { public static int getEnumValue(final TypedArray a, final int index, final int defValue) {
final TypedValue value = a.peekValue(index); final TypedValue value = a.peekValue(index);
if (value == null) { if (value == null) {
return defValue; return defValue;
@ -110,19 +134,19 @@ public final class ResourceUtils {
return defValue; return defValue;
} }
public static boolean isFractionValue(TypedValue v) { public static boolean isFractionValue(final TypedValue v) {
return v.type == TypedValue.TYPE_FRACTION; return v.type == TypedValue.TYPE_FRACTION;
} }
public static boolean isDimensionValue(TypedValue v) { public static boolean isDimensionValue(final TypedValue v) {
return v.type == TypedValue.TYPE_DIMENSION; return v.type == TypedValue.TYPE_DIMENSION;
} }
public static boolean isIntegerValue(TypedValue v) { public static boolean isIntegerValue(final TypedValue v) {
return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT; return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT;
} }
public static boolean isStringValue(TypedValue v) { public static boolean isStringValue(final TypedValue v) {
return v.type == TypedValue.TYPE_STRING; return v.type == TypedValue.TYPE_STRING;
} }
} }

View File

@ -78,10 +78,6 @@ public final class SettingsValues {
public final boolean mUseDoubleSpacePeriod; public final boolean mUseDoubleSpacePeriod;
// Use bigrams to predict the next word when there is no input for it yet // Use bigrams to predict the next word when there is no input for it yet
public final boolean mBigramPredictionEnabled; public final boolean mBigramPredictionEnabled;
@SuppressWarnings("unused") // TODO: Use this
private final int mVibrationDurationSettingsRawValue;
@SuppressWarnings("unused") // TODO: Use this
private final float mKeypressSoundVolumeRawValue;
public final boolean mGestureInputEnabled; public final boolean mGestureInputEnabled;
public final boolean mGesturePreviewTrailEnabled; public final boolean mGesturePreviewTrailEnabled;
public final boolean mGestureFloatingPreviewTextEnabled; public final boolean mGestureFloatingPreviewTextEnabled;
@ -158,9 +154,6 @@ public final class SettingsValues {
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true); mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue);
mBigramPredictionEnabled = isBigramPredictionEnabled(prefs, res); mBigramPredictionEnabled = isBigramPredictionEnabled(prefs, res);
mVibrationDurationSettingsRawValue =
prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1);
mKeypressSoundVolumeRawValue = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
// Compute other readable settings // Compute other readable settings
mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res);
@ -383,27 +376,23 @@ public final class SettingsValues {
// Accessed from the settings interface, hence public // Accessed from the settings interface, hence public
public static float getCurrentKeypressSoundVolume(final SharedPreferences prefs, public static float getCurrentKeypressSoundVolume(final SharedPreferences prefs,
final Resources res) { final Resources res) {
// TODO: use mVibrationDurationSettingsRawValue instead of reading it again here
final float volume = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); final float volume = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
if (volume >= 0) { if (volume >= 0) {
return volume; return volume;
} }
return Float.parseFloat(
return Float.parseFloat(ResourceUtils.getDeviceOverrideValue( ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_volumes));
res, R.array.keypress_volumes, "-1.0f"));
} }
// Likewise // Likewise
public static int getCurrentVibrationDuration(final SharedPreferences prefs, public static int getCurrentVibrationDuration(final SharedPreferences prefs,
final Resources res) { final Resources res) {
// TODO: use mKeypressVibrationDuration instead of reading it again here
final int ms = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); final int ms = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1);
if (ms >= 0) { if (ms >= 0) {
return ms; return ms;
} }
return Integer.parseInt(
return Integer.parseInt(ResourceUtils.getDeviceOverrideValue( ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations));
res, R.array.keypress_vibration_durations, "-1"));
} }
// Likewise // Likewise

View File

@ -61,6 +61,23 @@ public final class StringUtils {
return TextUtils.join(",", result); return TextUtils.join(",", result);
} }
/**
* Find a string that start with specified prefix from an array.
*
* @param prefix a prefix string to find.
* @param array an string array to be searched.
* @return the rest part of the string that starts with the prefix.
* Returns null if it couldn't be found.
*/
public static String findPrefixedString(final String prefix, final String[] array) {
for (final String element : array) {
if (element.startsWith(prefix)) {
return element.substring(prefix.length());
}
}
return null;
}
/** /**
* Remove duplicates from an array of strings. * Remove duplicates from an array of strings.
* *