diff options
| author | 2015-07-17 10:22:19 +0000 | |
|---|---|---|
| committer | 2015-07-17 10:22:19 +0000 | |
| commit | 71165ea6404da5282db8459f9f20e374f4c07cdc (patch) | |
| tree | a3ad0f7756ad3cc60ebfa65586c6e97d6492c0ef | |
| parent | d96243a1d7b2ce660b256694cd465b240e7413f1 (diff) | |
| parent | 7ce3847d753688c5339216dd174c094e2996fdf9 (diff) | |
am 7ce3847d: Merge "Migrate Resources.java to use ICU4j drectly."
* commit '7ce3847d753688c5339216dd174c094e2996fdf9':
Migrate Resources.java to use ICU4j drectly.
| -rw-r--r-- | core/java/android/content/res/Resources.java | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 73913b6c1762..71b365d2ccf3 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -19,6 +19,7 @@ package android.content.res; import android.animation.Animator; import android.animation.StateListAnimator; import android.annotation.NonNull; +import android.icu.text.PluralRules; import android.util.Pools.SynchronizedPool; import android.view.ViewDebug; import com.android.internal.util.XmlUtils; @@ -49,8 +50,6 @@ import java.io.InputStream; import java.lang.ref.WeakReference; import java.util.Locale; -import libcore.icu.NativePluralRules; - /** * Class for accessing an application's resources. This sits on top of the * asset manager of the application (accessible through {@link #getAssets}) and @@ -136,7 +135,7 @@ public class Resources { final DisplayMetrics mMetrics = new DisplayMetrics(); private final Configuration mConfiguration = new Configuration(); - private NativePluralRules mPluralRule; + private PluralRules mPluralRule; private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; @@ -321,9 +320,9 @@ public class Resources { * possibly styled text information. */ public CharSequence getQuantityText(int id, int quantity) throws NotFoundException { - NativePluralRules rule = getPluralRule(); + PluralRules rule = getPluralRule(); CharSequence res = mAssets.getResourceBagText(id, - attrForQuantityCode(rule.quantityForInt(quantity))); + attrForQuantityCode(rule.select(quantity))); if (res != null) { return res; } @@ -333,40 +332,29 @@ public class Resources { } throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id) + " quantity=" + quantity - + " item=" + stringForQuantityCode(rule.quantityForInt(quantity))); + + " item=" + rule.select(quantity)); } - private NativePluralRules getPluralRule() { + private PluralRules getPluralRule() { synchronized (sSync) { if (mPluralRule == null) { - mPluralRule = NativePluralRules.forLocale(mConfiguration.locale); + mPluralRule = PluralRules.forLocale(mConfiguration.locale); } return mPluralRule; } } - private static int attrForQuantityCode(int quantityCode) { + private static int attrForQuantityCode(String quantityCode) { switch (quantityCode) { - case NativePluralRules.ZERO: return 0x01000005; - case NativePluralRules.ONE: return 0x01000006; - case NativePluralRules.TWO: return 0x01000007; - case NativePluralRules.FEW: return 0x01000008; - case NativePluralRules.MANY: return 0x01000009; + case PluralRules.KEYWORD_ZERO: return 0x01000005; + case PluralRules.KEYWORD_ONE: return 0x01000006; + case PluralRules.KEYWORD_TWO: return 0x01000007; + case PluralRules.KEYWORD_FEW: return 0x01000008; + case PluralRules.KEYWORD_MANY: return 0x01000009; default: return ID_OTHER; } } - private static String stringForQuantityCode(int quantityCode) { - switch (quantityCode) { - case NativePluralRules.ZERO: return "zero"; - case NativePluralRules.ONE: return "one"; - case NativePluralRules.TWO: return "two"; - case NativePluralRules.FEW: return "few"; - case NativePluralRules.MANY: return "many"; - default: return "other"; - } - } - /** * Return the string value associated with a particular resource ID. It * will be stripped of any styled text information. @@ -1852,7 +1840,7 @@ public class Resources { } synchronized (sSync) { if (mPluralRule != null) { - mPluralRule = NativePluralRules.forLocale(config.locale); + mPluralRule = PluralRules.forLocale(config.locale); } } } |