Bug d'affichage fixé et autre feature implementées
authorPhilippe Lago <lago_p@epitech.net>
Wed, 15 Apr 2009 16:16:01 +0200
changeset 103 2320ab48e829
parent 102 e3e8bf449590
child 104 b31649abe731
Bug d'affichage fixé et autre feature implementées
res/layout/messagelist.xml
res/layout/sendim.xml
src/com/beem/project/beem/ui/SendIM.java
--- a/res/layout/messagelist.xml	Tue Apr 14 18:54:10 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-	android:id="@+id/messageview"
-	android:textSize="2mm"
-	android:singleLine="false"
-	android:layout_width="fill_parent"
-	android:layout_height="wrap_content" />
\ No newline at end of file
--- a/res/layout/sendim.xml	Tue Apr 14 18:54:10 2009 +0200
+++ b/res/layout/sendim.xml	Wed Apr 15 16:16:01 2009 +0200
@@ -25,13 +25,20 @@
 			android:layout_toRightOf="@id/sendimavatar"
         	android:hint="@string/SendIMLoginHint"/>
     </RelativeLayout>
-	
-	<ListView android:id="@android:id/list"
-        android:layout_width="fill_parent"
-        android:choiceMode="none" 
-        android:layout_height="wrap_content"
-        android:layout_weight="1"
-        android:transcriptMode="alwaysScroll"/>
+	<ScrollView
+		android:id="@+id/sendimscroll"
+		android:layout_width="fill_parent"
+		android:layout_height="fill_parent"
+		android:layout_weight="1">
+		
+		<TextView android:id="@+id/sendimlist"
+        	android:layout_width="fill_parent"
+        	android:layout_height="wrap_content"
+        	android:singleLine="false"/>
+        	<!--android:choiceMode="none"
+        	android:transcriptMode="alwaysScroll"-->
+        	
+    </ScrollView>
         
     <EditText android:id="@+id/userText"
         android:layout_width="fill_parent"
--- a/src/com/beem/project/beem/ui/SendIM.java	Tue Apr 14 18:54:10 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Apr 15 16:16:01 2009 +0200
@@ -2,12 +2,13 @@
 
 import java.util.ArrayList;
 
-import android.app.ListActivity;
+import android.app.Activity;
 import android.content.SharedPreferences;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.RemoteException;
+import android.text.method.ScrollingMovementMethod;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.Menu;
@@ -16,8 +17,8 @@
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnKeyListener;
-import android.widget.ArrayAdapter;
 import android.widget.EditText;
+import android.widget.ScrollView;
 import android.widget.TextView;
 
 import com.beem.project.beem.BeemApplication;
@@ -35,11 +36,11 @@
  *         after selecting a correspondant.
  */
 
-public class SendIM extends ListActivity implements OnClickListener,
+public class SendIM extends Activity implements OnClickListener,
 	OnKeyListener {
     private EditText mToSend;
     private ArrayList<String> mMessages = new ArrayList<String>();
-    private ArrayAdapter<String> mAdapter;
+    //private ArrayAdapter<String> mAdapter;
     private SendIMDialogSmiley mSmyDialog;
     private SharedPreferences mSet;
     private SharedPreferences mGlobalSettings;
@@ -52,7 +53,10 @@
     private IMessageListener mMessageListener;
     private IChat mChat;
     private Drawable mAvatar;
+    private TextView mText;
     private TextView mLogin;
+    private ScrollView mScrolling;
+    private Boolean mSpeak;
 
     /**
      * Constructor.
@@ -78,15 +82,17 @@
 	mSmyDialog = new SendIMDialogSmiley(this, mSet);
 	mGlobalSettings = getSharedPreferences(
 		getString(R.string.PreferenceFileName), MODE_PRIVATE);
-	mAdapter = new ArrayAdapter<String>(this, R.layout.messagelist,
+	/*mAdapter = new ArrayAdapter<String>(this, R.layout.messagelist,
 		mMessages);
-	setListAdapter(mAdapter);
+	setListAdapter(mAdapter);*/
 
 	mToSend.setOnClickListener(this);
 	mToSend.setOnKeyListener(this);
 	
 	mContact = getIntent().getParcelableExtra("contact");
 	setViewHeader();
+	mText = (TextView) findViewById(R.id.sendimlist);
+	mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
     }
     
     private void setViewHeader()
@@ -128,6 +134,8 @@
      * pendant la conversation
      */
     private void sendText() {
+	if (mSpeak == null)
+	    mSpeak = false;
 	String text = mToSend.getText().toString();
 	String from = mGlobalSettings.getString(
 		getString(R.string.PreferenceJID), "You");
@@ -140,7 +148,15 @@
 		// TODO Auto-generated catch block
 		e.printStackTrace();
 	    }
-	    mAdapter.add(from + getString(R.string.SendIMSays) + text);
+	    //mAdapter.add(from + getString(R.string.SendIMSays) + text);
+	    if (!mSpeak)
+		mText.append(from + getString(R.string.SendIMSays) + text + "\n");
+	    else
+		mText.append(text + "\n");
+	    mToSend.setText(null);
+	    mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	    mToSend.requestFocus();
+	    mSpeak = true;
 	}
     }
 
@@ -202,8 +218,26 @@
 	public void processMessage(IChat chat, Message msg)
 		throws RemoteException {
 	    Log.i("LOG", "processMessage");
-	    mAdapter.add(mContact.getJID() + " "
-		    + getString(R.string.SendIMSays) + msg.getBody());
+	    /*mAdapter.add(mContact.getJID() + " "
+		    + getString(R.string.SendIMSays) + msg.getBody());*/
+	    
+	    final Message m = msg;
+	    mHandler.post(new Runnable() {
+	    
+	        @Override
+	        public void run() {
+	            if (m.getBody() != null)
+	            {
+	        	if (!mSpeak)
+	        	    mText.append(m.getBody() + "\n");
+	        	else
+	        	    mText.append(mContact.getJID() + " "
+				    + getString(R.string.SendIMSays) + m.getBody() + "\n");
+	        	mSpeak = false;
+	        	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	            }
+	        }
+	    });
 	}
     }
 }