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

The following examples show how to use android.support.v4.graphics.drawable.RoundedBitmapDrawable#setAntiAlias() . 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: NoInternetDialog.java    From NoInternetDialog with Apache License 2.0 6 votes vote down vote up
private void initHalloweenTheme() {
    if (!isHalloween) {
        return;
    }

    Bitmap bmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ground);
    RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getContext().getResources(), bmp);
    dr.setCornerRadius(dialogRadius);
    dr.setAntiAlias(true);

    ground.setBackgroundDrawable(dr);

    plane.setImageResource(R.drawable.witch);
    tomb.setImageResource(R.drawable.tomb_hw);
    moon.setVisibility(View.VISIBLE);
    ground.setVisibility(View.VISIBLE);
    pumpkin.setVisibility(View.VISIBLE);
    wifiOn.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
    mobileOn.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
    airplaneOff.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
}
 
Example 2
Source File: TextCardView.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: NewTabPageView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onLargeIconAvailable(
        Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mItem.getUrl());
        mItemView.setIcon(new BitmapDrawable(getResources(), icon));
        mItem.setTileType(isFallbackColorDefault ? MostVisitedTileType.ICON_DEFAULT
                                                 : MostVisitedTileType.ICON_COLOR);
    } else {
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
                getResources(), icon);
        int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
                * getResources().getDisplayMetrics().density * icon.getWidth()
                / mDesiredIconSize);
        roundedIcon.setCornerRadius(cornerRadius);
        roundedIcon.setAntiAlias(true);
        roundedIcon.setFilterBitmap(true);
        mItemView.setIcon(roundedIcon);
        mItem.setTileType(MostVisitedTileType.ICON_REAL);
    }
    mSnapshotMostVisitedChanged = true;
    if (mIsInitialLoad) loadTaskCompleted();
}
 
Example 4
Source File: NewTabPageView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor) {
    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mItem.getUrl());
        mItemView.setIcon(new BitmapDrawable(getResources(), icon));
        mItem.setTileType(fallbackColor == ICON_BACKGROUND_COLOR
                ? MostVisitedTileType.ICON_DEFAULT : MostVisitedTileType.ICON_COLOR);
    } else {
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
                getResources(), icon);
        int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
                * getResources().getDisplayMetrics().density * icon.getWidth()
                / mDesiredIconSize);
        roundedIcon.setCornerRadius(cornerRadius);
        roundedIcon.setAntiAlias(true);
        roundedIcon.setFilterBitmap(true);
        mItemView.setIcon(roundedIcon);
        mItem.setTileType(MostVisitedTileType.ICON_REAL);
    }
    mSnapshotMostVisitedChanged = true;
    if (mIsInitialLoad) loadTaskCompleted();
}
 
Example 5
Source File: CircleImageView.java    From MediaNotification with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    if (bitmap != null) {
        int size = Math.min(canvas.getWidth(), canvas.getHeight());
        if (size != this.size) {
            this.size = size;
            bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);

            RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);

            roundedBitmapDrawable.setCornerRadius(size / 2);
            roundedBitmapDrawable.setAntiAlias(true);

            bitmap = ImageUtils.drawableToBitmap(roundedBitmapDrawable);
        }

        canvas.drawBitmap(bitmap, 0, 0, paint);
    }
}
 
Example 6
Source File: AppIconView.java    From MediaNotification with Apache License 2.0 5 votes vote down vote up
private Bitmap getRoundBitmap(@DrawableRes int drawable, int size) {
    Bitmap bitmap = ImageUtils.drawableToBitmap(ContextCompat.getDrawable(getContext(), drawable));
    bitmap = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 6, bitmap.getHeight() / 6, (int) (0.666 * bitmap.getWidth()), (int) (0.666 * bitmap.getHeight()));
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);

    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);

    roundedBitmapDrawable.setCornerRadius(size / 2);
    roundedBitmapDrawable.setAntiAlias(true);

    return ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
 
