Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/base/ResourceBundle.java |
| diff --git a/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java b/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java |
| index adbf8afac277330364f11daeafffa525c5224d7e..c181affe757eec234ee2f5341aab5938ae7e820f 100644 |
| --- a/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java |
| +++ b/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java |
| @@ -5,9 +5,8 @@ |
| package org.chromium.ui.base; |
| import android.content.Context; |
| -import android.content.res.Resources; |
| -import android.content.res.TypedArray; |
| +import org.chromium.base.LocalePakFiles; |
| import org.chromium.base.ResourceExtractor; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.annotations.CalledByNative; |
| @@ -23,49 +22,27 @@ import java.util.Locale; |
| */ |
| @JNINamespace("ui") |
| public class ResourceBundle { |
| - private static ResourceExtractor.ResourceEntry[] sActiveLocaleResources; |
| - /** |
| - * Applies the reverse mapping done by locale_pak_resources.py. |
| - */ |
| - private static String toChromeLocaleName(String srcFileName) { |
| - srcFileName = srcFileName.replace(".lpak", ".pak"); |
| - String[] parts = srcFileName.split("_"); |
| - if (parts.length > 1) { |
| - int dotIdx = parts[1].indexOf('.'); |
| - return parts[0] + "-" + parts[1].substring(0, dotIdx).toUpperCase(Locale.ENGLISH) |
| - + parts[1].substring(dotIdx); |
| - } |
| - return srcFileName; |
| - } |
| + private static ResourceExtractor.ResourceEntry[] sActiveLocaleResources; |
| /** |
| - * Initializes the list of locale packs for the active locale that are |
| - * present within the apk. |
| + * Initializes the list of locale packs for the active locale that are present within the apk. |
| * |
| * @param context Any context |
| - * @param localePaksResId Resource ID locale_paks (generated by |
| - * locale_pak_resources.py) |
| + * @param localePakFiles LocalePakFiles relevant to caller |
| */ |
| @SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC") // Not thread-safe. |
| - public static void initializeLocalePaks(Context context, int localePaksResId) { |
| + public static void initializeLocalePaks(Context context, LocalePakFiles localePakFiles) { |
| ThreadUtils.assertOnUiThread(); |
| assert sActiveLocaleResources == null; |
| - Resources resources = context.getResources(); |
| - TypedArray resIds = resources.obtainTypedArray(localePaksResId); |
| - try { |
| - int len = resIds.length(); |
| - sActiveLocaleResources = new ResourceExtractor.ResourceEntry[len]; |
| - for (int i = 0; i < len; ++i) { |
| - int resId = resIds.getResourceId(i, 0); |
| - String resPath = resources.getString(resId); |
| - String srcBaseName = new File(resPath).getName(); |
| - String dstBaseName = toChromeLocaleName(srcBaseName); |
| - sActiveLocaleResources[i] = new ResourceExtractor.ResourceEntry(resId, resPath, |
| - dstBaseName); |
| - } |
| - } finally { |
| - resIds.recycle(); |
| + String[] pakFiles = localePakFiles.getPakFilesForLocale(Locale.getDefault().getLanguage()); |
|
agrieve
2016/09/21 01:06:42
I think this could be simplified quite a bit if we
estevenson
2016/09/21 19:50:56
Done.
|
| + int len = pakFiles.length; |
| + sActiveLocaleResources = new ResourceExtractor.ResourceEntry[len]; |
| + for (int i = 0; i < len; ++i) { |
| + String assetPath = pakFiles[i]; |
| + String fileName = new File(assetPath).getName(); |
| + sActiveLocaleResources[i] = new ResourceExtractor.ResourceEntry(fileName, |
| + assetPath); |
| } |
| } |
| @@ -81,7 +58,7 @@ public class ResourceBundle { |
| } |
| String fileName = locale + ".pak"; |
| for (ResourceExtractor.ResourceEntry entry : sActiveLocaleResources) { |
| - if (fileName.equals(entry.extractedFileName)) { |
| + if (fileName.equals(entry.fileName)) { |
| return entry.pathWithinApk; |
| } |
| } |