EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.ui]

COVERAGE SUMMARY FOR SOURCE FILE [LocalizationUtils.java]

nameclass, %method, %block, %line, %
LocalizationUtils.java100% (1/1)57%  (4/7)66%  (50/76)60%  (10.9/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LocalizationUtils100% (1/1)57%  (4/7)66%  (50/76)60%  (10.9/18)
LocalizationUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getFirstStrongCharacterDirection (String): int 0%   (0/1)0%   (0/3)0%   (0/1)
isRtl (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
isSystemLayoutDirectionRtl (): boolean 100% (1/1)38%  (5/13)67%  (2/3)
getDefaultLocale (): String 100% (1/1)77%  (34/44)69%  (6.9/10)
getDisplayNameForLocale (Locale, Locale): String 100% (1/1)100% (4/4)100% (1/1)
getJavaLocale (String, String, String): Locale 100% (1/1)100% (7/7)100% (1/1)

1// Copyright (c) 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 
5package org.chromium.ui;
6 
7import org.chromium.base.CalledByNative;
8import org.chromium.base.JNINamespace;
9 
10import android.os.Build;
11import android.text.TextUtils;
12import android.view.View;
13 
14import java.util.Locale;
15 
16/**
17 * This class provides the locale related methods for the native library.
18 */
19@JNINamespace("l10n_util")
20public class LocalizationUtils {
21 
22    // This is mirrored from base/i18n/rtl.h. Please keep in sync.
23    public static final int UNKNOWN_DIRECTION = 0;
24    public static final int RIGHT_TO_LEFT = 1;
25    public static final int LEFT_TO_RIGHT = 2;
26 
27    private LocalizationUtils() { /* cannot be instantiated */ }
28 
29    /**
30     * @return the default locale, translating Android deprecated
31     * language codes into the modern ones used by Chromium.
32     */
33    @CalledByNative
34    public static String getDefaultLocale() {
35        Locale locale = Locale.getDefault();
36        String language = locale.getLanguage();
37        String country = locale.getCountry();
38 
39        // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the
40        // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino.
41        // So apply a mapping.
42        // See http://developer.android.com/reference/java/util/Locale.html
43        if ("iw".equals(language)) {
44            language = "he";
45        } else if ("in".equals(language)) {
46            language = "id";
47        } else if ("tl".equals(language)) {
48            language = "fil";
49        }
50        return country.isEmpty() ? language : language + "-" + country;
51    }
52 
53    @CalledByNative
54    private static Locale getJavaLocale(String language, String country, String variant) {
55        return new Locale(language, country, variant);
56    }
57 
58    @CalledByNative
59    private static String getDisplayNameForLocale(Locale locale, Locale displayLocale) {
60        return locale.getDisplayName(displayLocale);
61    }
62 
63    /**
64     * @return true if the system default layout direction is RTL, false otherwise.
65     *         RTL layout support is from Jelly Bean MR1, so if the version is lower
66     *         than that, it is always false.
67     */
68    public static boolean isSystemLayoutDirectionRtl() {
69        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
70            return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
71                    == View.LAYOUT_DIRECTION_RTL;
72        }
73        return false;
74    }
75 
76    /**
77     * Jni binding to base::i18n::IsRTL.
78     * @return true if the current locale is right to left.
79     */
80    public static boolean isRtl() {
81        return nativeIsRTL();
82    }
83 
84    /**
85     * Jni binding to base::i18n::GetFirstStrongCharacterDirection
86     * @param string String to decide the direction.
87     * @return One of the UNKNOWN_DIRECTION, RIGHT_TO_LEFT, and LEFT_TO_RIGHT.
88     */
89    public static int getFirstStrongCharacterDirection(String string) {
90        return nativeGetFirstStrongCharacterDirection(string);
91    }
92 
93    private static native boolean nativeIsRTL();
94 
95    private static native int nativeGetFirstStrongCharacterDirection(String string);
96}

[all classes][org.chromium.ui]
EMMA 2.0.5312 (C) Vladimir Roubtsov