com.facebook.rebound.Spring Java Examples

The following examples show how to use com.facebook.rebound.Spring. 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: ChatHeadCloseButton.java    From springy-heads with Apache License 2.0 8 votes vote down vote up
public void disappear(boolean immediate, boolean animate) {
    ySpring.setEndValue(mParentHeight - centerY + chatHeadManager.getConfig().getCloseButtonHeight());
    ySpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
    xSpring.setEndValue(0);
    ySpring.addListener(new SimpleSpringListener() {
        @Override
        public void onSpringAtRest(Spring spring) {
            super.onSpringAtRest(spring);
            ySpring.removeListener(this);
        }
    });
    scaleSpring.setEndValue(0.1f);
    if (!animate) {
        ySpring.setCurrentValue(mParentHeight, true);
        xSpring.setCurrentValue(0, true);
    }
    disappeared = true;
    if (listener != null) listener.onCloseButtonDisappear();

}
 
Example #2
Source File: FragmentSettings.java    From Pixiv-Shaft with MIT License 7 votes vote down vote up
private void animate(LinearLayout linearLayout) {
    SpringChain springChain = SpringChain.create(40, 8, 60, 10);

    int childCount = linearLayout.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View view = linearLayout.getChildAt(i);

        final int position = i;
        springChain.addSpring(new SimpleSpringListener() {
            @Override
            public void onSpringUpdate(Spring spring) {
                view.setTranslationX((float) spring.getCurrentValue());
                if (position == 0) {
                    Common.showLog(className + (float) spring.getCurrentValue());
                }
            }
        });
    }

    List<Spring> springs = springChain.getAllSprings();
    for (int i = 0; i < springs.size(); i++) {
        springs.get(i).setCurrentValue(400);
    }
    springChain.setControlSpringIndex(0).getControlSpring().setEndValue(0);
}
 
Example #3
Source File: SwitchButton.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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 #4
Source File: SpringFloatingActionMenu.java    From SpringFloatingActionMenu with Apache License 2.0 6 votes vote down vote up
private void applyBloomOpenAnimation() {
    final SpringSystem springSystem = SpringSystem.create();

    for (int i = 0; i < mMenuItemCount; i++) {
        // create the springs that control movement
        final Spring springX = springSystem.createSpring();
        final Spring springY = springSystem.createSpring();

        MenuItemView menuItemView = mMenuItemViews.get(i);
        springX.addListener(new MapPerformer(menuItemView, View.X, mFAB.getLeft(), menuItemView.getLeft()));
        springY.addListener(new MapPerformer(menuItemView, View.Y, mFAB.getTop(), menuItemView.getTop()));
        DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(this,mContainerView,true);
        springX.addListener(destroySelfSpringListener);
        springY.addListener(destroySelfSpringListener);
        springX.setEndValue(1);
        springY.setEndValue(1);
    }
}
 
Example #5
Source File: MenuItemView.java    From SpringFloatingActionMenu with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: MenuViewProxy.java    From RelaxFinger with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {

    float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.8);

    mMenuA.setScaleX(mappedValue);
    mMenuA.setScaleY(mappedValue);
    mMenuB.setScaleX(mappedValue);
    mMenuB.setScaleY(mappedValue);
    mMenuC.setScaleX(mappedValue);
    mMenuC.setScaleY(mappedValue);
    mMenuD.setScaleX(mappedValue);
    mMenuD.setScaleY(mappedValue);
    mMenuE.setScaleX(mappedValue);
    mMenuE.setScaleY(mappedValue);
}
 
Example #7
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 #8
Source File: Actor.java    From Backboard with Apache License 2.0 6 votes vote down vote up
/**
 * @param spring
 * 		the underlying {@link com.facebook.rebound.Spring}.
 * @param eventImitator
 * 		maps an event to a {@link com.facebook.rebound.Spring}
 * @param performers
 * 		map the {@link com.facebook.rebound.Spring} to a
 * 		{@link android.view.View}
 * @param springListeners
 * 		additional listeners to attach
 * @return the builder for chaining
 */
