Example usage for android.content.res TypedArray getColor

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

Introduction

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

Prototype

@ColorInt
public int getColor(@StyleableRes int index, @ColorInt int defValue) 

Source Link

Document

Retrieve the color value for the attribute at index.

Usage

From source file:angeloid.dreamnarae.SwipeyTabs.java

public SwipeyTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeyTabs, defStyle, 0);

    mBottomBarColor = a.getColor(R.styleable.SwipeyTabs_bottomBarColor, mBottomBarColor);
    mBottomBarHeight = a.getDimensionPixelSize(R.styleable.SwipeyTabs_bottomBarHeight, 2);
    mTabIndicatorHeight = a.getDimensionPixelSize(R.styleable.SwipeyTabs_tabIndicatorHeight, 3);

    a.recycle();/*from  w  w w . jav a2s .c o m*/

    init();
}

From source file:android.support.wear.widget.CircularProgressLayout.java

private int[] getColorListFromResources(Resources resources, int arrayResId) {
    TypedArray colorArray = resources.obtainTypedArray(arrayResId);
    int[] colors = new int[colorArray.length()];
    for (int i = 0; i < colorArray.length(); i++) {
        colors[i] = colorArray.getColor(i, 0);
    }//from  w ww  .  j  a  va 2  s.  co m
    colorArray.recycle();
    return colors;
}

From source file:com.development.jaba.view.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Setup the defaults for the colors.
    mTitleColor = R.color.slidingTabTitleColor;
    int titleSelectedColor = R.color.slidingTabSelectedTitleColor;
    int dividerColor = R.color.slidingTabDividerColor;
    int indicatorColor = R.color.slidingTabIndicatorColor;

    // Dig through the attributes to find the colors that were
    // set through the XML.
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout, 0, 0);

        try {// w  ww . j a  v  a 2s .  c o m
            mTitleColor = a.getColor(R.styleable.SlidingTabLayout_stlTitleColor, mTitleColor);
            titleSelectedColor = a.getColor(R.styleable.SlidingTabLayout_stlTitleColorSelected,
                    titleSelectedColor);
            dividerColor = a.getColor(R.styleable.SlidingTabLayout_stlDividerColor, dividerColor);
            indicatorColor = a.getColor(R.styleable.SlidingTabLayout_stlIndicatorColor, indicatorColor);
        } catch (Exception e) {
            Log.e("SlidingTabLayout", "Unable to load attributes");
        } finally {
            a.recycle();
        }
    }

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    // Make sure that the Tab Strips fills this View
    setFillViewport(true);

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);

    mTabStrip.setDividerColors(dividerColor);
    mTabStrip.setSelectedIndicatorColors(indicatorColor);
    mTabStrip.setTitleColors(mTitleColor);
    mTabStrip.setSelectedTitleColors(titleSelectedColor);

    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.view.IconicsImageView.java

public IconicsImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (!isInEditMode()) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView, defStyle, 0);
        String icon = a.getString(R.styleable.IconicsImageView_iiv_icon);

        //set the color even if we had no image yet
        mColor = a.getColor(R.styleable.IconicsImageView_iiv_color, 0);
        mSize = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_size, -1);
        mPadding = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_padding, -1);
        mContourColor = a.getColor(R.styleable.IconicsImageView_iiv_contour_color, 0);
        mContourWidth = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_contour_width, -1);
        mBackgroundColor = a.getColor(R.styleable.IconicsImageView_iiv_background_color, 0);
        mCornerRadius = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_corner_radius, -1);

        //recycle the typedArray
        a.recycle();//from  ww w.  java2s .c  o m

        //set the scale type for this view
        setScaleType(ScaleType.CENTER_INSIDE);

        //if we have no icon return now
        if (icon == null) {
            return;
        }

        //get the drawable
        mIcon = new IconicsDrawable(context, icon);

        //set attributes
        setAttributes();

        //set our values for this view
        setImageDrawable(mIcon);
    }
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

public void setTextAppearance(int resId) {
    TypedArray atp = this.getContext().obtainStyledAttributes(resId, R.styleable.CollapsingTextAppearance);
    this.mTextPaint.setColor(atp.getColor(R.styleable.CollapsingTextAppearance_android_textColor, Color.WHITE));
    this.mCollapsedTitleTextSize = atp
            .getDimensionPixelSize(R.styleable.CollapsingTextAppearance_android_textSize, 0);

    // added shadow so the text shows better on top of bright images
    this.mTextPaint.setShadowLayer(5, 0, 0, Color.rgb(0, 0, 0));

    atp.recycle();//from  w ww.  ja v  a2  s  .  co m

    this.recalculate();
}

From source file:com.franmontiel.fullscreendialog.FullScreenDialogFragment.java

