Пример #1
0
 /**
  * Calculates the animation duration given the |initialVelocity| and a desired |displacement|.
  *
  * @param initialVelocity The initial velocity of the animation in dps per second.
  * @param displacement The displacement of the animation in dps.
  * @return The animation duration in milliseconds.
  */
 private long calculateAnimationDuration(float initialVelocity, float displacement) {
   // NOTE(pedrosimonetti): This formula assumes the deceleration curve is
   // quadratic (t^2),
   // hence the duration formula should be:
   // duration = 2 * displacement / initialVelocity
   //
   // We are also converting the duration from seconds to milliseconds,
   // which explains why
   // we are multiplying by 2000 (2 * 1000) instead of 2.
   return MathUtils.clamp(
       Math.round(Math.abs(2000 * displacement / initialVelocity)),
       MINIMUM_ANIMATION_DURATION_MS,
       MAXIMUM_ANIMATION_DURATION_MS);
 }
Пример #2
0
 /**
  * A comparison function for sorting by storage (most used first).
  *
  * @return which site uses more storage.
  */
 public int compareByStorageTo(Website to) {
   if (this == to) return 0;
   return MathUtils.compareLongs(to.getTotalUsage(), getTotalUsage());
 }
Пример #3
0
 /**
  * Generate color based on bookmarked url's hash code. Same color will always be returned given
  * same bookmark item.
  *
  * @param item bookmark the color represents for
  * @return int for the generated color
  */
 public static int generateBackgroundColor(BookmarkItem item) {
   int normalizedIndex =
       MathUtils.positiveModulo(item.getUrl().hashCode(), DEFAULT_BACKGROUND_COLORS.length);
   return DEFAULT_BACKGROUND_COLORS[normalizedIndex];
 }
 @Override
 public float getTopControlsOffset(float currentOffsetDp) {
   return MathUtils.clamp(
       mBaseTab.getY(), -mSearchPanel.getToolbarHeight(), Math.min(currentOffsetDp, 0f));
 }