blob: 9c5801080e17e716f6e149aa05d33660ac1af17d [file] [log] [blame]
Xavier Ducrohet345f8662011-02-02 11:50:34 -08001/*
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
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080019import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
Deepanshu Guptad77b9ed2015-05-12 12:01:16 -070020
21import android.icu.text.DateTimePatternGenerator;
22import android.icu.util.Currency;
23import android.icu.util.ULocale;
Deepanshu Guptaeca05692015-05-13 14:58:15 -070024import android.icu.util.VersionInfo;
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080025
Xavier Ducrohet345f8662011-02-02 11:50:34 -080026import 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
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080037 // --- Java delegates
38
39 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080040 /*package*/ static String toLowerCase(String s, String localeName) {
41 return s.toLowerCase();
42 }
43
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080044 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080045 /*package*/ static String toUpperCase(String s, String localeName) {
46 return s.toUpperCase();
47 }
48
49 // --- Native methods accessing ICU's database.
50
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080051 @LayoutlibDelegate
Deepanshu Gupta0d7ebc52014-03-05 19:23:48 -080052 /*package*/ static String getBestDateTimePatternNative(String skeleton, String localeName) {
Deepanshu Gupta39e75832013-10-16 20:27:51 -070053 return DateTimePatternGenerator.getInstance(new ULocale(localeName))
54 .getBestPattern(skeleton);
Deepanshu Gupta279c00e2013-05-23 15:20:04 -070055 }
56
57 @LayoutlibDelegate
Deepanshu Guptaeca05692015-05-13 14:58:15 -070058 @SuppressWarnings("deprecation")
Deepanshu Gupta279c00e2013-05-23 15:20:04 -070059 /*package*/ static String getCldrVersion() {
Deepanshu Guptaeca05692015-05-13 14:58:15 -070060 return VersionInfo.ICU_DATA_VERSION.toString();
Deepanshu Gupta279c00e2013-05-23 15:20:04 -070061 }
62
63 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -070064 /*package*/ static String getIcuVersion() {
Deepanshu Guptaeca05692015-05-13 14:58:15 -070065 return VersionInfo.ICU_VERSION.toString();
Xavier Ducrohet66743a12011-06-15 14:43:42 -070066 }
67
68 @LayoutlibDelegate
69 /*package*/ static String getUnicodeVersion() {
Deepanshu Guptaeca05692015-05-13 14:58:15 -070070 return VersionInfo.UNICODE_7_0.toString();
Xavier Ducrohet66743a12011-06-15 14:43:42 -070071 }
72
73 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080074 /*package*/ static String[] getAvailableBreakIteratorLocalesNative() {
75 return new String[0];
76 }
77
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080078 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080079 /*package*/ static String[] getAvailableCalendarLocalesNative() {
80 return new String[0];
81 }
82
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080083 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080084 /*package*/ static String[] getAvailableCollatorLocalesNative() {
85 return new String[0];
86 }
87
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080088 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080089 /*package*/ static String[] getAvailableDateFormatLocalesNative() {
90 return new String[0];
91 }
92
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080093 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080094 /*package*/ static String[] getAvailableLocalesNative() {
95 return new String[0];
96 }
97
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080098 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080099 /*package*/ static String[] getAvailableNumberFormatLocalesNative() {
100 return new String[0];
101 }
102
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800103 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700104 /*package*/ static String[] getAvailableCurrencyCodes() {
105 return new String[0];
106 }
107
108 @LayoutlibDelegate
109 /*package*/ static String getCurrencyCode(String locale) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800110 return "";
111 }
112
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800113 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700114 /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) {
115 return "";
116 }
117
118 @LayoutlibDelegate
119 /*package*/ static int getCurrencyFractionDigits(String currencyCode) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800120 return 0;
121 }
122
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800123 @LayoutlibDelegate
Deepanshu Gupta103d4092014-03-14 13:24:56 -0700124 /*package*/ static int getCurrencyNumericCode(String currencyCode) {
125 return Currency.getInstance(currencyCode).getNumericCode();
126 }
127
128 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700129 /*package*/ static String getCurrencySymbol(String locale, String currencyCode) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800130 return "";
131 }
132
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800133 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800134 /*package*/ static String getDisplayCountryNative(String countryCode, String locale) {
135 return "";
136 }
137
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800138 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800139 /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) {
140 return "";
141 }
142
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800143 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800144 /*package*/ static String getDisplayVariantNative(String variantCode, String locale) {
145 return "";
146 }
147
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800148 @LayoutlibDelegate
Deepanshu Gupta0d7ebc52014-03-05 19:23:48 -0800149 /*package*/ static String getDisplayScriptNative(String variantCode, String locale) {
150 return "";
151 }
152
153 @LayoutlibDelegate
Deepanshu Guptabb5d0cc2014-06-25 16:57:03 -0700154 /*package*/ static String getISO3Country(String locale) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800155 return "";
156 }
157
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800158 @LayoutlibDelegate
Deepanshu Guptabb5d0cc2014-06-25 16:57:03 -0700159 /*package*/ static String getISO3Language(String locale) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800160 return "";
161 }
162
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800163 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700164 /*package*/ static String addLikelySubtags(String locale) {
165 return "";
166 }
167
Xavier Ducrohetfc511682011-06-21 11:03:29 -0700168 @LayoutlibDelegate
169 /*package*/ static String getScript(String locale) {
170 return "";
171 }
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700172
173 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800174 /*package*/ static String[] getISOLanguagesNative() {
175 return Locale.getISOLanguages();
176 }
177
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800178 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800179 /*package*/ static String[] getISOCountriesNative() {
180 return Locale.getISOCountries();
181 }
182
Deepanshu Gupta0d7ebc52014-03-05 19:23:48 -0800183 @LayoutlibDelegate
Deepanshu Gupta0d7ebc52014-03-05 19:23:48 -0800184 /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800185
186 // Used by Calendar.
Deepanshu Guptaeca05692015-05-13 14:58:15 -0700187 result.firstDayOfWeek = 1;
188 result.minimalDaysInFirstWeek = 1;
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800189
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
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700201 // 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>
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800203 result.longWeekdayNames = new String[] {
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700204 "", "Sunday", "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800205 result.shortWeekdayNames = new String[] {
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700206 "", "Sun", "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat" };
207 result.tinyWeekdayNames = new String[] {
208 "", "S", "M", "T", "W", "T", "F", "S" };
209
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800210 result.longStandAloneWeekdayNames = result.longWeekdayNames;
211 result.shortStandAloneWeekdayNames = result.shortWeekdayNames;
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700212 result.tinyStandAloneWeekdayNames = result.tinyWeekdayNames;
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800213
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';
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800226 result.decimalSeparator = '.';
227 result.groupingSeparator = ',';
228 result.patternSeparator = ' ';
Elliott Hughesd47acae2014-10-08 16:07:33 -0700229 result.percent = "%";
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800230 result.perMill = '\u2030';
231 result.monetarySeparator = ' ';
Narayan Kamathc73991b2014-03-14 14:10:30 +0000232 result.minusSign = "-";
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800233 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 }
Deepanshu Guptae2b67772014-04-21 14:33:33 -0700248
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 }
Deepanshu Guptad77b9ed2015-05-12 12:01:16 -0700258
259 @LayoutlibDelegate
260 /*package*/ static String getTZDataVersion() {
261 return ICU.getTZDataVersion();
262 }
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800263}