Loading core/java/android/content/res/Resources.java +14 −26 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.AttrRes; import android.annotation.ColorInt; import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.icu.text.PluralRules; import com.android.internal.util.GrowingArrayUtils; import com.android.internal.util.XmlUtils; Loading Loading @@ -68,8 +69,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 Loading Loading @@ -154,7 +153,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; Loading Loading @@ -335,9 +334,9 @@ public class Resources { */ public CharSequence getQuantityText(@PluralsRes 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; } Loading @@ -347,40 +346,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. Loading Loading @@ -2059,7 +2047,7 @@ public class Resources { } synchronized (sSync) { if (mPluralRule != null) { mPluralRule = NativePluralRules.forLocale(config.locale); mPluralRule = PluralRules.forLocale(config.locale); } } } Loading Loading
core/java/android/content/res/Resources.java +14 −26 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.AttrRes; import android.annotation.ColorInt; import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.icu.text.PluralRules; import com.android.internal.util.GrowingArrayUtils; import com.android.internal.util.XmlUtils; Loading Loading @@ -68,8 +69,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 Loading Loading @@ -154,7 +153,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; Loading Loading @@ -335,9 +334,9 @@ public class Resources { */ public CharSequence getQuantityText(@PluralsRes 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; } Loading @@ -347,40 +346,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. Loading Loading @@ -2059,7 +2047,7 @@ public class Resources { } synchronized (sSync) { if (mPluralRule != null) { mPluralRule = NativePluralRules.forLocale(config.locale); mPluralRule = PluralRules.forLocale(config.locale); } } } Loading