Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d9f2372 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Update Configuration for renaming and fixes"

parents bd3e5379 7a736fbf
Loading
Loading
Loading
Loading
+26 −24
Original line number Diff line number Diff line
@@ -277,24 +277,24 @@ public final class Configuration implements Parcelable, Comparable<Configuration
    public int compatSmallestScreenWidthDp;

    /**
     * @hide
     * @hide Do not use. Implementation not finished.
     */
    public static final int LAYOUT_DIRECTION_UNDEFINED = -1;
    public static final int TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE = -1;

    /**
     * @hide
     * @hide Do not use. Implementation not finished.
     */
    public static final int LAYOUT_DIRECTION_LTR = 0;
    public static final int TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE = 0;

    /**
     * @hide
     * @hide Do not use. Implementation not finished.
     */
    public static final int LAYOUT_DIRECTION_RTL = 1;
    public static final int TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE = 1;

    /**
     * @hide The layout direction associated to the current Locale
     * @hide The text layout direction associated to the current Locale
     */
    public int layoutDirection;
    public int textLayoutDirection;

    /**
     * @hide Internal book-keeping.
@@ -322,7 +322,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        mnc = o.mnc;
        if (o.locale != null) {
            locale = (Locale) o.locale.clone();
            layoutDirection = o.layoutDirection;
            textLayoutDirection = o.textLayoutDirection;
        }
        userSetLocale = o.userSetLocale;
        touchscreen = o.touchscreen;
@@ -358,6 +358,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        } else {
            sb.append(" (no locale)");
        }
        switch (textLayoutDirection) {
            case TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE: sb.append(" ?layoutdir"); break;
            case TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE: sb.append(" rtl"); break;
            default: sb.append(" layoutdir="); sb.append(textLayoutDirection); break;
        }
        if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
            sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp");
        } else {
@@ -450,11 +455,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            case NAVIGATIONHIDDEN_YES: sb.append("/h"); break;
            default: sb.append("/"); sb.append(navigationHidden); break;
        }
        switch (layoutDirection) {
            case LAYOUT_DIRECTION_UNDEFINED: sb.append(" ?layoutdir"); break;
            case LAYOUT_DIRECTION_LTR: sb.append(" ltr"); break;
            case LAYOUT_DIRECTION_RTL: sb.append(" rtl"); break;
        }
        if (seq != 0) {
            sb.append(" s.");
            sb.append(seq);
@@ -483,8 +483,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
        screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
        smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
        textLayoutDirection = TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
        seq = 0;
        layoutDirection = LAYOUT_DIRECTION_LTR;
    }

    /** {@hide} */
@@ -519,7 +519,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            changed |= ActivityInfo.CONFIG_LOCALE;
            locale = delta.locale != null
                    ? (Locale) delta.locale.clone() : null;
            layoutDirection = getLayoutDirectionFromLocale(locale);
            textLayoutDirection = getLayoutDirectionFromLocale(locale);
        }
        if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
        {
@@ -611,23 +611,25 @@ public final class Configuration implements Parcelable, Comparable<Configuration
    /**
     * Return the layout direction for a given Locale
     * @param locale the Locale for which we want the layout direction. Can be null.
     * @return the layout direction. This may be one of {@link #LAYOUT_DIRECTION_UNDEFINED},
     * {@link #LAYOUT_DIRECTION_LTR} or {@link #LAYOUT_DIRECTION_RTL}.
     * @return the layout direction. This may be one of:
     * {@link #TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE} or
     * {@link #TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE} or
     * {@link #TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE}.
     *
     * @hide
     */
    public static int getLayoutDirectionFromLocale(Locale locale) {
        if (locale == null || locale.equals(Locale.ROOT)) return LAYOUT_DIRECTION_UNDEFINED;
        if (locale == null || locale.equals(Locale.ROOT)) return TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE;
        // Be careful: this code will need to be changed when vertical scripts will be supported
        // OR if ICU4C is updated to have the "likelySubtags" file
        switch(Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) {
            case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
                return LAYOUT_DIRECTION_LTR;
                return TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
                return LAYOUT_DIRECTION_RTL;
                return TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE;
            default:
                return LAYOUT_DIRECTION_UNDEFINED;
                return TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE;
        }
    }

@@ -810,7 +812,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        dest.writeInt(compatScreenWidthDp);
        dest.writeInt(compatScreenHeightDp);
        dest.writeInt(compatSmallestScreenWidthDp);
        dest.writeInt(layoutDirection);
        dest.writeInt(textLayoutDirection);
        dest.writeInt(seq);
    }

@@ -838,7 +840,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        compatScreenWidthDp = source.readInt();
        compatScreenHeightDp = source.readInt();
        compatSmallestScreenWidthDp = source.readInt();
        layoutDirection = source.readInt();
        textLayoutDirection = source.readInt();
        seq = source.readInt();
    }
    
+57 −57
Original line number Diff line number Diff line
@@ -30,169 +30,169 @@ public class ConfigurationTest extends AndroidTestCase {
        args = {Locale.class}
    )
    public void testGetLayoutDirectionFromLocale() {
        assertEquals(Configuration.LAYOUT_DIRECTION_UNDEFINED,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(null));

        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.ENGLISH));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.CANADA));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.CANADA_FRENCH));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.FRANCE));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.FRENCH));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.GERMAN));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.GERMANY));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.ITALIAN));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.ITALY));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.UK));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.US));

        assertEquals(Configuration.LAYOUT_DIRECTION_UNDEFINED,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.ROOT));

        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.CHINA));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.CHINESE));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.JAPAN));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.JAPANESE));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.KOREA));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.KOREAN));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.PRC));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.SIMPLIFIED_CHINESE));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.TAIWAN));
        assertEquals(Configuration.LAYOUT_DIRECTION_LTR,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(Locale.TRADITIONAL_CHINESE));

        Locale locale = new Locale("ar");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "AE");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "BH");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "DZ");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "EG");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "IQ");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "JO");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "KW");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "LB");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "LY");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "MA");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "OM");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "QA");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "SA");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "SD");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "SY");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "TN");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ar", "YE");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));

        locale = new Locale("fa");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("fa", "AF");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("fa", "IR");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));

        locale = new Locale("iw");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("iw", "IL");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("he");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("he", "IL");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));

        // The following test will not pass until we are able to take care about the scrip subtag
        // thru having the "likelySubTags" file into ICU4C
//        locale = new Locale("pa_Arab");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));
//        locale = new Locale("pa_Arab", "PK");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));

        locale = new Locale("ps");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));
        locale = new Locale("ps", "AF");
        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            Configuration.getLayoutDirectionFromLocale(locale));

        // The following test will not work as the localized display name would be "Urdu" with ICU 4.4
        // We will need ICU 4.6 to get the correct localized display name
//        locale = new Locale("ur");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));
//        locale = new Locale("ur", "IN");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));
//        locale = new Locale("ur", "PK");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));

        // The following test will not pass until we are able to take care about the scrip subtag
        // thru having the "likelySubTags" file into ICU4C
//        locale = new Locale("uz_Arab");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));
//        locale = new Locale("uz_Arab", "AF");
//        assertEquals(Configuration.LAYOUT_DIRECTION_RTL,
//        assertEquals(Configuration.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
//            Configuration.getLayoutDirectionFromLocale(locale));
    }
}