mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Refactor KeyboardTextsSet class"
This commit is contained in:
commit
0c268b08b6
@ -43,18 +43,19 @@ public final class KeyboardTextsSet {
|
|||||||
mTextsTable = KeyboardTextsTable.getTextsTable(language);
|
mTextsTable = KeyboardTextsTable.getTextsTable(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Consolidate this method with {@link #setLocale(Locale)}.
|
||||||
public void loadStringResources(final Context context) {
|
public void loadStringResources(final Context context) {
|
||||||
|
final Resources res = context.getResources();
|
||||||
final int referenceId = context.getApplicationInfo().labelRes;
|
final int referenceId = context.getApplicationInfo().labelRes;
|
||||||
loadStringResourcesInternal(context, RESOURCE_NAMES, referenceId);
|
final String resourcePackageName = res.getResourcePackageName(referenceId);
|
||||||
|
loadStringResourcesInternal(res, RESOURCE_NAMES, resourcePackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
void loadStringResourcesInternal(final Context context, final String[] resourceNames,
|
void loadStringResourcesInternal(final Resources res, final String[] resourceNames,
|
||||||
final int referenceId) {
|
final String resourcePackageName) {
|
||||||
final Resources res = context.getResources();
|
|
||||||
final String packageName = res.getResourcePackageName(referenceId);
|
|
||||||
for (final String resName : resourceNames) {
|
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));
|
mResourceNameToTextsMap.put(resName, res.getString(resId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,6 +78,7 @@ public final class KeyboardTextsSet {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Resolve text reference when creating {@link KeyboardTextsTable} class.
|
||||||
public String resolveTextReference(final String rawText) {
|
public String resolveTextReference(final String rawText) {
|
||||||
if (TextUtils.isEmpty(rawText)) {
|
if (TextUtils.isEmpty(rawText)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -51,10 +51,13 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase {
|
|||||||
}.runInLocale(targetContext.getResources(), TEST_LOCALE);
|
}.runInLocale(targetContext.getResources(), TEST_LOCALE);
|
||||||
final String[] testResourceNames = getAllResourceIdNames(
|
final String[] testResourceNames = getAllResourceIdNames(
|
||||||
com.android.inputmethod.latin.tests.R.string.class);
|
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
|
// This dummy raw resource is needed to be able to load string resources from a test
|
||||||
// APK successfully.
|
// APK successfully.
|
||||||
com.android.inputmethod.latin.tests.R.raw.dummy_resource_for_testing);
|
com.android.inputmethod.latin.tests.R.raw.dummy_resource_for_testing);
|
||||||
|
mTextsSet.loadStringResourcesInternal(testRes, testResourceNames, testResPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) {
|
private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user