From 1244cc864a57ddbae21f7dc10fbee61543888263 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 6 Feb 2013 20:44:06 +0100 Subject: [PATCH] Make sure onSwitchComplete() is also called when animations are disabled --- src/com/fsck/k9/activity/MessageList.java | 8 ++++---- src/com/fsck/k9/view/ViewSwitcher.java | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 276e4f95d..b12bd1931 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -53,7 +53,7 @@ import com.fsck.k9.search.SearchSpecification.SearchCondition; import com.fsck.k9.view.MessageHeader; import com.fsck.k9.view.MessageTitleView; import com.fsck.k9.view.ViewSwitcher; -import com.fsck.k9.view.ViewSwitcher.OnAnimationEndListener; +import com.fsck.k9.view.ViewSwitcher.OnSwitchCompleteListener; import de.cketti.library.changelog.ChangeLog; @@ -65,7 +65,7 @@ import de.cketti.library.changelog.ChangeLog; */ public class MessageList extends K9FragmentActivity implements MessageListFragmentListener, MessageViewFragmentListener, OnBackStackChangedListener, OnSwipeGestureListener, - OnAnimationEndListener { + OnSwitchCompleteListener { // for this activity private static final String EXTRA_SEARCH = "search"; @@ -206,7 +206,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme mViewSwitcher.setFirstOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right)); mViewSwitcher.setSecondInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right)); mViewSwitcher.setSecondOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left)); - mViewSwitcher.setOnAnimationEndListener(this); + mViewSwitcher.setOnSwitchCompleteListener(this); } initializeActionBar(); @@ -1436,7 +1436,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme } @Override - public void onAnimationEnd(int displayedChild) { + public void onSwitchComplete(int displayedChild) { if (displayedChild == 0) { removeMessageViewFragment(); } diff --git a/src/com/fsck/k9/view/ViewSwitcher.java b/src/com/fsck/k9/view/ViewSwitcher.java index b60716e38..f38beb7f2 100644 --- a/src/com/fsck/k9/view/ViewSwitcher.java +++ b/src/com/fsck/k9/view/ViewSwitcher.java @@ -17,7 +17,7 @@ public class ViewSwitcher extends ViewAnimator implements AnimationListener { private Animation mFirstOutAnimation; private Animation mSecondInAnimation; private Animation mSecondOutAnimation; - private OnAnimationEndListener mListener; + private OnSwitchCompleteListener mListener; public ViewSwitcher(Context context) { @@ -35,6 +35,7 @@ public class ViewSwitcher extends ViewAnimator implements AnimationListener { setupAnimations(mFirstInAnimation, mFirstOutAnimation); setDisplayedChild(0); + handleSwitchCompleteCallback(); } public void showSecondView() { @@ -44,18 +45,26 @@ public class ViewSwitcher extends ViewAnimator implements AnimationListener { setupAnimations(mSecondInAnimation, mSecondOutAnimation); setDisplayedChild(1); + handleSwitchCompleteCallback(); } private void setupAnimations(Animation in, Animation out) { if (K9.showAnimations()) { setInAnimation(in); setOutAnimation(out); + out.setAnimationListener(this); } else { setInAnimation(null); setOutAnimation(null); } } + private void handleSwitchCompleteCallback() { + if (!K9.showAnimations()) { + onAnimationEnd(null); + } + } + public Animation getFirstInAnimation() { return mFirstInAnimation; } @@ -88,14 +97,14 @@ public class ViewSwitcher extends ViewAnimator implements AnimationListener { mSecondOutAnimation = outAnimation; } - public void setOnAnimationEndListener(OnAnimationEndListener listener) { + public void setOnSwitchCompleteListener(OnSwitchCompleteListener listener) { mListener = listener; } @Override public void onAnimationEnd(Animation animation) { if (mListener != null) { - mListener.onAnimationEnd(getDisplayedChild()); + mListener.onSwitchComplete(getDisplayedChild()); } } @@ -109,13 +118,13 @@ public class ViewSwitcher extends ViewAnimator implements AnimationListener { // unused } - public interface OnAnimationEndListener { + public interface OnSwitchCompleteListener { /** - * This method will be called after the switch animation has ended. + * This method will be called after the switch (including animation) has ended. * * @param displayedChild * Contains the zero-based index of the child view that is now displayed. */ - void onAnimationEnd(int displayedChild); + void onSwitchComplete(int displayedChild); } }