From b781ace4fad0fec92d569188750e89c22e97f5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 28 Jan 2015 11:30:29 +0100 Subject: [PATCH] OpenPGP header and sidebar tests --- .../fsck/k9/mailstore/MessageViewInfo.java | 11 +++++- .../ui/messageview/MessageContainerView.java | 30 ++++++++++----- ...penPgpView.java => OpenPgpHeaderView.java} | 38 ++++++++++--------- .../java/com/fsck/k9/view/MessageWebView.java | 22 +++++++++++ .../src/main/res/layout/message_container.xml | 17 ++++++--- ...ut.xml => message_view_openpgp_header.xml} | 8 ++-- k9mail/src/main/res/values/colors.xml | 1 - 7 files changed, 89 insertions(+), 38 deletions(-) rename k9mail/src/main/java/com/fsck/k9/ui/messageview/{MessageOpenPgpView.java => OpenPgpHeaderView.java} (93%) rename k9mail/src/main/res/layout/{message_view_openpgp_layout.xml => message_view_openpgp_header.xml} (97%) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfo.java b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfo.java index d254f114c..05a1b3d77 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfo.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfo.java @@ -1,6 +1,8 @@ package com.fsck.k9.mailstore; +import android.app.PendingIntent; + import java.util.ArrayList; import java.util.List; @@ -23,19 +25,26 @@ public class MessageViewInfo { final public String text; final public List attachments; + final public boolean encrypted; final public OpenPgpSignatureResult signatureResult; + final public PendingIntent pgpPendingIntent; MessageViewContainer(String text, List attachments) { this.text = text; this.attachments = attachments; this.signatureResult = null; + this.encrypted = false; + this.pgpPendingIntent = null; } MessageViewContainer(String text, List attachments, - OpenPgpSignatureResult signatureResult) { + OpenPgpSignatureResult signatureResult, boolean encrypted, + PendingIntent pgpPendingIntent) { this.text = text; this.attachments = attachments; this.signatureResult = signatureResult; + this.encrypted = encrypted; + this.pgpPendingIntent = pgpPendingIntent; } } diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageContainerView.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageContainerView.java index 6f0a687f4..e93c48066 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageContainerView.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageContainerView.java @@ -15,6 +15,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; +import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.os.Parcel; @@ -31,29 +32,24 @@ import android.view.MenuItem.OnMenuItemClickListener; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnCreateContextMenuListener; +import android.view.ViewStub; import android.webkit.WebView; import android.webkit.WebView.HitTestResult; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.Toast; -import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.R; -import com.fsck.k9.crypto.PgpData; import com.fsck.k9.helper.ClipboardManager; import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.FileHelper; -import com.fsck.k9.helper.HtmlConverter; import com.fsck.k9.helper.UrlEncodingHelper; -import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.Address; -import com.fsck.k9.mail.Flag; -import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mailstore.AttachmentViewInfo; -import com.fsck.k9.mailstore.MessageViewInfo; import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer; import com.fsck.k9.provider.AttachmentProvider.AttachmentProviderColumns; @@ -86,8 +82,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene }; private static final int DISPLAY_NAME_INDEX = 1; - - private MessageOpenPgpViewOld mOpenPgpView; + private ViewStub mOpenPgpHeaderStub; private MessageWebView mMessageContentView; private LinearLayout mAttachments; private Button mShowHiddenAttachments; @@ -97,6 +92,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene private View mShowAttachmentsAction; private boolean mShowPictures; private boolean mHasAttachments; + private boolean mHasOpenPgpInfo; private LayoutInflater mInflater; private Contacts mContacts; private AttachmentViewCallback attachmentCallback; @@ -110,6 +106,8 @@ public class MessageContainerView extends LinearLayout implements OnClickListene public void initialize(Fragment fragment, AttachmentViewCallback attachmentCallback) { this.attachmentCallback = attachmentCallback; + mOpenPgpHeaderStub = (ViewStub) findViewById(R.id.openpgp_header_stub); + Activity activity = fragment.getActivity(); mMessageContentView = (MessageWebView) findViewById(R.id.message_content); mMessageContentView.configure(); @@ -432,6 +430,13 @@ public class MessageContainerView extends LinearLayout implements OnClickListene throws MessagingException { resetView(); +// mHasOpenPgpInfo = (messageViewContainer.signatureResult != null +// || messageViewContainer.encrypted); +// if (mHasOpenPgpInfo) { + renderOpenPgpHeader(messageViewContainer); + mMessageContentView.setSidebar(true, Color.parseColor("#ff444444")); +// } + // Save the text so we can reset the WebView when the user clicks the "Show pictures" button mText = messageViewContainer.text; @@ -492,6 +497,13 @@ public class MessageContainerView extends LinearLayout implements OnClickListene mMessageContentView.setText(emailText); } + public void renderOpenPgpHeader(MessageViewContainer messageContainer) { + // inflate real header into stub + OpenPgpHeaderView view = (OpenPgpHeaderView) mOpenPgpHeaderStub.inflate(); + // view.setCallback(attachmentCallback); + view.setOpenPgpData(messageContainer.signatureResult, messageContainer.encrypted); + } + public void renderAttachments(MessageViewContainer messageContainer) throws MessagingException { for (AttachmentViewInfo attachment : messageContainer.attachments) { AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, null); diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageOpenPgpView.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/OpenPgpHeaderView.java similarity index 93% rename from k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageOpenPgpView.java rename to k9mail/src/main/java/com/fsck/k9/ui/messageview/OpenPgpHeaderView.java index 73a8ec91f..6f3e66d27 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageOpenPgpView.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/OpenPgpHeaderView.java @@ -1,7 +1,6 @@ package com.fsck.k9.ui.messageview; -import android.app.PendingIntent; import android.content.Context; import android.graphics.PorterDuff; import android.util.AttributeSet; @@ -13,7 +12,9 @@ import com.fsck.k9.R; import org.openintents.openpgp.OpenPgpSignatureResult; -public class MessageOpenPgpView extends LinearLayout { +public class OpenPgpHeaderView extends LinearLayout { + private OpenPgpSignatureResult signatureResult; + private boolean encrypted; private Context mContext; @@ -26,15 +27,22 @@ public class MessageOpenPgpView extends LinearLayout { private TextView mResultSignatureEmail; // private PendingIntent mMissingKeyPI; +// private static final int REQUEST_CODE_DECRYPT_VERIFY = 12; - private static final int REQUEST_CODE_DECRYPT_VERIFY = 12; - - public MessageOpenPgpView(Context context, AttributeSet attrs) { + public OpenPgpHeaderView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } - public void setupChildViews() { + public void setOpenPgpData(OpenPgpSignatureResult signatureResult, + boolean encrypted) { + this.signatureResult = signatureResult; + this.encrypted = encrypted; + + displayOpenPgpView(); + } + + public void displayOpenPgpView() { mResultEncryptionIcon = (ImageView) findViewById(R.id.result_encryption_icon); mResultEncryptionText = (TextView) findViewById(R.id.result_encryption_text); mResultSignatureIcon = (ImageView) findViewById(R.id.result_signature_icon); @@ -49,31 +57,25 @@ public class MessageOpenPgpView extends LinearLayout { // getMissingKey(); // } // }); - } // public void setFragment(Fragment fragment) { // mFragment = (MessageViewFragment) fragment; // } - /** - * Fill the decrypt layout with signature data, if known, make controls - * visible, if they should be visible. - */ - public void updateLayout(final OpenPgpSignatureResult signatureResult, - boolean decryptedData, - PendingIntent getMissingKeyIntent) { - if (decryptedData) { - // encrypted-only + if (encrypted) { setStatusImage(mContext, mResultEncryptionIcon, mResultEncryptionText, STATE_ENCRYPTED); // MessageOpenPgpView.this.setBackgroundColor(mContext.getResources().getColor( // R.color.openpgp_blue)); // mText.setText(R.string.openpgp_successful_decryption); - + } else { + setStatusImage(mContext, mResultEncryptionIcon, mResultEncryptionText, STATE_NOT_ENCRYPTED); } - if (signatureResult != null) { + if (signatureResult == null) { + setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_NOT_SIGNED); + } else { switch (signatureResult.getStatus()) { case OpenPgpSignatureResult.SIGNATURE_ERROR: setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_INVALID); diff --git a/k9mail/src/main/java/com/fsck/k9/view/MessageWebView.java b/k9mail/src/main/java/com/fsck/k9/view/MessageWebView.java index 0f64194e2..4fb3e5367 100644 --- a/k9mail/src/main/java/com/fsck/k9/view/MessageWebView.java +++ b/k9mail/src/main/java/com/fsck/k9/view/MessageWebView.java @@ -2,6 +2,9 @@ package com.fsck.k9.view; import android.content.Context; import android.content.pm.PackageManager; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -16,6 +19,9 @@ import com.fsck.k9.helper.HtmlSanitizer; public class MessageWebView extends RigidWebView { + private Paint sidebarPaint = new Paint(); + private boolean sidebarEnabled = false; + private int sidebarColor = 0; public MessageWebView(Context context) { super(context); @@ -29,6 +35,22 @@ public class MessageWebView extends RigidWebView { super(context, attrs, defStyle); } + public void setSidebar(boolean enable, int color) { + sidebarEnabled = enable; + sidebarColor = color; + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (sidebarEnabled) { + sidebarPaint.setColor(sidebarColor); + sidebarPaint.setStrokeWidth(40); + sidebarPaint.setStyle(Paint.Style.FILL); + canvas.drawLine(0, 0, 0, getHeight(), sidebarPaint); + } + } + /** * Configure a web view to load or not load network data. A true setting here means that * network data will be blocked. diff --git a/k9mail/src/main/res/layout/message_container.xml b/k9mail/src/main/res/layout/message_container.xml index cbcddd8d8..61064d9e7 100644 --- a/k9mail/src/main/res/layout/message_container.xml +++ b/k9mail/src/main/res/layout/message_container.xml @@ -4,14 +4,22 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + + android:layout_width="fill_parent" /> - + android:text="@string/message_view_show_more_attachments_action" /> + android:padding="4dip" /> - \ No newline at end of file diff --git a/k9mail/src/main/res/layout/message_view_openpgp_layout.xml b/k9mail/src/main/res/layout/message_view_openpgp_header.xml similarity index 97% rename from k9mail/src/main/res/layout/message_view_openpgp_layout.xml rename to k9mail/src/main/res/layout/message_view_openpgp_header.xml index 5441c624d..05e72439f 100644 --- a/k9mail/src/main/res/layout/message_view_openpgp_layout.xml +++ b/k9mail/src/main/res/layout/message_view_openpgp_header.xml @@ -1,5 +1,5 @@ - @@ -203,4 +203,4 @@ android:text="@string/openpgp_get_key" android:visibility="gone" /> - + diff --git a/k9mail/src/main/res/values/colors.xml b/k9mail/src/main/res/values/colors.xml index a8b257aa5..724ba796c 100644 --- a/k9mail/src/main/res/values/colors.xml +++ b/k9mail/src/main/res/values/colors.xml @@ -6,5 +6,4 @@ #FF8800 #669900 #336699 - #336699