Example usage for android.graphics Rect centerY

List of usage examples for android.graphics Rect centerY

Introduction

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

Prototype

public final int centerY() 

Source Link

Usage

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/*  w w  w. j  a v a2 s.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.itsronald.widget.IndicatorDotPathView.java

@NonNull
Animator connectPathAnimator() {// www.  j av a  2 s.c  om
    final Rect startSegmentBounds = viewRectInNeighborCoords(startPathSegment, endPathSegment);
    final Rect endSegmentBounds = viewRectInNeighborCoords(endPathSegment, startPathSegment);

    final int startSegmentToX = endSegmentBounds.centerX() < 0 ? endSegmentBounds.left : endSegmentBounds.right;
    final int startSegmentToY = endSegmentBounds.centerY() < 0 ? endSegmentBounds.top : endSegmentBounds.bottom;
    final int endSegmentToX = startSegmentBounds.centerX() < 0 ? startSegmentBounds.left
            : startSegmentBounds.right;
    final int endSegmentToY = startSegmentBounds.centerY() < 0 ? startSegmentBounds.top
            : startSegmentBounds.bottom;

    final Animator startSegmentAnimator = startPathSegment.stretchAnimator(PATH_STRETCH_ANIM_DURATION,
            startSegmentToX, startSegmentToY);
    final Animator endSegmentAnimator = endPathSegment.stretchAnimator(PATH_STRETCH_ANIM_DURATION,
            endSegmentToX, endSegmentToY);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(startSegmentAnimator, endSegmentAnimator, centerSegmentGrowAnimator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            startDot.setVisibility(VISIBLE);
            endDot.setVisibility(VISIBLE);
        }
    });

    return animatorSet;
}

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.j a  v a2  s.c  o  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);/* w  w w . j  a v  a  2 s.co m*/
        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.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);// ww  w  .j ava2 s  .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.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 ww  w.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) {
            if (Build.VERSION.SDK_INT >= 16) {
                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.waz.zclient.pages.main.profile.camera.CameraFragment.java

@Override
public void onFocus(Rect focusArea) {
    focusView.setColor(getControllerFactory().getAccentColorController().getColor());
    int x = focusArea.centerX();
    int y = focusArea.centerY();
    focusView.setX(x - focusView.getWidth() / 2);
    focusView.setY(y - focusView.getHeight() / 2);
    focusView.showFocusView();//from   ww w . j  av  a  2s  .  co m
}

From source file:android.support.transition.SidePropagation.java

@Override
public long getStartDelay(ViewGroup sceneRoot, Transition transition, TransitionValues startValues,
        TransitionValues endValues) {/*  w  ww.j  a  v a 2 s  . com*/
    if (startValues == null && endValues == null) {
        return 0;
    }
    int directionMultiplier = 1;
    Rect epicenter = transition.getEpicenter();
    TransitionValues positionValues;
    if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) {
        positionValues = startValues;
        directionMultiplier = -1;
    } else {
        positionValues = endValues;
    }

    int viewCenterX = getViewX(positionValues);
    int viewCenterY = getViewY(positionValues);

    int[] loc = new int[2];
    sceneRoot.getLocationOnScreen(loc);
    int left = loc[0] + Math.round(sceneRoot.getTranslationX());
    int top = loc[1] + Math.round(sceneRoot.getTranslationY());
    int right = left + sceneRoot.getWidth();
    int bottom = top + sceneRoot.getHeight();

    int epicenterX;
    int epicenterY;
    if (epicenter != null) {
        epicenterX = epicenter.centerX();
        epicenterY = epicenter.centerY();
    } else {
        epicenterX = (left + right) / 2;
        epicenterY = (top + bottom) / 2;
    }

    float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right,
            bottom);
    float maxDistance = getMaxDistance(sceneRoot);
    float distanceFraction = distance / maxDistance;

    long duration = transition.getDuration();
    if (duration < 0) {
        duration = 300;
    }

    return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction);
}

From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java

/**
 * Pulls the bitmap image of the body part out of its RelativeLayout, colors it appropriatly,
 * and then tells the zoomLayout where it needs to zoom to. Also swaps the FRONT/BACK buttons
 * for the ADD/DELETE buttons./*from  ww w  .  j av a2  s  . c  om*/
 *
 * @param image the body part the touch occured in.
 */
private void zoomOnImage(RelativeLayout image) {

    Bitmap bitm = ((BitmapDrawable) image.getBackground()).getBitmap();

    Bitmap temp = bitm.copy(bitm.getConfig(), true);
    int[] pixels = new int[temp.getHeight() * temp.getWidth()];

    temp.getPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());

    for (int i = 0; i < temp.getHeight() * temp.getWidth(); i++) {

        if (pixels[i] != 0) {

            int r, g, b;

            if (!blue) {
                r = Color.red(pixels[i]) + 100;
                if (r > 255) {
                    r = 255;
                }
                g = Color.green(pixels[i]) - 50;
                b = Color.blue(pixels[i]) - 50;
            } else {
                r = Color.red(pixels[i]) - 30;
                g = Color.green(pixels[i]) + 15;
                b = Color.blue(pixels[i]) + 100;
                if (b > 255) {
                    b = 255;
                }

            }
            pixels[i] = Color.argb(Color.alpha(pixels[i]), r, g, b);
        }
    }

    temp.setPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());
    image.setBackground(new BitmapDrawable(getResources(), temp));

    Rect rect = new Rect();
    image.getGlobalVisibleRect(rect);

    zoomLayout.zoomToRect(rect, 0, getYOffset());
    current = image;
    zoomed = true;
    swapButtons();

    placePointer(rect.centerX(), rect.centerY());

}