@Test public void testApplyNoOffsetsRtl() { Rect outRect = new Rect(); GravityCompat.apply(Gravity.LEFT | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Left / top aligned under RTL: ", outRect, 0, 0, 100, 50); GravityCompat.apply(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Center / top aligned under RTL: ", outRect, 50, 0, 150, 50); GravityCompat.apply(Gravity.RIGHT | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Right / top aligned under RTL: ", outRect, 100, 0, 200, 50); GravityCompat.apply(Gravity.LEFT | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Left / center aligned under RTL: ", outRect, 0, 25, 100, 75); GravityCompat.apply(Gravity.CENTER, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Center / center aligned under RTL: ", outRect, 50, 25, 150, 75); GravityCompat.apply(Gravity.RIGHT | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Right / center aligned under RTL: ", outRect, 100, 25, 200, 75); GravityCompat.apply(Gravity.LEFT | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Left / bottom aligned under RTL: ", outRect, 0, 50, 100, 100); GravityCompat.apply(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Center / bottom aligned under RTL: ", outRect, 50, 50, 150, 100); GravityCompat.apply(Gravity.RIGHT | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Right / bottom aligned under RTL: ", outRect, 100, 50, 200, 100); if (Build.VERSION.SDK_INT >= 17) { GravityCompat.apply(GravityCompat.START | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / top aligned under RTL: ", outRect, 100, 0, 200, 50); GravityCompat.apply(GravityCompat.END | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / top aligned under RTL: ", outRect, 0, 0, 100, 50); GravityCompat.apply(GravityCompat.START | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / center aligned under RTL: ", outRect, 100, 25, 200, 75); GravityCompat.apply(GravityCompat.END | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / center aligned under RTL: ", outRect, 0, 25, 100, 75); GravityCompat.apply(GravityCompat.START | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / bottom aligned under RTL: ", outRect, 100, 50, 200, 100); GravityCompat.apply(GravityCompat.END | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / bottom aligned under RTL: ", outRect, 0, 50, 100, 100); } else { GravityCompat.apply(GravityCompat.START | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / top aligned under RTL: ", outRect, 0, 0, 100, 50); GravityCompat.apply(GravityCompat.END | Gravity.TOP, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / top aligned under RTL: ", outRect, 100, 0, 200, 50); GravityCompat.apply(GravityCompat.START | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / center aligned under RTL: ", outRect, 0, 25, 100, 75); GravityCompat.apply(GravityCompat.END | Gravity.CENTER_VERTICAL, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / center aligned under RTL: ", outRect, 100, 25, 200, 75); GravityCompat.apply(GravityCompat.START | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("Start / bottom aligned under RTL: ", outRect, 0, 50, 100, 100); GravityCompat.apply(GravityCompat.END | Gravity.BOTTOM, 100, 50, new Rect(0, 0, 200, 100), outRect, ViewCompat.LAYOUT_DIRECTION_RTL); TestUtils.assertRectangleBounds("End / bottom aligned under RTL: ", outRect, 100, 50, 200, 100); } }
public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) { if (SDK_INT >= 17) { Gravity.apply(gravity, w, h, container, outRect, layoutDirection); } else { Gravity.apply(gravity, w, h, container, outRect); } }
GravityCompat { public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) { if (SDK_INT >= 17) { Gravity.apply(gravity, w, h, container, outRect, layoutDirection); } else { Gravity.apply(gravity, w, h, container, outRect); } } }
GravityCompat { public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) { if (SDK_INT >= 17) { Gravity.apply(gravity, w, h, container, outRect, layoutDirection); } else { Gravity.apply(gravity, w, h, container, outRect); } } private  GravityCompat(); }
GravityCompat { public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) { if (SDK_INT >= 17) { Gravity.apply(gravity, w, h, container, outRect, layoutDirection); } else { Gravity.apply(gravity, w, h, container, outRect); } } private  GravityCompat(); static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, int layoutDirection); static void apply(int gravity, int w, int h, Rect container,
            int xAdj, int yAdj, Rect outRect, int layoutDirection); static void applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection); static int getAbsoluteGravity(int gravity, int layoutDirection); }
GravityCompat { public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) { if (SDK_INT >= 17) { Gravity.apply(gravity, w, h, container, outRect, layoutDirection); } else { Gravity.apply(gravity, w, h, container, outRect); } } private  GravityCompat(); static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, int layoutDirection); static void apply(int gravity, int w, int h, Rect container,
            int xAdj, int yAdj, Rect outRect, int layoutDirection); static void applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection); static int getAbsoluteGravity(int gravity, int layoutDirection); static final int RELATIVE_LAYOUT_DIRECTION; static final int START; static final int END; static final int RELATIVE_HORIZONTAL_GRAVITY_MASK; }