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

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

Merge "Add support for Gravity BEFORE and AFTER"

parents 0a266a18 6a036405
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -8331,6 +8331,7 @@ package android.graphics.drawable {
    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();
@@ -8361,6 +8362,10 @@ package android.graphics.drawable {
    method public abstract void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);
  }
  public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback {
    method public abstract boolean isLayoutRtl(android.graphics.drawable.Drawable);
  }
  public static abstract class Drawable.ConstantState {
    ctor public Drawable.ConstantState();
    method public abstract int getChangingConfigurations();
@@ -20136,14 +20141,17 @@ 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 boolean isHorizontal(int);
    method public static boolean isVertical(int);
    field public static final int AFTER = 8388613; // 0x800005
    field public static final int AXIS_CLIP = 8; // 0x8
    field public static final int AXIS_PULL_AFTER = 4; // 0x4
    field public static final int AXIS_PULL_BEFORE = 2; // 0x2
    field public static final int AXIS_SPECIFIED = 1; // 0x1
    field public static final int AXIS_X_SHIFT = 0; // 0x0
    field public static final int AXIS_Y_SHIFT = 4; // 0x4
    field public static final int BEFORE = 8388611; // 0x800003
    field public static final int BOTTOM = 80; // 0x50
    field public static final int CENTER = 17; // 0x11
    field public static final int CENTER_HORIZONTAL = 1; // 0x1
@@ -20158,6 +20166,8 @@ package android.view {
    field public static final int HORIZONTAL_GRAVITY_MASK = 7; // 0x7
    field public static final int LEFT = 3; // 0x3
    field public static final int NO_GRAVITY = 0; // 0x0
    field public static final int RELATIVE_HORIZONTAL_DIRECTION = 8388608; // 0x800000
    field public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = 8388615; // 0x800007
    field public static final int RIGHT = 5; // 0x5
    field public static final int TOP = 48; // 0x30
    field public static final int VERTICAL_GRAVITY_MASK = 112; // 0x70
@@ -21136,7 +21146,7 @@ package android.view {
    method public void recycle();
  }
  public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
  public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback2 android.view.KeyEvent.Callback {
    ctor public View(android.content.Context);
    ctor public View(android.content.Context, android.util.AttributeSet);
    ctor public View(android.content.Context, android.util.AttributeSet, int);
@@ -21322,6 +21332,7 @@ package android.view {
    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();
+90 −7
Original line number Diff line number Diff line
@@ -81,8 +81,11 @@ public class Gravity
     *  horizontal axis. */
    public static final int CLIP_HORIZONTAL = AXIS_CLIP<<AXIS_X_SHIFT;

    /** Raw bit controlling whether the horizontal direction is relative (before/after) or not. */
    public static final int RELATIVE_HORIZONTAL_DIRECTION = 0x00800000;

    /**
     * Binary mask to get the horizontal gravity of a gravity.
     * Binary mask to get the absolute horizontal gravity of a gravity.
     */
    public static final int HORIZONTAL_GRAVITY_MASK = (AXIS_SPECIFIED |
            AXIS_PULL_BEFORE | AXIS_PULL_AFTER) << AXIS_X_SHIFT;
@@ -106,8 +109,19 @@ public class Gravity
     */
    public static final int DISPLAY_CLIP_HORIZONTAL = 0x01000000;
    
    /** Push object to x-axis position before its container, not changing its size. */
    public static final int BEFORE = RELATIVE_HORIZONTAL_DIRECTION | LEFT;

    /** Push object to x-axis position after its container, not changing its size. */
    public static final int AFTER = RELATIVE_HORIZONTAL_DIRECTION | RIGHT;

    /**
     * Apply a gravity constant to an object.
     * Binary mask for the horizontal gravity and script specific direction bit.
     */
    public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = BEFORE | AFTER;

    /**
     * Apply a gravity constant to an object. This suppose that the layout direction is LTR.
     * 
     * @param gravity The desired placement of the object, as defined by the
     *                constants in this class.
@@ -119,11 +133,32 @@ public class Gravity
     * @param outRect Receives the computed frame of the object in its
     *                container.
     */
    public static void apply(int gravity, int w, int h, Rect container,
                             Rect outRect) {
    public static void apply(int gravity, int w, int h, Rect container, Rect outRect) {
        apply(gravity, w, h, container, 0, 0, outRect);
    }

    /**
     * Apply a gravity constant to an object and take care if layout direction is RTL or not.
     *
     * @param gravity The desired placement of the object, as defined by the
     *                constants in this class.
     * @param w The horizontal size of the object.
     * @param h The vertical size of the object.
     * @param container The frame of the containing space, in which the object
     *                  will be placed.  Should be large enough to contain the
     *                  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.
     *
     * @hide
     */
    public static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, boolean isRtl) {
        int absGravity = getAbsoluteGravity(gravity, isRtl);
        apply(absGravity, w, h, container, 0, 0, outRect);
    }

    /**
     * Apply a gravity constant to an object.
     * 
@@ -301,6 +336,54 @@ public class Gravity
     * @return true if the supplied gravity has an horizontal pull
     */
    public static boolean isHorizontal(int gravity) {
        return gravity > 0 && (gravity & HORIZONTAL_GRAVITY_MASK) != 0;
        return gravity > 0 && (gravity & RELATIVE_HORIZONTAL_GRAVITY_MASK) != 0;
    }

    /**
     * <p>Convert script specific gravity to absolute horizontal value.</p>
     *
     * if horizontal direction is LTR, then BEFORE will set LEFT and AFTER will set RIGHT.
     * if horizontal direction is RTL, then BEFORE will set RIGHT and AFTER will set LEFT.
     *
     * If no horizontal direction is found, then just add LEFT to the existing gravity
     *
     * @param gravity The gravity to convert to absolute (horizontal) values.
     * @param isRtl Whether the layout is right-to-left.
     * @return gravity converted to absolute (horizontal) values.
     */
    public static int getAbsoluteGravity(int gravity, boolean isRtl) {
        int result = gravity;
        // Set default gravity, if no horizontal gravity is specified
        if ((result & HORIZONTAL_GRAVITY_MASK) == 0) {
            result |= Gravity.LEFT;
        }
        // If layout is script specific and gravity is horizontal relative (BEFORE or AFTER)
        if ((result & RELATIVE_HORIZONTAL_DIRECTION) > 0) {
            if ((result & Gravity.BEFORE) == Gravity.BEFORE) {
                // Remove the BEFORE bit
                result &= ~BEFORE;
                if (isRtl) {
                    // Set the RIGHT bit
                    result |= RIGHT;
                } else {
                    // Set the LEFT bit
                    result |= LEFT;
                }
            } else if ((result & Gravity.AFTER) == Gravity.AFTER) {
                // Remove the AFTER bit
                result &= ~AFTER;
                if (isRtl) {
                    // Set the LEFT bit
                    result |= LEFT;
                } else {
                    // Set the RIGHT bit
                    result |= RIGHT;
                }
            }
            // Don't need the script specific bit any more, so remove it as we are converting to
            // absolute values (LEFT or RIGHT)
            result &= ~RELATIVE_HORIZONTAL_DIRECTION;
        }
        return result;
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -631,7 +631,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 *
 * @see android.view.ViewGroup
 */
public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource {
public class View implements Drawable.Callback2, KeyEvent.Callback, AccessibilityEventSource {
    private static final boolean DBG = false;

    /**
@@ -10238,6 +10238,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        }
    }

     /**
     * Check if a given Drawable is in RTL layout direction.
     *
     * @param who the recipient of the action
     */
    public boolean isLayoutRtl(Drawable who) {
        return (who == mBGDrawable) && isLayoutRtl();
    }

    /**
     * If your view subclass is displaying its own Drawable objects, it should
     * override this function and return true for any Drawable it is
+2 −2
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ public interface WindowManager extends ViewManager {
            implements Parcelable {
        /**
         * X position for this window.  With the default gravity it is ignored.
         * When using {@link Gravity#LEFT} or {@link Gravity#RIGHT} it provides
         * an offset from the given edge.
         * When using {@link Gravity#LEFT} or {@link Gravity#BEFORE} or {@link Gravity#RIGHT} or
         * {@link Gravity#AFTER} it provides an offset from the given edge.
         */
        @ViewDebug.ExportedProperty
        public int x;
+5 −5
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ public class FrameLayout extends ViewGroup {
    }

    /**
     * Describes how the foreground is positioned. Defaults to FILL.
     * Describes how the foreground is positioned. Defaults to BEFORE and TOP.
     *
     * @param foregroundGravity See {@link android.view.Gravity}
     *
@@ -124,8 +124,8 @@ public class FrameLayout extends ViewGroup {
    @android.view.RemotableViewMethod
    public void setForegroundGravity(int foregroundGravity) {
        if (mForegroundGravity != foregroundGravity) {
            if ((foregroundGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
                foregroundGravity |= Gravity.LEFT;
            if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
                foregroundGravity |= Gravity.BEFORE;
            }

            if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
@@ -364,7 +364,7 @@ public class FrameLayout extends ViewGroup {
                    gravity = DEFAULT_CHILD_GRAVITY;
                }

                final int horizontalGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (horizontalGravity) {
@@ -436,7 +436,7 @@ public class FrameLayout extends ViewGroup {
                }

                Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds);
                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds, isLayoutRtl());
                foreground.setBounds(overlayBounds);
            }
            
Loading