List of usage examples for java.lang Math hypot
public static double hypot(double x, double y)
From source file:io.plaidapp.ui.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 . j a va 2 s. c o 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 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:com.hannesdorfmann.search.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 ww . j a v a 2 s .c o 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:com.andremion.music.MusicCoverView.java
float getMaxRadius() { final int w = getWidth(); final int h = getHeight(); return (float) Math.hypot(w / 2f, h / 2f); }
From source file:com.andremion.floatingnavigationview.FloatingNavigationView.java
private float getMaxRadius() { return (float) Math.hypot(mNavigationRect.width(), mNavigationRect.height()); }
From source file:io.plaidapp.ui.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.esa.beam.util.math.FastMathPerformance.java
public void testHypot() { System.gc();/*from w ww . ja va 2s .c om*/ double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) x += StrictMath.hypot(i * F1, i * F1); long strictTime = System.nanoTime() - time; System.gc(); double y = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) y += FastMath.hypot(i * F1, i * F1); long fastTime = System.nanoTime() - time; System.gc(); double z = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) z += Math.hypot(i * F1, i * F1); long mathTime = System.nanoTime() - time; report("hypot", x + y + z, strictTime, fastTime, mathTime); }
From source file:org.goodev.material.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { int interpolator = UI.isLollipop() ? android.R.interpolator.fast_out_slow_in : android.R.interpolator.accelerate_decelerate; int backInterpolator = UI.isLollipop() ? android.R.interpolator.fast_out_linear_in : android.R.interpolator.accelerate_decelerate; // translate the icon to match position in the launching activity searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, interpolator)) .setListener(new AnimatorListenerAdapter() { @Override//from w w w . j a v a 2 s . co m public void onAnimationEnd(Animator animation) { supportFinishAfterTransition(); } }).start(); if (UI.isLollipop()) { // 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, backInterpolator)).setListener(null).start(); searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start(); if (UI.isLollipop()) { if (searchToolbar.getZ() != 0f) { searchToolbar.animate().z(0f).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).start(); } } // if we're showing search results, circular hide them if (UI.isLollipop() && 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, backInterpolator)).setListener(null).start(); }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
/** * Actually draws the environment on the view. * /*from w ww .j a va 2 s . com*/ * @param g * {@link Graphics2D} object responsible for drawing */ protected final void drawEnvOnView(final Graphics2D g) { if (wormhole == null || !isVisible() || !isEnabled()) { return; } accessData(); if (hooked.isPresent()) { final Position hcoor = positions.get(hooked.get()); final Point hp = wormhole.getViewPoint(hcoor); if (hp.distance(getCenter()) > FREEDOM_RADIUS) { wormhole.setViewPosition(hp); } } /* * Compute nodes in sight and their screen position */ final Map<Node<T>, Point> onView = positions.entrySet().parallelStream() .map(pair -> new Pair<>(pair.getKey(), wormhole.getViewPoint(pair.getValue()))) .filter(p -> wormhole.isInsideView(p.getSecond())) .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); g.setColor(Color.BLACK); if (obstacles != null) { /* * TODO: only draw obstacles if on view */ obstacles.parallelStream().map(this::convertObstacle).forEachOrdered(g::fill); } if (paintLinks) { g.setColor(Color.GRAY); onView.keySet().parallelStream().map(neighbors::get) .flatMap(neigh -> neigh.getNeighbors().parallelStream() .map(node -> node.compareTo(neigh.getCenter()) > 0 ? new Pair<>(neigh.getCenter(), node) : new Pair<>(node, neigh.getCenter()))) .distinct().map( pair -> mapPair(pair, node -> Optional.ofNullable(onView.get(node)) .orElse(wormhole.getViewPoint(positions.get(node))))) .forEachOrdered(line -> { final Point p1 = line.getFirst(); final Point p2 = line.getSecond(); g.drawLine(p1.x, p1.y, p2.x, p2.y); }); } releaseData(); if (isDraggingMouse && status == ViewStatus.MOVING && originPoint.isPresent() && endingPoint.isPresent()) { for (final Node<T> n : selectedNodes) { if (onView.containsKey(n)) { onView.put(n, new Point(onView.get(n).x + (endingPoint.get().x - originPoint.get().x), onView.get(n).y + (endingPoint.get().y - originPoint.get().y))); } } } g.setColor(Color.GREEN); if (effectStack != null) { effectStack.forEach(effect -> { onView.entrySet().forEach(entry -> { final Point p = entry.getValue(); effect.apply(g, entry.getKey(), p.x, p.y); }); }); } if (isCloserNodeMarked()) { final Optional<Map.Entry<Node<T>, Point>> closest = onView.entrySet().parallelStream() .min((pair1, pair2) -> { final Point p1 = pair1.getValue(); final Point p2 = pair2.getValue(); final double d1 = Math.hypot(p1.x - mousex, p1.y - mousey); final double d2 = Math.hypot(p2.x - mousex, p2.y - mousey); return Double.compare(d1, d2); }); if (closest.isPresent()) { nearest = closest.get().getKey(); final int nearestx = closest.get().getValue().x; final int nearesty = closest.get().getValue().y; drawFriedEgg(g, nearestx, nearesty, Color.RED, Color.YELLOW); } } else { nearest = null; } if (isDraggingMouse && status == ViewStatus.SELECTING && originPoint.isPresent() && endingPoint.isPresent()) { g.setColor(Color.BLACK); final int x = originPoint.get().x < endingPoint.get().x ? originPoint.get().x : endingPoint.get().x; final int y = originPoint.get().y < endingPoint.get().y ? originPoint.get().y : endingPoint.get().y; final int width = Math.abs(endingPoint.get().x - originPoint.get().x); final int height = Math.abs(endingPoint.get().y - originPoint.get().y); g.drawRect(x, y, width, height); selectedNodes = onView.entrySet().parallelStream() .filter(nodes -> isInsideRectangle(nodes.getValue(), x, y, width, height)) .map(onScreen -> onScreen.getKey()).collect(Collectors.toSet()); } selectedNodes.parallelStream().map(e -> Optional.ofNullable(onView.get(e))).filter(Optional::isPresent) .map(Optional::get).forEachOrdered(p -> drawFriedEgg(g, p.x, p.y, Color.BLUE, Color.CYAN)); }
From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealTabsFragment.java
private void handleSearchManual() { if (card_search_manual.getVisibility() == View.VISIBLE) { searchManual.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Animator animatorHide = ViewAnimationUtils.createCircularReveal(card_search_manual, card_search_manual.getWidth() - (int) convertDpToPixel(24, getActivity()), (int) convertDpToPixel(23, getActivity()), (float) Math.hypot(card_search_manual.getWidth(), card_search_manual.getHeight()), 0); animatorHide.addListener(new Animator.AnimatorListener() { @Override//from w w w .j a va2s. c o m public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { card_search_manual.setVisibility(View.GONE); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(searchManual.getWindowToken(), 0); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorHide.setDuration(200); animatorHide.start(); } else { card_search_manual.setVisibility(View.GONE); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(searchManual.getWindowToken(), 0); } } else { searchManual.setVisibility(View.INVISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Animator animator = ViewAnimationUtils.createCircularReveal(card_search_manual, card_search_manual.getWidth() - (int) convertDpToPixel(24, getActivity()), (int) convertDpToPixel(23, getActivity()), 0, (float) Math.hypot(card_search_manual.getWidth(), card_search_manual.getHeight())); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { manualSearch.requestFocus(); } @Override public void onAnimationEnd(Animator animation) { ((InputMethodManager) getActivity().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) { } }); card_search_manual.setVisibility(View.VISIBLE); if (card_search_manual.getVisibility() == View.VISIBLE) { animator.setDuration(300); animator.start(); card_search_manual.setEnabled(true); } } else { manualSearch.requestFocus(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); card_search_manual.setVisibility(View.VISIBLE); } } }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
@Override public void onClick(final View v) { switch (v.getId()) { case R.id.set_button: setWallpaper();/*from www.ja va2s . co m*/ break; case R.id.floating_button_icon: final GradientDrawable circleDrawable = (GradientDrawable) getResources() .getDrawable(R.drawable.floating_button_circle); final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY()) + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2); Animation animation = new Animation() { private boolean needsFragment = true; private float pivot; @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (needsFragment && interpolatedTime >= 1) { needsFragment = false; showSourceAddFragment(); } else { float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime); t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot); } } @Override public boolean willChangeBounds() { return true; } }; animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); } @Override public void onAnimationEnd(Animation animation) { handler.postDelayed(new Runnable() { @Override public void run() { if (needsButtonReset) { addButton.setOnClickListener(SourceListFragment.this); addButtonBackground.setScaleX(1.0f); addButtonBackground.setScaleY(1.0f); addButtonBackground.clearAnimation(); circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); addButton.setVisibility(View.VISIBLE); } } }, 100); } @Override public void onAnimationRepeat(Animation animation) { } }); ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.ACCENT_OPAQUE), getResources().getColor(AppSettings.getBackgroundColorResource())); buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { circleDrawable.setColor((Integer) animation.getAnimatedValue()); addButtonBackground.setImageDrawable(circleDrawable); } }); DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(); animation.setDuration(ADD_ANIMATION_TIME); buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9)); buttonColorAnimation.setInterpolator(decelerateInterpolator); animation.setInterpolator(decelerateInterpolator); // Post a delayed Runnable to ensure reset even if animation is interrupted handler.postDelayed(new Runnable() { @Override public void run() { if (needsButtonReset) { addButtonBackground.setScaleX(1.0f); addButtonBackground.setScaleY(1.0f); addButtonBackground.clearAnimation(); circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); addButton.setVisibility(View.VISIBLE); needsButtonReset = false; } } }, (long) (ADD_ANIMATION_TIME * 1.1f)); needsButtonReset = true; addButton.setVisibility(View.GONE); buttonColorAnimation.start(); addButtonBackground.startAnimation(animation); break; default: } }