Debut du nouvel activite de Login.
authorDa Risk <darisk972@gmail.com>
Thu, 26 Nov 2009 23:11:06 +0100
changeset 545 0de3d7f3fa81
parent 544 24276024c388
child 546 97ae7bcc219a
Debut du nouvel activite de Login. La connexion auto se fait il manque juste la gestion du menu et l'affichage du message d'erreur. Pour LoginAnim : anim perso avec une belle image ou progress bar ronde par defaut ?
.hgignore
AndroidManifest.xml
res/layout/login_anim.xml
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/service/aidl/IXmppConnection.aidl
src/com/beem/project/beem/ui/Login2.java
src/com/beem/project/beem/ui/LoginAnim.java
--- a/.hgignore	Thu Nov 26 15:27:28 2009 +0100
+++ b/.hgignore	Thu Nov 26 23:11:06 2009 +0100
@@ -5,3 +5,6 @@
 src/com/beem/project/beem/service/aidl/*.java
 gen/*
 local.properties
+**~
+**/.*.sw?
+
--- a/AndroidManifest.xml	Thu Nov 26 15:27:28 2009 +0100
+++ b/AndroidManifest.xml	Thu Nov 26 23:11:06 2009 +0100
@@ -17,17 +17,26 @@
 			</intent-filter>
 		</activity>
 		
-		<activity android:name=".ui.LoginAnim" android:label="ANIM"
+		<activity android:name=".ui.Login2" android:label="NEWLOGIN"
 			android:launchMode="singleTask">
 			<intent-filter>
 				<action android:name="android.intent.action.MAIN" />
 				<category android:name="android.intent.category.LAUNCHER" />
+			    </intent-filter>
+		</activity>
+
+                 <activity android:name=".ui.LoginAnim" android:label="ANIM"
+			>
+			<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
--- a/res/layout/login_anim.xml	Thu Nov 26 15:27:28 2009 +0100
+++ b/res/layout/login_anim.xml	Thu Nov 26 23:11:06 2009 +0100
@@ -7,6 +7,10 @@
     <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 -->
+    <ProgressBar android:id="@+id/loginanim_progressbar"
+	android:layout_width= "fill_parent" android:layout_height="fill_parent" android:layout_weight="1" />
+    <TextView android:id="@+id/loginanim_error_label" 
+	android:layout_height="wrap_content" android:layout_width="fill_parent" />
     <Button android:id= "@+id/loginanim_cancel_button"
 	android:layout_height="wrap_content" android:layout_width="fill_parent"
 	android:layout_gravity="bottom"
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Nov 26 15:27:28 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Nov 26 23:11:06 2009 +0100
@@ -10,6 +10,7 @@
 import org.jivesoftware.smack.filter.PacketFilter;
 import org.jivesoftware.smack.packet.Packet;
 import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.packet.StreamError;
 import org.jivesoftware.smackx.ChatStateManager;
 import org.jivesoftware.smackx.ServiceDiscoveryManager;
 import org.jivesoftware.smackx.jingle.JingleManager;
@@ -51,6 +52,7 @@
     private final String mLogin;
     private final String mPassword;
     private String mResource;
+    private String mErrorMsg;
     private RosterAdapter mRoster;
     private int mPreviousPriority;
     private PrivacyListManagerAdapter mPrivacyListManager;
@@ -158,12 +160,22 @@
 	    return true;
 	} catch (XMPPException e) {
 	    Log.d(TAG, "Error while connecting", e);
-	    if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
-		mConListener.connectionFailed(e.getXMPPError().getMessage());
-	    else if (e.getMessage() != null)
-		mConListener.connectionFailed(e.getMessage());
+	    if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null) {
+		mErrorMsg = e.getXMPPError().getMessage();
+		Log.d(TAG, "XMPP Error "+ e.getXMPPError().getCode() + "message :" +e.getXMPPError().getMessage());
+	    }
+	    else if (e.getStreamError() != null ) {
+		mErrorMsg = e.getStreamError().toString();
+		Log.d(TAG, "Stream Error "+ e.getStreamError().getCode() + "message :" +e.getStreamError());
+	    }
+	    else if (e.getMessage() != null) {
+		// SASL !!
+		mErrorMsg = e.getMessage();
+		Log.d(TAG, "Error " + e.getMessage());
+	    }
 	    else
-		mConListener.connectionFailed("Error On Connection");
+		mErrorMsg = "Error On Connection";
+	    mConListener.connectionFailed(mErrorMsg);
 	} catch (IllegalStateException e) {
 	    mConListener.connectionFailed(e.getMessage());
 	}
@@ -333,6 +345,14 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getErrorMessage() {
+	return mErrorMsg;
+    }
+
+    /**
      * Listener for XMPP connection events. It will calls the remote listeners for connection events.
      * @author darisk
      */
--- a/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl	Thu Nov 26 15:27:28 2009 +0100
+++ b/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl	Thu Nov 26 23:11:06 2009 +0100
@@ -27,4 +27,6 @@
     void changeStatus(in int status, in String msg);
 
     IPrivacyListManager getPrivacyListManager();
