Example usage for java.lang Math hypot

List of usage examples for java.lang Math hypot

Introduction

In this page you can find the example usage for java.lang Math hypot.

Prototype

public static double hypot(double x, double y) 

Source Link

Document

Returns sqrt(x2 +y2) without intermediate overflow or underflow.

Usage

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

/**
 * Calculate the duration for the transition depending upon how far the text has to move.
 *//*from w ww.  j  ava  2 s.  c om*/
private long calculateDuration(@NonNull Rect startPosition, @NonNull Rect endPosition) {
    float distance = (float) Math.hypot(startPosition.exactCenterX() - endPosition.exactCenterX(),
            startPosition.exactCenterY() - endPosition.exactCenterY());
    long duration = (long) (1000 * (distance / velocity));
    return Math.max(minDuration, Math.min(maxDuration, duration));
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private float smallestDistanceToPath(Path path, float x, float y) {
    PathMeasure measure = new PathMeasure(path, false);
    float pos[] = { 0f, 0f };
    float minDist = 1000f;
    float dist;//from   ww  w  . j a  v  a  2  s . c o m

    for (int i = 0; i < measure.getLength(); ++i) {
        measure.getPosTan(i, pos, null);
        dist = (float) Math.hypot(x - pos[0], y - pos[1]);
        if (dist < minDist)
            minDist = dist;
    }
    return minDist;
}

From source file:br.liveo.searchliveo.SearchLiveo.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showAnimation() {
    try {/*from   w  w  w . jav a  2s .c o  m*/

        if (getStatusBarShowColor() != -1) {
            mContext.getWindow().setStatusBarColor(getStatusBarShowColor());
        } else {
            mContext.getWindow()
                    .setStatusBarColor(ContextCompat.getColor(mContext, R.color.search_liveo_primary_dark));
        }

        final Animator animator = ViewAnimationUtils.createCircularReveal(mViewSearch,
                mViewSearch.getWidth() - (int) dpToPixel(24, this.mContext), (int) dpToPixel(23, this.mContext),
                0, (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight()));
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                                .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                                        InputMethodManager.HIDE_IMPLICIT_ONLY);
                    }
                });
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        animator.setDuration(300);
        animator.start();
    } catch (Exception e) {
        e.getStackTrace();
        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                        .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            }
        });
    }

    mViewSearch.setVisibility(View.VISIBLE);
}

From source file:br.liveo.searchliveo.SearchCardLiveo.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showAnimation() {
    try {/*from  w  w  w .  ja  v  a  2 s.c o m*/

        if (getStatusBarShowColor() != -1) {
            mContext.getWindow().setStatusBarColor(getStatusBarShowColor());
        } else {
            mContext.getWindow()
                    .setStatusBarColor(ContextCompat.getColor(mContext, R.color.search_liveo_primary_dark));
        }

        final Animator animator = ViewAnimationUtils.createCircularReveal(mCardSearch,
                mCardSearch.getWidth() - (int) dpToPixel(24, this.mContext), (int) dpToPixel(23, this.mContext),
                0, (float) Math.hypot(mCardSearch.getWidth(), mCardSearch.getHeight()));
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                                .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                                        InputMethodManager.HIDE_IMPLICIT_ONLY);
                    }
                });
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        animator.setDuration(300);
        animator.start();
    } catch (Exception e) {
        e.getStackTrace();
        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                        .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            }
        });
    }

    mCardSearch.setVisibility(View.VISIBLE);
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static int getEnclosingCircleRadius(View v, int cx, int cy) {
    int realCenterX = cx + v.getLeft();
    int realCenterY = cy + v.getTop();
    int distanceTopLeft = (int) Math.hypot(realCenterX - v.getLeft(), realCenterY - v.getTop());
    int distanceTopRight = (int) Math.hypot(v.getRight() - realCenterX, realCenterY - v.getTop());
    int distanceBottomLeft = (int) Math.hypot(realCenterX - v.getLeft(), v.getBottom() - realCenterY);
    int distanceBotomRight = (int) Math.hypot(v.getRight() - realCenterX, v.getBottom() - realCenterY);

    int[] distances = new int[] { distanceTopLeft, distanceTopRight, distanceBottomLeft, distanceBotomRight };
    int radius = distances[0];
    for (int i = 1; i < distances.length; i++) {
        if (distances[i] > radius)
            radius = distances[i];//  w w w .j a  va  2  s. co m
    }
    return radius;
}

