Java 类com.facebook.rebound.Spring 实例源码

项目:android_camera_experiment    文件:SandriosCameraActivity.java   
private void setSpringSystem() {
    mSpringSystem = SpringSystem.create();
    mSpringsAlpha = mSpringSystem.createSpring()
            .setSpringConfig(alphaconfig)
            .setCurrentValue(1);

    mSpringsAlpha.addListener(new SimpleSpringListener() {

        @Override
        public void onSpringUpdate(Spring mSpring) {
            float value = (float) mSpring.getCurrentValue();
            mLockView.setAlpha(value);
        }
    });


}
项目:SpringFloatingActionMenu    文件:SpringFloatingActionMenu.java   
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);
    }
}
项目:SpringFloatingActionMenu    文件:SpringFloatingActionMenu.java   
private void applyBloomCloseAnimation() {
    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, menuItemView.getLeft(), mFAB.getLeft()));
        springY.addListener(new MapPerformer(menuItemView, View.Y, menuItemView.getTop(), mFAB.getTop()));
        DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(this,mContainerView,false);
        springX.addListener(destroySelfSpringListener);
        springY.addListener(destroySelfSpringListener);
        springX.setEndValue(1);
        springY.setEndValue(1);
    }
}
项目:SpringFloatingActionMenu    文件:MenuItemView.java   
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);
}
项目:SpiderMenu    文件:SpiderMenu.java   
/**
 * Bounce the view. Will use the respective values for center and radial view
 * @param child
 *      The child that has to be bounced
 * @param springAnimator
 *      The spring animator with the listener to be invoked.
 *      Set null if you dont need to intercept the spring animation end
 *
 * @author Melvin Lobo
 */
private void bounceView(View child, SpringAnimator springAnimator) {
    LayoutParams params = (LayoutParams) child.getLayoutParams();

    if(params.getMenuType() == LayoutParams.CENTER) {
        Spring centerScaleSpring = mSpringSystem.createSpring();
        centerScaleSpring.setSpringConfig( new SpringConfig( CENTER_SCALE_TENSION, CENTER_SCALE_FRICTION ) );
        centerScaleSpring.setEndValue( 1 );
        centerScaleSpring.addListener( springAnimator );
    }
    else {
        Spring radialScaleSpring = mSpringSystem.createSpring();
        radialScaleSpring.setSpringConfig( new SpringConfig( RADIAL_SCALE_TENSION, RADIAL_SCALE_FRICTION ) );
        radialScaleSpring.setEndValue( 1 );
        radialScaleSpring.addListener( springAnimator );
    }
}
项目:test4XXX    文件:MainActivity.java   
@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);
    mImageView.setScaleX(mappedValue);
    mImageView.setScaleY(mappedValue);
}
项目:Backboard    文件:Actor.java   
/**
 * @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}
 * @return the builder for chaining
 */
@NonNull
public Builder addMotion(@NonNull final Spring spring, @NonNull final EventImitator eventImitator,
                         @NonNull final Performer... performers) {

    final Motion motion = new Motion(spring, eventImitator, performers, null);

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

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

    mMotions.add(motion);

    return this;
}
项目:Backboard    文件:Actor.java   
/**
 * @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;
}
项目:boohee_v5.6    文件:SpringConfiguratorView.java   
private void togglePosition() {
    double d = PathListView.NO_ZOOM;
    double currentValue = this.mRevealerSpring.getEndValue();
    Spring spring = this.mRevealerSpring;
    if (currentValue == PathListView.NO_ZOOM) {
        d = 0.0d;
    }
    spring.setEndValue(d);
}
项目:FloatingView    文件:SpringHelper.java   
public void start(){
    SpringSystem springSystem = SpringSystem.create();
    Spring spring  = springSystem.createSpring();
    if (mConfig == 0){
        spring.setSpringConfig(SpringConfig.fromBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo));
    }else if (mConfig == 1){
        spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(mConfigValueOne, mConfigValueTwo));
    }
    start(spring);
}
项目:FloatingView    文件:SpringHelper.java   
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);
}
项目:sapphire    文件:MainActivity.java   
@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);
    suggestionView.setScaleX(mappedValue);
    suggestionView.setScaleY(mappedValue);
}
项目:Gank-Meizi    文件:ReboundImageView.java   
@Override
public void onSpringUpdate(Spring spring) {
    float mappedvalue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.8);
    view.setScaleX(mappedvalue);
    view.setScaleY(mappedvalue);

    float rotation = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 0, 30);
    view.setRotation(rotation);
}
项目:Incubators    文件:IOSToggleButton.java   
@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();
}
项目:liener    文件:BubbleHead.java   
@Override
public void onSpringUpdate(Spring spring) {
    float value = (float) spring.getCurrentValue();
    float scale = 1f - (value * 0.5f);
    view.setScaleX(scale);
    view.setScaleY(scale);
}
项目:SpringFloatingActionMenu    文件:MenuItemView.java   
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);
}
项目:SpringFloatingActionMenu    文件:DestroySelfSpringListener.java   
@Override
public void onSpringAtRest(Spring spring) {
    spring.removeAllListeners();
    spring.destroy();
    spring = null;
    if(mSpringMenu != null && !mInOpen) {
        mSpringMenu.removeView(view);
    }
}
项目:SpringFloatingActionMenu    文件:DestroySelfSpringListener.java   
@Override
public void onSpringActivate(Spring spring) {

    if(mSpringMenu != null && mSpringMenu.indexOfChild(view) == -1) {
       mSpringMenu.addView(view);
    }
}
项目:SpiderMenu    文件:SpiderMenu.java   
/**
 * Called whenever the spring is updated
 *
 * @param spring the Spring sending the update
 */