+
+    String getErrorMessage();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/Login2.java	Thu Nov 26 23:11:06 2009 +0100
@@ -0,0 +1,53 @@
+package com.beem.project.beem.ui;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import com.beem.project.beem.R;
+
+/**
+ * This class is the main Activity for the Beem project.
+ * @author Da Risk <darisk972@gmai.com>
+ */
+public class Login2 extends Activity {
+
+    private static final String TAG = "Login2";
+
+    /**
+     * Constructor.
+     */
+    public Login2() {
+    }
+
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.login);
+    }
+
+    @Override
+    protected void onStart() {
+	super.onStart();
+	Intent i = new Intent (this, LoginAnim.class);
+	startActivityForResult(i, 42);
+    }
+
+    @Override
+    protected void  onActivityResult  (int requestCode, int resultCode, Intent data) {
+	if (requestCode == 42) {
+	    if (resultCode == Activity.RESULT_OK) {
+		Log.d(TAG, "Connected !!! Launch contact list");
+		Intent i = new Intent(this, ContactList.class);
+		startActivity(i);
+		finish();
+	    } else if (resultCode == Activity.RESULT_CANCELED) { // or error ? 
+		// Set an intent with data in like the error msg
+		Log.d(TAG, "NOT Connected !!!");
+		
+	    }
+	}
+    }
+
+}
--- a/src/com/beem/project/beem/ui/LoginAnim.java	Thu Nov 26 15:27:28 2009 +0100
+++ b/src/com/beem/project/beem/ui/LoginAnim.java	Thu Nov 26 23:11:06 2009 +0100
@@ -13,6 +13,7 @@
 import android.widget.Button;
 import android.view.animation.Animation;
 import android.widget.ImageView;
+import android.widget.TextView;
 import android.view.animation.AnimationUtils;
 import com.beem.project.beem.R;
 import android.util.Log;
@@ -34,10 +35,12 @@
     }
     private ImageView mLogo;
     private Animation mRotateAnim;
+    private TextView mErrorLabel;
     private final ServiceConnection mServConn = new LoginServiceConnection();
     private IXmppFacade mXmppFacade;
     private AsyncTask<IXmppFacade, Void, Boolean>mTask;
     private Button mCancelBt;
+    private ProgressBar mProgressBar;
 
     /**
      * Constructor.
@@ -53,9 +56,12 @@
 	super.onCreate(savedInstanceState);
 	setContentView(R.layout.login_anim);
 	mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim);
+	mErrorLabel = (TextView) findViewById(R.id.loginanim_error_label);
 	mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale);
 	mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button);
 	mCancelBt.setOnClickListener( new ClickListener());
+	mProgressBar = (ProgressBar) findViewById(R.id.loginanim_progressbar);
+	mProgressBar.setIndeterminate(true);
     }
 
     /**
@@ -118,10 +124,25 @@
 	@Override
 	protected void onPostExecute(Boolean result) {
 	    if (result == null || !result) { // Task cancelled on exception
+		String msg;
 		Log.d(TAG, "Exception or cancelation of the connection");
+		try {
+		    if (!result)
+			msg = mConnection.getErrorMessage();
+		    else
+			msg = "Exception during connection";
+		} catch (RemoteException e) {
+		    Log.d(TAG, "Exception or cancelation of the connection");
+		    msg = "Remote Exception";
+		}
+		//TODO create an intent and store the error msg in. Return this intent on result.
+		LoginAnim.this.mErrorLabel.setText("Error !!!\n" + msg);
+		LoginAnim.this.setResult(Activity.RESULT_CANCELED);
+		LoginAnim.this.finish();
 	    } else {
 		LoginAnim.this.startService(LoginAnim.SERVICE_INTENT);
-		LoginAnim.this.startActivity(new Intent(LoginAnim.this, ContactList.class));
+		//LoginAnim.this.startActivity(new Intent(LoginAnim.this, ContactList.class));
+		LoginAnim.this.setResult(Activity.RESULT_OK);
 		LoginAnim.this.finish();
 	    }
 	}
@@ -137,7 +158,6 @@
 		Log.d(TAG, "Remote exception", e);
 	    }
 	    LoginAnim.this.stopService(LoginAnim.SERVICE_INTENT);
-	    LoginAnim.this.finish();
 	}
 
     }
@@ -151,7 +171,8 @@
 	public void onServiceConnected(ComponentName name, IBinder service) {
 	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
 	    Log.d(TAG, "Launch the task");
-	    mTask = mTask.execute(mXmppFacade);
+	    if (mTask.getStatus() == AsyncTask.Status.PENDING)
+		mTask = mTask.execute(mXmppFacade);
 	}
 	
 	@Override
@@ -169,6 +190,8 @@
 		if (! mTask.cancel(true)) {
 		    Log.d(TAG, "Can't interrupt the connection");
 		}
+		setResult(Activity.RESULT_CANCELED);
+		finish();
 	    }
 	}
     }