Search in sources :

Example 1 with RectF

use of android.graphics.RectF in project Launcher3 by chislon.

the class WallpaperCropActivity method cropImageAndSetWallpaper.

protected void cropImageAndSetWallpaper(Uri uri, OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) {
    // Get the crop
    boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
    Point minDims = new Point();
    Point maxDims = new Point();
    Display d = getWindowManager().getDefaultDisplay();
    d.getCurrentSizeRange(minDims, maxDims);
    Point displaySize = new Point();
    d.getSize(displaySize);
    int maxDim = Math.max(maxDims.x, maxDims.y);
    final int minDim = Math.min(minDims.x, minDims.y);
    int defaultWallpaperWidth;
    if (isScreenLarge(getResources())) {
        defaultWallpaperWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
    } else {
        defaultWallpaperWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
    }
    boolean isPortrait = displaySize.x < displaySize.y;
    int portraitHeight;
    if (isPortrait) {
        portraitHeight = mCropView.getHeight();
    } else {
        // TODO: how to actually get the proper portrait height?
        // This is not quite right:
        portraitHeight = Math.max(maxDims.x, maxDims.y);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Point realSize = new Point();
        d.getRealSize(realSize);
        portraitHeight = Math.max(realSize.x, realSize.y);
    }
    // Get the crop
    RectF cropRect = mCropView.getCrop();
    int cropRotation = mCropView.getImageRotation();
    float cropScale = mCropView.getWidth() / (float) cropRect.width();
    Point inSize = mCropView.getSourceDimensions();
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.setRotate(cropRotation);
    float[] rotatedInSize = new float[] { inSize.x, inSize.y };
    rotateMatrix.mapPoints(rotatedInSize);
    rotatedInSize[0] = Math.abs(rotatedInSize[0]);
    rotatedInSize[1] = Math.abs(rotatedInSize[1]);
    // ADJUST CROP WIDTH
    // Extend the crop all the way to the right, for parallax
    // (or all the way to the left, in RTL)
    float extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
    // Cap the amount of extra width
    float maxExtraSpace = defaultWallpaperWidth / cropScale - cropRect.width();
    extraSpace = Math.min(extraSpace, maxExtraSpace);
    if (ltr) {
        cropRect.right += extraSpace;
    } else {
        cropRect.left -= extraSpace;
    }
    // ADJUST CROP HEIGHT
    if (isPortrait) {
        cropRect.bottom = cropRect.top + portraitHeight / cropScale;
    } else {
        // LANDSCAPE
        float extraPortraitHeight = portraitHeight / cropScale - cropRect.height();
        float expandHeight = Math.min(Math.min(rotatedInSize[1] - cropRect.bottom, cropRect.top), extraPortraitHeight / 2);
        cropRect.top -= expandHeight;
        cropRect.bottom += expandHeight;
    }
    final int outWidth = (int) Math.round(cropRect.width() * cropScale);
    final int outHeight = (int) Math.round(cropRect.height() * cropScale);
    Runnable onEndCrop = new Runnable() {

        public void run() {
            updateWallpaperDimensions(outWidth, outHeight);
            if (finishActivityWhenDone) {
                setResult(Activity.RESULT_OK);
                finish();
            }
        }
    };
    BitmapCropTask cropTask = new BitmapCropTask(this, uri, cropRect, cropRotation, outWidth, outHeight, true, false, onEndCrop);
    if (onBitmapCroppedHandler != null) {
        cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
    }
    cropTask.execute();
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) Point(android.graphics.Point) Point(android.graphics.Point) Paint(android.graphics.Paint) Display(android.view.Display)

Example 2 with RectF

use of android.graphics.RectF in project Launcher3 by chislon.

the class WallpaperPickerActivity method createThumbnail.

private static Bitmap createThumbnail(Point size, Context context, Uri uri, byte[] imageBytes, Resources res, int resId, int rotation, boolean leftAligned) {
    int width = size.x;
    int height = size.y;
    BitmapCropTask cropTask;
    if (uri != null) {
        cropTask = new BitmapCropTask(context, uri, null, rotation, width, height, false, true, null);
    } else if (imageBytes != null) {
        cropTask = new BitmapCropTask(imageBytes, null, rotation, width, height, false, true, null);
    } else {
        cropTask = new BitmapCropTask(context, res, resId, null, rotation, width, height, false, true, null);
    }
    Point bounds = cropTask.getImageBounds();
    if (bounds == null || bounds.x == 0 || bounds.y == 0) {
        return null;
    }
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.setRotate(rotation);
    float[] rotatedBounds = new float[] { bounds.x, bounds.y };
    rotateMatrix.mapPoints(rotatedBounds);
    rotatedBounds[0] = Math.abs(rotatedBounds[0]);
    rotatedBounds[1] = Math.abs(rotatedBounds[1]);
    RectF cropRect = WallpaperCropActivity.getMaxCropRect((int) rotatedBounds[0], (int) rotatedBounds[1], width, height, leftAligned);
    cropTask.setCropBounds(cropRect);
    if (cropTask.cropBitmap()) {
        return cropTask.getCroppedBitmap();
    } else {
        return null;
    }
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) Point(android.graphics.Point) Point(android.graphics.Point)

Example 3 with RectF

use of android.graphics.RectF in project cw-omnibus by commonsguy.

