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

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

Merge "Make View respect LAYOUT_DIRECTION_LOCALE"

parents f74b9bf1 26e432d2
Loading
Loading
Loading
Loading
+30 −1
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Locale;
import java.util.WeakHashMap;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArrayList;


@@ -8665,7 +8666,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit


    /**
    /**
     * Resolving the layout direction. LTR is set initially.
     * Resolving the layout direction. LTR is set initially.
     * We are supposing here that the parent directionality will be resolved before its children
     * We are supposing here that the parent directionality will be resolved before its children.
     */
     */
    private void resolveLayoutDirection() {
    private void resolveLayoutDirection() {
        mPrivateFlags2 &= ~RESOLVED_LAYOUT_RTL;
        mPrivateFlags2 &= ~RESOLVED_LAYOUT_RTL;
@@ -8680,6 +8681,34 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
            case LAYOUT_DIRECTION_RTL:
            case LAYOUT_DIRECTION_RTL:
                mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
                mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
                break;
                break;
            case LAYOUT_DIRECTION_LOCALE:
                if(isLayoutDirectionRtl(Locale.getDefault())) {
                    mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
                }
                break;
            default:
                // Nothing to do, LTR by default
        }
    }

    /**
     * Check if a Locale is corresponding to a RTL script.
     *
     * @param locale Locale to check
     * @return true if a Locale is corresponding to a RTL script.
     */
    private static boolean isLayoutDirectionRtl(Locale locale) {
        if (locale == null || locale.equals(Locale.ROOT)) return false;
        // 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 false;
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
                return true;
            default:
                return false;
        }
        }
    }
    }


+0 −0

Empty file added.

+28 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,13 @@
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>


        <activity android:name=".BiDiTestLinearLayoutLocaleActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name=".BiDiTestFrameLayoutLtrActivity"
        <activity android:name=".BiDiTestFrameLayoutLtrActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
            <intent-filter>
@@ -71,6 +78,13 @@
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>


        <activity android:name=".BiDiTestFrameLayoutLocaleActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name=".BiDiTestRelativeLayoutLtrActivity"
        <activity android:name=".BiDiTestRelativeLayoutLtrActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
            <intent-filter>
@@ -99,6 +113,13 @@
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>


        <activity android:name=".BiDiTestRelativeLayoutLocaleActivity2"
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name=".BiDiTestTableLayoutLtrActivity"
        <activity android:name=".BiDiTestTableLayoutLtrActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
            <intent-filter>
@@ -113,6 +134,13 @@
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>


        <activity android:name=".BiDiTestTableLayoutLocaleActivity"
                  android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

    </application>
    </application>


</manifest>
</manifest>
+88 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/frame_layout_ltr"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layoutDirection="locale"
             android:background="#FF000000">

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="right|center_vertical"
            android:background="#FFFF0000">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="left|center_vertical"
            android:background="#FF00FF00">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="top|center_horizontal"
            android:background="#FF0000FF">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="#FF00FFFF">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="top|start"
            android:background="#FFFFFFFF">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="top|end"
            android:background="#FFFFFF00">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="bottom|start"
            android:background="#FFFFFFFF">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="bottom|end"
            android:background="#FFFFFF00">
    </FrameLayout>

    <FrameLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal|center_vertical"
            android:background="#FF888888">
    </FrameLayout>

</FrameLayout>
+257 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/linear_layout_rtl"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layoutDirection="locale">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="inherit">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="ltr">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="rtl">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="locale">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="inherit">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="ltr">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="rtl">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layoutDirection="locale">

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button1_text"
                android:textSize="24dip"
                />

        <TextView android:id="@+id/textview"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:textSize="24dip"
                  android:text="@string/textview_text"
                />

        <Button android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/button2_text"
                android:textSize="24dip"
                />
    </LinearLayout>

</LinearLayout>
 No newline at end of file
Loading