blob: ad4103bf747c4c35bfbb63516358198fb3df57dc [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 Gupta39e75832013-10-16 20:27:51 -070020import com.ibm.icu.text.DateTimePatternGenerator;
21import com.ibm.icu.util.ULocale;
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080022
Xavier Ducrohet345f8662011-02-02 11:50:34 -080023import 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
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080034 // --- Java delegates
35
36 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080037 /*package*/ static String toLowerCase(String s, String localeName) {
38 return s.toLowerCase();
39 }
40
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080041 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080042 /*package*/ static String toUpperCase(String s, String localeName) {
43 return s.toUpperCase();
44 }
45
46 // --- Native methods accessing ICU's database.
47
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080048 @LayoutlibDelegate
Deepanshu Gupta0baec412013-11-13 19:09:17 +053049 /*package*/ static String getBestDateTimePatternNative(String skeleton, String localeName) {
Deepanshu Gupta39e75832013-10-16 20:27:51 -070050 return DateTimePatternGenerator.getInstance(new ULocale(localeName))
51 .getBestPattern(skeleton);
Deepanshu Gupta279c00e2013-05-23 15:20:04 -070052 }
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
Xavier Ducrohet66743a12011-06-15 14:43:42 -070060 /*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
Xavier Ducrohet345f8662011-02-02 11:50:34 -080070 /*package*/ static String[] getAvailableBreakIteratorLocalesNative() {
71 return new String[0];
72 }
73
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080074 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080075 /*package*/ static String[] getAvailableCalendarLocalesNative() {
76 return new String[0];
77 }
78
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080079 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080080 /*package*/ static String[] getAvailableCollatorLocalesNative() {
81 return new String[0];
82 }
83
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080084 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080085 /*package*/ static String[] getAvailableDateFormatLocalesNative() {
86 return new String[0];
87 }
88
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080089 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080090 /*package*/ static String[] getAvailableLocalesNative() {
91 return new String[0];
92 }
93
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080094 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -080095 /*package*/ static String[] getAvailableNumberFormatLocalesNative() {
96 return new String[0];
97 }
98
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -080099 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700100 /*package*/ static String[] getAvailableCurrencyCodes() {
101 return new String[0];
102 }
103
104 @LayoutlibDelegate
105 /*package*/ static String getCurrencyCode(String locale) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800106 return "";
107 }
108
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800109 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700110 /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) {
111 return "";
112 }
113
114 @LayoutlibDelegate
115 /*package*/ static int getCurrencyFractionDigits(String currencyCode) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800116 return 0;
117 }
118
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800119 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700120 /*package*/ static String getCurrencySymbol(String locale, String currencyCode) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800121 return "";
122 }
123
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800124 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800125 /*package*/ static String getDisplayCountryNative(String countryCode, String locale) {
126 return "";
127 }
128
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800129 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800130 /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) {
131 return "";
132 }
133
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800134 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800135 /*package*/ static String getDisplayVariantNative(String variantCode, String locale) {
136 return "";
137 }
138
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800139 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800140 /*package*/ static String getISO3CountryNative(String locale) {
141 return "";
142 }
143
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800144 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800145 /*package*/ static String getISO3LanguageNative(String locale) {
146 return "";
147 }
148
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800149 @LayoutlibDelegate
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700150 /*package*/ static String addLikelySubtags(String locale) {
151 return "";
152 }
153
Xavier Ducrohetfc511682011-06-21 11:03:29 -0700154 @LayoutlibDelegate
155 /*package*/ static String getScript(String locale) {
156 return "";
157 }
Xavier Ducrohet66743a12011-06-15 14:43:42 -0700158
159 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800160 /*package*/ static String[] getISOLanguagesNative() {
161 return Locale.getISOLanguages();
162 }
163
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800164 @LayoutlibDelegate
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800165 /*package*/ static String[] getISOCountriesNative() {
166 return Locale.getISOCountries();
167 }
168
Xavier Ducrohet9a4fe292011-02-09 17:17:49 -0800169 @LayoutlibDelegate
Deepanshu Gupta0baec412013-11-13 19:09:17 +0530170 /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) {
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800171
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
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700187 // The platform code expects this to begin at index 1, rather than 0. It maps it directly to
188 // the constants from java.util.Calendar.<weekday>
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800189 result.longWeekdayNames = new String[] {
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700190 "", "Sunday", "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800191 result.shortWeekdayNames = new String[] {
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700192 "", "Sun", "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat" };
193 result.tinyWeekdayNames = new String[] {
194 "", "S", "M", "T", "W", "T", "F", "S" };
195
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800196 result.longStandAloneWeekdayNames = result.longWeekdayNames;
197 result.shortStandAloneWeekdayNames = result.shortWeekdayNames;
Deepanshu Gupta81f74f42013-10-12 18:37:19 -0700198 result.tinyStandAloneWeekdayNames = result.tinyWeekdayNames;
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800199
200 result.fullTimeFormat = "";
201 result.longTimeFormat = "";
202 result.mediumTimeFormat = "";
203 result.shortTimeFormat = "";
204
205 result.fullDateFormat = "";
206 result.longDateFormat = "";
207 result.mediumDateFormat = "";
208 result.shortDateFormat = "";
209
210 // Used by DecimalFormatSymbols.
211 result.zeroDigit = '0';
Xavier Ducrohet345f8662011-02-02 11:50:34 -0800212 result.decimalSeparator = '.';
213 result.groupingSeparator = ',';
214 result.patternSeparator = ' ';
215 result.percent = '%';
216 result.perMill = '\u2030';
217 result.monetarySeparator = ' ';
218 result.minusSign = '-';
219 result.exponentSeparator = "e";
220 result.infinity = "\u221E";
221 result.NaN = "NaN";
222 // Also used by Currency.
223 result.currencySymbol = "$";
224 result.internationalCurrencySymbol = "USD";
225
226 // Used by DecimalFormat and NumberFormat.
227 result.numberPattern = "%f";
228 result.integerPattern = "%d";
229 result.currencyPattern = "%s";
230 result.percentPattern = "%f";
231
232 return true;
233 }
234}