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 | 39e7583 | 2013-10-16 20:27:51 -0700 | [diff] [blame] | 20 | import com.ibm.icu.text.DateTimePatternGenerator; |
| 21 | import com.ibm.icu.util.ULocale; |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 22 | |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 23 | import 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 | */ |
| 32 | public class ICU_Delegate { |
| 33 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 34 | // --- Java delegates |
| 35 | |
| 36 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 37 | /*package*/ static String toLowerCase(String s, String localeName) { |
| 38 | return s.toLowerCase(); |
| 39 | } |
| 40 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 41 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 42 | /*package*/ static String toUpperCase(String s, String localeName) { |
| 43 | return s.toUpperCase(); |
| 44 | } |
| 45 | |
| 46 | // --- Native methods accessing ICU's database. |
| 47 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 48 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 49 | /*package*/ static String getBestDateTimePatternNative(String skeleton, String localeName) { |
Deepanshu Gupta | 39e7583 | 2013-10-16 20:27:51 -0700 | [diff] [blame] | 50 | return DateTimePatternGenerator.getInstance(new ULocale(localeName)) |
| 51 | .getBestPattern(skeleton); |
Deepanshu Gupta | 279c00e | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 52 | } |
| 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 Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 60 | /*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 Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 70 | /*package*/ static String[] getAvailableBreakIteratorLocalesNative() { |
| 71 | return new String[0]; |
| 72 | } |
| 73 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 74 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 75 | /*package*/ static String[] getAvailableCalendarLocalesNative() { |
| 76 | return new String[0]; |
| 77 | } |
| 78 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 79 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 80 | /*package*/ static String[] getAvailableCollatorLocalesNative() { |
| 81 | return new String[0]; |
| 82 | } |
| 83 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 84 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 85 | /*package*/ static String[] getAvailableDateFormatLocalesNative() { |
| 86 | return new String[0]; |
| 87 | } |
| 88 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 89 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 90 | /*package*/ static String[] getAvailableLocalesNative() { |
| 91 | return new String[0]; |
| 92 | } |
| 93 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 94 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 95 | /*package*/ static String[] getAvailableNumberFormatLocalesNative() { |
| 96 | return new String[0]; |
| 97 | } |
| 98 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 99 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 100 | /*package*/ static String[] getAvailableCurrencyCodes() { |
| 101 | return new String[0]; |
| 102 | } |
| 103 | |
| 104 | @LayoutlibDelegate |
| 105 | /*package*/ static String getCurrencyCode(String locale) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 106 | return ""; |
| 107 | } |
| 108 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 109 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 110 | /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) { |
| 111 | return ""; |
| 112 | } |
| 113 | |
| 114 | @LayoutlibDelegate |
| 115 | /*package*/ static int getCurrencyFractionDigits(String currencyCode) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 119 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 120 | /*package*/ static String getCurrencySymbol(String locale, String currencyCode) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 121 | return ""; |
| 122 | } |
| 123 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 124 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 125 | /*package*/ static String getDisplayCountryNative(String countryCode, String locale) { |
| 126 | return ""; |
| 127 | } |
| 128 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 129 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 130 | /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) { |
| 131 | return ""; |
| 132 | } |
| 133 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 134 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 135 | /*package*/ static String getDisplayVariantNative(String variantCode, String locale) { |
| 136 | return ""; |
| 137 | } |
| 138 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 139 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 140 | /*package*/ static String getDisplayScriptNative(String variantCode, String locale) { |
| 141 | return ""; |
| 142 | } |
| 143 | |
| 144 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 145 | /*package*/ static String getISO3CountryNative(String locale) { |
| 146 | return ""; |
| 147 | } |
| 148 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 149 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 150 | /*package*/ static String getISO3LanguageNative(String locale) { |
| 151 | return ""; |
| 152 | } |
| 153 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 154 | @LayoutlibDelegate |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 155 | /*package*/ static String addLikelySubtags(String locale) { |
| 156 | return ""; |
| 157 | } |
| 158 | |
Xavier Ducrohet | fc51168 | 2011-06-21 11:03:29 -0700 | [diff] [blame] | 159 | @LayoutlibDelegate |
| 160 | /*package*/ static String getScript(String locale) { |
| 161 | return ""; |
| 162 | } |
Xavier Ducrohet | 66743a1 | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 163 | |
| 164 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 165 | /*package*/ static String[] getISOLanguagesNative() { |
| 166 | return Locale.getISOLanguages(); |
| 167 | } |
| 168 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 169 | @LayoutlibDelegate |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 170 | /*package*/ static String[] getISOCountriesNative() { |
| 171 | return Locale.getISOCountries(); |
| 172 | } |
| 173 | |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 174 | |
Xavier Ducrohet | 9a4fe29 | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 175 | @LayoutlibDelegate |
Deepanshu Gupta | 0d7ebc5 | 2014-03-05 19:23:48 -0800 | [diff] [blame] | 176 | /*package*/ static String localeForLanguageTag(String languageTag, boolean strict) { |
| 177 | return ""; |
| 178 | } |
| 179 | |
| 180 | @LayoutlibDelegate |
| 181 | /*package*/ static String languageTagForLocale(String locale) { |
| 182 | return ""; |
| 183 | } |
| 184 | |
| 185 | @LayoutlibDelegate |
| 186 | /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) { |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 187 | |
| 188 | // Used by Calendar. |
| 189 | result.firstDayOfWeek = Integer.valueOf(1); |
| 190 | result.minimalDaysInFirstWeek = Integer.valueOf(1); |
| 191 | |
| 192 | // Used by DateFormatSymbols. |
| 193 | result.amPm = new String[] { "AM", "PM" }; |
| 194 | result.eras = new String[] { "BC", "AD" }; |
| 195 | |
| 196 | result.longMonthNames = new String[] { "January", "February", "March", "April", "May", |
| 197 | "June", "July", "August", "September", "October", "November", "December" }; |
| 198 | result.shortMonthNames = new String[] { "Jan", "Feb", "Mar", "Apr", "May", |
| 199 | "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
| 200 | result.longStandAloneMonthNames = result.longMonthNames; |
| 201 | result.shortStandAloneMonthNames = result.shortMonthNames; |
| 202 | |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 203 | // The platform code expects this to begin at index 1, rather than 0. It maps it directly to |
| 204 | // the constants from java.util.Calendar.<weekday> |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 205 | result.longWeekdayNames = new String[] { |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 206 | "", "Sunday", "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 207 | result.shortWeekdayNames = new String[] { |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 208 | "", "Sun", "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat" }; |
| 209 | result.tinyWeekdayNames = new String[] { |
| 210 | "", "S", "M", "T", "W", "T", "F", "S" }; |
| 211 | |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 212 | result.longStandAloneWeekdayNames = result.longWeekdayNames; |
| 213 | result.shortStandAloneWeekdayNames = result.shortWeekdayNames; |
Deepanshu Gupta | 81f74f4 | 2013-10-12 18:37:19 -0700 | [diff] [blame] | 214 | result.tinyStandAloneWeekdayNames = result.tinyWeekdayNames; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 215 | |
| 216 | result.fullTimeFormat = ""; |
| 217 | result.longTimeFormat = ""; |
| 218 | result.mediumTimeFormat = ""; |
| 219 | result.shortTimeFormat = ""; |
| 220 | |
| 221 | result.fullDateFormat = ""; |
| 222 | result.longDateFormat = ""; |
| 223 | result.mediumDateFormat = ""; |
| 224 | result.shortDateFormat = ""; |
| 225 | |
| 226 | // Used by DecimalFormatSymbols. |
| 227 | result.zeroDigit = '0'; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 228 | result.decimalSeparator = '.'; |
| 229 | result.groupingSeparator = ','; |
| 230 | result.patternSeparator = ' '; |
| 231 | result.percent = '%'; |
| 232 | result.perMill = '\u2030'; |
| 233 | result.monetarySeparator = ' '; |
Narayan Kamath | c73991b | 2014-03-14 14:10:30 +0000 | [diff] [blame] | 234 | result.minusSign = "-"; |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 235 | result.exponentSeparator = "e"; |
| 236 | result.infinity = "\u221E"; |
| 237 | result.NaN = "NaN"; |
| 238 | // Also used by Currency. |
| 239 | result.currencySymbol = "$"; |
| 240 | result.internationalCurrencySymbol = "USD"; |
| 241 | |
| 242 | // Used by DecimalFormat and NumberFormat. |
| 243 | result.numberPattern = "%f"; |
| 244 | result.integerPattern = "%d"; |
| 245 | result.currencyPattern = "%s"; |
| 246 | result.percentPattern = "%f"; |
| 247 | |
| 248 | return true; |
| 249 | } |
Deepanshu Gupta | e2b6777 | 2014-04-21 14:33:33 -0700 | [diff] [blame^] | 250 | |
| 251 | @LayoutlibDelegate |
| 252 | /*package*/ static void setDefaultLocale(String locale) { |
| 253 | ICU.setDefaultLocale(locale); |
| 254 | } |
| 255 | |
| 256 | @LayoutlibDelegate |
| 257 | /*package*/ static String getDefaultLocale() { |
| 258 | return ICU.getDefaultLocale(); |
| 259 | } |
Xavier Ducrohet | 345f866 | 2011-02-02 11:50:34 -0800 | [diff] [blame] | 260 | } |