List of usage examples for java.lang Math hypot
public static double hypot(double x, double y)
From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { // if we're showing search mRecyclerView, circular hide them if (mResultsContainer.getHeight() > 0) { ViewCompat.animate(mResultsContainer).alpha(0.f).setDuration(400L).setInterpolator(LINEAR_OUT_SLOW_INT) .start();// w w w.j a v a2 s .c o m Animator closeResults = ViewAnimationUtils.createCircularReveal(mResultsContainer, mSearchIconCenterX, 0, (float) Math.hypot(mSearchIconCenterX, mResultsContainer.getHeight()), 0f); closeResults.setDuration(500L); closeResults.setInterpolator(LINEAR_OUT_SLOW_INT); closeResults.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mResultsContainer.setVisibility(View.INVISIBLE); } }); closeResults.start(); } // translate the icon to match position in the launching activity ViewCompat.animate(mSearchNavButtonContainer).translationX(mSearchBackDistanceX).alpha(0.f) .setDuration(600L).setInterpolator(LINEAR_OUT_SLOW_INT) .setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationEnd(View view) { ActivityCompat.finishAfterTransition(SearchActivity.this); } }).start(); // transform from back icon to search icon mSearchNavButton.setImageResource(R.drawable.ic_search_24dp_black); // clear the background else the touch ripple moves with the translation which looks bad mSearchNavButton.setBackground(null); // fade out the other search chrome ViewCompat.animate(mSearchView).alpha(0f).setStartDelay(0L).setDuration(120L) .setInterpolator(LINEAR_OUT_SLOW_INT).setListener(null).start(); ViewCompat.animate(mSearchBackground).alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(LINEAR_OUT_SLOW_INT).setListener(null).start(); if (ViewCompat.getZ(mSearchToolbar) != 0f) { ViewCompat.animate(mSearchToolbar).z(0f).setDuration(600L).setInterpolator(LINEAR_OUT_SLOW_INT).start(); } // fade out the mScrim ViewCompat.animate(mScrim).alpha(0f).setDuration(400L).setInterpolator(LINEAR_OUT_SLOW_INT) .setListener(null).start(); }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
private void startUnlock(boolean animate) { if (animate) { // Calculate longest distance between center of // the circle and view's corners. float distance = 0f; int[] corners = new int[] { 0, 0, // top left 0, getHeight(), // bottom left getWidth(), getHeight(), // bottom right getWidth(), 0 // top right };/*from w w w . ja v a 2 s .c o m*/ for (int i = 0; i < corners.length; i += 2) { double c = Math.hypot(mPoint[0] - corners[i], mPoint[1] - corners[i + 1]); if (c > distance) distance = (float) c; } distance = (float) (Math.pow(distance / 50f, 2) * 50f); startAnimatorBy(mRadius, distance, mShortAnimTime); } final int delayUnlock = animate ? mShortAnimTime - 10 : 0; mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessage(ACTION_UNLOCK_START); mHandler.sendEmptyMessageDelayed(ACTION_UNLOCK, delayUnlock); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java
/** * test hypot/*w w w.j a v a 2 s. com*/ */ @Test public final void hypot() { final Random l_random = new Random(); final List<Double> l_input = IntStream.range(0, 100).mapToDouble(i -> l_random.nextGaussian()).boxed() .collect(Collectors.toList()); final List<ITerm> l_return = new ArrayList<>(); new CHypot().execute(false, IContext.EMPTYPLAN, l_input.stream().map(CRawTerm::from).collect(Collectors.toList()), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::<Number>raw).toArray(), StreamUtils.windowed(l_input.stream(), 2, 2).mapToDouble(i -> Math.hypot(i.get(0), i.get(1))) .boxed().toArray()); }
From source file:com.hannesdorfmann.search.SearchActivity.java
@OnClick(R.id.fab) protected void save() { // show the save confirmation bubble fab.setVisibility(View.INVISIBLE); confirmSaveContainer.setVisibility(View.VISIBLE); resultsScrim.setVisibility(View.VISIBLE); // expand it once it's been measured and show a scrim over the search results confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override// w w w . jav a 2 s . c o m public boolean onPreDraw() { // expand the confirmation confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this); Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer, confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2, fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2); reveal.setDuration(250L); reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); reveal.start(); // show the scrim int centerX = (fab.getLeft() + fab.getRight()) / 2; int centerY = (fab.getTop() + fab.getBottom()) / 2; Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0, (float) Math.hypot(centerX, centerY)); revealScrim.setDuration(400L); revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); revealScrim.start(); ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim)); fadeInScrim.setDuration(800L); fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); fadeInScrim.start(); // ease in the checkboxes saveDribbble.setAlpha(0.6f); saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f); saveDribbble.animate().alpha(1f).translationY(0f).setDuration(200L).setInterpolator(AnimationUtils .loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); saveDesignerNews.setAlpha(0.6f); saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f); saveDesignerNews.animate().alpha(1f).translationY(0f).setDuration(200L) .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); return false; } }); }
From source file:io.plaidapp.ui.SearchActivity.java
@OnClick(R.id.fab) protected void save() { // show the save confirmation bubble fab.setVisibility(View.INVISIBLE); confirmSaveContainer.setVisibility(View.VISIBLE); resultsScrim.setVisibility(View.VISIBLE); // expand it once it's been measured and show a scrim over the search results confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override// w w w . j av a2s . c o m public boolean onPreDraw() { // expand the confirmation confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this); Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer, confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2, fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2); reveal.setDuration(250L); reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); reveal.start(); // show the scrim int centerX = (fab.getLeft() + fab.getRight()) / 2; int centerY = (fab.getTop() + fab.getBottom()) / 2; Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0, (float) Math.hypot(centerX, centerY)); revealScrim.setDuration(400L); revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); revealScrim.start(); ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim)); fadeInScrim.setDuration(800L); fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); fadeInScrim.start(); // ease in the checkboxes saveDribbble.setAlpha(0.6f); saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f); saveDribbble.animate().alpha(1f).translationY(0f).setDuration(200L).setInterpolator(AnimationUtils .loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); saveDesignerNews.setAlpha(0.6f); saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f); saveDesignerNews.animate().alpha(1f).translationY(0f).setDuration(200L) .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); return false; } }); }
From source file:com.etmay.brescrollpager.ui.MyScroller.java
/** * Start scrolling based on a fling gesture. The distance travelled will * depend on the initial velocity of the fling. * * @param startX Starting point of the scroll (X) * @param startY Starting point of the scroll (Y) * @param velocityX Initial velocity of the fling (X) measured in pixels per * second.//from w w w.j ava 2 s . co m * @param velocityY Initial velocity of the fling (Y) measured in pixels per * second * @param minX Minimum X value. The scroller will not scroll past this * point. * @param maxX Maximum X value. The scroller will not scroll past this * point. * @param minY Minimum Y value. The scroller will not scroll past this * point. * @param maxY Maximum Y value. The scroller will not scroll past this * point. */ public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) { // Continue a scroll or fling in progress if (mFlywheel && !mFinished) { float oldVel = getCurrVelocity(); float dx = (float) (mFinalX - mStartX); float dy = (float) (mFinalY - mStartY); float hyp = (float) Math.hypot(dx, dy); float ndx = dx / hyp; float ndy = dy / hyp; float oldVelocityX = ndx * oldVel; float oldVelocityY = ndy * oldVel; if (Math.signum(velocityX) == Math.signum(oldVelocityX) && Math.signum(velocityY) == Math.signum(oldVelocityY)) { velocityX += oldVelocityX; velocityY += oldVelocityY; } } mMode = FLING_MODE; mFinished = false; float velocity = (float) Math.hypot(velocityX, velocityY); mVelocity = velocity; mDuration = getSplineFlingDuration(velocity); mStartTime = AnimationUtils.currentAnimationTimeMillis(); mStartX = startX; mStartY = startY; float coeffX = velocity == 0 ? 1.0f : velocityX / velocity; float coeffY = velocity == 0 ? 1.0f : velocityY / velocity; double totalDistance = getSplineFlingDistance(velocity); mDistance = (int) (totalDistance * Math.signum(velocity)); mMinX = minX; mMaxX = maxX; mMinY = minY; mMaxY = maxY; mFinalX = startX + (int) Math.round(totalDistance * coeffX); // Pin to mMinX <= mFinalX <= mMaxX mFinalX = Math.min(mFinalX, mMaxX); mFinalX = Math.max(mFinalX, mMinX); mFinalY = startY + (int) Math.round(totalDistance * coeffY); // Pin to mMinY <= mFinalY <= mMaxY mFinalY = Math.min(mFinalY, mMaxY); mFinalY = Math.max(mFinalY, mMinY); }
From source file:babbq.com.searchplace.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { // translate the icon to match position in the launching activity searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)) .setListener(new AnimatorListenerAdapter() { @Override/*from w w w .ja va 2 s . co m*/ public void onAnimationEnd(Animator animation) { finishAfterTransition(); } }).start(); // transform from back icon to search icon AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_back_to_search); searchBack.setImageDrawable(backToSearch); // clear the background else the touch ripple moves with the translation which looks bad searchBack.setBackground(null); backToSearch.start(); // fade out the other search chrome searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); if (searchToolbar.getZ() != 0f) { searchToolbar.animate().z(0f).setDuration(600L) .setInterpolator( AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .start(); } // if we're showing search results, circular hide them if (resultsContainer.getHeight() > 0) { Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0, (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f); closeResults.setDuration(500L); closeResults.setInterpolator( AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); closeResults.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resultsContainer.setVisibility(View.INVISIBLE); } }); closeResults.start(); } // fade out the scrim scrim.animate().alpha(0f).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); }
From source file:org.mdc.chess.ChessBoard.java
private void drawMoveHints(Canvas canvas) { if ((moveHints == null) || blindMode) { return;/* w w w.java2 s . c o m*/ } float h = (float) (sqSize / 2.0); float d = (float) (sqSize / 8.0); double v = 35 * Math.PI / 180; double cosv = Math.cos(v); double sinv = Math.sin(v); double tanv = Math.tan(v); int n = Math.min(moveMarkPaint.size(), moveHints.size()); for (int i = 0; i < n; i++) { Move m = moveHints.get(i); if ((m == null) || (m.from == m.to)) { continue; } float x0 = getXCrd(Position.getX(m.from)) + h; float y0 = getYCrd(Position.getY(m.from)) + h; float x1 = getXCrd(Position.getX(m.to)) + h; float y1 = getYCrd(Position.getY(m.to)) + h; float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d); float y2 = 0; float x3 = (float) (x2 - h * cosv); float y3 = (float) (y2 - h * sinv); float x4 = (float) (x3 - d * sinv); float y4 = (float) (y3 + d * cosv); float x5 = (float) (x4 + (-d / 2 - y4) / tanv); float y5 = -d / 2; float x6 = 0; float y6 = y5 / 2; Path path = new Path(); path.moveTo(x2, y2); path.lineTo(x3, y3); // path.lineTo(x4, y4); path.lineTo(x5, y5); path.lineTo(x6, y6); path.lineTo(x6, -y6); path.lineTo(x5, -y5); // path.lineTo(x4, -y4); path.lineTo(x3, -y3); path.close(); Matrix mtx = new Matrix(); mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI)); mtx.postTranslate(x0, y0); path.transform(mtx); Paint p = moveMarkPaint.get(i); canvas.drawPath(path, p); } }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
private void setRadius(float x, float y) { double radius = Math.hypot(x - mPoint[0], y - mPoint[1]); setRadius((float) radius); }
From source file:io.plaidapp.ui.DesignerNewsStory.java
private void doFabExpand() { // translate the chrome placeholder ui so that it is centered on the FAB int fabCenterX = (fab.getLeft() + fab.getRight()) / 2; int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop(); int translateX = fabCenterX - (fabExpand.getWidth() / 2); int translateY = fabCenterY - (fabExpand.getHeight() / 2); fabExpand.setTranslationX(translateX); fabExpand.setTranslationY(translateY); // then reveal the placeholder ui, starting from the center & same dimens as fab fabExpand.setVisibility(View.VISIBLE); Animator reveal = ViewAnimationUtils .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2, fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2)) .setDuration(fabExpandDuration); // translate the placeholder ui back into position along an arc ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumVerticalAngle(70f); Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0); Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath) .setDuration(fabExpandDuration); // animate from the FAB colour to the placeholder background color Animator background = ObjectAnimator .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.designer_news), ContextCompat.getColor(this, R.color.background_light)) .setDuration(fabExpandDuration); // fade out the fab (rapidly) Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60); // play 'em all together with the material interpolator AnimatorSet show = new AnimatorSet(); show.setInterpolator(/*from w ww . j av a 2s. c o m*/ AnimationUtils.loadInterpolator(DesignerNewsStory.this, android.R.interpolator.fast_out_slow_in)); show.playTogether(reveal, background, position, fadeOutFab); show.start(); }