--- 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);
+ }
+ }
+ });
}
}
}