List of usage examples for android.graphics Rect height
public final int height()
From source file:com.android.launcher3.CellLayout.java
private void markCellsForRect(Rect r, boolean[][] occupied, boolean value) { markCellsForView(r.left, r.top, r.width(), r.height(), occupied, value); }
From source file:com.hippo.widget.BothScrollView.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./*from w w w .ja v a 2s . c om*/ * @return The scroll delta. */ protected int computeScrollYDeltaToGetChildRectOnScreen(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.doubleTwist.drawerlib.ADrawerLayout.java
protected void layoutView(View v, int l, int t, int r, int b) { LayoutParams params = (LayoutParams) v.getLayoutParams(); Rect bounds = new Rect(); Rect boundsWithoutPeek = new Rect(); int gravity = params.gravity; switch (gravity) { case Gravity.RIGHT: if (DEBUG) Log.d(TAG, "gravity: right"); bounds.left = r - v.getMeasuredWidth() - mPeekSize.right; bounds.top = t;//from w ww . ja v a2s . co m bounds.right = r - mPeekSize.right; bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(mPeekSize.right, 0); mMinScrollX = -bounds.width(); break; case Gravity.TOP: if (DEBUG) Log.d(TAG, "gravity: top"); bounds.left = l; bounds.top = t + mPeekSize.top; bounds.right = v.getMeasuredWidth(); bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top; v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(0, -mPeekSize.top); mMaxScrollY = bounds.height(); break; case Gravity.BOTTOM: if (DEBUG) Log.d(TAG, "gravity: bottom"); bounds.left = l; bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom; bounds.right = l + v.getMeasuredWidth(); bounds.bottom = b - mPeekSize.bottom; v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(0, mPeekSize.bottom); mMinScrollY = -bounds.height(); break; case Gravity.LEFT: if (DEBUG) Log.d(TAG, "gravity: left"); bounds.left = l + mPeekSize.left; bounds.top = t; bounds.right = l + v.getMeasuredWidth() + mPeekSize.left; bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); mMaxScrollX = bounds.width(); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(-mPeekSize.left, 0); break; default: if (DEBUG) Log.d(TAG, "gravity: default"); bounds.left = l; bounds.top = t; bounds.right = l + v.getMeasuredWidth(); bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); break; } if (DEBUG) { Log.d(TAG, " == VIEW LAYOUT == " + v.toString()); Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom); } if (mLayoutBounds.containsKey(v)) mLayoutBounds.remove(v); mLayoutBounds.put(v, bounds); if (mLayoutBoundsWithoutPeek.containsKey(v)) mLayoutBoundsWithoutPeek.remove(v); mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek); }
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.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//from w ww.j a v a2 s . co m * The rect. * @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.launcher3.CellLayout.java
private void getDirectionVectorForDrop(int dragViewCenterX, int dragViewCenterY, int spanX, int spanY, View dragView, int[] resultDirection) { int[] targetDestination = new int[2]; findNearestArea(dragViewCenterX, dragViewCenterY, spanX, spanY, targetDestination); Rect dragRect = new Rect(); regionToRect(targetDestination[0], targetDestination[1], spanX, spanY, dragRect); dragRect.offset(dragViewCenterX - dragRect.centerX(), dragViewCenterY - dragRect.centerY()); Rect dropRegionRect = new Rect(); getViewsIntersectingRegion(targetDestination[0], targetDestination[1], spanX, spanY, dragView, dropRegionRect, mIntersectingViews); int dropRegionSpanX = dropRegionRect.width(); int dropRegionSpanY = dropRegionRect.height(); regionToRect(dropRegionRect.left, dropRegionRect.top, dropRegionRect.width(), dropRegionRect.height(), dropRegionRect);/*from ww w. j a va 2s . co m*/ int deltaX = (dropRegionRect.centerX() - dragViewCenterX) / spanX; int deltaY = (dropRegionRect.centerY() - dragViewCenterY) / spanY; if (dropRegionSpanX == mCountX || spanX == mCountX) { deltaX = 0; } if (dropRegionSpanY == mCountY || spanY == mCountY) { deltaY = 0; } if (deltaX == 0 && deltaY == 0) { // No idea what to do, give a random direction. resultDirection[0] = 1; resultDirection[1] = 0; } else { computeDirectionVector(deltaX, deltaY, resultDirection); } }
From source file:com.breakout.main.GameState.java
/** * If appropriate, draw a message in the middle of the screen. *///from ww w .j av a 2s. c o m void drawMessages() { if (mGameStatusMessageNum != TextResources.NO_MESSAGE) { TexturedAlignedRect msgBox = mGameStatusMessages; Rect boundsRect = mTextRes.getTextureRect(mGameStatusMessageNum); msgBox.setTextureCoords(boundsRect); /* * We need to scale the text to be easily readable. We have a basic choice to * make: do we want the message text to always be the same size (e.g. always at * 50 points), or should it be as large as it can be on the screen? * * For the mid-screen message, which is one or two words, we want it to be as large * as it can get. The expected strings will be much wider than they are tall, so * we scale the width of the bounding box to be a fixed percentage of the arena * width. This means the glyphs in "hello" will be much larger than they would be * in "hello, world", but that's exactly what we want. * * If we wanted consistent-size text, we'd need to change the way the TextResource * code works. It doesn't attempt to preserve the font metrics, and the bounding * boxes are based on the heights of the glyphs used in a given string (i.e. not * all possible glyphs in the font) so we just don't have enough information in * here to do that. */ float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / boundsRect.width(); msgBox.setScale(boundsRect.width() * scale, boundsRect.height() * scale); //Log.d(TAG, "drawing " + mGameStatusMessageNum); msgBox.draw(); } }
From source file:net.robotmedia.acv.ui.widget.OcrLayout.java
/** Update the location of the dictionary view based on the location of the capture box. */ @SuppressLint("NewApi") public void updateDicViewLocation() { if (this.captureBox != null) { DicViewLocation loc = this.determineDicViewLocation(); Rect rect = this.dicViewLocationToRect(loc); int width = rect.width(); int height = rect.height(); LayoutParams layoutParams = new LayoutParams(width, height); if (android.os.Build.VERSION.SDK_INT >= 11) { this.dicView.setLayoutParams(layoutParams); this.dicView.setX(rect.left); this.dicView.setY(rect.top); } else {/*from ww w . j a va 2 s . c o m*/ layoutParams.leftMargin = rect.left; layoutParams.topMargin = rect.top; this.dicView.setLayoutParams(layoutParams); } } }
From source file:com.marlonjones.voidlauncher.CellLayout.java
private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) { if (views.size() == 0) return true; boolean success = false; Rect boundingRect = new Rect(); // We construct a rect which represents the entire group of views passed in currentState.getBoundingRectForViews(views, boundingRect); // Mark the occupied state as false for the group of views we want to move. for (View v : views) { CellAndSpan c = currentState.map.get(v); mTmpOccupied.markCells(c, false); }/* w ww. j ava 2 s. c o m*/ GridOccupancy blockOccupied = new GridOccupancy(boundingRect.width(), boundingRect.height()); int top = boundingRect.top; int left = boundingRect.left; // We mark more precisely which parts of the bounding rect are truly occupied, allowing // for interlocking. for (View v : views) { CellAndSpan c = currentState.map.get(v); blockOccupied.markCells(c.cellX - left, c.cellY - top, c.spanX, c.spanY, true); } mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true); findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction, mTmpOccupied.cells, blockOccupied.cells, mTempLocation); // If we successfuly found a location by pushing the block of views, we commit it if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) { int deltaX = mTempLocation[0] - boundingRect.left; int deltaY = mTempLocation[1] - boundingRect.top; for (View v : views) { CellAndSpan c = currentState.map.get(v); c.cellX += deltaX; c.cellY += deltaY; } success = true; } // In either case, we set the occupied array as marked for the location of the views for (View v : views) { CellAndSpan c = currentState.map.get(v); mTmpOccupied.markCells(c, true); } return success; }
From source file:net.robotmedia.acv.ui.widget.OcrLayout.java
/** Returns true is text capture box orientation is vertical. */ private boolean isOrientationVertical(Rect captureBox) { if (this.textOrientation == this.TEXT_ORIENTATION_AUTO) { double aspectRatio = captureBox.width() / (double) captureBox.height(); if (aspectRatio < 2.0) { return true; } else {//from ww w .j a v a 2 s . co m return false; } } else { return (this.textOrientation == this.TEXT_ORIENTATION_VERTICAL); } }
From source file:cn.ismartv.tvrecyclerview.widget.StaggeredGridLayoutManager.java
@Override public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) { // we don't like it to wrap content in our non-scroll direction. final int width, height; final int horizontalPadding = getPaddingLeft() + getPaddingRight(); final int verticalPadding = getPaddingTop() + getPaddingBottom(); if (mOrientation == VERTICAL) { final int usedHeight = childrenBounds.height() + verticalPadding; height = chooseSize(hSpec, usedHeight, getMinimumHeight()); width = chooseSize(wSpec, mSizePerSpan * mSpanCount + horizontalPadding, getMinimumWidth()); } else {/* w ww . j a v a 2s . c o m*/ final int usedWidth = childrenBounds.width() + horizontalPadding; width = chooseSize(wSpec, usedWidth, getMinimumWidth()); height = chooseSize(hSpec, mSizePerSpan * mSpanCount + verticalPadding, getMinimumHeight()); } setMeasuredDimension(width, height); }