Example usage for android.graphics Rect centerX

List of usage examples for android.graphics Rect centerX

Introduction

In this page you can find the example usage for android.graphics Rect centerX.

Prototype

public final int centerX() 

Source Link

Usage

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 ww  . ja v a 2 s  .c  o  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: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);// w  ww  .  j av  a  2s.c o 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.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java

/**
 * Maps {@link Rect} face bounds from Camera 2 API towards the model used throughout the samples
 * then passes the RecognisedFace object back
 * @param faceBounds//from   w ww .j a v a 2s  . com
 * @param leftEyePosition
 * @param rightEyePosition
 */
private Face mapCameraFaceToCanvas(Rect faceBounds, Point leftEyePosition, Point rightEyePosition) {
    if (isViewAvailable()) {
        int w = faceBounds.width();
        int h = faceBounds.height();
        Face face = new Face(faceBounds.centerX() - w, faceBounds.centerY(), w, h);
        if (leftEyePosition != null) {
            face.setIrisLeft(leftEyePosition.x, leftEyePosition.y);
        }
        return face;
    }
    return new Face();
}

From source file:com.acious.android.paginationseekbar.internal.PopupIndicator.java

public void showIndicator(View parent, Rect touchBounds) {
    if (isShowing()) {
        mPopupView.mMarker.animateOpen();
        return;//from ww  w .ja  v  a2  s.  c o m
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
        WindowManager.LayoutParams p = createPopupLayout(windowToken);

        p.gravity = Gravity.TOP | GravityCompat.START;
        updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
        mShowing = true;

        translateViewIntoPosition(touchBounds.centerX());
        invokePopup(p);
    }
}

From source file:com.app.jdy.ui.MyFaceActivity.java

@SuppressLint("NewApi")
private void showLineTooltip(int setIndex, int entryIndex, Rect rect) {

    mLineTooltip = (TextView) getLayoutInflater().inflate(R.layout.circular_tooltip, null);
    mLineTooltip.setText(Integer.toString((int) lineValues[setIndex][entryIndex]));

    LayoutParams layoutParams = new LayoutParams((int) Tools.fromDpToPx(35), (int) Tools.fromDpToPx(35));
    layoutParams.leftMargin = rect.centerX() - layoutParams.width / 2;
    layoutParams.topMargin = rect.centerY() - layoutParams.height / 2;
    mLineTooltip.setLayoutParams(layoutParams);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        mLineTooltip.setPivotX(layoutParams.width / 2);
        mLineTooltip.setPivotY(layoutParams.height / 2);
        mLineTooltip.setAlpha(0);//from   w  w w . ja  va2s  .  co m
        mLineTooltip.setScaleX(0);
        mLineTooltip.setScaleY(0);
        mLineTooltip.animate().setDuration(150).alpha(1).scaleX(1).scaleY(1).rotation(360)
                .setInterpolator(enterInterpolator);
    }

    mLineChart.showTooltip(mLineTooltip);
}

From source file:com.app.jdy.ui.MyCommunityActivity.java

@SuppressLint("NewApi")
private void showLineTooltip(int setIndex, int entryIndex, Rect rect) {

    mLineTooltip = (TextView) getLayoutInflater().inflate(R.layout.circular_tooltip, null);
    mLineTooltip.setText(Integer.toString((int) lineValues[setIndex][entryIndex]));

    LayoutParams layoutParams = new LayoutParams((int) Tools.fromDpToPx(35), (int) Tools.fromDpToPx(35));
    layoutParams.leftMargin = rect.centerX() - layoutParams.width / 2;
    layoutParams.topMargin = rect.centerY() - layoutParams.height / 2;
    mLineTooltip.setLayoutParams(layoutParams);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        mLineTooltip.setPivotX(layoutParams.width / 2);
        mLineTooltip.setPivotY(layoutParams.height / 2);
        mLineTooltip.setAlpha(0);/*from   w w w  . j ava 2s .  com*/
        mLineTooltip.setScaleX(0);
        mLineTooltip.setScaleY(0);
        mLineTooltip.animate().setDuration(150).alpha(1).scaleX(1).scaleY(1).rotation(360)
                .setInterpolator(enterInterpolator);
    }

    my_community_linechart.showTooltip(mLineTooltip);
}

From source file:com.hezaijin.advance.widgets.view.progress.internal.PopupIndicator.java

public void showIndicator(View parent, Rect touchBounds) {
    if (isShowing()) {
        mPopupView.mMarker.animateOpen();
        return;//from w w  w .j a  va2  s  .com
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
        WindowManager.LayoutParams p = createPopupLayout(windowToken);
        p.gravity = Gravity.TOP | GravityCompat.START;
        updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
        mShowing = true;

        translateViewIntoPosition(touchBounds.centerX());
        invokePopup(p);
    }
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*  www.j  a va 2s .c  o m*/
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.itsronald.widget.IndicatorDotPathView.java

@NonNull
private Animator retreatConnectedPathAnimator(@NonNull IndicatorDotView fromDot,
        @NonNull IndicatorDotView toDot) {
    Rect endDotBounds = viewRectInNeighborCoords(toDot, fromDot);
    float toX = endDotBounds.left;
    float toY = endDotBounds.top;
    final Animator dotRetreatAnimator = retreatDotAnimator(fromDot, toX, toY, PATH_RETREAT_ANIM_DURATION);

    endDotBounds = viewRectInNeighborCoords(toDot, centerSegment);
    toX = endDotBounds.centerX() <= 0 ? 0 : centerSegment.getWidth();
    toY = endDotBounds.centerY() <= 0 ? 0 : centerSegment.getHeight();
    final Animator pathRetreatAnimator = retreatCenterSegmentAnimator(toX, toY, PATH_RETREAT_ANIM_DURATION);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(dotRetreatAnimator, pathRetreatAnimator);
    return animatorSet;
}

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from  w  ww.j  av a 2  s.co m*/
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}