summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/mail/browse/ConversationItemView.java53
-rw-r--r--src/com/android/mail/browse/SwipeableConversationItemView.java13
-rw-r--r--src/com/android/mail/ui/AnimatedAdapter.java54
-rw-r--r--src/com/android/mail/ui/LeaveBehindItem.java5
4 files changed, 103 insertions, 22 deletions
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index 5753dd9a5..5512ae2e2 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -17,7 +17,9 @@
package com.android.mail.browse;
+import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.ClipData;
import android.content.ClipData.Item;
@@ -160,6 +162,7 @@ public class ConversationItemView extends View implements SwipeableItemView {
private int mLastTouchX;
private int mLastTouchY;
private AnimatedAdapter mAdapter;
+ private int mAnimatedHeight = -1;
private static int sUndoAnimationOffset;
private static CharSequence sDraftSingularString;
private static CharSequence sDraftPluralString;
@@ -1333,24 +1336,62 @@ public class ConversationItemView extends View implements SwipeableItemView {
/**
* Grow the height of the item and fade it in when bringing a conversation
* back from a destructive action.
- *
* @param listener
*/
- public void startUndoAnimation(ViewMode viewMode, final AnimatorListener listener) {
+ public void startSwipeUndoAnimation(ViewMode viewMode, final AnimatorListener listener) {
final int start = sUndoAnimationOffset;
final int end = 0;
- ObjectAnimator undoAnimator = ObjectAnimator.ofFloat(this, "translationX" , start, end);
+ ObjectAnimator undoAnimator = ObjectAnimator.ofFloat(this, "translationX", start, end);
undoAnimator.setInterpolator(new DecelerateInterpolator(2.0f));
undoAnimator.addListener(listener);
undoAnimator.setDuration(sUndoAnimationDuration);
undoAnimator.start();
}
+ /**
+ * Grow the height of the item and fade it in when bringing a conversation
+ * back from a destructive action.
+ * @param listener
+ */
+ public void startUndoAnimation(ViewMode viewMode, final AnimatorListener listener) {
+ int minHeight = ConversationItemViewCoordinates.getMinHeight(mContext, viewMode);
+ setMinimumHeight(minHeight);
+ final int start = 0;
+ final int end = minHeight;
+ ObjectAnimator undoAnimator = ObjectAnimator.ofInt(this, "animatedHeight", start, end);
+ Animator fadeAnimator = ObjectAnimator.ofFloat(this, "itemAlpha", 0, 1.0f);
+ mAnimatedHeight = start;
+ undoAnimator.setInterpolator(new DecelerateInterpolator(2.0f));
+ undoAnimator.addListener(listener);
+ undoAnimator.setDuration(sUndoAnimationDuration);
+ AnimatorSet transitionSet = new AnimatorSet();
+ transitionSet.playTogether(undoAnimator, fadeAnimator);
+ transitionSet.start();
+ }
+
+ // Used by animator
+ @SuppressWarnings("unused")
+ public void setItemAlpha(float alpha) {
+ setAlpha(alpha);
+ invalidate();
+ }
+
+ // Used by animator
+ @SuppressWarnings("unused")
+ public void setAnimatedHeight(int height) {
+ mAnimatedHeight = height;
+ requestLayout();
+ }
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int height = measureHeight(heightMeasureSpec,
- ConversationItemViewCoordinates.getMode(mContext, mViewMode));
- setMeasuredDimension(widthMeasureSpec, height);
+ if (mAnimatedHeight == -1) {
+ int height = measureHeight(heightMeasureSpec,
+ ConversationItemViewCoordinates.getMode(mContext, mViewMode));
+ setMeasuredDimension(widthMeasureSpec, height);
+ } else {
+ setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mAnimatedHeight);
+ }
}
/**
diff --git a/src/com/android/mail/browse/SwipeableConversationItemView.java b/src/com/android/mail/browse/SwipeableConversationItemView.java
index c0a7bbfec..677c611a5 100644
--- a/src/com/android/mail/browse/SwipeableConversationItemView.java
+++ b/src/com/android/mail/browse/SwipeableConversationItemView.java
@@ -90,7 +90,16 @@ public class SwipeableConversationItemView extends FrameLayout {
animatedAdapter);
}
- public void startUndoAnimation(ViewMode viewMode, AnimatedAdapter listener) {
- mConversationItemView.startUndoAnimation(viewMode, listener);
+ public void startUndoAnimation(int actionText, ViewMode viewMode, AnimatedAdapter listener,
+ boolean swipe) {
+ if (swipe) {
+ addBackground(getContext(), actionText);
+ setBackgroundVisibility(View.VISIBLE);
+ mConversationItemView.startSwipeUndoAnimation(viewMode, listener);
+ } else {
+ setBackgroundVisibility(View.GONE);
+ mConversationItemView.startUndoAnimation(viewMode, listener);
+ }
+
}
}
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index f27f510af..9b9803fee 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -54,6 +54,7 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
private final static int TYPE_VIEW_LEAVEBEHIND = 4;
private HashSet<Integer> mDeletingItems = new HashSet<Integer>();
private HashSet<Integer> mUndoingItems = new HashSet<Integer>();
+ private HashSet<Integer> mSwipeUndoingItems = new HashSet<Integer>();
private Account mSelectedAccount;
private Context mContext;
private ConversationSelectionSet mBatchConversations;
@@ -119,6 +120,16 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
}
}
+ public void setSwipeUndo(boolean undo) {
+ if (undo && !mLastDeletingItems.isEmpty()) {
+ mSwipeUndoingItems.addAll(mLastDeletingItems);
+ mLastDeletingItems.clear();
+ // Start animation
+ notifyDataSetChanged();
+ performAndSetNextAction(mRefreshAction);
+ }
+ }
+
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
SwipeableConversationItemView view = new SwipeableConversationItemView(context,
@@ -154,7 +165,7 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
if (isPositionDeleting(position)) {
return TYPE_VIEW_DELETING;
}
- if (isPositionUndoing(position)) {
+ if (isPositionUndoingType(position)) {
return TYPE_VIEW_UNDOING;
}
if (mShowFooter && position == super.getCount()) {
@@ -228,7 +239,11 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
return mFooter;
}
if (isPositionUndoing(position)) {
- return getUndoingView(position, convertView, parent);
+ return getUndoingView(position, convertView, parent,
+ false /* don't show swipe background */);
+ } if (isPositionUndoingSwipe(position)) {
+ return getUndoingView(position, convertView, parent,
+ true /* show swipe background */);
} else if (isPositionDeleting(position)) {
return getDeletingView(position, convertView, parent);
}
@@ -356,20 +371,18 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
return view;
}
- private View getUndoingView(int position, View convertView, ViewGroup parent) {
+ private View getUndoingView(int position, View convertView, ViewGroup parent,
+ boolean swipe) {
Conversation conversation = new Conversation((ConversationCursor) getItem(position));
conversation.position = position;
// The undo animation consists of fading in the conversation that
// had been destroyed.
final SwipeableConversationItemView convView = (SwipeableConversationItemView) super
.getView(position, null, parent);
- convView.setBackgroundVisibility(View.GONE);
convView.bind(conversation, mViewMode, mBatchConversations, mFolder,
mCachedSettings != null ? mCachedSettings.hideCheckboxes : false, mSwipeEnabled,
this);
- convView.addBackground(mContext, mListView.getSwipeActionText());
- convView.setBackgroundVisibility(View.VISIBLE);
- convView.startUndoAnimation(mViewMode, this);
+ convView.startUndoAnimation(mListView.getSwipeActionText(), mViewMode, this, swipe);
return convView;
}
@@ -389,6 +402,14 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
return mUndoingItems.contains(position);
}
+ private boolean isPositionUndoingSwipe(int position) {
+ return mSwipeUndoingItems.contains(position);
+ }
+
+ private boolean isPositionUndoingType(int position) {
+ return isPositionUndoing(position) || isPositionUndoingSwipe(position);
+ }
+
private boolean isPositionLeaveBehind(Conversation conv) {
return hasLeaveBehinds()
&& mLeaveBehindItem.getConversationId() == conv.id
@@ -443,14 +464,21 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
clearLeaveBehind(objItem.getConversationId());
objItem.commit();
}
- } else if (!mUndoingItems.isEmpty()) {
+ } else if (hasUndoingItems()) {
// See if we have received all the animations we expected; if
// so, call the listener and reset it.
final int position = ((ConversationItemView) ((ObjectAnimator) animation).getTarget())
.getPosition();
- mUndoingItems.remove(position);
- if (mUndoingItems.isEmpty()) {
- performAndSetNextAction(null);
+ if (isPositionUndoingSwipe(position)) {
+ mSwipeUndoingItems.remove(position);
+ if (mSwipeUndoingItems.isEmpty()) {
+ performAndSetNextAction(null);
+ }
+ } else if (isPositionUndoing(position)) {
+ mUndoingItems.remove(position);
+ if (mUndoingItems.isEmpty()) {
+ performAndSetNextAction(null);
+ }
}
} else if (!mDeletingItems.isEmpty()) {
// See if we have received all the animations we expected; if
@@ -467,6 +495,10 @@ public class AnimatedAdapter extends SimpleCursorAdapter implements
notifyDataSetChanged();
}
+ private boolean hasUndoingItems() {
+ return !mUndoingItems.isEmpty() || !mSwipeUndoingItems.isEmpty();
+ }
+
@Override
public boolean areAllItemsEnabled() {
// The animating positions are not enabled.
diff --git a/src/com/android/mail/ui/LeaveBehindItem.java b/src/com/android/mail/ui/LeaveBehindItem.java
index 598a5486e..0f937ef7b 100644
--- a/src/com/android/mail/ui/LeaveBehindItem.java
+++ b/src/com/android/mail/ui/LeaveBehindItem.java
@@ -61,12 +61,11 @@ public class LeaveBehindItem extends AnimatingItemView implements OnClickListene
case R.id.undo_button:
if (mAccount.undoUri != null) {
// NOTE: We might want undo to return the messages affected,
- // in which case
- // the resulting cursor might be interesting...
+ // in which case the resulting cursor might be interesting...
// TODO: Use UIProvider.SEQUENCE_QUERY_PARAMETER to indicate
// the set of commands to undo
mAdapter.clearLeaveBehind(getConversationId());
- mAdapter.setUndo(true);
+ mAdapter.setSwipeUndo(true);
mConversationCursor.undo(getContext(), mAccount.undoUri);
}
break;