Java Code Examples for android.graphics.Canvas#concat()

The following examples show how to use android.graphics.Canvas#concat() . 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: Renderer.java    From android-anuto with GNU General Public License v2.0 6 votes vote down vote up
public void draw(Canvas canvas) {
    mLock.lock();

    canvas.drawColor(Color.BLACK);
    canvas.concat(mViewport.getScreenMatrix());
    canvas.clipRect(mViewport.getScreenClipRect());
    canvas.drawColor(mBackgroundColor);

    for (Drawable obj : mDrawables) {
        obj.draw(canvas);
    }

    mLock.unlock();

    mFrameRateLogger.incrementRenderCount();
}
 
Example 2
Source File: RxPorterShapeImageView.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintMaskCanvas(Canvas maskCanvas, Paint maskPaint, int width, int height) {
    if(shape != null) {
        if (shape instanceof BitmapDrawable) {
            configureBitmapBounds(getWidth(), getHeight());
            if(drawMatrix != null) {
                int drawableSaveCount = maskCanvas.getSaveCount();
                maskCanvas.save();
                maskCanvas.concat(matrix);
                shape.draw(maskCanvas);
                maskCanvas.restoreToCount(drawableSaveCount);
                return;
            }
        }

        shape.setBounds(0, 0, getWidth(), getHeight());
        shape.draw(maskCanvas);
    }
}
 
Example 3
Source File: GridLayout.java    From Carbon with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
    if (child instanceof ShadowView && (!Carbon.IS_LOLLIPOP_OR_HIGHER || ((ShadowView) child).getElevationShadowColor() != null && !Carbon.IS_PIE_OR_HIGHER)) {
        ShadowView shadowView = (ShadowView) child;
        shadowView.drawShadow(canvas);
    }

    if (child instanceof RippleView) {
        RippleView rippleView = (RippleView) child;
        RippleDrawable rippleDrawable = rippleView.getRippleDrawable();
        if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Borderless) {
            int saveCount = canvas.save();
            canvas.translate(child.getLeft(), child.getTop());
            canvas.concat(child.getMatrix());
            rippleDrawable.draw(canvas);
            canvas.restoreToCount(saveCount);
        }
    }

    return super.drawChild(canvas, child, drawingTime);
}
 
Example 4
Source File: PorterShapeImageView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintMaskCanvas(Canvas maskCanvas, Paint maskPaint, int width, int height) {
    if(shape != null) {
        if (shape instanceof BitmapDrawable) {
            configureBitmapBounds(width, height);
            if(drawMatrix != null) {
                int drawableSaveCount = maskCanvas.getSaveCount();
                maskCanvas.save();
                maskCanvas.concat(matrix);
                shape.draw(maskCanvas);
                maskCanvas.restoreToCount(drawableSaveCount);
                return;
            }
        }

        shape.setBounds(0, 0, width, height);
        shape.draw(maskCanvas);
    }
}
 
Example 5
Source File: ImageLayer.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@Override public void drawLayer(@NonNull Canvas canvas, Matrix parentMatrix, int parentAlpha) {
  Bitmap bitmap = getBitmap();
  if (bitmap == null || bitmap.isRecycled()) {
    return;
  }
  float density = Utils.dpScale();

  paint.setAlpha(parentAlpha);
  if (colorFilterAnimation != null) {
    paint.setColorFilter(colorFilterAnimation.getValue());
  }
  canvas.save();
  canvas.concat(parentMatrix);
  src.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
  dst.set(0, 0, (int) (bitmap.getWidth() * density), (int) (bitmap.getHeight() * density));
  canvas.drawBitmap(bitmap, src, dst , paint);
  canvas.restore();
}
 
Example 6
Source File: DepthRendrer.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
private void drawLeftEdge(DepthLayout dl, Canvas canvas, float[] src) {
  float[] dst = new float[] {
      dl.getTopLeft().x, dl.getTopLeft().y, dl.getTopLeftBack().x, dl.getTopLeftBack().y,
      dl.getBottomLeftBack().x, dl.getBottomLeftBack().y, dl.getBottomLeft().x,
      dl.getBottomLeft().y
  };
  int count = canvas.save();
  matrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
  canvas.concat(matrix);
  drawRectancle(dl, canvas);
  drawShadow(dl.getTopLeft(), dl.getBottomLeft(), 0, canvas, dl);

  canvas.restoreToCount(count);
}
 
