diff --git a/briar-android/build.gradle b/briar-android/build.gradle index f982a86bec0ad01b5297ae2201d0324449c40e7c..4ead68e29f986ba6a82f592616ace455699b2f7b 100644 --- a/briar-android/build.gradle +++ b/briar-android/build.gradle @@ -17,6 +17,7 @@ dependencies { compile "org.roboguice:roboguice:2.0" compile "info.guardianproject.panic:panic:0.5" compile "info.guardianproject.trustedintents:trustedintents:0.2" + compile "de.hdodenhof:circleimageview:2.0.0" } dependencyVerification { diff --git a/briar-android/res/layout/author_view.xml b/briar-android/res/layout/author_view.xml index a3e473dc78268cbb74aa9b1849288ead2938301d..92c863c374784ace09c8c75ef5bb64c18d05e197 100644 --- a/briar-android/res/layout/author_view.xml +++ b/briar-android/res/layout/author_view.xml @@ -4,8 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - <im.delight.android.identicons.SymmetricIdenticon - android:id="@+id/identiconView" + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/avatarView" android:layout_width="@dimen/listitem_picture_size" android:layout_height="@dimen/listitem_picture_size" android:layout_centerVertical="true" diff --git a/briar-android/res/layout/dropdown_author.xml b/briar-android/res/layout/dropdown_author.xml index 46126824305fdb467bd0cca57942e7d28833a1f1..01a9b3f5330f363b672becbc15ce8b1cd3e90d5c 100644 --- a/briar-android/res/layout/dropdown_author.xml +++ b/briar-android/res/layout/dropdown_author.xml @@ -6,8 +6,8 @@ android:layout_height="match_parent" android:gravity="center_vertical"> - <im.delight.android.identicons.SymmetricIdenticon - android:id="@+id/identiconView" + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/avatarView" android:layout_width="@dimen/dropdown_picture_size" android:layout_height="@dimen/dropdown_picture_size"/> diff --git a/briar-android/res/layout/list_item_contact.xml b/briar-android/res/layout/list_item_contact.xml index 0fc6d195feae7400f858e41feac2f4ff3519a25b..8259e1b3b4011a16bc656ce89fa30de922c0a415 100644 --- a/briar-android/res/layout/list_item_contact.xml +++ b/briar-android/res/layout/list_item_contact.xml @@ -11,8 +11,8 @@ android:layout_height="@dimen/listitem_height_one_line_avatar" android:background="?attr/selectableItemBackground"> - <im.delight.android.identicons.SymmetricIdenticon - android:id="@+id/identiconView" + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/avatarView" android:layout_width="@dimen/listitem_picture_size" android:layout_height="@dimen/listitem_picture_size" android:layout_alignParentLeft="true" diff --git a/briar-android/res/layout/list_item_msg_in.xml b/briar-android/res/layout/list_item_msg_in.xml index 614484e51fbd1af5de4681319c5132df67d98831..50ccd007720f43d5f23d90dd96c22f112f90fe3b 100644 --- a/briar-android/res/layout/list_item_msg_in.xml +++ b/briar-android/res/layout/list_item_msg_in.xml @@ -10,8 +10,8 @@ android:paddingTop="@dimen/margin_small" android:paddingBottom="@dimen/margin_small"> - <im.delight.android.identicons.SymmetricIdenticon - android:id="@+id/msgIdenticon" + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/msgAvatar" android:layout_width="@dimen/listitem_picture_size" android:layout_height="@dimen/listitem_picture_size" android:layout_marginLeft="@dimen/listitem_horizontal_margin" diff --git a/briar-android/src/im/delight/android/identicons/IdenticonDrawable.java b/briar-android/src/im/delight/android/identicons/IdenticonDrawable.java index ed9b0de2f21353ff61a445fa694e368f5ede7a35..6c78367f9e8fa45f0bbe9f7b4d2fd6dc2b67fa21 100644 --- a/briar-android/src/im/delight/android/identicons/IdenticonDrawable.java +++ b/briar-android/src/im/delight/android/identicons/IdenticonDrawable.java @@ -48,6 +48,16 @@ public class IdenticonDrawable extends Drawable { mDelegate.show(toShow); } + @Override + public int getIntrinsicHeight() { + return 200; + } + + @Override + public int getIntrinsicWidth() { + return 200; + } + @Override public void setBounds(Rect bounds) { super.setBounds(bounds); diff --git a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java index ac83a2fb499a3701ce2adc5f4f6089baa48a6ff6..739912d95343ed2c32afd572df539286a772bed6 100644 --- a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java @@ -14,12 +14,13 @@ import android.widget.TextView; import org.briarproject.R; import org.briarproject.api.contact.ContactId; +import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.identity.Author; import org.briarproject.api.sync.GroupId; import java.util.List; -import im.delight.android.identicons.IdenticonView; +import im.delight.android.identicons.IdenticonDrawable; import static android.support.v7.util.SortedList.INVALID_POSITION; @@ -86,9 +87,11 @@ public class ContactListAdapter } }); private Context ctx; + private CryptoComponent crypto; - public ContactListAdapter(Context context) { + public ContactListAdapter(Context context, CryptoComponent cryptoComponent) { ctx = context; + crypto = cryptoComponent; } @Override @@ -117,7 +120,8 @@ public class ContactListAdapter } Author author = item.getContact().getAuthor(); - ui.identicon.show(author.getId().getBytes()); + ui.avatar.setImageDrawable( + new IdenticonDrawable(crypto, author.getId().getBytes())); String contactName = author.getName(); if (unread > 0) { ui.name.setText(contactName + " (" + unread + ")"); @@ -198,7 +202,7 @@ public class ContactListAdapter public static class ContactHolder extends RecyclerView.ViewHolder { public ViewGroup layout; public ImageView bulb; - public IdenticonView identicon; + public ImageView avatar; public TextView name; public TextView date; @@ -207,7 +211,7 @@ public class ContactListAdapter layout = (ViewGroup) v; bulb = (ImageView) v.findViewById(R.id.bulbView); - identicon = (IdenticonView) v.findViewById(R.id.identiconView); + avatar = (ImageView) v.findViewById(R.id.avatarView); name = (TextView) v.findViewById(R.id.nameView); date = (TextView) v.findViewById(R.id.dateView); } diff --git a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java index d2bff01e582b45a40cb0c2bee5adbc1c897c9db8..bd52792c5b7d0b427b073d69d9ddf9b7dfd621fe 100644 --- a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java +++ b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java @@ -16,6 +16,7 @@ import org.briarproject.android.util.BriarRecyclerView; import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactManager; +import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.db.DbException; import org.briarproject.api.db.NoSuchContactException; import org.briarproject.api.event.ContactAddedEvent; @@ -62,6 +63,8 @@ public class ContactListFragment extends BaseEventFragment { return TAG; } + @Inject + private CryptoComponent crypto; @Inject private ConnectionRegistry connectionRegistry; private ContactListAdapter adapter = null; @@ -83,7 +86,7 @@ public class ContactListFragment extends BaseEventFragment { inflater.inflate(R.layout.activity_contact_list, container, false); - adapter = new ContactListAdapter(getContext()); + adapter = new ContactListAdapter(getContext(), crypto); list = (BriarRecyclerView) contentView.findViewById(R.id.contactList); list.setLayoutManager(new LinearLayoutManager(getContext())); list.setAdapter(adapter); diff --git a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java index 732d646532de80974385d46b800720521771c1ad..dc96bd47fb7e6bb51d1dfb480ff2b25a53df0e21 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java @@ -23,6 +23,7 @@ import org.briarproject.api.android.AndroidNotificationManager; import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactManager; +import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoExecutor; import org.briarproject.api.db.DbException; import org.briarproject.api.db.NoSuchContactException; @@ -71,6 +72,7 @@ public class ConversationActivity extends BriarActivity private static final Logger LOG = Logger.getLogger(ConversationActivity.class.getName()); + @Inject private CryptoComponent crypto; @Inject private AndroidNotificationManager notificationManager; @Inject private ConnectionRegistry connectionRegistry; @Inject @CryptoExecutor private Executor cryptoExecutor; @@ -102,7 +104,7 @@ public class ConversationActivity extends BriarActivity setContentView(R.layout.activity_conversation); - adapter = new ConversationAdapter(this); + adapter = new ConversationAdapter(this, crypto); list = (BriarRecyclerView) findViewById(R.id.conversationView); list.setLayoutManager(new LinearLayoutManager(this)); list.setAdapter(adapter); diff --git a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java index a1cf4d013d0ac88884e360223f7338d3b64b5919..a35db98bdd96863a16a752b4d87fdd7dd804c329 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java @@ -11,10 +11,11 @@ import android.widget.ImageView; import android.widget.TextView; import org.briarproject.R; +import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.messaging.PrivateMessageHeader; import org.briarproject.util.StringUtils; -import im.delight.android.identicons.IdenticonView; +import im.delight.android.identicons.IdenticonDrawable; import static android.support.v7.util.SortedList.INVALID_POSITION; @@ -72,10 +73,12 @@ class ConversationAdapter extends } }); private Context ctx; + private CryptoComponent crypto; private byte[] identiconKey; - public ConversationAdapter(Context context) { + public ConversationAdapter(Context context, CryptoComponent cryptoComponent) { ctx = context; + crypto = cryptoComponent; } public void setIdenticonKey(byte[] key) { @@ -129,7 +132,8 @@ class ConversationAdapter extends } } else { if (identiconKey != null) - ui.identicon.show(identiconKey); + ui.avatar.setImageDrawable( + new IdenticonDrawable(crypto, identiconKey)); if (!header.isRead()) { int left = ui.layout.getPaddingLeft(); int top = ui.layout.getPaddingTop(); @@ -198,7 +202,7 @@ class ConversationAdapter extends public TextView body; public TextView date; public ImageView status; - public IdenticonView identicon; + public ImageView avatar; public MessageHolder(View v, int type) { super(v); @@ -211,7 +215,7 @@ class ConversationAdapter extends if (type == MSG_OUT) { status = (ImageView) v.findViewById(R.id.msgStatus); } else { - identicon = (IdenticonView) v.findViewById(R.id.msgIdenticon); + avatar = (ImageView) v.findViewById(R.id.msgAvatar); } } } diff --git a/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java b/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java index 40e72a14877abad5ce9c4f3d74b3dc372a3449f3..a38433f311e324066248a455671078095a0fec57 100644 --- a/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java +++ b/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java @@ -123,7 +123,7 @@ implements OnItemSelectedListener, OnClickListener { left.addRule(CENTER_VERTICAL); header.addView(from, left); - adapter = new LocalAuthorSpinnerAdapter(this, true); + adapter = new LocalAuthorSpinnerAdapter(this, crypto, true); spinner = new Spinner(this); spinner.setId(2); spinner.setAdapter(adapter); diff --git a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java index 8e774ceb771cc77bc56baac7fbad7ab15336ade3..a0e2d88de2ebfff7c8dd3e5d3bdcb01f4ad2ffce 100644 --- a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java +++ b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java @@ -5,17 +5,19 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.ImageView; import android.widget.SpinnerAdapter; import android.widget.TextView; import org.briarproject.R; +import org.briarproject.api.crypto.CryptoComponent; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import im.delight.android.identicons.IdenticonView; +import im.delight.android.identicons.IdenticonDrawable; import static org.briarproject.android.identity.LocalAuthorItem.ANONYMOUS; import static org.briarproject.android.identity.LocalAuthorItem.NEW; @@ -24,11 +26,14 @@ public class LocalAuthorSpinnerAdapter extends BaseAdapter implements SpinnerAdapter { private final Context ctx; + private final CryptoComponent crypto; private final boolean includeAnonymous; private final List<LocalAuthorItem> list = new ArrayList<LocalAuthorItem>(); - public LocalAuthorSpinnerAdapter(Context ctx, boolean includeAnonymous) { + public LocalAuthorSpinnerAdapter(Context ctx, + CryptoComponent crypto, boolean includeAnonymous) { this.ctx = ctx; + this.crypto = crypto; this.includeAnonymous = includeAnonymous; } @@ -60,20 +65,21 @@ implements SpinnerAdapter { view = convertView; TextView name = (TextView) view.findViewById(R.id.nameView); - IdenticonView identicon = - (IdenticonView) view.findViewById(R.id.identiconView); + ImageView avatar = + (ImageView) view.findViewById(R.id.avatarView); LocalAuthorItem item = getItem(position); if (item == ANONYMOUS) { name.setText(R.string.anonymous); - identicon.setVisibility(View.INVISIBLE); + avatar.setVisibility(View.INVISIBLE); } else if (item == NEW) { name.setText(R.string.new_identity_item); - identicon.setVisibility(View.INVISIBLE); + avatar.setVisibility(View.INVISIBLE); } else { name.setText(item.getLocalAuthor().getName()); - identicon.setVisibility(View.VISIBLE); - identicon.show(item.getLocalAuthor().getId().getBytes()); + avatar.setVisibility(View.VISIBLE); + avatar.setImageDrawable(new IdenticonDrawable(crypto, + item.getLocalAuthor().getId().getBytes())); } return view; } diff --git a/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java b/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java index 940de7e7594f83fff6a48fd6d1d0062ce8e8f048..912d28ccebaf78525a7115852776583b1e3a3000 100644 --- a/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java +++ b/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java @@ -16,11 +16,16 @@ 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.api.crypto.CryptoComponent; import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.LocalAuthor; import java.util.Collection; +import javax.inject.Inject; + +import roboguice.RoboGuice; + import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE; import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION; import static org.briarproject.android.identity.LocalAuthorItem.NEW; @@ -30,6 +35,7 @@ import static org.briarproject.android.invitation.AddContactActivity.REQUEST_CRE class ChooseIdentityView extends AddContactView implements OnItemSelectedListener, OnClickListener { + @Inject private CryptoComponent crypto; private LocalAuthorSpinnerAdapter adapter = null; private Spinner spinner = null; @@ -40,6 +46,7 @@ implements OnItemSelectedListener, OnClickListener { void populate() { removeAllViews(); Context ctx = getContext(); + RoboGuice.injectMembers(ctx, this); LayoutInflater inflater = (LayoutInflater) ctx.getSystemService (Context.LAYOUT_INFLATER_SERVICE); @@ -50,7 +57,7 @@ implements OnItemSelectedListener, OnClickListener { TextView step = (TextView) view.findViewById(R.id.stepView); step.setText(String.format(ctx.getString(R.string.step), 1, 3)); - adapter = new LocalAuthorSpinnerAdapter(ctx, false); + adapter = new LocalAuthorSpinnerAdapter(ctx, crypto, false); spinner = (Spinner) view.findViewById(R.id.spinner); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); diff --git a/briar-android/src/org/briarproject/android/util/AuthorView.java b/briar-android/src/org/briarproject/android/util/AuthorView.java index 166e8d63babbf206bd8c90416a36277532903fdc..dd20a28e7717cd0e54a2a9f745bf5aef0d414595 100644 --- a/briar-android/src/org/briarproject/android/util/AuthorView.java +++ b/briar-android/src/org/briarproject/android/util/AuthorView.java @@ -9,13 +9,18 @@ import android.widget.ImageView; import android.widget.TextView; import org.briarproject.R; +import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.identity.Author; -import im.delight.android.identicons.IdenticonView; +import javax.inject.Inject; + +import im.delight.android.identicons.IdenticonDrawable; +import roboguice.RoboGuice; public class AuthorView extends FrameLayout { - private IdenticonView identiconView; + @Inject private CryptoComponent crypto; + private ImageView avatarView; private TextView nameView; private ImageView statusView; @@ -39,13 +44,14 @@ public class AuthorView extends FrameLayout { } private void initViews() { + RoboGuice.injectMembers(getContext(), this); if (isInEditMode()) return; View v = LayoutInflater.from(getContext()).inflate( R.layout.author_view, this, true); - identiconView = (IdenticonView) v.findViewById(R.id.identiconView); + avatarView = (ImageView) v.findViewById(R.id.avatarView); nameView = (TextView) v.findViewById(R.id.nameView); statusView = (ImageView) v.findViewById(R.id.statusView); } @@ -53,7 +59,8 @@ public class AuthorView extends FrameLayout { public void init(Author author, Author.Status status) { if (author == null) nameView.setText(R.string.anonymous); else { - identiconView.show(author.getId().getBytes()); + avatarView.setImageDrawable( + new IdenticonDrawable(crypto, author.getId().getBytes())); nameView.setText(author.getName()); }