am 5eb8e985: am 9879f656: Add ResourceUtils

* commit '5eb8e98542deb0d4ea15dcd336744d23757726e5':
  Add ResourceUtils
main
Tadashi G. Takaoka 2012-08-29 00:52:20 -07:00 committed by Android Git Automerger
commit 283f33eba9
6 changed files with 58 additions and 30 deletions

View File

@ -37,8 +37,8 @@ import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils; import com.android.inputmethod.latin.XmlParseUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -746,7 +746,7 @@ public class Keyboard {
R.styleable.Keyboard_Key); R.styleable.Keyboard_Key);
try { try {
final int displayHeight = mDisplayMetrics.heightPixels; final int displayHeight = mDisplayMetrics.heightPixels;
final String keyboardHeightString = Utils.getDeviceOverrideValue( final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
mResources, R.array.keyboard_heights, null); mResources, R.array.keyboard_heights, null);
final float keyboardHeight; final float keyboardHeight;
if (keyboardHeightString != null) { if (keyboardHeightString != null) {

View File

@ -48,10 +48,10 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
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.ResourceUtils;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger; import com.android.inputmethod.research.ResearchLogger;
@ -334,7 +334,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
final Resources res = getResources(); final Resources res = getResources();
final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
Utils.getDeviceOverrideValue(res, ResourceUtils.getDeviceOverrideValue(res,
R.array.phantom_sudden_move_event_device_list, "false")); R.array.phantom_sudden_move_event_device_list, "false"));
PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack); PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack);

View File

@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
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; import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger; import com.android.inputmethod.research.ResearchLogger;
@ -53,7 +53,7 @@ public class SuddenJumpingTouchEventHandler {
public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) {
mView = view; mView = view;
mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue( 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, "false"));
} }

View 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);
}
}

View File

@ -375,8 +375,8 @@ public class SettingsValues {
return volume; return volume;
} }
return Float.parseFloat( return Float.parseFloat(ResourceUtils.getDeviceOverrideValue(
Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f")); res, R.array.keypress_volumes, "-1.0f"));
} }
// Likewise // Likewise
@ -388,8 +388,8 @@ public class SettingsValues {
return ms; return ms;
} }
return Integer.parseInt( return Integer.parseInt(ResourceUtils.getDeviceOverrideValue(
Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1")); res, R.array.keypress_vibration_durations, "-1"));
} }
// Likewise // Likewise

View File

@ -426,24 +426,4 @@ 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<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);
}
} }