Refactor to memorize device dependent override parameters

Change-Id: I79482a8ef3846525669979a30dec183ea18138b5
main
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> <resources>
<string-array name="sudden_jumping_touch_event_device_list" translatable="false"> <string-array name="sudden_jumping_touch_event_device_list" translatable="false">
<!-- Nexus One --> <!-- "Build.HARDWARE,true" that needs "sudden jump touch event" hack.
<item>mahimahi</item> See {@link com.android.inputmethod.keyboard.SuddenJumpingTouchEventHandler}. -->
<!-- Droid --> <item>mahimahi,true</item> <!-- Nexus One -->
<item>sholes</item> <item>sholes,true</item> <!-- Droid -->
</string-array> </string-array>
</resources> </resources>

View File

@ -17,12 +17,12 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
public class SuddenJumpingTouchEventHandler { public class SuddenJumpingTouchEventHandler {
private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName(); private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName();
@ -49,18 +49,8 @@ public class SuddenJumpingTouchEventHandler {
public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) {
mView = view; mView = view;
final String[] deviceList = context.getResources().getStringArray( mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue(
R.array.sudden_jumping_touch_event_device_list); context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false"));
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;
} }
public void setKeyboard(Keyboard newKeyboard) { public void setKeyboard(Keyboard newKeyboard) {

View File

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

View File

@ -19,9 +19,11 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
@ -43,6 +45,7 @@ import java.io.PrintWriter;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
public class Utils { public class Utils {
private Utils() { private Utils() {
@ -465,4 +468,23 @@ public class Utils {
if (TextUtils.isEmpty(info)) return null; if (TextUtils.isEmpty(info)) return null;
return info; 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);
}
} }