@NonNull
public Builder addMotion(@NonNull final Spring spring, @NonNull final EventImitator eventImitator,
                         @NonNull final Performer[] performers, final SpringListener[] springListeners) {

	// create struct
	final Motion motion = new Motion(spring, eventImitator, performers, springListeners);

	// connect actors
	motion.imitators[0].setSpring(motion.spring);

	for (Performer performer : motion.performers) {
		performer.setTarget(mView);
	}

	mMotions.add(motion);

	return this;
}
 
Example #9
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 #10
Source File: MapPerformer.java    From Backboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringUpdate(@NonNull final Spring spring) {

	mProperty.set(mTarget,
			(float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(),
					initialStart, initialEnd, start, end)
	);
}
 
Example #11
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 #12
Source File: ChatHead.java    From springy-heads with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
    if (xPositionSpring != null && yPositionSpring != null) {
        Spring activeHorizontalSpring = xPositionSpring;
        Spring activeVerticalSpring = yPositionSpring;
        if (spring != activeHorizontalSpring && spring != activeVerticalSpring)
            return;
        int totalVelocity = (int) Math.hypot(activeHorizontalSpring.getVelocity(), activeVerticalSpring.getVelocity());
        if (manager.getActiveArrangement() != null)
            manager.getActiveArrangement().onSpringUpdate(this, isDragging, manager.getMaxWidth(), manager.getMaxHeight(), spring, activeHorizontalSpring, activeVerticalSpring, totalVelocity);
    }
}
 
Example #13
Source File: ReboundDemoActivity.java    From AndroidAnimations with Apache License 2.0 5 votes vote down vote up
@Override public void onSpringUpdate(Spring spring) {
  // On each update of the spring value, we adjust the scale of the image view to match the
  // springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
  // to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
  // with setScaleX/Y. Note that rendering is an implementation detail of the application and not
  // Rebound itself. If you need Gingerbread compatibility consider using NineOldAndroids to update
  // your view properties in a backwards compatible manner.
  float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
  imageView.setScaleX(mappedValue);
  imageView.setScaleY(mappedValue);
}
 
Example #14
Source File: SpringHelper.java    From FloatingView with Apache License 2.0 5 votes vote down vote up
public void start(final YumFloating yumFloating){
    if (mConfig == -1){
        throw new IllegalStateException("Hi , You must call one of the method configBouncinessAndSpeed and configTensionAndFriction to make mConfig");
    }
    
    Spring spring = null;
    if (mConfig == 0){
        spring = yumFloating.createSpringByBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo);
    }else if (mConfig == 1){
        spring = yumFloating.createSpringByTensionAndFriction(mConfigValueOne, mConfigValueTwo);
    }
    start(spring);
}
 
Example #15
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 #16
Source File: MinimizedArrangement.java    From springy-heads with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringAtRest(Spring spring) {
    super.onSpringAtRest(spring);
    if (isTransitioning) {
        isTransitioning = false;
    }
}
 
Example #17
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 #18
Source File: DestroySelfSpringListener.java    From SpringFloatingActionMenu with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringAtRest(Spring spring) {
    spring.removeAllListeners();
    spring.destroy();
    spring = null;
    if(mSpringMenu != null && !mInOpen) {
        mSpringMenu.removeView(view);
    }
}
 
Example #19
Source File: DestroySelfSpringListener.java    From SpringFloatingActionMenu with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringActivate(Spring spring) {

    if(mSpringMenu != null && mSpringMenu.indexOfChild(view) == -1) {
       mSpringMenu.addView(view);
    }
}
 
