Java Code Examples for android.view.View.getDrawingRect()

The following are Jave code examples for showing how to use getDrawingRect() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RNLearn_Project1   File: ReactClippingViewGroupHelper.java   Source Code and License Vote up 8 votes
/**
 * Can be used by view that support {@code removeClippedSubviews} property to calculate area that
 * given {@param view} should be clipped to based on the clipping rectangle of it's parent in
 * case when parent is also set to clip it's children.
 *
 * @param view view that we want to calculate clipping rect for
 * @param outputRect where the calculated rectangle will be written
 */
public static void calculateClippingRect(View view, Rect outputRect) {
  ViewParent parent = view.getParent();
  if (parent == null) {
    outputRect.setEmpty();
    return;
  } else if (parent instanceof ReactClippingViewGroup) {
    ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent;
    if (clippingViewGroup.getRemoveClippedSubviews()) {
      clippingViewGroup.getClippingRect(sHelperRect);
      // Intersect the view with the parent's rectangle
      // This will result in the overlap with coordinates in the parent space
      if (!sHelperRect.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
        outputRect.setEmpty();
        return;
      }
      // Now we move the coordinates to the View's coordinate space
      sHelperRect.offset(-view.getLeft(), -view.getTop());
      sHelperRect.offset(view.getScrollX(), view.getScrollY());
      outputRect.set(sHelperRect);
      return;
    }
  }
  view.getDrawingRect(outputRect);
}
 
Example 2
Project: exciting-app   File: HListView.java   Source Code and License Vote up 7 votes
/**
 * Determine how much we need to scroll in order to get newFocus in view.
 * 
 * @param direction
 *            either {@link android.view.View#FOCUS_UP} or
 *            {@link android.view.View#FOCUS_DOWN}.
 * @param newFocus
 *            The view that would take focus.
 * @param positionOfNewFocus
 *            The position of the list item containing newFocus
 * @return The amount to scroll. Note: this is always positive! Direction
 *         needs to be taken into account when actually scrolling.
 */
private int amountToScrollToNewFocus(int direction, View newFocus, int positionOfNewFocus) {
	int amountToScroll = 0;
	newFocus.getDrawingRect(mTempRect);
	offsetDescendantRectToMyCoords(newFocus, mTempRect);
	if (direction == View.FOCUS_UP) {
		if (mTempRect.left < mListPadding.left) {
			amountToScroll = mListPadding.left - mTempRect.left;
			if (positionOfNewFocus > 0) {
				amountToScroll += getArrowScrollPreviewLength();
			}
		}
	} else {
		final int listRight = getWidth() - mListPadding.right;
		if (mTempRect.bottom > listRight) {
			amountToScroll = mTempRect.right - listRight;
			if (positionOfNewFocus < mItemCount - 1) {
				amountToScroll += getArrowScrollPreviewLength();
			}
		}
	}
	return amountToScroll;
}
 
Example 3
Project: javaide   File: TwoDScrollView.java   Source Code and License Vote up 6 votes
@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 the currently-focused view was visible on the screen when the
    // screen was at the old height, then scroll the screen to make that
    // view visible with the new screen height.
    currentFocused.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(currentFocused, mTempRect);
    int scrollDeltaX = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    int scrollDeltaY = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    doScroll(scrollDeltaX, scrollDeltaY);
}
 
Example 4
Project: RNLearn_Project1   File: ReactClippingViewGroupHelper.java   Source Code and License Vote up 6 votes
/**
 * Can be used by view that support {@code removeClippedSubviews} property to calculate area that
 * given {@param view} should be clipped to based on the clipping rectangle of it's parent in
 * case when parent is also set to clip it's children.
 *
 * @param view view that we want to calculate clipping rect for
 * @param outputRect where the calculated rectangle will be written
 */
