public SearchableSpinner(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mContext = context; getAttributeSet(attrs, defStyleAttr, defStyleRes); final LayoutInflater factory = LayoutInflater.from(context); factory.inflate(R.layout.view_searchable_spinner, this, true); mSpinnerListContainer = (LinearLayout) factory.inflate(R.layout.view_list, this, false); mSpinnerListView = (ListView) mSpinnerListContainer.findViewById(R.id.LstVw_SpinnerListView); if (mListItemDivider != null) { mSpinnerListView.setDivider(mListItemDivider); mSpinnerListView.setDividerHeight(mListDividerSize); } mEmptyTextView = (TextView) mSpinnerListContainer.findViewById(R.id.TxtVw_EmptyText); mSpinnerListView.setEmptyView(mEmptyTextView); }
private void setCryptoMessageSingleLine(@AttrRes int colorAttr, @StringRes int topTextRes, @DrawableRes int statusIconRes, @DrawableRes Integer statusDotsRes) { @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr); authenticationIcon_1.setImageResource(statusIconRes); authenticationIcon_1.setColorFilter(color); authenticationText.setText(topTextRes); if (statusDotsRes != null) { authenticationIcon_3.setImageResource(statusDotsRes); authenticationIcon_3.setColorFilter(color); authenticationIcon_3.setVisibility(View.VISIBLE); } else { authenticationIcon_3.setVisibility(View.GONE); } trustText.setVisibility(View.GONE); trustIconFrame.setVisibility(View.GONE); }
private void getAttributeSet(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { if (attrs != null) { try { TypedArray attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.SearchableSpinner, defStyleAttr, defStyleRes); mRevealViewBackgroundColor = attributes.getColor(R.styleable.SearchableSpinner_RevealViewBackgroundColor, Color.WHITE); mStartEditTintColor = attributes.getColor(R.styleable.SearchableSpinner_StartSearchTintColor, Color.GRAY); mEditViewBackgroundColor = attributes.getColor(R.styleable.SearchableSpinner_SearchViewBackgroundColor, Color.WHITE); mEditViewTextColor = attributes.getColor(R.styleable.SearchableSpinner_SearchViewTextColor, Color.BLACK); mDoneEditTintColor = attributes.getColor(R.styleable.SearchableSpinner_DoneSearchTintColor, Color.GRAY); mBordersSize = attributes.getDimensionPixelSize(R.styleable.SearchableSpinner_BordersSize, 4); mExpandSize = attributes.getDimensionPixelSize(R.styleable.SearchableSpinner_SpinnerExpandHeight, 0); mShowBorders = attributes.getBoolean(R.styleable.SearchableSpinner_ShowBorders, false); mBoarderColor = attributes.getColor(R.styleable.SearchableSpinner_BoarderColor, Color.GRAY); mAnimDuration = attributes.getColor(R.styleable.SearchableSpinner_AnimDuration, DefaultAnimationDuration); mKeepLastSearch = attributes.getBoolean(R.styleable.SearchableSpinner_KeepLastSearch, false); mRevealEmptyText = attributes.getString(R.styleable.SearchableSpinner_RevealEmptyText); mSearchHintText = attributes.getString(R.styleable.SearchableSpinner_SearchHintText); mNoItemsFoundText = attributes.getString(R.styleable.SearchableSpinner_NoItemsFoundText); mListItemDivider = attributes.getDrawable(R.styleable.SearchableSpinner_ItemsDivider); mListDividerSize = attributes.getDimensionPixelSize(R.styleable.SearchableSpinner_DividerHeight, 0); } catch (UnsupportedOperationException e) { Log.e("SearchableSpinner", "getAttributeSet --> " + e.getLocalizedMessage()); } } }
public static ColorStateList resolveColorStateList(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TintTypedArray ta = TintTypedArray.obtainStyledAttributes(context, null, TEMP_ARRAY); try { return ta.getColorStateList(0); } finally { ta.recycle(); } }
public static int resolveResourceId(Context context, @AttrRes int attr, int fallback) { TEMP_ARRAY[0] = attr; TypedArray ta = context.obtainStyledAttributes(TEMP_ARRAY); try { return ta.getResourceId(0, fallback); } finally { ta.recycle(); } }
public static boolean getStyleValuesBoolean(Context context, @AttrRes int attrId, int style) { TypedArray a = null; if (style > 0) { int[] AttrSet = {attrId}; a = context.obtainStyledAttributes(style, AttrSet); a.recycle(); } return a.getBoolean(0, false); }
private void setTransportSecurityMessageSingleLine(@AttrRes int colorAttr, @StringRes int topTextRes, @DrawableRes int statusIconRes) { @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr); transportSecurityIcon_1.setImageResource(statusIconRes); transportSecurityIcon_1.setColorFilter(color); transportSecurityText.setText(topTextRes); }
/** * Returns the drawable, which corresponds to a specific theme attribute, regarding the * theme, which is used when using a specific layout. * * @param layout * The layout as a value of the enum {@link Layout}. The layout may not be null * @param resourceId * The resource id of the theme attribute, the drawable should be obtained from, as an * {@link Integer} value. The resource id must correspond to a valid theme attribute * @return The color state list, which has been obtained, as an instance of the class {@link * ColorStateList} */ public Drawable getDrawable(@NonNull final Layout layout, @AttrRes final int resourceId) { try { return ThemeUtil.getDrawable(context, resourceId); } catch (NotFoundException e1) { int themeResourceId = getThemeResourceId(layout); try { return ThemeUtil.getDrawable(context, themeResourceId, resourceId); } catch (NotFoundException e) { themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId); return ThemeUtil.getDrawable(context, themeResourceId, resourceId); } } }
private void setDKIMMessageSingleLine(@AttrRes int colorAttr, @StringRes int topTextRes, @DrawableRes int statusIconRes) { @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr); dkimIcon_1.setImageResource(statusIconRes); dkimIcon_1.setColorFilter(color); dkimText.setText(topTextRes); }
private void setCryptoStatusView(RecipientTokenHolder holder, @DrawableRes int cryptoStatusRes, @AttrRes int cryptoStatusColorAttr) { Resources resources = context.getResources(); Drawable drawable = resources.getDrawable(cryptoStatusRes); // noinspection ConstantConditions, we know the resource exists! drawable.mutate(); int cryptoStatusColor = ThemeUtils.getStyledColor(context, cryptoStatusColorAttr); drawable.setColorFilter(cryptoStatusColor, Mode.SRC_ATOP); holder.itemCryptoStatusIcon.setImageDrawable(drawable); holder.itemCryptoStatus.setVisibility(View.VISIBLE); }
@ColorInt public static int getAttributeColor(Context context, @AttrRes int attr, int fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] {attr}); try { return a.getColor(0, fallback); } finally { a.recycle(); } }
/** * Get color attribute from current theme * * @param context Themed context * @param attr The resource id of color attribute * @return Result */ @ColorInt static int getColorFromAttr(Context context, @AttrRes int attr) { TypedArray array = context.getTheme().obtainStyledAttributes(new int[]{attr}); int color = array.getColor(0, Color.TRANSPARENT); array.recycle(); return color; }
private static Drawable resolveDrawable(Context context, @AttrRes int attr, @SuppressWarnings( "SameParameterValue") Drawable fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr}); try { Drawable d = a.getDrawable(0); if (d == null && fallback != null) d = fallback; return d; } finally { a.recycle(); } }
static int getColor(Context context, @AttrRes int attr, int defaultColor) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr}); try { return a.getColor(0, defaultColor); } finally { a.recycle(); } }
public SCCameraView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); if (isInEditMode()){ cameraView = null; return; } cameraView = BaseCameraView.createCameraView(context); cameraView.loadAspectRatios(); this.addView(cameraView); }
public static boolean getThemeAttrBoolean(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getBoolean(0, false); } finally { a.recycle(); } }
public MzViewPager(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); handleTypedArray(context, attrs); mVpMargin = dp2px(DEFAULT_VP_MARGIN); mVpPadding = dp2px(DEFAULT_VP_PADDING); mContext = context; initViewPager(); }
private static int getColor(Context context, @AttrRes int attrRes) { int styleRes = R.style.AppTheme_Dark; if (Settings.getBooleanValue(context, Settings.UI_THEME_DARK)) { styleRes = R.style.AppTheme_Light; } int colorRes = Utils.getResourceId(context, attrRes, styleRes); return ContextCompat.getColor(context, colorRes); }
public ACheckBox(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(context, R.layout.layout_custom_checkbox, this); init(context, attrs); setOnClickListener(this); }
/** * Finds and returns an attribute color. If it was not found the method returns the default color */ public static int getColorAttribute(@AttrRes int attribute, @ColorRes int defaultColor, Context context) { TypedValue a = new TypedValue(); context.getTheme().resolveAttribute(attribute, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { return a.data; } else { return ContextCompat.getColor(context, defaultColor); } }
/** * Convenience method for retrieving a themed drawable. * * @param context the {@link Context} to resolve the theme attribute against * @param attr the attribute corresponding to the drawable to resolve * @return the drawable of the resolved attribute */ public static Drawable resolveDrawable(Context context, @AttrRes int attr) { final TypedArray a; synchronized (TEMP_ATTR) { TEMP_ATTR[0] = attr; a = context.obtainStyledAttributes(TEMP_ATTR); } try { return a.getDrawable(0); } finally { a.recycle(); } }
/** * Procedure sets the background for given view as a drawable with given resource id */ @SuppressWarnings("deprecation") public static void updateBackgroundAttr(Context c, View v, @DrawableRes int drawableId, @AttrRes int colorAttrId) { Drawable bg = null; if (drawableId >= 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { bg = c.getResources().getDrawable(drawableId, c.getTheme()); } else { bg = c.getResources().getDrawable(drawableId); } } setDrawableColorAttr(c, bg, colorAttrId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { v.setBackground(bg); } else { v.setBackgroundDrawable(bg); } }
public static int getThemeAttrId(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getResourceId(0, 0); } finally { a.recycle(); } }
private void updateHideMediaToggleColor() { @AttrRes int attribute; if (statusMarkSensitive) { attribute = R.attr.compose_hide_media_button_selected_color; } else { attribute = R.attr.compose_hide_media_button_color; } ThemeUtils.setDrawableTint(this, hideMediaToggle.getDrawable(), attribute); }
public NetworkStateView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NetworkStateView, defStyleAttr, R.style.NetworkStateView_Style); mLoadingViewId = typedArray.getResourceId(R.styleable.NetworkStateView_loadingView, R.layout.view_loading); mErrorViewId = typedArray.getResourceId(R.styleable.NetworkStateView_errorView, R.layout.view_network_error); mErrorImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvErrorImage, NO_ID); mErrorText = typedArray.getString(R.styleable.NetworkStateView_nsvErrorText); mNoNetworkViewId = typedArray.getResourceId(R.styleable.NetworkStateView_noNetworkView, R.layout.view_no_network); mNoNetworkImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvNoNetworkImage, NO_ID); mNoNetworkText = typedArray.getString(R.styleable.NetworkStateView_nsvNoNetworkText); mEmptyViewId = typedArray.getResourceId(R.styleable.NetworkStateView_emptyView, R.layout.view_empty); mEmptyImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvEmptyImage, NO_ID); mEmptyText = typedArray.getString(R.styleable.NetworkStateView_nsvEmptyText); mRefreshViewId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvRefreshImage, NO_ID); mTextColor = typedArray.getColor(R.styleable.NetworkStateView_nsvTextColor, 0x8a000000); mTextSize = typedArray.getDimensionPixelSize(R.styleable.NetworkStateView_nsvTextSize, UIUtils.dp2px(14)); typedArray.recycle(); mInflater = LayoutInflater.from(context); params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); setBackgroundColor(UIUtils.getColor(R.color.white)); }
public static int getThemeAttrColor(@NonNull Context context, @AttrRes int attributeColor) { int[] attrs = new int[]{attributeColor}; TypedArray ta = context.obtainStyledAttributes(attrs); int color = ta.getColor(0, Color.TRANSPARENT); ta.recycle(); return color; }
/** * Performs configuration of this controller from the given <var>attrs</var>. * * @param context Context used to obtain values for the given attributes. * @param attrs Set of attributes with values to be used to set up this controller. * @param defStyleAttr An attribute which contains a reference to a default style resource, for * the view attached to this controller, within a theme of the given context. * @param defStyleRes Resource id of the default style for the view attached to this controller. * @return {@code True} if some setting of this controller has been changed, {@code false} otherwise. */ @SuppressWarnings("ResourceType") public boolean setUpFromAttrs(@NonNull Context context, AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_PullController, defStyleAttr, defStyleRes); if (typedArray != null) { this.ensurePullHelper(); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_PullController_uiPullMode) { setPullMode(typedArray.getInteger(index, mPullHelper.getPullMode())); } else if (index == R.styleable.Ui_PullController_uiPullMinVelocity) { setPullMinVelocity(typedArray.getFloat(index, getPullMinVelocity())); } else if (index == R.styleable.Ui_PullController_uiPullDistanceFraction) { setPullDistanceFraction(typedArray.getFloat(index, getPullDistanceFraction())); } else if (index == R.styleable.Ui_PullController_uiPullDistance) { setPullDistance(typedArray.getDimensionPixelSize(index, (int) getPullDistance())); } else if (index == R.styleable.Ui_PullController_uiPullCollapseDuration) { setPullCollapseDuration(typedArray.getInt(index, (int) mAnimations.pullCollapseDuration)); } else if (index == R.styleable.Ui_PullController_uiPullCollapseDelay) { setPullCollapseDelay(typedArray.getInt(index, (int) mAnimations.pullCollapseDelay)); } } typedArray.recycle(); return n > 0; } return false; }
public static @DrawableRes int getDrawableId(Context context, @AttrRes int attribute, @DrawableRes int fallbackDrawableId) { TypedValue value = new TypedValue(); if (context.getTheme().resolveAttribute(attribute, value, true)) { return value.resourceId; } else { return fallbackDrawableId; } }
public ScriptListWithProgressBarView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); init(); }
public SquareFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); }
public NewsDetailHeader(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); initViews(); }
public TouchDelegateViewGroup(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); }
public CNodeOAuthLoginView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); }
public PersonWidget(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); }
public BallPulseFooter(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); initView(context, attrs, defStyleAttr); }
public CurtainCardView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public CompoundFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); }
public AtomView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); }
/** * Sets the tint color of the drawable **/ public static void setDrawableTint(Context context, Drawable drawable, @AttrRes int colorAttrRes) { int colorRes = getResourceId(context, colorAttrRes); int color = ContextCompat.getColor(context, colorRes); DrawableCompat.setTint(drawable, color); }
@Override public Config statusBarColorAttr(@AttrRes int colorAttr) { return statusBarColor(ATEUtil.resolveColor(mContext, colorAttr)); }