Make Gravity RTL APIs public

- also move unit tests to CTS
- also small improvement for View Javadoc

Change-Id: I166d5a10f4a00f1b46c90468c8b11906b438e1ea
diff --git a/api/current.txt b/api/current.txt
index dbe57d1..d410492 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -10782,8 +10782,8 @@
 
   public class MediaActionSound {
     ctor public MediaActionSound();
-    method public void load(int);
-    method public void play(int);
+    method public synchronized void load(int);
+    method public synchronized void play(int);
     method public void release();
     field public static final int FOCUS_COMPLETE = 1; // 0x1
     field public static final int SHUTTER_CLICK = 0; // 0x0
@@ -22096,8 +22096,11 @@
   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);
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 @@
      *                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 @@
     }
 
     /**
+     * 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 @@
             }
         }
     }
-    
+
+    /**
+     * 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 @@
      *
      * @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));
-    }
-}