Example 7
Source File: AppIconView.java    From Cleaner with Apache License 2.0 5 votes vote down vote up
private Bitmap getRoundBitmap(@DrawableRes int drawable, int size) {
    Bitmap bitmap = ImageUtils.drawableToBitmap(ContextCompat.getDrawable(getContext(), drawable));
    bitmap = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 6, bitmap.getHeight() / 6, (int) (0.666 * bitmap.getWidth()), (int) (0.666 * bitmap.getHeight()));
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);

    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);

    roundedBitmapDrawable.setCornerRadius(size / 2);
    roundedBitmapDrawable.setAntiAlias(true);

    return ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
 
Example 8
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 9
Source File: MainActivity.java    From Password-Storage with MIT License 5 votes vote down vote up
private RoundedBitmapDrawable createRoundedBitmapImageDrawableWithBorder(Bitmap bitmap){
    int bitmapWidthImage = bitmap.getWidth();
    int bitmapHeightImage = bitmap.getHeight();
    int borderWidthHalfImage = 4;

    int bitmapRadiusImage = Math.min(bitmapWidthImage,bitmapHeightImage)/2;
    int bitmapSquareWidthImage = Math.min(bitmapWidthImage,bitmapHeightImage);
    int newBitmapSquareWidthImage = bitmapSquareWidthImage+borderWidthHalfImage;

    Bitmap roundedImageBitmap = Bitmap.createBitmap(newBitmapSquareWidthImage,newBitmapSquareWidthImage,Bitmap.Config.ARGB_8888);
    Canvas mcanvas = new Canvas(roundedImageBitmap);
    mcanvas.drawColor(Color.RED);
    int i = borderWidthHalfImage + bitmapSquareWidthImage - bitmapWidthImage;
    int j = borderWidthHalfImage + bitmapSquareWidthImage - bitmapHeightImage;

    mcanvas.drawBitmap(bitmap, i, j, null);

    Paint borderImagePaint = new Paint();
    borderImagePaint.setStyle(Paint.Style.STROKE);
    borderImagePaint.setStrokeWidth(borderWidthHalfImage*2);
    borderImagePaint.setColor(Color.GRAY);
    mcanvas.drawCircle(mcanvas.getWidth()/2, mcanvas.getWidth()/2, newBitmapSquareWidthImage/2, borderImagePaint);

    RoundedBitmapDrawable roundedImageBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(),roundedImageBitmap);
    roundedImageBitmapDrawable.setCornerRadius(bitmapRadiusImage);
    roundedImageBitmapDrawable.setAntiAlias(true);
    return roundedImageBitmapDrawable;
}
 
Example 10
Source File: CircleImageView.java    From Pasta-Music with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    Bitmap image = ImageUtils.drawableToBitmap(getDrawable());
    if (image != null) {
        int size = Math.min(getWidth(), getHeight());
        image = ThumbnailUtils.extractThumbnail(image, size, size);

        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), image);

        roundedBitmapDrawable.setCornerRadius(size / 2);
        roundedBitmapDrawable.setAntiAlias(true);

        canvas.drawBitmap(ImageUtils.drawableToBitmap(roundedBitmapDrawable), 0, 0, paint);
    }
}
 
Example 11
Source File: RoundedNetworkImageView.java    From RestVolley with Apache License 2.0 5 votes vote down vote up
/**
 * get circle drawable.
 * @param context Context
 * @param bitmap Bitmap
 * @return {@link RoundedBitmapDrawable}
 */
public static RoundedBitmapDrawable getCircleDrawable(Context context, Bitmap bitmap) {
    RoundedBitmapDrawable circleDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    circleDrawable.setAntiAlias(true);
    circleDrawable.setCornerRadius(Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
    return circleDrawable;
}
 
Example 12
Source File: CharacterCardView.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
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);
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
        imageView.setImageDrawable(drawable);
    }
}
 
