mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
OpenPGP header and sidebar tests
This commit is contained in:
parent
4c78d12fc6
commit
b781ace4fa
@ -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<AttachmentViewInfo> attachments;
|
||||
final public boolean encrypted;
|
||||
final public OpenPgpSignatureResult signatureResult;
|
||||
final public PendingIntent pgpPendingIntent;
|
||||
|
||||
MessageViewContainer(String text, List<AttachmentViewInfo> attachments) {
|
||||
this.text = text;
|
||||
this.attachments = attachments;
|
||||
this.signatureResult = null;
|
||||
this.encrypted = false;
|
||||
this.pgpPendingIntent = null;
|
||||
}
|
||||
|
||||
MessageViewContainer(String text, List<AttachmentViewInfo> attachments,
|
||||
OpenPgpSignatureResult signatureResult) {
|
||||
OpenPgpSignatureResult signatureResult, boolean encrypted,
|
||||
PendingIntent pgpPendingIntent) {
|
||||
this.text = text;
|
||||
this.attachments = attachments;
|
||||
this.signatureResult = signatureResult;
|
||||
this.encrypted = encrypted;
|
||||
this.pgpPendingIntent = pgpPendingIntent;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
@ -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 <b>true</b> setting here means that
|
||||
* network data will be blocked.
|
||||
|
@ -4,14 +4,22 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- OpenPGP header -->
|
||||
<ViewStub
|
||||
android:id="@+id/openpgp_header_stub"
|
||||
android:inflatedId="@+id/openpgp_header"
|
||||
android:layout="@layout/message_view_openpgp_header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Content area -->
|
||||
<com.fsck.k9.view.MessageWebView
|
||||
android:id="@+id/message_content"
|
||||
android:layout_below="@+id/openpgp_header"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"/>
|
||||
android:layout_width="fill_parent" />
|
||||
|
||||
<!-- Attachments area -->
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/attachments_container"
|
||||
android:orientation="vertical"
|
||||
@ -29,15 +37,14 @@
|
||||
android:id="@+id/show_hidden_attachments"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/message_view_show_more_attachments_action"/>
|
||||
android:text="@string/message_view_show_more_attachments_action" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/hidden_attachments"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dip"/>
|
||||
android:padding="4dip" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.fsck.k9.ui.messageview.MessageContainerView>
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.fsck.k9.ui.messageview.MessageOpenPgpView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.fsck.k9.ui.messageview.OpenPgpHeaderView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_decrypt_openpgp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -9,8 +9,8 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
@ -203,4 +203,4 @@
|
||||
android:text="@string/openpgp_get_key"
|
||||
android:visibility="gone" />
|
||||
|
||||
</com.fsck.k9.ui.messageview.MessageOpenPgpView>
|
||||
</com.fsck.k9.ui.messageview.OpenPgpHeaderView>
|
@ -6,5 +6,4 @@
|
||||
<color name="openpgp_orange">#FF8800</color>
|
||||
<color name="openpgp_green">#669900</color>
|
||||
<color name="openpgp_blue">#336699</color>
|
||||
<color name="openpgp_blue">#336699</color>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user