Java Code Examples for com.facebook.rebound.Spring#getCurrentValue()

The following examples show how to use com.facebook.rebound.Spring#getCurrentValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Magnet.java    From Magnet with MIT License 6 votes vote down vote up
@Override public void onSpringUpdate(@NonNull Spring spring) {
  double currentValue = spring.getCurrentValue();
  if (motionProperty == MotionProperty.X) {
    layoutParams.x = (int) currentValue;
    windowManager.updateViewLayout(iconView, layoutParams);
  } else if (motionProperty == MotionProperty.Y) {
    layoutParams.y = (int) currentValue;
    windowManager.updateViewLayout(iconView, layoutParams);
  } else {
    return;
  }
  if (removeView.isShowing()) {
    removeView.onMove(layoutParams.x, layoutParams.y);
  }
  if (isFlinging && !isBeingDragged && iconOverlapsWithRemoveView()) {
    if (motionProperty == MotionProperty.Y) {
      isSnapping = false;
      isFlinging = false;
      if (iconCallback != null) {
        iconCallback.onFlingAway();
      }
    }
    hideRemoveView();
  }
}
 
Example 2
Source File: PrismActivity.java    From PrismView with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {
  super.onSpringUpdate(spring);
  double currentValue = spring.getCurrentValue();
  ViewCompat.setTranslationX(prismView, (float) SpringUtil.mapValueFromRangeToRange(
      currentValue, 0, 1, activityHelper.getWidth(), 0));
  mainViewUpdate(currentValue);
}
 
Example 3
Source File: ToggleButton.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
	final double value = spring.getCurrentValue();
	
	final float mapToggleX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, spotMinX, spotMaxX);
	spotX = mapToggleX;
	
	float mapOffLineWidth = (float) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, 10, spotSize);
	
	offLineWidth = mapOffLineWidth;
	
	final int fb = Color.blue(onColor);
	final int fr = Color.red(onColor);
	final int fg = Color.green(onColor);
	
	final int tb = Color.blue(offBorderColor);
	final int tr = Color.red(offBorderColor);
	final int tg = Color.green(offBorderColor);
	
	int sb = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fb, tb);
	int sr = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fr, tr);
	int sg = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fg, tg);
	
	sb = clamp(sb, 0, 255);
	sr = clamp(sr, 0, 255);
	sg = clamp(sg, 0, 255);
	
	borderColor = Color.rgb(sr, sg, sb);
	
	postInvalidate();
}
 
Example 4
Source File: SpringConfiguratorView.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
  float val = (float) spring.getCurrentValue();
  float minTranslate = mRevealPx;
  float maxTranslate = mStashPx;
  float range = maxTranslate - minTranslate;
  float yTranslate = (val * range) + minTranslate;
  SpringConfiguratorView.this.setTranslationY(yTranslate);
}
 
Example 5
Source File: PrismActivity.java    From PrismView with Apache License 2.0 5 votes vote down vote up
private void onSpringAtRestOut(Spring spring) {
  if (hideEnabled) {
    if (spring.getCurrentValue() == 1) {
      showPrismView();
    } else {
      showMainView();
    }
  }
}
 
Example 6
Source File: PrismActivity.java    From PrismView with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {
  super.onSpringUpdate(spring);
  double currentValue = spring.getCurrentValue();
  ViewCompat.setTranslationY(prismView,
      (float) SpringUtil.mapValueFromRangeToRange(currentValue, 0, 1,
          activityHelper.getHeight(), 0));
  mainViewUpdate(currentValue);
}
 
Example 7
Source File: PrismActivity.java    From PrismView with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {
  super.onSpringUpdate(spring);
  double currentValue = spring.getCurrentValue();
  ViewCompat.setTranslationY(prismView,
      (float) SpringUtil.mapValueFromRangeToRange(currentValue, 0, 1,
          -activityHelper.getHeight(), 0));
  mainViewUpdate(currentValue);
}
 
