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

The following examples show how to use android.view.View#getDrawingRect() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void initPeekHeight(DialogInterface dialog)
{
    if (dialog != null) {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null)
        {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            ViewGroup dialogLayout = (ViewGroup) bottomSheet.findViewById(R.id.dialog_lightmap_layout);
            View divider1 = bottomSheet.findViewById(R.id.info_time_lightmap);
            if (dialogLayout != null && divider1 != null)
            {
                Rect headerBounds = new Rect();
                divider1.getDrawingRect(headerBounds);
                dialogLayout.offsetDescendantRectToMyCoords(divider1, headerBounds);
                behavior.setPeekHeight(headerBounds.bottom + (int)getResources().getDimension(R.dimen.dialog_margin));

            } else {
                behavior.setPeekHeight(-1);
            }
        }
    }
}
 
Example 2
Source Project: android_9.0.0_r45   File: ScrollView.java    License: Apache License 2.0 6 votes vote down vote up
@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.
    if (isWithinDeltaOfScreen(currentFocused, 0, oldh)) {
        currentFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(currentFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(scrollDelta);
    }
}
 
Example 3
Source Project: Animer   File: AnScrollView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);

    if (scrollDelta != 0) {
        if(isVertScroll()){
            scrollBy(0, scrollDelta);
        }
        else {
            scrollBy(scrollDelta, 0);
        }
    }
}
 
Example 4
Source Project: Nimingban   File: BothScrollView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollXDelta = computeScrollXDeltaToGetChildRectOnScreen(mTempRect);
    int scrollYDelta = computeScrollYDeltaToGetChildRectOnScreen(mTempRect);

    if (scrollXDelta != 0 && scrollYDelta != 0) {
        scrollBy(scrollXDelta, scrollYDelta);
    }
}
 
Example 5
/**
  * 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 6
@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 7
/**
 * @return whether the descendant of this scroll view is within delta pixels
 * of being on the screen.
 */
private boolean isWithinDeltaOfScreen(@NonNull View descendant, int delta, int height) {
    descendant.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(descendant, mTempRect);

    return ((mTempRect.bottom + delta) >= getScrollY()) && ((mTempRect.top - delta) <= (getScrollY() + height));
}
 
