Improved chat view
This commit is contained in:
parent
717ef64ff5
commit
9a77d2f070
11 changed files with 165 additions and 33 deletions
|
@ -2,7 +2,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:linphone="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="75dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView
|
||||
|
@ -13,7 +13,7 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/picture"
|
||||
android:layout_width="100dp"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/content_description_contact_picture"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<org.linphone.ui.AvatarWithShadow
|
||||
android:id="@+id/contactPicture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
linphone:picture="@drawable/unknown_small" />
|
||||
|
||||
<TextView
|
||||
|
@ -51,13 +51,13 @@
|
|||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_height="60dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/message"
|
||||
android:inputType="textMultiLine"
|
||||
android:inputType="textShortMessage"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dip"
|
||||
|
|
25
res/layout/chat_bubble_alt_incoming.xml
Normal file
25
res/layout/chat_bubble_alt_incoming.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:paddingLeft="5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
24
res/layout/chat_bubble_alt_outgoing.xml
Normal file
24
res/layout/chat_bubble_alt_outgoing.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
24
res/layout/chat_bubble_incoming.xml
Normal file
24
res/layout/chat_bubble_incoming.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:singleLine="true"
|
||||
android:paddingLeft="5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
24
res/layout/chat_bubble_outgoing.xml
Normal file
24
res/layout/chat_bubble_outgoing.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,9 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="messages_date_format">HH:mm:ss d MMM</string>
|
||||
<string name="now_date_format">few seconds ago</string>
|
||||
<string name="today_date_format">HH:mm:ss</string>
|
||||
<string name="messages_date_format">HH:mm d MMM</string>
|
||||
<string name="today_date_format">HH:mm</string>
|
||||
|
||||
<string name="app_name">Linphone 2</string>
|
||||
<string name="notification_title">Linphone</string>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<bool name="emoticons_in_messages">true</bool>
|
||||
<bool name="only_display_username_if_unknown">true</bool>
|
||||
<bool name="display_messages_time">true</bool> <!-- Used to show the time of each message arrival -->
|
||||
<bool name="display_time_aside">true</bool> <!-- if display_messages_time = true, display time on the side of the message instead of below -->
|
||||
|
||||
<bool name="allow_ringing_while_early_media">true</bool>
|
||||
<bool name="allow_transfers">true</bool>
|
||||
|
|
|
@ -154,7 +154,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (chatRoom != null && message != null) {
|
||||
if (chatRoom != null && message != null && message.getText().length() > 0) {
|
||||
String messageToSend = message.getText().toString();
|
||||
message.setText("");
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
|||
LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
||||
}
|
||||
|
||||
displayMessage(previousMessageID + 2, messageToSend, getString(R.string.now_date_format), false, messagesLayout);
|
||||
displayMessage(previousMessageID + 2, messageToSend, String.valueOf(System.currentTimeMillis()), false, messagesLayout);
|
||||
scrollToEnd();
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
|||
public void onMessageReceived(LinphoneAddress from, String message) {
|
||||
if (from.asStringUriOnly().equals(sipUri)) {
|
||||
int id = previousMessageID + 2;
|
||||
displayMessage(id, message, getString(R.string.now_date_format), true, messagesLayout);
|
||||
displayMessage(id, message, String.valueOf(System.currentTimeMillis()), true, messagesLayout);
|
||||
scrollToEnd();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,13 +54,14 @@ public class ChatStorage {
|
|||
values.put("localContact", from);
|
||||
values.put("remoteContact", to);
|
||||
values.put("direction", OUTGOING);
|
||||
values.put("read", READ);
|
||||
} else if (to.equals("")) {
|
||||
values.put("localContact", to);
|
||||
values.put("remoteContact", from);
|
||||
values.put("direction", INCOMING);
|
||||
values.put("read", NOT_READ);
|
||||
}
|
||||
values.put("message", message);
|
||||
values.put("read", NOT_READ);
|
||||
values.put("time", System.currentTimeMillis());
|
||||
return (int) db.insert(TABLE_NAME, null, values);
|
||||
}
|
||||
|
|
|
@ -24,14 +24,15 @@ import java.util.Map.Entry;
|
|||
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
@ -77,7 +78,7 @@ public class BubbleChat {
|
|||
public BubbleChat(Context context, int id, String message, String time, boolean isIncoming, int previousID) {
|
||||
view = new RelativeLayout(context);
|
||||
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
if (isIncoming) {
|
||||
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
|
@ -92,30 +93,63 @@ public class BubbleChat {
|
|||
layoutParams.addRule(RelativeLayout.BELOW, previousID);
|
||||
}
|
||||
|
||||
TextView messageView = new TextView(context);
|
||||
messageView.setId(id);
|
||||
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||
messageView.setText(getSmiledText(context, message));
|
||||
} else {
|
||||
messageView.setText(message);
|
||||
}
|
||||
messageView.setTextColor(Color.BLACK);
|
||||
|
||||
view.setId(id);
|
||||
layoutParams.setMargins(0, LinphoneUtils.pixelsToDpi(context.getResources(), 10), 0, 0);
|
||||
view.setLayoutParams(layoutParams);
|
||||
view.addView(messageView);
|
||||
|
||||
if (context.getResources().getBoolean(R.bool.display_messages_time)) {
|
||||
TextView timeView = new TextView(context);
|
||||
LayoutParams timeParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
timeParams.addRule(RelativeLayout.BELOW, id);
|
||||
timeView.setLayoutParams(timeParams);
|
||||
timeView.setText(timestampToHumanDate(context, time));
|
||||
timeView.setTextColor(Color.GRAY);
|
||||
timeView.setTextSize(12);
|
||||
view.addView(timeView);
|
||||
if (context.getResources().getBoolean(R.bool.display_time_aside)) {
|
||||
LinearLayout layout;
|
||||
if (isIncoming) {
|
||||
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_incoming, null);
|
||||
} else {
|
||||
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_outgoing, null);
|
||||
}
|
||||
|
||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||
msgView.setText(getSmiledText(context, message));
|
||||
} else {
|
||||
msgView.setText(message);
|
||||
}
|
||||
|
||||
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
||||
timeView.setText(timestampToHumanDate(context, time));
|
||||
|
||||
view.addView(layout);
|
||||
} else {
|
||||
LinearLayout layout;
|
||||
if (isIncoming) {
|
||||
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_incoming, null);
|
||||
} else {
|
||||
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_outgoing, null);
|
||||
}
|
||||
|
||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||
msgView.setText(getSmiledText(context, message));
|
||||
} else {
|
||||
msgView.setText(message);
|
||||
}
|
||||
|
||||
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
||||
timeView.setText(timestampToHumanDate(context, time));
|
||||
|
||||
view.addView(layout);
|
||||
}
|
||||
} else {
|
||||
TextView messageView = new TextView(context);
|
||||
messageView.setId(id);
|
||||
messageView.setTextColor(Color.BLACK);
|
||||
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
|
||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||
messageView.setText(getSmiledText(context, message));
|
||||
} else {
|
||||
messageView.setText(message);
|
||||
}
|
||||
|
||||
view.addView(messageView);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue