| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.LocaleList; | 9 import android.os.LocaleList; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 public static String toLanguageTags(LocaleList localeList) { | 165 public static String toLanguageTags(LocaleList localeList) { |
| 166 ArrayList<String> newLocaleList = new ArrayList<>(); | 166 ArrayList<String> newLocaleList = new ArrayList<>(); |
| 167 for (int i = 0; i < localeList.size(); i++) { | 167 for (int i = 0; i < localeList.size(); i++) { |
| 168 Locale locale = getUpdatedLocaleForChromium(localeList.get(i)); | 168 Locale locale = getUpdatedLocaleForChromium(localeList.get(i)); |
| 169 newLocaleList.add(toLanguageTag(locale)); | 169 newLocaleList.add(toLanguageTag(locale)); |
| 170 } | 170 } |
| 171 return TextUtils.join(",", newLocaleList); | 171 return TextUtils.join(",", newLocaleList); |
| 172 } | 172 } |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * @return a comma separated language tags string that represents a default
locale. |
| 176 * Each language tag is well-formed IETF BCP 47 language tag with la
nguage and country |
| 177 * code. |
| 178 */ |
| 179 @CalledByNative |
| 180 public static String getDefaultLocaleString() { |
| 181 return toLanguageTag(Locale.getDefault()); |
| 182 } |
| 183 |
| 184 /** |
| 175 * @return a comma separated language tags string that represents a default
locale or locales. | 185 * @return a comma separated language tags string that represents a default
locale or locales. |
| 176 * Each language tag is well-formed IETF BCP 47 language tag with la
nguage and country | 186 * Each language tag is well-formed IETF BCP 47 language tag with la
nguage and country |
| 177 * code. | 187 * code. |
| 178 */ | 188 */ |
| 179 @CalledByNative | 189 public static String getDefaultLocaleListString() { |
| 180 public static String getDefaultLocaleString() { | |
| 181 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 190 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 182 return toLanguageTags(LocaleList.getAdjustedDefault()); | 191 return toLanguageTags(LocaleList.getDefault()); |
| 183 } | 192 } |
| 184 return toLanguageTag(Locale.getDefault()); | 193 return getDefaultLocaleString(); |
| 185 } | 194 } |
| 186 | 195 |
| 187 /** | 196 /** |
| 188 * @return The default country code set during install. | 197 * @return The default country code set during install. |
| 189 */ | 198 */ |
| 190 @CalledByNative | 199 @CalledByNative |
| 191 private static String getDefaultCountryCode() { | 200 private static String getDefaultCountryCode() { |
| 192 CommandLine commandLine = CommandLine.getInstance(); | 201 CommandLine commandLine = CommandLine.getInstance(); |
| 193 return commandLine.hasSwitch(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTAL
L) | 202 return commandLine.hasSwitch(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTAL
L) |
| 194 ? commandLine.getSwitchValue(BaseSwitches.DEFAULT_COUNTRY_CODE_A
T_INSTALL) | 203 ? commandLine.getSwitchValue(BaseSwitches.DEFAULT_COUNTRY_CODE_A
T_INSTALL) |
| 195 : Locale.getDefault().getCountry(); | 204 : Locale.getDefault().getCountry(); |
| 196 } | 205 } |
| 197 | 206 |
| 198 } | 207 } |
| OLD | NEW |