Layout fixes for long nicknames and group names.

This commit is contained in:
akwizgran
2014-02-06 18:32:33 +00:00
parent 54bc30ee39
commit 6b6b466724
11 changed files with 106 additions and 47 deletions

View File

@@ -82,8 +82,7 @@
<string name="subscribed_all">Subscribed, shared with all contacts</string>
<string name="subscribed_some">Subscribed, shared with chosen contacts</string>
<string name="not_subscribed">Not subscribed</string>
<string name="create_nickname_item">New nickname\u2026</string>
<string name="new_identity_title">New Nickname</string>
<string name="new_identity_title">New Identity</string>
<string name="create_button">Create</string>
<string name="no_contacts">You don\'t have any contacts. Add a contact now?</string>
<string name="add_button">Add</string>

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.contact;
import static android.text.TextUtils.TruncateAt.END;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
@@ -52,7 +53,8 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setMaxLines(1);
name.setSingleLine();
name.setEllipsize(END);
name.setPadding(0, pad, pad, pad);
int unread = item.getUnreadCount();
String contactName = item.getContact().getAuthor().getName();

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.contact;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static java.text.DateFormat.SHORT;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
@@ -38,6 +39,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
LinearLayout layout = new LinearLayout(ctx);
layout.setOrientation(HORIZONTAL);
layout.setGravity(CENTER_VERTICAL);
if(!header.isRead()) {
Resources res = ctx.getResources();
layout.setBackgroundColor(res.getColor(R.color.unread_background));

View File

@@ -2,9 +2,12 @@ package org.briarproject.android.contact;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
import static android.widget.RelativeLayout.CENTER_VERTICAL;
import static android.widget.RelativeLayout.LEFT_OF;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -20,7 +23,7 @@ import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.CommonLayoutParams;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.LocalAuthor;
@@ -46,6 +49,7 @@ import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -94,38 +98,47 @@ implements OnClickListener {
layout.setLayoutParams(MATCH_WRAP);
layout.setOrientation(VERTICAL);
LinearLayout header = new LinearLayout(this);
RelativeLayout header = new RelativeLayout(this);
header.setLayoutParams(MATCH_WRAP);
header.setOrientation(HORIZONTAL);
header.setGravity(CENTER_VERTICAL);
int pad = LayoutUtils.getPadding(this);
from = new TextView(this);
from.setId(1);
from.setTextSize(18);
from.setSingleLine();
from.setEllipsize(END);
from.setPadding(pad, pad, pad, pad);
from.setText(R.string.from);
header.addView(from);
header.addView(new ElasticHorizontalSpace(this));
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.wrapWrap();
leftOf.addRule(ALIGN_PARENT_LEFT);
leftOf.addRule(CENTER_VERTICAL);
leftOf.addRule(LEFT_OF, 2);
header.addView(from, leftOf);
sendButton = new ImageButton(this);
sendButton.setId(2);
sendButton.setBackgroundResource(0);
sendButton.setImageResource(R.drawable.social_send_now);
sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setOnClickListener(this);
header.addView(sendButton);
RelativeLayout.LayoutParams right = CommonLayoutParams.wrapWrap();
right.addRule(ALIGN_PARENT_RIGHT);
right.addRule(CENTER_VERTICAL);
header.addView(sendButton, right);
layout.addView(header);
to = new TextView(this);
to.setTextSize(18);
to.setSingleLine();
to.setEllipsize(END);
to.setPadding(pad, 0, pad, pad);
String format = getResources().getString(R.string.format_to);
to.setText(String.format(format, contactName));
layout.addView(to);
content = new EditText(this);
content.setId(1);
content.setId(3);
int inputType = TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
| TYPE_TEXT_FLAG_CAP_SENTENCES;
content.setInputType(inputType);

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.groups;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static java.text.DateFormat.SHORT;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
@@ -38,6 +39,7 @@ class GroupAdapter extends ArrayAdapter<MessageHeader> {
LinearLayout layout = new LinearLayout(ctx);
layout.setOrientation(HORIZONTAL);
layout.setGravity(CENTER_VERTICAL);
if(!header.isRead()) {
Resources res = ctx.getResources();
layout.setBackgroundColor(res.getColor(R.color.unread_background));

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.groups;
import static android.text.TextUtils.TruncateAt.END;
import static android.view.Gravity.CENTER;
import static android.widget.LinearLayout.HORIZONTAL;
import static java.text.DateFormat.SHORT;
@@ -83,7 +84,8 @@ class GroupListAdapter extends BaseAdapter {
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setMaxLines(1);
name.setSingleLine();
name.setEllipsize(END);
name.setPadding(pad, pad, pad, pad);
int unread = item.getUnreadCount();
String groupName = item.getGroup().getName();

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.groups;
import static android.text.TextUtils.TruncateAt.END;
import static android.view.Gravity.CENTER;
import static android.view.View.INVISIBLE;
import static android.widget.LinearLayout.HORIZONTAL;
@@ -82,7 +83,8 @@ class ManageGroupsAdapter extends BaseAdapter {
TextView name = new TextView(ctx);
name.setTextSize(18);
name.setMaxLines(1);
name.setSingleLine();
name.setEllipsize(END);
name.setPadding(0, pad, pad, pad);
name.setText(s.getGroup().getName());
innerLayout.addView(name);

View File

@@ -2,9 +2,13 @@ package org.briarproject.android.groups;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
import static android.widget.RelativeLayout.CENTER_VERTICAL;
import static android.widget.RelativeLayout.LEFT_OF;
import static android.widget.RelativeLayout.RIGHT_OF;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -25,7 +29,7 @@ import org.briarproject.android.identity.CreateIdentityActivity;
import org.briarproject.android.identity.LocalAuthorItem;
import org.briarproject.android.identity.LocalAuthorItemComparator;
import org.briarproject.android.identity.LocalAuthorSpinnerAdapter;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.CommonLayoutParams;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.LocalAuthor;
@@ -54,6 +58,7 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -106,43 +111,54 @@ implements OnItemSelectedListener, OnClickListener {
layout.setLayoutParams(MATCH_WRAP);
layout.setOrientation(VERTICAL);
LinearLayout header = new LinearLayout(this);
RelativeLayout header = new RelativeLayout(this);
header.setLayoutParams(MATCH_WRAP);
header.setOrientation(HORIZONTAL);
header.setGravity(CENTER_VERTICAL);
int pad = LayoutUtils.getPadding(this);
TextView from = new TextView(this);
from.setId(1);
from.setTextSize(18);
from.setPadding(pad, pad, 0, pad);
from.setText(R.string.from);
header.addView(from);
RelativeLayout.LayoutParams left = CommonLayoutParams.wrapWrap();
left.addRule(ALIGN_PARENT_LEFT);
left.addRule(CENTER_VERTICAL);
header.addView(from, left);
adapter = new LocalAuthorSpinnerAdapter(this, true);
spinner = new Spinner(this);
spinner.setId(2);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
header.addView(spinner);
header.addView(new ElasticHorizontalSpace(this));
RelativeLayout.LayoutParams between = CommonLayoutParams.wrapWrap();
between.addRule(CENTER_VERTICAL);
between.addRule(RIGHT_OF, 1);
between.addRule(LEFT_OF, 3);
header.addView(spinner, between);
sendButton = new ImageButton(this);
sendButton.setId(3);
sendButton.setBackgroundResource(0);
sendButton.setImageResource(R.drawable.social_send_now);
sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setOnClickListener(this);
header.addView(sendButton);
RelativeLayout.LayoutParams right = CommonLayoutParams.wrapWrap();
right.addRule(ALIGN_PARENT_RIGHT);
right.addRule(CENTER_VERTICAL);
header.addView(sendButton, right);
layout.addView(header);
to = new TextView(this);
to.setTextSize(18);
to.setSingleLine();
to.setEllipsize(END);
to.setPadding(pad, 0, pad, pad);
to.setText(R.string.to);
layout.addView(to);
content = new EditText(this);
content.setId(1);
content.setId(4);
int inputType = TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
| TYPE_TEXT_FLAG_CAP_SENTENCES;
content.setInputType(inputType);

View File

@@ -1,5 +1,6 @@
package org.briarproject.android.identity;
import static android.text.TextUtils.TruncateAt.END;
import static org.briarproject.android.identity.LocalAuthorItem.ANONYMOUS;
import static org.briarproject.android.identity.LocalAuthorItem.NEW;
@@ -9,9 +10,9 @@ import java.util.Comparator;
import java.util.List;
import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@@ -46,7 +47,17 @@ implements SpinnerAdapter {
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getView(position, convertView, parent);
TextView name = new TextView(ctx);
name.setTextSize(18);
name.setSingleLine();
name.setEllipsize(END);
int pad = LayoutUtils.getPadding(ctx);
name.setPadding(pad, pad, pad, pad);
LocalAuthorItem item = getItem(position);
if(item == ANONYMOUS) name.setText(R.string.anonymous);
else if(item == NEW) name.setText(R.string.new_identity_item);
else name.setText(item.getLocalAuthor().getName());
return name;
}
public LocalAuthorItem getItem(int position) {
@@ -67,11 +78,8 @@ implements SpinnerAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
TextView name = new TextView(ctx);
name.setTextSize(18);
name.setMaxLines(1);
Resources res = ctx.getResources();
// FIXME: Use LayoutUtils.getPadding() here?
int pad = res.getInteger(R.integer.spinner_padding);
name.setPadding(pad, pad, pad, pad);
name.setSingleLine();
name.setEllipsize(END);
LocalAuthorItem item = getItem(position);
if(item == ANONYMOUS) name.setText(R.string.anonymous);
else if(item == NEW) name.setText(R.string.new_identity_item);

View File

@@ -1,14 +1,16 @@
package org.briarproject.android.util;
import static android.text.TextUtils.TruncateAt.END;
import org.briarproject.R;
import org.briarproject.api.Author;
import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class AuthorView extends LinearLayout {
public class AuthorView extends RelativeLayout {
public AuthorView(Context ctx) {
super(ctx);
@@ -17,19 +19,24 @@ public class AuthorView extends LinearLayout {
public void init(String name, Author.Status status) {
Context ctx = getContext();
int pad = LayoutUtils.getPadding(ctx);
setOrientation(VERTICAL);
TextView nameView = new TextView(ctx);
// Give me all the unused width
nameView.setId(1);
nameView.setTextSize(18);
nameView.setMaxLines(1);
nameView.setSingleLine();
nameView.setEllipsize(END);
nameView.setPadding(pad, pad, pad, pad);
if(name == null) nameView.setText(R.string.anonymous);
else nameView.setText(name);
addView(nameView);
LinearLayout statusLayout = new LinearLayout(ctx);
statusLayout.setOrientation(HORIZONTAL);
LayoutParams leftOf = CommonLayoutParams.wrapWrap();
leftOf.addRule(ALIGN_PARENT_LEFT);
leftOf.addRule(CENTER_VERTICAL);
leftOf.addRule(LEFT_OF, 2);
addView(nameView, leftOf);
ImageView statusView = new ImageView(ctx);
statusView.setPadding(pad, 0, pad, pad);
statusView.setId(2);
statusView.setPadding(0, pad, pad, pad);
switch(status) {
case ANONYMOUS:
statusView.setImageResource(R.drawable.identity_anonymous);
@@ -44,8 +51,9 @@ public class AuthorView extends LinearLayout {
statusView.setImageResource(R.drawable.identity_verified);
break;
}
statusLayout.addView(statusView);
statusLayout.addView(new ElasticHorizontalSpace(ctx));
addView(statusLayout);
LayoutParams right = CommonLayoutParams.wrapWrap();
right.addRule(ALIGN_PARENT_RIGHT);
right.addRule(CENTER_VERTICAL);
addView(statusView, right);
}
}

View File

@@ -3,6 +3,7 @@ package org.briarproject.android.util;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class CommonLayoutParams {
@@ -20,4 +21,8 @@ public class CommonLayoutParams {
public static final LinearLayout.LayoutParams WRAP_WRAP_1 =
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1);
public static RelativeLayout.LayoutParams wrapWrap() {
return new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
}
}