@Override public int getChildWidthSpec(int widthSpec, RenderInfo renderInfo) { switch (mLinearLayoutManager.getOrientation()) { case LinearLayoutManager.HORIZONTAL: return SizeSpec.makeSizeSpec(0, SizeSpec.UNSPECIFIED); default: return widthSpec; } }
@Override public int getChildHeightSpec(int heightSpec, RenderInfo renderInfo) { switch (mLinearLayoutManager.getOrientation()) { case LinearLayoutManager.HORIZONTAL: return heightSpec; default: return SizeSpec.makeSizeSpec(0, SizeSpec.UNSPECIFIED); } }
@GuardedBy("this") private int getActualChildrenHeightSpec(final ComponentTreeHolder treeHolder) { if (mHasDynamicItemHeight) { return SizeSpec.UNSPECIFIED; } if (mIsMeasured.get() && !mRequiresRemeasure.get()) { return mLayoutInfo.getChildHeightSpec( SizeSpec.makeSizeSpec(mMeasuredSize.height, SizeSpec.EXACTLY), treeHolder.getRenderInfo()); } return mLayoutInfo.getChildHeightSpec(mLastHeightSpec, treeHolder.getRenderInfo()); }
@Override public void run() { recyclerBinder.measure( new Size(), makeSizeSpec(200, EXACTLY), makeSizeSpec(200, EXACTLY), null); } });
@Override public void run() { recyclerBinder.measure( new Size(), makeSizeSpec(200, EXACTLY), makeSizeSpec(200, EXACTLY), null); } });
private void setupBaseLayoutInfoMock(LayoutInfo layoutInfo, int orientation) { when(layoutInfo.getScrollDirection()).thenReturn(orientation); when(layoutInfo.getLayoutManager()) .thenReturn( new LinearLayoutManager(mComponentContext.getAndroidContext(), orientation, false)); when(layoutInfo.approximateRangeSize(anyInt(), anyInt(), anyInt(), anyInt())) .thenReturn(RANGE_SIZE); when(layoutInfo.getChildHeightSpec(anyInt(), any(RenderInfo.class))) .thenReturn(SizeSpec.makeSizeSpec(100, SizeSpec.EXACTLY)); when(layoutInfo.getChildWidthSpec(anyInt(), any(RenderInfo.class))) .thenReturn(SizeSpec.makeSizeSpec(100, SizeSpec.EXACTLY)); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mUnspecifiedSizeSpec = SizeSpec.makeSizeSpec(0, SizeSpec.UNSPECIFIED); final Field declaredField = ComponentsPools.class.getDeclaredField("sInternalNodePool"); mOriginalInternalNodePool = (RecyclePool<InternalNode>) declaredField.get(null); setFinalStatic(ComponentsPools.class, "sInternalNodePool", mInternalNodePool); }
private static InternalNode acquireInternalNode() { final ComponentContext context = new ComponentContext(RuntimeEnvironment.application); return createAndMeasureTreeForComponent( context, Column.create(context).build(), makeSizeSpec(0, UNSPECIFIED), makeSizeSpec(0, UNSPECIFIED)); }
@Test public void testWidthExactlyHeightUnspecified() { final Size size = new Size(); measureWithAspectRatio( makeSizeSpec(10, EXACTLY), makeSizeSpec(0, UNSPECIFIED), 0.5f, size); assertThat(size.width).isEqualTo(10); assertThat(size.height).isEqualTo(20); }
@Test public void testWidthAtMostHeightAtMostWidthSmaller() { final Size size = new Size(); measureWithAspectRatio( makeSizeSpec(10, AT_MOST), makeSizeSpec(20, AT_MOST), 0.5f, size); assertThat(size.width).isEqualTo(10); assertThat(size.height).isEqualTo(20); }
@Test public void testWidthExactlyHeightTooSmall() { final Size size = new Size(); measureWithAspectRatio( makeSizeSpec(10, EXACTLY), makeSizeSpec(20, AT_MOST), 0.1f, size); assertThat(size.width).isEqualTo(10); assertThat(size.height).isEqualTo(20); }
@Test public void testMeasureWithDesiredSizeAndExactlySpec() { final Size size = new Size(); measureWithDesiredPx( makeSizeSpec(50, EXACTLY), makeSizeSpec(30, EXACTLY), 80, 20, size); assertThat(size.width).isEqualTo(50); assertThat(size.height).isEqualTo(30); }
@Test public void testGetChildMeasureSpecHorizontal() { final LinearLayoutInfo linearLayoutInfo = new LinearLayoutInfo( application, HORIZONTAL, false); final int sizeSpec = makeSizeSpec(200, EXACTLY); final int heightSpec = linearLayoutInfo.getChildHeightSpec(sizeSpec, null); assertThat(sizeSpec).isEqualTo(heightSpec); final int widthSpec = linearLayoutInfo.getChildWidthSpec(sizeSpec, null); assertThat(makeSizeSpec(0, UNSPECIFIED)).isEqualTo(widthSpec); }
@Before public void setup() { final ComponentContext context = new ComponentContext(RuntimeEnvironment.application); mInternalNode = createAndMeasureTreeForComponent( context, Column.create(context).build(), makeSizeSpec(0, UNSPECIFIED), makeSizeSpec(0, UNSPECIFIED)); }
@Test public void testFullSpanChildWidthSpec() { final GridLayoutInfo gridLayoutInfo = createGridLayoutInfo(VERTICAL, 3); final int sizeSpec = SizeSpec.makeSizeSpec(200, EXACTLY); final RenderInfo renderInfo = mock(RenderInfo.class); when(renderInfo.isFullSpan()).thenReturn(true); final int heightSpec = gridLayoutInfo.getChildHeightSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getMode(heightSpec)).isEqualTo(UNSPECIFIED); final int widthSpec = gridLayoutInfo.getChildWidthSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getSize(widthSpec)).isEqualTo(200); assertThat(SizeSpec.getMode(widthSpec)).isEqualTo(EXACTLY); }
@Test public void testFullSpanChildHeightSpec() { final GridLayoutInfo gridLayoutInfo = createGridLayoutInfo(HORIZONTAL, 3); final int sizeSpec = SizeSpec.makeSizeSpec(200, EXACTLY); final RenderInfo renderInfo = mock(RenderInfo.class); when(renderInfo.isFullSpan()).thenReturn(true); final int widthSpec = gridLayoutInfo.getChildWidthSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getMode(widthSpec)).isEqualTo(UNSPECIFIED); final int heightSpec = gridLayoutInfo.getChildHeightSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getSize(heightSpec)).isEqualTo(200); assertThat(SizeSpec.getMode(heightSpec)).isEqualTo(EXACTLY); }
@Before public void setup() { final ComponentContext context = new ComponentContext(RuntimeEnvironment.application); mInternalNode = createAndMeasureTreeForComponent( context, Column.create(context).build(), makeSizeSpec(0, UNSPECIFIED), makeSizeSpec(0, UNSPECIFIED)); mInternalNode.touchHandler(new EventHandler(null, 1)); }
@Test public void testGetChildMeasureSpecVertical() { final GridLayoutInfo gridLayoutInfo = createGridLayoutInfo(VERTICAL, 3); final int sizeSpec = SizeSpec.makeSizeSpec(200, EXACTLY); final RenderInfo renderInfo = mock(RenderInfo.class); when(renderInfo.getSpanSize()).thenReturn(2); final int heightSpec = gridLayoutInfo.getChildHeightSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getMode(heightSpec)).isEqualTo(UNSPECIFIED); final int widthSpec = gridLayoutInfo.getChildWidthSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getSize(widthSpec)).isEqualTo((200 / 3) * 2); assertThat(SizeSpec.getMode(widthSpec)).isEqualTo(EXACTLY); }
@Test public void testGetChildMeasureSpecHorizontal() { final GridLayoutInfo gridLayoutInfo = createGridLayoutInfo(HORIZONTAL, 3); final int sizeSpec = SizeSpec.makeSizeSpec(200, EXACTLY); final RenderInfo renderInfo = mock(RenderInfo.class); when(renderInfo.getSpanSize()).thenReturn(2); final int heightSpec = gridLayoutInfo.getChildHeightSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getSize(heightSpec)).isEqualTo((200 / 3) * 2); assertThat(SizeSpec.getMode(heightSpec)).isEqualTo(EXACTLY); final int widthSpec = gridLayoutInfo.getChildWidthSpec(sizeSpec, renderInfo); assertThat(SizeSpec.getMode(widthSpec)).isEqualTo(UNSPECIFIED); }
@Before public void setup() throws Exception { mContext = new ComponentContext(RuntimeEnvironment.application); mUnspecifiedSpec = SizeSpec.makeSizeSpec(0, SizeSpec.UNSPECIFIED); sRedDrawable = ComparableColorDrawable.create(Color.RED); sBlackDrawable = ComparableColorDrawable.create(Color.BLACK); sTransparentDrawable = ComparableColorDrawable.create(TRANSPARENT); }