summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2012-03-09 17:10:19 -0800
committerFabrice Di Meglio <fdimeglio@google.com>2012-03-09 17:32:16 -0800
commite8dc07dcdb983d5d3999b16c2a49ddee4bdb942c (patch)
treefa3501d60b3caee9b10a511ffa4d88c6ba57e720 /core
parent3bef5e9f3aa90465ee3ab66ef33d7a88d1b0c5c1 (diff)
downloadframeworks_base-e8dc07dcdb983d5d3999b16c2a49ddee4bdb942c.zip
frameworks_base-e8dc07dcdb983d5d3999b16c2a49ddee4bdb942c.tar.gz
frameworks_base-e8dc07dcdb983d5d3999b16c2a49ddee4bdb942c.tar.bz2
Make Gravity RTL APIs public
- also move unit tests to CTS - also small improvement for View Javadoc Change-Id: I166d5a10f4a00f1b46c90468c8b11906b438e1ea
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/Gravity.java61
-rw-r--r--core/java/android/view/View.java4
-rw-r--r--core/tests/coretests/src/android/view/GravityTest.java74
3 files changed, 61 insertions, 78 deletions
diff --git a/core/java/android/view/Gravity.java b/core/java/android/view/Gravity.java
index 63f5ec1..f031fe7 100644
--- a/core/java/android/view/Gravity.java
+++ b/core/java/android/view/Gravity.java
@@ -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) {
@@ -268,6 +269,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
* {@link #apply(int, int, int, Rect, int, int, Rect)} to place the object
@@ -320,7 +352,32 @@ 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>
*
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 94531c8..adb13dc 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -9719,8 +9719,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) {
}
diff --git a/core/tests/coretests/src/android/view/GravityTest.java b/core/tests/coretests/src/android/view/GravityTest.java
deleted file mode 100644
index d8ef650..0000000
--- a/core/tests/coretests/src/android/view/GravityTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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));
- }
-}