Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:android.tumb.com.tumb.Misc.DividerItemDecoration.java

public DividerItemDecoration(Context context) {
    final TypedArray styledAttributes = context.obtainStyledAttributes(ATTRS);
    mDivider = ContextCompat.getDrawable(context, R.drawable.question_recycler_decorator);
    styledAttributes.recycle();/*from  w ww . j  ava  2 s  .co  m*/
}

From source file:com.cesards.samples.cropimageview.activity.CustomCropActivity.java

@Override
protected ImageView instantiatePagerItem(int position) {
    ForegroundCropImageView testCropImageView = new ForegroundCropImageView(CustomCropActivity.this);

    int image = images[position];
    if (image != -1) {
        testCropImageView.setImageDrawable(ContextCompat.getDrawable(this, image));
        testCropImageView.setForeground(ContextCompat.getDrawable(this, R.drawable.shape_grad_black_transp_70));
        @CropType//  w w  w  .ja  va  2s.c  om
        final int cropType = images[position];
        testCropImageView.setCropType(cropType);
        testCropImageView.setId(cropType);
    } else {
        testCropImageView.setImageDrawable(null);
    }

    return testCropImageView;
}

From source file:com.hippo.gl.glrenderer.XmlResourceTexture.java

@Override
protected Bitmap onGetBitmap() {
    Drawable drawable = ContextCompat.getDrawable(mContext, mResId);

    int width = mWidth;
    int height = mHeight;
    if (width <= 0) {
        width = drawable.getIntrinsicWidth();
    }/*from   w  w  w.  j  a v  a 2 s . c o m*/
    if (height <= 0) {
        height = drawable.getIntrinsicHeight();
    }
    if (width <= 0) {
        width = 1;
    }
    if (height <= 0) {
        height = 1;
    }

    drawable.setBounds(0, 0, width, height);

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);

    return bitmap;
}

From source file:com.jameswolfeoliver.pigeon.Utilities.Utils.java

public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);/*w  w w . j  a v a2s.co  m*/
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:com.filemanager.free.ui.icons.IconUtils.java

public Drawable getRootDrawable() {
    if (CURRENT == LIGHT)
        return ContextCompat.getDrawable(c, R.drawable.root);
    else//w w w .  j  a  va2  s  .co m
        return ContextCompat.getDrawable(c, R.drawable.root);
}

From source file:com.fox.myappstore.widgets.DividerDecoration.java

/**
 * Custom divider will be used
 */
public DividerDecoration(Context context, int resId) {
    divider = ContextCompat.getDrawable(context, resId);
}

From source file:com.example.zjy.niklauslibrary.rvhelper.divider.DividerItemDecoration.java

public DividerItemDecoration(Context context, int orientation, int drawableID) {
    this(context, orientation);
    mDivider = ContextCompat.getDrawable(context, drawableID);
}

From source file:app.iamin.iamin.ui.recyclerview.DividerItemDecoration.java

public DividerItemDecoration(Context context, int orientation) {
    mDivider = ContextCompat.getDrawable(context, R.drawable.divider);
    setOrientation(orientation);
}

From source file:agricultural.nxt.agriculturalsupervision.Activity.Seed.SeedDetailActivity.java

@Override
protected void initView() {
    toolBar.setTitle("??");
    toolBar.setLeftButtonIcon(ContextCompat.getDrawable(this, R.mipmap.icon_arrow_02));
    toolBar.setLeftButtonOnClickLinster(v -> finish());
    getData();//  w w  w  .  j a  v a2 s  . c  om
}

From source file:com.justplay1.shoppist.shared.widget.ColorMultiCheckedBox.java

public void setColor(@ColorInt int color) {
    StateListDrawable states = new StateListDrawable();

    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_000);
    Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_015);

    if (isEnabled()) {
        states.setColorFilter(DrawableUtils.getColorFilter(color));
    } else {/*  w w w  .j a  va2s. c o  m*/
        states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY));
    }

    states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable);
    states.addState(new int[] { android.R.attr.state_checked }, checked);
    states.addState(new int[] { android.R.attr.state_enabled }, drawable);
    states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked);
    states.addState(new int[] { -android.R.attr.state_enabled }, drawable);

    setButtonDrawable(states);
}