Add ResourceUtils
Change-Id: Ia198f8d95eae8c007623cd52d73cc1528d22fee9
This commit is contained in:
parent
95c486cdf3
commit
9879f65651
6 changed files with 58 additions and 30 deletions
|
@ -37,8 +37,8 @@ import com.android.inputmethod.latin.CollectionUtils;
|
|||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.ResourceUtils;
|
||||
import com.android.inputmethod.latin.SubtypeLocale;
|
||||
import com.android.inputmethod.latin.Utils;
|
||||
import com.android.inputmethod.latin.XmlParseUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -746,7 +746,7 @@ public class Keyboard {
|
|||
R.styleable.Keyboard_Key);
|
||||
try {
|
||||
final int displayHeight = mDisplayMetrics.heightPixels;
|
||||
final String keyboardHeightString = Utils.getDeviceOverrideValue(
|
||||
final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
|
||||
mResources, R.array.keyboard_heights, null);
|
||||
final float keyboardHeight;
|
||||
if (keyboardHeightString != null) {
|
||||
|
|
|
@ -48,10 +48,10 @@ import com.android.inputmethod.latin.Constants;
|
|||
import com.android.inputmethod.latin.LatinIME;
|
||||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.ResourceUtils;
|
||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||
import com.android.inputmethod.latin.StringUtils;
|
||||
import com.android.inputmethod.latin.SubtypeLocale;
|
||||
import com.android.inputmethod.latin.Utils;
|
||||
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
import com.android.inputmethod.research.ResearchLogger;
|
||||
|
@ -334,7 +334,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
|
|||
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
|
||||
final Resources res = getResources();
|
||||
final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
|
||||
Utils.getDeviceOverrideValue(res,
|
||||
ResourceUtils.getDeviceOverrideValue(res,
|
||||
R.array.phantom_sudden_move_event_device_list, "false"));
|
||||
PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.Keyboard;
|
|||
import com.android.inputmethod.keyboard.MainKeyboardView;
|
||||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.Utils;
|
||||
import com.android.inputmethod.latin.ResourceUtils;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
import com.android.inputmethod.research.ResearchLogger;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class SuddenJumpingTouchEventHandler {
|
|||
|
||||
public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) {
|
||||
mView = view;
|
||||
mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue(
|
||||
mNeedsSuddenJumpingHack = Boolean.parseBoolean(ResourceUtils.getDeviceOverrideValue(
|
||||
context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false"));
|
||||
}
|
||||
|
||||
|
|
48
java/src/com/android/inputmethod/latin/ResourceUtils.java
Normal file
48
java/src/com/android/inputmethod/latin/ResourceUtils.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ResourceUtils {
|
||||
private ResourceUtils() {
|
||||
// This utility class is not publicly instantiable.
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
sDeviceOverrideValueMap.put(key, overrideValue);
|
||||
}
|
||||
return sDeviceOverrideValueMap.get(key);
|
||||
}
|
||||
}
|
|
@ -375,8 +375,8 @@ public class SettingsValues {
|
|||
return volume;
|
||||
}
|
||||
|
||||
return Float.parseFloat(
|
||||
Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f"));
|
||||
return Float.parseFloat(ResourceUtils.getDeviceOverrideValue(
|
||||
res, R.array.keypress_volumes, "-1.0f"));
|
||||
}
|
||||
|
||||
// Likewise
|
||||
|
@ -388,8 +388,8 @@ public class SettingsValues {
|
|||
return ms;
|
||||
}
|
||||
|
||||
return Integer.parseInt(
|
||||
Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1"));
|
||||
return Integer.parseInt(ResourceUtils.getDeviceOverrideValue(
|
||||
res, R.array.keypress_vibration_durations, "-1"));
|
||||
}
|
||||
|
||||
// Likewise
|
||||
|
|
|
@ -426,24 +426,4 @@ public class Utils {
|
|||
if (TextUtils.isEmpty(info)) return null;
|
||||
return info;
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
sDeviceOverrideValueMap.put(key, overrideValue);
|
||||
}
|
||||
return sDeviceOverrideValueMap.get(key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue