blob: 9dc173023df8242157025000c34e2e57c070c5fb [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
Alexandre Lision666b3772013-10-28 17:42:48 -04009import android.content.Context;
10import android.graphics.Bitmap;
11import android.graphics.BitmapFactory;
Alexandre Lisiond5686032013-10-29 11:09:21 -040012import android.os.Bundle;
Alexandre Lision666b3772013-10-28 17:42:48 -040013import 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
Alexandre Lisiond5686032013-10-29 11:09:21 -040028 public DiscussArrayAdapter(Context context, Bundle args) {
Alexandre Lision666b3772013-10-28 17:42:48 -040029 mContext = context;
Alexandre Lisiond5686032013-10-29 11:09:21 -040030
31 if(args == null)
32 messages = new ArrayList<SipMessage>();
33 else
34 messages = args.getParcelableArrayList("messages");
35
Alexandre Lision666b3772013-10-28 17:42:48 -040036 }
37
38 public void add(SipMessage object) {
39 messages.add(object);
40 notifyDataSetChanged();
41 }
42
43 public int getCount() {
44 return this.messages.size();
45 }
46
47 public SipMessage getItem(int index) {
48 return this.messages.get(index);
49 }
50
51 public View getView(int position, View convertView, ViewGroup parent) {
52 View row = convertView;
53 if (row == null) {
54 LayoutInflater inflater = (LayoutInflater) LayoutInflater.from(mContext);
55 row = inflater.inflate(R.layout.item_message, parent, false);
56 }
57
58 wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
59
60 SipMessage coment = getItem(position);
61
62 countryName = (TextView) row.findViewById(R.id.comment);
63
64 countryName.setText(coment.comment);
65
66 countryName.setBackgroundResource(coment.left ? R.drawable.bubble_left_selector : R.drawable.bubble_right_selector);
67 wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
68
69 return row;
70 }
71
72 public Bitmap decodeToBitmap(byte[] decodedByte) {
73 return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
74 }
75
76 @Override
77 public long getItemId(int position) {
78 return 0;
79 }
80
81}