private static boolean offsetDescendantRectToAncestorCoords(View descendant, View ancestor, Rect rect) { View view = descendant; ViewParent parent; do { parent = view.getParent(); if (!(parent instanceof ViewGroup)) { return false; } ((ViewGroup) parent).offsetDescendantRectToMyCoords(view, rect); view = (View) parent; } while (parent != ancestor); return true; }
/** * 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); }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); // View#offsetDescendantRectToMyCoords includes scroll offsets of the last child. // We need to reverse it here so that we get the rect of the view itself rather // than its content. rect.offset(child.getScrollX(), child.getScrollY()); } }
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); } }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); } }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); } }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); } }
protected Rect findLocationWithView(View view) { ViewGroup root = (ViewGroup) view.getParent(); Rect rect = new Rect(); root.offsetDescendantRectToMyCoords(view, rect); return rect; }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); // View#offsetDescendantRectToMyCoords includes scroll offsets of the last child. // We need to reverse it here so that we get the rect of the view itself rather // than its content. rect.offset(child.getScrollX(), child.getScrollY()); } }
public Rect findLocationWithView(View view) { ViewGroup root = (ViewGroup)getMainUpView().getParent(); Rect rect = new Rect(); root.offsetDescendantRectToMyCoords(view, rect); return rect; }
@Override public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) { parent.offsetDescendantRectToMyCoords(child, rect); // View#offsetDescendantRectToMyCoords includes scroll offsets of the last child. // We need to reverse it here so that we get the rect of the view itself rather // than its content. rect.offset(child.getScrollX(), child.getScrollY()); } }
public Rect findLocationWithView(View view) { ViewGroup root = (ViewGroup) getMainUpView().getParent(); Rect rect = new Rect(); root.offsetDescendantRectToMyCoords(view, rect); return rect; }
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()}; }
/** * 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; } } 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); }
Log.d(TAG, "getGlobalVisibleRectOfDecorView getDrawingRect:" + rect.toString()); ViewGroup rootView = (ViewGroup) this.getRootView(); rootView.offsetDescendantRectToMyCoords(view, rect); Log.d(TAG, "getGlobalVisibleRectOfDecorView offset:" + rect.toString());