@Nullable static Drawable getBackgroundOrDefault(ComponentContext c, Drawable specifiedBackground) { if (specifiedBackground != null) { return specifiedBackground; } final int[] attrs = {android.R.attr.background}; TypedArray a = c.getAndroidContext().obtainStyledAttributes(null, attrs, android.R.attr.editTextStyle, 0); Drawable defaultBackground = a.getDrawable(0); a.recycle(); return defaultBackground; }
public void init(ComponentContext context) { mResources = context.getAndroidContext().getResources(); mTheme = context.getAndroidContext().getTheme(); mResourceCache = context.getResourceCache(); }
public LithoView(ComponentContext context, AttributeSet attrs) { super(context, attrs); mComponentContext = context; mMountState = new MountState(this); mAccessibilityManager = (AccessibilityManager) context.getAndroidContext().getSystemService(ACCESSIBILITY_SERVICE); }
@Override public LayoutInfo getLayoutInfo(ComponentContext c) { return new GridLayoutInfo( c.getAndroidContext(), mNumColumns, mOrientation, mReverseLayout, mAllowMeasureOverride); }
@OnEvent(ClickEvent.class) static void onClickAbsoluteChild(ComponentContext c, @Param String absoluteParam) { Toast.makeText(c.getAndroidContext(), "Absolute child clicked: " + absoluteParam, LENGTH_SHORT) .show(); } }
@OnEvent(ClickEvent.class) static void onClickSecondChild(ComponentContext c, @Prop String secondChildString) { Toast.makeText( c.getAndroidContext(), "Second child clicked: " + secondChildString, LENGTH_SHORT) .show(); }
@OnTrigger(ClearFocusEvent.class) static void clearFocus( ComponentContext c, @State AtomicReference<EditTextWithEventHandlers> mountedView) { EditTextWithEventHandlers eventHandler = mountedView.get(); if (eventHandler != null) { eventHandler.clearFocus(); InputMethodManager imm = (InputMethodManager) c.getAndroidContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(eventHandler.getWindowToken(), 0); } }
public T foregroundRes(@DrawableRes int resId) { if (resId == 0) { return foreground(null); } return foreground(ComparableResDrawable.create(mContext.getAndroidContext(), resId)); }
InternalNode backgroundRes(@DrawableRes int resId) { if (resId == 0) { return background((ComparableDrawable) null); } return background(ComparableResDrawable.create(mComponentContext.getAndroidContext(), resId)); }
public ComponentHost(ComponentContext context, AttributeSet attrs) { super(context.getAndroidContext(), attrs); setWillNotDraw(false); setChildrenDrawingOrderEnabled(true); refreshAccessibilityDelegatesIfNeeded(isAccessibilityEnabled(context.getAndroidContext())); mMountItems = new SparseArrayCompat<>(); mViewMountItems = new SparseArrayCompat<>(); mDrawableMountItems = new SparseArrayCompat<>(); mDisappearingItems = new ArrayList<>(); }
/** @param c The {@link ComponentContext} the RecyclerBinder will use. */ public RecyclerBinder build(ComponentContext c) { componentContext = new ComponentContext( c.getAndroidContext(), c.getLogTag(), c.getLogger(), c.getTreePropsCopy()); if (layoutInfo == null) { layoutInfo = new LinearLayoutInfo(c.getAndroidContext(), VERTICAL, false); } return new RecyclerBinder(this); } }
public SectionContext(ComponentContext context) { this( context.getAndroidContext(), context.getLogTag(), context.getLogger(), context.getTreePropsCopy()); }
@Override protected void onUnmount( ComponentContext context, Object mountedContent) { final MatrixDrawable<T> matrixDrawable = (MatrixDrawable<T>) mountedContent; final T innerMountedDrawable = matrixDrawable.getMountedDrawable(); matrixDrawable.unmount(); Reference.release(context.getAndroidContext(), innerMountedDrawable, getDrawable()); }
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)); }
private RecyclerBinder getStackedEndRecyclerBinder() { final LinearLayoutManager layoutManager = new LinearLayoutManager( mComponentContext.getAndroidContext(), OrientationHelper.VERTICAL, false); layoutManager.setStackFromEnd(true); when(mLayoutInfo.getLayoutManager()).thenReturn(layoutManager); return mRecyclerBinderBuilder.build(mComponentContext); }
@Test public void testAcquireAndRelease() { TestReferenceLifecycle referenceLifecycle = new TestReferenceLifecycle(); TestReference reference = new TestReference(referenceLifecycle); Drawable acquiredDrawable = acquire(mContext.getAndroidContext(), reference); assertThat(referenceLifecycle.mAcquired).isTrue(); release(mContext.getAndroidContext(), acquiredDrawable, reference); assertThat(referenceLifecycle.mReleased).isTrue(); }
@Before public void setup() { mContext = new ComponentContext(RuntimeEnvironment.application); mLithoView = new LithoView(mContext); mParent = new FrameLayout(mContext.getAndroidContext()); mParent.setLeft(0); mParent.setTop(0); mParent.setRight(10); mParent.setBottom(10); mParent.addView(mLithoView); }
@Test public void testWrapContentPreLollipop() { ComponentsConfiguration.useDisplayListForAllDrawables = true; Object content = mDLComponent.onCreateMountContent(mContext.getAndroidContext()); assertThat(MountState.wrapContentIfNeeded(mDLComponent, content, false)).isNull(); content = mNoDLComponent.onCreateMountContent(mContext.getAndroidContext()); assertThat(MountState.wrapContentIfNeeded(mNoDLComponent, content, false)).isNull(); content = mViewComponent.onCreateMountContent(mContext.getAndroidContext()); assertThat(MountState.wrapContentIfNeeded(mViewComponent, content, false)).isNull(); }
@Test public void testAcquire() { Drawable drawable = new TestColorDrawable(Color.BLACK); Context context = new ComponentContext(application).getAndroidContext(); DefaultComparableDrawable comparable = (DefaultComparableDrawable) acquire(context, DrawableReference.create(DefaultComparableDrawable.create(drawable))); assertThat(comparable.getWrappedDrawable()).isEqualTo(drawable); } }
@Test public void testGenericPropMatching() { final ComponentContext c = mComponentsRule.getContext(); final Component component = new MyGeneric<>(c.getAndroidContext()).create(c).genericProp(mGenericProp).build(); final Condition<InspectableComponent> matcher = TestMyGeneric.matcher(c).genericProp(mGenericProp).build(); assertThat(c, component).has(deepSubComponentWith(c, matcher)); }