2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.content.res;
19 import java.util.Locale;
22 * Yuck-o. This is not the right way to implement this. When the ICU PluralRules
23 * object has been integrated to android, we should switch to that. For now, yuck-o.
26 abstract class PluralRules {
28 static final int QUANTITY_OTHER = 0x0000;
29 static final int QUANTITY_ZERO = 0x0001;
30 static final int QUANTITY_ONE = 0x0002;
31 static final int QUANTITY_TWO = 0x0004;
32 static final int QUANTITY_FEW = 0x0008;
33 static final int QUANTITY_MANY = 0x0010;
35 static final int ID_OTHER = 0x01000004;
37 abstract int quantityForNumber(int n);
39 final int attrForNumber(int n) {
40 return PluralRules.attrForQuantity(quantityForNumber(n));
43 static final int attrForQuantity(int quantity) {
44 // see include/utils/ResourceTypes.h
46 case QUANTITY_ZERO: return 0x01000005;
47 case QUANTITY_ONE: return 0x01000006;
48 case QUANTITY_TWO: return 0x01000007;
49 case QUANTITY_FEW: return 0x01000008;
50 case QUANTITY_MANY: return 0x01000009;
51 default: return ID_OTHER;
55 static final String stringForQuantity(int quantity) {
72 static final PluralRules ruleForLocale(Locale locale) {
73 String lang = locale.getLanguage();
74 if ("cs".equals(lang)) {
75 if (cs == null) cs = new cs();
79 if (en == null) en = new en();
84 private static PluralRules cs;
85 private static class cs extends PluralRules {
86 int quantityForNumber(int n) {
90 else if (n >= 2 && n <= 4) {
94 return QUANTITY_OTHER;
99 private static PluralRules en;
100 private static class en extends PluralRules {
101 int quantityForNumber(int n) {
106 return QUANTITY_OTHER;