Example 13
Source File: DiscView.java    From Yuan-SxMusic with Apache License 2.0 5 votes vote down vote up
/**
 * 得到唱盘图片
 * 唱盘图片由空心圆盘及音乐专辑图片“合成”得到
 */
public Drawable getDiscDrawable(Bitmap bitmap) {
    int discSize = (int) (mScreenWidth * DisplayUtil.SCALE_DISC_SIZE);
    int musicPicSize = (int) (mScreenWidth * DisplayUtil.SCALE_MUSIC_PIC_SIZE);

    Bitmap bitmapDisc = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R
            .drawable.ic_disc), discSize, discSize, false);
    Bitmap bitmapMusicPic = Bitmap.createScaledBitmap(bitmap, musicPicSize, musicPicSize, true);
    BitmapDrawable discDrawable = new BitmapDrawable(bitmapDisc);
    RoundedBitmapDrawable roundMusicDrawable = RoundedBitmapDrawableFactory.create
            (getResources(), bitmapMusicPic);

    //抗锯齿
    discDrawable.setAntiAlias(true);
    roundMusicDrawable.setAntiAlias(true);

    Drawable[] drawables = new Drawable[2];
    drawables[0] = roundMusicDrawable;
    drawables[1] = discDrawable;

    LayerDrawable layerDrawable = new LayerDrawable(drawables);
    int musicPicMargin = (int) ((DisplayUtil.SCALE_DISC_SIZE - DisplayUtil
            .SCALE_MUSIC_PIC_SIZE) * mScreenWidth / 2);
    //调整专辑图片的四周边距,让其显示在正中
    layerDrawable.setLayerInset(0, musicPicMargin, musicPicMargin, musicPicMargin,
            musicPicMargin);

    return layerDrawable;
}
 
Example 14
Source File: TileGroup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onLargeIconAvailable(
        @Nullable Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    if (mTrackLoadTask) mObserver.onLoadTaskCompleted();

    Tile tile = getTile(mUrl);
    if (tile == null) return; // The tile might have been removed.

    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mUrl);
        tile.setIcon(new BitmapDrawable(mContext.getResources(), icon));
        tile.setType(isFallbackColorDefault ? TileVisualType.ICON_DEFAULT
                                            : TileVisualType.ICON_COLOR);
    } else {
        RoundedBitmapDrawable roundedIcon =
                RoundedBitmapDrawableFactory.create(mContext.getResources(), icon);
        int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
                * mContext.getResources().getDisplayMetrics().density * icon.getWidth()
                / mDesiredIconSize);
        roundedIcon.setCornerRadius(cornerRadius);
        roundedIcon.setAntiAlias(true);
        roundedIcon.setFilterBitmap(true);

        tile.setIcon(roundedIcon);
        tile.setType(TileVisualType.ICON_REAL);
    }

    mObserver.onTileIconChanged(tile);
}
 
Example 15
Source File: CircleImageView.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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;
}
 
Example 16
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 17
Source File: ContactHolder.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
private RoundedBitmapDrawable getRoundedBitmapDrawable(Context context, Bitmap b) {
    RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(context.getResources(), Bitmap.createScaledBitmap(b, Screen.dp(48), Screen.dp(48), false));
    d.setCornerRadius(d.getIntrinsicHeight() / 2);
    d.setAntiAlias(true);
    return d;
}
 
Example 18
Source File: RoundedNetworkImageView.java    From RestVolley with Apache License 2.0 3 votes vote down vote up
/**
 * get rounded drawable.
 * @param context Context
 * @param bitmap Bitmap
 * @param cornerRadius corner radius
 * @return {@link RoundedBitmapDrawable}
 */
public static RoundedBitmapDrawable getRoundedDrawable(Context context, Bitmap bitmap, float cornerRadius) {
    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    roundedBitmapDrawable.setAntiAlias(true);
    roundedBitmapDrawable.setCornerRadius(cornerRadius);
    return roundedBitmapDrawable;
}
 
Example 19
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 20
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;
    }