• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package libcore.icu;
18 
19 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20 
21 import android.icu.text.DateTimePatternGenerator;
22 import android.icu.util.Currency;
23 import android.icu.util.ULocale;
24 import android.icu.util.VersionInfo;
25 
26 import 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  */
35 public class ICU_Delegate {
36 
37     // --- Java delegates
38 
39     @LayoutlibDelegate
toLowerCase(String s, String localeName)40     /*package*/ static String toLowerCase(String s, String localeName) {
41         return s.toLowerCase();
42     }
43 
44     @LayoutlibDelegate
toUpperCase(String s, String localeName)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
getBestDateTimePatternNative(String skeleton, String localeName)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")
getCldrVersion()59     /*package*/ static String getCldrVersion() {
60         return VersionInfo.ICU_DATA_VERSION.toString();
61     }
62 
63     @LayoutlibDelegate
getIcuVersion()64     /*package*/ static String getIcuVersion() {
65         return VersionInfo.ICU_VERSION.toString();
66     }
67 
68     @LayoutlibDelegate
getUnicodeVersion()69     /*package*/ static String getUnicodeVersion() {
70         return VersionInfo.UNICODE_7_0.toString();
71     }
72 
73     @LayoutlibDelegate
getAvailableBreakIteratorLocalesNative()74     /*package*/ static String[] getAvailableBreakIteratorLocalesNative() {
75         return new String[0];
76     }
77 
78     @LayoutlibDelegate
getAvailableCalendarLocalesNative()79     /*package*/ static String[] getAvailableCalendarLocalesNative() {
80         return new String[0];
81     }
82 
83     @LayoutlibDelegate
getAvailableCollatorLocalesNative()84     /*package*/ static String[] getAvailableCollatorLocalesNative() {
85         return new String[0];
86     }
87 
88     @LayoutlibDelegate
getAvailableDateFormatLocalesNative()89     /*package*/ static String[] getAvailableDateFormatLocalesNative() {
90         return new String[0];
91     }
92 
93     @LayoutlibDelegate
getAvailableLocalesNative()94     /*package*/ static String[] getAvailableLocalesNative() {
95         return new String[0];
96     }
97 
98     @LayoutlibDelegate
getAvailableNumberFormatLocalesNative()99     /*package*/ static String[] getAvailableNumberFormatLocalesNative() {
100         return new String[0];
101     }
102 
103     @LayoutlibDelegate
getAvailableCurrencyCodes()104     /*package*/ static String[] getAvailableCurrencyCodes() {
105         return new String[0];
106     }
107 
108     @LayoutlibDelegate
getCurrencyCode(String locale)109     /*package*/ static String getCurrencyCode(String locale) {
110         return "";
111     }
112 
113     @LayoutlibDelegate
getCurrencyDisplayName(String locale, String currencyCode)114     /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) {
115         return "";
116     }
117 
118     @LayoutlibDelegate
getCurrencyFractionDigits(String currencyCode)119     /*package*/ static int getCurrencyFractionDigits(String currencyCode) {
120         return 0;
121     }
122 
123     @LayoutlibDelegate
getCurrencyNumericCode(String currencyCode)124     /*package*/ static int getCurrencyNumericCode(String currencyCode) {
125         return Currency.getInstance(currencyCode).getNumericCode();
126     }
127 
128     @LayoutlibDelegate
getCurrencySymbol(String locale, String currencyCode)129     /*package*/ static String getCurrencySymbol(String locale, String currencyCode) {
130         return "";
131     }
132 
133     @LayoutlibDelegate
getDisplayCountryNative(String countryCode, String locale)134     /*package*/ static String getDisplayCountryNative(String countryCode, String locale) {
135         return "";
136     }
137 
138     @LayoutlibDelegate
getDisplayLanguageNative(String languageCode, String locale)139     /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) {
140         return "";
141     }
142 
143     @LayoutlibDelegate
getDisplayVariantNative(String variantCode, String locale)144     /*package*/ static String getDisplayVariantNative(String variantCode, String locale) {
145         return "";
146     }
147 
148     @LayoutlibDelegate
getDisplayScriptNative(String variantCode, String locale)149     /*package*/ static String getDisplayScriptNative(String variantCode, String locale) {
150         return "";
151     }
152 
153     @LayoutlibDelegate
getISO3Country(String locale)154     /*package*/ static String getISO3Country(String locale) {
155         return "";
156     }
157 
158     @LayoutlibDelegate
getISO3Language(String locale)159     /*package*/ static String getISO3Language(String locale) {
160         return "";
161     }
162 
163     @LayoutlibDelegate
addLikelySubtags(String locale)164     /*package*/ static String addLikelySubtags(String locale) {
165         return "";
166     }
167 
168     @LayoutlibDelegate
getScript(String locale)169     /*package*/ static String getScript(String locale) {
170         return "";
171     }
172 
173     @LayoutlibDelegate
getISOLanguagesNative()174     /*package*/ static String[] getISOLanguagesNative() {
175         return Locale.getISOLanguages();
176     }
177 
178     @LayoutlibDelegate
getISOCountriesNative()179     /*package*/ static String[] getISOCountriesNative() {
180         return Locale.getISOCountries();
181     }
182 
183     @LayoutlibDelegate
initLocaleDataNative(String locale, LocaleData result)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
setDefaultLocale(String locale)250     /*package*/ static void setDefaultLocale(String locale) {
251         ICU.setDefaultLocale(locale);
252     }
253 
254     @LayoutlibDelegate
getDefaultLocale()255     /*package*/ static String getDefaultLocale() {
256         return ICU.getDefaultLocale();
257     }
258 
259     @LayoutlibDelegate
getTZDataVersion()260     /*package*/ static String getTZDataVersion() {
261         return ICU.getTZDataVersion();
262     }
263 }
264