From ba979808fef2db618f8b0f79c90190ecf2b0aefd Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 27 Feb 2012 21:34:18 +0100 Subject: [PATCH] Use AttachmentView instance as onClick and onLongClick listener --- src/com/fsck/k9/view/AttachmentView.java | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index 64ff1f08d..5eccda9eb 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -18,6 +18,8 @@ import android.os.Environment; import android.util.AttributeSet; import android.util.Log; import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -40,7 +42,7 @@ import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBodyPart; import com.fsck.k9.provider.AttachmentProvider; -public class AttachmentView extends FrameLayout { +public class AttachmentView extends FrameLayout implements OnClickListener, OnLongClickListener { /** * Regular expression that represents characters we won't allow in file names. * @@ -184,30 +186,9 @@ public class AttachmentView extends FrameLayout { downloadButton.setVisibility(View.GONE); } - viewButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - onViewButtonClicked(); - return; - } - }); - - - downloadButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - onSaveButtonClicked(); - return; - } - }); - downloadButton.setOnLongClickListener(new OnLongClickListener() { - - @Override - public boolean onLongClick(View v) { - callback.showFileBrowser(AttachmentView.this); - return true; - } - }); + viewButton.setOnClickListener(this); + downloadButton.setOnClickListener(this); + downloadButton.setOnLongClickListener(this); attachmentName.setText(name); attachmentInfo.setText(SizeFormatter.formatSize(mContext, size)); @@ -221,6 +202,30 @@ public class AttachmentView extends FrameLayout { return firstClassAttachment; } + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.view: { + onViewButtonClicked(); + break; + } + case R.id.download: { + onSaveButtonClicked(); + break; + } + } + } + + @Override + public boolean onLongClick(View view) { + if (view.getId() == R.id.download) { + callback.showFileBrowser(this); + return true; + } + + return false; + } + private Bitmap getPreviewIcon() { try { return BitmapFactory.decodeStream(