private void tintToolbarHomeButton(Toolbar toolbar, Drawable homeButtonDrawable) {
    int[] colorAttrs = new int[] { R.attr.colorControlNormal };
    TypedArray a = toolbar.getContext().obtainStyledAttributes(colorAttrs);
    int color = a.getColor(0, -1);
    a.recycle();/*from  w ww .  j a va2 s .  c o m*/

    DrawableCompat.setTint(DrawableCompat.wrap(homeButtonDrawable), color);
}

From source file:com.chess.genesis.view.SwipeTabs.java

public SwipeTabs(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeTabs, defStyle, 0);

    mBottomBarColor = a.getColor(R.styleable.SwipeTabs_bottomBarColor, mBottomBarColor);
    mBottomBarHeight = a.getDimensionPixelSize(R.styleable.SwipeTabs_bottomBarHeight, 2);
    mTabIndicatorHeight = a.getDimensionPixelSize(R.styleable.SwipeTabs_tabIndicatorHeight, 3);

    a.recycle();/*from w ww  .j a  v  a 2  s  .  c o m*/

    init();
}

From source file:am.widget.MaterialProgressImageView.java

private void initView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final float density = getResources().getDisplayMetrics().density;
    ArrayList<Integer> colors = new ArrayList<>();
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressImageView,
            defStyleAttr, defStyleRes);/* w  w  w  .j  a  va  2s  .c  om*/
    boolean autoStart = custom.getBoolean(R.styleable.MaterialProgressImageView_mpiAutoStart, true);
    int color = custom.getColor(R.styleable.MaterialProgressImageView_mpiShadowsCircleColor, DEFAULT_COLOR);
    float elevation = custom.getDimension(R.styleable.MaterialProgressImageView_mpiElevation,
            density * SHADOW_ELEVATION);
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor1)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor1, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor2)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor2, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor3)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor3, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor4)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor4, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor5)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor5, Color.BLACK));
    }
    custom.recycle();
    setElevationCompat(elevation);
    Drawable background = getBackground();
    if (background == null)
        setShadowsCircleBackground(color);
    drawable = new MaterialProgressDrawable(density);
    drawable.setBackgroundColor(0x00000000);
    drawable.setAlpha(255);
    drawable.setCallback(this);
    final int size = colors.size();
    if (size > 0) {
        int[] colorArray = new int[size];
        for (int i = 0; i < size; i++) {
            colorArray[i] = colors.get(i);
        }
        drawable.setColorSchemeColors(colorArray);
    }
    setImageDrawable(drawable);
    if (autoStart)
        start();
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private int getDefaultTextColor(Context context) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data,
            new int[] { android.R.attr.textColorPrimary });
    int defaultTextColor = typedArray.getColor(0, Color.BLACK);
    typedArray.recycle();/*from w w w .  ja v  a  2  s.co m*/
    return defaultTextColor;
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

public SunriseDrawable(Context context) {

    mContext = context;//from  w w w  .j  a  v  a 2s  . c  o  m

    Resources res = context.getResources();
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.colorPrimary, R.attr.colorAccent,
            R.attr.colorPrimaryDark, R.attr.appsiHomeWidgetPrimaryColor, });

    int primaryColor = a.getColor(0, Color.BLACK);
    int accentColor = a.getColor(1, Color.BLACK);
    int primaryColorDark = a.getColor(2, Color.BLACK);
    int textColor = a.getColor(3, Color.BLACK);
    a.recycle();

    mIsRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;

    float density = res.getDisplayMetrics().density;
    int sunBounds = (int) (density * 16);
    mTopOffset = (int) (density * 12);
    mLeftOffset = (int) (density * 24);
    mRightOffset = (int) (density * 24);
    mBottomOffset = (int) (density * 24);
    mDotRadius = (int) (density * 2);

    mSunImage = mContext.getResources().getDrawable(R.drawable.ic_weather_clear);
    mSunImage.setBounds(0, 0, sunBounds, sunBounds);

    mArcPaint = new Paint();
    mArcPaint.setColor(primaryColorDark);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setAntiAlias(true);

    mArcFillPaint = new Paint();
    mArcFillPaint.setColor(primaryColor);
    mArcFillPaint.setAlpha(64);
    mArcFillPaint.setStyle(Paint.Style.FILL);
    mArcFillPaint.setAntiAlias(true);

    mLinePaint = new Paint();
    mLinePaint.setColor(textColor);
    mLinePaint.setAlpha(128);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mDotPaint = new Paint();
    mDotPaint.setStyle(Paint.Style.FILL);
    mDotPaint.setColor(primaryColorDark);
    mDotPaint.setAntiAlias(true);
}