Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@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 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 31 | package com.savoirfairelinux.sflphone.model; |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 32 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 33 | import java.lang.reflect.Array; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 35 | import java.util.Arrays; |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 36 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 37 | import android.os.Parcel; |
| 38 | import android.os.Parcelable; |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 39 | import android.provider.Contacts.Phones; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 40 | |
| 41 | public class CallContact implements Parcelable { |
| 42 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 43 | private long id; |
| 44 | private String mDisplayName; |
| 45 | private long photo_id; |
| 46 | private ArrayList<Phone> phones, sip_phones; |
| 47 | private String mEmail; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 48 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 49 | private CallContact(long cID, String displayName, long photoID, ArrayList<Phone> p, ArrayList<Phone> sip, String mail) { |
| 50 | id = cID; |
| 51 | mDisplayName = displayName; |
| 52 | phones = p; |
| 53 | sip_phones = sip; |
| 54 | mEmail = mail; |
| 55 | photo_id = photoID; |
| 56 | } |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 57 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 58 | public CallContact(Parcel in) { |
| 59 | readFromParcel(in); |
| 60 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 61 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 62 | public long getId() { |
| 63 | return id; |
| 64 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 65 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 66 | public String getmDisplayName() { |
| 67 | return mDisplayName; |
| 68 | } |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 69 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 70 | public void setmDisplayName(String mDisplayName) { |
| 71 | this.mDisplayName = mDisplayName; |
| 72 | } |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 73 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 74 | public long getPhoto_id() { |
| 75 | return photo_id; |
| 76 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 77 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 78 | public void setPhoto_id(long photo_id) { |
| 79 | this.photo_id = photo_id; |
| 80 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 81 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 82 | public ArrayList<Phone> getPhones() { |
| 83 | return phones; |
| 84 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 85 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 86 | public void setPhones(ArrayList<Phone> phones) { |
| 87 | this.phones = phones; |
| 88 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 89 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 90 | public ArrayList<Phone> getSip_phones() { |
| 91 | return sip_phones; |
| 92 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 93 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 94 | public void setSip_phones(ArrayList<Phone> sip_phones) { |
| 95 | this.sip_phones = sip_phones; |
| 96 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 97 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 98 | public Phone getSipPhone() { |
| 99 | if (sip_phones.size() > 0) { |
| 100 | return sip_phones.get(0); |
| 101 | } |
| 102 | if (phones.size() > 0) { |
| 103 | return phones.get(0); |
| 104 | } |
| 105 | return null; |
| 106 | } |
Alexandre Savard | 38d6a15 | 2012-09-18 13:33:02 -0400 | [diff] [blame] | 107 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 108 | public String getmEmail() { |
| 109 | return mEmail; |
| 110 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 111 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 112 | public void setmEmail(String mEmail) { |
| 113 | this.mEmail = mEmail; |
| 114 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 115 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 116 | @Override |
| 117 | public String toString() { |
| 118 | return mDisplayName; |
| 119 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 120 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 121 | public static class ContactBuilder { |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 122 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 123 | long contactID; |
| 124 | String contactName; |
| 125 | long contactPhoto; |
| 126 | ArrayList<Phone> phones; |
| 127 | ArrayList<Phone> sip; |
| 128 | String contactMail; |
| 129 | boolean hasPhoto; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 130 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 131 | public ContactBuilder startNewContact(long id, String displayName, long photo_id) { |
| 132 | contactID = id; |
| 133 | contactName = displayName; |
| 134 | contactPhoto = photo_id; |
| 135 | phones = new ArrayList<Phone>(); |
| 136 | sip = new ArrayList<Phone>(); |
| 137 | return this; |
| 138 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 139 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 140 | public ContactBuilder addPhoneNumber(String num, int type) { |
| 141 | phones.add(new Phone(num, type)); |
| 142 | return this; |
| 143 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 144 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 145 | public ContactBuilder addSipNumber(String num, int type) { |
| 146 | sip.add(new Phone(num, type)); |
| 147 | return this; |
| 148 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 149 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 150 | public CallContact build() { |
| 151 | return new CallContact(contactID, contactName, contactPhoto, phones, sip, contactMail); |
| 152 | } |
Adrien BĂ©raud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 153 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 154 | public static ContactBuilder getInstance() { |
| 155 | return new ContactBuilder(); |
| 156 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 157 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 158 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 159 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 160 | @Override |
| 161 | public int describeContents() { |
| 162 | return 0; |
| 163 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 164 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 165 | @Override |
| 166 | public void writeToParcel(Parcel dest, int flags) { |
| 167 | dest.writeLong(id); |
| 168 | dest.writeString(mDisplayName); |
| 169 | dest.writeLong(photo_id); |
| 170 | dest.writeTypedList(phones); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 171 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 172 | dest.writeTypedList(sip_phones); |
| 173 | |
| 174 | dest.writeString(mEmail); |
| 175 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 176 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 177 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 178 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 179 | private void readFromParcel(Parcel in) { |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 180 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 181 | id = in.readLong(); |
| 182 | mDisplayName = in.readString(); |
| 183 | photo_id = in.readLong(); |
| 184 | phones = new ArrayList<CallContact.Phone>(); |
| 185 | sip_phones = new ArrayList<CallContact.Phone>(); |
| 186 | in.readTypedList(phones, Phone.CREATOR); |
| 187 | in.readTypedList(sip_phones, Phone.CREATOR); |
| 188 | mEmail = in.readString(); |
| 189 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 190 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 191 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { |
| 192 | @Override |
| 193 | public CallContact createFromParcel(Parcel in) { |
| 194 | return new CallContact(in); |
| 195 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 196 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 197 | @Override |
| 198 | public CallContact[] newArray(int size) { |
| 199 | return new CallContact[size]; |
| 200 | } |
| 201 | }; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 202 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 203 | public static class Phone implements Parcelable { |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 204 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 205 | int type; |
| 206 | String number; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 207 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 208 | public Phone(String num, int ty) { |
| 209 | type = ty; |
| 210 | number = num; |
| 211 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 212 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 213 | public Phone(Parcel in) { |
| 214 | readFromParcel(in); |
| 215 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 216 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 217 | @Override |
| 218 | public int describeContents() { |
| 219 | return 0; |
| 220 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 221 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 222 | @Override |
| 223 | public void writeToParcel(Parcel dest, int arg1) { |
| 224 | dest.writeInt(type); |
| 225 | dest.writeString(number); |
| 226 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 227 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 228 | private void readFromParcel(Parcel in) { |
| 229 | type = in.readInt(); |
| 230 | number = in.readString(); |
| 231 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 232 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 233 | public static final Parcelable.Creator<Phone> CREATOR = new Parcelable.Creator() { |
| 234 | @Override |
| 235 | public Phone createFromParcel(Parcel in) { |
| 236 | return new Phone(in); |
| 237 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 238 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 239 | @Override |
| 240 | public Phone[] newArray(int size) { |
| 241 | return new Phone[size]; |
| 242 | } |
| 243 | }; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 244 | |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 245 | public int getType() { |
| 246 | return type; |
| 247 | } |
| 248 | |
| 249 | public void setType(int type) { |
| 250 | this.type = type; |
| 251 | } |
| 252 | |
| 253 | public String getNumber() { |
| 254 | return number; |
| 255 | } |
| 256 | |
| 257 | public void setNumber(String number) { |
| 258 | this.number = number; |
| 259 | } |
| 260 | |
| 261 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 262 | |
Alexandre Savard | 166dbb6 | 2012-09-18 09:37:27 -0400 | [diff] [blame] | 263 | } |