mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Speech bubble layout for private conversations.
This commit is contained in:
@@ -1,29 +1,33 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.Gravity.CENTER_VERTICAL;
|
||||
import static android.widget.LinearLayout.HORIZONTAL;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static android.view.Gravity.LEFT;
|
||||
import static android.view.Gravity.RIGHT;
|
||||
import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
|
||||
import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
|
||||
import static android.widget.RelativeLayout.ALIGN_PARENT_TOP;
|
||||
import static android.widget.RelativeLayout.BELOW;
|
||||
import static android.widget.RelativeLayout.LEFT_OF;
|
||||
import static android.widget.RelativeLayout.RIGHT_OF;
|
||||
import static java.text.DateFormat.SHORT;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
||||
import static org.briarproject.api.Author.Status.VERIFIED;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AuthorView;
|
||||
import org.briarproject.android.util.CommonLayoutParams;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
@@ -43,46 +47,88 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
Context ctx = getContext();
|
||||
Resources res = ctx.getResources();
|
||||
|
||||
LinearLayout layout = new LinearLayout(ctx);
|
||||
layout.setOrientation(VERTICAL);
|
||||
layout.setGravity(CENTER_HORIZONTAL);
|
||||
RelativeLayout layout = new RelativeLayout(ctx);
|
||||
|
||||
int background;
|
||||
if(header.isRead()) background = res.getColor(R.color.read_background);
|
||||
else background = res.getColor(R.color.unread_background);
|
||||
layout.setBackgroundColor(background);
|
||||
|
||||
LinearLayout headerLayout = new LinearLayout(ctx);
|
||||
headerLayout.setOrientation(HORIZONTAL);
|
||||
headerLayout.setGravity(CENTER_VERTICAL);
|
||||
|
||||
AuthorView authorView = new AuthorView(ctx);
|
||||
authorView.setLayoutParams(WRAP_WRAP_1);
|
||||
authorView.init(header.getAuthor().getName(), VERIFIED);
|
||||
headerLayout.addView(authorView);
|
||||
|
||||
TextView date = new TextView(ctx);
|
||||
date.setId(1);
|
||||
date.setTextSize(14);
|
||||
date.setPadding(0, pad, pad, pad);
|
||||
date.setBackgroundColor(background);
|
||||
date.setPadding(pad, pad, pad, 0);
|
||||
long then = header.getTimestamp(), now = System.currentTimeMillis();
|
||||
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
|
||||
headerLayout.addView(date);
|
||||
layout.addView(headerLayout);
|
||||
|
||||
View content;
|
||||
if(item.getBody() == null) {
|
||||
TextView ellipsis = new TextView(ctx);
|
||||
ellipsis.setPadding(pad, 0, pad, pad);
|
||||
ellipsis.setText("\u2026");
|
||||
layout.addView(ellipsis);
|
||||
content = ellipsis;
|
||||
} else if(header.getContentType().equals("text/plain")) {
|
||||
TextView text = new TextView(ctx);
|
||||
text.setPadding(pad, 0, pad, pad);
|
||||
text.setText(StringUtils.fromUtf8(item.getBody()));
|
||||
layout.addView(text);
|
||||
content = text;
|
||||
} else {
|
||||
ImageButton attachment = new ImageButton(ctx);
|
||||
attachment.setPadding(pad, 0, pad, pad);
|
||||
attachment.setImageResource(R.drawable.content_attachment);
|
||||
layout.addView(attachment);
|
||||
content = attachment;
|
||||
}
|
||||
content.setId(2);
|
||||
content.setBackgroundColor(background);
|
||||
content.setPadding(pad, 0, pad, pad);
|
||||
|
||||
ImageView bubble = new ImageView(ctx);
|
||||
bubble.setId(3);
|
||||
|
||||
if(header.isLocal()) {
|
||||
Drawable d;
|
||||
if(header.isRead())
|
||||
d = res.getDrawable(R.drawable.bubble_read_right);
|
||||
else d = res.getDrawable(R.drawable.bubble_unread_right);
|
||||
bubble.setImageDrawable(d);
|
||||
layout.setPadding(d.getIntrinsicWidth(), 0, 0, 0);
|
||||
date.setGravity(RIGHT);
|
||||
// Bubble point at the top right, date on top, content below
|
||||
RelativeLayout.LayoutParams topRight =
|
||||
CommonLayoutParams.wrapWrap();
|
||||
topRight.addRule(ALIGN_PARENT_TOP);
|
||||
topRight.addRule(ALIGN_PARENT_RIGHT);
|
||||
layout.addView(bubble, topRight);
|
||||
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.wrapWrap();
|
||||
leftOf.addRule(ALIGN_PARENT_TOP);
|
||||
leftOf.addRule(ALIGN_PARENT_LEFT);
|
||||
leftOf.addRule(LEFT_OF, 3);
|
||||
layout.addView(date, leftOf);
|
||||
RelativeLayout.LayoutParams below = CommonLayoutParams.wrapWrap();
|
||||
below.addRule(ALIGN_PARENT_LEFT);
|
||||
below.addRule(LEFT_OF, 3);
|
||||
below.addRule(BELOW, 1);
|
||||
layout.addView(content, below);
|
||||
} else {
|
||||
Drawable d;
|
||||
if(header.isRead())
|
||||
d = res.getDrawable(R.drawable.bubble_read_left);
|
||||
else d = res.getDrawable(R.drawable.bubble_unread_left);
|
||||
bubble.setImageDrawable(d);
|
||||
layout.setPadding(0, 0, d.getIntrinsicWidth(), 0);
|
||||
date.setGravity(LEFT);
|
||||
// Bubble point at the top left, date on top, content below
|
||||
RelativeLayout.LayoutParams topLeft = CommonLayoutParams.wrapWrap();
|
||||
topLeft.addRule(ALIGN_PARENT_TOP);
|
||||
topLeft.addRule(ALIGN_PARENT_LEFT);
|
||||
layout.addView(bubble, topLeft);
|
||||
RelativeLayout.LayoutParams rightOf = CommonLayoutParams.wrapWrap();
|
||||
rightOf.addRule(ALIGN_PARENT_TOP);
|
||||
rightOf.addRule(ALIGN_PARENT_RIGHT);
|
||||
rightOf.addRule(RIGHT_OF, 3);
|
||||
layout.addView(date, rightOf);
|
||||
RelativeLayout.LayoutParams below = CommonLayoutParams.wrapWrap();
|
||||
below.addRule(ALIGN_PARENT_RIGHT);
|
||||
below.addRule(RIGHT_OF, 3);
|
||||
below.addRule(BELOW, 1);
|
||||
layout.addView(content, below);
|
||||
}
|
||||
|
||||
return layout;
|
||||
|
||||
Reference in New Issue
Block a user