merge
authormarseille@KungFuh
Wed, 08 Apr 2009 12:07:49 +0200
changeset 91 d8c5c3191491
parent 90 c2b22b565ef9 (current diff)
parent 85 7d0e36aa1be5 (diff)
child 93 a4501bbd1549
merge
--- a/res/layout/messagelist.xml	Wed Apr 08 00:05:03 2009 +0200
+++ b/res/layout/messagelist.xml	Wed Apr 08 12:07:49 2009 +0200
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android" id="text1"
           android:textSize="2mm"
-          android:textColor="@color/black"
           android:singleLine="false"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"/>
\ No newline at end of file
--- a/res/layout/sendim.xml	Wed Apr 08 00:05:03 2009 +0200
+++ b/res/layout/sendim.xml	Wed Apr 08 12:07:49 2009 +0200
@@ -2,8 +2,7 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent" 
-    android:layout_height="fill_parent"
-    android:background="@color/blue_sky">
+    android:layout_height="fill_parent">
 
     <ListView android:id="@android:id/list"
         android:layout_width="fill_parent" 
--- a/res/values/strings.xml	Wed Apr 08 00:05:03 2009 +0200
+++ b/res/values/strings.xml	Wed Apr 08 12:07:49 2009 +0200
@@ -28,7 +28,7 @@
 	<string name="PreferenceProxyTypeSocks5">SOCKS5</string>
 
 	<!--  SendIM class -->
-	<string name="SendIMSays">says :\n</string>
+	<string name="SendIMSays"> says :\n</string>
 	<string name="SendIMHint">Tip text here</string>
 	<string name="SendIMState">Is : </string>
 	<string name="SendIMFrom">and is speaking from : </string>
--- a/src/com/beem/project/beem/ui/SendIM.java	Wed Apr 08 00:05:03 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Apr 08 12:07:49 2009 +0200
@@ -4,7 +4,10 @@
 
 import android.app.ListActivity;
 import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.RemoteException;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.Menu;
@@ -16,8 +19,15 @@
 import android.widget.ArrayAdapter;
 import android.widget.EditText;
 
+import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
+import com.beem.project.beem.service.Message;
+import com.beem.project.beem.service.aidl.IChat;
+import com.beem.project.beem.service.aidl.IChatManager;
+import com.beem.project.beem.service.aidl.IChatManagerListener;
+import com.beem.project.beem.service.aidl.IMessageListener;
+import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
  * @author barbu This activity class provide the view for instant messaging
@@ -31,7 +41,15 @@
     private ArrayAdapter<String> mAdapter;
     private SendIMDialogSmiley mSmyDialog;
     private SharedPreferences mSet;
+    private SharedPreferences mGlobalSettings;
+    private BeemApplication mBeemApplication;
+    private Handler mHandler;
+    private IXmppFacade mService = null;
     private Contact mContact;
+    private IChatManager mChatManager;
+    private IChatManagerListener mChatManagerListener;
+    private IMessageListener mMessageListener;
+    private IChat mChat;
 
     /**
      * Constructor.
@@ -46,11 +64,15 @@
     @Override
     public void onCreate(Bundle saveBundle) {
 	super.onCreate(saveBundle);
-
+	mHandler = new Handler();
+	mChatManagerListener = new OnChatListener();
+	mMessageListener = new OnMessageListener();
+	mBeemApplication = BeemApplication.getApplication(this);
 	setContentView(R.layout.sendim);
 	mToSend = (EditText) findViewById(R.id.userText);
 	mSet = getSharedPreferences("lol", MODE_PRIVATE);
 	mSmyDialog = new SendIMDialogSmiley(this, mSet);
+	mGlobalSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
 
 	mAdapter = new ArrayAdapter<String>(this, R.layout.messagelist,
 		mMessages);
@@ -65,7 +87,16 @@
     @Override
     public void onStart() {
 	super.onStart();
-
+	mBeemApplication.startBeemService();
+	mService = mBeemApplication.getXmppFacade();
+	try {
+	    mChatManager = mService.getChatManager();
+	    mChatManager.addChatCreationListener(mChatManagerListener);
+	    mChat = mChatManager.createChat(mContact, mMessageListener);
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
     }
 
     /**
@@ -82,19 +113,17 @@
      */
     private void sendText() {
 	String text = mToSend.getText().toString();
+	String from = mGlobalSettings.getString(getString(R.string.PreferenceJID), "You");
 	if (!text.equals("")) {
-	    /*
-	     * Prepare the message to be send
-	     */
-	    /* Message msg = new Message("barbu", Message.Type.chat); */
-	    /* msg.setBody(text); */
-	    /*
-	     * Rien a voir il faut changer le mContact.getJID() et remplacer
-	     * avec son pseudo cetait juste un test pour savoir qu'on recupere
-	     * bien le contact a qui envoyer les infos
-	     */
-	    mAdapter.add(mContact.getJID() + " "
-		    + getString(R.string.SendIMSays) + text);
+	    Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+	    msg.setBody(text);
+	    try {
+		mChat.sendMessage(msg);
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }
+	    mAdapter.add(from + getString(R.string.SendIMSays) + text);
 	    mToSend.setText(null);
 	}
     }
@@ -139,4 +168,27 @@
 		return false;
 	}
     }
+    
+    private class OnChatListener extends IChatManagerListener.Stub {
+
+	@Override
+	public void chatCreated(IChat chat, boolean locally)
+		throws RemoteException {
+	    Log.i("LOG", "chatCreated");
+	    
+	}
+	
+    }
+    
+    private class OnMessageListener extends IMessageListener.Stub {
+
+	@Override
+	public void processMessage(IChat chat, Message msg)
+		throws RemoteException {
+	    Log.i("LOG", "processMessage");
+	    mAdapter.add(mContact.getJID() + " "
+		    + getString(R.string.SendIMSays) + msg.getBody());
+	}
+	
+    }
 }