Java Code Examples for com.google.android.material.floatingactionbutton.FloatingActionButton#getLocationOnScreen()
The following examples show how to use
com.google.android.material.floatingactionbutton.FloatingActionButton#getLocationOnScreen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppBarWithAnchoredFabMarginsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testFabBottomMargin() throws Throwable { configureContent( R.layout.design_appbar_anchored_fab_margin_bottom, R.string.design_appbar_anchored_fab_margin_bottom); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final CoordinatorLayout.LayoutParams fabLp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); assertEquals(mAppBar.getId(), fabLp.getAnchorId()); final int[] appbarOnScreenXY = new int[2]; final int[] fabOnScreenXY = new int[2]; mAppBar.getLocationOnScreen(appbarOnScreenXY); fab.getLocationOnScreen(fabOnScreenXY); // FAB is horizontally centered in the coordinate system of its anchor (app bar). assertEquals( appbarOnScreenXY[0] + mAppBar.getWidth() / 2, fabOnScreenXY[0] + fab.getWidth() / 2, 1); // Bottom margin is in the coordinate space of the parent (CoordinatorLayout) and not // the anchor. Since our FAB is far enough from the bottom edge of CoordinatorLayout, // we are expecting the vertical center of the FAB to be aligned with the bottom edge // of its anchor (app bar). assertEquals( appbarOnScreenXY[1] + mAppBar.getHeight(), fabOnScreenXY[1] + fab.getHeight() / 2, 1); }
Example 2
Source File: AppBarWithAnchoredFabMarginsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testFabTopMargin() throws Throwable { configureContent( R.layout.design_appbar_anchored_fab_margin_top, R.string.design_appbar_anchored_fab_margin_top); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final CoordinatorLayout.LayoutParams fabLp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); assertEquals(mAppBar.getId(), fabLp.getAnchorId()); final int[] appbarOnScreenXY = new int[2]; final int[] fabOnScreenXY = new int[2]; mAppBar.getLocationOnScreen(appbarOnScreenXY); fab.getLocationOnScreen(fabOnScreenXY); // FAB is horizontally centered in the coordinate system of its anchor (app bar). assertEquals( appbarOnScreenXY[0] + mAppBar.getWidth() / 2, fabOnScreenXY[0] + fab.getWidth() / 2, 1); // Top margin is in the coordinate space of the parent (CoordinatorLayout) and not // the anchor. Since our FAB is far enough from the bottom edge of CoordinatorLayout, // we are expecting the vertical center of the FAB to be aligned with the bottom edge // of its anchor (app bar). assertEquals( appbarOnScreenXY[1] + mAppBar.getHeight(), fabOnScreenXY[1] + fab.getHeight() / 2, 1); }
Example 3
Source File: AppBarWithAnchoredFabMarginsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testFabLeftMargin() throws Throwable { configureContent( R.layout.design_appbar_anchored_fab_margin_left, R.string.design_appbar_anchored_fab_margin_left); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final CoordinatorLayout.LayoutParams fabLp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); assertEquals(mAppBar.getId(), fabLp.getAnchorId()); final int[] appbarOnScreenXY = new int[2]; final int[] fabOnScreenXY = new int[2]; mAppBar.getLocationOnScreen(appbarOnScreenXY); fab.getLocationOnScreen(fabOnScreenXY); // FAB is left-aligned in the coordinate system of its anchor (app bar). In addition, // its left margin "pushes" it away in the coordinate system of the parent // (CoordinatorLayout) assertEquals(appbarOnScreenXY[0] + fabMargin, fabOnScreenXY[0], 1); // FAB's vertical center should be aligned with the bottom edge of its anchor (app bar). assertEquals( appbarOnScreenXY[1] + mAppBar.getHeight(), fabOnScreenXY[1] + fab.getHeight() / 2, 1); }
Example 4
Source File: AppBarWithAnchoredFabMarginsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testFabRightMargin() throws Throwable { configureContent( R.layout.design_appbar_anchored_fab_margin_right, R.string.design_appbar_anchored_fab_margin_right); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final CoordinatorLayout.LayoutParams fabLp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); assertEquals(mAppBar.getId(), fabLp.getAnchorId()); final int[] appbarOnScreenXY = new int[2]; final int[] fabOnScreenXY = new int[2]; mAppBar.getLocationOnScreen(appbarOnScreenXY); fab.getLocationOnScreen(fabOnScreenXY); // FAB is right-aligned in the coordinate system of its anchor (app bar). In addition, // its right margin "pushes" it away in the coordinate system of the parent // (CoordinatorLayout) assertEquals( appbarOnScreenXY[0] + mAppBar.getWidth() - fabMargin, fabOnScreenXY[0] + fab.getWidth(), 1); // FAB's vertical center should be aligned with the bottom edge of its anchor (app bar). assertEquals( appbarOnScreenXY[1] + mAppBar.getHeight(), fabOnScreenXY[1] + fab.getHeight() / 2, 1); }
Example 5
Source File: AppBarWithDodgingTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testLeftDodge() throws Throwable { configureContent(R.layout.design_appbar_dodge_left, R.string.design_appbar_dodge_left); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final FloatingActionButton fab2 = mCoordinatorLayout.findViewById(R.id.fab2); final int[] fabOnScreenXY = new int[2]; final int[] fab2OnScreenXY = new int[2]; fab.getLocationOnScreen(fabOnScreenXY); fab2.getLocationOnScreen(fab2OnScreenXY); final Rect fabRect = new Rect(); final Rect fab2Rect = new Rect(); fab.getContentRect(fabRect); fab2.getContentRect(fab2Rect); // Our second FAB is configured to "dodge" the first one - to be displayed to the // right of it int firstRight = fabOnScreenXY[0] + fabRect.right; int secondLeft = fab2OnScreenXY[0] + fab2Rect.left; assertTrue( "Second button left edge at " + secondLeft + " should be dodging the first button right edge at " + firstRight, secondLeft >= firstRight); }
Example 6
Source File: AppBarWithDodgingTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testRightDodge() throws Throwable { configureContent(R.layout.design_appbar_dodge_right, R.string.design_appbar_dodge_right); final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab); final FloatingActionButton fab2 = mCoordinatorLayout.findViewById(R.id.fab2); final int[] fabOnScreenXY = new int[2]; final int[] fab2OnScreenXY = new int[2]; fab.getLocationOnScreen(fabOnScreenXY); fab2.getLocationOnScreen(fab2OnScreenXY); final Rect fabRect = new Rect(); final Rect fab2Rect = new Rect(); fab.getContentRect(fabRect); fab2.getContentRect(fab2Rect); // Our second FAB is configured to "dodge" the first one - to be displayed to the // left of it int firstLeft = fabOnScreenXY[0] + fabRect.left; int secondRight = fab2OnScreenXY[0] + fab2Rect.right; assertTrue( "Second button right edge at " + secondRight + " should be dodging the first button left edge at " + firstLeft, secondRight <= firstLeft); }