author | marseille |
Fri, 24 Apr 2009 00:32:21 +0200 | |
changeset 162 | 72bfb4fe5815 |
parent 149 | 2faf7174aa03 |
child 165 | 6e008c3695ff |
permissions | -rw-r--r-- |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
1 |
/** |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
2 |
* |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
3 |
*/ |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
4 |
package com.beem.project.beem; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
5 |
|
46 | 6 |
import java.util.LinkedList; |
7 |
import java.util.List; |
|
162 | 8 |
|
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
9 |
import android.app.Activity; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
10 |
import android.app.Application; |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
11 |
import android.app.ProgressDialog; |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
12 |
import android.content.ComponentName; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
13 |
import android.content.Context; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
14 |
import android.content.Intent; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
15 |
import android.content.ServiceConnection; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
16 |
import android.content.res.Resources; |
46 | 17 |
import android.os.Handler; |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
18 |
import android.os.IBinder; |
46 | 19 |
import android.os.Message; |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
20 |
import android.os.RemoteException; |
99 | 21 |
import android.util.Log; |
162 | 22 |
import android.widget.Toast; |
23 |
||
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
24 |
import com.beem.project.beem.service.aidl.IBeemConnectionListener; |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
25 |
import com.beem.project.beem.service.aidl.IXmppConnection; |
67
8c3870db8e31
Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents:
55
diff
changeset
|
26 |
import com.beem.project.beem.service.aidl.IXmppFacade; |
162 | 27 |
import com.beem.project.beem.ui.AddContact; |
28 |
import com.beem.project.beem.ui.ContactList; |
|
106
a9bc9297dff7
Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents:
97
diff
changeset
|
29 |
import com.beem.project.beem.utils.Status; |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
30 |
|
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
31 |
/** |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
32 |
* The Beem application. This class has some methods utiliy needs by the activities. |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
33 |
* @author darisk |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
34 |
*/ |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
35 |
public class BeemApplication extends Application { |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
36 |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
37 |
private static BeemApplication mBeemApp; |
99 | 38 |
private Activity mActivity; |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
39 |
private static final Intent SERVICE_INTENT = new Intent(); |
99 | 40 |
public static final String TAG = "BeemApplication"; |
67
8c3870db8e31
Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents:
55
diff
changeset
|
41 |
private IXmppFacade mFacade; |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
42 |
private Context mApplicationContext; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
43 |
private Resources mPrivateResources; |
46 | 44 |
private List<Message> mQueue = new LinkedList<Message>(); |
47 | 45 |
private boolean mIsConnected; |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
46 |
private IXmppConnection mConnection; |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
47 |
private ProgressDialog mProgressDialog; |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
48 |
private ConnectionListener mConnectionListener = new ConnectionListener(); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
49 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
50 |
static { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
51 |
SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
52 |
} |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
53 |
|
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
54 |
private ServiceConnection mServConn = new ServiceConnection() { |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
55 |
|
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
56 |
@Override |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
57 |
public void onServiceDisconnected(ComponentName name) { |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
58 |
mFacade = null; |
47 | 59 |
mIsConnected = false; |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
60 |
} |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
61 |
|
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
62 |
@Override |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
63 |
public void onServiceConnected(ComponentName name, IBinder service) { |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
64 |
mIsConnected = true; |
67
8c3870db8e31
Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents:
55
diff
changeset
|
65 |
mFacade = IXmppFacade.Stub.asInterface(service); |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
66 |
try { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
67 |
mConnection = mFacade.createConnection(); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
68 |
if (!mConnection.isAuthentificated()) { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
69 |
mConnection.addConnectionListener(mConnectionListener); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
70 |
mApplicationContext.startService(BeemApplication.SERVICE_INTENT); |
133 | 71 |
}else { |
72 |
synchronized (mQueue) { |
|
73 |
for (Message msg : mQueue) { |
|
74 |
msg.sendToTarget(); |
|
75 |
} |
|
76 |
mQueue.clear(); |
|
77 |
} |
|
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
78 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
79 |
} catch (RemoteException e) { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
80 |
// TODO Auto-generated catch block |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
81 |
e.printStackTrace(); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
82 |
} |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
83 |
} |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
84 |
}; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
85 |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
86 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
87 |
* Constructor. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
88 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
89 |
public BeemApplication() { |
76
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
90 |
mIsConnected = false; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
91 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
92 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
93 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
94 |
* Get the Beem application for an activity. |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
95 |
* @param activity the activity which want the Beem application |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
96 |
* @return the Beem application |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
97 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
98 |
public static BeemApplication getApplication(Activity activity) { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
99 |
if (mBeemApp == null) { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
100 |
mBeemApp = new BeemApplication(); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
101 |
} |
99 | 102 |
mBeemApp.mActivity = activity; |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
103 |
mBeemApp.mProgressDialog = new ProgressDialog(activity); |
73
4d9067c5e08e
Add some thing for the progress dialog
Da Risk <darisk972@gmail.com>
parents:
72
diff
changeset
|
104 |
mBeemApp.mProgressDialog.setTitle("Beem"); |
149 | 105 |
mBeemApp.mProgressDialog.setIcon(R.drawable.barthe_f); |
111
d0fab932cb6e
Class et layout ChangeStatus pour bart + modification des layout pour gerer le mode paysage
Philippe Lago <lago_p@epitech.net>
parents:
108
diff
changeset
|
106 |
mBeemApp.mProgressDialog.setMessage("Connecting..."); |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
107 |
mBeemApp.mApplicationContext = activity.getApplication(); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
108 |
mBeemApp.mPrivateResources = activity.getResources(); |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
109 |
mBeemApp.onCreate(); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
110 |
return mBeemApp; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
111 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
112 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
113 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
114 |
* Start the beem service. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
115 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
116 |
public synchronized void startBeemService() { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
117 |
if (!mIsConnected) { |
162 | 118 |
mProgressDialog.setMessage("Connecting..."); |
119 |
mProgressDialog.show(); |
|
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
120 |
// the connection will be made on service connect |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
121 |
mApplicationContext.bindService(BeemApplication.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
122 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
123 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
124 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
125 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
126 |
* Stop the Beem service. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
127 |
*/ |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
128 |
public synchronized void stopBeemService() { |
52 | 129 |
if (mIsConnected) { |
130 |
Intent intent = new Intent(); |
|
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
131 |
intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); |
52 | 132 |
mApplicationContext.unbindService(mServConn); |
133 |
mApplicationContext.stopService(intent); |
|
134 |
mIsConnected = false; |
|
135 |
} |
|
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
136 |
} |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
137 |
|
127
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
138 |
public synchronized void unbindBeemService() { |
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
139 |
if (mIsConnected) { |
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
140 |
mApplicationContext.unbindService(mServConn); |
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
141 |
mIsConnected = false; |
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
142 |
} |
128 | 143 |
} |
127
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
144 |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
145 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
146 |
* Get the facade to use to access the Beem service. |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
147 |
* @return the facade or null if the application is not connected to the beem service. |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
148 |
*/ |
67
8c3870db8e31
Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents:
55
diff
changeset
|
149 |
public IXmppFacade getXmppFacade() { |
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
150 |
return mFacade; |
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
151 |
} |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
152 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
153 |
/** |
76
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
154 |
* Add a methode to execute when the application is connected to the server. |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
155 |
* @param target the handler which will execute the callback |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
156 |
* @param callback the callback to execute |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
47
diff
changeset
|
157 |
*/ |
76
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
158 |
public void callWhenConnectedToServer(Handler target, Runnable callback) { |
46 | 159 |
Message msg = Message.obtain(target, callback); |
76
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
160 |
if (mIsConnected) { |
46 | 161 |
msg.sendToTarget(); |
162 |
} else { |
|
163 |
startBeemService(); |
|
164 |
synchronized (mQueue) { |
|
165 |
mQueue.add(msg); |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
52 | 169 |
|
170 |
/** |
|
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
171 |
* Tell if we are connected with the Beem Service. |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
172 |
* @return true if connected false otherwise |
52 | 173 |
*/ |
174 |
public boolean isConnected() { |
|
175 |
return mIsConnected; |
|
176 |
} |
|
177 |
||
99 | 178 |
private class ConnectionRunnable implements Runnable { |
127
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
179 |
private String mErrorMsg; |
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
180 |
|
99 | 181 |
public ConnectionRunnable(String string) { |
182 |
this.mErrorMsg = string; |
|
183 |
} |
|
184 |
||
185 |
@Override |
|
186 |
public void run() { |
|
127
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
187 |
mBeemApp.mProgressDialog.setMessage(mErrorMsg); |
99 | 188 |
} |
189 |
||
190 |
/** |
|
191 |
* @param mErrorMsg the mErrorMsg to set |
|
192 |
*/ |
|
193 |
public void setMErrorMsg(String mErrorMsg) { |
|
194 |
this.mErrorMsg = mErrorMsg; |
|
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* @return the mErrorMsg |
|
199 |
*/ |
|
200 |
public String getMErrorMsg() { |
|
201 |
return mErrorMsg; |
|
202 |
} |
|
203 |
||
204 |
} |
|
205 |
||
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
206 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
207 |
* Connection listener use to hide the progress dialog. |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
208 |
* @author darisk |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
209 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
210 |
private class ConnectionListener extends IBeemConnectionListener.Stub { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
211 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
212 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
213 |
* Constructor. |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
214 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
215 |
public ConnectionListener() { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
216 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
217 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
218 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
219 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
220 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
221 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
222 |
public void connectionClosed() throws RemoteException { |
162 | 223 |
Log.e(TAG, "Connection Close"); |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
224 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
225 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
226 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
227 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
228 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
229 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
230 |
public void connectionClosedOnError() throws RemoteException { |
111
d0fab932cb6e
Class et layout ChangeStatus pour bart + modification des layout pour gerer le mode paysage
Philippe Lago <lago_p@epitech.net>
parents:
108
diff
changeset
|
231 |
mBeemApp.mProgressDialog.setMessage("Connection closed on error"); |
127
395f1beb409f
deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents:
111
diff
changeset
|
232 |
Log.e(TAG, "ConnectionClosedOnError"); |
106
a9bc9297dff7
Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents:
97
diff
changeset
|
233 |
// TODO afficher une notification et reafficher le progress dialog |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
234 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
235 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
236 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
237 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
238 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
239 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
240 |
public void onConnect() throws RemoteException { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
241 |
// TODO Auto-generated method stub |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
242 |
mProgressDialog.dismiss(); |
106
a9bc9297dff7
Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents:
97
diff
changeset
|
243 |
// TODO recuperer les informations de status dans les preferences |
a9bc9297dff7
Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents:
97
diff
changeset
|
244 |
mFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null); |
76
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
245 |
synchronized (mQueue) { |
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
246 |
for (Message msg : mQueue) { |
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
247 |
msg.sendToTarget(); |
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
248 |
} |
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
249 |
mQueue.clear(); |
144e837ee4a6
fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents:
73
diff
changeset
|
250 |
} |
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
251 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
252 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
253 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
254 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
255 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
256 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
257 |
public void reconnectingIn(int seconds) throws RemoteException { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
258 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
259 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
260 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
261 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
262 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
263 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
264 |
public void reconnectionFailed() throws RemoteException { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
265 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
266 |
|
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
267 |
/** |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
268 |
* {@inheritDoc} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
269 |
*/ |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
270 |
@Override |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
271 |
public void reconnectionSuccessful() throws RemoteException { |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
272 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
273 |
|
99 | 274 |
@Override |
275 |
public void connectionFailed(String errorMsg) throws RemoteException { |
|
276 |
Log.i(TAG, "Connection Failed"); |
|
277 |
ConnectionRunnable cRun = new ConnectionRunnable(errorMsg); |
|
278 |
mBeemApp.mActivity.runOnUiThread(cRun); |
|
279 |
} |
|
280 |
||
72
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
281 |
} |
cdedc3a25d39
Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents:
68
diff
changeset
|
282 |
|
45
ae035477b6aa
Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
283 |
} |