merge avec nikita et petit bug fixe
authorDa Risk <darisk972@gmail.com>
Tue, 21 Apr 2009 22:49:38 +0200
changeset 131 64cd99927c28
parent 130 eb0c7004090c (current diff)
parent 124 4eaf1efcadda (diff)
child 132 728adc0feb4e
child 133 190a55f30e11
merge avec nikita et petit bug fixe
AndroidManifest.xml
src/com/beem/project/beem/service/BeemChatManager.java
src/com/beem/project/beem/ui/ChangeStatus.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/SendIM.java
--- a/AndroidManifest.xml	Tue Apr 21 20:48:35 2009 +0200
+++ b/AndroidManifest.xml	Tue Apr 21 22:49:38 2009 +0200
@@ -7,11 +7,13 @@
 			<intent-filter>
 				<action android:name="android.intent.action.MAIN" />
 				<category android:name="android.intent.category.LAUNCHER" />
+				<category android:name="android.intent.category.ACCOUNT_CREATE" />
 			</intent-filter>
 		</activity>
 		<activity android:name=".ui.ContactListSettings" android:label="@string/app_name" />
 		<activity android:name=".ui.SendIM" android:label="@string/app_name" />
 		<activity android:name=".ui.ChangeStatus" android:label="@string/app_name" />
+		<activity android:name=".ui.AccountCreation" android:label="@string/app_name" />
 		<service android:name="BeemService" android:enabled="true"
 			android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
 			<intent-filter>
--- a/default.properties	Tue Apr 21 20:48:35 2009 +0200
+++ b/default.properties	Tue Apr 21 22:49:38 2009 +0200
@@ -7,8 +7,6 @@
 # "build.properties", and override values to adapt the script to your
 # project structure.
 
-# Project target.
-target=android-3
 # apk configurations. This property allows creation of APK files with limited
 # resources. For example, if your application contains many locales and
 # you wish to release multiple smaller apks instead of a large one, you can
@@ -20,3 +18,5 @@
 #     apk-config-european=en,fr,it,de,es
 #     apk-config-northamerica=en,es
 apk-configurations=
+# Project target.
+target=android-3
--- a/project.aidl	Tue Apr 21 20:48:35 2009 +0200
+++ b/project.aidl	Tue Apr 21 22:49:38 2009 +0200
@@ -4,5 +4,5 @@
 
 parcelable com.beem.project.beem.BeemException
 parcelable com.beem.project.beem.service.Message
+parcelable com.beem.project.beem.service.PresenceAdapter
 parcelable com.beem.project.beem.service.Contact
-parcelable com.beem.project.beem.service.PresenceAdapter
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/accountcreation.xml	Tue Apr 21 22:49:38 2009 +0200
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="fill_parent"
+        >
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Login:"
+                android:minWidth="70dp"
+                />
+                
+        <EditText android:id="@+id/login"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:capitalize="none"
+                  android:minWidth="150dp"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Email:"
+                android:minWidth="70dp"
+                />
+        <EditText android:id="@+id/email"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="250dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Password:"
+                android:minWidth="70dp"
+                />
+        <EditText android:id="@+id/password"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:password="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="250dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Repeat:"
+                android:minWidth="70dp"
+                />
+        <EditText android:id="@+id/password2"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:password="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="250dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+
+    <Button android:id="@+id/ok"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:text="OK">
+        <requestFocus/>
+    </Button>
+</LinearLayout>
\ No newline at end of file
--- a/res/menu/contactlistmenu.xml	Tue Apr 21 20:48:35 2009 +0200
+++ b/res/menu/contactlistmenu.xml	Tue Apr 21 22:49:38 2009 +0200
@@ -1,4 +1,5 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 	<item android:title="Creer ou Editer un compte" android:id="@+id/account_edit" android:icon="@drawable/xmpp"/>
 	<item android:title="L'equipe Beem" android:id="@+id/account_about"/>
+	<item android:title="TEMP/createAccount" android:id="@+id/account_create"/>
 </menu>
--- a/src/com/beem/project/beem/BeemService.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Apr 21 22:49:38 2009 +0200
@@ -72,6 +72,7 @@
      */
     @Override
     public void onCreate() {
+	
 	super.onCreate();
 	mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
 	mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), "");
@@ -182,6 +183,7 @@
 
 		}
 
