Example usage for android.content.res TypedArray hasValue

List of usage examples for android.content.res TypedArray hasValue

Introduction

In this page you can find the example usage for android.content.res TypedArray hasValue.

Prototype

public boolean hasValue(@StyleableRes int index) 

Source Link

Document

Determines whether there is an attribute at index.

Usage

From source file:com.stepstone.stepper.internal.DottedProgressBar.java

public DottedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mSelectedColor = ContextCompat.getColor(context, R.color.ms_selectedColor);
    mUnselectedColor = ContextCompat.getColor(context, R.color.ms_unselectedColor);
    if (attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DottedProgressBar,
                defStyleAttr, 0);/*from  w  w  w .j a  v a2s. c om*/

        if (a.hasValue(R.styleable.DottedProgressBar_ms_activeDotColor)) {
            mSelectedColor = a.getColor(R.styleable.DottedProgressBar_ms_activeDotColor, mSelectedColor);
        }
        if (a.hasValue(R.styleable.DottedProgressBar_ms_inactiveDotColor)) {
            mUnselectedColor = a.getColor(R.styleable.DottedProgressBar_ms_inactiveDotColor, mUnselectedColor);
        }

        a.recycle();
    }
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static Drawable getActionBarBackground(final Context context, final int themeRes) {
    final TypedArray a1 = context.obtainStyledAttributes(null, new int[] { android.R.attr.background },
            R.attr.actionBarStyle, themeRes);
    try {// w ww.j  a va  2  s .c o m
        if (a1.hasValue(0)) {
            return applyActionBarDrawable(context, a1.getDrawable(0), isTransparentBackground(themeRes));
        }
    } finally {
        a1.recycle();
    }
    final TypedArray a2 = context.obtainStyledAttributes(null, new int[] { android.R.attr.background },
            android.R.attr.actionBarStyle, themeRes);
    try {
        if (a2.hasValue(0)) {
            return applyActionBarDrawable(context, a2.getDrawable(0), isTransparentBackground(themeRes));
        }
    } finally {
        a2.recycle();
    }
    return null;
}

From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java

public MyParallaxScrimageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ParallaxScrimageView);
    if (a.hasValue(R.styleable.ParallaxScrimageView_scrimColor)) {
        scrimColor = a.getColor(R.styleable.ParallaxScrimageView_scrimColor, scrimColor);
    }/*from   w w  w .ja v a 2s .  com*/
    if (a.hasValue(R.styleable.ParallaxScrimageView_scrimAlpha)) {
        scrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_scrimAlpha, scrimAlpha);
    }
    if (a.hasValue(R.styleable.ParallaxScrimageView_maxScrimAlpha)) {
        maxScrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_maxScrimAlpha, maxScrimAlpha);
    }
    if (a.hasValue(R.styleable.ParallaxScrimageView_parallaxFactor)) {
        parallaxFactor = a.getFloat(R.styleable.ParallaxScrimageView_parallaxFactor, parallaxFactor);
    }
    a.recycle();

    scrimPaint = new Paint();
    scrimPaint.setColor(ColorUtils.modifyAlpha(scrimColor, scrimAlpha));
}

From source file:com.arbo.gaogao.widget.ParallaxScrimageView.java

public ParallaxScrimageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ParallaxScrimageView);
    if (a.hasValue(R.styleable.ParallaxScrimageView_scrimColor)) {
        scrimColor = a.getColor(R.styleable.ParallaxScrimageView_scrimColor, scrimColor);
    }//from  w ww .j  a  v  a  2 s .  c  om
    if (a.hasValue(R.styleable.ParallaxScrimageView_scrimAlpha)) {
        scrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_scrimAlpha, scrimAlpha);
    }
    if (a.hasValue(R.styleable.ParallaxScrimageView_maxScrimAlpha)) {
        maxScrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_maxScrimAlpha, maxScrimAlpha);
    }
    if (a.hasValue(R.styleable.ParallaxScrimageView_parallaxFactor)) {
        parallaxFactor = a.getFloat(R.styleable.ParallaxScrimageView_parallaxFactor, parallaxFactor);
    }
    a.recycle();

    scrimPaint = new Paint();
    scrimPaint.setColor(ColorUtils.modifyAlpha(scrimColor, scrimAlpha));
}

From source file:com.bilibili.magicasakura.widgets.AppCompatImageHelper.java

