src/com/beem/project/beem/BeemApplication.java
author Da Risk <darisk972@gmail.com>
Wed, 15 Apr 2009 19:41:35 +0200
changeset 108 c60aa2237865
parent 106 a9bc9297dff7
parent 99 8de21ac527ce
child 111 d0fab932cb6e
permissions -rw-r--r--
merge with ui
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
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.Configuration;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    17
import android.content.res.Resources;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    18
import android.os.Handler;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    19
import android.os.IBinder;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    20
import android.os.Message;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    21
import android.os.RemoteException;
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    22
import android.util.Log;
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    23
import android.widget.Toast;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    24
72
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.IBeemConnectionListener;
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    26
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
    27
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
    28
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
    29
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    30
/**
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    31
 * 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
    32
 * @author darisk
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    33
 */
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    34
public class BeemApplication extends Application {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    35
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    36
    private static BeemApplication mBeemApp;
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    37
    private Activity mActivity;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    38
    private static final Intent SERVICE_INTENT = new Intent();
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    39
    public static final String TAG = "BeemApplication";
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
    40
    private IXmppFacade mFacade;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    41
    private Context mApplicationContext;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    42
    private Resources mPrivateResources;
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
    43
    private List<Message> mQueue = new LinkedList<Message>();
47
743ccc7961dc Contact liste recuperer.
marseille@KungFuh
parents: 46
diff changeset
    44
    private boolean mIsConnected;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    45
    private IXmppConnection mConnection;
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    46
    private ProgressDialog mProgressDialog;
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    47
    private ConnectionListener mConnectionListener = new ConnectionListener();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    48
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    49
    static {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    50
	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
    51
    }
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    52
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    53
    private ServiceConnection mServConn = new ServiceConnection() {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    54
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    55
	@Override
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    56
	public void onServiceDisconnected(ComponentName name) {
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    57
	    mFacade = null;
47
743ccc7961dc Contact liste recuperer.
marseille@KungFuh
parents: 46
diff changeset
    58
	    mIsConnected = false;
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    59
	}
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
	@Override
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    62
	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
    63
	    mIsConnected = true;
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
    64
	    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
    65
	    try {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    66
		mConnection = mFacade.createConnection();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    67
		if (!mConnection.isAuthentificated()) {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    68
		    mProgressDialog.show();
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);
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    71
		}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    72
	    } catch (RemoteException e) {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    73
		// TODO Auto-generated catch block
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    74
		e.printStackTrace();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    75
	    }
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    76
	}
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    77
    };
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    78
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    79
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    80
     * Constructor.
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
    public BeemApplication() {
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
    83
	mIsConnected = false;
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    84
    }
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    85
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
     * 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
    88
     * @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
    89
     * @return the Beem application
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    90
     */
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    91
    public static BeemApplication getApplication(Activity activity) {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    92
	if (mBeemApp == null) {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    93
	    mBeemApp = new BeemApplication();
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
    94
	}
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
    95
	mBeemApp.mActivity = activity;
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
    96
	mBeemApp.mProgressDialog = new ProgressDialog(activity);
73
4d9067c5e08e Add some thing for the progress dialog
Da Risk <darisk972@gmail.com>
parents: 72
diff changeset
    97
	mBeemApp.mProgressDialog.setTitle("Beem");
4d9067c5e08e Add some thing for the progress dialog
Da Risk <darisk972@gmail.com>
parents: 72
diff changeset
    98
	mBeemApp.mProgressDialog.setIcon(R.drawable.logo);
4d9067c5e08e Add some thing for the progress dialog
Da Risk <darisk972@gmail.com>
parents: 72
diff changeset
    99
	mBeemApp.mProgressDialog.setMessage("Connexion en cours");
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   100
	mBeemApp.mApplicationContext = activity.getApplication();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   101
	mBeemApp.mPrivateResources = activity.getResources();
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   102
	mBeemApp.onCreate();
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   103
	return mBeemApp;
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
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   106
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   107
     * Start the beem service.
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   108
     */
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   109
    public synchronized void startBeemService() {
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   110
	if (!mIsConnected) {
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   111
	    // 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
   112
	    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
   113
	}
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   114
    }
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
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   117
     * Stop the Beem service.
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   118
     */
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   119
    public synchronized void stopBeemService() {
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   120
	if (mIsConnected) {
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   121
	    Intent intent = new Intent();
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   122
	    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
   123
	    mApplicationContext.unbindService(mServConn);
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   124
	    mApplicationContext.stopService(intent);
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   125
	    mIsConnected = false;
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   126
	}
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   127
    }
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   128
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   129
    /**
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   130
     * 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
   131
     * @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
   132
     */
67
8c3870db8e31 Rename some XMPP* classes in Xmpp*
Da Risk <darisk972@gmail.com>
parents: 55
diff changeset
   133
    public IXmppFacade getXmppFacade() {
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   134
	return mFacade;
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   135
    }
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   136
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   137
    /**
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   138
     * 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
   139
     * @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
   140
     * @param callback the callback to execute
55
66732dd2cb77 Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents: 47
diff changeset
   141
     */
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   142
    public void callWhenConnectedToServer(Handler target, Runnable callback) {
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   143
	Message msg = Message.obtain(target, callback);
76
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   144
	if (mIsConnected) {
46
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   145
	    msg.sendToTarget();
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   146
	} else {
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   147
	    startBeemService();
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   148
	    synchronized (mQueue) {
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   149
		mQueue.add(msg);
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   150
	    }
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   151
	}
d5a36d820645 Amelioration de l'application
Da Risk <darisk972@gmail.com>
parents: 45
diff changeset
   152
    }
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   153
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   154
    /**
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   155
     * 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
   156
     * @return true if connected false otherwise
52
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   157
     */
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   158
    public boolean isConnected() {
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   159
	return mIsConnected;
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   160
    }
375194dc3bca Gros menage dans les views.
marseille@KungFuh
parents: 47
diff changeset
   161
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   162
    private class ConnectionRunnable implements Runnable {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   163
	private String mErrorMsg;	
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   164
	
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   165
	public ConnectionRunnable(String string) {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   166
	    this.mErrorMsg = string;
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   167
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   168
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   169
	@Override
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   170
	public void run() {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   171
	    mBeemApp.mProgressDialog.setMessage(mErrorMsg);	    
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
	/**
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   175
	 * @param mErrorMsg the mErrorMsg to set
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   176
	 */
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   177
	public void setMErrorMsg(String mErrorMsg) {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   178
	    this.mErrorMsg = mErrorMsg;
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
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
	 * @return the mErrorMsg
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   183
	 */
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   184
	public String getMErrorMsg() {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   185
	    return mErrorMsg;
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
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
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   190
    /**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   191
     * 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
   192
     * @author darisk
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   193
     */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   194
    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
   195
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   196
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   197
	 * Constructor.
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
	public ConnectionListener() {
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
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
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   207
	public void connectionClosed() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   208
	    // TODO Auto-generated method stub
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   209
	    Log.e("BeemApp","test1");
72
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
	}
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
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   214
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   217
	public void connectionClosedOnError() throws RemoteException {
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   218
	    mBeemApp.mProgressDialog.setMessage("Connexion closed on error");
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   219
	    Log.e(TAG,"onnectionClosedOnError");
106
a9bc9297dff7 Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents: 97
diff changeset
   220
	    // 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
   221
	}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   222
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   223
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   224
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   227
	public void onConnect() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   228
	    // TODO Auto-generated method stub
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   229
	    mProgressDialog.dismiss();
106
a9bc9297dff7 Amelioration de la methode change status.
Da Risk <darisk972@gmail.com>
parents: 97
diff changeset
   230
	    // 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
   231
	    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
   232
	    synchronized (mQueue) {
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   233
		for (Message msg : mQueue) {
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   234
		    msg.sendToTarget();
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   235
		}
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   236
		mQueue.clear();
144e837ee4a6 fix some synchronisation problem with the server
Da Risk <darisk972@gmail.com>
parents: 73
diff changeset
   237
	    }
72
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
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   240
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   241
	 * {@inheritDoc}
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   242
	 */
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   243
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   244
	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
   245
	    // TODO Auto-generated method stub
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   246
	    mProgressDialog.show();
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
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   249
	/**
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   250
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   253
	public void reconnectionFailed() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   254
	    // TODO Auto-generated method stub
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   255
	    Log.e("BeemApp","test3");
72
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
	}
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
	 * {@inheritDoc}
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
	@Override
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   263
	public void reconnectionSuccessful() throws RemoteException {
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   264
	    // TODO Auto-generated method stub
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
99
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   268
	@Override
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   269
	public void connectionFailed(String errorMsg) throws RemoteException {
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   270
	    Log.i(TAG, "Connection Failed");
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   271
	    ConnectionRunnable cRun = new ConnectionRunnable(errorMsg);
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   272
	    mBeemApp.mActivity.runOnUiThread(cRun);
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   273
	}
8de21ac527ce revert pour refaire un push propre
nikita@nikita-rack
parents: 98
diff changeset
   274
72
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   275
    }
cdedc3a25d39 Show a progress dialog during connection with the server
Da Risk <darisk972@gmail.com>
parents: 68
diff changeset
   276
45
ae035477b6aa Utilisation d'une application qui gere les informations globales.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
   277
}