mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Speech bubble layout for private conversations.
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
<activity
|
||||
android:name=".android.contact.ReadPrivateMessageActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:label="@string/read_message_title"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
@@ -88,7 +88,7 @@
|
||||
<activity
|
||||
android:name=".android.contact.WritePrivateMessageActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/new_message_title"
|
||||
android:label="@string/write_message_title"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
|
||||
BIN
briar-android/res/drawable/bubble_read_left.png
Normal file
BIN
briar-android/res/drawable/bubble_read_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 496 B |
BIN
briar-android/res/drawable/bubble_read_right.png
Normal file
BIN
briar-android/res/drawable/bubble_read_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 507 B |
BIN
briar-android/res/drawable/bubble_unread_left.png
Normal file
BIN
briar-android/res/drawable/bubble_unread_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 341 B |
BIN
briar-android/res/drawable/bubble_unread_right.png
Normal file
BIN
briar-android/res/drawable/bubble_unread_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 322 B |
@@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<color name="home_screen_background">#FFFFFF</color>
|
||||
<color name="content_background">#FFFFFF</color>
|
||||
<color name="conversation_background">#DDDDDD</color>
|
||||
<color name="unread_background">#FFFFFF</color>
|
||||
<color name="read_background">#EEEEEE</color>
|
||||
<color name="horizontal_border">#CCCCCC</color>
|
||||
|
||||
@@ -55,11 +55,10 @@
|
||||
<string name="interfering">This could mean that someone is trying to interfere with your connection</string>
|
||||
<string name="contact_added_toast">Contact added</string>
|
||||
<string name="done_button">Done</string>
|
||||
<string name="messages_title">Messages</string>
|
||||
<string name="no_messages">(No messages)</string>
|
||||
<string name="format_from">From: %1$s</string>
|
||||
<string name="format_to">To: %1$s</string>
|
||||
<string name="new_message_title">New Message</string>
|
||||
<string name="read_message_title">Private Message</string>
|
||||
<string name="write_message_title">New Private Message</string>
|
||||
<string name="from">From:</string>
|
||||
<string name="to">To:</string>
|
||||
<string name="anonymous">Anonymous</string>
|
||||
|
||||
@@ -86,7 +86,9 @@ public class PasswordActivity extends RoboActivity {
|
||||
layout.addView(passwordEntry);
|
||||
|
||||
// Adjusting the padding of buttons and EditTexts has the wrong results
|
||||
layout.addView(new FixedVerticalSpace(this));
|
||||
FixedVerticalSpace space = new FixedVerticalSpace(this);
|
||||
space.setHeight(pad);
|
||||
layout.addView(space);
|
||||
|
||||
continueButton = new Button(this);
|
||||
continueButton.setLayoutParams(WRAP_WRAP);
|
||||
|
||||
@@ -24,6 +24,7 @@ import javax.inject.Inject;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.AuthorId;
|
||||
import org.briarproject.api.ContactId;
|
||||
@@ -43,6 +44,8 @@ import org.briarproject.api.messaging.GroupId;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@@ -100,6 +103,12 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
list = new ListView(this);
|
||||
// Give me all the width and all the unused height
|
||||
list.setLayoutParams(MATCH_WRAP_1);
|
||||
// Make the dividers the same colour as the background
|
||||
Resources res = getResources();
|
||||
int background = res.getColor(R.color.conversation_background);
|
||||
list.setBackgroundColor(background);
|
||||
list.setDivider(new ColorDrawable(background));
|
||||
list.setDividerHeight(LayoutUtils.getSeparatorWidth(this));
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
layout.addView(list);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -76,7 +76,6 @@ implements OnClickListener {
|
||||
Intent i = getIntent();
|
||||
contactName = i.getStringExtra("briar.CONTACT_NAME");
|
||||
if(contactName == null) throw new IllegalStateException();
|
||||
setTitle(contactName);
|
||||
byte[] b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
localAuthorId = new AuthorId(b);
|
||||
|
||||
@@ -99,8 +99,6 @@ implements OnClickListener {
|
||||
layout.setOrientation(VERTICAL);
|
||||
|
||||
RelativeLayout header = new RelativeLayout(this);
|
||||
header.setLayoutParams(MATCH_WRAP);
|
||||
|
||||
int pad = LayoutUtils.getPadding(this);
|
||||
|
||||
from = new TextView(this);
|
||||
|
||||
@@ -112,8 +112,6 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
layout.setOrientation(VERTICAL);
|
||||
|
||||
RelativeLayout header = new RelativeLayout(this);
|
||||
header.setLayoutParams(MATCH_WRAP);
|
||||
|
||||
int pad = LayoutUtils.getPadding(this);
|
||||
|
||||
TextView from = new TextView(this);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.android.util;
|
||||
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
public class FixedHorizontalSpace extends View {
|
||||
|
||||
public FixedHorizontalSpace(Context ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
setLayoutParams(new LayoutParams(width, WRAP_CONTENT));
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,9 @@ public class FixedVerticalSpace extends View {
|
||||
|
||||
public FixedVerticalSpace(Context ctx) {
|
||||
super(ctx);
|
||||
int pad = LayoutUtils.getPadding(ctx);
|
||||
setLayoutParams(new LayoutParams(WRAP_CONTENT, pad));
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
setLayoutParams(new LayoutParams(WRAP_CONTENT, height));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user