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