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); } }); }
@Override public void applyFloatingAnimation(@NonNull final FloatingTextView view) { Spring scaleAnim = createSpringByBouncinessAndSpeed(10, 15) .addListener(new SimpleSpringListener() { @Override public void onSpringUpdate(@NonNull Spring spring) { float transition = transition((float) spring.getCurrentValue(), 0.0f, 1.0f); view.setScaleX(transition); view.setScaleY(transition); } }); ValueAnimator alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0.0f); alphaAnimator.setDuration(duration); alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) { view.setAlpha((Float) valueAnimator.getAnimatedValue()); } }); scaleAnim.setEndValue(1f); alphaAnimator.start(); }
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(); }
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); }
private void initializeListeners() { SimpleSpringListener simpleSpringListener = null; if (prismPosition == PrismPosition.RIGHT) { simpleSpringListener = translationRight; } else if (prismPosition == PrismPosition.LEFT) { simpleSpringListener = translationLeft; } else if (prismPosition == PrismPosition.TOP) { simpleSpringListener = translationTop; } else if (prismPosition == PrismPosition.BOTTOM) { simpleSpringListener = translationBottom; } if (simpleSpringListener != null) { moveSpring().removeAllListeners().addListener(simpleSpringListener); } }
public SimpleSpringListener getFollowerListenerX() { return followerListenerX; }
public SimpleSpringListener getFollowerListenerY() { return followerListenerY; }
public OrigamiExample(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Inflate the layout. LayoutInflater inflater = LayoutInflater.from(context); ViewGroup root = (ViewGroup) inflater.inflate(R.layout.origami_example, this, false); addView(root); // Listen for clicks on the root view. root.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { handleClick(v); } }); // Get references to our views. mPhotoGrid = root.findViewById(R.id.grid); mSelectedPhoto = root.findViewById(R.id.selection); mFeedbackBar = root.findViewById(R.id.feedback); mSpringConfiguratorView = (SpringConfiguratorView) root.findViewById(R.id.spring_configurator); // Setup the Spring by creating a SpringSystem adding a SimpleListener that renders the // animation whenever the spring is updated. mSpring = SpringSystem .create() .createSpring() .setSpringConfig(ORIGAMI_SPRING_CONFIG) .addListener(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring spring) { // Just tell the UI to update based on the springs current state. render(); } }); // Here we just wait until the first layout pass finishes and call our render method to update // the animation to the initial resting state of the spring. mPhotoGrid.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { render(); mPhotoGrid.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); /** Optional - Live Spring Tuning **/ // Put our config into a registry. This is optional, but it gives you the ability to live tune // the spring using the SpringConfiguratorView which will show up at the bottom of the screen. SpringConfigRegistry.getInstance().addSpringConfig(ORIGAMI_SPRING_CONFIG, "origami animation spring"); // Tell the SpringConfiguratorView that we've updated the registry to allow you to live tune the animation spring. mSpringConfiguratorView.refreshSpringConfigurations(); // Uncomment this line to actually show the SpringConfiguratorView allowing you to live tune // the Spring constants as you manipulate the UI. mSpringConfiguratorView.setVisibility(View.VISIBLE); }
public PhotoGalleryExample(Context context) { super(context); int viewCount = ROWS * COLS; for (int i = 0; i < viewCount; i++) { final int j = i; // Create the View. final ImageView imageView = new ImageView(context); mImageViews.add(imageView); addView(imageView); imageView.setAlpha(0f); imageView.setBackgroundColor(Util.randomColor()); imageView.setLayerType(LAYER_TYPE_HARDWARE, null); // Add an image for each view. int res = getResources().getIdentifier("d" + (i % 11 + 1), "drawable", context.getPackageName()); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(res); // Add a click listener to handle scaling up the view. imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int endValue = mSpring.getEndValue() == 0 ? 1 : 0; imageView.bringToFront(); mActiveIndex = j; mSpring.setEndValue(endValue); } }); // Add a spring to the SpringChain to do an entry animation. mSpringChain.addSpring(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring spring) { render(); } }); } // Wait for layout. getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { layout(); getViewTreeObserver().removeOnGlobalLayoutListener(this); postOnAnimationDelayed(new Runnable() { @Override public void run() { mSpringChain.setControlSpringIndex(0).getControlSpring().setEndValue(1); } }, 500); } }); }
public SpringChainExample(Context context) { super(context); LayoutInflater inflater = LayoutInflater.from(context); ViewGroup container = (ViewGroup) inflater.inflate(R.layout.cascade_effect, this, false); addView(container); ViewGroup rootView = (ViewGroup) container.findViewById(R.id.root); int bgColor = Color.argb(255, 17, 148, 231); setBackgroundColor(bgColor); rootView.setBackgroundResource(R.drawable.rebound_tiles); int startColor = Color.argb(255, 255, 64, 230); int endColor = Color.argb(255, 255, 230, 64); ArgbEvaluator evaluator = new ArgbEvaluator(); int viewCount = 10; for (int i = 0; i < viewCount; i++) { final View view = new View(context); view.setLayoutParams( new TableLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); mSpringChain.addSpring(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring spring) { float value = (float) spring.getCurrentValue(); view.setTranslationX(value); } }); int color = (Integer) evaluator.evaluate((float) i / (float) viewCount, startColor, endColor); view.setBackgroundColor(color); view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return handleRowTouch(v, event); } }); mViews.add(view); rootView.addView(view); } getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { getViewTreeObserver().removeOnGlobalLayoutListener(this); List<Spring> springs = mSpringChain.getAllSprings(); for (int i = 0; i < springs.size(); i++) { springs.get(i).setCurrentValue(-mViews.get(i).getWidth()); } postDelayed(new Runnable() { @Override public void run() { mSpringChain .setControlSpringIndex(0) .getControlSpring() .setEndValue(0); } }, 500); } }); }
public OrigamiExample(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Inflate the layout. LayoutInflater inflater = LayoutInflater.from(context); ViewGroup root = (ViewGroup) inflater.inflate(R.layout.origami_example, this, false); addView(root); // Listen for clicks on the root view. root.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { handleClick(v); } }); // Get references to our views. mPhotoGrid = root.findViewById(R.id.grid); mSelectedPhoto = root.findViewById(R.id.selection); mFeedbackBar = root.findViewById(R.id.feedback); mSpringConfiguratorView = (SpringConfiguratorView) root.findViewById(R.id.spring_configurator); // Setup the Spring by creating a SpringSystem adding a SimpleListener that renders the // animation whenever the spring is updated. mSpring = SpringSystem .create() .createSpring() .setSpringConfig(ORIGAMI_SPRING_CONFIG) .addListener(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring spring) { // Just tell the UI to update based on the springs current state. render(); } }); // Here we just wait until the first layout pass finishes and call our render method to update // the animation to the initial resting state of the spring. mPhotoGrid.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { render(); mPhotoGrid.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); /** Optional - Live Spring Tuning **/ // Put our config into a registry. This is optional, but it gives you the ability to live tune // the spring using the SpringConfiguratorView which will show up at the bottom of the screen. SpringConfigRegistry.getInstance().addSpringConfig(ORIGAMI_SPRING_CONFIG, "origami animation spring"); // Tell the SpringConfiguratorView that we've updated the registry to allow you to live tune the animation spring. mSpringConfiguratorView.refreshSpringConfigurations(); // Uncomment this line to actually show the SpringConfiguratorView allowing you to live tune // the Spring constants as you manipulate the UI. mSpringConfiguratorView.setVisibility(View.VISIBLE); }