////@Override public void onSpringUpdate(Spring spring) { // Get the control spring index and update the endValue of each spring above and below it in the // spring collection triggering a cascading effect. int idx = mSprings.ToList <Spring>().IndexOf(spring); SpringListener listener = mListeners.ElementAt <SpringListener>(idx); int above = -1; int below = -1; if (idx == mControlSpringIndex) { below = idx - 1; above = idx + 1; } else if (idx < mControlSpringIndex) { below = idx - 1; } else if (idx > mControlSpringIndex) { above = idx + 1; } if (above > -1 && above < mSprings.Count) { mSprings.ElementAtOrDefault(above).setEndValue(spring.getCurrentValue()); } if (below > -1 && below < mSprings.Count) { mSprings.ElementAtOrDefault(below).setEndValue(spring.getCurrentValue()); } listener.onSpringUpdate(spring); }
/** * remove a listener * @param listenerToRemove to remove * @return the spring for chaining */ public Spring removeListener(SpringListener listenerToRemove) { if (listenerToRemove == null) { throw new IllegalArgumentException("listenerToRemove is required"); } mListeners.Remove(listenerToRemove); return(this); }
/** listeners **/ /** * add a listener * @param newListener to add * @return the spring for chaining */ public Spring addListener(SpringListener newListener) { if (newListener == null) { throw new IllegalArgumentException("newListener is required"); } mListeners.Add(newListener); return(this); }
/** * Add a spring to the chain that will callback to the provided listener. * @param listener the listener to notify for this Spring in the chain * @return this SpringChain for chaining */ public SpringChain addSpring(SpringListener listener) { // We listen to each spring added to the SpringChain and dynamically chain the springs together // whenever the control spring state is modified. Spring spring = mSpringSystem .createSpring() .addListener(this) .setSpringConfig(mAttachmentSpringConfig); mSprings.Add(spring); mListeners.Add(listener); return(this); }