From source file:com.hippo.ehviewer.ui.scene.GalleryDetailScene.java

private boolean createCircularReveal() {
    if (mColorBg == null) {
        return false;
    }/*from   ww  w .java  2  s.  c  om*/

    int w = mColorBg.getWidth();
    int h = mColorBg.getHeight();
    if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) {
        ViewAnimationUtils.createCircularReveal(mColorBg, w / 2, h / 2, 0, (float) Math.hypot(w / 2, h / 2))
                .setDuration(300).start();
        return true;
    } else {
        return false;
    }
}

From source file:br.liveo.searchliveo.SearchLiveo.java

private SearchLiveo hideAnimation() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        if (getStatusBarHideColor() != -1) {
            mContext.getWindow().setStatusBarColor(getStatusBarHideColor());
        } else {/*from   ww w.j av  a 2  s .co m*/
            mContext.getWindow().setStatusBarColor(getColorPrimaryDark());
        }

        final Animator animatorHide = ViewAnimationUtils.createCircularReveal(mViewSearch,
                mViewSearch.getWidth() - (int) dpToPixel(24, mContext), (int) dpToPixel(23, mContext),
                (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight()), 0);
        animatorHide.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                                .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
                    }
                });
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mViewSearch.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorHide.setDuration(200);
        animatorHide.start();

    } else {

        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
            }
        });

        Animation mFadeOut = AnimationUtils.loadAnimation(mContext.getApplicationContext(),
                android.R.anim.fade_out);
        mViewSearch.setAnimation(mFadeOut);
        mViewSearch.setVisibility(View.INVISIBLE);
    }

    mEdtSearch.setText("");
    mViewSearch.setEnabled(false);
    return this;
}

From source file:br.liveo.searchliveo.SearchCardLiveo.java

private SearchCardLiveo hideAnimation() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        if (getStatusBarHideColor() != -1) {
            mContext.getWindow().setStatusBarColor(getStatusBarHideColor());
        } else {/*from  w  w  w .  j  a v  a  2s  .  co  m*/
            mContext.getWindow().setStatusBarColor(getColorPrimaryDark());
        }

        final Animator animatorHide = ViewAnimationUtils.createCircularReveal(mCardSearch,
                mCardSearch.getWidth() - (int) dpToPixel(24, mContext), (int) dpToPixel(23, mContext),
                (float) Math.hypot(mCardSearch.getWidth(), mCardSearch.getHeight()), 0);
        animatorHide.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                                .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
                    }
                });
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mCardSearch.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorHide.setDuration(200);
        animatorHide.start();

    } else {

        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
            }
        });

        Animation mFadeOut = AnimationUtils.loadAnimation(mContext.getApplicationContext(),
                android.R.anim.fade_out);
        mCardSearch.setAnimation(mFadeOut);
        mCardSearch.setVisibility(View.INVISIBLE);
    }

    mEdtSearch.setText("");
    mCardSearch.setEnabled(false);
    return this;
}

