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:com.android.andryyu.lifehelper.widget.RippleView.java

/**
 * Method that initializes all fields and sets listeners
 *
 * @param context Context used to create this view
 * @param attrs   Attribute used to initialize fields
 *///  w  w  w  . ja  v  a 2  s .c om
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
    rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, Color.parseColor("#33626262"));
    rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
    hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
    isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
    rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration);
    frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate);
    rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha);
    ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
    canvasHandler = new Handler();
    zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
    zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
    isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false);
    typedArray.recycle();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);
    this.setWillNotDraw(false);

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent event) {
            super.onLongPress(event);
            animateRipple(event);
            sendClickEvent(true);
            lastLongPressX = (int) event.getX();
            lastLongPressY = (int) event.getY();
            rippleStatus = RIPPLE_LONG_PRESS;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });

    this.setDrawingCacheEnabled(true);
    this.setClickable(true);
    this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

From source file:cc.chenghong.vkagetorder.material.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);

    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] { mProgressColor };

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;/*from  w w w.ja  v  a2 s  .com*/
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    mProgressDrawable.setStartEndTrim(0, (float) 0.75);
    super.setImageDrawable(mProgressDrawable);
}

From source file:com.achenging.view.SlidingTabLayout.java

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

    mTabStrip = new SlidingTabStrip(context);
    int defaultBackgroundColor = mTabStrip.getSolidColor();

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(true);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from   w  w  w  . ja  v  a2 s .  co m
    //?
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    //
    mTabSelectedTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabSelectedTextColor, 0);
    mTabTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabTextColor, 0);

    //
    int selectedIndicatorThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_tabIndicatorThickness, SELECTED_INDICATOR_THICKNESS_DIPS);
    //
    int tabIndicatorColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabIndicatorColor,
            DEFAULT_SELECTED_INDICATOR_COLOR);

    //tab
    int tabDividerThickness = (int) typedArray.getDimension(R.styleable.SlidingTabLayout_dividerThickness,
            DEFAULT_DIVIDER_THICKNESS_DIPS);
    //tab
    int tabDividerColor = typedArray.getColor(R.styleable.SlidingTabLayout_dividerColor,
            defaultBackgroundColor);

    //tab??
    int tabBottomBorderThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_bottomBorderThickness, DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS);
    int tabBottomBorderColor = typedArray.getColor(R.styleable.SlidingTabLayout_bottomBorderColor,
            defaultBackgroundColor);

    //?tab?
    boolean showAsDivider = typedArray.getBoolean(R.styleable.SlidingTabLayout_showAsDivider, false);

    typedArray.recycle();
    //

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

    mTextPadding = (int) (DEFAULT_TEXT_PADDING * getResources().getDisplayMetrics().density);

    //
    setSelectedTitleColors(mTabSelectedTextColor);
    setUnSelectedTitleColors(mTabTextColor);
    setDividerColors(tabDividerColor);
    setSelectedIndicatorColors(tabIndicatorColor);
    setTabBottomBorderColor(tabBottomBorderColor);
    setTabDividerColor(tabDividerColor);
    //
    setSelectedIndicatorThickness(selectedIndicatorThickness);
    setTabBottomBorderThickness(tabBottomBorderThickness);
    setTabDividerThickness(tabDividerThickness);
    setShowAsDivider(showAsDivider);
    setShowTabDivider(false);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    addView(mTabStrip);
}

From source file:com.dl7.commonlib.views.RippleView.java

/**
 * Method that initializes all fields and sets listeners
 *
 * @param context Context used to create this view
 * @param attrs Attribute used to initialize fields
 *///from  www  .jav  a 2s.c o  m
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
    rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color,
            ContextCompat.getColor(context, R.color.rippelColor));
    rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
    hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
    isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
    rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration);
    frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate);
    rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha);
    ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
    canvasHandler = new Handler();
    zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
    zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
    isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false);
    typedArray.recycle();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);
    this.setWillNotDraw(false);

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent event) {
            super.onLongPress(event);
            animateRipple(event);
            sendClickEvent(true);
            lastLongPressX = (int) event.getX();
            lastLongPressY = (int) event.getY();
            rippleStatus = RIPPLE_LONG_PRESS;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });

    this.setDrawingCacheEnabled(true);
    this.setClickable(true);
    this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

