diff options
-rw-r--r-- | api/current.txt | 2 | ||||
-rw-r--r-- | core/java/android/view/View.java | 4 | ||||
-rw-r--r-- | core/java/android/view/ViewGroup.java | 145 | ||||
-rwxr-xr-x | core/res/res/values/attrs.xml | 6 | ||||
-rw-r--r-- | core/res/res/values/public.xml | 3 | ||||
-rw-r--r-- | tests/BiDiTests/res/layout/view_group_margin_mixed.xml | 241 | ||||
-rw-r--r-- | tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java | 19 | ||||
-rw-r--r-- | tests/BiDiTests/src/com/android/bidi/BiDiTestViewGroupMarginMixed.java | 17 |
8 files changed, 425 insertions, 12 deletions
diff --git a/api/current.txt b/api/current.txt index 2ad044e..d17ac52 100644 --- a/api/current.txt +++ b/api/current.txt @@ -601,8 +601,10 @@ package android { field public static final int layout_height = 16842997; // 0x10100f5 field public static final int layout_margin = 16842998; // 0x10100f6 field public static final int layout_marginBottom = 16843002; // 0x10100fa + field public static final int layout_marginEnd = 16843675; // 0x101039b field public static final int layout_marginLeft = 16842999; // 0x10100f7 field public static final int layout_marginRight = 16843001; // 0x10100f9 + field public static final int layout_marginStart = 16843674; // 0x101039a field public static final int layout_marginTop = 16843000; // 0x10100f8 field public static final int layout_row = 16843643; // 0x101037b field public static final int layout_rowSpan = 16843644; // 0x101037c diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 0413b05..7e75c4e 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -11830,6 +11830,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit mPrivateFlags |= FORCE_LAYOUT; mPrivateFlags |= INVALIDATED; + if (mLayoutParams != null) { + mLayoutParams.resolveWithDirection(getResolvedLayoutDirection()); + } + if (mParent != null && !mParent.isLayoutRequested()) { mParent.requestLayout(); } diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index a21f8bb..6405398 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -5175,6 +5175,21 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } /** + * Resolve layout parameters depending on the layout direction. Subclasses that care about + * layoutDirection changes should override this method. The default implementation does + * nothing. + * + * @param layoutDirection the direction of the layout + * + * {@link View#LAYOUT_DIRECTION_LTR} + * {@link View#LAYOUT_DIRECTION_RTL} + * + * @hide + */ + protected void resolveWithDirection(int layoutDirection) { + } + + /** * Returns a String representation of this set of layout parameters. * * @param output the String to prepend to the internal representation @@ -5215,30 +5230,56 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager */ public static class MarginLayoutParams extends ViewGroup.LayoutParams { /** - * The left margin in pixels of the child. + * The left margin in pixels of the child. Whenever this value is changed, a call to + * {@link android.view.View#requestLayout()} needs to be done. */ @ViewDebug.ExportedProperty(category = "layout") public int leftMargin; /** - * The top margin in pixels of the child. + * The top margin in pixels of the child. Whenever this value is changed, a call to + * {@link android.view.View#requestLayout()} needs to be done. */ @ViewDebug.ExportedProperty(category = "layout") public int topMargin; /** - * The right margin in pixels of the child. + * The right margin in pixels of the child. Whenever this value is changed, a call to + * {@link android.view.View#requestLayout()} needs to be done. */ @ViewDebug.ExportedProperty(category = "layout") public int rightMargin; /** - * The bottom margin in pixels of the child. + * The bottom margin in pixels of the child. Whenever this value is changed, a call to + * {@link android.view.View#requestLayout()} needs to be done. */ @ViewDebug.ExportedProperty(category = "layout") public int bottomMargin; /** + * The start margin in pixels of the child. + * + * @hide + * + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int startMargin = DEFAULT_RELATIVE; + + /** + * The end margin in pixels of the child. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int endMargin = DEFAULT_RELATIVE; + + /** + * The default start and end margin. + */ + static private final int DEFAULT_RELATIVE = Integer.MIN_VALUE; + + /** * Creates a new set of layout parameters. The values are extracted from * the supplied attributes set and context. * @@ -5270,6 +5311,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager R.styleable.ViewGroup_MarginLayout_layout_marginRight, 0); bottomMargin = a.getDimensionPixelSize( R.styleable.ViewGroup_MarginLayout_layout_marginBottom, 0); + startMargin = a.getDimensionPixelSize( + R.styleable.ViewGroup_MarginLayout_layout_marginStart, DEFAULT_RELATIVE); + endMargin = a.getDimensionPixelSize( + R.styleable.ViewGroup_MarginLayout_layout_marginEnd, DEFAULT_RELATIVE); } a.recycle(); @@ -5295,6 +5340,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager this.topMargin = source.topMargin; this.rightMargin = source.rightMargin; this.bottomMargin = source.bottomMargin; + this.startMargin = source.startMargin; + this.endMargin = source.endMargin; } /** @@ -5305,7 +5352,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } /** - * Sets the margins, in pixels. + * Sets the margins, in pixels. A call to {@link android.view.View#requestLayout()} needs + * to be done so that the new margins are taken into account. Left and right margins may be + * overriden by {@link android.view.View#requestLayout()} depending on layout direction. * * @param left the left margin size * @param top the top margin size @@ -5323,6 +5372,92 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager rightMargin = right; bottomMargin = bottom; } + + /** + * Sets the relative margins, in pixels. A call to {@link android.view.View#requestLayout()} + * needs to be done so that the new relative margins are taken into account. Left and right + * margins may be overriden by {@link android.view.View#requestLayout()} depending on layout + * direction. + * + * @param start the start margin size + * @param top the top margin size + * @param end the right margin size + * @param bottom the bottom margin size + * + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginTop + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginBottom + * + * @hide + */ + public void setMarginsRelative(int start, int top, int end, int bottom) { + startMargin = start; + topMargin = top; + endMargin = end; + bottomMargin = bottom; + } + + /** + * Returns the start margin in pixels. + * + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart + * + * @return the start margin in pixels. + * + * @hide + */ + public int getMarginStart() { + return startMargin; + } + + /** + * Returns the end margin in pixels. + * + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd + * + * @return the end margin in pixels. + * + * @hide + */ + public int getMarginEnd() { + return endMargin; + } + + /** + * Check if margins are relative. + * + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart + * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd + * + * @return true if either marginStart or marginEnd has been set + * + * @hide + */ + public boolean isMarginRelative() { + return (startMargin != DEFAULT_RELATIVE) || (endMargin != DEFAULT_RELATIVE); + } + + /** + * This will be called by {@link android.view.View#requestLayout()}. Left and Right margins + * maybe overriden depending on layout direction. + * + * @hide + */ + @Override + protected void resolveWithDirection(int layoutDirection) { + switch(layoutDirection) { + case View.LAYOUT_DIRECTION_RTL: + leftMargin = (endMargin > DEFAULT_RELATIVE) ? endMargin : leftMargin; + rightMargin = (startMargin > DEFAULT_RELATIVE) ? startMargin : rightMargin; + break; + case View.LAYOUT_DIRECTION_LTR: + default: + leftMargin = (startMargin > DEFAULT_RELATIVE) ? startMargin : leftMargin; + rightMargin = (endMargin > DEFAULT_RELATIVE) ? endMargin : rightMargin; + break; + } + } } /* Describes a touched view and the ids of the pointers that it has captured. diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 58d25d6..2f714f6 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2125,6 +2125,12 @@ <!-- Specifies extra space on the bottom side of this view. This space is outside this view's bounds. --> <attr name="layout_marginBottom" format="dimension" /> + <!-- Specifies extra space on the start side of this view. + This space is outside this view's bounds. --> + <attr name="layout_marginStart" format="dimension" /> + <!-- Specifies extra space on the end side of this view. + This space is outside this view's bounds. --> + <attr name="layout_marginEnd" format="dimension" /> </declare-styleable> <!-- Use <code>input-method</code> as the root tag of the XML resource that diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 580c204..ec191dd 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1778,4 +1778,7 @@ <public type="attr" name="paddingStart"/> <public type="attr" name="paddingEnd"/> + <public type="attr" name="layout_marginStart"/> + <public type="attr" name="layout_marginEnd"/> + </resources> diff --git a/tests/BiDiTests/res/layout/view_group_margin_mixed.xml b/tests/BiDiTests/res/layout/view_group_margin_mixed.xml new file mode 100644 index 0000000..5845b38 --- /dev/null +++ b/tests/BiDiTests/res/layout/view_group_margin_mixed.xml @@ -0,0 +1,241 @@ +<?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/view_group_margin_mixed" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="#FFFFFFFF"> + + <LinearLayout android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <LinearLayout android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layoutDirection="ltr"> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF0000FF"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="0dip" + android:layout_marginRight="0dip" + android:layout_marginTop="0dip" + android:layout_marginBottom="0dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF000000"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="10dip" + android:layout_marginStart="5dip" + android:layout_marginRight="20dip" + android:layout_marginEnd="5dip" + android:layout_marginTop="5dip" + android:layout_marginBottom="5dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + </LinearLayout> + + <LinearLayout android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layoutDirection="rtl"> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF0000FF"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="0dip" + android:layout_marginRight="0dip" + android:layout_marginTop="0dip" + android:layout_marginBottom="0dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF000000"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="10dip" + android:layout_marginStart="5dip" + android:layout_marginRight="20dip" + android:layout_marginEnd="5dip" + android:layout_marginTop="5dip" + android:layout_marginBottom="5dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + </LinearLayout> + + <LinearLayout android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layoutDirection="inherit"> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF0000FF"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="0dip" + android:layout_marginRight="0dip" + android:layout_marginTop="0dip" + android:layout_marginBottom="0dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF000000"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="10dip" + android:layout_marginStart="5dip" + android:layout_marginRight="20dip" + android:layout_marginEnd="5dip" + android:layout_marginTop="5dip" + android:layout_marginBottom="5dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + </LinearLayout> + + <LinearLayout android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layoutDirection="locale"> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF0000FF"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="0dip" + android:layout_marginRight="0dip" + android:layout_marginTop="0dip" + android:layout_marginBottom="0dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + <LinearLayout android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#FF000000"> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_marginLeft="10dip" + android:layout_marginStart="5dip" + android:layout_marginRight="20dip" + android:layout_marginEnd="5dip" + android:layout_marginTop="5dip" + android:layout_marginBottom="5dip" + android:background="#FFFF0000"> + </FrameLayout> + + <FrameLayout + android:layout_width="80dp" + android:layout_height="80dp" + android:background="#FF00FF00"> + </FrameLayout> + </LinearLayout> + + </LinearLayout> + + </LinearLayout> + +</FrameLayout>
\ No newline at end of file diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java index c2683c2..b1e494a 100644 --- a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java @@ -106,29 +106,34 @@ public class BiDiTestActivity extends Activity { addItem(result, "Linear LTR", BiDiTestLinearLayoutLtr.class, R.id.linear_layout_ltr); addItem(result, "Linear RTL", BiDiTestLinearLayoutRtl.class, R.id.linear_layout_rtl); addItem(result, "Linear LOC", BiDiTestLinearLayoutLocale.class, R.id.linear_layout_locale); - + addItem(result, "Frame LTR", BiDiTestFrameLayoutLtr.class, R.id.frame_layout_ltr); addItem(result, "Frame RTL", BiDiTestFrameLayoutRtl.class, R.id.frame_layout_rtl); addItem(result, "Frame LOC", BiDiTestFrameLayoutLocale.class, R.id.frame_layout_locale); - + addItem(result, "Relative LTR", BiDiTestRelativeLayoutLtr.class, R.id.relative_layout_ltr); addItem(result, "Relative RTL", BiDiTestRelativeLayoutRtl.class, R.id.relative_layout_rtl); - + addItem(result, "Relative2 LTR", BiDiTestRelativeLayout2Ltr.class, R.id.relative_layout_2_ltr); addItem(result, "Relative2 RTL", BiDiTestRelativeLayout2Rtl.class, R.id.relative_layout_2_rtl); addItem(result, "Relative2 LOC", BiDiTestRelativeLayout2Locale.class, R.id.relative_layout_2_locale); - + addItem(result, "Table LTR", BiDiTestTableLayoutLtr.class, R.id.table_layout_ltr); addItem(result, "Table RTL", BiDiTestTableLayoutRtl.class, R.id.table_layout_rtl); addItem(result, "Table LOC", BiDiTestTableLayoutLocale.class, R.id.table_layout_locale); + addItem(result, "ViewPadding", BiDiTestViewPadding.class, R.id.view_padding); + addItem(result, "ViewPadding MIXED", BiDiTestViewPaddingMixed.class, R.id.view_padding_mixed); + + addItem(result, "Padding", BiDiTestViewPadding.class, R.id.view_padding); + addItem(result, "Padding MIXED", BiDiTestViewPaddingMixed.class, R.id.view_padding_mixed); + + addItem(result, "Margin MIXED", BiDiTestViewGroupMarginMixed.class, R.id.view_group_margin_mixed); + addItem(result, "TextView LTR", BiDiTestTextViewLtr.class, R.id.textview_ltr); addItem(result, "TextView RTL", BiDiTestTextViewRtl.class, R.id.textview_rtl); addItem(result, "TextView LOC", BiDiTestTextViewLocale.class, R.id.textview_locale); - addItem(result, "ViewPadding", BiDiTestViewPadding.class, R.id.view_padding); - addItem(result, "ViewPadding MIXED", BiDiTestViewPaddingMixed.class, R.id.view_padding_mixed); - return result; } diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestViewGroupMarginMixed.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewGroupMarginMixed.java new file mode 100644 index 0000000..ce8c380 --- /dev/null +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewGroupMarginMixed.java @@ -0,0 +1,17 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +package com.android.bidi; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class BiDiTestViewGroupMarginMixed extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.view_group_margin_mixed, container, false); + } +} |