Example 8
Source File: PrismActivity.java    From PrismView with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {
  super.onSpringUpdate(spring);
  double currentValue = spring.getCurrentValue();
  ViewCompat.setTranslationX(prismView, (float) SpringUtil.mapValueFromRangeToRange(
      currentValue, 0, 1, -activityHelper.getWidth(), 0));
  mainViewUpdate(currentValue);
}
 
Example 9
Source File: DraggerView.java    From Dragger with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {

      double val = spring.getCurrentValue();
      switch (dragPosition) {
        case LEFT:
          ViewCompat.setTranslationX(dragView,
              (float) SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, -dragView.getWidth()));
          break;
        case RIGHT:
          ViewCompat.setTranslationX(dragView,
              (float) SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, dragView.getWidth()));
          break;
        case TOP:
          ViewCompat.setTranslationY(dragView,
              (float) SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, dragView.getHeight()));
          break;
        case BOTTOM:
          ViewCompat.setTranslationY(dragView,
              (float) SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, -dragView.getHeight()));
          break;
        default:
          break;
      }

      ViewCompat.setAlpha(shadowView,
          (float) (MAX_ALPHA - SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, 1)));

      if (draggerCallback != null) {
        draggerCallback.onProgress(spring.getCurrentValue());
      }
    }
 
Example 10
Source File: SpringConfiguratorView.java    From KugouLayout with MIT License 5 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
  float val = (float) spring.getCurrentValue();
  float minTranslate = mRevealPx;
  float maxTranslate = mStashPx;
  float range = maxTranslate - minTranslate;
  float yTranslate = (val * range) + minTranslate;
  SpringConfiguratorView.this.setTranslationY(yTranslate);
}
 
