Compact Chat window support + options in settings
author"Vincent Veronis"
Mon, 27 Dec 2010 01:20:24 +0100
changeset 836 ac719bcb0f25
parent 824 27a5b676b9f3
child 837 2db1305b4279
Compact Chat window support + options in settings
default.properties
res/layout/chat_compact.xml
res/layout/chat_msg_row_compact.xml
res/layout/preferences.xml
res/values-fr/strings.xml
res/values/strings.xml
src/com/beem/project/beem/ui/Chat.java
--- a/default.properties	Fri Dec 10 11:18:45 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-# 
-# This file must be checked in Version Control Systems.
-# 
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=android-7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/chat_compact.xml	Mon Dec 27 01:20:24 2010 +0100
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	android:layout_width="fill_parent" android:layout_height="fill_parent"
+	android:orientation="vertical">
+	<View android:layout_width="fill_parent" android:layout_height="2dp"
+		android:fadingEdge="horizontal" android:background="#222222" />
+	<ListView android:id="@+id/chat_messages"
+		android:layout_width="fill_parent" android:layout_height="0dip"
+		android:layout_weight="1" android:transcriptMode="normal"
+		android:stackFromBottom="true"
+		android:fadingEdge="none" android:padding="4px"
+		android:fastScrollEnabled="true" android:smoothScrollbar="false"
+		android:focusable="true"/>
+	<LinearLayout android:layout_width="fill_parent"
+		android:layout_height="wrap_content" android:orientation="horizontal"
+		android:background="#222222" android:padding="8px">
+		<EditText android:id="@+id/chat_input" android:layout_width="0dip"
+			android:layout_height="fill_parent" android:layout_weight="1"
+			android:maxLines="5"
+			android:inputType="textShortMessage|textAutoCorrect|textMultiLine"
+			android:imeOptions="actionSend" android:cursorVisible="true"
+			android:hint="@string/chat_input_default_value" />
+		<Button android:id="@+id/chat_send_message"
+			android:layout_width="wrap_content" android:layout_height="fill_parent"
+			android:text="@string/chat_send_message" />
+	</LinearLayout>
+</LinearLayout>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/chat_msg_row_compact.xml	Mon Dec 27 01:20:24 2010 +0100
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	android:orientation="vertical" android:layout_width="fill_parent"
+	android:layout_height="wrap_content">
+	<TextView android:id="@+id/chatmessagedate"
+		android:layout_width="wrap_content" android:layout_height="wrap_content"
+		android:autoLink="none" android:layout_marginRight="4dp" />
+	<TextView android:id="@+id/chatmessagename"
+		android:layout_width="wrap_content" android:layout_height="wrap_content"
+		android:textSize="14sp" android:textColor="#FFFFFF" android:textStyle="bold"
+		android:layout_toRightOf="@id/chatmessagedate" android:layout_marginRight="4dp" />
+	<TextView android:id="@+id/chatmessagetext"
+		android:layout_width="wrap_content" android:layout_height="wrap_content"
+		android:layout_toRightOf="@id/chatmessagename" android:autoLink="all" />
+</RelativeLayout>
+
--- a/res/layout/preferences.xml	Fri Dec 10 11:18:45 2010 +0100
+++ b/res/layout/preferences.xml	Mon Dec 27 01:20:24 2010 +0100
@@ -23,6 +23,9 @@
 				android:singleLine="true" android:summary="@string/away_message_sum"
 				android:title="@string/away_message_title" android:key="settings_away_message"
 				android:hint="@string/away_message_hint" />
+			<CheckBoxPreference android:title="@string/settings_chat_compact"
+				android:defaultValue="false" android:summary="@string/settings_chat_compact_sum"
+				android:key="settings_chat_compact_key" />
 		</PreferenceScreen>
 		<PreferenceScreen android:title="@string/notification_preferences">
 			<CheckBoxPreference android:title="@string/notification_enable_vibrate_title"