Example 7
Source File: RotationDrawStrategy.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 根据角度绘制图标的类
 * @param canvas 画布
 * @param degree 角度
 * @param icon 图标
 * @param width view宽度
 * @param height view高度
 */
private void drawIconThree(Canvas canvas, int degree, Bitmap icon, int width, int height) {
    Camera camera = new Camera();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    int centerX = width / 2;
    int centerY = height / 2 - 200;
    int x = centerX - icon.getWidth()/2;
    int y = centerY - icon.getHeight()/2;
    Matrix matrix = new Matrix();
    matrix.postScale(1.7f, 1.7f, centerX, centerY);
    //绘制上半部分
    canvas.save();
    canvas.concat(matrix);
    canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
    canvas.drawBitmap(icon, x, y, paint);
    canvas.restore();

    //绘制下半部分
    canvas.save();
    canvas.concat(matrix);
    if (degree <= 90)
        canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
    else
        canvas.clipRect(x, y + icon.getHeight() / 2, x + icon.getWidth(), y + icon.getHeight());
    canvas.translate(centerX, centerY);
    camera.save();
    camera.rotateX(180 - degree);
    camera.applyToCanvas(canvas);
    camera.restore();
    canvas.translate(-centerX, -centerY);
    canvas.drawBitmap(icon, x, y, paint);
    canvas.restore();
}
 
Example 8
Source File: ScaleTypeDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
  configureBoundsIfUnderlyingChanged();
  if (mDrawMatrix != null) {
    int saveCount = canvas.save();
    canvas.clipRect(getBounds());
    canvas.concat(mDrawMatrix);
    super.draw(canvas);
    canvas.restoreToCount(saveCount);
  } else {
    // mDrawMatrix == null means our bounds match and we can take fast path
    super.draw(canvas);
  }
}
 
Example 9
Source File: DrawView.java    From style-transfer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Matrix m = mImageView.getImageMatrix();
    Drawable d = mImageView.getDrawable();
    canvas.concat(m);

    for (Drawable elem : drawList) {
        elem.draw(canvas);
    }
    canvas.drawPath(mPoints, mPaint1);
    canvas.drawPath(mPoints, mPaint2);
}
 
Example 10
Source File: ScanView.java    From AndroidDemo with MIT License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Paint mPaint = new Paint();
    mPaint.setAntiAlias(true);
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    Rect rectd = new Rect((viewSize / 10) * 4, (viewSize / 10) * 4, viewSize - (viewSize / 10) * 4, viewSize - (viewSize / 10) * 4);
    canvas.drawBitmap(bitmap, rect, rectd, mPaint);

    circlePaint = new Paint();
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setAntiAlias(true);
    circlePaint.setStrokeWidth((viewSize / 10));

    circlePaint.setColor(Color.parseColor(circlrColor1));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 2.5f, circlePaint);

    circlePaint.setColor(Color.parseColor(circlrColor2));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 3.5f, circlePaint);

    circlePaint.setColor(Color.parseColor(circlrColor3));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 4.5f, circlePaint);

    sectorPaint = new Paint();
    sectorPaint.setAntiAlias(true);
    sectorPaint.setStyle(Paint.Style.STROKE);
    sectorPaint.setStrokeWidth((viewSize / 10) * 3);
    Shader sectorShader = new SweepGradient(viewSize / 2, viewSize / 2,
            new int[]{Color.TRANSPARENT, Color.argb(0,Color.red(accentColor),Color.green(accentColor),Color.blue(accentColor)),
                    Color.argb(255,Color.red(accentColor),Color.green(accentColor),Color.blue(accentColor))},
            new float[]{0, 0.875f, 1f});
    sectorPaint.setShader(sectorShader);

    if (threadFlag) {
        canvas.concat(matrix);
        canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 3.5f, sectorPaint);
    }
}
 
