blob: 5399c0a8c4321a76833e29bfd5e16017c0a25a2b [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
Alexandre Lision666b3772013-10-28 17:42:48 -040032package org.sflphone.adapters;
33
34import java.util.ArrayList;
35import java.util.List;
36
37import org.sflphone.R;
38import org.sflphone.model.SipMessage;
39
Alexandre Lision666b3772013-10-28 17:42:48 -040040import android.content.Context;
41import android.graphics.Bitmap;
42import android.graphics.BitmapFactory;
Alexandre Lisiond5686032013-10-29 11:09:21 -040043import android.os.Bundle;
Alexandre Lision666b3772013-10-28 17:42:48 -040044import android.view.Gravity;
45import android.view.LayoutInflater;
46import android.view.View;
47import android.view.ViewGroup;
48import android.widget.BaseAdapter;
49import android.widget.LinearLayout;
50import android.widget.TextView;
51
52public class DiscussArrayAdapter extends BaseAdapter {
53
54 private TextView countryName;
55 private List<SipMessage> messages = new ArrayList<SipMessage>();
56 private LinearLayout wrapper;
57 private Context mContext;
58
Alexandre Lisiond5686032013-10-29 11:09:21 -040059 public DiscussArrayAdapter(Context context, Bundle args) {
Alexandre Lision666b3772013-10-28 17:42:48 -040060 mContext = context;
Alexandre Lisiond5686032013-10-29 11:09:21 -040061
62 if(args == null)
63 messages = new ArrayList<SipMessage>();
64 else
65 messages = args.getParcelableArrayList("messages");
66
Alexandre Lision666b3772013-10-28 17:42:48 -040067 }
68
69 public void add(SipMessage object) {
70 messages.add(object);
71 notifyDataSetChanged();
72 }
73
74 public int getCount() {
75 return this.messages.size();
76 }
77
78 public SipMessage getItem(int index) {
79 return this.messages.get(index);
80 }
81
82 public View getView(int position, View convertView, ViewGroup parent) {
83 View row = convertView;
84 if (row == null) {
85 LayoutInflater inflater = (LayoutInflater) LayoutInflater.from(mContext);
86 row = inflater.inflate(R.layout.item_message, parent, false);
87 }
88
89 wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
90
91 SipMessage coment = getItem(position);
92
93 countryName = (TextView) row.findViewById(R.id.comment);
94
95 countryName.setText(coment.comment);
96
97 countryName.setBackgroundResource(coment.left ? R.drawable.bubble_left_selector : R.drawable.bubble_right_selector);
98 wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
99
100 return row;
101 }
102
103 public Bitmap decodeToBitmap(byte[] decodedByte) {
104 return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
105 }
106
107 @Override
108 public long getItemId(int position) {
109 return 0;
110 }
111
112}