Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable BitmapDrawable.

Prototype

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:com.danimahardhika.android.helpers.core.DrawableHelper.java

@Nullable
public static Drawable toDrawable(@NonNull Context context, @NonNull Bitmap bitmap) {
    try {//from  w ww .ja  va2 s.c om
        return new BitmapDrawable(context.getResources(), bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }
}

From source file:com.nerderylabs.android.nerdalert.ui.adapter.RecyclerViewAdapter.java

@Override
public void onBindViewHolder(RecyclerViewAdapter.ViewHolder holder, int position) {

    Neighbor neighbor = neighbors.get(position);
    if (neighbor.getName() != null) {
        holder.name.setText(neighbor.getName());
    }/* w w  w.  j a v  a2s .  co m*/
    if (neighbor.getTagline() != null) {
        holder.tagline.setText(neighbor.getTagline());
    }
    if (neighbor.getBitmap() != null) {
        holder.photo.setImageDrawable(new BitmapDrawable(context.getResources(), neighbor.getBitmap()));
    } else {
        Drawable photo = ContextCompat.getDrawable(context, tab.getEmptyPhotoDrawableId());
        DrawableCompat.setTint(photo, ContextCompat.getColor(context, R.color.color_nametag));
        holder.photo.setImageDrawable(photo);
    }

}

From source file:com.dm.wallpaper.board.helpers.DrawableHelper.java

@Nullable
public static Drawable getDefaultImage(@NonNull Context context, @DrawableRes int res, @ColorInt int color,
        int padding) {
    try {//  ww  w  . j a v a  2s .  com
        Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        Bitmap tintedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() + padding,
                Bitmap.Config.ARGB_8888);
        Canvas tintedCanvas = new Canvas(tintedBitmap);
        int background = ColorHelper.getAttributeColor(context, R.attr.card_background);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setAntiAlias(true);
        tintedCanvas.drawColor(background, PorterDuff.Mode.ADD);
        tintedCanvas.drawBitmap(bitmap, (tintedCanvas.getWidth() - bitmap.getWidth()) / 2,
                (tintedCanvas.getHeight() - bitmap.getHeight()) / 2, paint);
        return new BitmapDrawable(context.getResources(), tintedBitmap);
    } catch (Exception | OutOfMemoryError e) {
        return null;
    }
}

From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();//from   w  w w  .  j a  v  a2 s  . co  m
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
    PreferenceCategory category = new PreferenceCategory(this);
    category.setTitle(R.string.filter_pokemons);
    screen.addPreference(category);
    try {
        JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json"));
        for (int i = 0; i < pokemonList.length(); i++) {
            JSONObject pokemon = pokemonList.getJSONObject(i);
            CheckBoxPreference checkBox = new CheckBoxPreference(this);
            checkBox.setTitle(pokemon.getString("Name"));
            checkBox.setIcon(new BitmapDrawable(getResources(),
                    Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number")))));
            checkBox.setDefaultValue(true);
            checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary),
                    pokemon.getString("Name")));
            checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number")));
            category.addPreference(checkBox);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    setPreferenceScreen(screen);
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getResizedDrawable(@NonNull Context context, @DrawableRes int drawableRes,
        @DimenRes int dimenRes) {
    try {//  w ww.j a  v a2  s.  c  o m
        Drawable drawable = getDrawable(context, drawableRes);
        if (drawable == null)
            return null;

        int size = context.getResources().getDimensionPixelSize(dimenRes);

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, size, size, true));
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.d(Log.getStackTraceString(e));
        return null;
    }
}

From source file:com.nadmm.airports.utils.UiUtils.java

public static Drawable combineDrawables(Context context, Drawable d1, Drawable d2, int paddingDp) {
    // Assumes both d1 & d2 are same size and square shaped
    int w = d1.getIntrinsicWidth();
    int h = d1.getIntrinsicHeight();
    int paddingPx = convertDpToPx(context, paddingDp);
    Bitmap result = Bitmap.createBitmap(w + (d2 != null ? w + paddingPx : 0), h, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(result);
    canvas.setDensity(Bitmap.DENSITY_NONE);
    d1.setBounds(0, 0, w - 1, h - 1);/* w  ww .  j a  v a2 s .  com*/
    d1.draw(canvas);
    if (d2 != null) {
        canvas.translate(w + paddingPx, 0);
        d2.setBounds(0, 0, w - 1, h - 1);
        d2.draw(canvas);
    }

    return new BitmapDrawable(context.getResources(), result);
}

From source file:com.nf2m.util.ImageWorker.java

ImageWorker(@NonNull Context context) {
    mResources = context.getResources();
    mContext = context;/* w w w.jav  a  2  s .  c  o m*/
    Bitmap defaultBitmap = BitmapFactory.decodeResource(mResources, R.drawable.ic_default_albumart);
    defaultDrawable = new BitmapDrawable(mResources, defaultBitmap);
}

From source file:com.kth.baasio.baassample.BaseActivity.java

/**
 * Sets the icon color using some fancy blending mode trickery.
 *//*ww w  .ja  va  2 s.  c  o  m*/
protected void setActionBarColor(int color) {
    if (color == 0) {
        color = 0xffffffff;
    }

    final Resources res = getResources();
    Drawable maskDrawable = res.getDrawable(R.drawable.actionbar_icon_mask);
    if (!(maskDrawable instanceof BitmapDrawable)) {
        return;
    }

    Bitmap maskBitmap = ((BitmapDrawable) maskDrawable).getBitmap();
    final int width = maskBitmap.getWidth();
    final int height = maskBitmap.getHeight();

    Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(maskBitmap, 0, 0, null);

    Paint maskedPaint = new Paint();
    maskedPaint.setColor(color);
    maskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    canvas.drawRect(0, 0, width, height, maskedPaint);

    BitmapDrawable outDrawable = new BitmapDrawable(res, outBitmap);
    getSupportActionBar().setIcon(outDrawable);
}

From source file:com.kogitune.activitytransition.core.TransitionAnimation.java

private static void setImageToView(View toView, Bitmap bitmap) {
    if (toView instanceof ImageView) {
        final ImageView toImageView = (ImageView) toView;
        toImageView.setImageBitmap(bitmap);
    } else {/*from   w w w  .  ja  v  a 2 s.com*/
        ViewCompat.setBackground(toView, new BitmapDrawable(toView.getResources(), bitmap));
    }
}

From source file:com.nadmm.airports.utils.UiUtils.java

public static Drawable getRotatedDrawable(Context context, int resid, float rotation) {
    String key = String.format(Locale.US, "%d:%d", resid, (int) rotation);
    Drawable d = getDrawableFromCache(key);
    if (d == null) {
        Resources res = context.getResources();
        Bitmap bmp = BitmapFactory.decodeResource(res, resid);
        Bitmap rotated = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(rotated);
        canvas.setDensity(Bitmap.DENSITY_NONE);
        canvas.rotate(rotation, bmp.getWidth() / 2, bmp.getHeight() / 2);
        canvas.drawBitmap(bmp, 0, 0, sPaint);
        d = new BitmapDrawable(res, rotated);
        putDrawableIntoCache(key, d);//from   ww w  .  j  a v  a2s  .  c o m
    }
    return d;
}