| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.transition; |
| 18 |
|
| 19 |
import android.animation.Animator; |
| 20 |
import android.animation.ObjectAnimator; |
| 21 |
import android.content.Context; |
| 22 |
import android.util.AttributeSet; |
| 23 |
import android.view.View; |
| 24 |
import android.view.ViewGroup; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class ChangeScroll extends Transition { |
| 31 |
|
| 32 |
private static final String PROPNAME_SCROLL_X = "android:changeScroll:x"; |
| 33 |
private static final String PROPNAME_SCROLL_Y = "android:changeScroll:y"; |
| 34 |
|
| 35 |
private static final String[] PROPERTIES = { |
| 36 |
PROPNAME_SCROLL_X, |
| 37 |
PROPNAME_SCROLL_Y, |
| 38 |
}; |
| 39 |
|
| 40 |
public ChangeScroll() {} |
| 41 |
|
| 42 |
public ChangeScroll(Context context, AttributeSet attrs) { |
| 43 |
super(context, attrs); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public void captureStartValues(TransitionValues transitionValues) { |
| 48 |
captureValues(transitionValues); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void captureEndValues(TransitionValues transitionValues) { |
| 53 |
captureValues(transitionValues); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public String[] getTransitionProperties() { |
| 58 |
return PROPERTIES; |
| 59 |
} |
| 60 |
|
| 61 |
private void captureValues(TransitionValues transitionValues) { |
| 62 |
transitionValues.values.put(PROPNAME_SCROLL_X, transitionValues.view.getScrollX()); |
| 63 |
transitionValues.values.put(PROPNAME_SCROLL_Y, transitionValues.view.getScrollY()); |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, |
| 68 |
TransitionValues endValues) { |
| 69 |
if (startValues == null || endValues == null) { |
| 70 |
return null; |
| 71 |
} |
| 72 |
final View view = endValues.view; |
| 73 |
int startX = (Integer) startValues.values.get(PROPNAME_SCROLL_X); |
| 74 |
int endX = (Integer) endValues.values.get(PROPNAME_SCROLL_X); |
| 75 |
int startY = (Integer) startValues.values.get(PROPNAME_SCROLL_Y); |
| 76 |
int endY = (Integer) endValues.values.get(PROPNAME_SCROLL_Y); |
| 77 |
Animator scrollXAnimator = null; |
| 78 |
Animator scrollYAnimator = null; |
| 79 |
if (startX != endX) { |
| 80 |
view.setScrollX(startX); |
| 81 |
scrollXAnimator = ObjectAnimator.ofInt(view, "scrollX", startX, endX); |
| 82 |
} |
| 83 |
if (startY != endY) { |
| 84 |
view.setScrollY(startY); |
| 85 |
scrollYAnimator = ObjectAnimator.ofInt(view, "scrollY", startY, endY); |
| 86 |
} |
| 87 |
return TransitionUtils.mergeAnimators(scrollXAnimator, scrollYAnimator); |
| 88 |
} |
| 89 |
} |