Example 11
Source File: SimplePhotoView.java    From droidddle with Apache License 2.0 5 votes vote down vote up
/**
 * Here, you have to ��http://frescolib.org/docs/writing-custom-views.html#_
 */
@Override
protected void onDraw(@NonNull Canvas canvas) {
    int saveCount = canvas.save();
    canvas.concat(mCurrentMatrix);
    super.onDraw(canvas);
    canvas.restoreToCount(saveCount);
}
 
Example 12
Source File: BubbleShader.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Paint imagePaint, Paint borderPaint) {
    canvas.save();
    canvas.concat(matrix);
    canvas.drawPath(path, imagePaint);
    canvas.restore();
}
 
Example 13
Source File: FlipView.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private void drawFlippingHalf(Canvas canvas) {
    canvas.save();
    mCamera.save();

    final float degreesFlipped = getDegreesFlipped();

    if (degreesFlipped > 90) {
        canvas.clipRect(isFlippingVertically() ? mTopRect : mLeftRect);
        if (mIsFlippingVertically) {
            mCamera.rotateX(degreesFlipped - 180);
        } else {
            mCamera.rotateY(180 - degreesFlipped);
        }
    } else {
        canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect);
        if (mIsFlippingVertically) {
            mCamera.rotateX(degreesFlipped);
        } else {
            mCamera.rotateY(-degreesFlipped);
        }
    }

    mCamera.getMatrix(mMatrix);

    positionMatrix();
    canvas.concat(mMatrix);

    setDrawWithLayer(mCurrentPage.v, true);
    drawChild(canvas, mCurrentPage.v, 0);

    drawFlippingShadeShine(canvas);

    mCamera.restore();
    canvas.restore();
}
 
Example 14
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 5 votes vote down vote up
private int saveCanvas(BaseDanmaku danmaku, Canvas canvas, float left, float top) {
    this.camera.save();
    this.camera.rotateY(-danmaku.rotationY);
    this.camera.rotateZ(-danmaku.rotationZ);
    this.camera.getMatrix(this.matrix);
    this.matrix.preTranslate(-left, -top);
    this.matrix.postTranslate(left, top);
    this.camera.restore();
    int count = canvas.save();
    canvas.concat(this.matrix);
    return count;
}
 
Example 15
Source File: RoundedShader.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Paint imagePaint, Paint borderPaint) {
    canvas.drawRoundRect(borderRect, radius, radius, borderPaint);
    canvas.save();
    canvas.concat(matrix);
    canvas.drawRoundRect(imageRect, bitmapRadius, bitmapRadius, imagePaint);
    canvas.restore();
}
 
Example 16
Source File: CreditsRollView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    mPaddingLeft = getPaddingLeft();
    mPaddingTop = getPaddingTop();
    mPaddingRight = getPaddingRight();
    mPaddingBottom = getPaddingBottom();

    final CharSequence text = getText();
    if (TextUtils.isEmpty(text)) {
        return;
    }

    int contentWidth = getWidth() - mPaddingLeft - mPaddingRight;
    int contentHeight = getHeight() - mPaddingTop - mPaddingBottom;

    final int saveCnt = canvas.save();

    // Rotate/translate the camera
    canvas.getMatrix(mMatrix);
    mCamera.save();

    int cX = contentWidth / 2 + mPaddingLeft;
    int cY = contentHeight / 2 + mPaddingTop;
    mCamera.rotateX(mAngle);
    mCamera.translate(0, 0, mDistanceFromText);
    mCamera.getMatrix(mMatrix);
    mMatrix.preTranslate(-cX, -cY);
    mMatrix.postTranslate(cX, cY);
    mCamera.restore();

    canvas.concat(mMatrix);

    // The end scroll multiplier ensures that the text scrolls completely out of view
    canvas.translate(0f, contentHeight - mScrollPosition *
                                         (mTextLayout.getHeight() + mEndScrollMult * contentHeight));

    // Draw the text
    mTextLayout.draw(canvas);

    canvas.restoreToCount(saveCnt);
}
 
