List of usage examples for android.graphics Rect height
public final int height()
From source file:piuk.blockchain.android.ui.zxing.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring }/*from w ww .ja va 2 s. co m*/ cameraManager.setFramingViewSize(new Point(this.getWidth(), this.getHeight())); Rect frame = cameraManager.getFramingRect(); if (frame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // 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 { // Draw a red "laser scanner" line through the middle to show decoding is active paint.setColor(laserColor); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; int middle = frame.height() / 2 + frame.top; canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); Rect previewFrame = cameraManager.getFramingRectInPreview(); assert previewFrame != null; 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.example.imac.animationsdemo.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically:/*from ww w. ja v a2 s. c o m*/ * <p/> * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image. final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); //? findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); //?? float deltaHeight = (startHeight - startBounds.height()) / 2; //? ??? 2 ? startBounds.top -= deltaHeight; // startBounds.bottom += deltaHeight; // } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). Log.e("==startBounds===", startBounds.left + " " + startBounds.top); AnimatorSet set = new AnimatorSet(); Log.e("=====", startBounds.left + " " + startBounds.top + " " + thumbView.getLeft() + " " + thumbView.getTop()); set.play(ObjectAnimator.ofFloat(expandedImageView, "X", startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, "Y", startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); // expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); // expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:com.codegarden.nativenavigation.JuceActivity.java
public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds(boundsF, true);/*w ww . jav a2s . c o m*/ matrix.mapRect(boundsF); boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max(1, bounds.height()); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); matrix.postTranslate(-bounds.left, -bounds.top); c.setMatrix(matrix); c.drawPath(p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded]; bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java
private boolean ensureVisible(@NonNull final View infoWindowContainer) { final int[] infoWindowLocation = new int[2]; infoWindowContainer.getLocationOnScreen(infoWindowLocation); final boolean visible = true; final Rect infoWindowRect = new Rect(); infoWindowContainer.getHitRect(infoWindowRect); final int[] parentPosition = new int[2]; parent.getLocationOnScreen(parentPosition); final Rect parentRect = new Rect(); parent.getGlobalVisibleRect(parentRect); infoWindowContainer.getGlobalVisibleRect(infoWindowRect); final int visibleWidth = infoWindowRect.width(); final int actualWidth = infoWindowContainer.getWidth(); final int visibleHeight = infoWindowRect.height(); final int actualHeight = infoWindowContainer.getHeight(); int scrollX = (visibleWidth - actualWidth); int scrollY = (visibleHeight - actualHeight); if (scrollX != 0) { if (infoWindowRect.left == parentRect.left) { scrollX = -Math.abs(scrollX); } else {/*from www.ja v a 2 s . c o m*/ scrollX = Math.abs(scrollX); } } if (scrollY != 0) { if (infoWindowRect.top < parentRect.top) { scrollY = Math.abs(scrollY); } else { scrollY = -Math.abs(scrollY); } } if (scrollX != 0 || scrollY != 0) { final CameraUpdate cameraUpdate = CameraUpdateFactory.scrollBy(scrollX, scrollY); googleMap.animateCamera(cameraUpdate, DURATION_CAMERA_ENSURE_VISIBLE_ANIMATION, null); } return visible; }
From source file:com.coco.draggablegridviewpager.DraggableGridViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int childCount = getChildCount(); mPageCount = (childCount + mPageSize - 1) / mPageSize; mGridWidth = (getWidth() - mPaddingLeft - mPaddingRight - (mColCount - 1) * mGridGap) / mColCount; mGridHeight = (getHeight() - mPaddingTop - mPaddingButtom - (mRowCount - 1) * mGridGap) / mRowCount; mGridWidth = mGridHeight = Math.min(mGridWidth, mGridHeight); mMaxOverScrollSize = mGridWidth / 2; mEdgeSize = mGridWidth / 2;/*w ww . ja va 2 s. co m*/ newPositions.clear(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final Rect rect = getRectByPosition(i); child.measure(MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY)); DEBUG_LOG("child.layout position=" + i + ", rect=" + rect); child.layout(rect.left, rect.top, rect.right, rect.bottom); newPositions.add(-1); } if (mCurItem > 0 && mCurItem < mPageCount) { final int curItem = mCurItem; mCurItem = 0; setCurrentItem(curItem); } }
From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java
/** * Given a focus rectangle, returns another rectangle that is placed at the beginning of the * row or column of the focused object, depending on the direction in which we are navigating. * * Example:/*from w w w .ja va2s. c o m*/ * <pre> * +---------+ * | | node=# * A| # | When direction=TraversalStrategy.SEARCH_FOCUS_RIGHT, then a rectangle A with * | | same width and height as node gets returned. * | | When direction=TraversalStrategy.SEARCH_FOCUS_UP, then a rectangle B with same * +---------+ width and height as node gets returned. * B * </pre> */ private void getSearchStartRect(AccessibilityNodeInfoCompat node, int direction, Rect rect) { Rect focusedRect = new Rect(); node.getBoundsInScreen(focusedRect); Rect rootBounds = new Rect(); mRoot.getBoundsInScreen(rootBounds); switch (direction) { case TraversalStrategy.SEARCH_FOCUS_LEFT: // Start from right and move leftwards. rect.set(rootBounds.right, focusedRect.top, rootBounds.right + focusedRect.width(), focusedRect.bottom); break; case TraversalStrategy.SEARCH_FOCUS_RIGHT: // Start from left and move rightwards. rect.set(rootBounds.left - focusedRect.width(), focusedRect.top, rootBounds.left, focusedRect.bottom); break; case TraversalStrategy.SEARCH_FOCUS_UP: // Start from bottom and move upwards. rect.set(focusedRect.left, rootBounds.bottom, focusedRect.right, rootBounds.bottom + focusedRect.height()); break; case TraversalStrategy.SEARCH_FOCUS_DOWN: // Start from top and move downwards. rect.set(focusedRect.left, rootBounds.top - focusedRect.height(), focusedRect.right, rootBounds.top); break; default: throw new IllegalArgumentException("direction must be a SearchDirection"); } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) return;/*from w w w . j av a 2 s.co m*/ canvas.save(); if (image != null) { if (mShowOriginalDirection == 0) { if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { mShowOriginalDirection = UNVEIL_VERTICAL; } else { mShowOriginalDirection = UNVEIL_HORIZONTAL; } } int px = 0; int py = 0; if (mShowOriginalDirection == UNVEIL_VERTICAL) { px = mImageBounds.width(); py = mTouch.y - mImageBounds.top; } else { px = mTouch.x - mImageBounds.left; py = mImageBounds.height(); if (showsOriginal) { px = mImageBounds.width(); } } Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py); if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { if (mTouchDown.x - mTouch.x > 0) { d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py); } } else { if (mTouchDown.y - mTouch.y > 0) { d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom); } } canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); if (mShowOriginalDirection == UNVEIL_VERTICAL) { canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint); } else { canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint); } Rect bounds = new Rect(); paint.setAntiAlias(true); paint.setTextSize(mOriginalTextSize); paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); paint.setColor(Color.WHITE); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private Animator getRevealAnimator(View source, int revealColor) { final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//from w w w. ja v a 2 s. c o m containerView.addView(revealView); final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f)); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS); animatorSet.playSequentially(revealAnimator, fadeAnimator); return revealAnimator; }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
public boolean updateSize() { boolean invalid = false; Rect visibleRect = new Rect(); getWindowVisibleDisplayFrame(visibleRect); int newHeight; int newWidth; int newTop;/*from w w w . ja v a2s . c o m*/ int newLeft; if (mConsoleScreen.isFullScreen()) { newTop = Math.min(getTop(), visibleRect.top); newHeight = visibleRect.bottom - newTop; } else { newTop = getTop(); newHeight = visibleRect.height(); } newWidth = visibleRect.width(); newLeft = visibleRect.left; if ((newWidth != mConsoleScreen.getVisibleWidth()) || (newHeight != mConsoleScreen.getVisibleHeight())) { mConsoleScreen.setVisibleWidth(newWidth); mConsoleScreen.setVisibleHeight(newHeight); try { updateSize(mConsoleScreen.getVisibleWidth(), mConsoleScreen.getVisibleHeight()); } catch (ArrayIndexOutOfBoundsException ignored) { } invalid = true; } if ((newLeft != mConsoleScreen.getLeftVisible()) || (newTop != mConsoleScreen.getTopVisible())) { mConsoleScreen.setLeftVisible(newLeft); mConsoleScreen.setTopVisible(newTop); invalid = true; } if (invalid) postInvalidate(); return invalid; }
From source file:com.android.hcframe.DraggableGridViewPager.java
private int getTargetByXY(int x, int y) { final int position = getPositionByXY(x, y); if (position < 0) { return -1; }/*from w w w. j a va 2 s. c om*/ final Rect r = getRectByPosition(position); final int page = position / mPageSize; r.inset(r.width() / 4, r.height() / 4); r.offset(-getWidth() * page, 0); if (!r.contains(x, y)) { return -1; } return position; }