merge
authorDa Risk <darisk972@gmail.com>
Thu, 26 Nov 2009 15:27:28 +0100
changeset 544 24276024c388
parent 543 28d200758114 (diff)
parent 538 d0745275aed8 (current diff)
child 545 0de3d7f3fa81
merge
--- a/AndroidManifest.xml	Tue Nov 24 11:58:14 2009 +0100
+++ b/AndroidManifest.xml	Thu Nov 26 15:27:28 2009 +0100
@@ -16,6 +16,18 @@
 					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
 			</intent-filter>
 		</activity>
+		
+		<activity android:name=".ui.LoginAnim" android:label="ANIM"
+			android:launchMode="singleTask">
+			<intent-filter>
+				<action android:name="android.intent.action.MAIN" />
+				<category android:name="android.intent.category.LAUNCHER" />
+			</intent-filter>
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
 		<activity android:name=".ui.Settings" android:label="@string/edit_settings_name">
 			<intent-filter android:label="Beem Connection">
 				<action
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/anim/rotate_and_scale.xml	Thu Nov 26 15:27:28 2009 +0100
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+    <scale android:fromXScale="0.5" android:toXScale="1.0"
+	android:fromYScale="0.5" android:toYScale="1.0"
+	android:pivotX="50%" android:pivotY="50%" 
+	android:repeatMode="reverse" android:duration="8000"
+	android:repeatCount="infinite" />
+    <rotate android:fromDegrees="0" android:toDegrees="360"
+	android:pivotX="50%" android:pivotY="50%"
+	android:duration="5000"
+	android:repeatMode="restart"
+	android:repeatCount="infinite" />
+</set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/login_anim.xml	Thu Nov 26 15:27:28 2009 +0100
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="fill_parent"
+    android:layout_width="fill_parent"
+    android:orientation="vertical" >
+    <ImageView android:id="@+id/loginanim_logo_anim" android:src="@drawable/beem_launcher_icon_color" android:layout_height="fill_parent" android:layout_width="fill_parent" 
+	android:layout_weight="1"/>
+    <!-- TODO traduction -->
+    <Button android:id= "@+id/loginanim_cancel_button"
+	android:layout_height="wrap_content" android:layout_width="fill_parent"
+	android:layout_gravity="bottom"
+	android:text="Cancel" />
+</LinearLayout>
+
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Nov 24 11:58:14 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Nov 26 15:27:28 2009 +0100
@@ -120,6 +120,8 @@
      */
     @Override
     public final void connectAsync() throws RemoteException {
+	if (mAdaptee.isConnected() || mAdaptee.isAuthenticated())
+	    return;
 	Thread t = new Thread(new Runnable() {
 
 	    @Override
--- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl	Tue Nov 24 11:58:14 2009 +0100
+++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl	Thu Nov 26 15:27:28 2009 +0100
@@ -10,35 +10,35 @@
      *  Callback to call when the connection is closed
      */
     void connectionClosed();
-    
+
     /**
      *  Callback to call when the connection occurs
      */
     void onConnect();
-    
+
     //void connectionClosedOnError(in Exception e);
     /**
      *  Callback to call when the connection is closed on error
      */
     void connectionClosedOnError();
-     
+
     /**
      * Callback to call when trying to reconnecting
      */
     void reconnectingIn(in int seconds);
-    
+
     /**
      *  Callback to call when the reconnection has failed
      */
     void reconnectionFailed();
-     
+
     /**
      *  Callback to call when the reconnection is successfull
-     */ 
+     */
     void reconnectionSuccessful();
-    
+
     /**
      *  Callback to call when the connection Failed
-     */ 
+     */
     void connectionFailed(in String errorMsg);
 }
--- a/src/com/beem/project/beem/ui/AddContact.java	Tue Nov 24 11:58:14 2009 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java	Thu Nov 26 15:27:28 2009 +0100
@@ -129,6 +129,7 @@
 
     private final OnClickListener mOkListener = new OnClickListener() {
 
+	@Override
 	public void onClick(View v) {
 	    String login;
 	    login = getWidgetText(R.id.addc_login);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/LoginAnim.java	Thu Nov 26 15:27:28 2009 +0100
@@ -0,0 +1,175 @@
+package com.beem.project.beem.ui;
+
+import android.app.Activity;
+import android.content.ServiceConnection;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.AsyncTask;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.view.View.OnClickListener;
+import android.view.View;
+import android.widget.Button;
+import android.view.animation.Animation;
+import android.widget.ImageView;
+import android.view.animation.AnimationUtils;
+import com.beem.project.beem.R;
+import android.util.Log;
+import com.beem.project.beem.service.aidl.IXmppFacade;
+import com.beem.project.beem.service.aidl.IXmppConnection;
+import com.beem.project.beem.service.aidl.IXmppFacade;
+
+/**
+ * This class is an activity which display an animation during the connection
+ * with the server.
+ * @author Da Risk <darisk972@gmail.com>
+ */
+public class LoginAnim extends Activity {
+
+    private static final String TAG = "LoginAnim";
+    private static final Intent SERVICE_INTENT = new Intent();
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+    private ImageView mLogo;
+    private Animation mRotateAnim;
+    private final ServiceConnection mServConn = new LoginServiceConnection();
+    private IXmppFacade mXmppFacade;
+    private AsyncTask<IXmppFacade, Void, Boolean>mTask;
+    private Button mCancelBt;
+
+    /**
+     * Constructor.
+     */
+    public LoginAnim() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.login_anim);
+	mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim);
+	mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale);
+	mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button);
+	mCancelBt.setOnClickListener( new ClickListener());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStart() {
+	super.onStart();
+        mLogo.startAnimation(mRotateAnim);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	if (mTask == null) {
+	    mTask = new LoginTask();
+	}
+	if (mXmppFacade == null) {
+	    bindService(LoginAnim.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	}
+    }
+
+    @Override
+    protected void onPause() {
+	super.onPause();
+	if (mXmppFacade != null) { // and async task not en cours
+	    unbindService(mServConn);
+	    mXmppFacade = null;
+	}
+    }
+
+    class LoginTask extends AsyncTask<IXmppFacade, Void, Boolean> {
+
+	private IXmppConnection mConnection;
+
+	@Override
+	protected Boolean doInBackground(IXmppFacade ... params) {
+	    boolean result = true;
+	    IXmppFacade facade = params[0];
+	    try {
+		mConnection = facade.createConnection();
+		if (!mConnection.isAuthentificated()) {
+		    result = mConnection.connectSync();
+		    if (!result) {
+			// set bad message ?
+		    }
+		}
+	    } catch (RemoteException e) {
+		Log.d(TAG, "Error while connecting", e);
+		// set bad message ?
+		result = false;
+	    }
+	    Log.d(TAG, "Connection result? " + result);
+	    return result;
+	}
+
+	@Override
+	protected void onPostExecute(Boolean result) {
+	    if (result == null || !result) { // Task cancelled on exception
+		Log.d(TAG, "Exception or cancelation of the connection");
+	    } else {
+		LoginAnim.this.startService(LoginAnim.SERVICE_INTENT);
+		LoginAnim.this.startActivity(new Intent(LoginAnim.this, ContactList.class));
+		LoginAnim.this.finish();
+	    }
+	}
+
+	@Override
+	protected void onCancelled() {
+	    mCancelBt.setText("Cancelled. Retry");
+	    try {
+		if (mConnection.isAuthentificated()) {
+		    mConnection.disconnect();
+		}
+	    } catch (RemoteException e) {
+		Log.d(TAG, "Remote exception", e);
+	    }
+	    LoginAnim.this.stopService(LoginAnim.SERVICE_INTENT);
+	    LoginAnim.this.finish();
+	}
+
+    }
+
+    private class LoginServiceConnection implements ServiceConnection {
+
+	public LoginServiceConnection() {
+	}
+
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    Log.d(TAG, "Launch the task");
+	    mTask = mTask.execute(mXmppFacade);
+	}
+	
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    Log.d(TAG, "Service disconnected.");
+	    mXmppFacade = null;
+	}
+    }
+
+    private class ClickListener implements OnClickListener {
+	
+	@Override
+	public void onClick(View v) {
+	    if (v == mCancelBt) {
+		if (! mTask.cancel(true)) {
+		    Log.d(TAG, "Can't interrupt the connection");
+		}
+	    }
+	}
+    }
+}
--- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java	Tue Nov 24 11:58:14 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java	Thu Nov 26 15:27:28 2009 +0100
@@ -41,9 +41,10 @@
 	if (mIsBinded)
 	    context.unbindService(mService);
 	setBinded(false);
+	// TODO ce code est commenté car il empeche de gerer un cancel sur une connexion
 	// start activity if unexpected disconnection
-	if (!intent.getBooleanExtra("normally", false))
-	    context.startActivity(new Intent(context, Login.class));
+//         if (!intent.getBooleanExtra("normally", false))
+//             context.startActivity(new Intent(context, Login.class));
 	CharSequence message = intent.getCharSequenceExtra("message");
 	Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
 	if (context instanceof Activity) {