Search in sources :

Example 21 with Matrix

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

the class MatchView method onDraw.

@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 < mItemList.size(); i++) {
        canvas.save();
        MatchItem LoadingViewItem = mItemList.get(i);
        float offsetX = mOffsetX + LoadingViewItem.midPoint.x;
        float offsetY = mOffsetY + LoadingViewItem.midPoint.y;
        if (mIsInLoading) {
            LoadingViewItem.getTransformation(getDrawingTime(), mTransformation);
            canvas.translate(offsetX, offsetY);
        } else {
            if (progress == 0) {
                LoadingViewItem.resetPosition(horizontalRandomness);
                continue;
            }
            float startPadding = (1 - internalAnimationFactor) * i / len;
            float endPadding = 1 - internalAnimationFactor - startPadding;
            // done
            if (progress == 1 || progress >= 1 - endPadding) {
                canvas.translate(offsetX, offsetY);
                LoadingViewItem.setAlpha(mBarDarkAlpha);
            } else {
                float realProgress;
                if (progress <= startPadding) {
                    realProgress = 0;
                } else {
                    realProgress = Math.min(1, (progress - startPadding) / internalAnimationFactor);
                }
                offsetX += LoadingViewItem.translationX * (1 - realProgress);
                offsetY += -mDropHeight * (1 - realProgress);
                Matrix matrix = new Matrix();
                matrix.postRotate(360 * realProgress);
                matrix.postScale(realProgress, realProgress);
                matrix.postTranslate(offsetX, offsetY);
                LoadingViewItem.setAlpha(mBarDarkAlpha * realProgress);
                canvas.concat(matrix);
            }
        }
        LoadingViewItem.draw(canvas);
        canvas.restore();
    }
    if (mIsInLoading) {
        invalidate();
    }
    canvas.restoreToCount(c1);
}
Also used : Matrix(android.graphics.Matrix)

Example 22 with Matrix

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

the class BaseFoldingLayout method prepareFold.

/**
     * This method is called in order to update the fold's orientation, anchor
     * point and number of folds. This creates the necessary setup in order to
     * prepare the layout for a fold with the specified parameters. Some of the
     * dimensions required for the folding transformation are also acquired
     * here.
     * <p/>
     * After this method is called, it will be in a completely unfolded state by
     * default.
     */
private void prepareFold(Orientation orientation, float anchorFactor, int numberOfFolds) {
    mSrc = new float[NUM_OF_POLY_POINTS];
    mDst = new float[NUM_OF_POLY_POINTS];
    mDstRect = new Rect();
    mFoldFactor = 0;
    mPreviousFoldFactor = 0;
    mIsFoldPrepared = false;
    mSolidShadow = new Paint();
    mGradientShadow = new Paint();
    mOrientation = orientation;
    mIsHorizontal = (orientation == Orientation.HORIZONTAL);
    if (mIsHorizontal) {
        mShadowLinearGradient = new LinearGradient(0, 0, SHADING_FACTOR, 0, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
    } else {
        mShadowLinearGradient = new LinearGradient(0, 0, 0, SHADING_FACTOR, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
    }
    mGradientShadow.setStyle(Style.FILL);
    mGradientShadow.setShader(mShadowLinearGradient);
    mShadowGradientMatrix = new Matrix();
    mAnchorFactor = anchorFactor;
    mNumberOfFolds = numberOfFolds;
    mOriginalWidth = getMeasuredWidth();
    mOriginalHeight = getMeasuredHeight();
    mFoldRectArray = new Rect[mNumberOfFolds];
    mMatrix = new Matrix[mNumberOfFolds];
    for (int x = 0; x < mNumberOfFolds; x++) {
        mMatrix[x] = new Matrix();
    }
    int h = mOriginalHeight;
    int w = mOriginalWidth;
    if (Util.IS_JBMR2 && h != 0 && w != 0) {
        mFullBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(mFullBitmap);
        getChildAt(0).draw(canvas);
    }
    int delta = Math.round(mIsHorizontal ? ((float) w) / ((float) mNumberOfFolds) : ((float) h) / ((float) mNumberOfFolds));
    /*
         * Loops through the number of folds and segments the full layout into a
		 * number of smaller equal components. If the number of folds is odd,
		 * then one of the components will be smaller than all the rest. Note
		 * that deltap below handles the calculation for an odd number of folds.
		 */
    for (int x = 0; x < mNumberOfFolds; x++) {
        if (mIsHorizontal) {
            int deltap = (x + 1) * delta > w ? w - x * delta : delta;
            mFoldRectArray[x] = new Rect(x * delta, 0, x * delta + deltap, h);
        } else {
            int deltap = (x + 1) * delta > h ? h - x * delta : delta;
            mFoldRectArray[x] = new Rect(0, x * delta, w, x * delta + deltap);
        }
    }
    if (mIsHorizontal) {
        mFoldMaxHeight = h;
        mFoldMaxWidth = delta;
    } else {
        mFoldMaxHeight = delta;
        mFoldMaxWidth = w;
    }
    mIsFoldPrepared = true;
}
Also used : LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 23 with Matrix

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

the class GoogleMusicDicesDrawable method drawScaleY.

private void drawScaleY(Canvas canvas) {
    canvas.save();
    Matrix matrix = new Matrix();
    matrix.preScale(1, mScale, mSize / 2, 0);
    canvas.concat(matrix);
    drawDiceSide(canvas, mDiceStates[mDiceState].side1, false);
    canvas.restore();
    canvas.save();
    matrix = new Matrix();
    matrix.preScale(1, 1 - mScale, mSize / 2, mSize);
    canvas.concat(matrix);
    drawDiceSide(canvas, mDiceStates[mDiceState].side2, mScale > 0.1f);
    canvas.restore();
}
Also used : Matrix(android.graphics.Matrix)

Example 24 with Matrix

use of android.graphics.Matrix in project android by owncloud.

the class TouchImageViewCustom method sharedConstructing.

private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (mScaleType == null) {
        mScaleType = ScaleType.FIT_CENTER;
    }
    minScale = 1;
    maxScale = 3;
    superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setState(State.NONE);
    onDrawReady = false;
    super.setOnTouchListener(new PrivateOnTouchListener());
}
Also used : Matrix(android.graphics.Matrix) GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 25 with Matrix

use of android.graphics.Matrix 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)

Aggregations

Matrix (android.graphics.Matrix)1590 Bitmap (android.graphics.Bitmap)487 Paint (android.graphics.Paint)344 RectF (android.graphics.RectF)276 Test (org.junit.Test)154 Canvas (android.graphics.Canvas)139 Rect (android.graphics.Rect)127 ColorMatrix (android.graphics.ColorMatrix)87 Point (android.graphics.Point)79 View (android.view.View)78 Path (android.graphics.Path)74 ImageView (android.widget.ImageView)73 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)67 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)67 IOException (java.io.IOException)61 Drawable (android.graphics.drawable.Drawable)48 BitmapFactory (android.graphics.BitmapFactory)47 Bundle (android.os.Bundle)46 ViewGroup (android.view.ViewGroup)44 PointF (android.graphics.PointF)42