@Override public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION); return createAnimator(view, sceneRoot.getHeight() + (position[1] * spread), 0f); }
@Override public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION); return createAnimator(view, 0f, sceneRoot.getHeight() + (position[1] * spread)); }
@Override public float getGoneY(ViewGroup sceneRoot, View view) { return view.getTranslationY() - sceneRoot.getHeight(); } };
@Override public float getGoneY(ViewGroup sceneRoot, View view) { return view.getTranslationY() + sceneRoot.getHeight(); } };
@SuppressLint("RtlHardcoded") private int getMaxDistance(@NonNull ViewGroup sceneRoot) { switch (mSide) { case Gravity.LEFT: case Gravity.RIGHT: case Gravity.START: case Gravity.END: return sceneRoot.getWidth(); default: return sceneRoot.getHeight(); } } }
@Override public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) { toolbar.setAlpha(1 - Math.min(percent, 1)); floor.setTranslationY(Math.min(offset - floor.getHeight() + toolbar.getHeight(), refreshLayout.getLayout().getHeight() - floor.getHeight())); } // @Override
@Nullable @Override public Object getElementToHighlightAtPosition(ViewGroup element, int x, int y, Rect bounds) { View hitChild = null; for (int i = element.getChildCount() - 1; i >= 0; --i) { final View childView = element.getChildAt(i); if (isChildVisible(childView) && childView.getVisibility() == View.VISIBLE) { childView.getHitRect(bounds); if (bounds.contains(x, y)) { hitChild = childView; break; } } } if (hitChild != null) { return hitChild; } else { bounds.set(0, 0, element.getWidth(), element.getHeight()); return element; } } }
/** * Performs incremental mount on the children views of the given ViewGroup. * @param scrollingViewParent ViewGroup container of views that will be incrementally mounted. */ public static void performIncrementalMount(ViewGroup scrollingViewParent) { assertMainThread(); final int viewGroupWidth = scrollingViewParent.getWidth(); final int viewGroupHeight = scrollingViewParent.getHeight(); for (int i = 0; i < scrollingViewParent.getChildCount(); i++) { maybePerformIncrementalMountOnView( viewGroupWidth, viewGroupHeight, scrollingViewParent.getChildAt(i)); } }
@Test public void testMatchParentWidthAndHeight() { LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); view.setLayoutParams(params); target.getSize(cb); verify(cb, never()).onSizeReady(anyInt(), anyInt()); activity.visible(); view.getViewTreeObserver().dispatchOnPreDraw(); verify(cb).onSizeReady(eq(parent.getWidth()), eq(parent.getHeight())); }
public void resetPosition() { ViewGroup parent = (ViewGroup) getParent(); if (parent == null) return; setPosition(parent.getWidth()/2, parent.getHeight()/2); }
/** * 保存大小和状态 */ private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) { mParent.getLocationOnScreen(mNormalItemRect); int statusBarH = getStatusBarHeight(context); int actionBerH = getActionBarHeight((Activity) context); if (statusBar) { mNormalItemRect[1] = mNormalItemRect[1] - statusBarH; } if (actionBar) { mNormalItemRect[1] = mNormalItemRect[1] - actionBerH; } mNormalItemSize[0] = mParent.getWidth(); mNormalItemSize[1] = mParent.getHeight(); }
/** * 保存大小和状态 */ private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) { listParent.getLocationOnScreen(listItemRect); int statusBarH = getStatusBarHeight(context); int actionBerH = getActionBarHeight((Activity) context); if (statusBar) { listItemRect[1] = listItemRect[1] - statusBarH; } if (actionBar) { listItemRect[1] = listItemRect[1] - actionBerH; } listItemSize[0] = listParent.getWidth(); listItemSize[1] = listParent.getHeight(); }
/** * 保存大小和状态 */ private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) { listParent.getLocationOnScreen(listItemRect); int statusBarH = getStatusBarHeight(context); int actionBerH = getActionBarHeight((Activity) context); if (statusBar) { listItemRect[1] = listItemRect[1] - statusBarH; } if (actionBar) { listItemRect[1] = listItemRect[1] - actionBerH; } listItemSize[0] = listParent.getWidth(); listItemSize[1] = listParent.getHeight(); }
@Test public void test_get_distance_point_for_bottom_left() { corneredSort = new CorneredSort(/*interObjectDelay=*/0, /*reversed=*/false, CorneredSort.Corner.BOTTOM_LEFT); // fake a height of 20, this will be the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); PointF resultPoint = corneredSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(0F, 20F), resultPoint); }
@Test public void test_get_distance_point_for_bottom_right() { corneredSort = new CorneredSort(/*interObjectDelay=*/0, /*reversed=*/false, CorneredSort.Corner.BOTTOM_RIGHT); // fake a width of 20, this will be the expected value Mockito.when(mockParent.getWidth()).thenReturn(20); // fake a height of 20, this will be the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); PointF resultPoint = corneredSort.getDistancePoint(mockParent, mockChildren); PointF expectedPoint = new PointF(20F, 20F); assertEquals(expectedPoint, resultPoint); }
@Test public void test_get_distance_point_for_bottom_left() { radialSort = new RadialSort(/*interObjectDelay=*/0, /*reversed=*/false, RadialSort.Position.BOTTOM_LEFT); // fake a height of 20, this will be the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); // distance view to point calculation before it gets to DistancedSort.translate(). The return will be the parent's height for the points y setupMockChildrenForPoint(0, /*heightOfParent=*/20); PointF resultPoint = radialSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(0F, 20F), resultPoint); }
@Test public void test_get_distance_point_for_left() { radialSort = new RadialSort(/*interObjectDelay=*/0, /*reversed=*/false, RadialSort.Position.LEFT); // fake a height of 20, this will be double the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); // distance view to point calculation before it gets to DistancedSort.translate(). The point's y will be the parent's height divided by 2 setupMockChildrenForPoint(0, /*heightOfParent=*/20 / 2); PointF resultPoint = radialSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(0, 10F), resultPoint); }
@Test public void test_get_distance_point_for_right() { radialSort = new RadialSort(/*interObjectDelay=*/0, /*reversed=*/false, RadialSort.Position.RIGHT); // fake a width and height of 20, the height will be double the expected value and the width will be the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); Mockito.when(mockParent.getWidth()).thenReturn(20); // distance view to point calculation before it gets to DistancedSort.translate() will be the parent's height and width divided by 2 setupMockChildrenForPoint(/*widthOfParent=*/20, /*heightOfParent=*/20 / 2); PointF resultPoint = radialSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(20F, 10F), resultPoint); }
@Test public void test_get_distance_point_for_middle() { radialSort = new RadialSort(/*interObjectDelay=*/0, /*reversed=*/false, RadialSort.Position.MIDDLE); // fake a width and height of 20, this will be double the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); Mockito.when(mockParent.getWidth()).thenReturn(20); // distance view to point calculation before it gets to DistancedSort.translate() will be the parent's height and width divided by 2 setupMockChildrenForPoint(/*widthOfParent=*/20 / 2, /*heightOfParent=*/20 / 2); PointF resultPoint = radialSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(10F, 10F), resultPoint); }
@Test public void test_get_distance_point_for_bottom_right() { radialSort = new RadialSort(/*interObjectDelay=*/0, /*reversed=*/false, RadialSort.Position.BOTTOM_RIGHT); // fake a width of 20, this will be the expected value Mockito.when(mockParent.getWidth()).thenReturn(20); // fake a height of 20, this will be the expected value Mockito.when(mockParent.getHeight()).thenReturn(20); setupMockChildrenForPoint(/*widthOfParent=*/20, /*heightOfParent=*/20); PointF resultPoint = radialSort.getDistancePoint(mockParent, mockChildren); assertEquals(new PointF(20F, 20F), resultPoint); }