From source file:com.android.launcher3.folder.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer))
        return;//from w ww.  j  av  a 2 s.co m

    mContent.completePendingPageChanges();
    if (!mDragInProgress) {
        // Open on the first page.
        mContent.snapToPageImmediately(0);
    }

    // This is set to true in close(), but isn't reset to false until onDropCompleted(). This
    // leads to an inconsistent state if you drag out of the folder and drag back in without
    // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
    mDeleteFolderOnDropCompleted = false;

    Animator openFolderAnim = null;
    final Runnable onCompleteRunnable;
    if (!Utilities.ATLEAST_LOLLIPOP) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 1, 1, 1);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat(TRANSLATION_X, transX, 0);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat(TRANSLATION_Y, transY, 0);

        Animator drift = ObjectAnimator.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.hypot(rx, ry);

        Animator reveal = new CircleRevealOutlineProvider((int) getPivotX(), (int) getPivotY(), 0, radius)
                .createRevealAnimator(this);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mContent.setAlpha(0f);
        Animator iconsAlpha = ObjectAnimator.ofFloat(mContent, "alpha", 0f, 1f);
        iconsAlpha.setDuration(mMaterialExpandDuration);
        iconsAlpha.setStartDelay(mMaterialExpandStagger);
        iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        mFooter.setAlpha(0f);
        Animator textAlpha = ObjectAnimator.ofFloat(mFooter, "alpha", 0f, 1f);
        textAlpha.setDuration(mMaterialExpandDuration);
        textAlpha.setStartDelay(mMaterialExpandStagger);
        textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        anim.play(drift);
        anim.play(iconsAlpha);
        anim.play(textAlpha);
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        mFooter.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
                mFooter.setLayerType(LAYER_TYPE_NONE, null);
                mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            Utilities.sendCustomAccessibilityEvent(Folder.this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    mContent.getAccessibilityDescription());
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            onCompleteRunnable.run();
            mContent.setFocusOnFirstChild();
        }
    });

    // Footer animation
    if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
        int footerWidth = mContent.getDesiredWidth() - mFooter.getPaddingLeft() - mFooter.getPaddingRight();

        float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
        float translation = (footerWidth - textWidth) / 2;
        mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation);
        mPageIndicator.prepareEntryAnimation();

        // Do not update the flag if we are in drag mode. The flag will be updated, when we
        // actually drop the icon.
        final boolean updateAnimationFlag = !mDragInProgress;
        openFolderAnim.addListener(new AnimatorListenerAdapter() {

            @SuppressLint("InlinedApi")
            @Override
            public void onAnimationEnd(Animator animation) {
                mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION).translationX(0)
                        .setInterpolator(Utilities.ATLEAST_LOLLIPOP
                                ? AnimationUtils.loadInterpolator(mLauncher,
                                        android.R.interpolator.fast_out_slow_in)
                                : new LogDecelerateInterpolator(100, 0));
                mPageIndicator.playEntryAnimation();

                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher);
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }

    mPageIndicator.stopAllAnimations();
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }

    mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}

From source file:com.example.SmartBoard.DrawingView.java

public void onDrawCircle(Canvas canvas) {
    Paint paint = drawPaint;//  w  w  w  . ja v a2s .  co m
    if (points[3] == null) //point4 null when user did not touch and move on screen.
        return;
    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }

    float cx = (left + right) / 2f;
    float cy = (top + bottom) / 2f;
    float radius = (float) Math.hypot(top - bottom, right - left) / 2f;

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    // paint.setColor(Color.parseColor("#AADB1255"));
    paint.setStrokeWidth(5);

    if (finished) {

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("id", key);
            objectProperties.put("type", "Circle");
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("radius", radius);
            objectProperties.put("x", cx);
            objectProperties.put("y", cy);

        } catch (JSONException e) {

        }

        objectDrawables.put(key, objectProperties);

        //  drawCanvas.drawCircle(cx, cy, radius, paint);

        //   drawCanvas.save();
        //  mqtt.publishRectangle(objectProperties);
        mqtt.publishCircle(objectProperties);

        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;

    }

    canvas.drawCircle(cx, cy, radius, paint);
    // draw the balls on the canvas
    //  paint.setColor(Color.BLUE);
    paint.setTextSize(18);
    paint.setStrokeWidth(0);
    // paint.setColor(Color.BLUE);
    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);

        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}