2015-01-15 02:25:43 -05:00
|
|
|
package com.fsck.k9.ui.messageview;
|
2011-01-06 11:56:20 -05:00
|
|
|
|
2014-10-20 19:39:16 -04:00
|
|
|
|
2011-01-06 11:56:20 -05:00
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Bitmap;
|
2014-02-16 18:10:44 -05:00
|
|
|
import android.os.AsyncTask;
|
2011-01-06 11:56:20 -05:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2012-02-27 15:34:18 -05:00
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnLongClickListener;
|
2011-04-23 23:56:34 -04:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2011-01-06 11:56:20 -05:00
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
import com.fsck.k9.helper.SizeFormatter;
|
2012-02-27 15:00:44 -05:00
|
|
|
import com.fsck.k9.mail.MessagingException;
|
2015-01-15 05:19:32 -05:00
|
|
|
import com.fsck.k9.mailstore.AttachmentViewInfo;
|
2011-01-06 11:56:20 -05:00
|
|
|
|
2012-01-26 21:07:44 -05:00
|
|
|
|
2012-02-27 15:34:18 -05:00
|
|
|
public class AttachmentView extends FrameLayout implements OnClickListener, OnLongClickListener {
|
2015-01-15 05:19:32 -05:00
|
|
|
private AttachmentViewInfo attachment;
|
|
|
|
private AttachmentViewCallback callback;
|
2011-04-24 00:00:10 -04:00
|
|
|
|
2014-10-20 21:21:09 -04:00
|
|
|
private Button viewButton;
|
|
|
|
private Button downloadButton;
|
|
|
|
|
2011-04-24 00:00:10 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public AttachmentView(Context context, AttributeSet attrs, int defStyle) {
|
2011-01-06 11:56:20 -05:00
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
2014-10-20 19:39:16 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public AttachmentView(Context context, AttributeSet attrs) {
|
2011-01-06 11:56:20 -05:00
|
|
|
super(context, attrs);
|
|
|
|
}
|
2014-10-20 19:39:16 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public AttachmentView(Context context) {
|
2011-01-06 11:56:20 -05:00
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
public AttachmentViewInfo getAttachment() {
|
|
|
|
return attachment;
|
2011-04-24 00:00:10 -04:00
|
|
|
}
|
2012-01-18 00:00:26 -05:00
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
public void enableViewButton() {
|
|
|
|
viewButton.setEnabled(true);
|
2014-10-20 21:06:31 -04:00
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
public void disableViewButton() {
|
|
|
|
viewButton.setEnabled(false);
|
|
|
|
}
|
2011-01-06 11:56:20 -05:00
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
public void setAttachment(AttachmentViewInfo attachment) throws MessagingException {
|
|
|
|
this.attachment = attachment;
|
2012-02-27 14:29:22 -05:00
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
displayAttachmentInformation();
|
2014-10-20 21:06:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayAttachmentInformation() {
|
2012-02-27 15:00:44 -05:00
|
|
|
TextView attachmentName = (TextView) findViewById(R.id.attachment_name);
|
|
|
|
TextView attachmentInfo = (TextView) findViewById(R.id.attachment_info);
|
|
|
|
viewButton = (Button) findViewById(R.id.view);
|
|
|
|
downloadButton = (Button) findViewById(R.id.download);
|
2014-10-20 21:06:31 -04:00
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
if (attachment.size > K9.MAX_ATTACHMENT_DOWNLOAD_SIZE) {
|
2012-02-27 15:00:44 -05:00
|
|
|
viewButton.setVisibility(View.GONE);
|
|
|
|
downloadButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2012-02-27 15:34:18 -05:00
|
|
|
viewButton.setOnClickListener(this);
|
|
|
|
downloadButton.setOnClickListener(this);
|
|
|
|
downloadButton.setOnLongClickListener(this);
|
2012-02-27 15:00:44 -05:00
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
attachmentName.setText(attachment.displayName);
|
|
|
|
attachmentInfo.setText(SizeFormatter.formatSize(getContext(), attachment.size));
|
2011-01-06 11:56:20 -05:00
|
|
|
|
2014-10-20 20:46:46 -04:00
|
|
|
ImageView thumbnail = (ImageView) findViewById(R.id.attachment_icon);
|
|
|
|
new LoadAndDisplayThumbnailAsyncTask(thumbnail).execute();
|
2011-01-06 11:56:20 -05:00
|
|
|
}
|
|
|
|
|
2012-02-27 15:34:18 -05:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
switch (view.getId()) {
|
|
|
|
case R.id.view: {
|
2015-01-15 05:19:32 -05:00
|
|
|
onViewButtonClick();
|
2012-02-27 15:34:18 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.download: {
|
2015-01-15 05:19:32 -05:00
|
|
|
onSaveButtonClick();
|
2012-02-27 15:34:18 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
if (view.getId() == R.id.download) {
|
2015-01-15 05:19:32 -05:00
|
|
|
onSaveButtonLongClick();
|
2012-02-27 15:34:18 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
private void onViewButtonClick() {
|
|
|
|
callback.onViewAttachment(attachment);
|
2011-01-06 11:56:20 -05:00
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
private void onSaveButtonClick() {
|
|
|
|
callback.onSaveAttachment(attachment);
|
2011-01-06 11:56:20 -05:00
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
private void onSaveButtonLongClick() {
|
|
|
|
callback.onSaveAttachmentToUserProvidedDirectory(attachment);
|
2011-01-06 11:56:20 -05:00
|
|
|
}
|
|
|
|
|
2015-01-15 05:19:32 -05:00
|
|
|
public void setCallback(AttachmentViewCallback callback) {
|
2011-04-24 00:00:10 -04:00
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
|
2014-10-20 20:46:46 -04:00
|
|
|
private class LoadAndDisplayThumbnailAsyncTask extends AsyncTask<Void, Void, Bitmap> {
|
|
|
|
private final ImageView thumbnail;
|
|
|
|
|
|
|
|
public LoadAndDisplayThumbnailAsyncTask(ImageView thumbnail) {
|
|
|
|
this.thumbnail = thumbnail;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Bitmap doInBackground(Void... asyncTaskArgs) {
|
|
|
|
return getPreviewIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Bitmap getPreviewIcon() {
|
2015-01-14 03:56:57 -05:00
|
|
|
//FIXME - temporarily disabled
|
|
|
|
return null;
|
|
|
|
// Bitmap icon = null;
|
|
|
|
// try {
|
|
|
|
// InputStream input = context.getContentResolver().openInputStream(
|
|
|
|
// AttachmentProvider.getAttachmentThumbnailUri(account,
|
|
|
|
// part.getAttachmentId(),
|
|
|
|
// 62,
|
|
|
|
// 62));
|
|
|
|
// icon = BitmapFactory.decodeStream(input);
|
|
|
|
// input.close();
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// // We don't care what happened, we just return null for the preview icon.
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return icon;
|
2014-10-20 20:46:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void onPostExecute(Bitmap previewIcon) {
|
|
|
|
if (previewIcon != null) {
|
|
|
|
thumbnail.setImageBitmap(previewIcon);
|
|
|
|
} else {
|
|
|
|
thumbnail.setImageResource(R.drawable.attached_image_placeholder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-06 11:56:20 -05:00
|
|
|
}
|