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

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

Merge "Add View.getResolvedLayoutDirection()"

parents 051d16eb c0053223
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -8512,11 +8512,11 @@ package android.graphics.drawable {
    method public int getMinimumWidth();
    method public abstract int getOpacity();
    method public boolean getPadding(android.graphics.Rect);
    method public int getResolvedLayoutDirectionSelf();
    method public int[] getState();
    method public android.graphics.Region getTransparentRegion();
    method public void inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
    method public void invalidateSelf();
    method public boolean isLayoutRtlSelf();
    method public boolean isStateful();
    method public final boolean isVisible();
    method public void jumpToCurrentState();
@@ -8548,7 +8548,7 @@ package android.graphics.drawable {
  }
  public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback {
    method public abstract boolean isLayoutRtl(android.graphics.drawable.Drawable);
    method public abstract int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
  }
  public static abstract class Drawable.ConstantState {
@@ -20583,7 +20583,7 @@ package android.view {
    method public static void apply(int, int, int, android.graphics.Rect, android.graphics.Rect);
    method public static void apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect);
    method public static void applyDisplay(int, android.graphics.Rect, android.graphics.Rect);
    method public static int getAbsoluteGravity(int, boolean);
    method public static int getAbsoluteGravity(int, int);
    method public static boolean isHorizontal(int);
    method public static boolean isVertical(int);
    field public static final int AXIS_CLIP = 8; // 0x8
@@ -21724,6 +21724,7 @@ package android.view {
    method public final android.view.ViewParent getParent();
    method public float getPivotX();
    method public float getPivotY();
    method public int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
    method public android.content.res.Resources getResources();
    method public final int getRight();
    method protected float getRightFadingEdgeStrength();
@@ -21789,8 +21790,6 @@ package android.view {
    method public boolean isInEditMode();
    method public boolean isInTouchMode();
    method public boolean isLayoutRequested();
    method public boolean isLayoutRtl();
    method public boolean isLayoutRtl(android.graphics.drawable.Drawable);
    method public boolean isLongClickable();
    method public boolean isOpaque();
    method protected boolean isPaddingOffsetRequired();
+8 −7
Original line number Diff line number Diff line
@@ -151,13 +151,13 @@ public class Gravity
     *                  width and height of the object.
     * @param outRect Receives the computed frame of the object in its
     *                container.
     * @param isRtl Whether the layout is right-to-left.
     * @param layoutDirection The layout direction.
     *
     * @hide
     */
    public static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, boolean isRtl) {
        int absGravity = getAbsoluteGravity(gravity, isRtl);
            Rect outRect, int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        apply(absGravity, w, h, container, 0, 0, outRect);
    }

@@ -347,18 +347,19 @@ public class Gravity
     * if horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
     * if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
     *
     *
     * @param gravity The gravity to convert to absolute (horizontal) values.
     * @param isRtl Whether the layout is right-to-left.
     * @param layoutDirection The layout direction.
     * @return gravity converted to absolute (horizontal) values.
     */
    public static int getAbsoluteGravity(int gravity, boolean isRtl) {
    public static int getAbsoluteGravity(int gravity, int layoutDirection) {
        int result = gravity;
        // If layout is script specific and gravity is horizontal relative (START or END)
        if ((result & RELATIVE_LAYOUT_DIRECTION) > 0) {
            if ((result & Gravity.START) == Gravity.START) {
                // Remove the START bit
                result &= ~START;
                if (isRtl) {
                if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                    // Set the RIGHT bit
                    result |= RIGHT;
                } else {
@@ -368,7 +369,7 @@ public class Gravity
            } else if ((result & Gravity.END) == Gravity.END) {
                // Remove the END bit
                result &= ~END;
                if (isRtl) {
                if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                    // Set the LEFT bit
                    result |= LEFT;
                } else {
+45 −20
Original line number Diff line number Diff line
@@ -4272,6 +4272,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
     *   {@link #LAYOUT_DIRECTION_INHERIT} or
     *   {@link #LAYOUT_DIRECTION_LOCALE}.
     * @attr ref android.R.styleable#View_layoutDirection
     *
     * @hide
     */
    @ViewDebug.ExportedProperty(category = "layout", mapping = {
@@ -4292,6 +4293,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
     *   {@link #LAYOUT_DIRECTION_INHERIT} or
     *   {@link #LAYOUT_DIRECTION_LOCALE}.
     * @attr ref android.R.styleable#View_layoutDirection
     *
     * @hide
     */
    @RemotableViewMethod
@@ -4299,6 +4301,37 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
        setFlags(layoutDirection, LAYOUT_DIRECTION_MASK);
    }

    /**
     * Returns the resolved layout direction for this view.
     *
     * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns
     * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL.
     *
     * @hide
     */
    @ViewDebug.ExportedProperty(category = "layout", mapping = {
        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR,     to = "RESOLVED_DIRECTION_LTR"),
        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL,     to = "RESOLVED_DIRECTION_RTL")
    })
    public int getResolvedLayoutDirection() {
        resolveLayoutDirection();
        return ((mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL) ?
                LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
    }

    /**
     * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
     * layout attribute and/or the inherited value from the parent.</p>
     *
     * @return true if the layout is right-to-left.
     *
     * @hide
     */
    @ViewDebug.ExportedProperty(category = "layout")
    public boolean isLayoutRtl() {
        return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL);
    }

    /**
     * If this view doesn't do any drawing on its own, set this flag to
     * allow further optimizations. By default, this flag is not set on
@@ -8713,8 +8746,9 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
        switch (getLayoutDirection()) {
            case LAYOUT_DIRECTION_INHERIT:
                // If this is root view, no need to look at parent's layout dir.
                if (mParent != null && mParent instanceof ViewGroup &&
                        ((ViewGroup) mParent).isLayoutRtl()) {
                if (mParent != null &&
                        mParent instanceof ViewGroup &&
                        ((ViewGroup) mParent).getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                    mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
                }
                break;
@@ -10236,17 +10270,6 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
        return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT;
    }

    /**
     * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
     * layout attribute and/or the inherited value from the parent.</p>
     *
     * @return true if the layout is right-to-left.
     */
    @ViewDebug.ExportedProperty(category = "layout")
    public boolean isLayoutRtl() {
        return (mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL;
    }

    /**
     * Assign a size and position to a view and all of its
     * descendants
@@ -10460,12 +10483,14 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
    }

    /**
     * Check if a given Drawable is in RTL layout direction.
    * Return the layout direction of a given Drawable.
    *
     * @param who the recipient of the action
    * @param who the Drawable to query
    *
    * @hide
    */
    public boolean isLayoutRtl(Drawable who) {
        return (who == mBGDrawable) && isLayoutRtl();
    public int getResolvedLayoutDirection(Drawable who) {
        return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
    }

    /**
+5 −2
Original line number Diff line number Diff line
@@ -364,7 +364,8 @@ public class FrameLayout extends ViewGroup {
                    gravity = DEFAULT_CHILD_GRAVITY;
                }

                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
                final int layoutDirection = getResolvedLayoutDirection();
                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
@@ -435,8 +436,10 @@ public class FrameLayout extends ViewGroup {
                    selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom);
                }

                final int layoutDirection = getResolvedLayoutDirection();
                Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds, isLayoutRtl());
                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds,
                        layoutDirection);
                foreground.setBounds(overlayBounds);
            }
            
+2 −1
Original line number Diff line number Diff line
@@ -1408,7 +1408,8 @@ public class GridView extends AbsListView {
        int childLeft;
        final int childTop = flow ? y : y - h;

        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity,isLayoutRtl());
        final int layoutDirection = getResolvedLayoutDirection();
        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
            case Gravity.LEFT:
                childLeft = childrenLeft;
Loading