Java Code Examples for android.support.v4.graphics.drawable.RoundedBitmapDrawable#setCircular()

The following examples show how to use android.support.v4.graphics.drawable.RoundedBitmapDrawable#setCircular() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterestsItemView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected Drawable doInBackground(Void... voids) {
    // This is run on a background thread.
    try {
        // TODO(peconn): Replace this with something from the C++ Chrome stack.
        URL imageUrl = new URL(mUrl);
        InputStream in = imageUrl.openStream();

        Bitmap raw = BitmapFactory.decodeStream(in);
        int dimension = Math.min(raw.getHeight(), raw.getWidth());
        RoundedBitmapDrawable img = RoundedBitmapDrawableFactory.create(mResources,
                ThumbnailUtils.extractThumbnail(raw, dimension, dimension));
        img.setCircular(true);

        return img;
    } catch (IOException e) {
        Log.e(TAG, "Error downloading image: " + e.toString());
    }
    return null;
}
 
Example 2
Source File: RoundedContact.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
static RoundedBitmapDrawable get(Activity activity, Uri thumbnail) {

        RoundedBitmapDrawable dr = null;

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), thumbnail);
            dr = RoundedBitmapDrawableFactory.create(activity.getResources(), bitmap);
            dr.setCircular(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dr;
    }
 
Example 3
Source File: AvatarView.java    From android-topeka with Apache License 2.0 5 votes vote down vote up
private void setAvatarPreLollipop(@DrawableRes int resId) {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId,
            getContext().getTheme());
    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    @SuppressWarnings("ConstantConditions")
    RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
            bitmapDrawable.getBitmap());
    roundedDrawable.setCircular(true);
    setImageDrawable(roundedDrawable);
}
 
Example 4
Source File: LoadCircularImageTask.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Drawable getDrawable(Bitmap bitmap) {
    if (cropCircle) {
        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(imageView.getResources(), bitmap);
        roundedBitmapDrawable.setCircular(true);
        roundedBitmapDrawable.setAntiAlias(true);
        return roundedBitmapDrawable;
    } else {
        return super.getDrawable(bitmap);
    }
}
 
Example 5
Source File: ContactAdapter.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Crop ImageView in parameter for create a circle
 */
private void cropRoundedImageView(ImageView imageView) {
    Bitmap imageBitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    RoundedBitmapDrawable imageDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), imageBitmap);
    imageDrawable.setCircular(true);
    imageDrawable.setCornerRadius(Math.max(imageBitmap.getWidth(), imageBitmap.getHeight()) / 2.0f);
    imageView.setImageDrawable(imageDrawable);
}
 
Example 6
Source File: DrawableUtils.java    From meiShi with Apache License 2.0 5 votes vote down vote up
public static Drawable roundedBitmap(Bitmap bitmap) {
    RoundedBitmapDrawable circleDrawable = RoundedBitmapDrawableFactory.create(App.getInstance().getResources(), bitmap);
    circleDrawable.getPaint().setAntiAlias(true);
    circleDrawable.setCircular(true);
    circleDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
    return circleDrawable;
}
 
Example 7
Source File: AvatarView.java    From CoolSignIn with Apache License 2.0 5 votes vote down vote up
private void setAvatarPreLollipop(@DrawableRes int resId) {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId,
            getContext().getTheme());
    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    @SuppressWarnings("ConstantConditions")
    RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
            bitmapDrawable.getBitmap());
    roundedDrawable.setCircular(true);
    setImageDrawable(roundedDrawable);
}
 
Example 8
Source File: Utils.java    From ColorBox-library with GNU General Public License v3.0 4 votes vote down vote up
static RoundedBitmapDrawable round(Resources resources, boolean isLand, int dim, int color) {

        Bitmap.Config conf = Bitmap.Config.ARGB_8888;

        int dimen = isLand ? Math.round((int) resources.getDimension(dim) * 0.85f) : (int) resources.getDimension(dim);

        Bitmap bitmap = Bitmap.createBitmap(dimen, dimen, conf);

        bitmap.eraseColor(color);

        // Create a new RoundedBitmapDrawable
        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, bitmap);

        roundedBitmapDrawable.setCircular(true);

        roundedBitmapDrawable.setAntiAlias(true);

        // Return the RoundedBitmapDrawable
        return roundedBitmapDrawable;
    }
 
Example 9
Source File: ThemePreference.java    From LaunchEnr with GNU General Public License v3.0 3 votes vote down vote up
private static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap bitmap, int color, Resources mResources) {

        bitmap.eraseColor(color);

        // Create a new RoundedBitmapDrawable
        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(mResources, bitmap);

        roundedBitmapDrawable.setCircular(true);

        roundedBitmapDrawable.setAntiAlias(true);

        // Return the RoundedBitmapDrawable
        return roundedBitmapDrawable;
    }
 
Example 10
Source File: paletteUtils.java    From Color-picker-library with GNU General Public License v3.0 2 votes vote down vote up
private static RoundedBitmapDrawable createRoundedBitmapDrawableWithBorder(Activity activity, Bitmap bitmap, int tagColor, int viewColor, Resources mResources) {

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();
        int borderWidthHalf = 10; // In pixels

        // Calculate the bitmap radius
        int bitmapRadius = Math.min(bitmapWidth, bitmapHeight) / 2;

        int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight);

        int bitmapDim = bitmapSquareWidth + borderWidthHalf;

        // Initializing a new empty bitmap.
        Bitmap roundedBitmap = Bitmap.createBitmap(bitmapDim, bitmapDim, Bitmap.Config.ARGB_8888);

        // Initialize a new Canvas to draw empty bitmap
        Canvas canvas = new Canvas(roundedBitmap);

        // Draw a solid color to canvas
        canvas.drawColor(tagColor);

        // Calculation to draw bitmap at the circular bitmap center position
        int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth;
        int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight;

        // Draw the bitmap to canvas
        // Bitmap will draw its center to circular bitmap center by keeping border spaces
        canvas.drawBitmap(bitmap, x, y, null);

        // Initializing a new Paint instance to draw circular border
        final Paint borderPaint = new Paint();
        borderPaint.setStyle(Paint.Style.STROKE);
        borderPaint.setAntiAlias(true);
        borderPaint.setStrokeWidth(borderWidthHalf);

        // Set paint color according to view color to make it always visible
        double darkness = 1 - (0.299 * Color.red(viewColor) + 0.587 * Color.green(viewColor) + 0.114 * Color.blue(viewColor)) / 255;

        if (darkness < 0.5) {

            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {

                    borderPaint.setColor(colorUtils.opaqueColor(Color.DKGRAY));

                }
            });

        } else {

            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    borderPaint.setColor(colorUtils.opaqueColor(Color.LTGRAY));


                }
            });
        }

        // drawCircle(float cx, float cy, float radius, Paint paint)
        // Draw the specified circle using the specified paint.
        canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, bitmapDim / 2, borderPaint);

        // Create a new RoundedBitmapDrawable
        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(mResources, roundedBitmap);

        // Set the corner radius of the bitmap drawable
        roundedBitmapDrawable.setCornerRadius(bitmapRadius);

        roundedBitmapDrawable.setCircular(true);

        roundedBitmapDrawable.setAntiAlias(true);

        // Return the RoundedBitmapDrawable
        return roundedBitmapDrawable;
    }