public static void calculateClippingRect(View view, Rect outputRect) {
  ViewParent parent = view.getParent();
  if (parent == null) {
    outputRect.setEmpty();
    return;
  } else if (parent instanceof ReactClippingViewGroup) {
    ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent;
    if (clippingViewGroup.getRemoveClippedSubviews()) {
      clippingViewGroup.getClippingRect(sHelperRect);
      // Intersect the view with the parent's rectangle
      // This will result in the overlap with coordinates in the parent space
      if (!sHelperRect.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
        outputRect.setEmpty();
        return;
      }
      // Now we move the coordinates to the View's coordinate space
      sHelperRect.offset(-view.getLeft(), -view.getTop());
      sHelperRect.offset(view.getScrollX(), view.getScrollY());
      outputRect.set(sHelperRect);
      return;
    }
  }
  view.getDrawingRect(outputRect);
}
 
Example 5
Project: LaunchEnr   File: ShortcutAndWidgetContainer.java   Source Code and License Vote up 5 votes
@Override
public void requestChildFocus(View child, View focused) {
    super.requestChildFocus(child, focused);
    if (child != null) {
        Rect r = new Rect();
        child.getDrawingRect(r);
        requestRectangleOnScreen(r);
    }
}
 
Example 6
Project: ticket-view   File: TicketView.java   Source Code and License Vote up 5 votes
public void setAnchor(View view) {
    Rect rect = new Rect();
    //get view's visible bounds
    view.getDrawingRect(rect);
    //calculate the relative coordinates to parent
    offsetDescendantRectToMyCoords(view, rect);
    if (orientation == Orientation.HORIZONTAL) {
        holePosition = rect.left - holeRadius;
    } else {
        holePosition = rect.bottom + holeRadius;
    }
    postInvalidate();
}
 
Example 7
Project: FlickLauncher   File: ShortcutAndWidgetContainer.java   Source Code and License Vote up 5 votes
@Override
public void requestChildFocus(View child, View focused) {
    super.requestChildFocus(child, focused);
    if (child != null) {
        Rect r = new Rect();
        child.getDrawingRect(r);
        requestRectangleOnScreen(r);
    }
}
 
Example 8
Project: letv   File: HListView.java   Source Code and License Vote up 5 votes
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    ListAdapter adapter = this.mAdapter;
    int closetChildIndex = -1;
    int closestChildLeft = 0;
    if (!(adapter == null || !gainFocus || previouslyFocusedRect == null)) {
        previouslyFocusedRect.offset(getScrollX(), getScrollY());
        if (adapter.getCount() < getChildCount() + this.mFirstPosition) {
            this.mLayoutMode = 0;
            layoutChildren();
        }
        Rect otherRect = this.mTempRect;
        int minDistance = Integer.MAX_VALUE;
        int childCount = getChildCount();
        int firstPosition = this.mFirstPosition;
        for (int i = 0; i < childCount; i++) {
            if (adapter.isEnabled(firstPosition + i)) {
                View other = getChildAt(i);
                other.getDrawingRect(otherRect);
                offsetDescendantRectToMyCoords(other, otherRect);
                int distance = AbsHListView.getDistance(previouslyFocusedRect, otherRect, direction);
                if (distance < minDistance) {
                    minDistance = distance;
                    closetChildIndex = i;
                    closestChildLeft = other.getLeft();
                }
            }
        }
    }
    if (closetChildIndex >= 0) {
        setSelectionFromLeft(this.mFirstPosition + closetChildIndex, closestChildLeft);
    } else {
        requestLayout();
    }
}
 
