Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 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 Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 32 | package org.sflphone.adapters; |
| 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.List; |
| 36 | |
| 37 | import org.sflphone.R; |
| 38 | import org.sflphone.model.SipMessage; |
| 39 | |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.graphics.Bitmap; |
| 42 | import android.graphics.BitmapFactory; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 43 | import android.os.Bundle; |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 44 | import android.view.Gravity; |
| 45 | import android.view.LayoutInflater; |
| 46 | import android.view.View; |
| 47 | import android.view.ViewGroup; |
| 48 | import android.widget.BaseAdapter; |
| 49 | import android.widget.LinearLayout; |
| 50 | import android.widget.TextView; |
| 51 | |
| 52 | public 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 Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 59 | public DiscussArrayAdapter(Context context, Bundle args) { |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 60 | mContext = context; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 61 | |
| 62 | if(args == null) |
| 63 | messages = new ArrayList<SipMessage>(); |
| 64 | else |
| 65 | messages = args.getParcelableArrayList("messages"); |
| 66 | |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 67 | } |
| 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) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 85 | LayoutInflater inflater = LayoutInflater.from(mContext); |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 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 | |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 103 | @Override |
| 104 | public long getItemId(int position) { |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | } |