public SimpleStringRecyclerViewAdapter(Context context, List<String> items) { context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); mBackground = mTypedValue.resourceId; mValues = items; }
@SuppressWarnings("deprecation") public static Drawable resolveDrawable(@DrawableRes int resId, Context context) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); if (Build.VERSION.SDK_INT >= 22) { return resources.getDrawable(resId, theme); } else { return resources.getDrawable(resId); } }
public void setIconColor(Drawable icon) { int textColorSecondary = android.R.attr.textColorSecondary; TypedValue value = new TypedValue(); if (!mContext.getTheme().resolveAttribute(textColorSecondary, value, true)) { return; } int baseColor = mContext.getResources().getColor(value.resourceId); icon.setColorFilter(baseColor, PorterDuff.Mode.MULTIPLY); } }
public static int getActionBarSize(@NonNull Context context) { TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true); int actionBarSize = TypedValue.complexToDimensionPixelSize( value.data, context.getResources().getDisplayMetrics()); return actionBarSize; }
/** * Get the boolean value of a given styleable. * * @param ctx * @param styleable * @param def * @return */ public static boolean getBooleanStyleable(Context ctx, @StyleableRes int styleable, boolean def) { TypedArray ta = ctx.getTheme().obtainStyledAttributes(R.styleable.MaterialDrawer); return ta.getBoolean(styleable, def); }
@NonNull protected static TypedValue getTypedValue(@NonNull Context context, @AttrRes int resId) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(resId, tv, true); return tv; }
public AlbumMediaAdapter(Context context, SelectedItemCollection selectedCollection, RecyclerView recyclerView) { super(null); mSelectionSpec = SelectionSpec.getInstance(); mSelectedCollection = selectedCollection; TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{R.attr.item_placeholder}); mPlaceholder = ta.getDrawable(0); ta.recycle(); mRecyclerView = recyclerView; }
public AspectRatioFrameLayout(Context context, AttributeSet attrs) { super(context, attrs); resizeMode = RESIZE_MODE_FIT; if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AspectRatioFrameLayout, 0, 0); try { resizeMode = a.getInt(R.styleable.AspectRatioFrameLayout_resize_mode, RESIZE_MODE_FIT); } finally { a.recycle(); } } aspectRatioUpdateDispatcher = new AspectRatioUpdateDispatcher(); }
public static int getActionBarHeight(Context context) { int mActionBarHeight; TypedValue mTypedValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.actionBarSize, mTypedValue, true); mActionBarHeight = TypedValue.complexToDimensionPixelSize(mTypedValue.data, context.getResources().getDisplayMetrics()); return mActionBarHeight; }
/** * Get a color from an attr styled according to the the context's theme. */ public static int resolveColorFromAttr(Context context, @AttrRes int attrColor) { final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(attrColor, value, true); if (value.resourceId != 0) { return ContextCompat.getColor(context, value.resourceId); } return value.data; }
@SuppressWarnings("deprecation") public void setColorSchemeColorIds(@IdRes int... resources) { final View thisView = this; final Resources res = thisView.getResources(); final int[] colorRes = new int[resources.length]; for (int i = 0; i < resources.length; i++) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { colorRes[i] = res.getColor(resources[i], getContext().getTheme()); } else { colorRes[i] = res.getColor(resources[i]); } } mProgress.setColorSchemeColors(colorRes); } //</editor-fold>
private static Drawable getDrawable( Context ourContext, Context targetContext, @DrawableRes int id, @Nullable Theme theme) { try { // Race conditions may cause us to attempt to load using v7 more than once. That's ok since // this check is a modest optimization and the output will be correct anyway. if (shouldCallAppCompatResources) { return loadDrawableV7(targetContext, id, theme); } } catch (NoClassDefFoundError error) { shouldCallAppCompatResources = false; } catch (IllegalStateException e) { if (ourContext.getPackageName().equals(targetContext.getPackageName())) { throw e; } return ContextCompat.getDrawable(targetContext, id); } catch (Resources.NotFoundException e) { // Ignored, this can be thrown when drawable compat attempts to decode a canary resource. If // that decode attempt fails, we still want to try with the v4 ResourcesCompat below. } return loadDrawableV4(targetContext, id, theme != null ? theme : targetContext.getTheme()); }
private Drawable loadDrawable(@DrawableRes int resourceId) { Theme theme = requestOptions.getTheme() != null ? requestOptions.getTheme() : context.getTheme(); return DrawableDecoderCompat.getDrawable(glideContext, resourceId, theme); }
static int getAttrDimensionPixelOffset(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int value = a.getDimensionPixelOffset(0, defaultValue); a.recycle(); return value; }
static int getAttrColor(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int colorId = a.getResourceId(0, 0); final int value = colorId != 0 ? ThemeUtils.replaceColorById(context, colorId) : ThemeUtils.replaceColor(context, a.getColor(0, defaultValue)); a.recycle(); return value; }
public void init(ComponentContext context) { mResources = context.getAndroidContext().getResources(); mTheme = context.getAndroidContext().getTheme(); mResourceCache = context.getResourceCache(); }
private void init() { mSelectedColor = ResourcesCompat.getColor( getResources(), R.color.zhihu_item_checkCircle_backgroundColor, getContext().getTheme()); mUnSelectUdColor = ResourcesCompat.getColor( getResources(), R.color.zhihu_check_original_radio_disable, getContext().getTheme()); setChecked(false); }
public void sameAs(@DrawableRes int resourceId) { Context context = InstrumentationRegistry.getTargetContext(); Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceId, context.getTheme()); sameAs(drawable); }
@UiThread // Implicit synchronization for use of shared resource VALUE. public static Drawable getTintedDrawable(Context context, @DrawableRes int id, @AttrRes int tintAttrId) { boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true); if (!attributeFound) { throw new Resources.NotFoundException("Required tint color attribute with name " + context.getResources().getResourceEntryName(tintAttrId) + " and attribute ID " + tintAttrId + " was not found."); } Drawable drawable = ContextCompat.getDrawable(context, id); drawable = DrawableCompat.wrap(drawable.mutate()); int color = ContextCompat.getColor(context, VALUE.resourceId); DrawableCompat.setTint(drawable, color); return drawable; }
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { getContext().getTheme().applyStyle(R.style.Theme_AppCompat, true); return super.onCreateView(inflater, container, savedInstanceState); }