Example 9
Project: letv   File: NestedScrollView.java   Source Code and License Vote up 5 votes
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    }
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    int maxJump = getMaxScrollAmount();
    if (nextFocused == null || !isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        int scrollDelta = maxJump;
        if (direction == 33 && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == 130 && getChildCount() > 0) {
            int daBottom = getChildAt(0).getBottom();
            int screenBottom = (getScrollY() + getHeight()) - getPaddingBottom();
            if (daBottom - screenBottom < maxJump) {
                scrollDelta = daBottom - screenBottom;
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        int i;
        if (direction == 130) {
            i = scrollDelta;
        } else {
            i = -scrollDelta;
        }
        doScrollY(i);
    } else {
        nextFocused.getDrawingRect(this.mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, this.mTempRect);
        doScrollY(computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
        nextFocused.requestFocus(direction);
    }
    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        int descendantFocusability = getDescendantFocusability();
        setDescendantFocusability(131072);
        requestFocus();
        setDescendantFocusability(descendantFocusability);
    }
    return true;
}
 
Example 10
Project: letv   File: NestedScrollView.java   Source Code and License Vote up 5 votes
private void scrollToChild(View child) {
    child.getDrawingRect(this.mTempRect);
    offsetDescendantRectToMyCoords(child, this.mTempRect);
    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(this.mTempRect);
    if (scrollDelta != 0) {
        scrollBy(0, scrollDelta);
    }
}
 
Example 11
Project: letv   File: NestedScrollView.java   Source Code and License Vote up 5 votes
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    View currentFocused = findFocus();
    if (currentFocused != null && this != currentFocused && isWithinDeltaOfScreen(currentFocused, 0, oldh)) {
        currentFocused.getDrawingRect(this.mTempRect);
        offsetDescendantRectToMyCoords(currentFocused, this.mTempRect);
        doScrollY(computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
    }
}
 
Example 12
Project: javaide   File: TwoDScrollView.java   Source Code and License Vote up 5 votes
/**
  * Scrolls the view to the given child.
  *
  * @param child the View to scroll to
  */
 private void scrollToChild(View child) {
     child.getDrawingRect(mTempRect);
/* Offset from child's local coordinates to TwoDScrollView coordinates */
     offsetDescendantRectToMyCoords(child, mTempRect);
     int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
     if (scrollDelta != 0) {
         scrollBy(0, scrollDelta);
     }
 }
 
Example 13
Project: boohee_v5.6   File: NestedScrollView.java   Source Code and License Vote up 5 votes
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    }
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    int maxJump = getMaxScrollAmount();
    if (nextFocused == null || !isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        int scrollDelta = maxJump;
        if (direction == 33 && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == 130 && getChildCount() > 0) {
            int daBottom = getChildAt(0).getBottom();
            int screenBottom = (getScrollY() + getHeight()) - getPaddingBottom();
            if (daBottom - screenBottom < maxJump) {
                scrollDelta = daBottom - screenBottom;
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        int i;
        if (direction == 130) {
            i = scrollDelta;
        } else {
            i = -scrollDelta;
        }
        doScrollY(i);
    } else {
        nextFocused.getDrawingRect(this.mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, this.mTempRect);
        doScrollY(computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
        nextFocused.requestFocus(direction);
    }
    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        int descendantFocusability = getDescendantFocusability();
        setDescendantFocusability(131072);
        requestFocus();
        setDescendantFocusability(descendantFocusability);
    }
    return true;
}
 
Example 14
Project: boohee_v5.6   File: NestedScrollView.java   Source Code and License Vote up 5 votes
private void scrollToChild(View child) {
    child.getDrawingRect(this.mTempRect);
    offsetDescendantRectToMyCoords(child, this.mTempRect);
    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(this.mTempRect);
    if (scrollDelta != 0) {
        scrollBy(0, scrollDelta);
    }
}
 
Example 15
Project: boohee_v5.6   File: NestedScrollView.java   Source Code and License Vote up 5 votes
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    View currentFocused = findFocus();
    if (currentFocused != null && this != currentFocused && isWithinDeltaOfScreen(currentFocused, 0, oldh)) {
        currentFocused.getDrawingRect(this.mTempRect);
        offsetDescendantRectToMyCoords(currentFocused, this.mTempRect);
        doScrollY(computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
    }
}
 
Example 16
Project: SimpleUILauncher   File: ShortcutAndWidgetContainer.java   Source Code and License Vote up 5 votes
@Override
public void requestChildFocus(View child, View focused) {
    super.requestChildFocus(child, focused);
    if (child != null) {
        Rect r = new Rect();
        child.getDrawingRect(r);
        requestRectangleOnScreen(r);
    }
}
 
Example 17
Project: letv   File: NestedScrollView.java   Source Code and License Vote up 4 votes
private boolean isWithinDeltaOfScreen(View descendant, int delta, int height) {
    descendant.getDrawingRect(this.mTempRect);
    offsetDescendantRectToMyCoords(descendant, this.mTempRect);
    return this.mTempRect.bottom + delta >= getScrollY() && this.mTempRect.top - delta <= getScrollY() + height;
}
 
Example 18
Project: exciting-app   File: HListView.java   Source Code and License Vote up 4 votes
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
	super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);

	final ListAdapter adapter = mAdapter;
	int closetChildIndex = -1;
	int closestChildLeft = 0;
	if (adapter != null && gainFocus && previouslyFocusedRect != null) {
		previouslyFocusedRect.offset(getScrollX(), getScrollY());

		// Don't cache the result of getChildCount or mFirstPosition here,
		// it could change in layoutChildren.
		if (adapter.getCount() < getChildCount() + mFirstPosition) {
			mLayoutMode = LAYOUT_NORMAL;
			layoutChildren();
		}

		// figure out which item should be selected based on previously
		// focused rect
		Rect otherRect = mTempRect;
		int minDistance = Integer.MAX_VALUE;
		final int childCount = getChildCount();
		final int firstPosition = mFirstPosition;

		for (int i = 0; i < childCount; i++) {
			// only consider selectable views
			if (!adapter.isEnabled(firstPosition + i)) {
				continue;
			}

			View other = getChildAt(i);
			other.getDrawingRect(otherRect);
			offsetDescendantRectToMyCoords(other, otherRect);
			int distance = getDistance(previouslyFocusedRect, otherRect, direction);

			if (distance < minDistance) {
				minDistance = distance;
				closetChildIndex = i;
				closestChildLeft = other.getLeft();
			}
		}
	}

	if (closetChildIndex >= 0) {
		setSelectionFromLeft(closetChildIndex + mFirstPosition, closestChildLeft);
	} else {
		requestLayout();
	}
}
 
