diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 367751f82..5c227ab33 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -53,6 +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 de.cketti.library.changelog.ChangeLog; @@ -63,7 +64,8 @@ import de.cketti.library.changelog.ChangeLog; * From this Activity the user can perform all standard message operations. */ public class MessageList extends K9FragmentActivity implements MessageListFragmentListener, - MessageViewFragmentListener, OnBackStackChangedListener, OnSwipeGestureListener { + MessageViewFragmentListener, OnBackStackChangedListener, OnSwipeGestureListener, + OnAnimationEndListener { // for this activity private static final String EXTRA_SEARCH = "search"; @@ -204,6 +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); } initializeActionBar(); @@ -1362,7 +1365,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme mMessageListFragment.setActiveMessage(null); showDefaultTitleView(); - removeMessageViewFragment(); } private void showMessageView() { @@ -1427,4 +1429,11 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme mMessageViewFragment.updateTitle(); } } + + @Override + public void onAnimationEnd(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 686af4981..f394b5f74 100644 --- a/src/com/fsck/k9/view/ViewSwitcher.java +++ b/src/com/fsck/k9/view/ViewSwitcher.java @@ -3,17 +3,19 @@ package com.fsck.k9.view; import android.content.Context; import android.util.AttributeSet; import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; import android.widget.ViewAnimator; /** * A {@link ViewAnimator} that animates between two child views using different animations * depending on which view is displayed. */ -public class ViewSwitcher extends ViewAnimator { +public class ViewSwitcher extends ViewAnimator implements AnimationListener { private Animation mFirstInAnimation; private Animation mFirstOutAnimation; private Animation mSecondInAnimation; private Animation mSecondOutAnimation; + private OnAnimationEndListener mListener; public ViewSwitcher(Context context) { @@ -75,4 +77,35 @@ public class ViewSwitcher extends ViewAnimator { public void setSecondOutAnimation(Animation outAnimation) { mSecondOutAnimation = outAnimation; } + + public void setOnAnimationEndListener(OnAnimationEndListener listener) { + mListener = listener; + } + + @Override + public void onAnimationEnd(Animation animation) { + if (mListener != null) { + mListener.onAnimationEnd(getDisplayedChild()); + } + } + + @Override + public void onAnimationRepeat(Animation animation) { + // unused + } + + @Override + public void onAnimationStart(Animation animation) { + // unused + } + + public interface OnAnimationEndListener { + /** + * This method will be called after the switch animation has ended. + * + * @param displayedChild + * Contains the zero-based index of the child view that is now displayed. + */ + void onAnimationEnd(int displayedChild); + } }