Rect outRect = new Rect(); int[] location = new int[2]; private boolean isViewInBounds(View view, int x, int y){ view.getDrawingRect(outRect); view.getLocationOnScreen(location); outRect.offset(location[0], location[1]); return outRect.contains(x, y); }
public static void drawMeasures(View view, Canvas canvas, Integer measureCount) { final int color; switch (measureCount) { case 0: case 1: color = NO_OVERMEASURE; break; case 2: color = OVERMEASURE_1x; break; case 3: color = OVERMEASURE_2x; break; case 4: color = OVERMEASURE_3x; break; default: color = OVERMEASURE_4x; break; } if (measureCount > 1) { final int tintColor = Color.argb(150, Color.red(color), Color.green(color), Color.blue(color)); Rect rect = new Rect(); view.getDrawingRect(rect); Paint paint = new Paint(); paint.setColor(tintColor); canvas.drawRect(rect, paint); } }
} else { Rect viewDrawingRect = new Rect(); viewContext.getDrawingRect(viewDrawingRect);
/** * setup matrix to draw starting from blurView's position */ private void setupInternalCanvasMatrix() { blurView.getDrawingRect(relativeViewBounds); if (shouldTryToOffsetCoords) { try { rootView.offsetDescendantRectToMyCoords(blurView, relativeViewBounds); } catch (IllegalArgumentException e) { // BlurView is not a child of the rootView (i.e. it's in Dialog) // Fallback to regular coordinates system shouldTryToOffsetCoords = false; } } else { blurView.getLocationInWindow(locationInWindow); relativeViewBounds.offset(locationInWindow[0], locationInWindow[1]); } float scaleFactorX = scaleFactor * roundingWidthScaleFactor; float scaleFactorY = scaleFactor * roundingHeightScaleFactor; float scaledLeftPosition = -relativeViewBounds.left / scaleFactorX; float scaledTopPosition = -relativeViewBounds.top / scaleFactorY; float scaledTranslationX = blurView.getTranslationX() / scaleFactorX; float scaledTranslationY = blurView.getTranslationY() / scaleFactorY; internalCanvas.translate(scaledLeftPosition - scaledTranslationX, scaledTopPosition - scaledTranslationY); internalCanvas.scale(1f / scaleFactorX, 1f / scaleFactorY); }
other.getDrawingRect(otherRect); offsetDescendantRectToMyCoords(other, otherRect); int distance = getDistance(previouslyFocusedRect, otherRect, direction);
private boolean isViewInBounds(View view, int x, int y) { view.getDrawingRect(outRect); view.getLocationOnScreen(location); outRect.offset(location[0], location[1]); return outRect.contains(x, y); }
/** Mimic {@link ToroUtil#visibleAreaOffset(ToroPlayer, ViewParent)} */ private static float visibleAreaOffset(@NonNull View playerView) { Rect drawRect = new Rect(); playerView.getDrawingRect(drawRect); int drawArea = drawRect.width() * drawRect.height(); Rect playerRect = new Rect(); boolean visible = playerView.getGlobalVisibleRect(playerRect, new Point()); float offset = 0.f; if (visible && drawArea > 0) { int visibleArea = playerRect.height() * playerRect.width(); offset = visibleArea / (float) drawArea; } return offset; }
} else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) {
} else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) {
private void scrollToChild(View child) { child.getDrawingRect(mTempRect); offsetDescendantRectToMyCoords(child, mTempRect); int deltaX = computeScrollXDeltaToGetChildRectOnScreen(mTempRect); int deltaY = computeScrollYDeltaToGetChildRectOnScreen(mTempRect); if (deltaY != 0 || deltaX != 0) { scrollBy(deltaX, deltaY); } }
private boolean isWithinDeltaOfScreen(View descendant, int delta, int width, int height) { descendant.getDrawingRect(mTempRect); offsetDescendantRectToMyCoords(descendant, mTempRect); return ((mTempRect.bottom + delta) >= getScrollY() && (mTempRect.top - delta) <= (getScrollY() + height)) && ((mTempRect.right + delta) >= getScrollX() && (mTempRect.left - delta) <= (getScrollX() + width)); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); View currentFocused = findFocus(); if (null == currentFocused || this == currentFocused) { return; } if (isWithinDeltaOfScreen(currentFocused, 0, oldw, oldh)) { currentFocused.getDrawingRect(mTempRect); offsetDescendantRectToMyCoords(currentFocused, mTempRect); int deltaX = computeScrollXDeltaToGetChildRectOnScreen(mTempRect); int deltaY = computeScrollYDeltaToGetChildRectOnScreen(mTempRect); performScrollBy(deltaX, deltaY); } }
private boolean inViewBounds(View view, int x, int y){ view.getDrawingRect(outRect); view.getLocationOnScreen(location); outRect.offset(location[0], location[1]); return outRect.contains(x, y); }
@Override public void requestChildFocus(View child, View focused) { super.requestChildFocus(child, focused); if (child != null) { Rect r = new Rect(); child.getDrawingRect(r); requestRectangleOnScreen(r); } }
@Override public void requestChildFocus(View child, View focused) { super.requestChildFocus(child, focused); if (child != null) { Rect r = new Rect(); child.getDrawingRect(r); requestRectangleOnScreen(r); } }
@Override public void requestChildFocus(View child, View focused) { super.requestChildFocus(child, focused); if (child != null) { Rect r = new Rect(); child.getDrawingRect(r); requestRectangleOnScreen(r); } }
@Override public void requestChildFocus(View child, View focused) { super.requestChildFocus(child, focused); if (child != null) { Rect r = new Rect(); child.getDrawingRect(r); requestRectangleOnScreen(r); } }
private int[] getCenterClickedView(ViewGroup from) { Rect clickedViewRect = new Rect(); clickedView.getDrawingRect(clickedViewRect); from.offsetDescendantRectToMyCoords(clickedView, clickedViewRect); return new int[] {(int) clickedViewRect.exactCenterX(), (int) clickedViewRect.exactCenterY()}; }
/** * @return whether the descendant of this scroll view is within delta * pixels of being on the screen. */ private boolean isWithinDeltaOfScreen(View descendant, int delta, int height) { descendant.getDrawingRect(mTempRect); offsetDescendantRectToMyCoords(descendant, mTempRect); return (mTempRect.bottom + delta) >= getScrollY() && (mTempRect.top - delta) <= (getScrollY() + height); }
/** * @return whether the descendant of this scroll view is within delta pixels * of being on the screen. */ private boolean isWithinDeltaOfScreenV(View descendant, int delta, int height) { descendant.getDrawingRect(mTempRect); offsetDescendantRectToMyCoords(descendant, mTempRect); return (mTempRect.bottom + delta) >= getScrollY() && (mTempRect.top - delta) <= (getScrollY() + height); }