package com.beem.project.beem.ui;

import java.util.ArrayList;

import org.jivesoftware.smack.packet.Message;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.beem.project.beem.R;

public class SendIM extends Activity {
	private EditText		mToSend;
	private ListView		mList;
	private ArrayList<String>	mMessages = new ArrayList<String>();
	
	@Override
    public void onCreate(Bundle saveBundle) {
        super.onCreate(saveBundle);
        setContentView(R.layout.sendim);
        mToSend = (EditText) findViewById(R.id.sendText);
        mList = (ListView) findViewById(R.id.listMessages);
        
        Button send = (Button) this.findViewById(R.id.send);
        send.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String text = mToSend.getText().toString();
                /*
                 * Prepare the message to send 
                 * */
                Message msg = new Message("barbu", Message.Type.chat);
                msg.setBody(text);
                mMessages.add(text);
                setListAdapter();
            }
        });
	}
	
	private void setListAdapter() {
	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.messagelist, mMessages);
	    mList.setAdapter(adapter);
	}
}
