Example usage for android.support.v4.graphics.drawable RoundedBitmapDrawable setAntiAlias

List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawable setAntiAlias

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable RoundedBitmapDrawable setAntiAlias.

Prototype

public void setAntiAlias(boolean z) 

Source Link

Usage

From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java

/**
 * Create a circular drawable from a resource drawable id.
 *
 * @param context   Need to get the resources
 * @param resId     Drawable's id./*from w  w w.j a v a 2  s.c o  m*/
 *
 * @return RoundedBitmapDrawable
 */
public static RoundedBitmapDrawable getCircleBitmapDrawable(Context context, int resId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId);
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    drawable.setCornerRadius(Math.max(bitmap.getWidth() / 2, bitmap.getHeight() / 2));
    drawable.setAntiAlias(true);
    return drawable;
}

From source file:com.tr4android.support.extension.widget.CircleImageView.java

/**
 * Helper for creating a circle bitmap drawable using the {@link android.support.v4.graphics.drawable.RoundedBitmapDrawable}
 *
 * @param bitmap The bitmap which should be converted to a circle bitmap drawable
 * @return the {@link android.support.v4.graphics.drawable.RoundedBitmapDrawable} containing the bitmap
 *//* w  w w  .j  av a  2 s.c  o  m*/
public static RoundedBitmapDrawable getCircleBitmapDrawable(Context context, Bitmap bitmap) {
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    drawable.setCornerRadius(Math.max(bitmap.getWidth() / 2, bitmap.getHeight() / 2));
    drawable.setAntiAlias(true);
    return drawable;
}

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.TextCardView.java

public void updateUi(Card card) {
    TextView extraText = (TextView) findViewById(R.id.extra_text);
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    extraText.setText(card.getExtraText());
    primaryText.setText(card.getTitle());

    // Create a rounded drawable.
    int resourceId = card.getLocalImageResourceId(getContext());
    Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resourceId);
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), bitmap);
    drawable.setAntiAlias(true);
    drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
    imageView.setImageDrawable(drawable);
}

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.CharacterCardView.java

public void updateUi(Card card) {
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    primaryText.setText(card.getTitle());
    if (card.getLocalImageResourceName() != null) {
        int resourceId = card.getLocalImageResourceId(getContext());
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resourceId);
        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(),
                bitmap);//  w w  w  . j ava 2s . c o  m
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
        imageView.setImageDrawable(drawable);
    }
}

From source file:im.vector.view.VectorCircularImageView.java

/**
 * Update the bitmap.//from w ww  .j a v  a  2s.  co  m
 * The bitmap is first squared before adding corners
 * @param bm the new bitmap
 */
public void setImageBitmap(Bitmap bm) {
    if (null != bm) {
        // convert the bitmap to a square bitmap
        int width = bm.getWidth();
        int height = bm.getHeight();

        if (width == height) {
            // nothing to do
        }
        // larger than high
        else if (width > height) {
            try {
                bm = Bitmap.createBitmap(bm, (width - height) / 2, 0, height, height);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }
        // higher than large
        else {
            try {
                bm = Bitmap.createBitmap(bm, 0, (height - width) / 2, width, width);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }

        try {
            // create a rounded bitmap
            RoundedBitmapDrawable img = RoundedBitmapDrawableFactory.create(getResources(), bm);
            img.setAntiAlias(true);
            img.setCornerRadius(height / 2.0f);

            // apply it to the image
            this.setImageDrawable(img);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## setImageBitmap - RoundedBitmapDrawableFactory.create " + e.getMessage());
            super.setImageBitmap(null);
        }
    } else {
        super.setImageBitmap(null);
    }
}

From source file:net.simno.klingar.ui.widget.CircleImageViewTarget.java

@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
    super.onResourceReady(bitmap, glideAnimation);

    RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(view.getResources(), bitmap);
    rounded.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()));
    rounded.setAntiAlias(true);

    view.setImageDrawable(rounded);/*  w w  w.ja v a  2 s  . c o m*/
}

From source file:im.neon.view.VectorCircularImageView.java

/**
 * Update the bitmap./*  ww w.java2s  . co m*/
 * The bitmap is first squared before adding corners
 * @param bm the new bitmap
 */
public void setImageBitmap(Bitmap bm) {
    if (null != bm) {
        // convert the bitmap to a square bitmap
        int width = bm.getWidth();
        int height = bm.getHeight();

        if (width == height) {
            // nothing to do
        }
        // larger than high
        else if (width > height) {
            try {
                bm = Bitmap.createBitmap(bm, (width - height) / 2, 0, height, height);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }
        // higher than large
        else {
            try {
                bm = Bitmap.createBitmap(bm, 0, (height - width) / 2, width, width);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }

        try {
            // create a rounded bitmap
            RoundedBitmapDrawable img = RoundedBitmapDrawableFactory.create(getResources(), bm);
            img.setAntiAlias(true);
            img.setCornerRadius(height / 2.0f);

            // apply it to the image
            super.setImageDrawable(img);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## setImageBitmap - RoundedBitmapDrawableFactory.create " + e.getMessage());
            super.setImageBitmap(null);
        }
    } else {
        super.setImageBitmap(null);
    }
}

From source file:com.android.dialer.contactinfo.ContactPhotoLoader.java

/**
 * @return a {@link Drawable} of  circular photo icon if the photo can be loaded, {@code null}
 * otherwise.//from w w  w . ja va2 s . c o m
 */
@Nullable
private Drawable createPhotoIconDrawable() {
    if (mContactInfo.photoUri == null) {
        return null;
    }
    try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), mContactInfo.photoUri);
        final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(),
                bitmap);
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(bitmap.getHeight() / 2);
        return drawable;
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        return null;
    }
}

From source file:org.mozilla.gecko.fxa.activities.PicassoPreferenceIconTarget.java

@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
    // Updating icons from Java is not supported prior to API 11.
    if (!AppConstants.Versions.feature11Plus) {
        return;//from  w  w w .ja  v a  2s.  c om
    }

    final Drawable drawable;
    if (cornerRadius > 0) {
        final RoundedBitmapDrawable roundedBitmapDrawable;
        roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, bitmap);
        roundedBitmapDrawable.setCornerRadius(cornerRadius);
        roundedBitmapDrawable.setAntiAlias(true);
        drawable = roundedBitmapDrawable;
    } else {
        drawable = new BitmapDrawable(resources, bitmap);
    }
    preference.setIcon(drawable);
}

From source file:com.ticketmaster.servos.util.picasso.RoundedBitmapTransform.java

@Override
public Bitmap transform(Bitmap source) {
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(res, source);
    drawable.setCornerRadius(getCornerRadius(source));
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
    Canvas canvas = new Canvas(output);
    drawable.setAntiAlias(true);
    drawable.setBounds(0, 0, source.getWidth(), source.getHeight());
    drawable.draw(canvas);/*  w  w  w .j a  v a2  s. co m*/
    if (source != output) {
        source.recycle();
    }
    return output;
}