Example 19
Project: GravityBox   File: TouchInterceptor.java   Source Code and License Vote up 4 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mDragListener != null || mDropListener != null) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                int x = (int) ev.getX();
                int y = (int) ev.getY();
                int itemnum = pointToPosition(x, y);
                if (itemnum == AdapterView.INVALID_POSITION) {
                    break;
                }
                ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
                mDragPoint = y - item.getTop();
                mCoordOffset = ((int) ev.getRawY()) - y;
                View dragger = item.findViewById(R.id.grabber);
                Rect r = mTempRect;
                dragger.getDrawingRect(r);
                if (shouldStartDragging(x, r.width())) {
                    // Fix x position while dragging
                    int[] itemPos = new int[2];
                    item.getLocationOnScreen(itemPos);

                    item.setDrawingCacheEnabled(true);
                    // Create a copy of the drawing cache so that it does
                    // not get recycled
                    // by the framework when the list tries to clean up
                    // memory
                    Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
                    startDragging(bitmap, itemPos[0], y);
                    mDragPos = itemnum;
                    mFirstDragPos = mDragPos;
                    mHeight = getHeight();
                    int touchSlop = mTouchSlop;
                    mUpperBound = Math.min(y - touchSlop, mHeight / 3);
                    mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
                    return false;
                }
                stopDragging();
                break;
        }
    }
    return super.onInterceptTouchEvent(ev);
}
 
Example 20
Project: boohee_v5.6   File: NestedScrollView.java   Source Code and License Vote up 4 votes
private boolean isWithinDeltaOfScreen(View descendant, int delta, int height) {
    descendant.getDrawingRect(this.mTempRect);
    offsetDescendantRectToMyCoords(descendant, this.mTempRect);
    return this.mTempRect.bottom + delta >= getScrollY() && this.mTempRect.top - delta <= getScrollY() + height;
}