Merge change I8b63ab66 into eclair

* changes:
  Better animation for sliding widget.
This commit is contained in:
Android (Google) Code Review
2009-12-03 22:14:19 -08:00

View File

@ -433,9 +433,16 @@ public class SlidingTab extends ViewGroup {
return tab.getMeasuredHeight(); return tab.getMeasuredHeight();
} }
public void startAnimation(Animation animation) { /**
tab.startAnimation(animation); * Start animating the slider. Note we need two animations since an Animator
text.startAnimation(animation); * keeps internal state of the invalidation region which is just the view being animated.
*
* @param anim1
* @param anim2
*/
public void startAnimation(Animation anim1, Animation anim2) {
tab.startAnimation(anim1);
text.startAnimation(anim2);
} }
public void hideTarget() { public void hideTarget() {
@ -620,7 +627,8 @@ public class SlidingTab extends ViewGroup {
void startAnimating(final boolean holdAfter) { void startAnimating(final boolean holdAfter) {
mAnimating = true; mAnimating = true;
final Animation trans; final Animation trans1;
final Animation trans2;
final Slider slider = mCurrentSlider; final Slider slider = mCurrentSlider;
final Slider other = mOtherSlider; final Slider other = mOtherSlider;
final int dx; final int dx;
@ -644,12 +652,16 @@ public class SlidingTab extends ViewGroup {
dy = slider == mRightSlider ? (top + viewHeight - holdOffset) dy = slider == mRightSlider ? (top + viewHeight - holdOffset)
: - ((viewHeight - bottom) + viewHeight - holdOffset); : - ((viewHeight - bottom) + viewHeight - holdOffset);
} }
trans = new TranslateAnimation(0, dx, 0, dy); trans1 = new TranslateAnimation(0, dx, 0, dy);
trans.setDuration(ANIM_DURATION); trans1.setDuration(ANIM_DURATION);
trans.setInterpolator(new LinearInterpolator()); trans1.setInterpolator(new LinearInterpolator());
trans.setFillAfter(true); trans1.setFillAfter(true);
trans2 = new TranslateAnimation(0, dx, 0, dy);
trans2.setDuration(ANIM_DURATION);
trans2.setInterpolator(new LinearInterpolator());
trans2.setFillAfter(true);
trans.setAnimationListener(new AnimationListener() { trans1.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
Animation anim; Animation anim;
if (holdAfter) { if (holdAfter) {
@ -662,8 +674,10 @@ public class SlidingTab extends ViewGroup {
resetView(); resetView();
} }
anim.setAnimationListener(mAnimationDoneListener); anim.setAnimationListener(mAnimationDoneListener);
mLeftSlider.startAnimation(anim);
mRightSlider.startAnimation(anim); /* Animation can be the same for these since the animation just holds */
mLeftSlider.startAnimation(anim, anim);
mRightSlider.startAnimation(anim, anim);
} }
public void onAnimationRepeat(Animation animation) { public void onAnimationRepeat(Animation animation) {
@ -677,7 +691,7 @@ public class SlidingTab extends ViewGroup {
}); });
slider.hideTarget(); slider.hideTarget();
slider.startAnimation(trans); slider.startAnimation(trans1, trans2);
} }
private void onAnimationDone() { private void onAnimationDone() {