+		
 		@Override
 		public void onConnect() throws RemoteException {
 		    // TODO Auto-generated method stub
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Tue Apr 21 22:49:38 2009 +0200
@@ -141,9 +141,10 @@
 	public void chatCreated(Chat chat, boolean locally) {
 	    IChat newchat = getChat(chat);
 	    if (!locally) {
-		chat.addMessageListener(mChatListener);
+	//	chat.addMessageListener(mChatListener);
 		notifyNewChat(newchat);
 	    }
+	    chat.addMessageListener(mChatListener);
 	    final int n = mRemoteChatCreationListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
@@ -188,7 +189,6 @@
 		for (int i = 0; i < n; i++) {
 		    IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
 		    listener.processMessage(newchat, new com.beem.project.beem.service.Message(message));
-
 		}
 		mRemoteMessageListeners.finishBroadcast();
 	    } catch (RemoteException e) {
@@ -201,6 +201,7 @@
 	@Override
 	public void stateChanged(Chat chat, ChatState state) {
 	    try {
+		Log.d(TAG, "state changed");
 		mChats.get(chat.getParticipant()).setState(state.name());
 	    } catch (RemoteException e) {
 		e.printStackTrace();
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Apr 21 22:49:38 2009 +0200
@@ -42,13 +42,16 @@
      * @param roster the roster to adapt
      */
     public RosterAdapter(final Roster roster) {
-	Log.d(TAG, "CTOR");
 	mAdaptee = roster;
 	roster.addRosterListener(mRosterListener);
 	for (RosterEntry entry : roster.getEntries()) {
 	    String user = StringUtils.parseBareAddress(entry.getUser());
-	    if (!mContacts.containsKey(user))
-		mContacts.put(user, new Contact(user));
+	    if (!mContacts.containsKey(user)) {
+		Contact c = new Contact(user);
+		c.setStatus(roster.getPresence(user));
+		mContacts.put(user, c);
+		
+	    }
 	}
     }
 
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 21 22:49:38 2009 +0200
@@ -10,6 +10,7 @@
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.XMPPException;
 import org.jivesoftware.smack.packet.XMPPError;
+import org.jivesoftware.smackx.ChatStateManager;
 import org.jivesoftware.smackx.ServiceDiscoveryManager;
 import org.jivesoftware.smackx.jingle.JingleManager;
 import android.os.RemoteCallbackList;
@@ -82,9 +83,11 @@
 	    mAdaptee.connect();
 	    mAdaptee.addConnectionListener(mConListener);
 	    mAdaptee.login(mLogin, mPassword, "BEEM");
+	    
 	    mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
 	    // TODO find why this cause a null pointer exception
-	    // this.initFeatures(); // pour declarer les features xmpp qu'on supporte
+	    this.initFeatures(); // pour declarer les features xmpp qu'on supporte
+	    ChatStateManager.getInstance(mAdaptee);
 	    mLastException = null;
 	    triggerAsynchronousConnectEvent();
 	    return true;
@@ -177,6 +180,8 @@
     private void initFeatures() {
 	JingleManager.setJingleServiceEnabled();
 	ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	if (sdm == null)
+	    sdm = new ServiceDiscoveryManager(mAdaptee);
 	sdm.addFeature("http://jabber.org/protocol/disco#info");
 	// sdm.addFeature("http://jabber.org/protocol/nick");
 
--- a/src/com/beem/project/beem/service/aidl/IMessageListener.aidl	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IMessageListener.aidl	Tue Apr 21 22:49:38 2009 +0200
@@ -5,5 +5,5 @@
 
 interface IMessageListener {
 
-	void processMessage(in IChat chat, in Message msg); 
+	void processMessage(in IChat chat, in Message msg);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/AccountCreation.java	Tue Apr 21 22:49:38 2009 +0200
@@ -0,0 +1,111 @@
+/**
+ * 
+ */
+package com.beem.project.beem.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jivesoftware.smack.AccountManager;
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+
+import com.beem.project.beem.R;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+/**
+ * @author nikita
+ *
+ */
+public class AccountCreation extends Activity {    
+
+    protected static final String TAG = "AccountCreation";
+    private SharedPreferences mSettings;
+    Map<String, String> mAttributes = new HashMap<String, String>();
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.accountcreation);
+	Button ok = (Button) findViewById(R.id.ok);
+	mSettings = getSharedPreferences(
+		getString(R.string.PreferenceFileName), MODE_PRIVATE);
+	//mAccountManager = new AccountManager();
+	ok.setOnClickListener(mOkListener);
+    }
+
+    private OnClickListener mOkListener = new OnClickListener() {
+	
+	@Override
+	public void onClick(View v) {
+	    boolean valid = true;
+	    if (getWidgetText(R.id.login).length() == 0) {
+		Log.d(TAG, "login pas ok");
+		valid = false;
+	    } else {
+		mAttributes.put("login", getWidgetText(R.id.login));
+		mAttributes.put("name", getWidgetText(R.id.login));
+	    }
+	    if (getWidgetText(R.id.password).length() == 0 || !getWidgetText(R.id.password).contains(getWidgetText(R.id.password2))) {
+		valid = false;
+		
+	    } else {
+		mAttributes.put("password", getWidgetText(R.id.password));
+	    }
+	    if (getWidgetText(R.id.email).length() == 0) {
+		valid = false;
+	    } else {
+		mAttributes.put("email", getWidgetText(R.id.email));
+	    }
+	    
+	    if (valid) {
+		setResult(RESULT_OK);
+		try {
+		    createAccount();
+		    Toast.makeText(AccountCreation.this, "Account created",
+	                    Toast.LENGTH_SHORT).show();
+		    finish();
+		} catch (XMPPException e) {
+		    Log.e(TAG, "Account creation failed", e);
+		    Toast.makeText(AccountCreation.this, e.getMessage(),
+	                    Toast.LENGTH_SHORT).show();
+		    e.printStackTrace();
+		}
+	    } else {
+		Toast.makeText(AccountCreation.this, "Form error",
+                    Toast.LENGTH_SHORT).show();
+		setResult(RESULT_CANCELED);
+	    }
+	    
+	}
+    };
+
+    protected void createAccount() throws XMPPException {
+	String mHost = mSettings.getString(getString(R.string.PreferenceHostKey), "");
+	XMPPConnection xmmpCo = new XMPPConnection(new ConnectionConfiguration(mHost));
+	xmmpCo.connect();
+	AccountManager accM = new AccountManager(xmmpCo);
+	accM.createAccount(mAttributes.get("login"), mAttributes.get("password"), mAttributes);
+	xmmpCo.disconnect();
+	SharedPreferences.Editor editor = mSettings.edit();
+	
+	editor.putString(getString(R.string.PreferenceLoginKey), mAttributes.get("login"));
+	editor.putString(getString(R.string.PreferencePasswordKey), mAttributes.get("password"));
+	editor.commit();	
+    }
+    
+    private String getWidgetText(int id) {
+	EditText widget = (EditText) this.findViewById(id);
+	return widget.getText().toString();
+    }
+}
\ No newline at end of file
--- a/src/com/beem/project/beem/ui/ChangeStatus.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java	Tue Apr 21 22:49:38 2009 +0200
@@ -77,7 +77,7 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        mBeemApplication.unbindBeemService();
+//        mBeemApplication.unbindBeemService();
     }
 
     private OnClickListener mOnClickOk = new OnClickListener() {
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 21 22:49:38 2009 +0200
@@ -37,7 +37,8 @@
 public class ContactList extends ExpandableListActivity {
 
     private static final String TAG = "CONTACTLIST_ACT";
-    private static final int PREFERENCECHANGED = 0; 
+    private static final int PREFERENCECHANGED = 0;
+    private static final int CREATEACCOUNT = 1;
     private IXmppFacade mService = null;
     private SharedPreferences mSettings;
     private Handler mHandler;
@@ -78,7 +79,7 @@
     protected void onDestroy() {
         // TODO Auto-generated method stub
         super.onDestroy();
-        mBeemApplication.unbindBeemService();
+ //       mBeemApplication.unbindBeemService();
     }
 
     @Override
@@ -153,6 +154,9 @@
 		return true;
 	    case R.id.account_about:
 		return true;
+	    case R.id.account_create:
+		startActivity(new Intent(this, AccountCreation.class));
+		return true;
 	    default:
 		return false;
 	}
--- a/src/com/beem/project/beem/ui/ContactListSettings.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactListSettings.java	Tue Apr 21 22:49:38 2009 +0200
@@ -4,7 +4,6 @@
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.view.View;
-import android.util.Log;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.EditText;
--- a/src/com/beem/project/beem/ui/SendIM.java	Tue Apr 21 20:48:35 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Tue Apr 21 22:49:38 2009 +0200
@@ -105,15 +105,15 @@
 	    mContact = getIntent().getParcelableExtra("contact");
 	setViewHeader();
 	mService = mBeemApplication.getXmppFacade();
-	
+
     }
-    
+
     @Override
     protected void onResume() {
-        super.onResume();
-        mBeemApplication.startBeemService();
-        mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable(){
-	
+	super.onResume();
+	mBeemApplication.startBeemService();
+	mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() {
+
 	    @Override
 	    public void run() {
 		mService = mBeemApplication.getXmppFacade();
@@ -132,20 +132,22 @@
 		}
 	    }
 	});
-        
+
     }
 
     @Override
     protected void onDestroy() {
 	super.onDestroy();
-	try {
-	    mChatManager.removeChatCreationListener(mChatManagerListener);
-	    mChatManager.destroyChat(mChat);
-	} catch (RemoteException e) {
-	    // TODO Auto-generated catch block
-	    e.printStackTrace();
+	if (mChatManager != null) {
+	    try {
+		mChatManager.removeChatCreationListener(mChatManagerListener);
+		mChatManager.destroyChat(mChat);
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }
 	}
-	mBeemApplication.unbindBeemService();
+//	mBeemApplication.unbindBeemService();
     }
 
     /**