1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Only remove message view fragment after animation is complete

This commit is contained in:
cketti 2013-02-06 00:56:33 +01:00
parent 473aebefdb
commit 3286cea148
2 changed files with 45 additions and 3 deletions

View File

@ -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();
}
}
}

View File

@ -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);
}
}