alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame^] | 1 | package com.savoirfairelinux.sflphone.adapters; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.HashMap; |
| 5 | |
| 6 | import com.savoirfairelinux.sflphone.R; |
| 7 | import com.savoirfairelinux.sflphone.adapters.CallElementAdapter.CallElementView; |
| 8 | import com.savoirfairelinux.sflphone.model.SipCall; |
| 9 | import com.savoirfairelinux.sflphone.service.ServiceConstants; |
| 10 | |
| 11 | import android.app.Activity; |
| 12 | import android.content.Context; |
| 13 | import android.view.LayoutInflater; |
| 14 | import android.view.View; |
| 15 | import android.view.ViewGroup; |
| 16 | import android.widget.BaseAdapter; |
| 17 | import android.widget.ImageView; |
| 18 | import android.widget.TextView; |
| 19 | |
| 20 | public class HistoryAdapter extends BaseAdapter{ |
| 21 | |
| 22 | Context mContext; |
| 23 | ArrayList<HashMap<String, String>> dataset; |
| 24 | |
| 25 | |
| 26 | public HistoryAdapter(Activity activity, ArrayList<HashMap<String, String>> entries) { |
| 27 | mContext = activity; |
| 28 | dataset = entries; |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public View getView(int pos, View convertView, ViewGroup arg2) { |
| 33 | View rowView = convertView; |
| 34 | HistoryView entryView = null; |
| 35 | |
| 36 | if (rowView == null) { |
| 37 | // Get a new instance of the row layout view |
| 38 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 39 | rowView = inflater.inflate(R.layout.item_contact, null); |
| 40 | |
| 41 | // Hold the view objects in an object |
| 42 | // so they don't need to be re-fetched |
| 43 | entryView = new HistoryView(); |
| 44 | entryView.displayName = (TextView) rowView.findViewById(R.id.display_name); |
| 45 | |
| 46 | rowView.setTag(entryView); |
| 47 | } else { |
| 48 | entryView = (HistoryView) rowView.getTag(); |
| 49 | } |
| 50 | |
| 51 | // Transfer the stock data from the data object |
| 52 | // to the view objects |
| 53 | |
| 54 | // SipCall call = (SipCall) mCallList.values().toArray()[position]; |
| 55 | entryView.displayName.setText(dataset.get(pos).get(ServiceConstants.HISTORY_ACCOUNT_ID_KEY)); |
| 56 | // entryView.phones.setText(call.getPhone()); |
| 57 | // entryView.state.setText(CURRENT_STATE_LABEL + call.getCallStateString()); |
| 58 | |
| 59 | return rowView; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | /********************* |
| 64 | * ViewHolder Pattern |
| 65 | *********************/ |
| 66 | public class HistoryView { |
| 67 | protected ImageView photo; |
| 68 | protected TextView displayName; |
| 69 | protected TextView phones; |
| 70 | public TextView state; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int getCount() { |
| 75 | |
| 76 | return dataset.size(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public HashMap<String, String> getItem(int pos) { |
| 81 | return dataset.get(pos); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public long getItemId(int arg0) { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | public void clear() { |
| 90 | dataset.clear(); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | public void addAll(ArrayList<HashMap<String, String>> history) { |
| 95 | dataset.addAll(history); |
| 96 | |
| 97 | } |
| 98 | |
| 99 | } |