List of usage examples for android.graphics Rect height
public final int height()
From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java
private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { // Release memory now clearImageView();//from w w w . j a v a2s . co m InputStream is = null; Bitmap croppedImage = null; try { is = getContentResolver().openInputStream(sourceUri); BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false); final int width = decoder.getWidth(); final int height = decoder.getHeight(); if (exifRotation != 0) { // Adjust crop area to account for image rotation Matrix matrix = new Matrix(); matrix.setRotate(-exifRotation); RectF adjusted = new RectF(); matrix.mapRect(adjusted, new RectF(rect)); //if the cutting box are rectangle( outWidth != outHeight ),and the exifRotation is 90 or 270, //the outWidth and outHeight showld be interchanged if (exifRotation == 90 || exifRotation == 270) { int temp = outWidth; outWidth = outHeight; outHeight = temp; } // Adjust to account for origin at 0,0 adjusted.offset(adjusted.left < 0 ? width : 0, adjusted.top < 0 ? height : 0); rect = new Rect((int) adjusted.left, (int) adjusted.top, (int) adjusted.right, (int) adjusted.bottom); } try { croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options()); if (rect.width() > outWidth || rect.height() > outHeight) { Matrix matrix = new Matrix(); matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height()); //if the picture's exifRotation !=0 ,they should be rotate to 0 degrees matrix.postRotate(exifRotation); croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true); } else { //if the picture need not to be scale, they also neet to be rotate to 0 degrees Matrix matrix = new Matrix(); matrix.postRotate(exifRotation); croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true); } } catch (IllegalArgumentException e) { // Rethrow with some extra information throw new IllegalArgumentException("Rectangle " + rect + " is outside of the image (" + width + "," + height + "," + exifRotation + ")", e); } } catch (IOException e) { Log.e("Error cropping image: " + e.getMessage(), e); finish(); } catch (OutOfMemoryError e) { Log.e("OOM cropping image: " + e.getMessage(), e); setResultException(e); } finally { CropUtil.closeSilently(is); } return croppedImage; }
From source file:com.android.leanlauncher.Workspace.java
public int[] estimateItemSize(int hSpan, int vSpan, boolean springLoaded) { int[] size = new int[2]; if (getChildCount() > 0) { // Use the first non-custom page to estimate the child position Rect r = estimateItemPosition(mWorkspace, 0, 0, hSpan, vSpan); size[0] = r.width();//ww w.j a va 2 s. c om size[1] = r.height(); if (springLoaded) { size[0] *= mSpringLoadedShrinkFactor; size[1] *= mSpringLoadedShrinkFactor; } return size; } else { size[0] = Integer.MAX_VALUE; size[1] = Integer.MAX_VALUE; return size; } }
From source file:com.brian.common.view.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (mIsCirculate) { if (mProgress >= .995) { flipped = true;//w ww . j a v a 2 s . c o m } else if (mProgress <= .005) { flipped = false; } if (flipped) { canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } } Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false; break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; default: flipToPointRight = false; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress)); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5 + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:me.test.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override/* w w w .ja v a2 s . c o m*/ public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); if (!isFirst) { isFirst = true; slideTop = frame.top; } // // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // paint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_dark)); // canvas.drawRect(frame.left, frame.top, frame.left + 50, frame.top + 10, paint); canvas.drawRect(frame.left, frame.top, frame.left + 10, frame.top + 50, paint); //? canvas.drawRect(frame.right - 50, frame.top, frame.right, frame.top + 10, paint); canvas.drawRect(frame.right - 10, frame.top, frame.right, frame.top + 50, paint); // canvas.drawRect(frame.left, frame.bottom - 10, frame.left + 50, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - 50, frame.left + 10, frame.bottom, paint); //? canvas.drawRect(frame.right - 50, frame.bottom - 10, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - 10, frame.bottom - 50, frame.right, frame.bottom, paint); //,??SPEEN_DISTANCE slideTop += 5; if (slideTop >= frame.bottom) { slideTop = frame.top; } canvas.drawRect(frame.left + 5, slideTop - 6 / 2, frame.right - 5, slideTop + 6 / 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
/** * Compute the amount to scroll in the Y direction in order to get * a rectangle completely on the screen (or, if taller than the screen, * at least the first screen size chunk of it). * * @param rect The rect.// w w w .jav a2 s.c o m * @return The scroll delta. */ protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) { if (getChildCount() == 0) return 0; int height = getHeight(); int screenTop = getScrollY(); int screenBottom = screenTop + height; int fadingEdge = getVerticalFadingEdgeLength(); // leave room for top fading edge as long as rect isn't at very top if (rect.top > 0) { screenTop += fadingEdge; } // leave room for bottom fading edge as long as rect isn't at very bottom if (rect.bottom < getChildAt(0).getHeight()) { screenBottom -= fadingEdge; } int scrollYDelta = 0; if (rect.bottom > screenBottom && rect.top > screenTop) { // need to move down to get it in view: move down just enough so // that the entire rectangle is in view (or at least the first // screen size chunk). if (rect.height() > height) { // just enough to get screen size chunk on scrollYDelta += (rect.top - screenTop); } else { // get entire rect at bottom of screen scrollYDelta += (rect.bottom - screenBottom); } // make sure we aren't scrolling beyond the end of our content int bottom = getChildAt(0).getBottom(); int distanceToBottom = bottom - screenBottom; scrollYDelta = Math.min(scrollYDelta, distanceToBottom); } else if (rect.top < screenTop && rect.bottom < screenBottom) { // need to move up to get it in view: move up just enough so that // entire rectangle is in view (or at least the first screen // size chunk of it). if (rect.height() > height) { // screen size chunk scrollYDelta -= (screenBottom - rect.bottom); } else { // entire rect at top scrollYDelta -= (screenTop - rect.top); } // make sure we aren't scrolling any further than the top our content scrollYDelta = Math.max(scrollYDelta, -getScrollY()); } return scrollYDelta; }
From source file:com.android.leanlauncher.Workspace.java
int getOverviewModeTranslationY() { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); Rect overviewBar = grid.getOverviewModeButtonBarRect(); int availableHeight = mViewPort.height(); int scaledHeight = (int) (mOverviewModeShrinkFactor * mViewPort.height()); int offsetFromTopEdge = (availableHeight - scaledHeight) / 2; int offsetToCenterInOverview = (availableHeight - overviewBar.height() - scaledHeight) / 2; return -offsetFromTopEdge + offsetToCenterInOverview; }
From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java
private void performAnimation() { if (!mViewCacheForAnim.isEmpty()) { isAnimating = true;//from w w w. j a v a 2 s . c o m int count = mViewCacheForAnim.size(); final View view = mViewCacheForAnim.remove(0); Rect rect = new Rect(); this.getGlobalVisibleRect(rect); int fly_distance = (int) (rect.height()); float top = view.getY(); float bottom = view.getY() + view.getMeasuredHeight(); float startTop = top + fly_distance; float startBottom = bottom + fly_distance; int bufferDis = rect.height() / 4; if (startBottom < 0) { Log.d(TAG, "No animation as the view is passed!!"); view.setVisibility(View.VISIBLE); performAnimation(); return; } else if (startTop < rect.height()) { fly_distance += (rect.height() - startTop + bufferDis); } if (fly_distance > rect.height() * 2) { Log.d(TAG, "No animation as the fly distance is too long!"); view.setVisibility(View.VISIBLE); performAnimation(); return; } else if (fly_distance < rect.height()) { fly_distance = rect.height(); } view.setTranslationY(fly_distance); long delay = FLY_IN_DELAY / count; long duration = delay > FLY_IN_DURATION ? FLY_IN_DURATION : delay; view.animate().setDuration(duration).setInterpolator(new DecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { public void onAnimationStart(Animator anim) { view.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator anim) { view.clearAnimation(); view.setTranslationY(0f); performAnimation(); } }).translationY(0); } else { isAnimating = false; } }
From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false;//from www . j a v a 2 s .c o m break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; case ARROW_DIRECTION_END: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR; break; case ARROW_DIRECTION_START: default: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress)); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5 + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false;// w w w. j a va 2 s . c om break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; case ARROW_DIRECTION_END: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR; break; case ARROW_DIRECTION_START: default: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress)); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5f + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.android.leanlauncher.Workspace.java
private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean external, boolean scale) { // Now we animate the dragView, (ie. the widget or shortcut preview) into its final // location and size on the home screen. int spanX = info.spanX; int spanY = info.spanY; Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY); loc[0] = r.left;/*w ww . ja v a2 s . c o m*/ loc[1] = r.top; setFinalTransitionTransform(layout); float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true); resetTransitionTransform(layout); float dragViewScaleX; float dragViewScaleY; if (scale) { dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth(); dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight(); } else { dragViewScaleX = 1f; dragViewScaleY = 1f; } // The animation will scale the dragView about its center, so we need to center about // the final location. loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; scaleXY[0] = dragViewScaleX * cellLayoutScale; scaleXY[1] = dragViewScaleY * cellLayoutScale; }