Example #20
Source File: ExplosionFragment.java    From Backboard with Apache License 2.0 5 votes vote down vote up
private static void createCircle(Context context, ViewGroup rootView,
                                 SpringSystem springSystem,
                                 SpringConfig coasting,
                                 SpringConfig gravity,
                                 int diameter,
                                 Drawable backgroundDrawable) {

	final Spring xSpring = springSystem.createSpring().setSpringConfig(coasting);
	final Spring ySpring = springSystem.createSpring().setSpringConfig(gravity);

	// create view
	View view = new View(context);

	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(diameter, diameter);
	params.addRule(RelativeLayout.CENTER_IN_PARENT);
	view.setLayoutParams(params);
	view.setBackgroundDrawable(backgroundDrawable);

	rootView.addView(view);

	// generate random direction and magnitude
	double magnitude = Math.random() * 1000 + 3000;
	double angle = Math.random() * Math.PI / 2 + Math.PI / 4;

	xSpring.setVelocity(magnitude * Math.cos(angle));
	ySpring.setVelocity(-magnitude * Math.sin(angle));

	int maxX = rootView.getMeasuredWidth() / 2 + diameter;
	xSpring.addListener(new Destroyer(rootView, view, -maxX, maxX));

	int maxY = rootView.getMeasuredHeight() / 2 + diameter;
	ySpring.addListener(new Destroyer(rootView, view, -maxY, maxY));

	xSpring.addListener(new Performer(view, View.TRANSLATION_X));
	ySpring.addListener(new Performer(view, View.TRANSLATION_Y));

	// set a different end value to cause the animation to play
	xSpring.setEndValue(2);
	ySpring.setEndValue(9001);
}
 
Example #21
Source File: CountdownAnimationTextView.java    From AndroidPlayground with MIT License 5 votes vote down vote up
@Override
public void onSpringUpdate(Spring spring) {
    if (mView != null) {
        float mappedValue =
                (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1,
                        1, TO_HIGH);
        mView.setScaleX(mappedValue);
        mView.setScaleY(mappedValue);
    }
}
 
Example #22
Source File: InertialImitator.java    From Backboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpringUpdate(final Spring spring) {
	if (mSpring != null) {
		final double restPosition = calculateRestPosition();
		if (mSpring.getSpringConfig().equals(SPRING_CONFIG_FRICTION)) {
			if (mSpring.getCurrentValue() > mMaxValue && restPosition > mMaxValue) {
				mSpring.setSpringConfig(mOriginalConfig);
				mSpring.setEndValue(mMaxValue);
			} else if (mSpring.getCurrentValue() < mMinValue && restPosition < mMinValue) {
				mSpring.setSpringConfig(mOriginalConfig);
				mSpring.setEndValue(mMinValue);
			}
		}
	}
}
 
Example #23
Source File: DraggerView.java    From Dragger with Apache License 2.0 5 votes vote down vote up
/**
 * The global default {@link Spring} instance.
 *
 * This instance is automatically initialized with defaults that are suitable to most
 * implementations.
 *
 */
private Spring getSpring() {
  if (singleton == null) {
    synchronized (Spring.class) {
      if (singleton == null) {
        singleton = SpringSystem
            .create()
            .createSpring()
            .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(tension, friction));
      }
    }
  }
  return singleton;
}
 
Example #24
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 #25
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 #26
Source File: Actor.java    From Backboard with Apache License 2.0 5 votes vote down vote up
private Motion(@NonNull final Spring spring, @NonNull final Performer[] performers,
               @Nullable final SpringListener[] springListeners) {
	this.imitators = new MotionImitator[0];
	this.performers = performers;
	this.spring = spring;
	this.springListeners = springListeners;
}
 
Example #27
Source File: Actor.java    From Backboard with Apache License 2.0 5 votes vote down vote up
private Motion(@NonNull final Spring spring, @NonNull final EventImitator[] imitators, @NonNull final Performer[] performers,
               @Nullable final SpringListener[] springListeners) {
	this.imitators = imitators;
	this.performers = performers;
	this.spring = spring;
	this.springListeners = springListeners;
}
 
Example #28
Source File: Magnet.java    From Magnet with MIT License 5 votes vote down vote up
@Override public void onSpringAtRest(Spring spring) {
  super.onSpringAtRest(spring);
  isGoingToWall = false;
  if (!isSnapping && !isBeingDragged) {
    hideRemoveView();
  }
}
 
Example #29
Source File: InertialImitator.java    From Backboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringEndStateChange(final Spring spring) {
	// pass
}
 
Example #30
Source File: InertialImitator.java    From Backboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringActivate(final Spring spring) {
	// pass
}