Example usage for android.content.res TypedArray getDrawable

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

Introduction

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

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:com.hippo.preference.DialogPreference.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr,
            defStyleRes);/*from   w  ww .j av a2s  . com*/
    mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
    if (mDialogTitle == null) {
        // Fallback on the regular title of the preference
        // (the one that is seen in the list)
        mDialogTitle = getTitle();
    }
    mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon);
    mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText);
    mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText);
    mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId);
    a.recycle();
}

From source file:com.github.segoh.viewpagerindicator.ViewPagerIndicator.java

public ViewPagerIndicator(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    if (isInEditMode()) {
        return;//from  www . j a v  a  2 s.c  om
    }
    final Resources res = getResources();
    final int defaultCurrentPageColor = res.getColor(R.color.vpi__current_page);
    final int defaultPageColor = res.getColor(R.color.vpi__page);
    final float defaultRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
            res.getDisplayMetrics());
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerIndicator, defStyleAttr, 0);
    if (a != null) {
        mPaintPage.setStyle(Paint.Style.FILL);
        mPaintPage.setColor(a.getColor(R.styleable.ViewPagerIndicator_pageColor, defaultPageColor));
        mPaintCurrentPage.setStyle(Paint.Style.FILL);
        mPaintCurrentPage
                .setColor(a.getColor(R.styleable.ViewPagerIndicator_currentPageColor, defaultCurrentPageColor));
        mRadius = a.getDimension(R.styleable.ViewPagerIndicator_radius, defaultRadius);
        Drawable background = a.getDrawable(R.styleable.ViewPagerIndicator_android_background);
        setBackgroundDrawable(background);
        a.recycle();
    }
}

From source file:com.mfh.framework.uikit.widget.SideSlidingTabStrip.java

public SideSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); // ??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager,
                    false);//from   w w w. j av a  2  s  .  co  m
            attrsTypedArray.recycle();
        }
    }
}

From source file:com.mfh.litecashier.ui.widget.LeftSlidingTabStrip.java

public LeftSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); // ??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager,
                    false);/*from   w  ww  .  jav a2s  .co  m*/
            attrsTypedArray.recycle();
        }
    }
}

From source file:com.triggertrap.seekarc.SeekArc.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    Log.d(TAG, "Initialising SeekArc");
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = ContextCompat.getColor(context, R.color.progress_gray);
    int progressColor = ContextCompat.getColor(context, R.color.default_blue_light);
    // Convert progress width to pixels for current density
    mProgressWidth = (int) (mProgressWidth * density);

    if (attrs != null) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekArc, defStyle, 0);

        arcColor = a.getColor(R.styleable.SeekArc_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.SeekArc_progressColor, progressColor);

        Drawable thumb = a.getDrawable(R.styleable.SeekArc_thumb);
        if (thumb != null) {
            setThumb(thumb);//from   w w w .j  a v  a  2s  .c om
            mThumb.setColorFilter(progressColor, PorterDuff.Mode.SRC_IN);
        } else {
            setThumb(ContextCompat.getDrawable(context, R.drawable.seek_arc_control_selector));
        }

        mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
        mProgress = a.getInteger(R.styleable.SeekArc_progress, mProgress);
        mProgressWidth = (int) a.getDimension(R.styleable.SeekArc_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth, mArcWidth);
        mStartAngle = a.getInt(R.styleable.SeekArc_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.SeekArc_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.SeekArc_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.SeekArc_roundEdges, mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.SeekArc_touchInside, mTouchInside);
        mClockwise = a.getBoolean(R.styleable.SeekArc_clockwise, mClockwise);
        mEnabled = a.getBoolean(R.styleable.SeekArc_enabled, mEnabled);

        a.recycle();
    }

    mProgress = (mProgress > mMax) ? mMax : mProgress;
    mProgress = (mProgress < 0) ? 0 : mProgress;

    mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
    mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

    mProgressSweep = (float) mProgress / mMax * mSweepAngle;

    mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
    mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

    mArcPaint = new Paint();
    mArcPaint.setColor(arcColor);
    mArcPaint.setAntiAlias(true);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);
    //mArcPaint.setAlpha(45);

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mProgressWidth);

    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    }
}

From source file:co.paulburke.android.textviewpager.TextViewPagerIndicator.java

public TextViewPagerIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;// w  ww. j av  a  2s  . co  m

    final Resources res = getResources();

    // Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.scroll_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.scroll_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.scroll_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.scroll_indicator_selected_color);

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

    setFades(a.getBoolean(R.styleable.TextViewPagerIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.TextViewPagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.TextViewPagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.TextViewPagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.TextViewPagerIndicator_android_background);
    if (background != null)
        setBackgroundDrawable(background);

    a.recycle();
}

From source file:com.lovebridge.library.view.viewpagerindicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w  w  w.  j av a2s  .c  o  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));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));
    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:com.ring.widget.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); //??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager,
                    false);//from  w  ww.j  a v  a  2s . c o m
            disableTensileSlidingBlock = attrsTypedArray
                    .getBoolean(R.styleable.PagerSlidingTabStrip_disableTensileSlidingBlock, false);
            attrsTypedArray.recycle();
        }
    }
    init();
}

From source file:com.ekumen.tangobot.application.ModuleStatusIndicator.java

/**
 * Look for the resource according to the case and apply it with its respective color.
 * Note: This function does not perform any checks as assumes the xml file is correct.
 * It should have one array for each state, and each array should have a drawable resource and a color resource (in that order).
 *///from  ww w. ja va 2  s  . co  m
private void switchStatusDisplay() {
    mActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            TypedArray img = null;

            switch (mStatus) {
            case PAUSED:
                img = mActivity.getResources().obtainTypedArray(R.array.status_paused);
                break;

            case OK:
                img = mActivity.getResources().obtainTypedArray(R.array.status_running);
                break;

            case LOADING:
                img = mActivity.getResources().obtainTypedArray(R.array.status_loading);
                break;

            case ERROR:
                img = mActivity.getResources().obtainTypedArray(R.array.status_error);
                break;
            }

            int color = img.getColor(COLOR_INDEX, mActivity.getResources().getColor(android.R.color.black));
            Drawable drawable = img.getDrawable(RESOURCE_INDEX);
            mImageView.setImageDrawable(drawable);
            drawable = DrawableCompat.wrap(mImageView.getDrawable().mutate());
            DrawableCompat.setTint(drawable, color);
            img.recycle();
        }
    });
}

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

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w w  w .  j  a  v a 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));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

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

    a.recycle();

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