--- a/res/values-fr/strings.xml	Fri Dec 10 11:18:45 2010 +0100
+++ b/res/values-fr/strings.xml	Mon Dec 27 01:20:24 2010 +0100
@@ -117,6 +117,8 @@
 	<string name="notification_enable_vibrate_sum">Activer le vibreur pour les messages entrants</string>
 	<string name="notification_snd_title">Sonnerie des messages</string>
 	<string name="notification_snd_sum">Configurer la sonnerie des messages entrants</string>
+	<string name="settings_chat_compact">Chat compact</string>
+	<string name="settings_chat_compact_sum">Activer la fenetre Chat compact</string>
 	
 	<!-- Subscription class -->
 	<string name="SubscriptAccept">Inscription acceptée</string>
--- a/res/values/strings.xml	Fri Dec 10 11:18:45 2010 +0100
+++ b/res/values/strings.xml	Mon Dec 27 01:20:24 2010 +0100
@@ -117,7 +117,8 @@
 	<string name="notification_enable_vibrate_sum">Enable vibrate on incoming messages</string>
 	<string name="notification_snd_title">Message ringtone</string>
 	<string name="notification_snd_sum">Set your incoming message ringtone</string>
-
+	<string name="settings_chat_compact">Chat compact</string>
+	<string name="settings_chat_compact_sum">Set the chat windows compact</string>
 	
 	<!-- Subscription class -->
 	<string name="SubscriptAccept">Subscription accepted</string>
--- a/src/com/beem/project/beem/ui/Chat.java	Fri Dec 10 11:18:45 2010 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java	Mon Dec 27 01:20:24 2010 +0100
@@ -50,7 +50,9 @@
 import java.util.List;
 import java.util.Map;
 
+import org.jivesoftware.smack.packet.Presence.Mode;
 import org.jivesoftware.smack.util.StringUtils;
+import org.w3c.dom.Entity;
 
 import android.app.Activity;
 import android.app.Dialog;
@@ -58,6 +60,8 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Color;
@@ -65,6 +69,9 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.preference.PreferenceManager;
+import android.text.Html;
+import android.text.TextUtils;
 import android.text.util.Linkify;
 import android.util.Log;
 import android.view.KeyEvent;
