107
|
1 |
/**
|
310
|
2 |
*
|
107
|
3 |
*/
|
|
4 |
package com.beem.project.beem.utils;
|
|
5 |
|
|
6 |
import org.jivesoftware.smack.packet.Presence;
|
|
7 |
import org.jivesoftware.smack.packet.Presence.Mode;
|
|
8 |
|
|
9 |
/**
|
310
|
10 |
* @author marseille
|
107
|
11 |
*/
|
342
|
12 |
public final class Status {
|
107
|
13 |
|
|
14 |
/**
|
|
15 |
* Status of a disconnected contact.
|
|
16 |
*/
|
310
|
17 |
public static final int CONTACT_STATUS_DISCONNECT = 100;
|
107
|
18 |
|
|
19 |
/**
|
|
20 |
* Status of a unavailable (long away) contact.
|
|
21 |
*/
|
310
|
22 |
public static final int CONTACT_STATUS_UNAVAILABLE = 200;
|
107
|
23 |
|
|
24 |
/**
|
|
25 |
* Status of a away contact.
|
|
26 |
*/
|
310
|
27 |
public static final int CONTACT_STATUS_AWAY = 300;
|
107
|
28 |
|
|
29 |
/**
|
|
30 |
* Status of a busy contact.
|
|
31 |
*/
|
310
|
32 |
public static final int CONTACT_STATUS_BUSY = 400;
|
107
|
33 |
|
|
34 |
/**
|
|
35 |
* Status of a available contact.
|
|
36 |
*/
|
310
|
37 |
public static final int CONTACT_STATUS_AVAILABLE = 500;
|
107
|
38 |
|
|
39 |
/**
|
|
40 |
* Status of a available for chat contact.
|
|
41 |
*/
|
|
42 |
public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
|
|
43 |
|
|
44 |
/**
|
342
|
45 |
* Default constructor masked.
|
|
46 |
*/
|
|
47 |
private Status() {
|
|
48 |
}
|
|
49 |
|
|
50 |
/**
|
310
|
51 |
* Get the smack presence mode for a status.
|
|
52 |
* @param status the status in beem
|
212
|
53 |
* @return the presence mode to use in presence packet or null if there is no mode to use
|
|
54 |
*/
|
|
55 |
public static Presence.Mode getPresenceModeFromStatus(int status) {
|
|
56 |
Presence.Mode res;
|
|
57 |
switch (status) {
|
310
|
58 |
case CONTACT_STATUS_AVAILABLE:
|
|
59 |
res = Presence.Mode.available;
|
|
60 |
break;
|
|
61 |
case CONTACT_STATUS_AVAILABLE_FOR_CHAT:
|
|
62 |
res = Presence.Mode.chat;
|
|
63 |
break;
|
|
64 |
case CONTACT_STATUS_AWAY:
|
|
65 |
res = Presence.Mode.away;
|
|
66 |
break;
|
|
67 |
case CONTACT_STATUS_BUSY:
|
|
68 |
res = Presence.Mode.dnd;
|
|
69 |
break;
|
|
70 |
case CONTACT_STATUS_UNAVAILABLE:
|
|
71 |
res = Presence.Mode.xa;
|
|
72 |
break;
|
|
73 |
default:
|
|
74 |
return null;
|
212
|
75 |
}
|
|
76 |
return res;
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
107
|
80 |
* Get the status of from a presence packet.
|
310
|
81 |
* @param presence the presence containing status
|
|
82 |
* @return an int representing the status
|
107
|
83 |
*/
|
|
84 |
public static int getStatusFromPresence(Presence presence) {
|
|
85 |
int res = Status.CONTACT_STATUS_DISCONNECT;
|
|
86 |
if (presence.getType().equals(Presence.Type.unavailable)) {
|
|
87 |
res = Status.CONTACT_STATUS_DISCONNECT;
|
|
88 |
} else {
|
|
89 |
Mode mode = presence.getMode();
|
|
90 |
if (mode == null) {
|
|
91 |
res = Status.CONTACT_STATUS_AVAILABLE;
|
|
92 |
} else {
|
|
93 |
switch (mode) {
|
310
|
94 |
case available:
|
|
95 |
res = Status.CONTACT_STATUS_AVAILABLE;
|
|
96 |
break;
|
|
97 |
case away:
|
|
98 |
res = Status.CONTACT_STATUS_AWAY;
|
|
99 |
break;
|
|
100 |
case chat:
|
|
101 |
res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
|
|
102 |
break;
|
|
103 |
case dnd:
|
|
104 |
res = Status.CONTACT_STATUS_BUSY;
|
|
105 |
break;
|
|
106 |
case xa:
|
|
107 |
res = Status.CONTACT_STATUS_UNAVAILABLE;
|
|
108 |
break;
|
|
109 |
default:
|
|
110 |
res = Status.CONTACT_STATUS_DISCONNECT;
|
|
111 |
break;
|
107
|
112 |
}
|
|
113 |
}
|
|
114 |
}
|
|
115 |
return res;
|
|
116 |
}
|
|
117 |
}
|