From source file:com.ch.ch_library.smartlayout.SmartTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//www  .  j  av a2 s  .c om
    setOverScrollMode(OVER_SCROLL_NEVER);

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    int textColor = TAB_VIEW_TEXT_COLOR;
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int textLayoutId = NO_ID;
    int textViewId = NO_ID;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    textLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, textLayoutId);
    textViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, textViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    a.recycle();

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * density);
    mTabViewTextAllCaps = textAllCaps;
    mTabViewTextColor = textColor;
    mTabViewTextSize = textSize;
    mTabViewTextHorizontalPadding = textHorizontalPadding;
    mTabViewTextMinWidth = textMinWidth;
    mTabViewLayoutId = textLayoutId;
    mTabViewTextViewId = textViewId;
    mDistributeEvenly = distributeEvenly;

    mTabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

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

From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedComment.java

public RedditPreparedComment(final Context context, final RedditComment comment,
        final RedditPreparedComment parentComment, final long timestamp, final boolean needsUpdating,
        final RedditPreparedPost parentPost, final RedditAccount user,
        final EnumSet<PrefsUtility.AppearanceCommentHeaderItems> headerItems) {

    this.src = comment;
    this.parentPost = parentPost;
    this.headerItems = headerItems;

    // TODO custom time

    // TODO don't fetch these every time
    final TypedArray appearance = context
            .obtainStyledAttributes(new int[] { R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol,
                    R.attr.rrPostSubtitleUpvoteCol, R.attr.rrPostSubtitleDownvoteCol });

    rrCommentHeaderBoldCol = appearance.getColor(0, 255);
    rrCommentHeaderAuthorCol = appearance.getColor(1, 255);
    rrPostSubtitleUpvoteCol = appearance.getColor(2, 255);
    rrPostSubtitleDownvoteCol = appearance.getColor(3, 255);

    body = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(comment.body));
    if (comment.author_flair_text != null) {
        flair = StringEscapeUtils.unescapeHtml4(comment.author_flair_text);
    } else {/*from w  ww .j  a  v a2s  . c om*/
        flair = null;
    }

    if (parentComment == null) {
        indentation = 0;
    } else {
        indentation = parentComment.indentation + 1;
        parentComment.addChild(this);
    }

    idAlone = comment.id;
    idAndType = comment.name;

    if (comment.likes == null) {
        voteDirection = 0;
    } else {
        voteDirection = Boolean.TRUE.equals(comment.likes) ? 1 : -1;
    }

    lastChange = timestamp;
    if (src.likes != null) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, true);
    } else if (needsUpdating) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, false);
    }

    rebuildHeader(context);
}

From source file:com.example.test2969mediabrowser.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w w  w.  j ava  2 s .co m

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    mColorSelected = a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor);//joe

    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    //==================joe add 20150918===============
    defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);//joe
    mPaintText.setTextSize(res.getDimension(R.dimen.default_title_indicator_text_size));
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(defaultFooterLineHeight);
    mPaintFooterLine.setColor(getResources().getColor(R.color.blue_select));
    //==================joe add 20150918 end===============

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

private void init(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
    mArcWidth = getResources().getDimensionPixelSize(R.dimen.fp_progress_arc_stroke_width);
    mFabIcon = getDrawable();/*  w  w  w  .  ja va2  s.  c  o m*/
    mAccentColor = fetchAccentColor();

    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FabProgress, defStyleAttr, 0);
    try {
        mArcColor = attr.getColor(R.styleable.FabProgress_fp_arcColor,
                ContextCompat.getColor(context, R.color.green_500));
        mUseRoundedStroke = attr.getBoolean(R.styleable.FabProgress_fp_roundedStroke, false);
        mCompleteIcon = attr.getDrawable(R.styleable.FabProgress_fp_finalIcon);
        if (mCompleteIcon == null) {
            mCompleteIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_done_white_24dp);
        }
        mIsReusable = attr.getBoolean(R.styleable.FabProgress_fp_reusable, false);
    } finally {
        attr.recycle();
    }

    if (!Utils.isRunningLollipopAndHigher()) {
        setFakeShadowPadding(context, attrs, defStyleAttr);
    }

    setupPaint();
    setupAnimations();
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;/*from www  .  j a  v  a  2  s.  c o  m*/
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(a.getColor(0, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

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  a  va  2  s .com*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    a.recycle();
    recalculate();
}