Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 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 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 19 | import com.android.tools.layoutlib.annotations.LayoutlibDelegate; |
Deepanshu Gupta | d77b9ed | 2015-05-12 12:01:16 -0700 | [diff] [blame] | 20 | |
| 21 | import android.icu.text.DateTimePatternGenerator; |
| 22 | import android.icu.util.Currency; |
| 23 | import android.icu.util.ULocale; |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 24 | import android.icu.util.VersionInfo; |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 25 | |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 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 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 37 | // --- Java delegates |
| 38 | |
| 39 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 40 | /*package*/ static String toLowerCase(String s, String localeName) { |
| 41 | return s.toLowerCase(); |
| 42 | } |
| 43 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 44 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 45 | /*package*/ static String toUpperCase(String s, String localeName) { |
| 46 | return s.toUpperCase(); |
| 47 | } |
| 48 | |
| 49 | // --- Native methods accessing ICU's database. |
| 50 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 51 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 52 | /*package*/ static String getBestDateTimePatternNative(String skeleton, String localeName) { |
Deepanshu Gupta | 39e7583 | 2013-10-16 20:27:51 -0700 | [diff] [blame] | 53 | return DateTimePatternGenerator.getInstance(new ULocale(localeName)) |
| 54 | .getBestPattern(skeleton); |
Deepanshu Gupta | 279c00e | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @LayoutlibDelegate |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 58 | @SuppressWarnings("deprecation") |
Deepanshu Gupta | 279c00e | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 59 | /*package*/ static String getCldrVersion() { |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 60 | return VersionInfo.ICU_DATA_VERSION.toString(); |
Deepanshu Gupta | 279c00e | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 64 | /*package*/ static String getIcuVersion() { |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 65 | return VersionInfo.ICU_VERSION.toString(); |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @LayoutlibDelegate |
| 69 | /*package*/ static String getUnicodeVersion() { |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 70 | return VersionInfo.UNICODE_7_0.toString(); |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 74 | /*package*/ static String[] getAvailableBreakIteratorLocalesNative() { |
| 75 | return new String[0]; |
| 76 | } |
| 77 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 78 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 79 | /*package*/ static String[] getAvailableCalendarLocalesNative() { |
| 80 | return new String[0]; |
| 81 | } |
| 82 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 83 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 84 | /*package*/ static String[] getAvailableCollatorLocalesNative() { |
| 85 | return new String[0]; |
| 86 | } |
| 87 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 88 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 89 | /*package*/ static String[] getAvailableDateFormatLocalesNative() { |
| 90 | return new String[0]; |
| 91 | } |
| 92 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 93 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 94 | /*package*/ static String[] getAvailableLocalesNative() { |
| 95 | return new String[0]; |
| 96 | } |
| 97 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 98 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 99 | /*package*/ static String[] getAvailableNumberFormatLocalesNative() { |
| 100 | return new String[0]; |
| 101 | } |
| 102 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 103 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 104 | /*package*/ static String[] getAvailableCurrencyCodes() { |
| 105 | return new String[0]; |
| 106 | } |
| 107 | |
| 108 | @LayoutlibDelegate |
| 109 | /*package*/ static String getCurrencyCode(String locale) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 110 | return ""; |
| 111 | } |
| 112 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 113 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 114 | /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) { |
| 115 | return ""; |
| 116 | } |
| 117 | |
| 118 | @LayoutlibDelegate |
| 119 | /*package*/ static int getCurrencyFractionDigits(String currencyCode) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 123 | @LayoutlibDelegate |
Deepanshu Gupta | 103d409 | 2014-03-14 13:24:56 -0700 | [diff] [blame] | 124 | /*package*/ static int getCurrencyNumericCode(String currencyCode) { |
| 125 | return Currency.getInstance(currencyCode).getNumericCode(); |
| 126 | } |
| 127 | |
| 128 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 129 | /*package*/ static String getCurrencySymbol(String locale, String currencyCode) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 130 | return ""; |
| 131 | } |
| 132 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 133 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 134 | /*package*/ static String getDisplayCountryNative(String countryCode, String locale) { |
| 135 | return ""; |
| 136 | } |
| 137 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 138 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 139 | /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) { |
| 140 | return ""; |
| 141 | } |
| 142 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 143 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 144 | /*package*/ static String getDisplayVariantNative(String variantCode, String locale) { |
| 145 | return ""; |
| 146 | } |
| 147 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 148 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 149 | /*package*/ static String getDisplayScriptNative(String variantCode, String locale) { |
| 150 | return ""; |
| 151 | } |
| 152 | |
| 153 | @LayoutlibDelegate |
Deepanshu Gupta | bb5d0cc | 2014-06-25 16:57:03 -0700 | [diff] [blame] | 154 | /*package*/ static String getISO3Country(String locale) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 155 | return ""; |
| 156 | } |
| 157 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 158 | @LayoutlibDelegate |
Deepanshu Gupta | bb5d0cc | 2014-06-25 16:57:03 -0700 | [diff] [blame] | 159 | /*package*/ static String getISO3Language(String locale) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 160 | return ""; |
| 161 | } |
| 162 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 163 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 164 | /*package*/ static String addLikelySubtags(String locale) { |
| 165 | return ""; |
| 166 | } |
| 167 | |
Xavier Ducrohet | fc51168 | 2011-06-21 11:03:29 -0700 | [diff] [blame] | 168 | @LayoutlibDelegate |
| 169 | /*package*/ static String getScript(String locale) { |
| 170 | return ""; |
| 171 | } |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 172 | |
| 173 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 174 | /*package*/ static String[] getISOLanguagesNative() { |
| 175 | return Locale.getISOLanguages(); |
| 176 | } |
| 177 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 178 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 179 | /*package*/ static String[] getISOCountriesNative() { |
| 180 | return Locale.getISOCountries(); |
| 181 | } |
| 182 | |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 183 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 184 | /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 185 | |
| 186 | // Used by Calendar. |
Deepanshu Gupta | eca0569 | 2015-05-13 14:58:15 -0700 | [diff] [blame] | 187 | result.firstDayOfWeek = 1; |
| 188 | result.minimalDaysInFirstWeek = 1; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 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 | |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 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> |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 203 | result.longWeekdayNames = new String[] { |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 204 | "", "Sunday", "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 205 | result.shortWeekdayNames = new String[] { |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 206 | "", "Sun", "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat" }; |
| 207 | result.tinyWeekdayNames = new String[] { |
| 208 | "", "S", "M", "T", "W", "T", "F", "S" }; |
| 209 | |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 210 | result.longStandAloneWeekdayNames = result.longWeekdayNames; |
| 211 | result.shortStandAloneWeekdayNames = result.shortWeekdayNames; |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 212 | result.tinyStandAloneWeekdayNames = result.tinyWeekdayNames; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 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'; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 226 | result.decimalSeparator = '.'; |
| 227 | result.groupingSeparator = ','; |
| 228 | result.patternSeparator = ' '; |
Elliott Hughes | d47acae | 2014-10-08 16:07:33 -0700 | [diff] [blame] | 229 | result.percent = "%"; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 230 | result.perMill = '\u2030'; |
| 231 | result.monetarySeparator = ' '; |
Narayan Kamath | c73991b | 2014-03-14 14:10:30 +0000 | [diff] [blame] | 232 | result.minusSign = "-"; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 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 | } |
Deepanshu Gupta | e2b6777 | 2014-04-21 14:33:33 -0700 | [diff] [blame] | 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 | } |
Deepanshu Gupta | d77b9ed | 2015-05-12 12:01:16 -0700 | [diff] [blame] | 258 | |
| 259 | @LayoutlibDelegate |
| 260 | /*package*/ static String getTZDataVersion() { |
| 261 | return ICU.getTZDataVersion(); |
| 262 | } |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 263 | } |