| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.content.res.Configuration; | 7 import android.content.res.Configuration; |
| 8 import android.view.View; | 8 import android.view.View; |
| 9 | 9 |
| 10 import org.chromium.base.ApiCompatibilityUtils; | 10 import org.chromium.base.ApiCompatibilityUtils; |
| 11 import org.chromium.base.ApplicationStatus; | 11 import org.chromium.base.ApplicationStatus; |
| 12 import org.chromium.base.CalledByNative; | 12 import org.chromium.base.CalledByNative; |
| 13 import org.chromium.base.JNINamespace; | 13 import org.chromium.base.JNINamespace; |
| 14 import org.chromium.base.LocaleUtils; |
| 14 | 15 |
| 15 import java.util.Locale; | 16 import java.util.Locale; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * This class provides the locale related methods for the native library. | 19 * This class provides the locale related methods for the native library. |
| 19 */ | 20 */ |
| 20 @JNINamespace("l10n_util") | 21 @JNINamespace("l10n_util") |
| 21 public class LocalizationUtils { | 22 public class LocalizationUtils { |
| 22 | 23 |
| 23 // This is mirrored from base/i18n/rtl.h. Please keep in sync. | 24 // This is mirrored from base/i18n/rtl.h. Please keep in sync. |
| 24 public static final int UNKNOWN_DIRECTION = 0; | 25 public static final int UNKNOWN_DIRECTION = 0; |
| 25 public static final int RIGHT_TO_LEFT = 1; | 26 public static final int RIGHT_TO_LEFT = 1; |
| 26 public static final int LEFT_TO_RIGHT = 2; | 27 public static final int LEFT_TO_RIGHT = 2; |
| 27 | 28 |
| 28 private static Boolean sIsLayoutRtl; | 29 private static Boolean sIsLayoutRtl; |
| 29 | 30 |
| 30 private LocalizationUtils() { /* cannot be instantiated */ } | 31 private LocalizationUtils() { /* cannot be instantiated */ } |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * @return the default locale, translating Android deprecated | 34 * @return the default locale, translating Android deprecated |
| 34 * language codes into the modern ones used by Chromium. | 35 * language codes into the modern ones used by Chromium. |
| 35 */ | 36 */ |
| 36 @CalledByNative | 37 @CalledByNative |
| 37 public static String getDefaultLocale() { | 38 public static String getDefaultLocale() { |
| 38 Locale locale = Locale.getDefault(); | 39 // TODO(vivekg): Native callers should use LocaleUtils directly instead
of the redirection. |
| 39 String language = locale.getLanguage(); | 40 return LocaleUtils.getDefaultLocale(); |
| 40 String country = locale.getCountry(); | |
| 41 | |
| 42 // Android uses deprecated lanuages codes for Hebrew and Indonesian but
Chromium uses the | |
| 43 // updated codes. Also, Android uses "tl" while Chromium uses "fil" for
Tagalog/Filipino. | |
| 44 // So apply a mapping. | |
| 45 // See http://developer.android.com/reference/java/util/Locale.html | |
| 46 if ("iw".equals(language)) { | |
| 47 language = "he"; | |
| 48 } else if ("in".equals(language)) { | |
| 49 language = "id"; | |
| 50 } else if ("tl".equals(language)) { | |
| 51 language = "fil"; | |
| 52 } | |
| 53 return country.isEmpty() ? language : language + "-" + country; | |
| 54 } | 41 } |
| 55 | 42 |
| 56 @CalledByNative | 43 @CalledByNative |
| 57 private static Locale getJavaLocale(String language, String country, String
variant) { | 44 private static Locale getJavaLocale(String language, String country, String
variant) { |
| 58 return new Locale(language, country, variant); | 45 return new Locale(language, country, variant); |
| 59 } | 46 } |
| 60 | 47 |
| 61 @CalledByNative | 48 @CalledByNative |
| 62 private static String getDisplayNameForLocale(Locale locale, Locale displayL
ocale) { | 49 private static String getDisplayNameForLocale(Locale locale, Locale displayL
ocale) { |
| 63 return locale.getDisplayName(displayLocale); | 50 return locale.getDisplayName(displayLocale); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 * @return time remaining | 88 * @return time remaining |
| 102 */ | 89 */ |
| 103 public static String getDurationString(long timeInMillis) { | 90 public static String getDurationString(long timeInMillis) { |
| 104 return nativeGetDurationString(timeInMillis); | 91 return nativeGetDurationString(timeInMillis); |
| 105 } | 92 } |
| 106 | 93 |
| 107 private static native int nativeGetFirstStrongCharacterDirection(String stri
ng); | 94 private static native int nativeGetFirstStrongCharacterDirection(String stri
ng); |
| 108 | 95 |
| 109 private static native String nativeGetDurationString(long timeInMillis); | 96 private static native String nativeGetDurationString(long timeInMillis); |
| 110 } | 97 } |
| OLD | NEW |