Refactor to memorize device dependent override parameters

Change-Id: I79482a8ef3846525669979a30dec183ea18138b5
This commit is contained in:
Tadashi G. Takaoka 2012-03-21 15:33:55 +09:00
parent 1fe943aabd
commit 624f1bab39
4 changed files with 34 additions and 35 deletions

View file

@ -19,9 +19,9 @@
-->
<resources>
<string-array name="sudden_jumping_touch_event_device_list" translatable="false">
<!-- Nexus One -->
<item>mahimahi</item>
<!-- Droid -->
<item>sholes</item>
<!-- "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 -->
</string-array>
</resources>

View file

@ -17,12 +17,12 @@
package com.android.inputmethod.keyboard;
import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.MotionEvent;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
public class SuddenJumpingTouchEventHandler {
private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName();
@ -49,18 +49,8 @@ public class SuddenJumpingTouchEventHandler {
public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) {
mView = view;
final String[] deviceList = context.getResources().getStringArray(
R.array.sudden_jumping_touch_event_device_list);
mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.HARDWARE, deviceList);
}
private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) {
for (String device : deviceList) {
if (device.equalsIgnoreCase(deviceName)) {
return true;
}
}
return false;
mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue(
context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false"));
}
public void setKeyboard(Keyboard newKeyboard) {

View file

@ -19,7 +19,6 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
@ -322,14 +321,8 @@ public class SettingsValues {
return volume;
}
final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes);
final String hardwarePrefix = Build.HARDWARE + ",";
for (final String element : volumePerHardwareList) {
if (element.startsWith(hardwarePrefix)) {
return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
}
}
return -1.0f;
return Float.parseFloat(
Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f"));
}
// Likewise
@ -340,15 +333,9 @@ public class SettingsValues {
if (ms >= 0) {
return ms;
}
final String[] durationPerHardwareList = res.getStringArray(
R.array.keypress_vibration_durations);
final String hardwarePrefix = Build.HARDWARE + ",";
for (final String element : durationPerHardwareList) {
if (element.startsWith(hardwarePrefix)) {
return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1));
}
}
return -1;
return Integer.parseInt(
Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1"));
}
// Likewise

View file

@ -19,9 +19,11 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
@ -43,6 +45,7 @@ import java.io.PrintWriter;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
public class Utils {
private Utils() {
@ -465,4 +468,23 @@ public class Utils {
if (TextUtils.isEmpty(info)) return null;
return info;
}
private static final String HARDWARE_PREFIX = Build.HARDWARE + ",";
private static final HashMap<Integer, String> sDeviceOverrideValueMap =
new HashMap<Integer, String>();
public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) {
final Integer key = overrideResId;
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;
}
}
sDeviceOverrideValueMap.put(key, overrideValue);
}
return sDeviceOverrideValueMap.get(key);
}
}