List of usage examples for android.graphics Rect centerY
public final int centerY()
From source file:andoridhost.imczy.com.activitymaterial.custom.ChangePosition.java
@Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; }/* www.ja va 2 s . c om*/ if (startValues.view.getId() > 0) { Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION); Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION); final View view = endValues.view; Log.e(TAG, "createAnimator: startRect = " + startRect + " , endRect = " + endRect); Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(), endRect.centerX(), endRect.centerY()); int radius = startRect.centerY() - endRect.centerY(); ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position", new PointF(endRect.centerX(), endRect.centerY())), null, changePosPath); objectAnimator.setInterpolator(new FastOutSlowInInterpolator()); return objectAnimator; } return null; }
From source file:andoridhost.imczy.com.activitymaterial.custom.ReturnChangePosition.java
@Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; }/*www. j av a2s. c o m*/ if (startValues.view.getId() > 0) { Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION); Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION); final View view = endValues.view; Log.e(TAG, "createAnimator: startRect = " + startRect + " , endRect = " + endRect); Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(), endRect.centerX(), endRect.centerY() - endRect.height() / 2); int radius = startRect.centerY() - endRect.centerY(); Log.e(TAG, "createAnimator: startRect center x = " + startRect.centerX() + " , centerY= " + startRect.centerY()); Log.w(TAG, "createAnimator: end rect center x = " + endRect.centerX() + " , centerY= " + endRect.centerY()); ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position", new PointF(startRect.centerX(), startRect.centerY())), null, changePosPath); objectAnimator.setInterpolator(new FastOutSlowInInterpolator()); return objectAnimator; } return null; }
From source file:com.android.camera.HighlightView.java
public int getHit(float x, float y) { Rect r = computeLayout(); final float hysteresis = 20F; int retval = GROW_NONE; if (mCircle) { float distX = x - r.centerX(); float distY = y - r.centerY(); int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY); int radius = mDrawRect.width() / 2; int delta = distanceFromCenter - radius; if (Math.abs(delta) <= hysteresis) { if (Math.abs(distY) > Math.abs(distX)) { if (distY < 0) { retval = GROW_TOP_EDGE; } else { retval = GROW_BOTTOM_EDGE; }//from w w w. j av a 2 s . c om } else { if (distX < 0) { retval = GROW_LEFT_EDGE; } else { retval = GROW_RIGHT_EDGE; } } } else if (distanceFromCenter < radius) { retval = MOVE; } else { retval = GROW_NONE; } } else { // verticalCheck makes sure the position is between the top and // the bottom edge (with some tolerance). Similar for horizCheck. boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis); boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis); // Check whether the position is near some edge(s). if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) { retval |= GROW_LEFT_EDGE; } if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) { retval |= GROW_RIGHT_EDGE; } if ((Math.abs(r.top - y) < hysteresis) && horizCheck) { retval |= GROW_TOP_EDGE; } if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) { retval |= GROW_BOTTOM_EDGE; } // Not near any edge but inside the rectangle: move. if (retval == GROW_NONE && r.contains((int) x, (int) y)) { retval = MOVE; } } return retval; }
From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); if (mBounds == null) { mBounds = new Rect(); }/* w w w .j a v a 2 s.co m*/ int size = Math.min(bounds.height(), bounds.width()); mBounds.left = bounds.centerX() - size / 2; mBounds.right = mBounds.left + size; mBounds.top = bounds.centerY() - size / 2; mBounds.bottom = mBounds.top + size; configureBounds(); }
From source file:com.example.gatsu.theevent.HighlightView.java
public int getHit(float x, float y) { Rect r = computeLayout(); final float hysteresis = 20F; int retval = GROW_NONE; if (mCircle) { float distX = x - r.centerX(); float distY = y - r.centerY(); int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY); int radius = mDrawRect.width() / 2; int delta = distanceFromCenter - radius; if (Math.abs(delta) <= hysteresis) { if (Math.abs(distY) > Math.abs(distX)) { if (distY < 0) { retval = GROW_TOP_EDGE; } else { retval = GROW_BOTTOM_EDGE; }//w w w .j a va2 s . c o m } else { if (distX < 0) { retval = GROW_LEFT_EDGE; } else { retval = GROW_RIGHT_EDGE; } } } else if (distanceFromCenter < radius) { retval = MOVE; } else { retval = GROW_NONE; } } else { // verticalCheck makes sure the position is between the top and // the bottom edge (with some tolerance). Similar for horizCheck. boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis); boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis); // Check whether the position is near some edge(s). if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) { retval |= GROW_LEFT_EDGE; } if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) { retval |= GROW_RIGHT_EDGE; } if ((Math.abs(r.top - y) < hysteresis) && horizCheck) { retval |= GROW_TOP_EDGE; } if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) { retval |= GROW_BOTTOM_EDGE; } // Not near any edge but inside the rectangle: move. if (retval == GROW_NONE && r.contains((int) x, (int) y)) { retval = MOVE; } } return retval; }
From source file:org.mozilla.search.MainActivity.java
/** * Animates search suggestion to search bar. This animation has 2 main parts: * * 1) Vertically translate query text from suggestion card to search bar. * 2) Expand suggestion card to fill the results view area. * * @param query/* w ww .jav a 2 s .c om*/ * @param suggestionAnimation */ private void animateSuggestion(final String query, final SuggestionAnimation suggestionAnimation) { animationText.setText(query); final Rect startBounds = suggestionAnimation.getStartBounds(); final Rect endBounds = new Rect(); animationCard.getGlobalVisibleRect(endBounds, null); // Vertically translate the animated card to align with the start bounds. final float cardStartY = startBounds.centerY() - endBounds.centerY(); // Account for card background padding when calculating start scale. final float startScaleX = (float) (startBounds.width() - cardPaddingX * 2) / endBounds.width(); final float startScaleY = (float) (startBounds.height() - cardPaddingY * 2) / endBounds.height(); animationText.setVisibility(View.VISIBLE); animationCard.setVisibility(View.VISIBLE); final AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(animationText, "translationY", startBounds.top, textEndY), ObjectAnimator.ofFloat(animationCard, "translationY", cardStartY, 0), ObjectAnimator.ofFloat(animationCard, "alpha", 0.5f, 1), ObjectAnimator.ofFloat(animationCard, "scaleX", startScaleX, 1f), ObjectAnimator.ofFloat(animationCard, "scaleY", startScaleY, 1f)); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { setEditState(EditState.WAITING); setSearchState(SearchState.POSTSEARCH); editText.setText(query); // We need to manually clear the animation for the views to be hidden on gingerbread. animationText.clearAnimation(); animationCard.clearAnimation(); animationText.setVisibility(View.INVISIBLE); animationCard.setVisibility(View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); set.setDuration(SUGGESTION_TRANSITION_DURATION); set.setInterpolator(SUGGESTION_TRANSITION_INTERPOLATOR); set.start(); }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
private void drawSun(Canvas canvas, float pct) { // Draw the dots canvas.drawCircle(mBezier1x, mBezier1y, mDotRadius, mDotPaint); canvas.drawCircle(mBezier4x, mBezier4y, mDotRadius, mDotPaint); // calculate the center point of the sun image float x = bezierInterpolation(pct, mBezier1x, mBezier2x, mBezier3x, mBezier4x); float y = bezierInterpolation(pct, mBezier1y, mBezier2y, mBezier3y, mBezier4y); Rect sunBounds = mSunImage.getBounds(); x -= sunBounds.width() / 2;/*from w w w . ja v a 2 s.co m*/ y -= sunBounds.height() / 2; // if we are in rtl, we still want to show the image normally // so flip it back canvas.translate(x, y); if (mIsRtl) { canvas.save(); canvas.scale(-1, 1, sunBounds.centerX(), sunBounds.centerY()); } // draw the sun image mSunImage.draw(canvas); // restore the flip again if (mIsRtl) { canvas.restore(); } canvas.translate(-x, -y); }
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 ww .jav a2s . c o 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:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java
@Override public void doDraw(Canvas canvas, Paint paint) { Rect bounds = getBounds(); int size = Math.min(bounds.width(), bounds.height()); float scale = mCurrentScale; int rippleColor = mRippleColor; int bgColor = mRippleBgColor; float radius = (size / 2); float radiusAnimated = radius * scale; if (scale > INACTIVE_SCALE) { if (bgColor != 0) { paint.setColor(bgColor);//from w w w. j av a 2 s.co m paint.setAlpha(decreasedAlpha(Color.alpha(bgColor))); canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint); } if (rippleColor != 0) { paint.setColor(rippleColor); paint.setAlpha(modulateAlpha(Color.alpha(rippleColor))); canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint); } } }
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); }//from w w w . j av a 2 s . com 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; } }