Show contact picture in email list and view (if available)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/darker_gray"
|
||||
@@ -22,11 +22,21 @@
|
||||
android:text="Subject"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/email_subject"
|
||||
android:layout_below="@+id/email_subject"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginBottom="5dp" >
|
||||
android:layout_below="@+id/email_subject"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_toRightOf="@+id/contact_picture" >
|
||||
|
||||
<TableRow
|
||||
android:layout_width="wrap_content"
|
||||
@@ -60,7 +70,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
@@ -96,10 +105,9 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Datetime" />
|
||||
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/email_content"
|
||||
|
||||
@@ -4,20 +4,27 @@
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/email_subject"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="Email subject" />
|
||||
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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/email_from"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignLeft="@+id/email_subject"
|
||||
android:layout_below="@+id/email_subject"
|
||||
android:text="From" />
|
||||
|
||||
@@ -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" />
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -11,11 +11,13 @@ import i2p.bote.email.Email;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class EmailListAdapter extends ArrayAdapter<Email> {
|
||||
@@ -40,15 +42,21 @@ public class EmailListAdapter extends ArrayAdapter<Email> {
|
||||
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()));
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user