use of android.graphics.RectF in project platform_frameworks_base by android.
the class WallpaperCropActivity method cropImageAndSetWallpaper.
protected void cropImageAndSetWallpaper(Uri uri, OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) {
boolean centerCrop = getResources().getBoolean(R.bool.center_crop);
// Get the crop
boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
Display d = getWindowManager().getDefaultDisplay();
Point displaySize = new Point();
d.getSize(displaySize);
boolean isPortrait = displaySize.x < displaySize.y;
Point defaultWallpaperSize = getDefaultWallpaperSize(getResources(), getWindowManager());
// Get the crop
RectF cropRect = mCropView.getCrop();
Point inSize = mCropView.getSourceDimensions();
int cropRotation = mCropView.getImageRotation();
float cropScale = mCropView.getWidth() / (float) cropRect.width();
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]);
// Due to rounding errors in the cropview renderer the edges can be slightly offset
// therefore we ensure that the boundaries are sanely defined
cropRect.left = Math.max(0, cropRect.left);
cropRect.right = Math.min(rotatedInSize[0], cropRect.right);
cropRect.top = Math.max(0, cropRect.top);
cropRect.bottom = Math.min(rotatedInSize[1], cropRect.bottom);
// 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;
if (centerCrop) {
extraSpace = 2f * Math.min(rotatedInSize[0] - cropRect.right, cropRect.left);
} else {
extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
}
// Cap the amount of extra width
float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width();
extraSpace = Math.min(extraSpace, maxExtraSpace);
if (centerCrop) {
cropRect.left -= extraSpace / 2f;
cropRect.right += extraSpace / 2f;
} else {
if (ltr) {
cropRect.right += extraSpace;
} else {
cropRect.left -= extraSpace;
}
}
// ADJUST CROP HEIGHT
if (isPortrait) {
cropRect.bottom = cropRect.top + defaultWallpaperSize.y / cropScale;
} else {
// LANDSCAPE
float extraPortraitHeight = defaultWallpaperSize.y / 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() {
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();
}
use of android.graphics.RectF in project platform_frameworks_base by android.
the class WindowStateAnimator method seamlesslyRotateWindow.
void seamlesslyRotateWindow(int oldRotation, int newRotation) {
final WindowState w = mWin;
if (!w.isVisibleNow() || w.mIsWallpaper) {
return;
}
final Rect cropRect = mService.mTmpRect;
final Rect displayRect = mService.mTmpRect2;
final RectF frameRect = mService.mTmpRectF;
final Matrix transform = mService.mTmpTransform;
final float x = w.mFrame.left;
final float y = w.mFrame.top;
final float width = w.mFrame.width();
final float height = w.mFrame.height();
mService.getDefaultDisplayContentLocked().getLogicalDisplayRect(displayRect);
final float displayWidth = displayRect.width();
final float displayHeight = displayRect.height();
// Compute a transform matrix to undo the coordinate space transformation,
// and present the window at the same physical position it previously occupied.
final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation);
DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight, transform);
// occurs, at which point we undo, them.
if (w.isChildWindow() && mSurfaceController.getTransformToDisplayInverse()) {
frameRect.set(x, y, x + width, y + height);
transform.mapRect(frameRect);
w.mAttrs.x = (int) frameRect.left - w.mAttachedWindow.mFrame.left;
w.mAttrs.y = (int) frameRect.top - w.mAttachedWindow.mFrame.top;
w.mAttrs.width = (int) Math.ceil(frameRect.width());
w.mAttrs.height = (int) Math.ceil(frameRect.height());
w.setWindowScale(w.mRequestedWidth, w.mRequestedHeight);
w.applyGravityAndUpdateFrame(w.mContainingFrame, w.mDisplayFrame);
computeShownFrameLocked();
setSurfaceBoundariesLocked(false);
// The stack bounds will not yet be rotated at this point so setSurfaceBoundaries locked
// will crop us incorrectly. Overwrite the crop, exposing the full surface. By the next
// transaction this will be corrected.
cropRect.set(0, 0, w.mRequestedWidth, w.mRequestedWidth + w.mRequestedHeight);
mSurfaceController.setCropInTransaction(cropRect, false);
} else {
mService.markForSeamlessRotation(w, true);
transform.getValues(mService.mTmpFloats);
float DsDx = mService.mTmpFloats[Matrix.MSCALE_X];
float DtDx = mService.mTmpFloats[Matrix.MSKEW_Y];
float DsDy = mService.mTmpFloats[Matrix.MSKEW_X];
float DtDy = mService.mTmpFloats[Matrix.MSCALE_Y];
float nx = mService.mTmpFloats[Matrix.MTRANS_X];
float ny = mService.mTmpFloats[Matrix.MTRANS_Y];
mSurfaceController.setPositionInTransaction(nx, ny, false);
mSurfaceController.setMatrixInTransaction(DsDx * w.mHScale, DtDx * w.mVScale, DsDy * w.mHScale, DtDy * w.mVScale, false);
}
}
use of android.graphics.RectF in project androidquery by androidquery.
the class BitmapAjaxCallback method getRoundedCornerBitmap.
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
use of android.graphics.RectF in project Android-Universal-Image-Loader by nostra13.
the class OldRoundedBitmapDisplayer method getRoundedCornerBitmap.
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width, int height) {
Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final RectF destRectF = new RectF(destRect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(0xFF000000);
canvas.drawRoundRect(destRectF, roundPixels, roundPixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, srcRect, destRectF, paint);
return output;
}
use of android.graphics.RectF in project chromeview by pwnall.
the class PopupZoomer method initDimensions.
private void initDimensions() {
if (mTargetBounds == null || mTouch == null)
return;
// Compute the final zoom scale.
mScale = (float) mZoomedBitmap.getWidth() / mTargetBounds.width();
float l = mTouch.x - mScale * (mTouch.x - mTargetBounds.left);
float t = mTouch.y - mScale * (mTouch.y - mTargetBounds.top);
float r = l + mZoomedBitmap.getWidth();
float b = t + mZoomedBitmap.getHeight();
mClipRect = new RectF(l, t, r, b);
int width = getWidth();
int height = getHeight();
mViewClipRect = new RectF(ZOOM_BOUNDS_MARGIN, ZOOM_BOUNDS_MARGIN, width - ZOOM_BOUNDS_MARGIN, height - ZOOM_BOUNDS_MARGIN);
// Ensure it stays inside the bounds of the view. First shift it around to see if it
// can fully fit in the view, then clip it to the padding section of the view to
// ensure no overflow.
mShiftX = 0;
mShiftY = 0;
// to the left instead of right.
if (mClipRect.left < ZOOM_BOUNDS_MARGIN) {
mShiftX = ZOOM_BOUNDS_MARGIN - mClipRect.left;
mClipRect.left += mShiftX;
mClipRect.right += mShiftX;
} else if (mClipRect.right > width - ZOOM_BOUNDS_MARGIN) {
mShiftX = (width - ZOOM_BOUNDS_MARGIN - mClipRect.right);
mClipRect.right += mShiftX;
mClipRect.left += mShiftX;
}
if (mClipRect.top < ZOOM_BOUNDS_MARGIN) {
mShiftY = ZOOM_BOUNDS_MARGIN - mClipRect.top;
mClipRect.top += mShiftY;
mClipRect.bottom += mShiftY;
} else if (mClipRect.bottom > height - ZOOM_BOUNDS_MARGIN) {
mShiftY = height - ZOOM_BOUNDS_MARGIN - mClipRect.bottom;
mClipRect.bottom += mShiftY;
mClipRect.top += mShiftY;
}
// Allow enough scrolling to get to the entire bitmap that may be clipped inside the
// bounds of the view.
mMinScrollX = mMaxScrollX = mMinScrollY = mMaxScrollY = 0;
if (mViewClipRect.right + mShiftX < mClipRect.right) {
mMinScrollX = mViewClipRect.right - mClipRect.right;
}
if (mViewClipRect.left + mShiftX > mClipRect.left) {
mMaxScrollX = mViewClipRect.left - mClipRect.left;
}
if (mViewClipRect.top + mShiftY > mClipRect.top) {
mMaxScrollY = mViewClipRect.top - mClipRect.top;
}
if (mViewClipRect.bottom + mShiftY < mClipRect.bottom) {
mMinScrollY = mViewClipRect.bottom - mClipRect.bottom;
}
// Now that we know how much we need to scroll, we can intersect with mViewClipRect.
mClipRect.intersect(mViewClipRect);
mLeftExtrusion = mTouch.x - mClipRect.left;
mRightExtrusion = mClipRect.right - mTouch.x;
mTopExtrusion = mTouch.y - mClipRect.top;
mBottomExtrusion = mClipRect.bottom - mTouch.y;
// Set an initial scroll position to take touch point into account.
float percentX = (mTouch.x - mTargetBounds.centerX()) / (mTargetBounds.width() / 2.f) + .5f;
float percentY = (mTouch.y - mTargetBounds.centerY()) / (mTargetBounds.height() / 2.f) + .5f;
float scrollWidth = mMaxScrollX - mMinScrollX;
float scrollHeight = mMaxScrollY - mMinScrollY;
mPopupScrollX = scrollWidth * percentX * -1f;
mPopupScrollY = scrollHeight * percentY * -1f;
// Constrain initial scroll position within allowed bounds.
mPopupScrollX = constrain(mPopupScrollX, mMinScrollX, mMaxScrollX);
mPopupScrollY = constrain(mPopupScrollY, mMinScrollY, mMaxScrollY);
}
Aggregations