1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-02 14:02:17 -05:00

Merge pull request #537

This commit is contained in:
cketti 2015-01-29 17:48:28 +01:00
commit 38d3564c57
4 changed files with 115 additions and 134 deletions

View File

@ -43,7 +43,6 @@ import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.util.Rfc822Tokenizer; import android.text.util.Rfc822Tokenizer;
import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
@ -89,6 +88,7 @@ import com.fsck.k9.crypto.PgpData;
import com.fsck.k9.fragment.ProgressDialogFragment; import com.fsck.k9.fragment.ProgressDialogFragment;
import com.fsck.k9.helper.ContactItem; import com.fsck.k9.helper.ContactItem;
import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.SimpleTextWatcher;
import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.helper.HtmlConverter; import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.IdentityHelper; import com.fsck.k9.helper.IdentityHelper;
@ -112,6 +112,7 @@ import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.mailstore.LocalMessage; import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.TempFileBody; import com.fsck.k9.mailstore.TempFileBody;
import com.fsck.k9.mailstore.TempFileMessageBody; import com.fsck.k9.mailstore.TempFileMessageBody;
import com.fsck.k9.ui.EolConvertingEditText;
import com.fsck.k9.view.MessageWebView; import com.fsck.k9.view.MessageWebView;
import org.apache.james.mime4j.codec.EncoderUtil; import org.apache.james.mime4j.codec.EncoderUtil;
@ -297,20 +298,14 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private Button mQuotedTextShow; private Button mQuotedTextShow;
private View mQuotedTextBar; private View mQuotedTextBar;
private ImageButton mQuotedTextEdit; private ImageButton mQuotedTextEdit;
private ImageButton mQuotedTextDelete;
private EolConvertingEditText mQuotedText; private EolConvertingEditText mQuotedText;
private MessageWebView mQuotedHTML; private MessageWebView mQuotedHTML;
private InsertableHtmlContent mQuotedHtmlContent; // Container for HTML reply as it's being built. private InsertableHtmlContent mQuotedHtmlContent; // Container for HTML reply as it's being built.
private View mEncryptLayout;
private CheckBox mCryptoSignatureCheckbox; private CheckBox mCryptoSignatureCheckbox;
private CheckBox mEncryptCheckbox; private CheckBox mEncryptCheckbox;
private TextView mCryptoSignatureUserId; private TextView mCryptoSignatureUserId;
private TextView mCryptoSignatureUserIdRest; private TextView mCryptoSignatureUserIdRest;
private ImageButton mAddToFromContacts;
private ImageButton mAddCcFromContacts;
private ImageButton mAddBccFromContacts;
private PgpData mPgpData = null; private PgpData mPgpData = null;
private String mOpenPgpProvider; private String mOpenPgpProvider;
private OpenPgpServiceConnection mOpenPgpServiceConnection; private OpenPgpServiceConnection mOpenPgpServiceConnection;
@ -409,8 +404,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}; };
private Listener mListener = new Listener(); private Listener mListener = new Listener();
private EmailAddressAdapter mAddressAdapter;
private Validator mAddressValidator;
private FontSizes mFontSizes = K9.getFontSizes(); private FontSizes mFontSizes = K9.getFontSizes();
private ContextThemeWrapper mThemeContext; private ContextThemeWrapper mThemeContext;
@ -521,8 +514,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// theme the whole content according to the theme (except the action bar) // theme the whole content according to the theme (except the action bar)
mThemeContext = new ContextThemeWrapper(this, mThemeContext = new ContextThemeWrapper(this,
K9.getK9ThemeResourceId(K9.getK9ComposerTheme())); K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
View v = ((LayoutInflater) mThemeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)). View v = LayoutInflater.from(mThemeContext).inflate(R.layout.message_compose, null);
inflate(R.layout.message_compose, null);
TypedValue outValue = new TypedValue(); TypedValue outValue = new TypedValue();
// background color needs to be forced // background color needs to be forced
mThemeContext.getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true); mThemeContext.getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
@ -565,8 +557,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mContacts = Contacts.getInstance(MessageCompose.this); mContacts = Contacts.getInstance(MessageCompose.this);
mAddressAdapter = new EmailAddressAdapter(mThemeContext); EmailAddressAdapter mAddressAdapter = new EmailAddressAdapter(mThemeContext);
mAddressValidator = new EmailAddressValidator(); Validator mAddressValidator = new EmailAddressValidator();
mChooseIdentityButton = (Button) findViewById(R.id.identity); mChooseIdentityButton = (Button) findViewById(R.id.identity);
mChooseIdentityButton.setOnClickListener(this); mChooseIdentityButton.setOnClickListener(this);
@ -582,9 +574,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mSubjectView = (EditText) findViewById(R.id.subject); mSubjectView = (EditText) findViewById(R.id.subject);
mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true); mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true);
mAddToFromContacts = (ImageButton) findViewById(R.id.add_to); ImageButton mAddToFromContacts = (ImageButton) findViewById(R.id.add_to);
mAddCcFromContacts = (ImageButton) findViewById(R.id.add_cc); ImageButton mAddCcFromContacts = (ImageButton) findViewById(R.id.add_cc);
mAddBccFromContacts = (ImageButton) findViewById(R.id.add_bcc); ImageButton mAddBccFromContacts = (ImageButton) findViewById(R.id.add_bcc);
mCcWrapper = (LinearLayout) findViewById(R.id.cc_wrapper); mCcWrapper = (LinearLayout) findViewById(R.id.cc_wrapper);
mBccWrapper = (LinearLayout) findViewById(R.id.bcc_wrapper); mBccWrapper = (LinearLayout) findViewById(R.id.bcc_wrapper);
@ -602,7 +595,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mQuotedTextShow = (Button)findViewById(R.id.quoted_text_show); mQuotedTextShow = (Button)findViewById(R.id.quoted_text_show);
mQuotedTextBar = findViewById(R.id.quoted_text_bar); mQuotedTextBar = findViewById(R.id.quoted_text_bar);
mQuotedTextEdit = (ImageButton)findViewById(R.id.quoted_text_edit); mQuotedTextEdit = (ImageButton)findViewById(R.id.quoted_text_edit);
mQuotedTextDelete = (ImageButton)findViewById(R.id.quoted_text_delete); ImageButton mQuotedTextDelete = (ImageButton) findViewById(R.id.quoted_text_delete);
mQuotedText = (EolConvertingEditText)findViewById(R.id.quoted_text); mQuotedText = (EolConvertingEditText)findViewById(R.id.quoted_text);
mQuotedText.getInputExtras(true).putBoolean("allowEmoji", true); mQuotedText.getInputExtras(true).putBoolean("allowEmoji", true);
@ -617,81 +610,34 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
}); });
TextWatcher watcher = new TextWatcher() { TextWatcher draftNeedsChangingTextWatcher = new SimpleTextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int before, int after) {
/* do nothing */
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
mDraftNeedsSaving = true; mDraftNeedsSaving = true;
} }
@Override
public void afterTextChanged(android.text.Editable s) { /* do nothing */ }
}; };
// For watching changes to the To:, Cc:, and Bcc: fields for auto-encryption on a matching TextWatcher signTextWatcher = new SimpleTextWatcher() {
// address.
TextWatcher recipientWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int before, int after) {
/* do nothing */
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mDraftNeedsSaving = true;
}
@Override
public void afterTextChanged(android.text.Editable s) {
/* do nothing */
}
};
TextWatcher sigwatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int before, int after) {
/* do nothing */
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
mDraftNeedsSaving = true; mDraftNeedsSaving = true;
mSignatureChanged = true; mSignatureChanged = true;
} }
@Override
public void afterTextChanged(android.text.Editable s) { /* do nothing */ }
}; };
mToView.addTextChangedListener(recipientWatcher); mToView.addTextChangedListener(draftNeedsChangingTextWatcher);
mCcView.addTextChangedListener(recipientWatcher); mCcView.addTextChangedListener(draftNeedsChangingTextWatcher);
mBccView.addTextChangedListener(recipientWatcher); mBccView.addTextChangedListener(draftNeedsChangingTextWatcher);
mSubjectView.addTextChangedListener(watcher); mSubjectView.addTextChangedListener(draftNeedsChangingTextWatcher);
mMessageContentView.addTextChangedListener(watcher); mMessageContentView.addTextChangedListener(draftNeedsChangingTextWatcher);
mQuotedText.addTextChangedListener(watcher); mQuotedText.addTextChangedListener(draftNeedsChangingTextWatcher);
/* Yes, there really are poeple who ship versions of android without a contact picker */ /* Yes, there really are people who ship versions of android without a contact picker */
if (mContacts.hasContactPicker()) { if (mContacts.hasContactPicker()) {
mAddToFromContacts.setOnClickListener(new OnClickListener() { mAddToFromContacts.setOnClickListener(new DoLaunchOnClickListener(CONTACT_PICKER_TO));
@Override public void onClick(View v) { mAddCcFromContacts.setOnClickListener(new DoLaunchOnClickListener(CONTACT_PICKER_CC));
doLaunchContactPicker(CONTACT_PICKER_TO); mAddBccFromContacts.setOnClickListener(new DoLaunchOnClickListener(CONTACT_PICKER_BCC));
}
});
mAddCcFromContacts.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
doLaunchContactPicker(CONTACT_PICKER_CC);
}
});
mAddBccFromContacts.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
doLaunchContactPicker(CONTACT_PICKER_BCC);
}
});
} else { } else {
mAddToFromContacts.setVisibility(View.GONE); mAddToFromContacts.setVisibility(View.GONE);
mAddCcFromContacts.setVisibility(View.GONE); mAddCcFromContacts.setVisibility(View.GONE);
@ -761,7 +707,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mSignatureView = lowerSignature; mSignatureView = lowerSignature;
upperSignature.setVisibility(View.GONE); upperSignature.setVisibility(View.GONE);
} }
mSignatureView.addTextChangedListener(sigwatcher); mSignatureView.addTextChangedListener(signTextWatcher);
if (!mIdentity.getSignatureUse()) { if (!mIdentity.getSignatureUse()) {
mSignatureView.setVisibility(View.GONE); mSignatureView.setVisibility(View.GONE);
@ -813,23 +759,24 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mMessageReference.flag = Flag.FORWARDED; mMessageReference.flag = Flag.FORWARDED;
} }
mEncryptLayout = findViewById(R.id.layout_encrypt); final View mEncryptLayout = findViewById(R.id.layout_encrypt);
initializeCrypto();
mOpenPgpProvider = mAccount.getOpenPgpProvider();
if (mOpenPgpProvider != null) {
mCryptoSignatureCheckbox = (CheckBox)findViewById(R.id.cb_crypto_signature); mCryptoSignatureCheckbox = (CheckBox)findViewById(R.id.cb_crypto_signature);
mCryptoSignatureCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { final OnCheckedChangeListener updateListener = new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateMessageFormat(); updateMessageFormat();
} }
}); };
mCryptoSignatureCheckbox.setOnCheckedChangeListener(updateListener);
mCryptoSignatureUserId = (TextView)findViewById(R.id.userId); mCryptoSignatureUserId = (TextView)findViewById(R.id.userId);
mCryptoSignatureUserIdRest = (TextView)findViewById(R.id.userIdRest); mCryptoSignatureUserIdRest = (TextView)findViewById(R.id.userIdRest);
mEncryptCheckbox = (CheckBox)findViewById(R.id.cb_encrypt); mEncryptCheckbox = (CheckBox)findViewById(R.id.cb_encrypt);
mEncryptCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { mEncryptCheckbox.setOnCheckedChangeListener(updateListener);
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateMessageFormat();
}
});
if (mSourceMessageBody != null) { if (mSourceMessageBody != null) {
// mSourceMessageBody is set to something when replying to and forwarding decrypted // mSourceMessageBody is set to something when replying to and forwarding decrypted
@ -837,10 +784,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
mEncryptCheckbox.setChecked(true); mEncryptCheckbox.setChecked(true);
} }
initializeCrypto();
mOpenPgpProvider = mAccount.getOpenPgpProvider();
if (mOpenPgpProvider != null) {
// New OpenPGP Provider API // New OpenPGP Provider API
// bind to service // bind to service
@ -2236,11 +2179,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
} }
public void doLaunchContactPicker(int resultId) {
mIgnoreOnPause = true;
startActivityForResult(mContacts.contactPickerIntent(), resultId);
}
private void onAccountChosen(Account account, Identity identity) { private void onAccountChosen(Account account, Identity identity) {
if (!mAccount.equals(account)) { if (!mAccount.equals(account)) {
if (K9.DEBUG) { if (K9.DEBUG) {
@ -3955,34 +3893,18 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} }
} }
/** class DoLaunchOnClickListener implements OnClickListener {
* An {@link EditText} extension with methods that convert line endings from
* {@code \r\n} to {@code \n} and back again when setting and getting text.
*
*/
public static class EolConvertingEditText extends EditText {
public EolConvertingEditText(Context context, AttributeSet attrs) { private final int resultId;
super(context, attrs);
DoLaunchOnClickListener(int resultId) {
this.resultId = resultId;
} }
/** @Override
* Return the text the EolConvertingEditText is displaying. public void onClick(View v) {
* mIgnoreOnPause = true;
* @return A string with any line endings converted to {@code \r\n}. startActivityForResult(mContacts.contactPickerIntent(), resultId);
*/
public String getCharacters() {
return getText().toString().replace("\n", "\r\n");
}
/**
* Sets the string value of the EolConvertingEditText. Any line endings
* in the string will be converted to {@code \n}.
*
* @param text
*/
public void setCharacters(CharSequence text) {
setText(text.toString().replace("\r\n", "\n"));
} }
} }
} }

