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