@@ -96,6 +103,7 @@
 import com.beem.project.beem.service.aidl.IXmppFacade;
 import com.beem.project.beem.ui.dialogs.builders.ChatList;
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
+import com.beem.project.beem.utils.PresenceType;
 import com.beem.project.beem.utils.Status;
 
 /**
@@ -136,6 +144,7 @@
     private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
     private IXmppFacade mXmppFacade;
     private boolean mBinded;
+    private boolean mCompact;
 
     /**
      * Constructor.
@@ -150,14 +159,19 @@
     @Override
     protected void onCreate(Bundle savedBundle) {
 	super.onCreate(savedBundle);
-	setContentView(R.layout.chat);
 	this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-
+	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+	mCompact = settings.getBoolean("settings_chat_compact_key", false);
 	// UI
-	mContactNameTextView = (TextView) findViewById(R.id.chat_contact_name);
-	mContactStatusMsgTextView = (TextView) findViewById(R.id.chat_contact_status_msg);
-	mContactChatState = (TextView) findViewById(R.id.chat_contact_chat_state);
-	mContactStatusIcon = (ImageView) findViewById(R.id.chat_contact_status_icon);
+	if (!mCompact) {
+	    setContentView(R.layout.chat);
+	    mContactNameTextView = (TextView) findViewById(R.id.chat_contact_name);
+	    mContactStatusMsgTextView = (TextView) findViewById(R.id.chat_contact_status_msg);
+	    mContactChatState = (TextView) findViewById(R.id.chat_contact_chat_state);
+	    mContactStatusIcon = (ImageView) findViewById(R.id.chat_contact_status_icon);
+	} else {
+	    setContentView(R.layout.chat_compact);
+	}
 	mMessagesListView = (ListView) findViewById(R.id.chat_messages);
 	mMessagesListView.setAdapter(mMessagesListAdapter);
 	mInputField = (EditText) findViewById(R.id.chat_input);
@@ -532,7 +546,8 @@
 		    } else if ("paused".equals(state)) {
 			text = Chat.this.getString(R.string.chat_state_active);
 		    }
-		    mContactChatState.setText(text);
+		    if (!mCompact)
+			mContactChatState.setText(text);
 		}
 	    });
 
@@ -548,13 +563,17 @@
 	String res = mContact.getSelectedRes();
 	if (!"".equals(res))
 	    name += "(" + res + ")";
-	if (!(mContactNameTextView.getText().toString().equals(name)))
-	    mContactNameTextView.setText(name);
-
-	// Check for a contact status message update
-	if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) {
-	    mContactStatusMsgTextView.setText(mContact.getMsgState());
-	    Linkify.addLinks(mContactStatusMsgTextView, Linkify.WEB_URLS);
+	if (!mCompact) {
+	    if (!(mContactNameTextView.getText().toString().equals(name)))
+		mContactNameTextView.setText(name);
+	    //Check for a contact status message update
+	    if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) {
+		mContactStatusMsgTextView.setText(mContact.getMsgState());
+		Linkify.addLinks(mContactStatusMsgTextView, Linkify.WEB_URLS);
+	    }
+	} else {
+	    Mode m = Status.getPresenceModeFromStatus(mContact.getStatus());
+	    setTitle(getString(R.string.chat_name) + " " + mContact.getName() + " (" + m.name() + ")");
 	}
     }
 
@@ -562,7 +581,8 @@
      * Update the contact status icon.
      */
     private void updateContactStatusIcon() {
-	mContactStatusIcon.setImageLevel(mContact.getStatus());
+	if (!mCompact)
+	    mContactStatusIcon.setImageLevel(mContact.getStatus());
     }
 
     /**
@@ -634,26 +654,35 @@
 	    View sv;
 	    if (convertView == null) {
 		LayoutInflater inflater = Chat.this.getLayoutInflater();
-		sv = inflater.inflate(R.layout.chat_msg_row, null);
+		if (!mCompact)
+		    sv = inflater.inflate(R.layout.chat_msg_row, null);
+		else 
+		    sv = inflater.inflate(R.layout.chat_msg_row_compact, null);
 	    } else {
 		sv = convertView;
 	    }
+	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
 	    MessageText msg = mListMessages.get(position);
-	    TextView msgName = (TextView) sv.findViewById(R.id.chatmessagename);
-	    msgName.setText(msg.getName());
-	    msgName.setTextColor(Color.WHITE);
-	    msgName.setError(null);
-	    TextView msgText = (TextView) sv.findViewById(R.id.chatmessagetext);
-	    msgText.setText(msg.getMessage());
-	    TextView msgDate = (TextView) sv.findViewById(R.id.chatmessagedate);
-	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
-	    String date = df.format(msg.getTimestamp());
-	    msgDate.setText(date);
-	    if (msg.isError()) {
-		String err = getString(R.string.chat_error);
-		msgName.setText(err);
-		msgName.setTextColor(Color.RED);
-		msgName.setError(err);
+	    if (!mCompact) {
+		TextView msgName = (TextView) sv.findViewById(R.id.chatmessagename);
+		msgName.setText(msg.getName());
+		msgName.setTextColor(Color.WHITE);
+		msgName.setError(null);
+		TextView msgText = (TextView) sv.findViewById(R.id.chatmessagetext);
+		msgText.setText(msg.getMessage());
+		TextView msgDate = (TextView) sv.findViewById(R.id.chatmessagedate);
+		String date = df.format(msg.getTimestamp());
+		msgDate.setText(date);
+		if (msg.isError()) {
+		    String err = getString(R.string.chat_error);
+		    msgName.setText(err);
+		    msgName.setTextColor(Color.RED);
+		    msgName.setError(err);
+		}
+	    } else {
+		String str = "(" + df.format(msg.getTimestamp()) + ") " + msg.getName() + " : " + msg.getMessage();
+		TextView msgText = (TextView) sv.findViewById(R.id.chatmessagetext);
+		msgText.setText(str);
 	    }
 	    return sv;
 	}