• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.AbsListView.OnScrollListener;
24 import android.widget.AbsListView;
25 import android.widget.FrameLayout;
26 import android.widget.ListView;
27 
28 import com.android.mail.providers.Conversation;
29 import com.android.mail.providers.Folder;
30 import com.android.mail.ui.AnimatedAdapter;
31 import com.android.mail.ui.AnimatedAdapter.ConversationListListener;
32 import com.android.mail.ui.ControllableActivity;
33 import com.android.mail.ui.ConversationSelectionSet;
34 
35 public class SwipeableConversationItemView extends FrameLayout
36         implements ToggleableItem, OnScrollListener {
37 
38     private final ConversationItemView mConversationItemView;
39 
SwipeableConversationItemView(Context context, String account)40     public SwipeableConversationItemView(Context context, String account) {
41         super(context);
42         mConversationItemView = new ConversationItemView(context, account);
43         addView(mConversationItemView);
44     }
45 
getListView()46     public ListView getListView() {
47         return (ListView) getParent();
48     }
49 
reset()50     public void reset() {
51         mConversationItemView.reset();
52     }
53 
getSwipeableItemView()54     public ConversationItemView getSwipeableItemView() {
55         return mConversationItemView;
56     }
57 
bind(final Conversation conversation, final ControllableActivity activity, final ConversationListListener conversationListListener, final ConversationSelectionSet set, final Folder folder, final int checkboxOrSenderImage, final boolean showAttachmentPreviews, final boolean parallaxSpeedAlternative, final boolean parallaxDirectionAlternative, final boolean swipeEnabled, final boolean priorityArrowsEnabled, final AnimatedAdapter animatedAdapter)58     public void bind(final Conversation conversation, final ControllableActivity activity,
59             final ConversationListListener conversationListListener,
60             final ConversationSelectionSet set, final Folder folder,
61             final int checkboxOrSenderImage, final boolean showAttachmentPreviews,
62             final boolean parallaxSpeedAlternative, final boolean parallaxDirectionAlternative,
63             final boolean swipeEnabled, final boolean priorityArrowsEnabled,
64             final AnimatedAdapter animatedAdapter) {
65         mConversationItemView.bind(conversation, activity, conversationListListener, set, folder,
66                 checkboxOrSenderImage, showAttachmentPreviews, parallaxSpeedAlternative,
67                 parallaxDirectionAlternative, swipeEnabled, priorityArrowsEnabled, animatedAdapter);
68     }
69 
startUndoAnimation(AnimatorListener listener, boolean swipe)70     public void startUndoAnimation(AnimatorListener listener, boolean swipe) {
71         final Animator a = (swipe) ? mConversationItemView.createSwipeUndoAnimation()
72                 : mConversationItemView.createUndoAnimation();
73         a.addListener(listener);
74         a.start();
75     }
76 
startDeleteAnimation(AnimatorListener listener, boolean swipe)77     public void startDeleteAnimation(AnimatorListener listener, boolean swipe) {
78         final Animator a = (swipe) ? mConversationItemView.createDestroyWithSwipeAnimation()
79                 : mConversationItemView.createDestroyAnimation();
80         a.addListener(listener);
81         a.start();
82     }
83 
84     @Override
toggleSelectedStateOrBeginDrag()85     public boolean toggleSelectedStateOrBeginDrag() {
86         if (mConversationItemView != null) {
87             return mConversationItemView.toggleSelectedStateOrBeginDrag();
88         }
89 
90         return false;
91     }
92 
93     @Override
toggleSelectedState()94     public boolean toggleSelectedState() {
95         if (mConversationItemView != null) {
96             return mConversationItemView.toggleSelectedState();
97         }
98 
99         return false;
100     }
101 
102     @Override
onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)103     public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
104             int totalItemCount) {
105         if (mConversationItemView != null) {
106             mConversationItemView.onScroll(view, firstVisibleItem, visibleItemCount,
107                     totalItemCount);
108         }
109     }
110 
111     @Override
onScrollStateChanged(AbsListView view, int scrollState)112     public void onScrollStateChanged(AbsListView view, int scrollState) {
113     }
114 
115 }
116