OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.ui.base; | |
6 | |
7 import android.content.res.Configuration; | |
8 import android.view.View; | |
9 | |
10 import org.chromium.base.ApiCompatibilityUtils; | |
11 import org.chromium.base.ApplicationStatus; | |
12 import org.chromium.base.CalledByNative; | |
13 import org.chromium.base.JNINamespace; | |
14 | |
15 import java.util.Locale; | |
16 | |
17 /** | |
18 * This class provides the locale related methods for the native library. | |
19 */ | |
20 @JNINamespace("l10n_util") | |
21 public class LocalizationUtils { | |
22 | |
23 // 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 RIGHT_TO_LEFT = 1; | |
26 public static final int LEFT_TO_RIGHT = 2; | |
27 | |
28 private static Boolean sIsLayoutRtl; | |
29 | |
30 private LocalizationUtils() { /* cannot be instantiated */ } | |
31 | |
32 @CalledByNative | |
33 private static Locale getJavaLocale(String language, String country, String
variant) { | |
34 return new Locale(language, country, variant); | |
35 } | |
36 | |
37 @CalledByNative | |
38 private static String getDisplayNameForLocale(Locale locale, Locale displayL
ocale) { | |
39 return locale.getDisplayName(displayLocale); | |
40 } | |
41 | |
42 /** | |
43 * Returns whether the Android layout direction is RTL. | |
44 * | |
45 * Note that the locale direction can be different from layout direction. Tw
o known cases: | |
46 * - RTL languages on Android 4.1, due to the lack of RTL layout support on
4.1. | |
47 * - When user turned on force RTL layout option under developer options. | |
48 * | |
49 * Therefore, only this function should be used to query RTL for layout purp
oses. | |
50 */ | |
51 @CalledByNative | |
52 public static boolean isLayoutRtl() { | |
53 if (sIsLayoutRtl == null) { | |
54 Configuration configuration = | |
55 ApplicationStatus.getApplicationContext().getResources().get
Configuration(); | |
56 sIsLayoutRtl = Boolean.valueOf( | |
57 ApiCompatibilityUtils.getLayoutDirection(configuration) == | |
58 View.LAYOUT_DIRECTION_RTL); | |
59 } | |
60 | |
61 return sIsLayoutRtl.booleanValue(); | |
62 } | |
63 | |
64 /** | |
65 * Jni binding to base::i18n::GetFirstStrongCharacterDirection | |
66 * @param string String to decide the direction. | |
67 * @return One of the UNKNOWN_DIRECTION, RIGHT_TO_LEFT, and LEFT_TO_RIGHT. | |
68 */ | |
69 public static int getFirstStrongCharacterDirection(String string) { | |
70 return nativeGetFirstStrongCharacterDirection(string); | |
71 } | |
72 | |
73 /** | |
74 * Jni binding to ui::TimeFormat::TimeRemaining. Converts milliseconds to | |
75 * time remaining format : "3 mins left", "2 days left". | |
76 * @param timeInMillis time in milliseconds | |
77 * @return time remaining | |
78 */ | |
79 public static String getDurationString(long timeInMillis) { | |
80 return nativeGetDurationString(timeInMillis); | |
81 } | |
82 | |
83 private static native int nativeGetFirstStrongCharacterDirection(String stri
ng); | |
84 | |
85 private static native String nativeGetDurationString(long timeInMillis); | |
86 } | |
OLD | NEW |