mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
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
This commit is contained in:
parent
a2982dd5a7
commit
fa7f08b373
@ -33,5 +33,7 @@
|
||||
<!-- Preferable keyboard height in absolute scale: 48.0mm -->
|
||||
<!-- Xoom -->
|
||||
<item>stingray,283.1337</item>
|
||||
<!-- Default value for unknown device: empty string -->
|
||||
<item>DEFAULT,</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -24,5 +24,7 @@
|
||||
<item>tuna,5</item>
|
||||
<item>mako,5</item>
|
||||
<item>manta,16</item>
|
||||
<!-- Default value for unknown device -->
|
||||
<item>DEFAULT,10</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -20,11 +20,13 @@
|
||||
<resources>
|
||||
<string-array name="keypress_volumes" translatable="false">
|
||||
<!-- Build.HARDWARE,volume -->
|
||||
<item>herring,0.5</item>
|
||||
<item>tuna,0.5</item>
|
||||
<item>stingray,0.4</item>
|
||||
<item>grouper,0.3</item>
|
||||
<item>mako,0.3</item>
|
||||
<item>manta,0.2</item>
|
||||
<item>herring,0.5f</item>
|
||||
<item>tuna,0.5f</item>
|
||||
<item>stingray,0.4f</item>
|
||||
<item>grouper,0.3f</item>
|
||||
<item>mako,0.3f</item>
|
||||
<item>manta,0.2f</item>
|
||||
<!-- Default value for unknown device -->
|
||||
<item>DEFAULT,0.2f</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -21,6 +21,9 @@
|
||||
<string-array name="phantom_sudden_move_event_device_list" translatable="false">
|
||||
<!-- "Build.HARDWARE,true" that needs "phantom sudden move event" hack.
|
||||
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>
|
||||
</resources>
|
||||
|
@ -21,7 +21,11 @@
|
||||
<string-array name="sudden_jumping_touch_event_device_list" translatable="false">
|
||||
<!-- "Build.HARDWARE,true" that needs "sudden jump touch event" hack.
|
||||
See {@link com.android.inputmethod.keyboard.SuddenJumpingTouchEventHandler}. -->
|
||||
<item>mahimahi,true</item> <!-- Nexus One -->
|
||||
<item>sholes,true</item> <!-- Droid -->
|
||||
<!-- Nexus One -->
|
||||
<item>mahimahi,true</item>
|
||||
<!-- Droid -->
|
||||
<item>sholes,true</item>
|
||||
<!-- Default value for unknown device -->
|
||||
<item>DEFAULT,false</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -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(
|
||||
|
@ -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<KP extends KeyboardParams> {
|
||||
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);
|
||||
|
@ -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) {
|
||||
|
@ -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<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user