blob: 8312c2ad31c3b8e2055ad02b28ef6a1c7c52ea7a [file] [log] [blame]
Alexandre Lision666b3772013-10-28 17:42:48 -04001package org.sflphone.adapters;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.sflphone.R;
7import org.sflphone.model.SipMessage;
8
9import android.app.Activity;
10import android.content.Context;
11import android.graphics.Bitmap;
12import android.graphics.BitmapFactory;
13import android.view.Gravity;
14import android.view.LayoutInflater;
15import android.view.View;
16import android.view.ViewGroup;
17import android.widget.BaseAdapter;
18import android.widget.LinearLayout;
19import android.widget.TextView;
20
21public class DiscussArrayAdapter extends BaseAdapter {
22
23 private TextView countryName;
24 private List<SipMessage> messages = new ArrayList<SipMessage>();
25 private LinearLayout wrapper;
26 private Context mContext;
27
28 public DiscussArrayAdapter(Context context) {
29 mContext = context;
30 }
31
32 public void add(SipMessage object) {
33 messages.add(object);
34 notifyDataSetChanged();
35 }
36
37 public int getCount() {
38 return this.messages.size();
39 }
40
41 public SipMessage getItem(int index) {
42 return this.messages.get(index);
43 }
44
45 public View getView(int position, View convertView, ViewGroup parent) {
46 View row = convertView;
47 if (row == null) {
48 LayoutInflater inflater = (LayoutInflater) LayoutInflater.from(mContext);
49 row = inflater.inflate(R.layout.item_message, parent, false);
50 }
51
52 wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
53
54 SipMessage coment = getItem(position);
55
56 countryName = (TextView) row.findViewById(R.id.comment);
57
58 countryName.setText(coment.comment);
59
60 countryName.setBackgroundResource(coment.left ? R.drawable.bubble_left_selector : R.drawable.bubble_right_selector);
61 wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
62
63 return row;
64 }
65
66 public Bitmap decodeToBitmap(byte[] decodedByte) {
67 return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
68 }
69
70 @Override
71 public long getItemId(int position) {
72 return 0;
73 }
74
75}