display chat history as a scrolling list of TextView objects rather

than in a single TextView so different styles can be applied based on
whether text is from local or remote device.  For now text is just
grey if local.
This commit is contained in:
Andy2 2011-02-16 18:53:47 -08:00
parent 736860685b
commit fec402cf50
4 changed files with 63 additions and 23 deletions

View file

@ -6,30 +6,39 @@
android:layout_height="fill_parent"
>
<TextView android:id="@+id/chat_history"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText android:id="@+id/chat_edit"
android:layout_width="wrap_content"
<!-- history is kept in a scrolling list of textview elems so
different style can be applied based on whether they're local or
remote. Inserted at runtime.... -->
<ScrollView android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<LinearLayout android:id="@+id/chat_history"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="1"
/>
</ScrollView>
<Button android:id="@+id/send_button"
android:layout_width="wrap_content"
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/chat_send"
android:layout_weight="0"
/>
>
</LinearLayout>
<EditText android:id="@+id/chat_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="1"
/>
<Button android:id="@+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chat_send"
android:layout_weight="0"
/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF7F7F7F"
/>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

View file

@ -26,7 +26,9 @@ import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
public class ChatActivity extends XWActivity implements View.OnClickListener {
@ -46,8 +48,19 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
}
String history = DBUtils.getChatHistory( this, m_path );
TextView textView = (TextView)findViewById( R.id.chat_history );
textView.setText( history );
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
LayoutInflater factory = LayoutInflater.from( this );
String local = getString( R.string.chat_local_id );
for ( String str : parseHistory( history ) ) {
TextView view =
(TextView)factory.inflate( str.startsWith(local)
? R.layout.chat_history_local
: R.layout.chat_history_remote,
null );
view.setText( str );
layout.addView( view );
}
((Button)findViewById( R.id.send_button )).setOnClickListener( this );
}
@ -69,4 +82,9 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
finish();
}
private String[] parseHistory( String history )
{
return history.split( "\n" );
}
}