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

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

Merge "Make Gravity RTL APIs public"

parents 1a22cbd1 e8dc07dc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22105,8 +22105,11 @@ package android.view {
  public class Gravity {
    ctor public Gravity();
    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, android.graphics.Rect, int);
    method public static void apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect);
    method public static void apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect, int);
    method public static void applyDisplay(int, android.graphics.Rect, android.graphics.Rect);
    method public static void applyDisplay(int, android.graphics.Rect, android.graphics.Rect, int);
    method public static int getAbsoluteGravity(int, int);
    method public static boolean isHorizontal(int);
    method public static boolean isVertical(int);
+59 −2
Original line number Diff line number Diff line
@@ -153,7 +153,8 @@ public class Gravity
     *                container.
     * @param layoutDirection The layout direction.
     *
     * @hide
     * @see {@link View#LAYOUT_DIRECTION_LTR}
     * @see {@link View#LAYOUT_DIRECTION_RTL}
     */
    public static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, int layoutDirection) {
@@ -267,6 +268,37 @@ public class Gravity
        }
    }

    /**
     * Apply a gravity constant to an object.
     *
     * @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 xAdj Offset to apply to the X axis.  If gravity is LEFT this
     *             pushes it to the right; if gravity is RIGHT it pushes it to
     *             the left; if gravity is CENTER_HORIZONTAL it pushes it to the
     *             right or left; otherwise it is ignored.
     * @param yAdj Offset to apply to the Y axis.  If gravity is TOP this pushes
     *             it down; if gravity is BOTTOM it pushes it up; if gravity is
     *             CENTER_VERTICAL it pushes it down or up; otherwise it is
     *             ignored.
     * @param outRect Receives the computed frame of the object in its
     *                container.
     * @param layoutDirection The layout direction.
     *
     * @see {@link View#LAYOUT_DIRECTION_LTR}
     * @see {@link View#LAYOUT_DIRECTION_RTL}
     */
    public static void apply(int gravity, int w, int h, Rect container,
                             int xAdj, int yAdj, Rect outRect, int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        apply(absGravity, w, h, container, xAdj, yAdj, outRect);
    }

    /**
     * Apply additional gravity behavior based on the overall "display" that an
     * object exists in.  This can be used after
@@ -321,6 +353,31 @@ public class Gravity
        }
    }

    /**
     * Apply additional gravity behavior based on the overall "display" that an
     * object exists in.  This can be used after
     * {@link #apply(int, int, int, Rect, int, int, Rect)} to place the object
     * within a visible display.  By default this moves or clips the object
     * to be visible in the display; the gravity flags
     * {@link #DISPLAY_CLIP_HORIZONTAL} and {@link #DISPLAY_CLIP_VERTICAL}
     * can be used to change this behavior.
     *
     * @param gravity Gravity constants to modify the placement within the
     * display.
     * @param display The rectangle of the display in which the object is
     * being placed.
     * @param inoutObj Supplies the current object position; returns with it
     * modified if needed to fit in the display.
     * @param layoutDirection The layout direction.
     *
     * @see {@link View#LAYOUT_DIRECTION_LTR}
     * @see {@link View#LAYOUT_DIRECTION_RTL}
     */
    public static void applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        applyDisplay(absGravity, display, inoutObj);
    }

    /**
     * <p>Indicate whether the supplied gravity has a vertical pull.</p>
     *
+2 −2
Original line number Diff line number Diff line
@@ -9819,8 +9819,8 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     *
     * @param layoutDirection the direction of the layout
     *
     * {@link #LAYOUT_DIRECTION_LTR}
     * {@link #LAYOUT_DIRECTION_RTL}
     * @see {@link #LAYOUT_DIRECTION_LTR}
     * @see {@link #LAYOUT_DIRECTION_RTL}
     */
    public void onPaddingChanged(int layoutDirection) {
    }
+0 −74
Original line number Diff line number Diff line
/*
 * 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.
 */

package android.view;

import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

public class GravityTest extends AndroidTestCase {

    @SmallTest
    public void testGetAbsoluteGravity() throws Exception {
        assertOneGravity(Gravity.LEFT, Gravity.LEFT, false);
        assertOneGravity(Gravity.LEFT, Gravity.LEFT, true);

        assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, false);
        assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, true);

        assertOneGravity(Gravity.TOP, Gravity.TOP, false);
        assertOneGravity(Gravity.TOP, Gravity.TOP, true);

        assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, false);
        assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, true);

        assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, false);
        assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, true);

        assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, false);
        assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, true);

        assertOneGravity(Gravity.CENTER, Gravity.CENTER, false);
        assertOneGravity(Gravity.CENTER, Gravity.CENTER, true);

        assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, false);
        assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, true);

        assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, false);
        assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, true);

        assertOneGravity(Gravity.FILL, Gravity.FILL, false);
        assertOneGravity(Gravity.FILL, Gravity.FILL, true);

        assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, false);
        assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, true);

        assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, false);
        assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, true);

        assertOneGravity(Gravity.LEFT, Gravity.START, false);
        assertOneGravity(Gravity.RIGHT, Gravity.START, true);

        assertOneGravity(Gravity.RIGHT, Gravity.END, false);
        assertOneGravity(Gravity.LEFT, Gravity.END, true);
    }

    private void assertOneGravity(int expected, int initial, boolean isRtl) {
        final int layoutDirection = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;

        assertEquals(expected, Gravity.getAbsoluteGravity(initial, layoutDirection));
    }
}