ICU_Delegate.java revision 39e75835399f4d979cf82069dae2bd1ec496fb81
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package libcore.icu;
18
19import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20import com.ibm.icu.text.DateTimePatternGenerator;
21import com.ibm.icu.util.ULocale;
22
23import java.util.Locale;
24
25/**
26 * Delegate implementing the native methods of libcore.icu.ICU
27 *
28 * Through the layoutlib_create tool, the original native methods of ICU have been replaced
29 * by calls to methods of the same name in this delegate class.
30 *
31 */
32public class ICU_Delegate {
33
34    // --- Java delegates
35
36    @LayoutlibDelegate
37    /*package*/ static String toLowerCase(String s, String localeName) {
38        return s.toLowerCase();
39    }
40
41    @LayoutlibDelegate
42    /*package*/ static String toUpperCase(String s, String localeName) {
43        return s.toUpperCase();
44    }
45
46    // --- Native methods accessing ICU's database.
47
48    @LayoutlibDelegate
49    /*package*/ static String getBestDateTimePattern(String skeleton, String localeName) {
50        return DateTimePatternGenerator.getInstance(new ULocale(localeName))
51                .getBestPattern(skeleton);
52    }
53
54    @LayoutlibDelegate
55    /*package*/ static String getCldrVersion() {
56        return "22.1.1";      // TODO: check what the right value should be.
57    }
58
59    @LayoutlibDelegate
60    /*package*/ static String getIcuVersion() {
61        return "unknown_layoutlib";
62    }
63
64    @LayoutlibDelegate
65    /*package*/ static String getUnicodeVersion() {
66        return "5.2";
67    }
68
69    @LayoutlibDelegate
70    /*package*/ static String[] getAvailableBreakIteratorLocalesNative() {
71        return new String[0];
72    }
73
74    @LayoutlibDelegate
75    /*package*/ static String[] getAvailableCalendarLocalesNative() {
76        return new String[0];
77    }
78
79    @LayoutlibDelegate
80    /*package*/ static String[] getAvailableCollatorLocalesNative() {
81        return new String[0];
82    }
83
84    @LayoutlibDelegate
85    /*package*/ static String[] getAvailableDateFormatLocalesNative() {
86        return new String[0];
87    }
88
89    @LayoutlibDelegate
90    /*package*/ static String[] getAvailableLocalesNative() {
91        return new String[0];
92    }
93
94    @LayoutlibDelegate
95    /*package*/ static String[] getAvailableNumberFormatLocalesNative() {
96        return new String[0];
97    }
98
99    @LayoutlibDelegate
100    /*package*/ static String[] getAvailableCurrencyCodes() {
101        return new String[0];
102    }
103
104    @LayoutlibDelegate
105    /*package*/ static String getCurrencyCode(String locale) {
106        return "";
107    }
108
109    @LayoutlibDelegate
110    /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) {
111        return "";
112    }
113
114    @LayoutlibDelegate
115    /*package*/ static int getCurrencyFractionDigits(String currencyCode) {
116        return 0;
117    }
118
119    @LayoutlibDelegate
120    /*package*/ static String getCurrencySymbol(String locale, String currencyCode) {
121        return "";
122    }
123
124    @LayoutlibDelegate
125    /*package*/ static String getDisplayCountryNative(String countryCode, String locale) {
126        return "";
127    }
128
129    @LayoutlibDelegate
130    /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) {
131        return "";
132    }
133
134    @LayoutlibDelegate
135    /*package*/ static String getDisplayVariantNative(String variantCode, String locale) {
136        return "";
137    }
138
139    @LayoutlibDelegate
140    /*package*/ static String getISO3CountryNative(String locale) {
141        return "";
142    }
143
144    @LayoutlibDelegate
145    /*package*/ static String getISO3LanguageNative(String locale) {
146        return "";
147    }
148
149    @LayoutlibDelegate
150    /*package*/ static String addLikelySubtags(String locale) {
151        return "";
152    }
153
154    @LayoutlibDelegate
155    /*package*/ static String getScript(String locale) {
156        return "";
157    }
158
159    @LayoutlibDelegate
160    /*package*/ static String[] getISOLanguagesNative() {
161        return Locale.getISOLanguages();
162    }
163
164    @LayoutlibDelegate
165    /*package*/ static String[] getISOCountriesNative() {
166        return Locale.getISOCountries();
167    }
168
169    @LayoutlibDelegate
170    /*package*/ static boolean initLocaleDataImpl(String locale, LocaleData result) {
171
172        // Used by Calendar.
173        result.firstDayOfWeek = Integer.valueOf(1);
174        result.minimalDaysInFirstWeek = Integer.valueOf(1);
175
176        // Used by DateFormatSymbols.
177        result.amPm = new String[] { "AM", "PM" };
178        result.eras = new String[] { "BC", "AD" };
179
180        result.longMonthNames = new String[] { "January", "February", "March", "April", "May",
181                "June", "July", "August", "September", "October", "November", "December" };
182        result.shortMonthNames = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
183                "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
184        result.longStandAloneMonthNames = result.longMonthNames;
185        result.shortStandAloneMonthNames = result.shortMonthNames;
186
187        result.longWeekdayNames = new String[] {
188                "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
189        result.shortWeekdayNames = new String[] {
190                "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
191        result.longStandAloneWeekdayNames = result.longWeekdayNames;
192        result.shortStandAloneWeekdayNames = result.shortWeekdayNames;
193
194        result.fullTimeFormat = "";
195        result.longTimeFormat = "";
196        result.mediumTimeFormat = "";
197        result.shortTimeFormat = "";
198
199        result.fullDateFormat = "";
200        result.longDateFormat = "";
201        result.mediumDateFormat = "";
202        result.shortDateFormat = "";
203
204        // Used by DecimalFormatSymbols.
205        result.zeroDigit = '0';
206        result.decimalSeparator = '.';
207        result.groupingSeparator = ',';
208        result.patternSeparator = ' ';
209        result.percent = '%';
210        result.perMill = '\u2030';
211        result.monetarySeparator = ' ';
212        result.minusSign = '-';
213        result.exponentSeparator = "e";
214        result.infinity = "\u221E";
215        result.NaN = "NaN";
216        // Also used by Currency.
217        result.currencySymbol = "$";
218        result.internationalCurrencySymbol = "USD";
219
220        // Used by DecimalFormat and NumberFormat.
221        result.numberPattern = "%f";
222        result.integerPattern = "%d";
223        result.currencyPattern = "%s";
224        result.percentPattern = "%f";
225
226        return true;
227    }
228}
229