Search in sources :

Example 36 with Path

use of android.graphics.Path in project android-app-common-tasks by multidots.

the class CropImage method onSaveClicked.

private void onSaveClicked() {
    // bitmap doesn't have to be read into memory
    if (mSaving)
        return;
    if (mCrop == null) {
        return;
    }
    mSaving = true;
    Rect r = mCrop.getCropRect();
    int width = r.width();
    int height = r.height();
    // If we are circle cropping, we want alpha channel, which is the
    // third param here.
    Bitmap croppedImage;
    croppedImage = Bitmap.createBitmap(width, height, mCircleCrop || mOutputFormat == Bitmap.CompressFormat.PNG ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    if (croppedImage == null) {
        return;
    }
    {
        Canvas canvas = new Canvas(croppedImage);
        Rect dstRect = new Rect(0, 0, width, height);
        canvas.drawBitmap(mBitmap, r, dstRect, null);
    }
    if (mCircleCrop) {
        // OK, so what's all this about?
        // Bitmaps are inherently rectangular but we want to return
        // something that's basically a circle.  So we fill in the
        // area around the circle with alpha.  Note the all important
        // PortDuff.Mode.CLEAR.
        Canvas c = new Canvas(croppedImage);
        Path p = new Path();
        p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
        c.clipPath(p, Region.Op.DIFFERENCE);
        c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
    }
    /* If the output is required to a specific size then scale or fill */
    if (mOutputX != 0 && mOutputY != 0) {
        if (mScale) {
            /* Scale the image to the required dimensions */
            Bitmap old = croppedImage;
            croppedImage = Util.transform(new Matrix(), croppedImage, mOutputX, mOutputY, mScaleUp);
            if (old != croppedImage) {
                old.recycle();
            }
        } else {
            /* Don't scale the image crop it to the size requested.
                 * Create an new image with the cropped image in the center and
				 * the extra space filled.
				 */
            // Don't scale the image but instead fill it so it's the
            // required dimension
            Bitmap b = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(b);
            Rect srcRect = mCrop.getCropRect();
            Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);
            int dx = (srcRect.width() - dstRect.width()) / 2;
            int dy = (srcRect.height() - dstRect.height()) / 2;
            /* If the srcRect is too big, use the center part of it. */
            srcRect.inset(Math.max(0, dx), Math.max(0, dy));
            /* If the dstRect is too big, use the center part of it. */
            dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));
            /* Draw the cropped bitmap in the center */
            canvas.drawBitmap(mBitmap, srcRect, dstRect, null);
            /* Set the cropped bitmap as the new bitmap */
            croppedImage.recycle();
            croppedImage = b;
        }
    }
    // Return the cropped image directly or save it to the specified URI.
    Bundle myExtras = getIntent().getExtras();
    if (myExtras != null && (myExtras.getParcelable("data") != null || myExtras.getBoolean(RETURN_DATA))) {
        Bundle extras = new Bundle();
        extras.putParcelable(RETURN_DATA_AS_BITMAP, croppedImage);
        setResult(RESULT_OK, (new Intent()).setAction(ACTION_INLINE_DATA).putExtras(extras));
        finish();
    } else {
        final Bitmap b = croppedImage;
        Util.startBackgroundJob(this, null, getString(R.string.saving_image), new Runnable() {

            public void run() {
                saveOutput(b);
            }
        }, mHandler);
    }
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 37 with Path

use of android.graphics.Path in project PhotoNoter by yydcdut.

the class MaterialRippleLayout method draw.

/*
     * Drawing
     */
@Override
public void draw(Canvas canvas) {
    final boolean positionChanged = adapterPositionChanged();
    if (rippleOverlay) {
        if (!positionChanged) {
            rippleBackground.draw(canvas);
        }
        super.draw(canvas);
        if (!positionChanged) {
            if (rippleRoundedCorners != 0) {
                Path clipPath = new Path();
                RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
                clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
                canvas.clipPath(clipPath);
            }
            canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
        }
    } else {
        if (!positionChanged) {
            rippleBackground.draw(canvas);
            canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
        }
        super.draw(canvas);
    }
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF)

Example 38 with Path

use of android.graphics.Path in project TastyToast by yadav-rahul.

the class ConfusingToastView method initPath.

