diff --git a/res/layout/fragment_view_email.xml b/res/layout/fragment_view_email.xml
index 2ceadda..3674a52 100644
--- a/res/layout/fragment_view_email.xml
+++ b/res/layout/fragment_view_email.xml
@@ -8,7 +8,7 @@
android:layout_height="wrap_content"
android:orientation="vertical" >
-
+
+
+ android:layout_below="@+id/email_subject"
+ android:layout_marginBottom="5dp"
+ android:layout_marginLeft="5dp"
+ android:layout_toRightOf="@+id/contact_picture" >
-
@@ -96,10 +105,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Datetime" />
-
-
+
+
+
+ android:layout_alignTop="@+id/contact_picture"
+ android:layout_marginLeft="5dp"
+ android:layout_toRightOf="@+id/contact_picture"
+ android:text="Email subject"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
@@ -25,10 +32,10 @@
android:id="@+id/email_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
+ android:layout_alignLeft="@+id/email_from"
android:layout_below="@+id/email_from"
- android:maxLines="1"
android:ellipsize="end"
+ android:maxLines="1"
android:text="Content" />
{
@@ -40,15 +42,21 @@ public class EmailListAdapter extends ArrayAdapter {
View v = mInflater.inflate(R.layout.listitem_email, parent, false);
Email email = getItem(position);
+ ImageView picture = (ImageView) v.findViewById(R.id.contact_picture);
TextView subject = (TextView) v.findViewById(R.id.email_subject);
TextView from = (TextView) v.findViewById(R.id.email_from);
TextView content = (TextView) v.findViewById(R.id.email_content);
TextView sent = (TextView) v.findViewById(R.id.email_sent);
try {
+ String fromAddress = email.getOneFromAddress();
+
+ Bitmap pic = BoteHelper.getPictureForAddress(fromAddress);
+ if (pic != null)
+ picture.setImageBitmap(pic);
+
subject.setText(email.getSubject());
- from.setText(BoteHelper.getNameAndShortDestination(
- email.getOneFromAddress()));
+ from.setText(BoteHelper.getNameAndShortDestination(fromAddress));
if (email.getSentDate() != null)
sent.setText(DateFormat.getInstance().format(
email.getSentDate()));
diff --git a/src/i2p/bote/ViewEmailFragment.java b/src/i2p/bote/ViewEmailFragment.java
index c2245ea..6507cd0 100644
--- a/src/i2p/bote/ViewEmailFragment.java
+++ b/src/i2p/bote/ViewEmailFragment.java
@@ -10,11 +10,13 @@ import javax.mail.MessagingException;
import i2p.bote.email.Email;
import i2p.bote.fileencryption.PasswordException;
import i2p.bote.util.BoteHelper;
+import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -64,6 +66,7 @@ public class ViewEmailFragment extends Fragment {
private void displayEmail(Email email, View v) {
TextView subject = (TextView) v.findViewById(R.id.email_subject);
+ ImageView picture = (ImageView) v.findViewById(R.id.contact_picture);
TextView sender = (TextView) v.findViewById(R.id.email_sender);
LinearLayout recipients = (LinearLayout) v.findViewById(R.id.email_recipients);
TextView sent = (TextView) v.findViewById(R.id.email_sent);
@@ -71,10 +74,15 @@ public class ViewEmailFragment extends Fragment {
TextView content = (TextView) v.findViewById(R.id.email_content);
try {
+ String fromAddress = email.getOneFromAddress();
+
subject.setText(email.getSubject());
- sender.setText(BoteHelper.getDisplayAddress(
- email.getOneFromAddress()));
+ Bitmap pic = BoteHelper.getPictureForAddress(fromAddress);
+ if (pic != null)
+ picture.setImageBitmap(pic);
+
+ sender.setText(BoteHelper.getDisplayAddress(fromAddress));
for (Address recipient : email.getToAddresses()) {
TextView tv = new TextView(getActivity());
diff --git a/src/i2p/bote/util/BoteHelper.java b/src/i2p/bote/util/BoteHelper.java
index d417da8..42a04c1 100644
--- a/src/i2p/bote/util/BoteHelper.java
+++ b/src/i2p/bote/util/BoteHelper.java
@@ -6,10 +6,17 @@ import java.security.GeneralSecurityException;
import javax.mail.MessagingException;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Base64;
+import i2p.bote.I2PBote;
import i2p.bote.R;
+import i2p.bote.email.EmailDestination;
+import i2p.bote.email.EmailIdentity;
import i2p.bote.fileencryption.PasswordException;
import i2p.bote.folder.EmailFolder;
+import i2p.bote.packet.dht.Contact;
public class BoteHelper extends GeneralHelper {
/**
@@ -63,4 +70,44 @@ public class BoteHelper extends GeneralHelper {
: (name.isEmpty() ? emailDest.substring(0, 10)
: name + " <" + emailDest.substring(0, 10) + "...>"));
}
+
+ /**
+ * Get a Bitmap containing the picture for the contact or identity
+ * corresponding to the given address.
+ * @param address
+ * @return a Bitmap, or null if no picture was found.
+ * @throws PasswordException
+ * @throws IOException
+ * @throws GeneralSecurityException
+ */
+ public static Bitmap getPictureForAddress(String address) throws PasswordException, IOException, GeneralSecurityException {
+ String fullAdr = getNameAndDestination(address);
+
+ if (!address.equals(fullAdr)) {
+ // Address was found; try address book first
+ String base64dest = EmailDestination.extractBase64Dest(fullAdr);
+ Contact c = getContact(base64dest);
+ if (c != null) {
+ // Address is in address book
+ String pic = c.getPictureBase64();
+ if (pic != null) {
+ byte[] decodedPic = Base64.decode(pic, Base64.DEFAULT);
+ return BitmapFactory.decodeByteArray(decodedPic, 0, decodedPic.length);
+ }
+ } else {
+ // Address is an identity
+ EmailIdentity i = getIdentity(base64dest);
+ if (i != null) {
+ String pic = i.getPictureBase64();
+ if (pic != null) {
+ byte[] decodedPic = Base64.decode(pic, Base64.DEFAULT);
+ return BitmapFactory.decodeByteArray(decodedPic, 0, decodedPic.length);
+ }
+ }
+ }
+ }
+
+ // Address not found anywhere, or found and has no picture
+ return null;
+ }
}