src/com/beem/project/beem/BeemApplication.java
author Da Risk <darisk972@gmail.com>
Tue, 21 Apr 2009 20:48:35 +0200
changeset 130 eb0c7004090c
parent 128 52d32ded7b9d
child 133 190a55f30e11
permissions -rw-r--r--
Besoin de changement sur BeemApplication
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
     6
import java.util.LinkedList;
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
     7
import java.util.List;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     8
import android.app.Activity;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     9
import android.app.Application;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    10
import android.app.ProgressDialog;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    11
import android.content.ComponentName;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    12
import android.content.Context;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    13
import android.content.Intent;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    14
import android.content.ServiceConnection;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    15
import android.content.res.Resources;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    16
import android.os.Handler;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    17
import android.os.IBinder;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    18
import android.os.Message;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    19
import android.os.RemoteException;
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    20
import android.util.Log;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    21
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
    22
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
    23
import com.beem.project.beem.service.aidl.IXmppFacade;
106
a9bc9297dff7 Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents: 97
diff changeset
    24
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
    25
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    26
/**
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    27
 * 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
    28
 * @author darisk
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    29
 */
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    30
public class BeemApplication extends Application {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    31
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    32
    private static BeemApplication mBeemApp;
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    33
    private Activity mActivity;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    34
    private static final Intent SERVICE_INTENT = new Intent();
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    35
    public static final String TAG = "BeemApplication";
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
    36
    private IXmppFacade mFacade;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    37
    private Context mApplicationContext;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    38
    private Resources mPrivateResources;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    39
    private List<Message> mQueue = new LinkedList<Message>();
47
743ccc7961dc Contact liste recuperer.
marseille@KungFuh
parents: 46
diff changeset
    40
    private boolean mIsConnected;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    41
    private IXmppConnection mConnection;
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    42
    private ProgressDialog mProgressDialog;
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    43
    private ConnectionListener mConnectionListener = new ConnectionListener();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    44
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    45
    static {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    46
	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
    47
    }
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    48
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    49
    private ServiceConnection mServConn = new ServiceConnection() {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    50
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    51
	@Override
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    52
	public void onServiceDisconnected(ComponentName name) {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    53
	    mFacade = null;
47
743ccc7961dc Contact liste recuperer.
marseille@KungFuh
parents: 46
diff changeset
    54
	    mIsConnected = false;
45
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
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    57
	@Override
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    58
	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
    59
	    mIsConnected = true;
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
    60
	    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
    61
	    try {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    62
		mConnection = mFacade.createConnection();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    63
		if (!mConnection.isAuthentificated()) {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    64
		    mProgressDialog.show();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    65
		    mConnection.addConnectionListener(mConnectionListener);
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    66
		    mApplicationContext.startService(BeemApplication.SERVICE_INTENT);
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    67
		}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    68
	    } catch (RemoteException e) {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    69
		// TODO Auto-generated catch block
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    70
		e.printStackTrace();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    71
	    }
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    72
	}
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    73
    };
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    74
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    75
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    76
     * Constructor.
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    77
     */
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    78
    public BeemApplication() {
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
    79
	mIsConnected = false;
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    80
    }
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    81
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    82
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    83
     * 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
    84
     * @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
    85
     * @return the Beem application
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
    public static BeemApplication getApplication(Activity activity) {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    88
	if (mBeemApp == null) {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    89
	    mBeemApp = new BeemApplication();
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    90
	}
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    91
	mBeemApp.mActivity = activity;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    92
	mBeemApp.mProgressDialog = new ProgressDialog(activity);
73
4d9067c5e08e Add some thing for the progress dialog
Da Risk <darisk972@gmail.com>
parents: 72
diff changeset
    93
	mBeemApp.mProgressDialog.setTitle("Beem");
113
01b2fc87427b remise du logo modifié pour bart
Philippe Lago <lago_p@epitech.net>
parents: 111
diff changeset
    94
	mBeemApp.mProgressDialog.setIcon(R.drawable.signal);
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
    95
	mBeemApp.mProgressDialog.setMessage("Connecting...");
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    96
	mBeemApp.mApplicationContext = activity.getApplication();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    97
	mBeemApp.mPrivateResources = activity.getResources();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    98
	mBeemApp.onCreate();
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    99
	return mBeemApp;
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   100
    }
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   101
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   102
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   103
     * Start the beem service.
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   104
     */
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   105
    public synchronized void startBeemService() {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   106
	if (!mIsConnected) {
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   107
	    // 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
   108
	    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
   109
	}
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   110
    }
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
     * Stop the Beem service.
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   114
     */
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   115
    public synchronized void stopBeemService() {
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   116
	if (mIsConnected) {
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   117
	    Intent intent = new Intent();
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   118
	    intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   119
	    mApplicationContext.unbindService(mServConn);
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   120
	    mApplicationContext.stopService(intent);
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   121
	    mIsConnected = false;
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   122
	}
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   123
    }
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   124
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   125
    public synchronized void unbindBeemService() {
130
eb0c7004090c Besoin de changement sur BeemApplication
Da Risk <darisk972@gmail.com>
parents: 128
diff changeset
   126
	
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   127
	if (mIsConnected) {
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   128
	    mApplicationContext.unbindService(mServConn);
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   129
	    mIsConnected = false;
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   130
	}
130
eb0c7004090c Besoin de changement sur BeemApplication
Da Risk <darisk972@gmail.com>
parents: 128
diff changeset
   131
	
128
Da Risk <darisk972@gmail.com>
parents: 127 113
diff changeset
   132
     }
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   133
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   134
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   135
     * 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
   136
     * @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
   137
     */
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
   138
    public IXmppFacade getXmppFacade() {
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   139
	return mFacade;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   140
    }
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   141
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   142
    /**
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   143
     * 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
   144
     * @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
   145
     * @param callback the callback to execute
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   146
     */
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   147
    public void callWhenConnectedToServer(Handler target, Runnable callback) {
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   148
	Message msg = Message.obtain(target, callback);
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   149
	if (mIsConnected) {
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   150
	    msg.sendToTarget();
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   151
	} else {
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   152
	    startBeemService();
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   153
	    synchronized (mQueue) {
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   154
		mQueue.add(msg);
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   155
	    }
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   156
	}
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   157
    }
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   158
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   159
    /**
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   160
     * 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
   161
     * @return true if connected false otherwise
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   162
     */
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   163
    public boolean isConnected() {
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   164
	return mIsConnected;
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   165
    }
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   166
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   167
    private class ConnectionRunnable implements Runnable {
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   168
	private String mErrorMsg;
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   169
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   170
	public ConnectionRunnable(String string) {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   171
	    this.mErrorMsg = string;
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   172
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   173
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   174
	@Override
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   175
	public void run() {
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   176
	    mBeemApp.mProgressDialog.setMessage(mErrorMsg);
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   177
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   178
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   179
	/**
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   180
	 * @param mErrorMsg the mErrorMsg to set
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   181
	 */
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   182
	public void setMErrorMsg(String mErrorMsg) {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   183
	    this.mErrorMsg = mErrorMsg;
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   184
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   185
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   186
	/**
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   187
	 * @return the mErrorMsg
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   188
	 */
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   189
	public String getMErrorMsg() {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   190
	    return mErrorMsg;
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   191
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   192
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   193
    }
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   194
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   195
    /**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   196
     * 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
   197
     * @author darisk
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   198
     */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   199
    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
   200
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   201
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   202
	 * Constructor.
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   203
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   204
	public ConnectionListener() {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   205
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
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   208
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   209
	 * {@inheritDoc}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   210
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   211
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   212
	public void connectionClosed() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   213
	    // TODO Auto-generated method stub
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   214
	    Log.e("BeemApp", "test1");
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   215
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 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
   223
	    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
   224
	    Log.e(TAG, "ConnectionClosedOnError");
106
a9bc9297dff7 Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents: 97
diff changeset
   225
	    // 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
   226
	}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   227
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
	 * {@inheritDoc}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   230
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   231
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   232
	public void onConnect() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   233
	    // TODO Auto-generated method stub
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   234
	    mProgressDialog.dismiss();
106
a9bc9297dff7 Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents: 97
diff changeset
   235
	    // 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
   236
	    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
   237
	    synchronized (mQueue) {
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   238
		for (Message msg : mQueue) {
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   239
		    msg.sendToTarget();
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   240
		}
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   241
		mQueue.clear();
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   242
	    }
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   243
	}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   244
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   245
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   246
	 * {@inheritDoc}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   247
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   248
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   249
	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
   250
	    // TODO Auto-generated method stub
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   251
	    mProgressDialog.show();
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
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   255
	 * {@inheritDoc}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   256
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   257
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   258
	public void reconnectionFailed() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   259
	    // TODO Auto-generated method stub
127
395f1beb409f deconnexion et fin du service presque ok
Da Risk <darisk972@gmail.com>
parents: 111
diff changeset
   260
	    Log.e("BeemApp", "test3");
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   261
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
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   264
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   265
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   268
	public void reconnectionSuccessful() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   269
	    // TODO Auto-generated method stub
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   270
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   271
	}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   272
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   273
	@Override
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   274
	public void connectionFailed(String errorMsg) throws RemoteException {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   275
	    Log.i(TAG, "Connection Failed");
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   276
	    ConnectionRunnable cRun = new ConnectionRunnable(errorMsg);
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   277
	    mBeemApp.mActivity.runOnUiThread(cRun);
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   278
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   279
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   280
    }
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   281
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   282
}