Example 17
Source File: CollapsingToolbarLayout.java    From Carbon with Apache License 2.0 4 votes vote down vote up
@Override
public void drawShadow(@NotNull Canvas canvas) {
    float alpha = getAlpha() * Carbon.getBackgroundTintAlpha(this) / 255.0f;
    if (alpha == 0 || !hasShadow())
        return;

    float z = getElevation() + getTranslationZ();

    int saveCount;
    boolean maskShadow = getBackground() != null && alpha != 1;
    boolean r = revealAnimator != null && revealAnimator.isRunning();

    if (alpha != 255) {
        paint.setAlpha((int) (127 * alpha));
        saveCount = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), paint, Canvas.ALL_SAVE_FLAG);
    } else {
        saveCount = canvas.save();
    }
    Matrix matrix = getMatrix();
    canvas.setMatrix(matrix);

    if (r) {
        canvas.clipRect(
                getLeft() + revealAnimator.x - revealAnimator.radius, getTop() + revealAnimator.y - revealAnimator.radius,
                getLeft() + revealAnimator.x + revealAnimator.radius, getTop() + revealAnimator.y + revealAnimator.radius);
    }

    shadowDrawable.setFillColor(spotShadowColor);
    shadowDrawable.setShadowColor(spotShadowColor != null ? spotShadowColor.getColorForState(getDrawableState(), spotShadowColor.getDefaultColor()) : 0xff000000);
    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS);
    shadowDrawable.setAlpha(0x44);
    shadowDrawable.setElevation(z);
    shadowDrawable.setShadowVerticalOffset(0);
    shadowDrawable.setBounds(getLeft(), (int) (getTop() + z / 4), getRight(), (int) (getBottom() + z / 4));
    shadowDrawable.draw(canvas);

    canvas.translate(this.getLeft(), this.getTop());
    canvas.concat(matrix);
    paint.setXfermode(Carbon.CLEAR_MODE);
    if (maskShadow) {
        cornersMask.setFillType(Path.FillType.WINDING);
        canvas.drawPath(cornersMask, paint);
    }
    if (r)
        canvas.drawPath(revealAnimator.mask, paint);

    canvas.restoreToCount(saveCount);
    paint.setXfermode(null);
    paint.setAlpha(255);
}
 
Example 18
Source File: SmoothImageView.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (getDrawable() == null) {
        return; // couldn't resolve the URI
    }

    if (mState == STATE_TRANSFORM_IN || mState == STATE_TRANSFORM_OUT) {
        if (mTransformStart) {
            initTransform();
        }
        if (mTransfrom == null) {
            super.onDraw(canvas);
            return;
        }

        if (mTransformStart) {
            if (mState == STATE_TRANSFORM_IN) {
                mTransfrom.initStartIn();
            } else {
                mTransfrom.initStartOut();
            }
        }

        if (mTransformStart) {
            Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.startScale);
            Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.endScale);
            Log.d("Dean", "mTransfrom.scale:" + mTransfrom.scale);
            Log.d("Dean", "mTransfrom.startRect:" + mTransfrom.startRect.toString());
            Log.d("Dean", "mTransfrom.endRect:" + mTransfrom.endRect.toString());
            Log.d("Dean", "mTransfrom.rect:" + mTransfrom.rect.toString());
        }

        mPaint.setAlpha(mBgAlpha);
        canvas.drawPaint(mPaint);

        int saveCount = canvas.getSaveCount();
        canvas.save();
        // 先得到图片在此刻的图像Matrix矩阵
        getBmpMatrix();
        canvas.translate(mTransfrom.rect.left, mTransfrom.rect.top);
        canvas.clipRect(0, 0, mTransfrom.rect.width, mTransfrom.rect.height);
        canvas.concat(mSmoothMatrix);
        getDrawable().draw(canvas);
        canvas.restoreToCount(saveCount);
        if (mTransformStart) {
            mTransformStart = false;
            startTransform(mState);
        }
    } else {
        //当Transform In变化完成后,把背景改为黑色,使得Activity不透明
        mPaint.setAlpha(255);
        canvas.drawPaint(mPaint);
        super.onDraw(canvas);
    }
}
 
