am 0c268b08: Merge "Refactor KeyboardTextsSet class"

* commit '0c268b08b69e9f4f730dc145bb86522ca2964a52':
  Refactor KeyboardTextsSet class
main
Tadashi G. Takaoka 2014-03-20 02:56:05 -07:00 committed by Android Git Automerger
commit 600a730004
2 changed files with 12 additions and 7 deletions

View File

@ -43,18 +43,19 @@ public final class KeyboardTextsSet {
mTextsTable = KeyboardTextsTable.getTextsTable(language);
}
// TODO: Consolidate this method with {@link #setLocale(Locale)}.
public void loadStringResources(final Context context) {
final Resources res = context.getResources();
final int referenceId = context.getApplicationInfo().labelRes;
loadStringResourcesInternal(context, RESOURCE_NAMES, referenceId);
final String resourcePackageName = res.getResourcePackageName(referenceId);
loadStringResourcesInternal(res, RESOURCE_NAMES, resourcePackageName);
}
@UsedForTesting
void loadStringResourcesInternal(final Context context, final String[] resourceNames,
final int referenceId) {
final Resources res = context.getResources();
final String packageName = res.getResourcePackageName(referenceId);
void loadStringResourcesInternal(final Resources res, final String[] resourceNames,
final String resourcePackageName) {
for (final String resName : resourceNames) {
final int resId = res.getIdentifier(resName, "string", packageName);
final int resId = res.getIdentifier(resName, "string", resourcePackageName);
mResourceNameToTextsMap.put(resName, res.getString(resId));
}
}
@ -77,6 +78,7 @@ public final class KeyboardTextsSet {
return size;
}
// TODO: Resolve text reference when creating {@link KeyboardTextsTable} class.
public String resolveTextReference(final String rawText) {
if (TextUtils.isEmpty(rawText)) {
return null;

View File

@ -51,10 +51,13 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase {
}.runInLocale(targetContext.getResources(), TEST_LOCALE);
final String[] testResourceNames = getAllResourceIdNames(
com.android.inputmethod.latin.tests.R.string.class);
mTextsSet.loadStringResourcesInternal(instrumentation.getContext(), testResourceNames,
final Context testContext = instrumentation.getContext();
final Resources testRes = testContext.getResources();
final String testResPackageName = testRes.getResourcePackageName(
// This dummy raw resource is needed to be able to load string resources from a test
// APK successfully.
com.android.inputmethod.latin.tests.R.raw.dummy_resource_for_testing);
mTextsSet.loadStringResourcesInternal(testRes, testResourceNames, testResPackageName);
}
private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) {