@SuppressWarnings("ResourceType")
@Override//w  w  w .ja va  2  s .  com
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTRS, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mImageTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportImageTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportImageTint(mImageTintResId);
    } else {
        Drawable image = mTintManager.getDrawable(mImageResId = array.getResourceId(0, 0));
        if (image != null) {
            setImageDrawable(image);
        }
    }
    array.recycle();
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr,
            0);/*from  w  w  w .  j a v a2s.c o m*/
    try {
        if (a.hasValue(R.styleable.CompoundButton_android_button)) {
            final int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0);
            if (resourceId != 0) {
                mView.setButtonDrawable(mDrawableManager.getDrawable(mView.getContext(), resourceId));
            }
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            CompoundButtonCompat.setButtonTintList(mView,
                    a.getColorStateList(R.styleable.CompoundButton_buttonTint));
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
            CompoundButtonCompat.setButtonTintMode(mView,
                    DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null));
        }
    } finally {
        a.recycle();
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundButtonHelper.java

@SuppressWarnings("ResourceType")
@Override/*  w  ww . ja v a 2 s  .  com*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTRS, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mCompoundButtonTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportButtonDrawableTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportButtonDrawableTint(mCompoundButtonTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mCompoundButtonResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setButtonDrawable(drawable);
        }
    }
    array.recycle();
}

From source file:com.bilibili.magicasakura.widgets.AppCompatForegroundHelper.java

@SuppressWarnings("ResourceType")
@Override/* w  w w. j ava  2  s. co m*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mForegroundResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportForegroundTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportForegroundTint(mForegroundTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mForegroundResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setForegroundDrawable(drawable);
        }
    }
    array.recycle();
}

From source file:com.pierfrancescosoffritti.shrinkingimagelayout.parallaxScrimageView.ParallaxScrimageView.java

public ParallaxScrimageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ParallaxScrimageView);
        if (a.hasValue(R.styleable.ParallaxScrimageView_scrimColor)) {
            scrimColor = a.getColor(R.styleable.ParallaxScrimageView_scrimColor, scrimColor);
        }//from w  ww  .j  av a  2s.  c  o  m
        if (a.hasValue(R.styleable.ParallaxScrimageView_scrimAlpha)) {
            scrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_scrimAlpha, scrimAlpha);
        }
        if (a.hasValue(R.styleable.ParallaxScrimageView_maxScrimAlpha)) {
            maxScrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_maxScrimAlpha, maxScrimAlpha);
        }
        if (a.hasValue(R.styleable.ParallaxScrimageView_parallaxFactor)) {
            parallaxFactor = a.getFloat(R.styleable.ParallaxScrimageView_parallaxFactor, parallaxFactor);
        }
        a.recycle();
    }

    scrimPaint = new Paint();
    scrimPaint.setColor(ColorUtils.modifyAlpha(scrimColor, scrimAlpha));
}

From source file:me.oriley.vista.VistaEdgeEffectHelper.java

public VistaEdgeEffectHelper(@NonNull VistaEdgeEffectHost customEdgeEffectHost, @NonNull Context context,
        @Nullable AttributeSet attrs) {
    mHost = customEdgeEffectHost;//from   w  w  w.ja  v a  2  s .com

    float thicknessScale = DEFAULT_THICKNESS_SCALE;
    float edgeScale = DEFAULT_EDGE_SCALE;
    boolean disableHotspot = false;

    boolean customColor = false;
    int initialColor = Color.WHITE;

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VistaView);
        if (a.hasValue(R.styleable.VistaView_vistaColor)) {
            customColor = true;
            initialColor = a.getColor(R.styleable.VistaView_vistaColor, initialColor);
        }
        disableHotspot = a.getBoolean(R.styleable.VistaView_vistaDisableHotspot, false);
        thicknessScale = a.getFloat(R.styleable.VistaView_vistaThicknessScale, DEFAULT_THICKNESS_SCALE);
        edgeScale = a.getFloat(R.styleable.VistaView_vistaEdgeScale, DEFAULT_EDGE_SCALE);
        a.recycle();
    }

    // Couldn't get from attribute, try app compat accent color
    if (!customColor) {
        TypedValue typedValue = new TypedValue();
        TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
        initialColor = a.getColor(0, Color.WHITE);
        a.recycle();
    }

    mInitialColor = initialColor;
    mDisableHotspot = disableHotspot;
    mThicknessScale = thicknessScale;
    mEdgeScale = edgeScale;
}