private void initPath() {
    Path mPath = new Path();
    RectF rectF = new RectF(mWidth / 2f - dip2px(1.5f), mHeight / 2f - dip2px(1.5f), mWidth / 2f + dip2px(1.5f), mHeight / 2f + dip2px(1.5f));
    mPath.addArc(rectF, 180f, 180f);
    rectF.set(rectF.left - dip2px(3), rectF.top - dip2px(1.5f), rectF.right, rectF.bottom + dip2px(1.5f));
    mPath.addArc(rectF, 0f, 180f);
    rectF.set(rectF.left, rectF.top - dip2px(1.5f), rectF.right + dip2px(3), rectF.bottom + dip2px(1.5f));
    mPath.addArc(rectF, 180f, 180f);
    rectF.set(rectF.left - dip2px(3), rectF.top - dip2px(1.5f), rectF.right, rectF.bottom + dip2px(1.5f));
    mPath.addArc(rectF, 0f, 180f);
    eye = Bitmap.createBitmap((int) mWidth, (int) mHeight, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(eye);
    mPaint.setStrokeWidth(dip2px(1.7f));
    c.drawPath(mPath, mPaint);
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) Canvas(android.graphics.Canvas)

Example 39 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

the class ChangeTransform method createTransformAnimator.

private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues, final boolean handleParentChange) {
    Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
    Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);
    if (startMatrix == null) {
        startMatrix = Matrix.IDENTITY_MATRIX;
    }
    if (endMatrix == null) {
        endMatrix = Matrix.IDENTITY_MATRIX;
    }
    if (startMatrix.equals(endMatrix)) {
        return null;
    }
    final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);
    // clear the transform properties so that we can use the animation matrix instead
    final View view = endValues.view;
    setIdentityTransforms(view);
    final float[] startMatrixValues = new float[9];
    startMatrix.getValues(startMatrixValues);
    final float[] endMatrixValues = new float[9];
    endMatrix.getValues(endMatrixValues);
    final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);
    PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY, new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
    Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y], endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
    PropertyValuesHolder translationProperty = PropertyValuesHolder.ofObject(TRANSLATIONS_PROPERTY, null, path);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty, translationProperty);
    final Matrix finalEndMatrix = endMatrix;
    AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {

        private boolean mIsCanceled;

        private Matrix mTempMatrix = new Matrix();

        @Override
        public void onAnimationCancel(Animator animation) {
            mIsCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mIsCanceled) {
                if (handleParentChange && mUseOverlay) {
                    setCurrentMatrix(finalEndMatrix);
                } else {
                    view.setTagInternal(R.id.transitionTransform, null);
                    view.setTagInternal(R.id.parentMatrix, null);
                }
            }
            view.setAnimationMatrix(null);
            transforms.restore(view);
        }

        @Override
        public void onAnimationPause(Animator animation) {
            Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
            setCurrentMatrix(currentMatrix);
        }

        @Override
        public void onAnimationResume(Animator animation) {
            setIdentityTransforms(view);
        }

        private void setCurrentMatrix(Matrix currentMatrix) {
            mTempMatrix.set(currentMatrix);
            view.setTagInternal(R.id.transitionTransform, mTempMatrix);
            transforms.restore(view);
        }
    };
    animator.addListener(listener);
    animator.addPauseListener(listener);
    return animator;
}
Also used : Path(android.graphics.Path) FloatArrayEvaluator(android.animation.FloatArrayEvaluator) Matrix(android.graphics.Matrix) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) GhostView(android.view.GhostView) View(android.view.View)

Example 40 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

the class TextView method getUpdatedHighlightPath.

private Path getUpdatedHighlightPath() {
    Path highlight = null;
    Paint highlightPaint = mHighlightPaint;
    final int selStart = getSelectionStart();
    final int selEnd = getSelectionEnd();
    if (mMovement != null && (isFocused() || isPressed()) && selStart >= 0) {
        if (selStart == selEnd) {
            if (mEditor != null && mEditor.isCursorVisible() && (SystemClock.uptimeMillis() - mEditor.mShowCursor) % (2 * Editor.BLINK) < Editor.BLINK) {
                if (mHighlightPathBogus) {
                    if (mHighlightPath == null)
                        mHighlightPath = new Path();
                    mHighlightPath.reset();
                    mLayout.getCursorPath(selStart, mHighlightPath, mText);
                    mEditor.updateCursorsPositions();
                    mHighlightPathBogus = false;
                }
                // XXX should pass to skin instead of drawing directly
                highlightPaint.setColor(mCurTextColor);
                highlightPaint.setStyle(Paint.Style.STROKE);
                highlight = mHighlightPath;
            }
        } else {
            if (mHighlightPathBogus) {
                if (mHighlightPath == null)
                    mHighlightPath = new Path();
                mHighlightPath.reset();
                mLayout.getSelectionPath(selStart, selEnd, mHighlightPath);
                mHighlightPathBogus = false;
            }
            // XXX should pass to skin instead of drawing directly
            highlightPaint.setColor(mHighlightColor);
            highlightPaint.setStyle(Paint.Style.FILL);
            highlight = mHighlightPath;
        }
    }
    return highlight;
}
Also used : Path(android.graphics.Path) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

Path (android.graphics.Path)1012 Paint (android.graphics.Paint)462 RectF (android.graphics.RectF)289 Matrix (android.graphics.Matrix)74 Rect (android.graphics.Rect)59 Canvas (android.graphics.Canvas)53 TextPaint (android.text.TextPaint)37 Bitmap (android.graphics.Bitmap)36 PointF (android.graphics.PointF)29 Point (android.graphics.Point)28 LinearGradient (android.graphics.LinearGradient)24 View (android.view.View)24 ObjectAnimator (android.animation.ObjectAnimator)23 Stack (java.util.Stack)22 Animator (android.animation.Animator)18 PathMeasure (android.graphics.PathMeasure)18 RadialGradient (android.graphics.RadialGradient)17 Test (org.junit.Test)15 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)14 DashPathEffect (android.graphics.DashPathEffect)14