src/com/beem/project/beem/BeemApplication.java
changeset 99 8de21ac527ce
parent 98 4d6ff785605d
child 108 c60aa2237865
equal deleted inserted replaced
98:4d6ff785605d 99:8de21ac527ce
    17 import android.content.res.Resources;
    17 import android.content.res.Resources;
    18 import android.os.Handler;
    18 import android.os.Handler;
    19 import android.os.IBinder;
    19 import android.os.IBinder;
    20 import android.os.Message;
    20 import android.os.Message;
    21 import android.os.RemoteException;
    21 import android.os.RemoteException;
       
    22 import android.util.Log;
       
    23 import android.widget.Toast;
    22 
    24 
    23 import com.beem.project.beem.service.aidl.IBeemConnectionListener;
    25 import com.beem.project.beem.service.aidl.IBeemConnectionListener;
    24 import com.beem.project.beem.service.aidl.IXmppConnection;
    26 import com.beem.project.beem.service.aidl.IXmppConnection;
    25 import com.beem.project.beem.service.aidl.IXmppFacade;
    27 import com.beem.project.beem.service.aidl.IXmppFacade;
    26 
    28 
    29  * @author darisk
    31  * @author darisk
    30  */
    32  */
    31 public class BeemApplication extends Application {
    33 public class BeemApplication extends Application {
    32 
    34 
    33     private static BeemApplication mBeemApp;
    35     private static BeemApplication mBeemApp;
       
    36     private Activity mActivity;
    34     private static final Intent SERVICE_INTENT = new Intent();
    37     private static final Intent SERVICE_INTENT = new Intent();
       
    38     public static final String TAG = "BeemApplication";
    35     private IXmppFacade mFacade;
    39     private IXmppFacade mFacade;
    36     private Context mApplicationContext;
    40     private Context mApplicationContext;
    37     private Resources mPrivateResources;
    41     private Resources mPrivateResources;
    38     private List<Message> mQueue = new LinkedList<Message>();
    42     private List<Message> mQueue = new LinkedList<Message>();
    39     private boolean mIsConnected;
    43     private boolean mIsConnected;
    85      */
    89      */
    86     public static BeemApplication getApplication(Activity activity) {
    90     public static BeemApplication getApplication(Activity activity) {
    87 	if (mBeemApp == null) {
    91 	if (mBeemApp == null) {
    88 	    mBeemApp = new BeemApplication();
    92 	    mBeemApp = new BeemApplication();
    89 	}
    93 	}
       
    94 	mBeemApp.mActivity = activity;
    90 	mBeemApp.mProgressDialog = new ProgressDialog(activity);
    95 	mBeemApp.mProgressDialog = new ProgressDialog(activity);
    91 	mBeemApp.mProgressDialog.setTitle("Beem");
    96 	mBeemApp.mProgressDialog.setTitle("Beem");
    92 	mBeemApp.mProgressDialog.setIcon(R.drawable.logo);
    97 	mBeemApp.mProgressDialog.setIcon(R.drawable.logo);
    93 	mBeemApp.mProgressDialog.setMessage("Connexion en cours");
    98 	mBeemApp.mProgressDialog.setMessage("Connexion en cours");
    94 	mBeemApp.mApplicationContext = activity.getApplication();
    99 	mBeemApp.mApplicationContext = activity.getApplication();
   151      */
   156      */
   152     public boolean isConnected() {
   157     public boolean isConnected() {
   153 	return mIsConnected;
   158 	return mIsConnected;
   154     }
   159     }
   155 
   160 
       
   161     private class ConnectionRunnable implements Runnable {
       
   162 	private String mErrorMsg;	
       
   163 	
       
   164 	public ConnectionRunnable(String string) {
       
   165 	    this.mErrorMsg = string;
       
   166 	}
       
   167 
       
   168 	@Override
       
   169 	public void run() {
       
   170 	    mBeemApp.mProgressDialog.setMessage(mErrorMsg);	    
       
   171 	}
       
   172 
       
   173 	/**
       
   174 	 * @param mErrorMsg the mErrorMsg to set
       
   175 	 */
       
   176 	public void setMErrorMsg(String mErrorMsg) {
       
   177 	    this.mErrorMsg = mErrorMsg;
       
   178 	}
       
   179 
       
   180 	/**
       
   181 	 * @return the mErrorMsg
       
   182 	 */
       
   183 	public String getMErrorMsg() {
       
   184 	    return mErrorMsg;
       
   185 	}
       
   186 
       
   187     }
       
   188 
   156     /**
   189     /**
   157      * Connection listener use to hide the progress dialog.
   190      * Connection listener use to hide the progress dialog.
   158      * @author darisk
   191      * @author darisk
   159      */
   192      */
   160     private class ConnectionListener extends IBeemConnectionListener.Stub {
   193     private class ConnectionListener extends IBeemConnectionListener.Stub {
   170 	 * {@inheritDoc}
   203 	 * {@inheritDoc}
   171 	 */
   204 	 */
   172 	@Override
   205 	@Override
   173 	public void connectionClosed() throws RemoteException {
   206 	public void connectionClosed() throws RemoteException {
   174 	    // TODO Auto-generated method stub
   207 	    // TODO Auto-generated method stub
       
   208 	    Log.e("BeemApp","test1");
   175 
   209 
   176 	}
   210 	}
   177 
   211 
   178 	/**
   212 	/**
   179 	 * {@inheritDoc}
   213 	 * {@inheritDoc}
   180 	 */
   214 	 */
   181 	@Override
   215 	@Override
   182 	public void connectionClosedOnError() throws RemoteException {
   216 	public void connectionClosedOnError() throws RemoteException {
   183 	    // TODO Auto-generated method stub
   217 	    mBeemApp.mProgressDialog.setMessage("Connexion closed on error");
       
   218 	    Log.e(TAG,"onnectionClosedOnError");
   184 	    // afficher une notification et reafficher le progress dialog
   219 	    // afficher une notification et reafficher le progress dialog
   185 	}
   220 	}
   186 
   221 
   187 	/**
   222 	/**
   188 	 * {@inheritDoc}
   223 	 * {@inheritDoc}
   213 	 * {@inheritDoc}
   248 	 * {@inheritDoc}
   214 	 */
   249 	 */
   215 	@Override
   250 	@Override
   216 	public void reconnectionFailed() throws RemoteException {
   251 	public void reconnectionFailed() throws RemoteException {
   217 	    // TODO Auto-generated method stub
   252 	    // TODO Auto-generated method stub
       
   253 	    Log.e("BeemApp","test3");
   218 
   254 
   219 	}
   255 	}
   220 
   256 
   221 	/**
   257 	/**
   222 	 * {@inheritDoc}
   258 	 * {@inheritDoc}
   225 	public void reconnectionSuccessful() throws RemoteException {
   261 	public void reconnectionSuccessful() throws RemoteException {
   226 	    // TODO Auto-generated method stub
   262 	    // TODO Auto-generated method stub
   227 
   263 
   228 	}
   264 	}
   229 
   265 
       
   266 	@Override
       
   267 	public void connectionFailed(String errorMsg) throws RemoteException {
       
   268 	    Log.i(TAG, "Connection Failed");
       
   269 	    ConnectionRunnable cRun = new ConnectionRunnable(errorMsg);
       
   270 	    mBeemApp.mActivity.runOnUiThread(cRun);
       
   271 	}
       
   272 
   230     }
   273     }
   231 
   274 
   232 }
   275 }