Example 19
Source File: DebugOverlay.java    From GestureViews with Apache License 2.0 4 votes vote down vote up
public static void drawDebug(View view, Canvas canvas) {
    final GestureController controller = ((GestureView) view).getController();
    final ViewPositionAnimator animator = ((AnimatorView) view).getPositionAnimator();
    final Settings settings = controller.getSettings();
    final Context context = view.getContext();
    final float stroke = UnitsUtils.toPixels(context, STROKE_WIDTH);
    final float textSize = UnitsUtils.toPixels(context, TEXT_SIZE);

    canvas.save();
    canvas.translate(view.getPaddingLeft(), view.getPaddingTop());

    // Viewport
    rectF.set(0f, 0f, settings.getViewportW(), settings.getViewportH());
    drawRect(canvas, rectF, Color.GRAY, stroke);

    // Movement area
    GravityUtils.getMovementAreaPosition(settings, rect);
    rectF.set(rect);
    drawRect(canvas, rectF, Color.GREEN, stroke);

    // Image bounds with rotation
    controller.getState().get(matrix);
    canvas.save();
    canvas.concat(matrix);
    rectF.set(0f, 0f, settings.getImageW(), settings.getImageH());
    drawRect(canvas, rectF, Color.YELLOW, stroke / controller.getState().getZoom());
    canvas.restore();

    // Image bounds
    rectF.set(0f, 0f, settings.getImageW(), settings.getImageH());
    controller.getState().get(matrix);
    matrix.mapRect(rectF);
    drawRect(canvas, rectF, Color.RED, stroke);

    // State source
    float pos = animator.getPosition();
    if (pos == 1f || (pos == 0f && animator.isLeaving())) {
        final StateSource source = getStateSource(controller);

        drawText(canvas, settings, source.name(), Color.CYAN, textSize);

        if (source != StateSource.NONE) {
            view.invalidate();
        }
    } else if (pos > 0f) {
        String direction = animator.isLeaving() ? "EXIT" : "ENTER";
        String text = String.format(Locale.US, "%s %.0f%%", direction, pos * 100f);
        drawText(canvas, settings, text, Color.MAGENTA, textSize);
    }

    canvas.restore();
}
 
Example 20
Source File: StoreHouseHeader.java    From Elephant with Apache License 2.0 4 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    float progress = mProgress;
    int c1 = canvas.save();
    int len = mItemList.size();

    for (int i = 0; i < len; i++) {

        canvas.save();
        StoreHouseBarItem storeHouseBarItem = mItemList.get(i);
        float offsetX = mOffsetX + storeHouseBarItem.midPoint.x;
        float offsetY = mOffsetY + storeHouseBarItem.midPoint.y;

        if (mIsInLoading) {
            storeHouseBarItem.getTransformation(getDrawingTime(), mTransformation);
            canvas.translate(offsetX, offsetY);
        } else {

            if (progress == 0) {
                storeHouseBarItem.resetPosition(mHorizontalRandomness);
                continue;
            }

            float startPadding = (1 - mInternalAnimationFactor) * i / len;
            float endPadding = 1 - mInternalAnimationFactor - startPadding;

            // done
            if (progress == 1 || progress >= 1 - endPadding) {
                canvas.translate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha);
            } else {
                float realProgress;
                if (progress <= startPadding) {
                    realProgress = 0;
                } else {
                    realProgress = Math.min(1, (progress - startPadding) / mInternalAnimationFactor);
                }
                offsetX += storeHouseBarItem.translationX * (1 - realProgress);
                offsetY += -mDropHeight * (1 - realProgress);
                Matrix matrix = new Matrix();
                matrix.postRotate(360 * realProgress);
                matrix.postScale(realProgress, realProgress);
                matrix.postTranslate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha * realProgress);
                canvas.concat(matrix);
            }
        }
        storeHouseBarItem.draw(canvas);
        canvas.restore();
    }
    if (mIsInLoading) {
        invalidate();
    }
    canvas.restoreToCount(c1);
}