• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Esmertec AG.
3  * Copyright (C) 2008 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.mms.ui;
19 
20 import android.content.Context;
21 import android.database.Cursor;
22 import android.util.Log;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.AbsListView;
27 import android.widget.CursorAdapter;
28 
29 import com.android.mms.LogTag;
30 import com.android.mms.R;
31 import com.android.mms.data.Conversation;
32 
33 /**
34  * The back-end data adapter for ConversationList.
35  */
36 //TODO: This should be public class ConversationListAdapter extends ArrayAdapter<Conversation>
37 public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
38     private static final String TAG = LogTag.TAG;
39     private static final boolean LOCAL_LOGV = false;
40 
41     private final LayoutInflater mFactory;
42     private OnContentChangedListener mOnContentChangedListener;
43 
ConversationListAdapter(Context context, Cursor cursor)44     public ConversationListAdapter(Context context, Cursor cursor) {
45         super(context, cursor, false /* auto-requery */);
46         mFactory = LayoutInflater.from(context);
47     }
48 
49     @Override
bindView(View view, Context context, Cursor cursor)50     public void bindView(View view, Context context, Cursor cursor) {
51         if (!(view instanceof ConversationListItem)) {
52             Log.e(TAG, "Unexpected bound view: " + view);
53             return;
54         }
55 
56         ConversationListItem headerView = (ConversationListItem) view;
57         Conversation conv = Conversation.from(context, cursor);
58         headerView.bind(context, conv);
59     }
60 
onMovedToScrapHeap(View view)61     public void onMovedToScrapHeap(View view) {
62         ConversationListItem headerView = (ConversationListItem)view;
63         headerView.unbind();
64     }
65 
66     @Override
newView(Context context, Cursor cursor, ViewGroup parent)67     public View newView(Context context, Cursor cursor, ViewGroup parent) {
68         if (LOCAL_LOGV) Log.v(TAG, "inflating new view");
69         return mFactory.inflate(R.layout.conversation_list_item, parent, false);
70     }
71 
72     public interface OnContentChangedListener {
onContentChanged(ConversationListAdapter adapter)73         void onContentChanged(ConversationListAdapter adapter);
74     }
75 
setOnContentChangedListener(OnContentChangedListener l)76     public void setOnContentChangedListener(OnContentChangedListener l) {
77         mOnContentChangedListener = l;
78     }
79 
80     @Override
onContentChanged()81     protected void onContentChanged() {
82         if (mCursor != null && !mCursor.isClosed()) {
83             if (mOnContentChangedListener != null) {
84                 mOnContentChangedListener.onContentChanged(this);
85             }
86         }
87     }
88 
uncheckAll()89     public void uncheckAll() {
90         int count = getCount();
91         for (int i = 0; i < count; i++) {
92             Cursor cursor = (Cursor)getItem(i);
93             Conversation conv = Conversation.from(mContext, cursor);
94             conv.setIsChecked(false);
95         }
96     }
97 }
98