diff options
author | Mindy Pereira <mindyp@google.com> | 2012-04-07 14:29:15 -0700 |
---|---|---|
committer | Mindy Pereira <mindyp@google.com> | 2012-04-16 10:46:43 -0700 |
commit | 6c72a787b58a0bc3afcb71093eddf8c29d1cf5ed (patch) | |
tree | 98f391b487e52f75247add5bd38c6bacb647f4df /src/com/android/mail/ui/LeaveBehindItem.java | |
parent | a137a52a1f51ea8502636e87294dfa2eb2985b46 (diff) | |
download | android_packages_apps_UnifiedEmail-6c72a787b58a0bc3afcb71093eddf8c29d1cf5ed.tar.gz android_packages_apps_UnifiedEmail-6c72a787b58a0bc3afcb71093eddf8c29d1cf5ed.tar.bz2 android_packages_apps_UnifiedEmail-6c72a787b58a0bc3afcb71093eddf8c29d1cf5ed.zip |
Show leavebehind after swiping away an item.
Change-Id: I3bae79ed5bb8919985dbfa6e81416da980281cff
Diffstat (limited to 'src/com/android/mail/ui/LeaveBehindItem.java')
-rw-r--r-- | src/com/android/mail/ui/LeaveBehindItem.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/com/android/mail/ui/LeaveBehindItem.java b/src/com/android/mail/ui/LeaveBehindItem.java new file mode 100644 index 000000000..5790b6cdd --- /dev/null +++ b/src/com/android/mail/ui/LeaveBehindItem.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2012 Google Inc. + * Licensed to The Android Open Source Project. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mail.ui; + +import android.content.Context; +import android.text.Html; +import android.util.AttributeSet; +import android.widget.Button; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.view.View; +import android.view.View.OnClickListener; + +import com.android.mail.R; +import com.android.mail.providers.Account; +import com.android.mail.providers.Conversation; +import com.android.mail.ui.SwipeableListView.SwipeCompleteListener; +import com.google.common.collect.ImmutableList; + +import java.util.ArrayList; +import java.util.Collection; + +public class LeaveBehindItem extends RelativeLayout implements OnClickListener, SwipeableItemView { + + private UndoOperation mUndoOp; + private Account mAccount; + private AnimatedAdapter mAdapter; + private Conversation mConversation; + + public LeaveBehindItem(Context context) { + this(context, null); + } + + public LeaveBehindItem(Context context, AttributeSet attrs) { + this(context, attrs, -1); + } + + public LeaveBehindItem(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + switch (id) { + 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... + // TODO: Use UIProvider.SEQUENCE_QUERY_PARAMETER to indicate + // the set of + // commands to undo + mAdapter.clearLeaveBehind(mConversation); + mAdapter.setUndo(true); + Conversation.undo(getContext(), mAccount.undoUri); + } + break; + } + } + + public void bindOperations(Account account, AnimatedAdapter adapter, UndoOperation undoOp, + Conversation target) { + mUndoOp = undoOp; + mAccount = account; + mAdapter = adapter; + mConversation = target; + ((TextView) findViewById(R.id.undo_description)).setText(Html.fromHtml(mUndoOp + .getDescription(getContext()))); + ((Button) findViewById(R.id.undo_button)).setOnClickListener(this); + } + + public void commit() { + Conversation.delete(getContext(), ImmutableList.of(mConversation)); + mAdapter.clearLeaveBehind(mConversation); + } + + public boolean canSwipe() { + return true; + } + + @Override + public View getView() { + return this; + } + + @Override + public void cancelTap() { + // Do nothing. + } +} |