Example 11
Source File: MaximizedArrangement.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringUpdate(ChatHead activeChatHead, boolean isDragging, int maxWidth, int maxHeight, Spring spring, Spring activeHorizontalSpring, Spring activeVerticalSpring, int totalVelocity) {
    /** Bounds Check **/
    if (spring == activeHorizontalSpring && !isDragging) {
        double xPosition = activeHorizontalSpring.getCurrentValue();
        if (xPosition + manager.getConfig().getHeadWidth() > maxWidth && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
        if (xPosition < 0 && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
    } else if (spring == activeVerticalSpring && !isDragging) {
        double yPosition = activeVerticalSpring.getCurrentValue();

        if (yPosition + manager.getConfig().getHeadHeight() > maxHeight && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
        if (yPosition < 0 && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }

    }

    /** position it back **/
    if (!isDragging && totalVelocity < MIN_VELOCITY_TO_POSITION_BACK && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING) {
        positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);

    }

    if (activeChatHead == currentChatHead)

        showOrHideView(activeChatHead);

    if (!isDragging) {
        /** Capturing check **/
        int[] coords = manager.getChatHeadCoordsForCloseButton(activeChatHead);
        double distanceCloseButtonFromHead = manager.getDistanceCloseButtonFromHead((float) activeHorizontalSpring.getCurrentValue() + manager.getConfig().getHeadWidth() / 2, (float) activeVerticalSpring.getCurrentValue() + manager.getConfig().getHeadHeight() / 2);

        if (distanceCloseButtonFromHead < activeChatHead.CLOSE_ATTRACTION_THRESHOLD && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && activeVerticalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && !activeChatHead.isSticky()) {

            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeChatHead.setState(ChatHead.State.CAPTURED);
        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.CAPTURING) {
            activeHorizontalSpring.setAtRest();
            activeVerticalSpring.setAtRest();
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeHorizontalSpring.setEndValue(coords[0]);
            activeVerticalSpring.setEndValue(coords[1]);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeVerticalSpring.isAtRest()) {
            manager.getCloseButton().disappear(false, true);
            manager.captureChatHeads(activeChatHead);
        }
        if (!activeVerticalSpring.isAtRest() && !isTransitioning) {
            manager.getCloseButton().appear();
        } else {
            manager.getCloseButton().disappear(true, true);
        }
    }
}
 
Example 12
Source File: ExplosionFragment.java    From Backboard with Apache License 2.0 4 votes vote down vote up
public boolean shouldClean(Spring spring) {
	// these are arbitrary values to keep the view from disappearing before it is
	// fully off the screen
	return spring.getCurrentValue() < mMin || spring.getCurrentValue() > mMax;
}
 
Example 13
Source File: MinimizedArrangement.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringUpdate(ChatHead activeChatHead, boolean isDragging, int maxWidth, int maxHeight, Spring spring, Spring activeHorizontalSpring, Spring activeVerticalSpring, int totalVelocity) {
    /** This method does a bounds Check **/
    double xVelocity = activeHorizontalSpring.getVelocity();
    double yVelocity = activeVerticalSpring.getVelocity();
    if (!isDragging && Math.abs(totalVelocity) < MIN_VELOCITY_TO_POSITION_BACK && activeChatHead == hero) {

        if (Math.abs(totalVelocity) < MAX_VELOCITY_FOR_IDLING && activeChatHead.getState() == ChatHead.State.FREE && hasActivated) {
            setIdleStateX((int) activeHorizontalSpring.getCurrentValue());
            setIdleStateY((int) activeVerticalSpring.getCurrentValue());
        }
        if (spring == activeHorizontalSpring) {

            double xPosition = activeHorizontalSpring.getCurrentValue();
            if (xPosition + manager.getConfig().getHeadWidth() > maxWidth && activeHorizontalSpring.getVelocity() > 0) {
                //outside the right bound
                //System.out.println("outside the right bound !! xPosition = " + xPosition);
                int newPos = maxWidth - manager.getConfig().getHeadWidth();
                activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeHorizontalSpring.setEndValue(newPos);
            } else if (xPosition < 0 && activeHorizontalSpring.getVelocity() < 0) {
                //outside the left bound
                //System.out.println("outside the left bound !! xPosition = " + xPosition);
                activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeHorizontalSpring.setEndValue(0);

            } else {
                //within bound


            }
        } else if (spring == activeVerticalSpring) {
            double yPosition = activeVerticalSpring.getCurrentValue();
            if (yPosition + manager.getConfig().getHeadWidth() > maxHeight && activeVerticalSpring.getVelocity() > 0) {
                //outside the bottom bound
                //System.out.println("outside the bottom bound !! yPosition = " + yPosition);

                activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeVerticalSpring.setEndValue(maxHeight - manager.getConfig().getHeadHeight());
            } else if (yPosition < 0 && activeVerticalSpring.getVelocity() < 0) {
                //outside the top bound
                //System.out.println("outside the top bound !! yPosition = " + yPosition);

                activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeVerticalSpring.setEndValue(0);
            } else {
                //within bound
            }

        }
    }

    if (!isDragging && activeChatHead == hero) {

        /** Capturing check **/


        int[] coords = manager.getChatHeadCoordsForCloseButton(activeChatHead);
        double distanceCloseButtonFromHead = manager.getDistanceCloseButtonFromHead((float) activeHorizontalSpring.getCurrentValue() + manager.getConfig().getHeadWidth() / 2, (float) activeVerticalSpring.getCurrentValue() + manager.getConfig().getHeadHeight() / 2);

        if (distanceCloseButtonFromHead < activeChatHead.CLOSE_ATTRACTION_THRESHOLD && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && activeVerticalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING) {
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeChatHead.setState(ChatHead.State.CAPTURED);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.CAPTURING) {
            activeHorizontalSpring.setAtRest();
            activeVerticalSpring.setAtRest();
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeHorizontalSpring.setEndValue(coords[0]);
            activeVerticalSpring.setEndValue(coords[1]);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeVerticalSpring.isAtRest()) {
            manager.getCloseButton().disappear(false, true);
            manager.captureChatHeads(activeChatHead);
        }
        if (!activeVerticalSpring.isAtRest() && !isTransitioning) {
            manager.getCloseButton().appear();
        } else {
            manager.getCloseButton().disappear(true, true);
        }
    }


}
 
Example 14
Source File: MinimizedArrangement.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
    currentDelta = (float) ((float) DELTA * (maxWidth / 2 - spring.getCurrentValue()) / (maxWidth / 2));
    if (horizontalSpringChain != null)
        horizontalSpringChain.getControlSpring().setCurrentValue(spring.getCurrentValue());
}
 
Example 15
Source File: ChatHeadCloseButton.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
private int getXFromSpring(Spring spring) {
    return centerX + (int) spring.getCurrentValue() - getMeasuredWidth() / 2;
}
 
Example 16
Source File: ChatHeadCloseButton.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
private int getYFromSpring(Spring spring) {
    return centerY + (int) spring.getCurrentValue() - getMeasuredHeight() / 2;
}
 
Example 17
Source File: ChatHead.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    super.onTouchEvent(event);

    if(xPositionSpring==null || yPositionSpring==null) return false;
    //Chathead view will set the correct active springs on touch
    Spring activeHorizontalSpring = xPositionSpring;
    Spring activeVerticalSpring = yPositionSpring;

    int action = event.getAction();
    float rawX = event.getRawX();
    float rawY = event.getRawY();
    float offsetX = rawX - downX;
    float offsetY = rawY - downY;
    boolean showCloseButton = manager.getActiveArrangement().shouldShowCloseButton(this);
    event.offsetLocation(manager.getChatHeadContainer().getViewX(this), manager.getChatHeadContainer().getViewY(this));
    if (action == MotionEvent.ACTION_DOWN) {
        if (velocityTracker == null) {
            velocityTracker = VelocityTracker.obtain();
        } else {
            velocityTracker.clear();

        }
        activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
        activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
        setState(ChatHead.State.FREE);
        downX = rawX;
        downY = rawY;
        downTranslationX = (float) activeHorizontalSpring.getCurrentValue();
        downTranslationY = (float) activeVerticalSpring.getCurrentValue();
        scaleSpring.setEndValue(.9f);
        activeHorizontalSpring.setAtRest();
        activeVerticalSpring.setAtRest();
        velocityTracker.addMovement(event);


    } else if (action == MotionEvent.ACTION_MOVE) {
        if (Math.hypot(offsetX, offsetY) > touchSlop) {
            isDragging = true;
            if (showCloseButton) {
                manager.getCloseButton().appear();
            }
        }
        velocityTracker.addMovement(event);

        if (isDragging) {
            manager.getCloseButton().pointTo(rawX, rawY);
            if (manager.getActiveArrangement().canDrag(this)) {
                double distanceCloseButtonFromHead = manager.getDistanceCloseButtonFromHead(rawX, rawY);
                if (distanceCloseButtonFromHead < CLOSE_ATTRACTION_THRESHOLD && showCloseButton) {
                    setState(ChatHead.State.CAPTURED);
                    activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                    activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                    int[] coords = manager.getChatHeadCoordsForCloseButton(this);
                    activeHorizontalSpring.setEndValue(coords[0]);
                    activeVerticalSpring.setEndValue(coords[1]);
                    manager.getCloseButton().onCapture();

                } else {
                    setState(ChatHead.State.FREE);
                    activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.DRAGGING);
                    activeVerticalSpring.setSpringConfig(SpringConfigsHolder.DRAGGING);
                    activeHorizontalSpring.setCurrentValue(downTranslationX + offsetX);
                    activeVerticalSpring.setCurrentValue(downTranslationY + offsetY);
                    manager.getCloseButton().onRelease();
                }

                velocityTracker.computeCurrentVelocity(1000);
            }

        }

    } else {
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            boolean wasDragging = isDragging;
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.DRAGGING);
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.DRAGGING);
            isDragging = false;
            scaleSpring.setEndValue(1);
            int xVelocity = (int) velocityTracker.getXVelocity();
            int yVelocity = (int) velocityTracker.getYVelocity();
            velocityTracker.recycle();
            velocityTracker = null;
            if(xPositionSpring!=null && yPositionSpring!=null) {
                boolean touchUpHandled = manager.getActiveArrangement().handleTouchUp(this, xVelocity, yVelocity, activeHorizontalSpring, activeVerticalSpring, wasDragging);
            }
        }
    }

    return true;
}
 
Example 18
Source File: ToggleButton.java    From ToggleButton with MIT License 4 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
	final double value = spring.getCurrentValue();
	calculateEffect(value);
}