Search in sources :

Example 31 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method prepareHaloNotification.

public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
    Notification notif = notification.getNotification();
    // Get the remote view
    try {
        if (!update) {
            ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
            if (mainView instanceof FrameLayout) {
                entry.haloContent = mainView.getChildAt(1);
                mainView.removeViewAt(1);
            } else {
                entry.haloContent = mainView;
            }
        } else {
            notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
        }
    } catch (Exception e) {
        // Non uniform content?
        android.util.Log.d("PARANOID", "   Non uniform content?");
    }
    // Construct the round icon
    final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
    int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
    int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
    int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
    int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
    Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(roundIcon);
    canvas.drawARGB(0, 0, 0, 0);
    // halo-bubble, we'll use that one and cut it round
    if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
        Paint smoothingPaint = new Paint();
        smoothingPaint.setAntiAlias(true);
        smoothingPaint.setFilterBitmap(true);
        smoothingPaint.setDither(true);
        canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
        smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        final int newWidth = iconSize;
        final int newHeight = iconSize * largeIconWidth / largeIconHeight;
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
        canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
    } else {
        try {
            Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
            if (icon == null)
                icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
            int margin = (iconSize - smallIconSize) / 2;
            icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
            icon.draw(canvas);
        } catch (Exception e) {
        // NameNotFoundException
        }
    }
    entry.roundIcon = roundIcon;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Paint(android.graphics.Paint) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) FrameLayout(android.widget.FrameLayout) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Example 32 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project MaterialDesignLibrary by navasmdc.

the class ProgressBarCircularIndeterminate method drawFirstAnimation.

/**
	 * Draw first animation of view
	 * @param canvas
	 */
private void drawFirstAnimation(Canvas canvas) {
    if (radius1 < getWidth() / 2) {
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(makePressColor());
        radius1 = (radius1 >= getWidth() / 2) ? (float) getWidth() / 2 : radius1 + 1;
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius1, paint);
    } else {
        Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas temp = new Canvas(bitmap);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(makePressColor());
        temp.drawCircle(getWidth() / 2, getHeight() / 2, getHeight() / 2, paint);
        Paint transparentPaint = new Paint();
        transparentPaint.setAntiAlias(true);
        transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
        transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        if (cont >= 50) {
            radius2 = (radius2 >= getWidth() / 2) ? (float) getWidth() / 2 : radius2 + 1;
        } else {
            radius2 = (radius2 >= getWidth() / 2 - Utils.dpToPx(4, getResources())) ? (float) getWidth() / 2 - Utils.dpToPx(4, getResources()) : radius2 + 1;
        }
        temp.drawCircle(getWidth() / 2, getHeight() / 2, radius2, transparentPaint);
        canvas.drawBitmap(bitmap, 0, 0, new Paint());
        if (radius2 >= getWidth() / 2 - Utils.dpToPx(4, getResources()))
            cont++;
        if (radius2 >= getWidth() / 2)
            firstAnimationOver = true;
    }
}
Also used : Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 33 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project MaterialShowcaseView by deano2390.

the class MaterialShowcaseView method onDraw.

/**
     * Interesting drawing stuff.
     * We draw a block of semi transparent colour to fill the whole screen then we draw of transparency
     * to create a circular "viewport" through to the underlying content
     *
     * @param canvas
     */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // don't bother drawing if we're not ready
    if (!mShouldRender)
        return;
    // get current dimensions
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    // don't bother drawing if there is nothing to draw on
    if (width <= 0 || height <= 0)
        return;
    // build a new canvas if needed i.e first pass or new dimensions
    if (mBitmap == null || mCanvas == null || mOldHeight != height || mOldWidth != width) {
        if (mBitmap != null)
            mBitmap.recycle();
        mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }
    // save our 'old' dimensions
    mOldWidth = width;
    mOldHeight = height;
    // clear canvas
    mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    // draw solid background
    mCanvas.drawColor(mMaskColour);
    // Prepare eraser Paint if needed
    if (mEraser == null) {
        mEraser = new Paint();
        mEraser.setColor(0xFFFFFFFF);
        mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mEraser.setFlags(Paint.ANTI_ALIAS_FLAG);
    }
    // draw (erase) shape
    mShape.draw(mCanvas, mEraser, mXPosition, mYPosition, mShapePadding);
    // Draw the bitmap on our views  canvas.
    canvas.drawBitmap(mBitmap, 0, 0, null);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 34 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project UltimateAndroid by cymcsg.

the class RippleDrawable method draw.

@Override
public void draw(Canvas canvas) {
    final boolean hasMask = mMask != null;
    //TODO if contentDrawable is not null
    final boolean drawNonMaskContent = mContent != null;
    final boolean drawMask = hasMask && mMask.getOpacity() != PixelFormat.OPAQUE;
    final Rect bounds = getDirtyBounds();
    final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(bounds);
    // If we have content, draw it into a layer first.
    if (drawNonMaskContent) {
        drawContentLayer(canvas, bounds, SRC_OVER);
    }
    // Next, try to draw the ripples (into a layer if necessary). If we need
    // to mask against the underlying content, set the xfermode to SRC_ATOP.
    final PorterDuffXfermode xfermode = (hasMask || !drawNonMaskContent) ? SRC_OVER : SRC_ATOP;
    // If we have a background and a non-opaque mask, draw the masking layer.
    final int backgroundLayer = drawBackgroundLayer(canvas, bounds, xfermode, drawMask);
    if (backgroundLayer >= 0) {
        if (drawMask) {
            drawMaskingLayer(canvas, bounds, DST_IN);
        }
        canvas.restoreToCount(backgroundLayer);
    }
    // If we have ripples and a non-opaque mask, draw the masking layer.
    final int rippleLayer = drawRippleLayer(canvas, bounds, xfermode);
    if (rippleLayer >= 0) {
        if (drawMask) {
            drawMaskingLayer(canvas, bounds, DST_IN);
        }
        canvas.restoreToCount(rippleLayer);
    }
    // least draw a color so that hardware invalidation works correctly.
    if (mNeedsDraw) {
        canvas.drawColor(Color.TRANSPARENT);
        // Request another draw so we can avoid adding a transparent layer
        // during the next display list refresh.
        invalidateSelf();
    }
    mNeedsDraw = false;
    canvas.restoreToCount(saveCount);
}
Also used : Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint)

Example 35 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project phonegap-plugin-push by phonegap.

the class GCMIntentService method getCircleBitmap.

private Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    float cx = bitmap.getWidth() / 2;
    float cy = bitmap.getHeight() / 2;
    float radius = cx < cy ? cx : cy;
    canvas.drawCircle(cx, cy, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

PorterDuffXfermode (android.graphics.PorterDuffXfermode)152 Paint (android.graphics.Paint)127 Canvas (android.graphics.Canvas)103 Bitmap (android.graphics.Bitmap)92 Rect (android.graphics.Rect)65 RectF (android.graphics.RectF)51 Matrix (android.graphics.Matrix)11 LinearGradient (android.graphics.LinearGradient)10 SuppressLint (android.annotation.SuppressLint)9 TypedArray (android.content.res.TypedArray)8 Point (android.graphics.Point)6 IOException (java.io.IOException)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 ColorMatrix (android.graphics.ColorMatrix)4 Path (android.graphics.Path)4 Resources (android.content.res.Resources)3 Drawable (android.graphics.drawable.Drawable)3 ResourceHelper (com.klinker.android.launcher.api.ResourceHelper)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 RadialGradient (android.graphics.RadialGradient)2