Java Code Examples for com.facebook.rebound.Spring#setCurrentValue()
The following examples show how to use
com.facebook.rebound.Spring#setCurrentValue() .
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: SwitchButton.java From FimiX8-RE with MIT License | 6 votes |
private void takeEffect(boolean animate) { double d = 1.0d; if (animate) { Spring spring = this.spring; if (!this.toggleOn) { d = 0.0d; } spring.setEndValue(d); return; } double d2; Spring spring2 = this.spring; if (this.toggleOn) { d2 = 1.0d; } else { d2 = 0.0d; } spring2.setCurrentValue(d2); if (!this.toggleOn) { d = 0.0d; } calculateEffect(d); }
Example 2
Source File: MenuItemView.java From SpringFloatingActionMenu with Apache License 2.0 | 6 votes |
private void applyPressAnimation() { SpringSystem springSystem = SpringSystem.create(); final Spring spring = springSystem.createSpring(); spring.addListener(new Performer(mBtn, View.SCALE_X)); spring.addListener(new Performer(mBtn, View.SCALE_Y)); mBtn.setOnTouchListener(new ToggleImitator(spring, 1, 1.2){ @Override public void imitate(MotionEvent event) { super.imitate(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: callOnClick(); break; default: } } }); spring.setCurrentValue(1); }
Example 3
Source File: MenuItemView.java From SpringFloatingActionMenu with Apache License 2.0 | 5 votes |
public void showLabel() { SpringSystem springSystem = SpringSystem.create(); final Spring spring = springSystem.createSpring(); spring.addListener(new MapPerformer(mLabel, View.SCALE_X, 0, 1)); spring.addListener(new MapPerformer(mLabel, View.SCALE_Y, 0, 1)); spring.setCurrentValue(0); new Handler().postDelayed(new Runnable() { @Override public void run() { spring.setEndValue(1); } }, 200); }
Example 4
Source File: ChatHead.java From springy-heads with Apache License 2.0 | 4 votes |
@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; }