2011-02-10 19:29:46 -05:00
|
|
|
package com.fsck.k9.view;
|
|
|
|
|
2011-02-11 10:09:15 -05:00
|
|
|
import android.app.Activity;
|
2011-02-10 19:29:46 -05:00
|
|
|
import android.content.Context;
|
|
|
|
import android.util.AttributeSet;
|
2011-02-11 10:09:15 -05:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2011-02-10 19:29:46 -05:00
|
|
|
import android.widget.LinearLayout;
|
2011-02-11 10:09:15 -05:00
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
import com.fsck.k9.controller.MessagingController;
|
|
|
|
import com.fsck.k9.controller.MessagingListener;
|
|
|
|
import com.fsck.k9.crypto.CryptoProvider;
|
|
|
|
import com.fsck.k9.crypto.PgpData;
|
|
|
|
import com.fsck.k9.mail.*;
|
|
|
|
import com.fsck.k9.mail.internet.MimeUtility;
|
|
|
|
import com.fsck.k9.mail.store.LocalStore;
|
|
|
|
|
2011-02-10 19:29:46 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2011-02-11 10:09:15 -05:00
|
|
|
public class SingleMessageView extends LinearLayout {
|
|
|
|
private boolean mScreenReaderEnabled;
|
|
|
|
private MessageCryptoView mCryptoView;
|
|
|
|
private MessageWebView mMessageContentView;
|
|
|
|
private AccessibleWebView mAccessibleMessageContentView;
|
|
|
|
private MessageHeader mHeaderContainer;
|
|
|
|
private LinearLayout mAttachments;
|
|
|
|
private View mShowPicturesSection;
|
|
|
|
private boolean mShowPictures;
|
|
|
|
private Button mDownloadRemainder;
|
|
|
|
private Activity mActivity;
|
|
|
|
|
|
|
|
|
|
|
|
public void initialize(Activity activity, Boolean isScreenReaderActive) {
|
|
|
|
mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
|
|
|
|
mAccessibleMessageContentView = (AccessibleWebView) findViewById(R.id.accessible_message_content);
|
|
|
|
mAttachments = (LinearLayout) findViewById(R.id.attachments);
|
|
|
|
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
|
|
|
|
mCryptoView = (MessageCryptoView) findViewById(R.id.layout_decrypt);
|
|
|
|
mCryptoView.setActivity(activity);
|
|
|
|
mCryptoView.setupChildViews();
|
|
|
|
mShowPicturesSection = findViewById(R.id.show_pictures_section);
|
|
|
|
mShowPictures = false;
|
|
|
|
|
|
|
|
mActivity = activity;
|
|
|
|
|
|
|
|
mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
|
|
|
|
mMessageContentView.configure();
|
|
|
|
|
|
|
|
|
|
|
|
mAttachments.setVisibility(View.GONE);
|
|
|
|
if (isScreenReaderActive) {
|
|
|
|
mAccessibleMessageContentView.setVisibility(View.VISIBLE);
|
|
|
|
mMessageContentView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
mAccessibleMessageContentView.setVisibility(View.GONE);
|
|
|
|
mMessageContentView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
mScreenReaderEnabled = isScreenReaderActive;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-10 19:29:46 -05:00
|
|
|
public SingleMessageView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
2011-02-11 10:09:15 -05:00
|
|
|
|
|
|
|
public boolean showPictures() {
|
|
|
|
return mShowPictures;
|
|
|
|
}
|
|
|
|
public void setShowPictures(Boolean show) {
|
|
|
|
mShowPictures = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void blockNetworkData(Boolean block) {
|
|
|
|
mMessageContentView.blockNetworkData(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Button downloadRemainderButton() {
|
|
|
|
return mDownloadRemainder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showShowPicturesSection(boolean show) {
|
|
|
|
mShowPicturesSection.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHeaders(final Message message, Account account) {
|
|
|
|
try {
|
|
|
|
mHeaderContainer.populate(message, account);
|
|
|
|
mHeaderContainer.setOnFlagListener(new OnClickListener() {
|
|
|
|
@Override public void onClick(View v) {
|
|
|
|
if (message != null) {
|
|
|
|
//TODO: reenable onFlag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception me) {
|
|
|
|
Log.e(K9.LOG_TAG, "setHeaders - error", me);
|
|
|
|
}
|
|
|
|
if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
|
|
|
|
mDownloadRemainder.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
mDownloadRemainder.setEnabled(true);
|
|
|
|
mDownloadRemainder.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void showAllHeaders() {
|
|
|
|
mHeaderContainer.onShowAdditionalHeaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean additionalHeadersVisible() {
|
|
|
|
return mHeaderContainer.additionalHeadersVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void loadBodyFromUrl(Message message, String url) {
|
|
|
|
mMessageContentView.loadUrl(url);
|
|
|
|
// TODO reenable: updateCryptoLayout(cryptoProvider, pgpData, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadBodyFromText(CryptoProvider cryptoProvider, PgpData pgpData, Message message, String emailText, String contentType) {
|
|
|
|
if (mScreenReaderEnabled) {
|
|
|
|
mAccessibleMessageContentView.loadDataWithBaseURL("http://", emailText, contentType, "utf-8", null);
|
|
|
|
} else {
|
|
|
|
mMessageContentView.loadDataWithBaseURL("http://", emailText, contentType, "utf-8", null);
|
|
|
|
mMessageContentView.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
updateCryptoLayout(cryptoProvider, pgpData, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateCryptoLayout(CryptoProvider cp, PgpData pgpData, Message message) {
|
|
|
|
mCryptoView.updateLayout(cp, pgpData, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAttachmentsEnabled(boolean enabled) {
|
|
|
|
for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
|
|
|
|
AttachmentView attachment = (AttachmentView) mAttachments.getChildAt(i);
|
|
|
|
attachment.viewButton.setEnabled(enabled);
|
|
|
|
attachment.downloadButton.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeAllAttachments() {
|
|
|
|
for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
|
|
|
|
mAttachments.removeView(mAttachments.getChildAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderAttachments(Part part, int depth,
|
|
|
|
|
|
|
|
Message message, Account account, MessagingController controller, MessagingListener listener) throws MessagingException {
|
|
|
|
|
|
|
|
if (part.getBody() instanceof Multipart) {
|
|
|
|
Multipart mp = (Multipart) part.getBody();
|
|
|
|
for (int i = 0; i < mp.getCount(); i++) {
|
|
|
|
renderAttachments(mp.getBodyPart(i), depth + 1, message, account, controller, listener);
|
|
|
|
}
|
|
|
|
} else if (part instanceof LocalStore.LocalAttachmentBodyPart) {
|
|
|
|
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
|
|
|
// Inline parts with a content-id are almost certainly components of an HTML message
|
|
|
|
// not attachments. Don't show attachment download buttons for them.
|
|
|
|
if (contentDisposition != null &&
|
|
|
|
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)")
|
|
|
|
&& part.getHeader("Content-ID") != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LayoutInflater inflater = mActivity.getLayoutInflater();
|
|
|
|
AttachmentView view = (AttachmentView)inflater.inflate(R.layout.message_view_attachment, null);
|
|
|
|
if (view.populateFromPart(part, message, account, controller, listener)) {
|
|
|
|
addAttachment(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void addAttachment(View attachmentView) {
|
|
|
|
mAttachments.addView(attachmentView);
|
|
|
|
mAttachments.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
public void zoom(KeyEvent event) {
|
|
|
|
if (mScreenReaderEnabled) {
|
|
|
|
mAccessibleMessageContentView.zoomIn();
|
|
|
|
} else {
|
|
|
|
if (event.isShiftPressed()) {
|
|
|
|
mMessageContentView.zoomIn();
|
|
|
|
} else {
|
|
|
|
mMessageContentView.zoomOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void beginSelectingText() {
|
|
|
|
mMessageContentView.emulateShiftHeld();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void resetView() {
|
|
|
|
|
|
|
|
mMessageContentView.scrollTo(0, 0);
|
|
|
|
mHeaderContainer.setVisibility(View.GONE);
|
|
|
|
mMessageContentView.clearView();
|
|
|
|
mAttachments.removeAllViews();
|
|
|
|
}
|
2011-02-10 19:29:46 -05:00
|
|
|
}
|