Make sure onSwitchComplete() is also called when animations are disabled

This commit is contained in:
cketti 2013-02-06 20:44:06 +01:00
parent 0febc8c312
commit 1244cc864a
2 changed files with 19 additions and 10 deletions

View File

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

View File

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