Search in sources :

Example 71 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class CheckableDrawable method drawChecked.

private void drawChecked(@NonNull Canvas canvas, float radius) {
    Rect bounds = getBounds();
    paint.setShader(null);
    paint.setColorFilter(uncheckedFilter);
    canvas.drawBitmap(uncheckedBitmap, bounds.left, bounds.top, paint);
    maskCanvas.drawColor(0xffffffff);
    maskPaint.setXfermode(porterDuffClear);
    maskCanvas.drawCircle(maskBitmap.getWidth() / 2 + bounds.width() * offset.x, maskBitmap.getHeight() / 2 + bounds.height() * offset.y, radius, maskPaint);
    maskPaint.setXfermode(porterDuffSrcIn);
    maskCanvas.drawBitmap(filledBitmap, 0, 0, maskPaint);
    canvas.drawBitmap(maskBitmap, bounds.left, bounds.top, paint);
    paint.setShader(checkedShader);
    paint.setColorFilter(checkedFilter);
    canvas.drawCircle(bounds.centerX() + bounds.width() * offset.x, bounds.centerY() + bounds.height() * offset.y, radius, paint);
}
Also used : Rect(android.graphics.Rect)

Example 72 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class CheckableDrawable method draw.

@Override
public void draw(@NonNull Canvas canvas) {
    if (checkedBitmap == null)
        renderSVGs();
    Rect bounds = getBounds();
    if (animator != null && animator.isRunning()) {
        if (currAnim == ANIMATION_FILL) {
            drawUnchecked(canvas, currRadius);
        } else {
            drawChecked(canvas, currRadius);
        }
    } else {
        if (checkedState == CheckedState.CHECKED) {
            paint.setColorFilter(checkedFilter);
            canvas.drawBitmap(checkedBitmap, bounds.left, bounds.top, paint);
        } else if (checkedState == CheckedState.UNCHECKED) {
            paint.setColorFilter(uncheckedFilter);
            canvas.drawBitmap(uncheckedBitmap, bounds.left, bounds.top, paint);
        } else {
            paint.setColorFilter(uncheckedFilter);
            canvas.drawBitmap(filledBitmap, bounds.left, bounds.top, paint);
        }
    }
}
Also used : Rect(android.graphics.Rect)

Example 73 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class CoordinatorLayout method isTransformedTouchPointInView.

protected boolean isTransformedTouchPointInView(float x, float y, View child, PointF outLocalPoint) {
    final Rect frame = new Rect();
    child.getHitRect(frame);
    return frame.contains((int) x, (int) y);
}
Also used : Rect(android.graphics.Rect)

Example 74 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class RippleDrawableFroyo method drawBackgroundAndRipples.

private void drawBackgroundAndRipples(Canvas canvas) {
    final RippleForeground active = mRipple;
    final RippleBackground background = mBackground;
    final int count = mExitingRipplesCount;
    if (active == null && count <= 0 && (background == null || !background.isVisible())) {
        // Move along, nothing to draw here.
        return;
    }
    final float x = mHotspotBounds.exactCenterX();
    final float y = mHotspotBounds.exactCenterY();
    canvas.translate(x, y);
    updateMaskShaderIfNeeded();
    // Position the shader to account for canvas translation.
    if (mMaskShader != null) {
        final Rect bounds = getBounds();
        mMaskMatrix.setTranslate(bounds.left - x, bounds.top - y);
        mMaskShader.setLocalMatrix(mMaskMatrix);
    }
    // Grab the color for the current state and cut the alpha channel in
    // half so that the ripple and background together yield full alpha.
    final int color = mState.mColor.getColorForState(getState(), Color.BLACK);
    final int halfAlpha = (Color.alpha(color) / 2) << 24;
    final Paint p = getRipplePaint();
    if (mMaskColorFilter != null) {
        // The ripple timing depends on the paint's alpha value, so we need
        // to push just the alpha channel into the paint and let the filter
        // handle the full-alpha color.
        final int fullAlphaColor = color | (0xFF << 24);
        DrawableReflectiveUtils.setColor(mMaskColorFilter, fullAlphaColor, PorterDuff.Mode.SRC_IN);
        //mMaskColorFilter.setColor(fullAlphaColor);
        p.setColor(halfAlpha);
        p.setColorFilter(mMaskColorFilter);
        p.setShader(mMaskShader);
    } else {
        final int halfAlphaColor = (color & 0xFFFFFF) | halfAlpha;
        p.setColor(halfAlphaColor);
        p.setColorFilter(null);
        p.setShader(null);
    }
    if (background != null && background.isVisible()) {
        background.draw(canvas, p);
    }
    if (count > 0) {
        final RippleForeground[] ripples = mExitingRipples;
        for (int i = 0; i < count; i++) {
            ripples[i].draw(canvas, p);
        }
    }
    if (active != null) {
        active.draw(canvas, p);
    }
    canvas.translate(-x, -y);
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 75 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class RippleDrawableFroyo method draw.

/**
     * Optimized for drawing ripples with a mask layer and optional content.
     */
@Override
public void draw(@NonNull Canvas canvas) {
    pruneRipples();
    // Clip to the dirty bounds, which will be the drawable bounds if we
    // have a mask or content and the ripple bounds if we're projecting.
    final Rect bounds = getDirtyBounds();
    final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(bounds);
    drawContent(canvas);
    drawBackgroundAndRipples(canvas);
    canvas.restoreToCount(saveCount);
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint)

Aggregations

Rect (android.graphics.Rect)4805 Paint (android.graphics.Paint)1052 View (android.view.View)687 Point (android.graphics.Point)563 Bitmap (android.graphics.Bitmap)467 Canvas (android.graphics.Canvas)372 RectF (android.graphics.RectF)266 Drawable (android.graphics.drawable.Drawable)241 Matrix (android.graphics.Matrix)125 ViewGroup (android.view.ViewGroup)121 ArrayList (java.util.ArrayList)121 TextView (android.widget.TextView)119 SuppressLint (android.annotation.SuppressLint)116 Resources (android.content.res.Resources)112 TextPaint (android.text.TextPaint)110 PorterDuffXfermode (android.graphics.PorterDuffXfermode)105 ImageView (android.widget.ImageView)97 BitmapDrawable (android.graphics.drawable.BitmapDrawable)95 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 RemoteException (android.os.RemoteException)93