List of usage examples for android.content.res TypedArray hasValue
public boolean hasValue(@StyleableRes int index)
From source file:io.plaidapp.core.ui.widget.CollapsingTitleLayout.java
private void parseTextAttrs(TypedArray ta) { if (ta.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) { collapsedTextSize = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0); paint.setTextSize(collapsedTextSize); }/*w w w.ja va2 s .c o m*/ if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_textColor)) { paint.setColor(ta.getColor(R.styleable.CollapsingTitleLayout_android_textColor, Color.WHITE)); } if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_fontFamily)) { try { fontResId = ta.getResourceId(R.styleable.CollapsingTitleLayout_android_fontFamily, 0); Typeface font = ResourcesCompat.getFont(getContext(), fontResId); if (font != null) { paint.setTypeface(font); } } catch (Resources.NotFoundException nfe) { // swallow; use default typeface } } if (ta.hasValue(R.styleable.CollapsingTitleLayout_maxExpandedTextSize)) { maxExpandedTextSize = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_maxExpandedTextSize, Integer.MAX_VALUE); } if (ta.hasValue(R.styleable.CollapsingTitleLayout_lineHeightHint)) { lineHeightHint = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0); } if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_maxLines)) { maxLines = ta.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5); } }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java
private Drawable obtainSelectableItemBackground() { // Create an array of the attributes we want to resolve int[] attrs = new int[] { R.attr.selectableItemBackground }; // index 0 // Obtain the styled attributes TypedArray ta = mContext.obtainStyledAttributes(attrs); Drawable drawableFromTheme = null;/* w ww . jav a 2 s .c o m*/ if (ta.hasValue(0)) { // Get the value of the 'selectableItemBackground' attribute that was // set in the theme. The parameter is the index // of the attribute in the 'attrs' array. drawableFromTheme = ta.getDrawable(0); // index } // Finally free resources used by TypedArray ta.recycle(); return drawableFromTheme; }
From source file:ezy.ui.view.NoticeView.java
private void initWithContext(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NoticeView); mIcon = a.getDrawable(R.styleable.NoticeView_nvIcon); mIconPadding = (int) a.getDimension(R.styleable.NoticeView_nvIconPadding, 0); boolean hasIconTint = a.hasValue(R.styleable.NoticeView_nvIconTint); if (hasIconTint) { mIconTint = a.getColor(R.styleable.NoticeView_nvIconTint, 0xff999999); }/*from w ww .j a v a 2 s .com*/ mInterval = a.getInteger(R.styleable.NoticeView_nvInterval, 4000); mDuration = a.getInteger(R.styleable.NoticeView_nvDuration, 900); mDefaultFactory.resolve(a); a.recycle(); if (mIcon != null) { mPaddingLeft = getPaddingLeft(); int realPaddingLeft = mPaddingLeft + mIconPadding + mIcon.getIntrinsicWidth(); setPadding(realPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom()); if (hasIconTint) { mIcon = mIcon.mutate(); DrawableCompat.setTint(mIcon, mIconTint); } } }
From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java
@SuppressWarnings("ResourceType") @Override/*from www. ja v a 2s.c om*/ void loadFromAttribute(AttributeSet attrs, int defStyleAttr) { Context context = mView.getContext(); TypedArray a = context.obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0); for (int tintIndex = 0; tintIndex < 4; tintIndex++) { int modeIndex = tintIndex + 4; mCompoundDrawableResIds[tintIndex] = a.getResourceId(tintIndex, 0); mCompoundDrawableTintResIds[tintIndex] = a.getResourceId(tintIndex, 0); if (a.hasValue(modeIndex)) { mCompoundDrawableTintModes[tintIndex] = DrawableUtils.parseTintMode(a.getInt(modeIndex, 0), null); } } mCompoundDrawableResIds[0] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableLeft); mCompoundDrawableResIds[1] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableTop); mCompoundDrawableResIds[2] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableRight); mCompoundDrawableResIds[3] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableBottom); a.recycle(); setCompoundDrawablesWithIntrinsicBounds(getCompoundDrawableByPosition(0), getCompoundDrawableByPosition(1), getCompoundDrawableByPosition(2), getCompoundDrawableByPosition(3)); }
From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java
public void setCollapsedTextAppearance(int resId) { TypedArray a = this.mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { this.mCollapsedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, 0); }/*w w w. j av a 2 s. c o m*/ if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { this.mCollapsedTextSize = (float) a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); } a.recycle(); this.recalculate(); }
From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java
public void setExpandedTextAppearance(int resId) { TypedArray a = this.mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { this.mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, 0); }/* w w w. j ava2s. c o m*/ if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { this.mExpandedTextSize = (float) a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); } a.recycle(); this.recalculate(); }
From source file:android.support.wear.widget.CircularProgressLayout.java
public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mProgressDrawable = new CircularProgressDrawable(context); mProgressDrawable.setProgressRotation(DEFAULT_ROTATION); mProgressDrawable.setStrokeCap(Paint.Cap.BUTT); setBackground(mProgressDrawable);// w w w . j a v a 2 s . c o m // If a child view is added, make it center aligned so it fits in the progress drawable. setOnHierarchyChangeListener(new OnHierarchyChangeListener() { @Override public void onChildViewAdded(View parent, View child) { // Ensure that child view is aligned in center LayoutParams params = (LayoutParams) child.getLayoutParams(); params.gravity = Gravity.CENTER; child.setLayoutParams(params); } @Override public void onChildViewRemoved(View parent, View child) { } }); mController = new CircularProgressLayoutController(this); Resources r = context.getResources(); TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout); if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) { int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors, R.array.circular_progress_layout_color_scheme_colors); setColorSchemeColors(getColorListFromResources(r, arrayResId)); } else { setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK)); } setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth, r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width))); setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor, ContextCompat.getColor(context, R.color.circular_progress_layout_background_color))); setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false)); a.recycle(); }
From source file:com.auth0.android.lock.LockActivity.java
private boolean hasValidTheme() { TypedArray a = getTheme().obtainStyledAttributes(R.styleable.Lock_Theme); if (!a.hasValue(R.styleable.Lock_Theme_Auth0_HeaderLogo)) { a.recycle();//from ww w .jav a2 s . co m return false; } return true; }
From source file:com.amitupadhyay.aboutexample.util.CollapsingTextHelper.java
public void setCollapsedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mCollapsedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedTextColor); }/*www . j a v a 2 s .co m*/ if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mCollapsedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) mCollapsedTextSize); } a.recycle(); recalculate(); }
From source file:com.amitupadhyay.aboutexample.util.CollapsingTextHelper.java
public void setExpandedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mExpandedTextColor); }/*from w w w . j av a 2 s . c o m*/ if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) mExpandedTextSize); } a.recycle(); recalculate(); }