Home | History | Annotate | Download | only in browse
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mail.browse;
     19 
     20 import android.animation.Animator;
     21 import android.animation.Animator.AnimatorListener;
     22 import android.content.Context;
     23 import android.widget.FrameLayout;
     24 import android.widget.ListView;
     25 
     26 import com.android.mail.providers.Conversation;
     27 import com.android.mail.providers.Folder;
     28 import com.android.mail.providers.UIProvider;
     29 import com.android.mail.ui.AnimatedAdapter;
     30 import com.android.mail.ui.ControllableActivity;
     31 import com.android.mail.ui.ConversationSelectionSet;
     32 
     33 public class SwipeableConversationItemView extends FrameLayout implements ToggleableItem {
     34 
     35     private final ConversationItemView mConversationItemView;
     36 
     37     public SwipeableConversationItemView(Context context, String account) {
     38         super(context);
     39         mConversationItemView = new ConversationItemView(context, account);
     40         addView(mConversationItemView);
     41     }
     42 
     43     public ListView getListView() {
     44         return (ListView) getParent();
     45     }
     46 
     47     public void reset() {
     48         mConversationItemView.reset();
     49     }
     50 
     51     public ConversationItemView getSwipeableItemView() {
     52         return mConversationItemView;
     53     }
     54 
     55     public void bind(final Conversation conversation, final ControllableActivity activity,
     56             final ConversationSelectionSet set, final Folder folder,
     57             final int checkboxOrSenderImage, boolean swipeEnabled,
     58             final boolean importanceMarkersEnabled, final boolean showChevronsEnabled,
     59             final AnimatedAdapter animatedAdapter) {
     60         // Only enable delete for failed items in the Outbox.
     61         // Necessary to do it here because Outbox is the only place where we selectively enable
     62         // swipe on a item-by-item basis.
     63         if (folder.isType(UIProvider.FolderType.OUTBOX)) {
     64             swipeEnabled &=
     65                     conversation.sendingState != UIProvider.ConversationSendingState.SENDING &&
     66                     conversation.sendingState != UIProvider.ConversationSendingState.RETRYING;
     67         }
     68         mConversationItemView.bind(conversation, activity, set, folder, checkboxOrSenderImage,
     69                 swipeEnabled, importanceMarkersEnabled, showChevronsEnabled, animatedAdapter);
     70     }
     71 
     72     public void startUndoAnimation(AnimatorListener listener, boolean swipe) {
     73         final Animator a = (swipe) ? mConversationItemView.createSwipeUndoAnimation()
     74                 : mConversationItemView.createUndoAnimation();
     75         a.addListener(listener);
     76         a.start();
     77     }
     78 
     79     public void startDeleteAnimation(AnimatorListener listener, boolean swipe) {
     80         final Animator a = (swipe) ? mConversationItemView.createDestroyWithSwipeAnimation()
     81                 : mConversationItemView.createDestroyAnimation();
     82         a.addListener(listener);
     83         a.start();
     84     }
     85 
     86     @Override
     87     public boolean toggleSelectedStateOrBeginDrag() {
     88         return mConversationItemView.toggleSelectedStateOrBeginDrag();
     89     }
     90 
     91     @Override
     92     public boolean toggleSelectedState() {
     93         return mConversationItemView.toggleSelectedState();
     94     }
     95 }
     96