18 * This class contains informations on a jabber contact. |
18 * This class contains informations on a jabber contact. |
19 * @author darisk |
19 * @author darisk |
20 */ |
20 */ |
21 public class Contact implements Parcelable { |
21 public class Contact implements Parcelable { |
22 |
22 |
|
23 /** |
|
24 * Status of a disconnected contact. |
|
25 */ |
23 public static final int CONTACT_STATUS_DISCONNECT = 100; |
26 public static final int CONTACT_STATUS_DISCONNECT = 100; |
|
27 |
|
28 /** |
|
29 * Status of a unavailable (long away) contact. |
|
30 */ |
24 public static final int CONTACT_STATUS_UNAVAILABLE = 200; |
31 public static final int CONTACT_STATUS_UNAVAILABLE = 200; |
|
32 |
|
33 /** |
|
34 * Status of a away contact. |
|
35 */ |
25 public static final int CONTACT_STATUS_AWAY = 300; |
36 public static final int CONTACT_STATUS_AWAY = 300; |
|
37 |
|
38 /** |
|
39 * Status of a busy contact. |
|
40 */ |
26 public static final int CONTACT_STATUS_BUSY = 400; |
41 public static final int CONTACT_STATUS_BUSY = 400; |
|
42 |
|
43 /** |
|
44 * Status of a available contact. |
|
45 */ |
27 public static final int CONTACT_STATUS_AVAILABLE = 500; |
46 public static final int CONTACT_STATUS_AVAILABLE = 500; |
|
47 |
|
48 /** |
|
49 * Status of a available for chat contact. |
|
50 */ |
28 public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600; |
51 public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600; |
|
52 |
29 private static final String TAG = "Contact"; |
53 private static final String TAG = "Contact"; |
30 |
54 |
31 private int mID; |
55 private int mID; |
32 private int mStatus; |
56 private int mStatus; |
33 private String mJID; |
57 private String mJID; |
47 @Override |
71 @Override |
48 public Contact[] newArray(int size) { |
72 public Contact[] newArray(int size) { |
49 return new Contact[size]; |
73 return new Contact[size]; |
50 } |
74 } |
51 }; |
75 }; |
|
76 |
|
77 /** |
|
78 * Constructor. |
|
79 */ |
|
80 public Contact() { |
|
81 // TODO Auto-generated constructor stub |
|
82 } |
|
83 |
|
84 /** |
|
85 * Constructor. |
|
86 * @param jid JID of the contact |
|
87 */ |
|
88 public Contact(final String jid) { |
|
89 mJID = jid; |
|
90 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
|
91 mRes = new ArrayList<String>(); |
|
92 mRes.add("none"); |
|
93 } |
52 |
94 |
53 /** |
95 /** |
54 * Construct a contact from a parcel. |
96 * Construct a contact from a parcel. |
55 * @param in parcel to use for construction |
97 * @param in parcel to use for construction |
56 */ |
98 */ |
58 mID = in.readInt(); |
100 mID = in.readInt(); |
59 mStatus = in.readInt(); |
101 mStatus = in.readInt(); |
60 mJID = in.readString(); |
102 mJID = in.readString(); |
61 mMsgState = in.readString(); |
103 mMsgState = in.readString(); |
62 mRes = new ArrayList<String>(); |
104 mRes = new ArrayList<String>(); |
63 in.readStringList(mRes); |
105 in.readStringList(mRes); |
64 } |
106 } |
65 |
107 |
66 /** |
108 /** |
67 * {@inheritDoc} |
109 * {@inheritDoc} |
68 */ |
110 */ |
83 // TODO Auto-generated method stub |
125 // TODO Auto-generated method stub |
84 return 0; |
126 return 0; |
85 } |
127 } |
86 |
128 |
87 /** |
129 /** |
88 * Constructor. |
130 * Get the id of the contact on the phone contact list. |
89 */ |
|
90 public Contact() { |
|
91 // TODO Auto-generated constructor stub |
|
92 } |
|
93 |
|
94 /** |
|
95 * Constructor. |
|
96 * @param jid JID of the contact |
|
97 */ |
|
98 public Contact(final String jid) { |
|
99 mJID = jid; |
|
100 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
|
101 mRes = new ArrayList<String>(); |
|
102 mRes.add("none"); |
|
103 } |
|
104 |
|
105 /** |
|
106 * @return the mID |
131 * @return the mID |
107 */ |
132 */ |
108 public int getID() { |
133 public int getID() { |
109 return mID; |
134 return mID; |
110 } |
135 } |
111 |
136 |
112 /** |
137 /** |
|
138 * set the id of te contact on the phone contact list. |
113 * @param mid the mID to set |
139 * @param mid the mID to set |
114 */ |
140 */ |
115 public void setID(int mid) { |
141 public void setID(int mid) { |
116 mID = mid; |
142 mID = mid; |
117 } |
143 } |
118 |
144 |
119 /** |
145 /** |
|
146 * Get the status of the contact. |
120 * @return the mStatus |
147 * @return the mStatus |
121 */ |
148 */ |
122 public int getStatus() { |
149 public int getStatus() { |
123 return mStatus; |
150 return mStatus; |
124 } |
151 } |
125 |
152 |
126 /** |
153 /** |
|
154 * Set the status of the contact. |
127 * @param status the mStatus to set |
155 * @param status the mStatus to set |
128 */ |
156 */ |
129 public void setStatus(int status) { |
157 public void setStatus(int status) { |
130 mStatus = status; |
158 mStatus = status; |
131 } |
159 } |
132 |
160 |
133 /** |
161 /** |
|
162 * Set the status of the contact using a presence packet. |
134 * @param presence the presence containing status |
163 * @param presence the presence containing status |
135 */ |
164 */ |
136 public void setStatus(Presence presence) { |
165 public void setStatus(Presence presence) { |
137 if (presence.getType().equals(Presence.Type.unavailable)) { |
166 if (presence.getType().equals(Presence.Type.unavailable)) { |
138 Log.d(TAG, "Presence pas dispo"); |
167 Log.d(TAG, "Presence pas dispo"); |
139 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
168 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
140 } else { |
169 } else { |
141 Log.d(TAG,"Presence OK"); |
170 Log.d(TAG, "Presence OK"); |
142 Mode mode = presence.getMode(); |
171 Mode mode = presence.getMode(); |
143 switch (mode) { |
172 switch (mode) { |
144 case available: |
173 case available: |
145 mStatus = Contact.CONTACT_STATUS_AVAILABLE; |
174 mStatus = Contact.CONTACT_STATUS_AVAILABLE; |
146 break; |
175 break; |
156 case xa: |
185 case xa: |
157 mStatus = Contact.CONTACT_STATUS_UNAVAILABLE; |
186 mStatus = Contact.CONTACT_STATUS_UNAVAILABLE; |
158 break; |
187 break; |
159 default: |
188 default: |
160 Log.e("RosterAdapter", "Status mode non gere"); |
189 Log.e("RosterAdapter", "Status mode non gere"); |
161 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
190 mStatus = Contact.CONTACT_STATUS_DISCONNECT; |
162 break; |
191 break; |
163 } |
192 } |
164 } |
193 } |
165 } |
194 } |
166 |
195 |
167 /** |
196 /** |
168 * @return the mMsgState |
197 * Get the message status of the contact. |
169 */ |
198 * @return the message status of the contact. |
170 public String getMMsgState() { |
199 */ |
|
200 public String getMsgState() { |
171 return mMsgState; |
201 return mMsgState; |
172 } |
202 } |
173 |
203 |
174 /** |
204 /** |
175 * @param msgState the mMsgState to set |
205 * Set the message status of the contact. |
176 */ |
206 * @param msgState the message status of the contact to set |
177 public void setMMsgState(String msgState) { |
207 */ |
|
208 public void setMsgState(String msgState) { |
178 mMsgState = msgState; |
209 mMsgState = msgState; |
179 } |
210 } |
180 |
211 |
181 /** |
212 /** |
182 * Get the Jabber ID of the contact. |
213 * Get the Jabber ID of the contact. |
186 return mJID; |
217 return mJID; |
187 } |
218 } |
188 |
219 |
189 /** |
220 /** |
190 * Set the Jabber ID of the contact. |
221 * Set the Jabber ID of the contact. |
191 * @param mjid the jabber ID to set |
222 * @param mjid the jabber ID to set |
192 */ |
223 */ |
193 public void setJID(String mjid) { |
224 public void setJID(String mjid) { |
194 mJID = mjid; |
225 mJID = mjid; |
195 } |
226 } |
196 |
227 |
|
228 /** |
|
229 * |
|
230 * @param res |
|
231 */ |
197 public void addRes(String res) { |
232 public void addRes(String res) { |
198 if (!mRes.contains(res)) |
233 if (!mRes.contains(res)) |
199 mRes.add(res); |
234 mRes.add(res); |
200 } |
235 } |
201 |
236 |
|
237 /** |
|
238 * |
|
239 * @param res |
|
240 */ |
202 public void delRes(String res) { |
241 public void delRes(String res) { |
203 mRes.remove(res); |
242 mRes.remove(res); |
204 } |
243 } |
205 |
244 |
206 /** |
245 /** |