List of usage examples for android.graphics Rect offsetTo
public void offsetTo(int newLeft, int newTop)
From source file:net.nurik.roman.formwatchface.CompanionWatchFaceConfigActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void updateUIToSelectedTheme(final String themeId, final boolean animate) { for (final ThemeUiHolder holder : mThemeUiHolders) { boolean selected = holder.theme.id.equals(themeId); holder.button.setSelected(selected); if (holder.selected != selected && selected) { if (mCurrentRevealAnimator != null) { mCurrentRevealAnimator.end(); updatePreviewView(mAnimatingTheme, mMainClockContainerView, mMainClockView); }// w w w .j a v a2s . co m if (animate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mAnimatingTheme = holder.theme; updatePreviewView(mAnimatingTheme, mAnimateClockContainerView, mAnimateClockView); Rect buttonRect = new Rect(); Rect clockContainerRect = new Rect(); holder.button.getGlobalVisibleRect(buttonRect); mMainClockContainerView.getGlobalVisibleRect(clockContainerRect); int cx = buttonRect.centerX() - clockContainerRect.left; int cy = buttonRect.centerY() - clockContainerRect.top; clockContainerRect.offsetTo(0, 0); mCurrentRevealAnimator = ViewAnimationUtils.createCircularReveal(mAnimateClockContainerView, cx, cy, 0, MathUtil.maxDistanceToCorner(clockContainerRect, cx, cy)); mAnimateClockContainerView.setVisibility(View.VISIBLE); mCurrentRevealAnimator.setDuration(300); mCurrentRevealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (mCurrentRevealAnimator == animation) { mAnimateClockContainerView.setVisibility(View.INVISIBLE); updatePreviewView(holder.theme, mMainClockContainerView, mMainClockView); } } }); mAnimateClockView.postInvalidateOnAnimation(); mCurrentRevealAnimator.start(); } else { updatePreviewView(holder.theme, mMainClockContainerView, mMainClockView); } } holder.selected = selected; } }
From source file:com.commit451.springy.CompanionWatchFaceConfigActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void updateUIToSelectedTheme(final String themeId, final boolean animate) { for (final ThemeUiHolder holder : mThemeUiHolders) { boolean selected = holder.theme.id.equals(themeId); holder.button.setSelected(selected); if (holder.selected != selected && selected) { if (mCurrentRevealAnimator != null) { mCurrentRevealAnimator.end(); updatePreviewView(mAnimatingTheme, mMainClockContainerView); }// w w w. j ava 2 s .c o m if (animate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mAnimatingTheme = holder.theme; updatePreviewView(mAnimatingTheme, mAnimateClockContainerView); Rect buttonRect = new Rect(); Rect clockContainerRect = new Rect(); holder.button.getGlobalVisibleRect(buttonRect); mMainClockContainerView.getGlobalVisibleRect(clockContainerRect); int cx = buttonRect.centerX() - clockContainerRect.left; int cy = buttonRect.centerY() - clockContainerRect.top; clockContainerRect.offsetTo(0, 0); mCurrentRevealAnimator = ViewAnimationUtils.createCircularReveal(mAnimateClockContainerView, cx, cy, 0, MathUtil.maxDistanceToCorner(clockContainerRect, cx, cy)); mAnimateClockContainerView.setVisibility(View.VISIBLE); mCurrentRevealAnimator.setDuration(300); mCurrentRevealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (mCurrentRevealAnimator == animation) { mAnimateClockContainerView.setVisibility(View.INVISIBLE); updatePreviewView(holder.theme, mMainClockContainerView); } } }); mAnimateClockView.postInvalidateOnAnimation(); mCurrentRevealAnimator.start(); } else { updatePreviewView(holder.theme, mMainClockContainerView); } } holder.selected = selected; } }
From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (null != mViewPager) { if (mViewPager instanceof CircularViewPager) { mPointCount = ((CircularViewPager) mViewPager).getCount(); } else {/*from www . j av a 2 s . com*/ mPointCount = mViewPager.getAdapter().getCount(); } } if (mPointCount <= 0) { return; } final int count = mPointCount; final int margin = mPointMargin; final int height = getHeight(); final int width = getWidth(); final int selIndex = mPosition; final Rect normalRc = mNormalPointRect; final Rect selectRc = mSelectPointRect; final Drawable dNormal = mNormalDrawable; final Drawable dSelect = mSelectDrawable; int left = (width - (margin * (count - 1) + normalRc.width() * (count - 1) + selectRc.width())) / 2; int top = 0; for (int index = 0; index < count; ++index) { if (index == selIndex) { if (null != dSelect) { top = (height - selectRc.height()) / 2; selectRc.offsetTo(left, top); dSelect.setBounds(selectRc); dSelect.draw(canvas); } left += (selectRc.width() + margin); } else { if (null != dNormal) { top = (height - normalRc.height()) / 2; normalRc.offsetTo(left, top); dNormal.setBounds(normalRc); dNormal.draw(canvas); } left += (normalRc.width() + margin); } } }
From source file:com.vnidens.clickableedittext.ClickableEditTextHelper.java
private boolean isTouchInside(@NonNull View v, int xTouch, int yTouch, int drawablePosition) { Rect iconRect; int viewPaddingStart = ViewCompat.getPaddingStart(v); int viewPaddingEnd = ViewCompat.getPaddingEnd(v); int ltDirection = ViewCompat.getLayoutDirection(v); switch (drawablePosition) { case DRAWABLE_POSITION_START: if (startButtonDrawable == null || onStartButtonClickListener == null) { return false; }//w w w. j a va2s . c om iconRect = startButtonDrawable.copyBounds(); break; case DRAWABLE_POSITION_END: if (endButtonDrawable == null || onEndButtonClickListener == null) { return false; } iconRect = endButtonDrawable.copyBounds(); break; default: return false; } int viewCenterVertical = v.getPaddingTop() + ((v.getHeight() - v.getPaddingBottom()) - v.getPaddingTop()) / 2; if ((drawablePosition == DRAWABLE_POSITION_START && ltDirection == ViewCompat.LAYOUT_DIRECTION_LTR) || (drawablePosition == DRAWABLE_POSITION_END && ltDirection == ViewCompat.LAYOUT_DIRECTION_RTL)) { iconRect.offsetTo(viewPaddingStart, viewCenterVertical - iconRect.centerY()); } else if ((drawablePosition == DRAWABLE_POSITION_START && ltDirection == ViewCompat.LAYOUT_DIRECTION_RTL) || (drawablePosition == DRAWABLE_POSITION_END && ltDirection == ViewCompat.LAYOUT_DIRECTION_LTR)) { iconRect.offsetTo(v.getWidth() - viewPaddingEnd - iconRect.width(), viewCenterVertical - iconRect.centerY()); } else { return false; } iconRect.left = iconRect.left - extraTouchableAreaPx; iconRect.right = iconRect.right + extraTouchableAreaPx; iconRect.top = iconRect.top - extraTouchableAreaPx; iconRect.bottom = iconRect.bottom + extraTouchableAreaPx; return iconRect.contains(xTouch, yTouch); }
From source file:org.androfarsh.widget.DragGridLayout.java
public Cell findFreeCell(int rows, int cols, Region freeRegion) { if (mCells.isEmpty()) { return null; }/*from ww w.ja v a2 s . com*/ final Rect boundRect = new Rect(); final Rect rect = new Rect(0, 0, cols * mCellSize, rows * mCellSize); for (final Cell cell : mCells) { mTmpRegion.set(freeRegion); rect.offsetTo(cell.rect.left, cell.rect.top); mTmpRegion.op(rect, Op.INTERSECT); if (!mTmpRegion.isEmpty() && mTmpRegion.isRect()) { mTmpRegion.getBounds(boundRect); if ((boundRect.width() == rect.width()) && (boundRect.height() == rect.height())) { return cell; } } } return null; }
From source file:com.android.launcher3.Workspace.java
private static Rect getDrawableBounds(Drawable d) { Rect bounds = new Rect(); d.copyBounds(bounds);/* w ww .ja v a 2 s . c o m*/ if (bounds.width() == 0 || bounds.height() == 0) { bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } else { bounds.offsetTo(0, 0); } if (d instanceof PreloadIconDrawable) { int inset = -((PreloadIconDrawable) d).getOutset(); bounds.inset(inset, inset); } return bounds; }