Example 8
private void scrollToChild(View child) {
    child.getDrawingRect(mTempRect);

    /* Offset from child's local coordinates to ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    if (scrollDelta != 0) {
        this.scrollBy(scrollDelta, 0);
    }
}
 
Example 9
@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 10
Source Project: android_9.0.0_r45   File: ScrollView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);

    if (scrollDelta != 0) {
        scrollBy(0, scrollDelta);
    }
}
 
Example 11
Source Project: Animer   File: AnScrollView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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 value) {
    descendant.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(descendant, mTempRect);

    if(isVertScroll()){
        return (mTempRect.bottom + delta) >= getScrollY()  && (mTempRect.top - delta) <= (getScrollY() + value);
    }
    else {
        return (mTempRect.right + delta) >= getScrollX()  && (mTempRect.left - delta) <= (getScrollX() + value);
    }
}
 
Example 12
Source Project: AndroidSweetSheet   File: Blur.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 从View 中生成 BitMap
     *
     * @param view
     * @return
     */
    public static Bitmap convertFromView(View view) {

        Bitmap bitmap=null;
        Rect rect = new Rect();
        view.getDrawingRect(rect);
        view.destroyDrawingCache();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache(true);
        bitmap = view.getDrawingCache(true);


            /**
             * After rotation, the DecorView has no height and no width. Therefore
             * .getDrawingCache() return null. That's why we  have to force measure and layout.
             */
            if (bitmap == null) {
                view.measure(
                        View.MeasureSpec.makeMeasureSpec(rect.width(), View.MeasureSpec.EXACTLY),
                        View.MeasureSpec.makeMeasureSpec(rect.height(), View.MeasureSpec.EXACTLY)
                );
                view.layout(0, 0, view.getMeasuredWidth(),
                        view.getMeasuredHeight());
                view.destroyDrawingCache();
                view.setDrawingCacheEnabled(true);
                view.buildDrawingCache(true);
                bitmap = view.getDrawingCache(true);
            }

//        view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
//                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
//        view.buildDrawingCache();
//        Bitmap bitmap = view.getDrawingCache();

        return bitmap;
    }
 
Example 13
Source Project: imsdk-android   File: TwoDScrollView.java    License: MIT License 5 votes vote down vote up
/**
  * 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 14
Source Project: recent-images   File: TwoWayGridView.java    License: MIT License 5 votes vote down vote up
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
	super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);

	int closestChildIndex = -1;
	if (gainFocus && previouslyFocusedRect != null) {
		previouslyFocusedRect.offset(getScrollX(), getScrollY());

		// figure out which item should be selected based on previously
		// focused rect
		Rect otherRect = mTempRect;
		int minDistance = Integer.MAX_VALUE;
		final int childCount = getChildCount();
		for (int i = 0; i < childCount; i++) {
			// only consider view's on appropriate edge of grid
			if (!mGridBuilder.isCandidateSelection(i, direction)) {
				continue;
			}

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

			if (distance < minDistance) {
				minDistance = distance;
				closestChildIndex = i;
			}
		}
	}

	if (closestChildIndex >= 0) {
		setSelection(closestChildIndex + mFirstPosition);
	} else {
		requestLayout();
	}
}
 
Example 15
Source Project: letv   File: HListView.java    License: Apache License 2.0 5 votes vote down vote up
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 16
private void scrollToChild(View child) {
    child.getDrawingRect(mTempRect);

    /* Offset from child's local coordinates to ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    if (scrollDelta != 0) {
        this.scrollBy(scrollDelta, 0);
    }
}
 
Example 17
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);
}
 
Example 18
Source Project: CircularReveal   File: MainActivity.java    License: MIT License 4 votes vote down vote up
@OnClick(R.id.activator) void activateAwareMotion(View target) {
  // Cancel all concurrent events on view
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    target.cancelPendingInputEvents();
  }
  target.setEnabled(false);

  // Coordinates of circle initial point
  final ViewGroup parent = (ViewGroup) activatorMask.getParent();
  final Rect bounds = new Rect();
  final Rect maskBounds = new Rect();

  target.getDrawingRect(bounds);
  activatorMask.getDrawingRect(maskBounds);
  parent.offsetDescendantRectToMyCoords(target, bounds);
  parent.offsetDescendantRectToMyCoords(activatorMask, maskBounds);

  // Put Mask view at circle 8initial points
  maskElevation = activatorMask.getCardElevation();
  activatorMask.setCardElevation(0);
  activatorMask.setVisibility(View.VISIBLE);
  activatorMask.setX(bounds.left - maskBounds.centerX());
  activatorMask.setY(bounds.top - maskBounds.centerY());

  circlesLine.setVisibility(View.INVISIBLE);

  final int cX = maskBounds.centerX();
  final int cY = maskBounds.centerY();

  final float endRadius = (float) Math.hypot(maskBounds.width() * .5f, maskBounds.height() * .5f);

  Animator circularReveal =
      ViewAnimationUtils.createCircularReveal(activatorMask, cX, cY, target.getWidth() / 2,
          endRadius, View.LAYER_TYPE_HARDWARE);

  final float c0X = bounds.centerX() - maskBounds.centerX();
  final float c0Y = bounds.centerY() - maskBounds.centerY();

  AnimatorPath path = new AnimatorPath();
  path.moveTo(c0X, c0Y);
  path.curveTo(c0X, c0Y, 0, c0Y, 0, 0);

  ObjectAnimator pathAnimator = ObjectAnimator.ofObject(this, "maskLocation", new PathEvaluator(),
      path.getPoints().toArray());

  AnimatorSet set = new AnimatorSet();
  set.playTogether(circularReveal, pathAnimator);
  set.setInterpolator(new FastOutSlowInInterpolator());
  set.setDuration(SLOW_DURATION);
  set.addListener(new AnimatorListenerAdapter() {
    @Override public void onAnimationEnd(Animator animation) {
      executeCardsSequentialAnimation();
      activatorMask.setCardElevation(maskElevation);
    }
  });
  set.start();
}
 
Example 19
Source Project: CircularReveal   File: MainActivity.java    License: MIT License 4 votes vote down vote up
@OnClick(R.id.reset) void resetUi(View resetCard) {
  cardsLine.setVisibility(View.INVISIBLE);

  final View target = ButterKnife.findById(this, R.id.activator);

  // Coordinates of circle initial point
  final ViewGroup parent = (ViewGroup) activatorMask.getParent();
  final Rect bounds = new Rect();
  final Rect maskBounds = new Rect();

  target.getDrawingRect(bounds);
  activatorMask.getDrawingRect(maskBounds);
  parent.offsetDescendantRectToMyCoords(target, bounds);
  parent.offsetDescendantRectToMyCoords(activatorMask, maskBounds);

  maskElevation = activatorMask.getCardElevation();
  activatorMask.setCardElevation(0);

  final int cX = maskBounds.centerX();
  final int cY = maskBounds.centerY();

  final Animator circularReveal = ViewAnimationUtils.createCircularReveal(activatorMask, cX, cY,
      (float) Math.hypot(maskBounds.width() * .5f, maskBounds.height() * .5f),
      target.getWidth() / 2f, View.LAYER_TYPE_HARDWARE);

  final float c0X = bounds.centerX() - maskBounds.centerX();
  final float c0Y = bounds.centerY() - maskBounds.centerY();

  AnimatorPath path = new AnimatorPath();
  path.moveTo(0, 0);
  path.curveTo(0, 0, 0, c0Y, c0X, c0Y);

  ObjectAnimator pathAnimator = ObjectAnimator.ofObject(this, "maskLocation", new PathEvaluator(),
      path.getPoints().toArray());

  AnimatorSet set = new AnimatorSet();
  set.playTogether(circularReveal, pathAnimator);
  set.setInterpolator(new FastOutSlowInInterpolator());
  set.setDuration(SLOW_DURATION);
  set.addListener(new AnimatorListenerAdapter() {
    @Override public void onAnimationEnd(Animator animation) {
      activatorMask.setCardElevation(maskElevation);
      activatorMask.setVisibility(View.INVISIBLE);

      circlesLine.setVisibility(View.VISIBLE);
      executeCirclesDropDown();
      target.setEnabled(true);
    }
  });
  set.start();
}
 
Example 20
Source Project: GravityBox   File: TouchInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}