@Override
public void onSpringUpdate( Spring spring ) {
    /*
    Map our current value to scale values. Rebound has a nifty SpringUtil class to do that
    We map our values between scale 0.3 to 1 (Range of 30% to 100%)
     */
    double nMappedValue = SpringUtil.mapValueFromRangeToRange( spring.getCurrentValue(), 0.0d, 1.0d, 0.8d, 1.0d);
    mView.get().setScaleX( (float)nMappedValue );
    mView.get().setScaleY( (float)nMappedValue );
}
项目:RxComboDetector    文件:YOLOComboView.java   
@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);
    }
}
项目:AndroidAnimations    文件:ReboundDemoActivity.java   
@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);
}
项目:FloatWindow    文件:SpringConfiguratorView.java   
@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);
}
项目:MyScse-Client    文件:SpringConfiguratorView.java   
@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);
}
项目:collapselrecycler    文件:FaceBookAnimActivity.java   
public void setMoreViewAnim(){
    /*
    其中带参数的第一个参数表示起主导作用spring的拉力系数,
    第二个参数表示起主导作用Spring的摩擦力系数,
    第三个和第四个表示附属的拉力和摩擦力系数
     */
    SpringChain springChain = SpringChain.create(40,6,50,7);

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

        springChain.addSpring(new SimpleSpringListener() {
            @Override
            public void onSpringUpdate(Spring spring) {
                view.setTranslationY((float) spring.getCurrentValue());
            }
        });
    }

    List<Spring> springs = springChain.getAllSprings();
    for (int i = 0; i < springs.size(); i++) {
        springs.get(i).setCurrentValue(400);
    }

    springChain.setControlSpringIndex(4).getControlSpring().setEndValue(0);

}
项目:MultiLayout    文件:Page.java   
private void animTop(Spring spring, boolean toOpen) {
    if (isOpened) {
        spring.setCurrentValue(-mView.getHeight());
    }

    spring.setEndValue(toOpen ? 0 : -mView.getHeight());
}
项目:EveryXDay    文件:ToggleButton.java   
@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();
}
项目:Green    文件:SpringConfiguratorView.java   
@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);
}
项目:test4XXX    文件:ExampleContainerView.java   
@Override
public void onSpringUpdate(Spring spring) {
  double val = spring.getCurrentValue();
  float xlat = (float) SpringUtil.mapValueFromRangeToRange(val, 0, 1, 0, getWidth());
  setTranslationX(xlat);
  if (mCallback != null) {
    mCallback.onProgress(spring.getCurrentValue());
  }
}
项目:Backboard    文件:ExplosionFragment.java   
public void clean(Spring spring) {
    if (mViewGroup != null && mViewToRemove != null) {
        mViewGroup.removeView(mViewToRemove);
    }
    if (spring != null) {
        spring.destroy();
    }
}
项目:AndroidPlayground    文件:CountdownAnimationTextView.java   
@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);
    }
}
项目:Backboard    文件:ExplosionFragment.java   
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);
}
项目:Backboard    文件:InertialImitator.java   
@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);
            }
        }
    }
}
项目:Backboard    文件:Imitator.java   
/**
 * @param spring
 *      the spring to set (sets spring's current to the rest value)
 */
public void setSpring(@NonNull final Spring spring) {
    mSpring = spring;

    if (mSpring != null) {
        // Start spring at rest.
        mSpring.setCurrentValue(mRestValue, true);
    }
}
项目:PrismView    文件:PrismActivity.java   
private void onSpringAtRestOut(Spring spring) {
  if (hideEnabled) {
    if (spring.getCurrentValue() == 1) {
      showPrismView();
    } else {
      showMainView();
    }
  }
}
项目:springy-heads    文件:ChatHead.java   
@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);
    }
}
项目:springy-heads    文件:MinimizedArrangement.java   
@Override
public void onSpringAtRest(Spring spring) {
    super.onSpringAtRest(spring);
    if (isTransitioning) {
        isTransitioning = false;
    }
}
项目:Backboard    文件:MapPerformer.java   
@Override
public void onSpringUpdate(@NonNull final Spring spring) {

    mProperty.set(mTarget,
            (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(),
                    initialStart, initialEnd, start, end)
    );
}
项目:SwipCard    文件:DragCard.java   
@Override
public void onSpringUpdate(Spring spring) {
    float value = (float) spring.getCurrentValue();
    float scale = 1f - (value * 0.5f);
    ViewCompat.setScaleX(DragCard.this, scale);
    ViewCompat.setScaleY(DragCard.this, scale);
}
项目:KugouLayout    文件:SpringConfiguratorView.java   
@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);
}
项目:Bound    文件:SpringController.java   
public Spring slideButtonSpring() {
  if(slideButtonSpring == null) {
    synchronized (Spring.class) {
      if(slideButtonSpring == null) {
        slideButtonSpring = SpringSystem
            .create()
            .createSpring()
            .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(slideButtonTension, slideButtonFriction));
      }
    }
  }
  return slideButtonSpring;
}