View File

@ -0,0 +1,22 @@
package com.fsck.k9.helper;
import android.text.Editable;
import android.text.TextWatcher;
/**
* all methods empty - but this way we can have TextWatchers with less boilder-plate where
* we just override the methods we want and not always al 3
*/
public class SimpleTextWatcher implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
}

View File

@ -0,0 +1,37 @@
package com.fsck.k9.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
/**
* An {@link android.widget.EditText} extension with methods that convert line endings from
* {@code \r\n} to {@code \n} and back again when setting and getting text.
*
*/
public class EolConvertingEditText extends EditText {
public EolConvertingEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Return the text the EolConvertingEditText is displaying.
*
* @return A string with any line endings converted to {@code \r\n}.
*/
public String getCharacters() {
return getText().toString().replace("\n", "\r\n");
}
/**
* Sets the string value of the EolConvertingEditText. Any line endings
* in the string will be converted to {@code \n}.
*
* @param text
*/
public void setCharacters(CharSequence text) {
setText(text.toString().replace("\r\n", "\n"));
}
}

View File

@ -217,7 +217,7 @@
<!-- We have to use "wrap_content" (not "0dip") for "layout_height", otherwise the <!-- We have to use "wrap_content" (not "0dip") for "layout_height", otherwise the
EditText won't properly grow in height while the user is typing the message --> EditText won't properly grow in height while the user is typing the message -->
<view <view
class="com.fsck.k9.activity.MessageCompose$EolConvertingEditText" class="com.fsck.k9.ui.EolConvertingEditText"
android:id="@+id/message_content" android:id="@+id/message_content"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -230,7 +230,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<view <view
class="com.fsck.k9.activity.MessageCompose$EolConvertingEditText" class="com.fsck.k9.ui.EolConvertingEditText"
android:id="@+id/upper_signature" android:id="@+id/upper_signature"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -256,7 +256,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<view <view
class="com.fsck.k9.activity.MessageCompose$EolConvertingEditText" class="com.fsck.k9.ui.EolConvertingEditText"
android:id="@+id/quoted_text" android:id="@+id/quoted_text"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -297,7 +297,7 @@
</RelativeLayout> </RelativeLayout>
<view <view
class="com.fsck.k9.activity.MessageCompose$EolConvertingEditText" class="com.fsck.k9.ui.EolConvertingEditText"
android:id="@+id/lower_signature" android:id="@+id/lower_signature"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"