the class AnimatorProxy method invalidateAfterUpdate.

private void invalidateAfterUpdate() {
    View view = mView.get();
    if (view == null || view.getParent() == null) {
        return;
    }
    final RectF after = mAfter;
    computeRect(after, view);
    after.union(mBefore);
    ((View) view.getParent()).invalidate((int) Math.floor(after.left), (int) Math.floor(after.top), (int) Math.ceil(after.right), (int) Math.ceil(after.bottom));
}
Also used : RectF(android.graphics.RectF) View(android.view.View)

Example 4 with RectF

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

the class CircularImageView method onDraw.

@Override
public void onDraw(Canvas canvas) {
    // Don't draw anything without an image
    if (image == null)
        return;
    // Nothing to draw (Empty bounds)
    if (image.getHeight() == 0 || image.getWidth() == 0)
        return;
    // Update shader if canvas size has changed
    int oldCanvasSize = canvasSize;
    canvasSize = getWidth() < getHeight() ? getWidth() : getHeight();
    if (oldCanvasSize != canvasSize)
        updateBitmapShader();
    // Apply shader to paint
    paint.setShader(shader);
    // Keep track of selectorStroke/border width
    int outerWidth = 0;
    // Get the exact X/Y axis of the view
    int center = canvasSize / 2;
    if (hasSelector && isSelected) {
        // Draw the selector stroke & apply the selector filter, if applicable
        outerWidth = selectorStrokeWidth;
        center = (canvasSize - (outerWidth * 2)) / 2;
        paint.setColorFilter(selectorFilter);
        canvas.drawCircle(center + outerWidth, center + outerWidth, ((canvasSize - (outerWidth * 2)) / 2) + outerWidth - 4.0f, paintSelectorBorder);
    } else if (hasBorder) {
        // If no selector was drawn, draw a border and clear the filter instead... if enabled
        outerWidth = borderWidth;
        center = (canvasSize - (outerWidth * 2)) / 2;
        paint.setColorFilter(null);
        RectF rekt = new RectF(0 + outerWidth / 2, 0 + outerWidth / 2, canvasSize - outerWidth / 2, canvasSize - outerWidth / 2);
        canvas.drawArc(rekt, 360, 360, false, paintBorder);
    //canvas.drawCircle(center + outerWidth, center + outerWidth, ((canvasSize - (outerWidth * 2)) / 2) + outerWidth - 4.0f, paintBorder);
    } else
        // Clear the color filter if no selector nor border were drawn
        paint.setColorFilter(null);
    // Draw the circular image itself
    canvas.drawCircle(center + outerWidth, center + outerWidth, ((canvasSize - (outerWidth * 2)) / 2), paint);
}
Also used : RectF(android.graphics.RectF) Paint(android.graphics.Paint)

Example 5 with RectF

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

the class SearchDrawable method createSearchPath.

private void createSearchPath(float phase) {
    RectF oval = new RectF(0.0f, 0.0f, mRadius * 2.0f, mRadius * 2.0f);
    float cx = oval.centerX();
    float cy = oval.centerY();
    float rx = oval.width() / 2.0f;
    float ry = oval.height() / 2.0f;
    final float TAN_PI_OVER_8 = 0.414213562f;
    final float ROOT_2_OVER_2 = 0.707106781f;
    float sx = rx * TAN_PI_OVER_8;
    float sy = ry * TAN_PI_OVER_8;
    float mx = rx * ROOT_2_OVER_2;
    float my = ry * ROOT_2_OVER_2;
    float L = oval.left;
    float T = oval.top;
    float R = oval.right;
    float B = oval.bottom;
    mPath = new Path();
    mPath.moveTo(cx + mx, cy + my);
    mPath.quadTo(cx + sx, B, cx, B);
    mPath.quadTo(cx - sx, B, cx - mx, cy + my);
    mPath.quadTo(L, cy + sy, L, cy);
    mPath.quadTo(L, cy - sy, cx - mx, cy - my);
    mPath.quadTo(cx - sx, T, cx, T);
    mPath.quadTo(cx + sx, T, cx + mx, cy - my);
    mPath.quadTo(R, cy - sy, R, cy);
    mPath.quadTo(R, cy + sy, cx + mx, cy + my);
    mPath.lineTo(1.5f * R, 1.5f * B);
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path)

Aggregations

RectF (android.graphics.RectF)1216 Paint (android.graphics.Paint)437 Rect (android.graphics.Rect)176 Matrix (android.graphics.Matrix)150 Bitmap (android.graphics.Bitmap)148 Path (android.graphics.Path)140 Canvas (android.graphics.Canvas)134 Point (android.graphics.Point)78 ImageView (android.widget.ImageView)74 PorterDuffXfermode (android.graphics.PorterDuffXfermode)49 View (android.view.View)39 LinearGradient (android.graphics.LinearGradient)38 SuppressLint (android.annotation.SuppressLint)32 Drawable (android.graphics.drawable.Drawable)26 PointF (android.graphics.PointF)21 RadialGradient (android.graphics.RadialGradient)21 TextPaint (android.text.TextPaint)21 ArrayList (java.util.ArrayList)21 BitmapDrawable (android.graphics.drawable.BitmapDrawable)20 TypedArray (android.content.res.TypedArray)14