diff --git a/app/src/main/res/drawable/message_background.xml b/app/src/main/res/drawable/message_background.xml
new file mode 100644
index 0000000..14a6988
--- /dev/null
+++ b/app/src/main/res/drawable/message_background.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_add_contacts.xml b/app/src/main/res/layout/activity_add_contacts.xml
index 308529f..657d19e 100644
--- a/app/src/main/res/layout/activity_add_contacts.xml
+++ b/app/src/main/res/layout/activity_add_contacts.xml
@@ -1,3 +1,5 @@
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index da8b68a..5cb293b 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,3 +1,5 @@
+
+
+
+
-
+ android:layout_width="match_parent"
+ android:layout_weight="11"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="10dip"
+ android:layout_marginBottom="2dip"
+ android:background="@color/chat_background">
-
+ android:stackFromBottom="true"
+ android:transcriptMode="normal"
+ android:divider="@android:color/transparent"
+ android:dividerHeight="5dp"/>
-
+
-
+
+
-
+
-
-
-
-
-
-
-
-
-
+
diff --git a/app/src/main/res/layout/fragment_contacts.xml b/app/src/main/res/layout/fragment_contacts.xml
index 9de2c56..b8b4950 100644
--- a/app/src/main/res/layout/fragment_contacts.xml
+++ b/app/src/main/res/layout/fragment_contacts.xml
@@ -1,3 +1,5 @@
+
+
diff --git a/app/src/main/res/layout/item_message.xml b/app/src/main/res/layout/item_message.xml
new file mode 100644
index 0000000..caf600e
--- /dev/null
+++ b/app/src/main/res/layout/item_message.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-v21/style.xml b/app/src/main/res/values-v21/style.xml
index 9c242f5..427ac46 100644
--- a/app/src/main/res/values-v21/style.xml
+++ b/app/src/main/res/values-v21/style.xml
@@ -1,4 +1,5 @@
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..8ad38e2
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+ #E6FFE6
+
+
+ #AAAAAA
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7b32f61..d4b3d54 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,5 @@
+
diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml
index f43b8bb..ce0b1ee 100644
--- a/app/src/main/res/values/style.xml
+++ b/app/src/main/res/values/style.xml
@@ -1,4 +1,5 @@
+
diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml
index e9b9486..363cb03 100644
--- a/app/src/main/res/xml/settings.xml
+++ b/app/src/main/res/xml/settings.xml
@@ -1,4 +1,5 @@
+
- val text: String = messageText.getText.toString
+ val text: String = messageText.getText.toString.trim
if (!text.isEmpty) {
if (!chatService.isConnected(device)) {
Toast.makeText(getActivity, R.string.contact_offline_toast, Toast.LENGTH_SHORT).show()
diff --git a/app/src/main/scala/com/nutomic/ensichat/util/MessagesAdapter.scala b/app/src/main/scala/com/nutomic/ensichat/util/MessagesAdapter.scala
index e252aa5..62fd966 100644
--- a/app/src/main/scala/com/nutomic/ensichat/util/MessagesAdapter.scala
+++ b/app/src/main/scala/com/nutomic/ensichat/util/MessagesAdapter.scala
@@ -1,8 +1,9 @@
package com.nutomic.ensichat.util
import android.content.Context
-import android.view.{View, ViewGroup}
-import android.widget.{ArrayAdapter, TextView}
+import android.view.{Gravity, View, ViewGroup}
+import android.widget.{ArrayAdapter, RelativeLayout, TextView}
+import com.nutomic.ensichat.R
import com.nutomic.ensichat.bluetooth.Device
import com.nutomic.ensichat.messages.TextMessage
@@ -10,15 +11,30 @@ import com.nutomic.ensichat.messages.TextMessage
* Displays [[TextMessage]]s in ListView.
*/
class MessagesAdapter(context: Context, localDevice: Device.ID) extends
- ArrayAdapter[TextMessage](context, android.R.layout.simple_list_item_1) {
+ ArrayAdapter[TextMessage](context, R.layout.item_message, android.R.id.text1) {
+
+ /**
+ * Free space to the right/left to a message depending on who sent it, in dip.
+ */
+ private val MessageMargin = 50
override def getView(position: Int, convertView: View, parent: ViewGroup): View = {
- val view: View = super.getView(position, convertView, parent)
- val tv: TextView = view.findViewById(android.R.id.text1).asInstanceOf[TextView]
- view.setBackgroundColor(context.getResources.getColor(
- if (getItem(position).sender == localDevice) android.R.color.holo_blue_light
- else android.R.color.holo_green_light))
+ val view = super.getView(position, convertView, parent).asInstanceOf[RelativeLayout]
+ val tv = view.findViewById(android.R.id.text1).asInstanceOf[TextView]
+
tv.setText(getItem(position).text)
+
+ val lp = new RelativeLayout.LayoutParams(tv.getLayoutParams)
+ val margin = (MessageMargin * context.getResources.getDisplayMetrics.density).toInt
+ if (getItem(position).sender == localDevice) {
+ view.setGravity(Gravity.RIGHT)
+ lp.setMargins(margin, 0, 0, 0)
+ } else {
+ view.setGravity(Gravity.LEFT)
+ lp.setMargins(0, 0, margin, 0)
+ }
+ tv.setLayoutParams(lp)
+
view
}