Here are the examples of the java api class android.graphics.Rect taken from open source projects.
1. DrawUtil#drawPadding()
Project: ViewInspector
File: DrawUtil.java
File: DrawUtil.java
public static void drawPadding(View view, Canvas canvas) { int width = view.getWidth(); int height = view.getHeight(); int lPad = view.getPaddingLeft(); int tPad = view.getPaddingTop(); int rPad = view.getPaddingRight(); int bPad = view.getPaddingBottom(); Rect lRect = new Rect(0, 0, lPad, height); Rect tRect = new Rect(lPad, 0, width - rPad, tPad); Rect rRect = new Rect(width - rPad, 0, width, height); Rect bRect = new Rect(lPad, height - bPad, width - rPad, height); Paint paint = new Paint(); paint.setColor(PADDING_COLOR); canvas.drawRect(lRect, paint); canvas.drawRect(tRect, paint); canvas.drawRect(rRect, paint); canvas.drawRect(bRect, paint); }
2. ViewUtils#viewsIntersect()
Project: plaid
File: ViewUtils.java
File: ViewUtils.java
/** * Determines if two views intersect in the window. */ public static boolean viewsIntersect(View view1, View view2) { if (view1 == null || view2 == null) return false; final int[] view1Loc = new int[2]; view1.getLocationOnScreen(view1Loc); final Rect view1Rect = new Rect(view1Loc[0], view1Loc[1], view1Loc[0] + view1.getWidth(), view1Loc[1] + view1.getHeight()); int[] view2Loc = new int[2]; view2.getLocationOnScreen(view2Loc); final Rect view2Rect = new Rect(view2Loc[0], view2Loc[1], view2Loc[0] + view2.getWidth(), view2Loc[1] + view2.getHeight()); return view1Rect.intersect(view2Rect); }
3. CropHighlightView#moveBy()
Project: Book-Catalogue
File: CropHighlightView.java
File: CropHighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
4. HighlightView#moveBy()
Project: bither-android
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
5. ObjectPropertyAnimActivity#startRectAnimation()
Project: AndroidStudyDemo
File: ObjectPropertyAnimActivity.java
File: ObjectPropertyAnimActivity.java
public void startRectAnimation(View v) { Rect local = new Rect(); mShowAnimIV.getLocalVisibleRect(local); Rect from = new Rect(local); Rect to = new Rect(local); from.right = from.left + local.width() / 4; from.bottom = from.top + local.height() / 2; to.left = to.right - local.width() / 2; to.top = to.bottom - local.height() / 4; if (Build.VERSION.SDK_INT >= 18) { ObjectAnimator objectAnimator = ObjectAnimator.ofObject(mShowAnimIV, "clipBounds", new RectEvaluator(), from, to); objectAnimator.setDuration(C.Int.ANIM_DURATION * 4); objectAnimator.start(); } }
6. HighlightView#moveBy()
Project: Android-RTEditor
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
7. PagerTabStrip#updateTextPositions()
Project: UltimateAndroid
File: PagerTabStrip.java
File: PagerTabStrip.java
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); }
8. HighlightView#moveBy()
Project: UltimateAndroid
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectangle by (dx, dy) in image space void moveBy(float dx, float dy) { Rect invalRect = new Rect(drawRect); cropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle cropRect.offset(Math.max(0, imageRect.left - cropRect.left), Math.max(0, imageRect.top - cropRect.top)); cropRect.offset(Math.min(0, imageRect.right - cropRect.right), Math.min(0, imageRect.bottom - cropRect.bottom)); drawRect = computeLayout(); invalRect.union(drawRect); invalRect.inset(-(int) handleRadius, -(int) handleRadius); viewContext.invalidate(invalRect); }
9. DraggableGridViewPager#getTargetByXY()
Project: UltimateAndroid
File: DraggableGridViewPager.java
File: DraggableGridViewPager.java
private int getTargetByXY(int x, int y) { final int position = getPositionByXY(x, y); if (position < 0) { return -1; } final Rect r = getRectByPosition(position); final int page = position / mPageSize; r.inset(r.width() / 4, r.height() / 4); r.offset(-getWidth() * page, 0); if (!r.contains(x, y)) { return -1; } return position; }
10. PagerTabStrip#updateTextPositions()
Project: UltimateAndroid
File: PagerTabStrip.java
File: PagerTabStrip.java
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); }
11. HighlightView#moveBy()
Project: UltimateAndroid
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectangle by (dx, dy) in image space void moveBy(float dx, float dy) { Rect invalRect = new Rect(drawRect); cropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle cropRect.offset(Math.max(0, imageRect.left - cropRect.left), Math.max(0, imageRect.top - cropRect.top)); cropRect.offset(Math.min(0, imageRect.right - cropRect.right), Math.min(0, imageRect.bottom - cropRect.bottom)); drawRect = computeLayout(); invalRect.union(drawRect); invalRect.inset(-(int) handleRadius, -(int) handleRadius); viewContext.invalidate(invalRect); }
12. DraggableGridViewPager#getTargetByXY()
Project: UltimateAndroid
File: DraggableGridViewPager.java
File: DraggableGridViewPager.java
private int getTargetByXY(int x, int y) { final int position = getPositionByXY(x, y); if (position < 0) { return -1; } final Rect r = getRectByPosition(position); final int page = position / mPageSize; r.inset(r.width() / 4, r.height() / 4); r.offset(-getWidth() * page, 0); if (!r.contains(x, y)) { return -1; } return position; }
13. CompositeDrawable#drawTo()
Project: materialize
File: CompositeDrawable.java
File: CompositeDrawable.java
public void drawTo(Canvas canvas, boolean antiAliasing) { Rect bounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF foregroundBounds = new RectF(bounds); applyForegroundBounds(foregroundBounds); Rect backgroundBounds = new Rect(bounds); applyBackgroundBounds(backgroundBounds); Rect scoreBounds = new Rect(bounds); applyScoreBounds(scoreBounds); drawInternal(canvas, antiAliasing, bounds, foregroundBounds, backgroundBounds, scoreBounds); }
14. ViewPosition#unpack()
Project: GestureViews
File: ViewPosition.java
File: ViewPosition.java
/** * Restores ViewPosition from the string created by {@link #pack()} method. */ // Public API @SuppressWarnings("unused") public static ViewPosition unpack(String str) { String[] parts = TextUtils.split(str, SPLIT_PATTERN); if (parts.length != 3) { throw new IllegalArgumentException("Wrong ViewPosition string: " + str); } Rect view = Rect.unflattenFromString(parts[0]); Rect viewport = Rect.unflattenFromString(parts[1]); Rect image = Rect.unflattenFromString(parts[2]); if (view == null || viewport == null || image == null) { throw new IllegalArgumentException("Wrong ViewPosition string: " + str); } return new ViewPosition(view, viewport, image); }
15. HighlightView#moveBy()
Project: GalleryFinal
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectangle by (dx, dy) in image space void moveBy(float dx, float dy) { Rect invalRect = new Rect(drawRect); cropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle cropRect.offset(Math.max(0, imageRect.left - cropRect.left), Math.max(0, imageRect.top - cropRect.top)); cropRect.offset(Math.min(0, imageRect.right - cropRect.right), Math.min(0, imageRect.bottom - cropRect.bottom)); drawRect = computeLayout(); invalRect.union(drawRect); invalRect.inset(-(int) handleRadius, -(int) handleRadius); viewContext.invalidate(invalRect); }
16. PagerTabStripV22#updateTextPositions()
Project: Dividers
File: PagerTabStripV22.java
File: PagerTabStripV22.java
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); }
17. PagerTabStrip#updateTextPositions()
Project: CodenameOne
File: PagerTabStrip.java
File: PagerTabStrip.java
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); }
18. DraggableGridViewPager#getTargetByXY()
Project: Android-DraggableGridViewPager
File: DraggableGridViewPager.java
File: DraggableGridViewPager.java
private int getTargetByXY(int x, int y) { final int position = getPositionByXY(x, y); if (position < 0) { return -1; } final Rect r = getRectByPosition(position); final int page = position / mPageSize; r.inset(r.width() / 4, r.height() / 4); r.offset(-getWidth() * page, 0); if (!r.contains(x, y)) { return -1; } return position; }
19. HighlightView#moveBy()
Project: android-cropimage
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
20. HighlightView#moveBy()
Project: YiBo
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
21. HighlightView#moveBy()
Project: WifiChat
File: HighlightView.java
File: HighlightView.java
// Grows the cropping rectange by (dx, dy) in image space. void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); // mContext.invalidate(invalRect); mContext.invalidate(); }
22. Lanes#getChildFrame()
Project: UltimateAndroid
File: Lanes.java
File: Lanes.java
public void getChildFrame(Rect outRect, int childWidth, int childHeight, LaneInfo laneInfo, Direction direction) { final Rect startRect = mLanes[laneInfo.startLane]; // The anchor lane only applies when we're get child frame in the direction // of the forward scroll. We'll need to rethink this once we start working on // RTL support. final int anchorLane = (direction == Direction.END ? laneInfo.anchorLane : laneInfo.startLane); final Rect anchorRect = mLanes[anchorLane]; if (mIsVertical) { outRect.left = startRect.left; outRect.top = (direction == Direction.END ? anchorRect.bottom : anchorRect.top - childHeight); } else { outRect.top = startRect.top; outRect.left = (direction == Direction.END ? anchorRect.right : anchorRect.left - childWidth); } outRect.right = outRect.left + childWidth; outRect.bottom = outRect.top + childHeight; }
23. DynamicListView#getAndAddHoverView()
Project: UltimateAndroid
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
24. DynamicGridView#getAndAddHoverView()
Project: UltimateAndroid
File: DynamicGridView.java
File: DynamicGridView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
25. MaterialProgressDrawable#draw()
Project: UltimateAndroid
File: MaterialProgressDrawable.java
File: MaterialProgressDrawable.java
@Override public void draw(Canvas c) { mWidth = dp2px(40); Rect bounds = getBounds(); int left = (int) (bounds.width() / 2 - mWidth / 2); int right = (int) (bounds.width() / 2 + mWidth / 2); int bottom = (int) (bounds.top + mHeight); bounds = new Rect(left, bounds.top, right, bottom); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
26. DiscreteSeekBar#startDragging()
Project: UltimateAndroid
File: DiscreteSeekBar.java
File: DiscreteSeekBar.java
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDraggOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDraggOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); } return mIsDragging; }
27. MaterialProgressDrawable#draw()
Project: UltimateAndroid
File: MaterialProgressDrawable.java
File: MaterialProgressDrawable.java
@Override public void draw(Canvas c) { mWidth = dp2px(40); Rect bounds = getBounds(); int left = (int) (bounds.width() / 2 - mWidth / 2); int right = (int) (bounds.width() / 2 + mWidth / 2); int bottom = (int) (bounds.top + mHeight); bounds = new Rect(left, bounds.top, right, bottom); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
28. DynamicGridView#getAndAddHoverView()
Project: UltimateAndroid
File: DynamicGridView.java
File: DynamicGridView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
29. DynamicListView#getAndAddHoverView()
Project: UltimateAndroid
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
30. ReorderRecyclerView#getAndAddHoverView()
Project: Tower
File: ReorderRecyclerView.java
File: ReorderRecyclerView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth() + SCALE_FACTOR; int h = v.getHeight() + SCALE_FACTOR; int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, w, h, false); BitmapDrawable drawable = new BitmapDrawable(getResources(), scaledBitmap); hoverCellOriginalBounds = new Rect(left, top, left + w, top + h); hoverCellCurrentBounds = new Rect(hoverCellOriginalBounds); drawable.setBounds(hoverCellCurrentBounds); return drawable; }
31. SwitchAccessWindowInfoTest#testGetBounds_shouldReturnWrappedBounds()
Project: talkback
File: SwitchAccessWindowInfoTest.java
File: SwitchAccessWindowInfoTest.java
@Test public void testGetBounds_shouldReturnWrappedBounds() { AccessibilityWindowInfo window = AccessibilityWindowInfo.obtain(); ShadowAccessibilityWindowInfo shadowWindow = (ShadowAccessibilityWindowInfo) ShadowExtractor.extract(window); Rect rectIn = new Rect(100, 200, 300, 400); shadowWindow.setBoundsInScreen(rectIn); SwitchAccessWindowInfo windowInfo = new SwitchAccessWindowInfo(window, null); Rect rectOut = new Rect(); windowInfo.getBoundsInScreen(rectOut); assertEquals(rectIn, rectOut); }
32. AccessibilityNodeInfoUtils#isNodeInBoundsOfOther()
Project: talkback
File: AccessibilityNodeInfoUtils.java
File: AccessibilityNodeInfoUtils.java
private static boolean isNodeInBoundsOfOther(AccessibilityNodeInfoCompat outerNode, AccessibilityNodeInfoCompat innerNode) { if (outerNode == null || innerNode == null) { return false; } Rect outerRect = new Rect(); Rect innerRect = new Rect(); outerNode.getBoundsInScreen(outerRect); innerNode.getBoundsInScreen(innerRect); if (outerRect.top > innerRect.bottom || outerRect.bottom < innerRect.top) { return false; } //noinspection RedundantIfStatement if (outerRect.left > innerRect.right || outerRect.right < innerRect.left) { return false; } return true; }
33. StaggeredGridView#positionSelector()
Project: StaggeredGridView
File: StaggeredGridView.java
File: StaggeredGridView.java
void positionSelector(int position, View sel) { if (position != INVALID_POSITION) { mSelectorPosition = position; } final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); if (sel instanceof SelectionBoundsAdjuster) { ((SelectionBoundsAdjuster) sel).adjustListItemSelectionBounds(selectorRect); } positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; if (getSelectedItemPosition() != INVALID_POSITION) { refreshDrawableState(); } } }
34. ActionBarSliderHandle#onInterceptTouchEvent()
Project: socialize-sdk-android
File: ActionBarSliderHandle.java
File: ActionBarSliderHandle.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Rect rect = new Rect(); closeButton.getHitRect(rect); adjustHitRect(rect); if (rect.contains((int) FloatMath.ceil(ev.getX()), (int) FloatMath.ceil(ev.getY()))) { getSlider().close(); } else { getSlider().slide(); } return true; }
35. SlideSwitch#initDrawingVal()
Project: SlideSwitch
File: SlideSwitch.java
File: SlideSwitch.java
public void initDrawingVal() { int width = getMeasuredWidth(); int height = getMeasuredHeight(); backCircleRect = new RectF(); frontCircleRect = new RectF(); frontRect = new Rect(); backRect = new Rect(0, 0, width, height); min_left = RIM_SIZE; if (shape == SHAPE_RECT) max_left = width / 2; else max_left = width - (height - 2 * RIM_SIZE) - RIM_SIZE; if (isOpen) { frontRect_left = max_left; alpha = 255; } else { frontRect_left = RIM_SIZE; alpha = 0; } frontRect_left_begin = frontRect_left; }
36. DiscreteSeekBar#startDragging()
Project: Sky31Radio
File: DiscreteSeekBar.java
File: DiscreteSeekBar.java
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); } return mIsDragging; }
37. DynamicListView#getAndAddHoverView()
Project: Kore
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapWithBorder(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
38. MessageListFragment#handleSwipe()
Project: k-9
File: MessageListFragment.java
File: MessageListFragment.java
/** * Handle a select or unselect swipe event. * * @param downMotion * Event that started the swipe * @param selected * {@code true} if this was an attempt to select (i.e. left to right). */ private void handleSwipe(final MotionEvent downMotion, final boolean selected) { int x = (int) downMotion.getRawX(); int y = (int) downMotion.getRawY(); Rect headerRect = new Rect(); mListView.getGlobalVisibleRect(headerRect); // Only handle swipes in the visible area of the message list if (headerRect.contains(x, y)) { int[] listPosition = new int[2]; mListView.getLocationOnScreen(listPosition); int listX = x - listPosition[0]; int listY = y - listPosition[1]; int listViewPosition = mListView.pointToPosition(listX, listY); toggleMessageSelect(listViewPosition); } }
39. DynamicListView#getAndAddHoverView()
Project: arcgis-runtime-samples-android
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapWithBorder(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
40. Position#getRealVisibleRect()
Project: AndroidStudyDemo
File: Position.java
File: Position.java
/** * @param v * @return ??view????????????????????????0 */ public static Rect getRealVisibleRect(View v) { //??view??????????????? int[] position = new int[2]; v.getLocationOnScreen(position); Rect bounds = new Rect(); boolean isInScreen = v.getGlobalVisibleRect(bounds); Rect mRect = new Rect(); mRect.left = position[0]; mRect.top = position[1]; if (isInScreen) { mRect.right = mRect.left + bounds.width(); mRect.bottom = mRect.top + bounds.height(); } else { mRect.right = mRect.left; mRect.bottom = mRect.top; } return mRect; }
41. ZrcAbsListView#positionSelector()
Project: AndroidStudyDemo
File: ZrcAbsListView.java
File: ZrcAbsListView.java
void positionSelector(int position, View sel) { if (position != INVALID_POSITION) { mSelectorPosition = position; } final Rect selectorRect = mSelectorRect; invalidate(selectorRect); selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); invalidate(selectorRect); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; } }
42. LeafLoadingView#onSizeChanged()
Project: AndroidStudyDemo
File: LeafLoadingView.java
File: LeafLoadingView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mTotalWidth = w; mTotalHeight = h; mProgressWidth = mTotalWidth - mLeftMargin - mRightMargin; mArcRadius = (mTotalHeight - 2 * mLeftMargin) / 2; mOuterSrcRect = new Rect(0, 0, mOuterWidth, mOuterHeight); mOuterDestRect = new Rect(0, 0, mTotalWidth, mTotalHeight); mWhiteRectF = new RectF(mLeftMargin + mCurrentProgressPosition, mLeftMargin, mTotalWidth - mRightMargin, mTotalHeight - mLeftMargin); mOrangeRectF = new RectF(mLeftMargin + mArcRadius, mLeftMargin, mCurrentProgressPosition, mTotalHeight - mLeftMargin); mArcRectF = new RectF(mLeftMargin, mLeftMargin, mLeftMargin + 2 * mArcRadius, mTotalHeight - mLeftMargin); mArcRightLocation = mLeftMargin + mArcRadius; }
43. LineView#drawPopup()
Project: AndroidCharts
File: LineView.java
File: LineView.java
/** * * @param canvas The canvas you need to draw on. * @param point The Point consists of the x y coordinates from left bottom to right top. * Like is * * 3 * 2 * 1 * 0 1 2 3 4 5 */ private void drawPopup(Canvas canvas, String num, Point point, int PopupColor) { boolean singularNum = (num.length() == 1); int sidePadding = MyUtils.dip2px(getContext(), singularNum ? 8 : 5); int x = point.x; int y = point.y - MyUtils.dip2px(getContext(), 5); Rect popupTextRect = new Rect(); popupTextPaint.getTextBounds(num, 0, num.length(), popupTextRect); Rect r = new Rect(x - popupTextRect.width() / 2 - sidePadding, y - popupTextRect.height() - bottomTriangleHeight - popupTopPadding * 2 - popupBottomMargin, x + popupTextRect.width() / 2 + sidePadding, y + popupTopPadding - popupBottomMargin); NinePatchDrawable popup = (NinePatchDrawable) getResources().getDrawable(PopupColor); popup.setBounds(r); popup.draw(canvas); canvas.drawText(num, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint); }
44. DynamicListView#getAndAddHoverView()
Project: android-open-project-demo
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
45. HeaderPositionCalculator#translateHeaderWithNextHeader()
Project: AmazeFileManager
File: HeaderPositionCalculator.java
File: HeaderPositionCalculator.java
private void translateHeaderWithNextHeader(RecyclerView recyclerView, int orientation, Rect translation, View currentHeader, View viewAfterNextHeader, View nextHeader) { Rect nextHeaderMargins = mDimensionCalculator.getMargins(nextHeader); Rect stickyHeaderMargins = mDimensionCalculator.getMargins(currentHeader); if (orientation == LinearLayoutManager.VERTICAL) { int topOfStickyHeader = getListTop(recyclerView) + stickyHeaderMargins.top + stickyHeaderMargins.bottom; int shiftFromNextHeader = viewAfterNextHeader.getTop() - nextHeader.getHeight() - nextHeaderMargins.bottom - nextHeaderMargins.top - currentHeader.getHeight() - topOfStickyHeader; if (shiftFromNextHeader < topOfStickyHeader) { translation.top += shiftFromNextHeader; } } else { int leftOfStickyHeader = getListLeft(recyclerView) + stickyHeaderMargins.left + stickyHeaderMargins.right; int shiftFromNextHeader = viewAfterNextHeader.getLeft() - nextHeader.getWidth() - nextHeaderMargins.right - nextHeaderMargins.left - currentHeader.getWidth() - leftOfStickyHeader; if (shiftFromNextHeader < leftOfStickyHeader) { translation.left += shiftFromNextHeader; } } }
46. Position#getRealVisibleRect()
Project: ActivityOptionsICS
File: Position.java
File: Position.java
/** * @param v * @return ??view????????????????????????0 */ public static Rect getRealVisibleRect(View v) { //??view??????????????? int[] position = new int[2]; v.getLocationOnScreen(position); Rect bounds = new Rect(); boolean isInScreen = v.getGlobalVisibleRect(bounds); Rect mRect = new Rect(); mRect.left = position[0]; mRect.top = position[1]; if (isInScreen) { mRect.right = mRect.left + bounds.width(); mRect.bottom = mRect.top + bounds.height(); } else { mRect.right = mRect.left; mRect.bottom = mRect.top; } return mRect; }
47. DiffLineSpan#drawBackground()
Project: Gitskarios
File: DiffLineSpan.java
File: DiffLineSpan.java
@Override public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) { // expand canvas bounds by padding Rect clipBounds = c.getClipBounds(); clipBounds.inset(-padding, 0); //c.clipRect(clipBounds, Region.Op.REPLACE); final int paintColor = p.getColor(); p.setColor(color); mTmpRect.set(left - padding, top, right + padding, bottom); c.drawRect(mTmpRect, p); p.setColor(paintColor); }
48. AnimatedDrawableBackendImpl#forNewBounds()
Project: fresco
File: AnimatedDrawableBackendImpl.java
File: AnimatedDrawableBackendImpl.java
@Override public AnimatedDrawableBackend forNewBounds(Rect bounds) { Rect boundsToUse = getBoundsToUse(mAnimatedImage, bounds); if (boundsToUse.equals(mRenderedBounds)) { // Actual bounds aren't changed. return this; } return new AnimatedDrawableBackendImpl(mAnimatedDrawableUtil, mAnimatedImageResult, bounds); }
49. OverlayView#onDraw()
Project: ExhibitionCenter
File: OverlayView.java
File: OverlayView.java
public void onDraw(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Rect frame; if (boundsWidth < 0 || boundsHeight < 0) { //????????? boundsLeft = viewWidth / 4; boundsWidth = viewWidth / 2; boundsTop = (viewHeight - boundsWidth) / 2; boundsHeight = boundsWidth; } int top = boundsTop + boundsMarginTop; frame = new Rect(boundsLeft, top, boundsLeft + boundsWidth, top + boundsHeight); drawFrameBounds(canvas, paint, frame); drawScanLight(canvas, paint, frame); drawHintText(canvas, paint, frame); //???? postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom); }
50. PLA_AbsListView#positionSelector()
Project: EverMemo
File: PLA_AbsListView.java
File: PLA_AbsListView.java
void positionSelector(View sel) { final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; refreshDrawableState(); } }
51. ValueLineChart#calculateValueTextHeight()
Project: EazeGraph
File: ValueLineChart.java
File: ValueLineChart.java
/** * Calculates the text height for the indicator value and sets its x-coordinate. */ private void calculateValueTextHeight() { Rect valueRect = new Rect(); Rect legendRect = new Rect(); String str = Utils.getFloatString(mFocusedPoint.getValue(), mShowDecimal) + (!mIndicatorTextUnit.isEmpty() ? " " + mIndicatorTextUnit : ""); // calculate the boundaries for both texts mIndicatorPaint.getTextBounds(str, 0, str.length(), valueRect); mLegendPaint.getTextBounds(mFocusedPoint.getLegendLabel(), 0, mFocusedPoint.getLegendLabel().length(), legendRect); // calculate string positions in overlay mValueTextHeight = valueRect.height(); mValueLabelY = (int) (mValueTextHeight + mIndicatorTopPadding); mLegendLabelY = (int) (mValueTextHeight + mIndicatorTopPadding + legendRect.height() + Utils.dpToPx(7.f)); int chosenWidth = valueRect.width() > legendRect.width() ? valueRect.width() : legendRect.width(); // check if text reaches over screen if (mFocusedPoint.getCoordinates().getX() + chosenWidth + mIndicatorLeftPadding > -Utils.getTranslationX(mDrawMatrixValues) + mGraphWidth) { mValueLabelX = (int) (mFocusedPoint.getCoordinates().getX() - (valueRect.width() + mIndicatorLeftPadding)); mLegendLabelX = (int) (mFocusedPoint.getCoordinates().getX() - (legendRect.width() + mIndicatorLeftPadding)); } else { mValueLabelX = mLegendLabelX = (int) (mFocusedPoint.getCoordinates().getX() + mIndicatorLeftPadding); } }
52. DynamicGridView#getAndAddHoverView()
Project: DynamicGrid
File: DynamicGridView.java
File: DynamicGridView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapFromView(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
53. SuperImageView#resize()
Project: droid-comic-viewer
File: SuperImageView.java
File: SuperImageView.java
/** * Recalculates the given frame of the original image considering the given width as the width of the image. * Also centers the new frame in the parent view * @param frame Frame of the original image. * @param newWidth Width of the image. * @param keepInside * @return */ private Rect resize(Rect frame, int newWidth, boolean keepInside) { // Recalculate frame based on new width final Rect newFrame = new Rect(); float scale = (float) newWidth / (float) getOriginalWidth(); newFrame.left = Math.round(frame.left * scale); newFrame.top = Math.round(frame.top * scale); newFrame.right = Math.round(frame.right * scale); newFrame.bottom = Math.round(frame.bottom * scale); int dx = -(Math.min(newWidth, getRootViewWidth()) - newFrame.width()) / 2; final int newHeight = Math.round(getOriginalHeight() * scale); int dy = -(Math.min(newHeight, getRootViewHeight()) - newFrame.height()) / 2; newFrame.offset(dx, dy); if (// No letterbox keepInside) { Point scroll = calculateSafeScroll(newFrame.left, newFrame.top, newWidth, newHeight); newFrame.offsetTo(scroll.x, scroll.y); } return newFrame; }
54. DragSortRecycler#createFloatingBitmap()
Project: DragSortRecycler
File: DragSortRecycler.java
File: DragSortRecycler.java
private BitmapDrawable createFloatingBitmap(View v) { floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); floatingItemBounds = new Rect(floatingItemStatingBounds); Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(), floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.draw(canvas); BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap); retDrawable.setBounds(floatingItemBounds); return retDrawable; }
55. AndroidGraphics#drawImageImpl()
Project: CodenameOne
File: AndroidGraphics.java
File: AndroidGraphics.java
void drawImageImpl(Object img, int x, int y, int w, int h) { Bitmap b = (Bitmap) img; Rect src = new Rect(); src.top = 0; src.bottom = b.getHeight(); src.left = 0; src.right = b.getWidth(); Rect dest = new Rect(); dest.top = y; dest.bottom = y + h; dest.left = x; dest.right = x + w; canvas.drawBitmap(b, src, dest, paint); }
56. DynamicListView#getAndAddHoverView()
Project: codeexamples-android
File: DynamicListView.java
File: DynamicListView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every * single time an invalidate call is made. */ private BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapWithBorder(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
57. PLAAbsListView#positionSelector()
Project: SimplifyReader
File: PLAAbsListView.java
File: PLAAbsListView.java
void positionSelector(View sel) { final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; refreshDrawableState(); } }
58. LineView#drawPopup()
Project: SimplePomodoro-android
File: LineView.java
File: LineView.java
/** * * @param canvas The canvas you need to draw on. * @param point The Point consists of the x y coordinates from left bottom to right top. * Like is ? * 3 * 2 * 1 * 0 1 2 3 4 5 */ private void drawPopup(Canvas canvas, String num, Point point) { boolean singularNum = (num.length() == 1); int sidePadding = MyUtils.dip2px(getContext(), singularNum ? 8 : 5); int x = point.x; int y = point.y - MyUtils.dip2px(getContext(), 5); Rect popupTextRect = new Rect(); popupTextPaint.getTextBounds(num, 0, num.length(), popupTextRect); Rect r = new Rect(x - popupTextRect.width() / 2 - sidePadding, y - popupTextRect.height() - bottomTriangleHeight - popupTopPadding * 2 - popupBottomMargin, x + popupTextRect.width() / 2 + sidePadding, y + popupTopPadding - popupBottomMargin); NinePatchDrawable popup = (NinePatchDrawable) getResources().getDrawable(R.drawable.popup_red); popup.setBounds(r); popup.draw(canvas); canvas.drawText(num, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint); }
59. TwoWayAbsListView#positionSelector()
Project: serenity-android
File: TwoWayAbsListView.java
File: TwoWayAbsListView.java
void positionSelector(View sel) { final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; refreshDrawableState(); } }
60. DragSortRecycler#createFloatingBitmap()
Project: rox-android
File: DragSortRecycler.java
File: DragSortRecycler.java
private BitmapDrawable createFloatingBitmap(View v) { floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); floatingItemBounds = new Rect(floatingItemStatingBounds); Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(), floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.draw(canvas); BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap); retDrawable.setBounds(floatingItemBounds); return retDrawable; }
61. TwoWayAbsListView#positionSelector()
Project: recent-images
File: TwoWayAbsListView.java
File: TwoWayAbsListView.java
void positionSelector(View sel) { final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; refreshDrawableState(); } }
62. CenterDrawable#onBoundsChange()
Project: Pr0
File: CenterDrawable.java
File: CenterDrawable.java
@Override protected void onBoundsChange(Rect bounds) { Rect wrapped = getWrappedDrawable().getBounds(); float innerAspect = wrapped.width() / (float) wrapped.height(); float outerAspect = bounds.width() / (float) bounds.height(); Rect result = new Rect(bounds); if (innerAspect > outerAspect) { result.top = (int) (bounds.exactCenterY() - 0.5f * bounds.width() / innerAspect); result.bottom = (int) (bounds.exactCenterY() + 0.5f * bounds.width() / innerAspect); } else { result.left = (int) (bounds.exactCenterX() - 0.5f * bounds.height() / innerAspect); result.right = (int) (bounds.exactCenterX() + 0.5f * bounds.height() / innerAspect); } getWrappedDrawable().setBounds(result); }
63. PXBorderOverlay#loadScene()
Project: pixate-freestyle-android
File: PXBorderOverlay.java
File: PXBorderOverlay.java
/* * (non-Javadoc) * * @see com.pixate.freestyle.pxengine.view.BasePXShapeDrawable#loadScene() */ @Override public PXShapeDocument loadScene() { Rect bounds = getBounds(); if (bounds.isEmpty()) { scene = null; return scene; } if (scene != null) { return scene; } PXRectangle rectangle = new PXRectangle(new RectF(bounds)); PXStroke stroke = new PXStroke(); stroke.setColor(new PXSolidPaint(color)); stroke.setWidth(size); rectangle.setStroke(stroke); PXShapeDocument aScene = new PXShapeDocument(); aScene.setShape(rectangle); scene = aScene; return scene; }
64. Marker#draw()
Project: osmdroid
File: Marker.java
File: Marker.java
@Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { if (shadow) return; if (mIcon == null) return; final Projection pj = mapView.getProjection(); pj.toPixels(mPosition, mPositionPixels); int width = mIcon.getIntrinsicWidth(); int height = mIcon.getIntrinsicHeight(); Rect rect = new Rect(0, 0, width, height); rect.offset(-(int) (mAnchorU * width), -(int) (mAnchorV * height)); mIcon.setBounds(rect); mIcon.setAlpha((int) (mAlpha * 255)); float rotationOnScreen = (mFlat ? -mBearing : mapView.getMapOrientation() - mBearing); drawAt(canvas, mIcon, mPositionPixels.x, mPositionPixels.y, false, rotationOnScreen); }
65. DragSortRecycler#createFloatingBitmap()
Project: Muzesto
File: DragSortRecycler.java
File: DragSortRecycler.java
private BitmapDrawable createFloatingBitmap(View v) { floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); floatingItemBounds = new Rect(floatingItemStatingBounds); Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(), floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.draw(canvas); BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap); retDrawable.setBounds(floatingItemBounds); return retDrawable; }
66. CameraPreview#calculateFramingRect()
Project: zxing-android-embedded
File: CameraPreview.java
File: CameraPreview.java
/** * Calculate framing rectangle, relative to the preview frame. * * Note that the SurfaceView may be larger than the container. * * Override this for more control over the framing rect calculations. * * @param container this container, with left = top = 0 * @param surface the SurfaceView, relative to this container * @return the framing rect, relative to this container */ protected Rect calculateFramingRect(Rect container, Rect surface) { // intersection is the part of the container that is used for the preview Rect intersection = new Rect(container); boolean intersects = intersection.intersect(surface); if (framingRectSize != null) { // Specific size is specified. Make sure it's not larger than the container or surface. int horizontalMargin = Math.max(0, (intersection.width() - framingRectSize.width) / 2); int verticalMargin = Math.max(0, (intersection.height() - framingRectSize.height) / 2); intersection.inset(horizontalMargin, verticalMargin); return intersection; } // margin as 10% (default) of the smaller of width, height int margin = (int) Math.min(intersection.width() * marginFraction, intersection.height() * marginFraction); intersection.inset(margin, margin); if (intersection.height() > intersection.width()) { // We don't want a frame that is taller than wide. intersection.inset(0, (intersection.height() - intersection.width()) / 2); } return intersection; }
67. ZrcAbsListView#positionSelector()
Project: ZrcListView
File: ZrcAbsListView.java
File: ZrcAbsListView.java
void positionSelector(int position, View sel) { if (position != INVALID_POSITION) { mSelectorPosition = position; } final Rect selectorRect = mSelectorRect; invalidate(selectorRect); selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); invalidate(selectorRect); final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; } }
68. AbstractWheelPicker#instantiation()
Project: WheelPicker
File: AbstractWheelPicker.java
File: AbstractWheelPicker.java
protected void instantiation() { mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG); mTextPaint.setTextAlign(Paint.Align.CENTER); mTextPaint.setTextSize(textSize); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); mTextBound = new Rect(); mDrawBound = new Rect(); mHandler = new Handler(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { mScroller = new OverScrollerCompat(getContext(), new DecelerateInterpolator()); } else { mScroller = new ScrollerCompat(getContext(), new DecelerateInterpolator()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mScroller.setFriction(ViewConfiguration.getScrollFriction() / 25); } }
69. DragSortGridView#moveView()
Project: WayHoo
File: DragSortGridView.java
File: DragSortGridView.java
private void moveView(int fromPosition, int toPosition) { if (DEBUG_LOG) { L.d(TAG, "moveView from:" + fromPosition + ",to:" + toPosition); } final View from = getView(fromPosition); final View to = getView(toPosition); final Rect fromRect = new Rect(); getLayout(from, fromRect); final Rect toRect = new Rect(); getLayout(to, toRect); Animation translate = new TranslateAnimation(0, toRect.left - fromRect.left, 0, toRect.top - fromRect.top); translate.setDuration(150); translate.setFillEnabled(true); translate.setFillBefore(true); translate.setFillAfter(true); translate.setAnimationListener(new MoveViewAnimationListener(from, to.getLeft(), to.getTop())); from.startAnimation(translate); }
70. SwipeViewLayout#layoutLayDown()
Project: UltimateSwipeTool
File: SwipeViewLayout.java
File: SwipeViewLayout.java
void layoutLayDown() { View surfaceView = getSurfaceView(); Rect surfaceRect = mViewBoundCache.get(surfaceView); if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); if (surfaceView != null) { surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } View currentBottomView = getCurrentBottomView(); Rect bottomViewRect = mViewBoundCache.get(currentBottomView); if (bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect); if (currentBottomView != null) { currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } }
71. SwipeViewLayout#layoutPullOut()
Project: UltimateSwipeTool
File: SwipeViewLayout.java
File: SwipeViewLayout.java
void layoutPullOut() { View surfaceView = getSurfaceView(); Rect surfaceRect = mViewBoundCache.get(surfaceView); if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); if (surfaceView != null) { surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } View currentBottomView = getCurrentBottomView(); Rect bottomViewRect = mViewBoundCache.get(currentBottomView); if (bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect); if (currentBottomView != null) { currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } }
72. HeaderPositionCalculator#translateHeaderWithNextHeader()
Project: UltimateRecyclerView
File: HeaderPositionCalculator.java
File: HeaderPositionCalculator.java
private void translateHeaderWithNextHeader(RecyclerView recyclerView, int orientation, Rect translation, View currentHeader, View viewAfterNextHeader, View nextHeader) { Rect nextHeaderMargins = mDimensionCalculator.getMargins(nextHeader); Rect stickyHeaderMargins = mDimensionCalculator.getMargins(currentHeader); if (orientation == LinearLayoutManager.VERTICAL) { int topOfStickyHeader = getListTop(recyclerView) + stickyHeaderMargins.top + stickyHeaderMargins.bottom; int shiftFromNextHeader = viewAfterNextHeader.getTop() - nextHeader.getHeight() - nextHeaderMargins.bottom - nextHeaderMargins.top - currentHeader.getHeight() - topOfStickyHeader; if (shiftFromNextHeader < topOfStickyHeader) { translation.top += shiftFromNextHeader; } } else { int leftOfStickyHeader = getListLeft(recyclerView) + stickyHeaderMargins.left + stickyHeaderMargins.right; int shiftFromNextHeader = viewAfterNextHeader.getLeft() - nextHeader.getWidth() - nextHeaderMargins.right - nextHeaderMargins.left - currentHeader.getWidth() - leftOfStickyHeader; if (shiftFromNextHeader < leftOfStickyHeader) { translation.left += shiftFromNextHeader; } } }
73. ZrcAbsListView#canScrollList()
Project: ZrcListView
File: ZrcAbsListView.java
File: ZrcAbsListView.java
public boolean canScrollList(int direction) { final int childCount = getChildCount(); if (childCount == 0) { return false; } final int firstPosition = mFirstPosition; final Rect listPadding = mListPadding; if (direction > 0) { final int lastBottom = getChildAt(childCount - 1).getBottom(); final int lastPosition = firstPosition + childCount; return lastPosition < mItemCount || lastBottom > getHeight() - listPadding.bottom - mLastBottomOffset; } else { final int firstTop = getChildAt(0).getTop(); return firstPosition > 0 || firstTop < listPadding.top + mFirstTopOffset; } }
74. ZrcAbsListView#pointToPosition()
Project: ZrcListView
File: ZrcAbsListView.java
File: ZrcAbsListView.java
public int pointToPosition(int x, int y) { Rect frame = mTouchFrame; if (frame == null) { mTouchFrame = new Rect(); frame = mTouchFrame; } final int count = getChildCount(); for (int i = count - 1; i >= 0; i--) { final View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { child.getHitRect(frame); if (frame.contains(x, y)) { return mFirstPosition + i; } } } return INVALID_POSITION; }
75. RippleView#getCircleBitmap()
Project: ZDepthShadow
File: RippleView.java
File: RippleView.java
private Bitmap getCircleBitmap(final int radius) { final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius)); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(x, y, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(originBitmap, rect, rect, paint); return output; }
76. BezelImageView#setFrame()
Project: YouJoin-Android
File: BezelImageView.java
File: BezelImageView.java
@Override protected boolean setFrame(int l, int t, int r, int b) { final boolean changed = super.setFrame(l, t, r, b); mBounds = new Rect(0, 0, r - l, b - t); mBoundsF = new RectF(mBounds); if (mMaskDrawable != null) { mMaskDrawable.setBounds(mBounds); } if (changed) { mCacheValid = false; } return changed; }
77. BitmapUtils#getRoundedCornerBitmap()
Project: YouJoin-Android
File: BitmapUtils.java
File: BitmapUtils.java
/** * ????????? * * @param bitmap ?Bitmap * @param roundPx ???? * @return ??Bitmap */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
78. HighlightView#handleMotion()
Project: YiBo
File: HighlightView.java
File: HighlightView.java
// Handles motion (dx, dy) in screen space. // The "edge" parameter specifies which edges the user is dragging. void handleMotion(int edge, float dx, float dy) { Rect r = computeLayout(); if (edge == GROW_NONE) { return; } else if (edge == MOVE) { // Convert to image space before sending to moveBy(). moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height())); } else { if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) { dx = 0; } if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) { dy = 0; } // Convert to image space before sending to growBy(). float xDelta = dx * (mCropRect.width() / r.width()); float yDelta = dy * (mCropRect.height() / r.height()); growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta); } }
79. CropImageView#centerBasedOnHighlightView()
Project: YiBo
File: CropImageView.java
File: CropImageView.java
// If the cropping rectangle's size changed significantly, change the // view's center and scale according to the cropping rectangle. private void centerBasedOnHighlightView(HighlightView hv) { Rect drawRect = hv.mDrawRect; float width = drawRect.width(); float height = drawRect.height(); float thisWidth = getWidth(); float thisHeight = getHeight(); float z1 = thisWidth / width * .6F; float z2 = thisHeight / height * .6F; float zoom = Math.min(z1, z2); zoom = zoom * this.getScale(); zoom = Math.max(1F, zoom); if ((Math.abs(zoom - getScale()) / zoom) > .1) { float[] coordinates = new float[] { hv.mCropRect.centerX(), hv.mCropRect.centerY() }; getImageMatrix().mapPoints(coordinates); zoomTo(zoom, coordinates[0], coordinates[1], 300F); } ensureVisible(hv); }
80. CropImageView#ensureVisible()
Project: YiBo
File: CropImageView.java
File: CropImageView.java
// Pan the displayed image to make sure the cropping rectangle is visible. private void ensureVisible(HighlightView hv) { Rect r = hv.mDrawRect; int panDeltaX1 = Math.max(0, getLeft() - r.left); int panDeltaX2 = Math.min(0, getRight() - r.right); int panDeltaY1 = Math.max(0, getTop() - r.top); int panDeltaY2 = Math.min(0, getBottom() - r.bottom); int panDeltaX = panDeltaX1 != 0 ? panDeltaX1 : panDeltaX2; int panDeltaY = panDeltaY1 != 0 ? panDeltaY1 : panDeltaY2; if (panDeltaX != 0 || panDeltaY != 0) { panBy(panDeltaX, panDeltaY); } }
81. SwipeBackLayout#drawShadow()
Project: XMVideo
File: SwipeBackLayout.java
File: SwipeBackLayout.java
private void drawShadow(Canvas canvas, View child) { final Rect childRect = mTmpRect; child.getHitRect(childRect); if ((mEdgeFlag & EDGE_LEFT) != 0) { mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, childRect.left, childRect.bottom); mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowLeft.draw(canvas); } if ((mEdgeFlag & EDGE_RIGHT) != 0) { mShadowRight.setBounds(childRect.right, childRect.top, childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom); mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowRight.draw(canvas); } if ((mEdgeFlag & EDGE_BOTTOM) != 0) { mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, childRect.bottom + mShadowBottom.getIntrinsicHeight()); mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowBottom.draw(canvas); } }
82. TextTexture#ensureChar()
Project: wwmmo
File: TextTexture.java
File: TextTexture.java
private void ensureChar(char ch) { if (characters.containsKey(ch)) { return; } String str = new String(new char[] { ch }); int charWidth = (int) Math.ceil(paint.measureText(str)); if (currRowOffsetX + charWidth > BITMAP_WIDTH) { currRowOffsetX = 0; currRowOffsetY += ROW_HEIGHT; } canvas.drawText(str, currRowOffsetX, currRowOffsetY + TEXT_HEIGHT - paint.descent() + (ROW_HEIGHT - TEXT_HEIGHT), paint); Rect bounds = new Rect(currRowOffsetX, currRowOffsetY, currRowOffsetX + charWidth, currRowOffsetY + ROW_HEIGHT); characters.put(ch, bounds); currRowOffsetX += charWidth; dirty = true; }
83. TextDrawable#draw()
Project: WordPress-Android
File: TextDrawable.java
File: TextDrawable.java
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); final int count = canvas.save(); canvas.translate(bounds.left, bounds.top); if (mTextPath == null) { //Allow the layout to draw the text mTextLayout.draw(canvas); } else { //Draw directly on the canvas using the supplied path canvas.drawTextOnPath(mText.toString(), mTextPath, 0, 0, mTextPaint); } canvas.restoreToCount(count); }
84. ImageUtils#getCircularBitmap()
Project: WordPress-Android
File: ImageUtils.java
File: ImageUtils.java
public static Bitmap getCircularBitmap(final Bitmap bitmap) { if (bitmap == null) return null; final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.RED); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
85. ImageUtils#toRoundCorner()
Project: WifiChat
File: ImageUtils.java
File: ImageUtils.java
/** * ?????? * * @param bitmap * @param pixels * @return */ public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
86. HighlightView#handleMotion()
Project: WifiChat
File: HighlightView.java
File: HighlightView.java
// Handles motion (dx, dy) in screen space. // The "edge" parameter specifies which edges the user is dragging. public void handleMotion(int edge, float dx, float dy) { Rect r = computeLayout(); if (edge == GROW_NONE) { return; } else if (edge == MOVE) { // Convert to image space before sending to moveBy(). moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height())); } else { if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) { dx = 0; } if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) { dy = 0; } // Convert to image space before sending to growBy(). float xDelta = dx * (mCropRect.width() / r.width()); float yDelta = dy * (mCropRect.height() / r.height()); growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta); } }
87. CropImageView#resetView()
Project: WifiChat
File: CropImageView.java
File: CropImageView.java
public void resetView(Bitmap b) { setImageBitmap(b); setImageBitmapResetBase(b, true); setImageMatrix(getImageViewMatrix()); int width = mBitmapDisplayed.getWidth(); int height = mBitmapDisplayed.getHeight(); Rect imageRect = new Rect(0, 0, width, height); int cropWidth = Math.min(width, height) * 4 / 5; int cropHeight = cropWidth; int x = (width - cropWidth) / 2; int y = (height - cropHeight) / 2; RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight); HighlightView hv = new HighlightView(this); hv.setup(getImageViewMatrix(), imageRect, cropRect, false, true); hv.setFocus(true); add(hv); centerBasedOnHighlightView(hv); hv.setMode(HighlightView.ModifyMode.None); center(true, true); invalidate(); }
88. CropImageView#centerBasedOnHighlightView()
Project: WifiChat
File: CropImageView.java
File: CropImageView.java
// If the cropping rectangle's size changed significantly, change the // view's center and scale according to the cropping rectangle. // hv.mDrawRect.width<0.54*thisWidth||width>0.66*thisWidth,need to zoom private void centerBasedOnHighlightView(HighlightView hv) { Rect drawRect = hv.mDrawRect; float width = drawRect.width(); float height = drawRect.height(); float thisWidth = getWidth(); float thisHeight = getHeight(); float z1 = thisWidth / width * .6F; float z2 = thisHeight / height * .6F; float zoom = Math.min(z1, z2); zoom = zoom * this.getScale(); // assure getScale()>1 zoom = Math.max(1F, zoom); if ((Math.abs(zoom - getScale()) / zoom) > 0.1) { float[] coordinates = new float[] { hv.mCropRect.centerX(), hv.mCropRect.centerY() }; getImageMatrix().mapPoints(coordinates); // CR: 300.0f. zoomTo(zoom, coordinates[0], coordinates[1], 300F); } ensureVisible(hv); }
89. CropImageView#ensureVisible()
Project: WifiChat
File: CropImageView.java
File: CropImageView.java
// Pan the displayed image to make sure the cropping rectangle is visible. private void ensureVisible(HighlightView hv) { Rect r = hv.mDrawRect; int panDeltaX1 = Math.max(0, getLeft() - r.left); int panDeltaX2 = Math.min(0, getRight() - r.right); int panDeltaY1 = Math.max(0, getTop() - r.top); int panDeltaY2 = Math.min(0, getBottom() - r.bottom); int panDeltaX = panDeltaX1 != 0 ? panDeltaX1 : panDeltaX2; int panDeltaY = panDeltaY1 != 0 ? panDeltaY1 : panDeltaY2; if (panDeltaX != 0 || panDeltaY != 0) { panBy(panDeltaX, panDeltaY); } }
90. Utility#locateView()
Project: weiciyuan
File: Utility.java
File: Utility.java
public static Rect locateView(View v) { int[] location = new int[2]; if (v == null) { return null; } try { v.getLocationOnScreen(location); } catch (NullPointerException npe) { return null; } Rect locationRect = new Rect(); locationRect.left = location[0]; locationRect.top = location[1]; locationRect.right = locationRect.left + v.getWidth(); locationRect.bottom = locationRect.top + v.getHeight(); return locationRect; }
91. ImageEditUtility#getRoundedCornerBitmap()
Project: weiciyuan
File: ImageEditUtility.java
File: ImageEditUtility.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int cornerRadius) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = cornerRadius; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
92. ScreenShot#getStatusBarHeight()
Project: weex
File: ScreenShot.java
File: ScreenShot.java
public static int getStatusBarHeight(Activity activity) { int result = 0; Rect rect = new Rect(); Window window = activity.getWindow(); if (window != null) { window.getDecorView().getWindowVisibleDisplayFrame(rect); android.view.View v = window.findViewById(Window.ID_ANDROID_CONTENT); android.view.Display display = ((android.view.WindowManager) activity.getSystemService(activity.WINDOW_SERVICE)).getDefaultDisplay(); //return result title bar height int result1 = display.getHeight() - v.getBottom() + rect.top; int result2 = display.getHeight() - v.getBottom(); int result3 = v.getTop() - rect.top; int result4 = display.getHeight() - v.getHeight(); Log.e("StatusBarHeight==", "result1== " + result1 + " result2 = " + result2 + "result3=" + result3 + "result4=" + result4); } return result; }
93. MyMenuItemStuffListener#onLongClick()
Project: weechat-android
File: MyMenuItemStuffListener.java
File: MyMenuItemStuffListener.java
@Override public boolean onLongClick(View v) { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int width = view.getWidth(); final int height = view.getHeight(); final int midy = screenPos[1] + height / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; Toast cheatSheet = Toast.makeText(context, hint, Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height); } else { cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
94. DismissAreaView#onSizeChanged()
Project: WebCards
File: DismissAreaView.java
File: DismissAreaView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { backgroundPaint.setShader(new RadialGradient(w, h, h, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR)); indicatorRect = new Rect(w - indicatorSize - indicatorMargin, h - indicatorSize - indicatorMargin, w - indicatorMargin, h - indicatorMargin); final int centerX = w - indicatorMargin - (indicatorSize / 2); final int centerY = h - indicatorMargin - (indicatorSize / 2); final int left = centerX - (crossSize / 2); final int top = centerY - (crossSize / 2); final int right = centerX + (crossSize / 2); final int bottom = centerY + (crossSize / 2); crossLines = new float[] { left, top, right, bottom, right, top, left, bottom }; }
95. SwipeBackLayout#drawShadow()
Project: WayHoo
File: SwipeBackLayout.java
File: SwipeBackLayout.java
private void drawShadow(Canvas canvas, View child) { final Rect childRect = mTmpRect; child.getHitRect(childRect); if ((mEdgeFlag & EDGE_LEFT) != 0) { mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, childRect.left, childRect.bottom); mShadowLeft.draw(canvas); } if ((mEdgeFlag & EDGE_RIGHT) != 0) { mShadowRight.setBounds(childRect.right, childRect.top, childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom); mShadowRight.draw(canvas); } if ((mEdgeFlag & EDGE_BOTTOM) != 0) { mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, childRect.bottom + mShadowBottom.getIntrinsicHeight()); mShadowBottom.draw(canvas); } }
96. WaveDrawable#draw()
Project: WaveDrawable
File: WaveDrawable.java
File: WaveDrawable.java
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); // circle wavePaint.setStyle(Paint.Style.FILL); wavePaint.setColor(color); wavePaint.setAlpha(alpha); canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius * waveScale, wavePaint); }
97. ImageUtils#getRoundedCornerBitmap()
Project: wakao-app
File: ImageUtils.java
File: ImageUtils.java
/** * ????????? * * @param bitmap * @param roundPx * ????14 * @return */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
98. VisibilityPercentsCalculator#getVisibilityPercents()
Project: VideoListPlayer
File: VisibilityPercentsCalculator.java
File: VisibilityPercentsCalculator.java
/** * When this method is called, the implementation should provide a visibility percents in range 0 - 100 % * @param view the view which visibility percent should be calculated. * Note: visibility doesn't have to depend on the visibility of a full view. * It might be calculated by calculating the visibility of any inner View * * @return percents of visibility */ public static int getVisibilityPercents(View view) { final Rect currentViewRect = new Rect(); int percents = 100; int height = (view == null || view.getVisibility() != View.VISIBLE) ? 0 : view.getHeight(); if (height == 0) { return 0; } if (view.getLocalVisibleRect(currentViewRect)) { if (viewIsPartiallyHiddenTop(currentViewRect)) { // view is partially hidden behind the top edge percents = (height - currentViewRect.top) * 100 / height; } else if (viewIsPartiallyHiddenBottom(currentViewRect, height)) { percents = currentViewRect.bottom * 100 / height; } return percents; } return 0; }
99. AudioPlaylistView#dragDropped()
Project: VCL-Android
File: AudioPlaylistView.java
File: AudioPlaylistView.java
public void dragDropped() { mIsDragging = false; // Find the child view that was touched (perform a hit test) Rect rect = new Rect(); boolean b_foundHitChild = false; for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.getHitRect(rect); if (rect.contains(getWidth() / 2, (int) mTouchY)) { // Send back the performed change thanks to the listener. AudioPlaylistAdapter.ViewHolder holder = (AudioPlaylistAdapter.ViewHolder) child.getTag(); if (mOnItemDraggedListener != null) mOnItemDraggedListener.onItemDragged(mPositionDragStart, holder.position); b_foundHitChild = true; break; } } if (!b_foundHitChild) mOnItemDraggedListener.onItemDragged(mPositionDragStart, this.getCount()); }
100. AudioPlaylistView#dragging()
Project: VCL-Android
File: AudioPlaylistView.java
File: AudioPlaylistView.java
private void dragging() { // Find the child view that is currently touched (perform a hit test) Rect rect = new Rect(); for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); AudioPlaylistAdapter.ViewHolder holder = (AudioPlaylistAdapter.ViewHolder) child.getTag(); if (holder.position == mPositionDragStart) { holder.layoutItem.setVisibility(LinearLayout.GONE); holder.layoutFooter.setVisibility(LinearLayout.GONE); } else { child.getHitRect(rect); if (rect.contains(getWidth() / 2, (int) mTouchY)) holder.expansion.setVisibility(LinearLayout.VISIBLE); else holder.expansion.setVisibility(LinearLayout.GONE); } } }