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:cl.monsoon.s1next.widget.BezelImageView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    // attribute initialization
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
            defStyleAttr, defStyleRes);/*from ww  w.j  av  a  2  s  .  c o  m*/

    mMaskDrawable = typedArray.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mBorderDrawable = typedArray.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    typedArray.recycle();

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // always want a cache allocated
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
}

From source file:app.philm.in.view.InsetFrameLayout.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawInsetsFrameLayout, defStyle, 0);
    if (a == null) {
        return;/*from  w ww  .  j  a  v a  2 s.co m*/
    }
    mDefaultInsetBackground = mInsetBackground = a
            .getDrawable(R.styleable.DrawInsetsFrameLayout_insetBackground);
    a.recycle();

    setWillNotDraw(true);
}

From source file:com.dream.yzbb.wolfkiller.widget.BezelImageView.java

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

    // Attribute initialization.
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
            defStyle, 0);/*www.j a v  a 2  s  .c o  m*/

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress,
            mDesaturateOnPress);

    a.recycle();

    // Other initialization.
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.actionbarsherlock.internal.widget.ActionBarContainer.java

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

    setBackgroundDrawable(null);/*  w  ww  . j  a v  a2s.com*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionBar);
    mBackground = a.getDrawable(R.styleable.SherlockActionBar_background);
    mStackedBackground = a.getDrawable(R.styleable.SherlockActionBar_backgroundStacked);

    if (getId() == R.id.abs__split_action_bar) {
        mIsSplit = true;
        mSplitBackground = a.getDrawable(R.styleable.SherlockActionBar_backgroundSplit);
    }
    a.recycle();

    setWillNotDraw(mIsSplit ? mSplitBackground == null : mBackground == null && mStackedBackground == null);
}

From source file:com.retropoktan.rptrello.widget.BezelImageView.java

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

    // Attribute initialization.
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*from  w  w  w  .  j  a v a  2 s  .co m*/

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    mSetOutline = a.getBoolean(R.styleable.BezelImageView_setOutline, mSetOutline);

    a.recycle();

    // Other initialization.
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

protected void init() {
    //1. get clean
    int[] attrs = new int[] { R.attr.ic_clear };
    TypedArray ta = getContext().obtainStyledAttributes(attrs);
    mCleanImage = ta.getDrawable(0);
    ta.recycle();/*from w  ww  .  java2s.  c  om*/

    mClearBuff = (int) (getContext().getResources().getDisplayMetrics().density * CLEAR_BUFF_DP);
    mClearImageSize = (int) (getContext().getResources().getDisplayMetrics().density * CLEAR_IMAGE_SIZE_DP);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(3);
    mPaint.setDither(true);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    boolean bDark = PreferenceManager.getDefaultSharedPreferences(getContext())
            .getString(SettingsConstantsUI.KEY_PREF_THEME, "light").equals("dark");
    if (bDark)
        mPaint.setColor(Color.WHITE);
    else
        mPaint.setColor(Color.BLACK);

    mPath = new Path();
    mPaths.add(mPath);
}

From source file:com.grarak.kerneladiutor.views.recyclerview.CardView.java

@Override
protected void refresh() {
    super.refresh();
    if (mTitle != null) {
        if (mTitleText != null) {
            mTitle.setText(mTitleText);/*ww  w. j  a va 2 s. c o  m*/
            mTitle.setVisibility(View.VISIBLE);
        } else {
            mTitle.setVisibility(View.GONE);
        }
    }
    if (mMenuButton != null && mOnMenuListener != null) {
        mMenuButton.setVisibility(View.VISIBLE);
        mPopupMenu = new PopupMenu(mMenuButton.getContext(), mMenuButton);
        mOnMenuListener.onMenuReady(this, mPopupMenu);
    }
    if (mRootView != null && getOnItemClickListener() != null) {
        TypedArray typedArray = mRootView.getContext()
                .obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
        mRootView.setForeground(typedArray.getDrawable(0));
        typedArray.recycle();
        mRootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getOnItemClickListener().onClick(CardView.this);
            }
        });
    }
}

From source file:com.android.mail.browse.ConversationPagerController.java

private void setupPageMargin(Context c) {
    final TypedArray a = c.obtainStyledAttributes(new int[] { android.R.attr.listDivider });
    final Drawable divider = a.getDrawable(0);
    a.recycle();//from   w  ww .j  a  v a 2  s  . c  o  m
    final int padding = c.getResources().getDimensionPixelOffset(R.dimen.conversation_page_gutter);
    final Drawable gutterDrawable = new PageMarginDrawable(divider, padding, 0, padding, 0,
            c.getResources().getColor(R.color.conversation_view_background_color));
    mPager.setPageMargin(gutterDrawable.getIntrinsicWidth() + 2 * padding);
    mPager.setPageMarginDrawable(gutterDrawable);
}

From source file:com.github.andrewlord1990.materialandroid.component.textfield.PasswordEditText.java

private void loadIcons(TypedArray attrs) {
    shownIcon = attrs.getDrawable(R.styleable.MDPasswordEditText_md_password_shown_drawable);
    hiddenIcon = attrs.getDrawable(R.styleable.MDPasswordEditText_md_password_hidden_drawable);
}

From source file:com.saarang.samples.apps.iosched.ui.widget.BezelImageView.java

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

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs,
            com.saarang.samples.apps.iosched.R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(com.saarang.samples.apps.iosched.R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*  ww w  . j  av  a  2 s .  c  om*/

    mBorderDrawable = a.getDrawable(com.saarang.samples.apps.iosched.R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(
            com.saarang.samples.apps.iosched.R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}