From fa7f08b37327c825baf0a6455d6f7fdf8b37da57 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 27 Dec 2012 14:48:47 +0900 Subject: [PATCH] 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 --- java/res/values/keyboard-heights.xml | 2 + .../values/keypress-vibration-durations.xml | 2 + java/res/values/keypress-volumes.xml | 14 +++-- .../phantom-sudden-move-event-device-list.xml | 5 +- ...sudden-jumping-touch-event-device-list.xml | 8 ++- .../keyboard/MainKeyboardView.java | 4 +- .../keyboard/internal/KeyboardBuilder.java | 11 ++-- .../internal/TouchScreenRegulator.java | 2 +- .../inputmethod/latin/ResourceUtils.java | 56 +++++++++++++------ .../inputmethod/latin/SettingsValues.java | 19 ++----- .../inputmethod/latin/StringUtils.java | 17 ++++++ 11 files changed, 92 insertions(+), 48 deletions(-) diff --git a/java/res/values/keyboard-heights.xml b/java/res/values/keyboard-heights.xml index 7d85994be..418d3e5b6 100644 --- a/java/res/values/keyboard-heights.xml +++ b/java/res/values/keyboard-heights.xml @@ -33,5 +33,7 @@ stingray,283.1337 + + DEFAULT, diff --git a/java/res/values/keypress-vibration-durations.xml b/java/res/values/keypress-vibration-durations.xml index 370959c1a..9b1d5431e 100644 --- a/java/res/values/keypress-vibration-durations.xml +++ b/java/res/values/keypress-vibration-durations.xml @@ -24,5 +24,7 @@ tuna,5 mako,5 manta,16 + + DEFAULT,10 diff --git a/java/res/values/keypress-volumes.xml b/java/res/values/keypress-volumes.xml index d1120694b..047fe0c5f 100644 --- a/java/res/values/keypress-volumes.xml +++ b/java/res/values/keypress-volumes.xml @@ -20,11 +20,13 @@ - herring,0.5 - tuna,0.5 - stingray,0.4 - grouper,0.3 - mako,0.3 - manta,0.2 + herring,0.5f + tuna,0.5f + stingray,0.4f + grouper,0.3f + mako,0.3f + manta,0.2f + + DEFAULT,0.2f diff --git a/java/res/values/phantom-sudden-move-event-device-list.xml b/java/res/values/phantom-sudden-move-event-device-list.xml index 63d12e96e..22f510229 100644 --- a/java/res/values/phantom-sudden-move-event-device-list.xml +++ b/java/res/values/phantom-sudden-move-event-device-list.xml @@ -21,6 +21,9 @@ - stingray,true + + stingray,true + + DEFAULT,false diff --git a/java/res/values/sudden-jumping-touch-event-device-list.xml b/java/res/values/sudden-jumping-touch-event-device-list.xml index 543992a81..3fdc0c7e3 100644 --- a/java/res/values/sudden-jumping-touch-event-device-list.xml +++ b/java/res/values/sudden-jumping-touch-event-device-list.xml @@ -21,7 +21,11 @@ - mahimahi,true - sholes,true + + mahimahi,true + + sholes,true + + DEFAULT,false diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 584d2fe46..7caa8bcbc 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -393,8 +393,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mHasDistinctMultitouch = hasDistinctMultitouch && !forceNonDistinctMultitouch; final Resources res = getResources(); final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( - ResourceUtils.getDeviceOverrideValue(res, - R.array.phantom_sudden_move_event_device_list, "false")); + ResourceUtils.getDeviceOverrideValue( + res, R.array.phantom_sudden_move_event_device_list)); PointerTracker.init(needsPhantomSuddenMoveEventHack); final TypedArray a = context.obtainStyledAttributes( diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index da418f41a..0f1d5cc80 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; @@ -240,14 +241,14 @@ public class KeyboardBuilder { try { final int displayHeight = mDisplayMetrics.heightPixels; final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue( - mResources, R.array.keyboard_heights, null); + mResources, R.array.keyboard_heights); final float keyboardHeight; - if (keyboardHeightString != null) { - keyboardHeight = Float.parseFloat(keyboardHeightString) - * mDisplayMetrics.density; - } else { + if (TextUtils.isEmpty(keyboardHeightString)) { keyboardHeight = keyboardAttr.getDimension( R.styleable.Keyboard_keyboardHeight, displayHeight / 2); + } else { + keyboardHeight = Float.parseFloat(keyboardHeightString) + * mDisplayMetrics.density; } final float maxKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2); diff --git a/java/src/com/android/inputmethod/keyboard/internal/TouchScreenRegulator.java b/java/src/com/android/inputmethod/keyboard/internal/TouchScreenRegulator.java index c795d5322..e7a0a70d1 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/TouchScreenRegulator.java +++ b/java/src/com/android/inputmethod/keyboard/internal/TouchScreenRegulator.java @@ -55,7 +55,7 @@ public final class TouchScreenRegulator { public TouchScreenRegulator(final Context context, final ProcessMotionEvent view) { mView = view; 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) { diff --git a/java/src/com/android/inputmethod/latin/ResourceUtils.java b/java/src/com/android/inputmethod/latin/ResourceUtils.java index 5021ad384..b74b979b5 100644 --- a/java/src/com/android/inputmethod/latin/ResourceUtils.java +++ b/java/src/com/android/inputmethod/latin/ResourceUtils.java @@ -19,11 +19,15 @@ package com.android.inputmethod.latin; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Build; +import android.util.Log; import android.util.TypedValue; import java.util.HashMap; 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 int UNDEFINED_DIMENSION = -1; @@ -31,24 +35,44 @@ public final class ResourceUtils { // 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 HashMap sDeviceOverrideValueMap = 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 String key = overrideResId + "-" + orientation; - if (!sDeviceOverrideValueMap.containsKey(key)) { - String overrideValue = defValue; - for (final String element : res.getStringArray(overrideResId)) { - if (element.startsWith(HARDWARE_PREFIX)) { - overrideValue = element.substring(HARDWARE_PREFIX.length()); - break; - } + if (sDeviceOverrideValueMap.containsKey(key)) { + return sDeviceOverrideValueMap.get(key); + } + + final String[] overrideArray = res.getStringArray(overrideResId); + 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); + 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) { @@ -85,8 +109,8 @@ public final class ResourceUtils { return a.getDimensionPixelSize(index, ResourceUtils.UNDEFINED_DIMENSION); } - public static float getDimensionOrFraction(TypedArray a, int index, int base, - float defValue) { + public static float getDimensionOrFraction(final TypedArray a, final int index, final int base, + final float defValue) { final TypedValue value = a.peekValue(index); if (value == null) { return defValue; @@ -99,7 +123,7 @@ public final class ResourceUtils { 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); if (value == null) { return defValue; @@ -110,19 +134,19 @@ public final class ResourceUtils { return defValue; } - public static boolean isFractionValue(TypedValue v) { + public static boolean isFractionValue(final TypedValue v) { 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; } - 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; } - public static boolean isStringValue(TypedValue v) { + public static boolean isStringValue(final TypedValue v) { return v.type == TypedValue.TYPE_STRING; } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index a23876722..157684437 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -78,10 +78,6 @@ public final class SettingsValues { public final boolean mUseDoubleSpacePeriod; // Use bigrams to predict the next word when there is no input for it yet 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 mGesturePreviewTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; @@ -158,9 +154,6 @@ public final class SettingsValues { mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true); mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); 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 mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); @@ -383,27 +376,23 @@ public final class SettingsValues { // Accessed from the settings interface, hence public public static float getCurrentKeypressSoundVolume(final SharedPreferences prefs, final Resources res) { - // TODO: use mVibrationDurationSettingsRawValue instead of reading it again here final float volume = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); if (volume >= 0) { return volume; } - - return Float.parseFloat(ResourceUtils.getDeviceOverrideValue( - res, R.array.keypress_volumes, "-1.0f")); + return Float.parseFloat( + ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_volumes)); } // Likewise public static int getCurrentVibrationDuration(final SharedPreferences prefs, final Resources res) { - // TODO: use mKeypressVibrationDuration instead of reading it again here final int ms = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); if (ms >= 0) { return ms; } - - return Integer.parseInt(ResourceUtils.getDeviceOverrideValue( - res, R.array.keypress_vibration_durations, "-1")); + return Integer.parseInt( + ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations)); } // Likewise diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java index 043043cef..ddaa5ff5b 100644 --- a/java/src/com/android/inputmethod/latin/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -61,6 +61,23 @@ public final class StringUtils { 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. *