Search in sources :

Example 11 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageHeader method populate.

public void populate(final Message message, final Account account) {
    final Contacts contacts = K9.showContactName() ? mContacts : null;
    final CharSequence from = MessageHelper.toFriendly(message.getFrom(), contacts);
    final CharSequence to = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
    final CharSequence cc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);
    Address[] fromAddrs = message.getFrom();
    Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
    Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
    boolean fromMe = mMessageHelper.toMe(account, fromAddrs);
    Address counterpartyAddress = null;
    if (fromMe) {
        if (toAddrs.length > 0) {
            counterpartyAddress = toAddrs[0];
        } else if (ccAddrs.length > 0) {
            counterpartyAddress = ccAddrs[0];
        }
    } else if (fromAddrs.length > 0) {
        counterpartyAddress = fromAddrs[0];
    }
    /* We hide the subject by default for each new message, and MessageTitleView might show
         * it later by calling showSubjectLine(). */
    boolean newMessageShown = mMessage == null || mMessage.getId() != message.getId();
    if (newMessageShown) {
        mSubjectView.setVisibility(GONE);
    }
    mMessage = message;
    mAccount = account;
    if (K9.showContactPicture()) {
        mContactBadge.setVisibility(View.VISIBLE);
        mContactsPictureLoader = ContactPicture.getContactPictureLoader(mContext);
    } else {
        mContactBadge.setVisibility(View.GONE);
    }
    if (shouldShowSender(message)) {
        mSenderView.setVisibility(VISIBLE);
        String sender = getResources().getString(R.string.message_view_sender_label, MessageHelper.toFriendly(message.getSender(), contacts));
        mSenderView.setText(sender);
    } else {
        mSenderView.setVisibility(View.GONE);
    }
    final String subject = message.getSubject();
    if (TextUtils.isEmpty(subject)) {
        mSubjectView.setText(mContext.getText(R.string.general_no_subject));
    } else {
        mSubjectView.setText(subject);
    }
    mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);
    String dateTime = DateUtils.formatDateTime(mContext, message.getSentDate().getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR);
    mDateView.setText(dateTime);
    if (K9.showContactPicture()) {
        if (counterpartyAddress != null) {
            Utility.setContactForBadge(mContactBadge, counterpartyAddress);
            mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
        } else {
            mContactBadge.setImageResource(R.drawable.ic_contact_picture);
        }
    }
    mFromView.setText(from);
    updateAddressField(mToView, to, mToLabel);
    updateAddressField(mCcView, cc, mCcLabel);
    mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
    mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
    mFlagged.setChecked(message.isSet(Flag.FLAGGED));
    mChip.setBackgroundColor(mAccount.getChipColor());
    setVisibility(View.VISIBLE);
    if (mSavedState != null) {
        if (mSavedState.additionalHeadersVisible) {
            showAdditionalHeaders();
        }
        mSavedState = null;
    } else {
        hideAdditionalHeaders();
    }
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address) SpannableString(android.text.SpannableString)

Example 12 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessagingController method getInstance.

public static synchronized MessagingController getInstance(Context context) {
    if (inst == null) {
        Context appContext = context.getApplicationContext();
        NotificationController notificationController = NotificationController.newInstance(appContext);
        Contacts contacts = Contacts.getInstance(context);
        TransportProvider transportProvider = TransportProvider.getInstance();
        inst = new MessagingController(appContext, notificationController, contacts, transportProvider);
    }
    return inst;
}
Also used : Context(android.content.Context) Contacts(com.fsck.k9.helper.Contacts) NotificationController(com.fsck.k9.notification.NotificationController) TransportProvider(com.fsck.k9.mail.TransportProvider)

Example 13 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class RecipientLoader method fillContactDataFromCursor.

private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients, Map<String, Recipient> recipientMap) {
    while (cursor.moveToNext()) {
        String name = cursor.getString(INDEX_NAME);
        String email = cursor.getString(INDEX_EMAIL);
        long contactId = cursor.getLong(INDEX_CONTACT_ID);
        String lookupKey = cursor.getString(INDEX_LOOKUP_KEY);
        // already exists? just skip then
        if (recipientMap.containsKey(email)) {
            // TODO merge? do something else? what do we do?
            continue;
        }
        int addressType = cursor.getInt(INDEX_EMAIL_TYPE);
        String addressLabel = null;
        switch(addressType) {
            case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
                {
                    addressLabel = getContext().getString(R.string.address_type_home);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
                {
                    addressLabel = getContext().getString(R.string.address_type_work);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_OTHER:
                {
                    addressLabel = getContext().getString(R.string.address_type_other);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE:
                {
                    // mobile isn't listed as an option contacts app, but it has a constant so we better support it
                    addressLabel = getContext().getString(R.string.address_type_mobile);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM:
                {
                    addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL);
                    break;
                }
        }
        Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey);
        if (recipient.isValidEmailAddress()) {
            Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));
            recipient.photoThumbnailUri = photoUri;
            recipientMap.put(email, recipient);
            recipients.add(recipient);
        }
    }
    cursor.close();
}
Also used : Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) Uri(android.net.Uri)

Example 14 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageCompose method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (UpgradeDatabases.actionUpgradeDatabases(this, getIntent())) {
        finish();
        return;
    }
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    if (K9.getK9ComposerThemeSetting() != K9.Theme.USE_GLOBAL) {
        // theme the whole content according to the theme (except the action bar)
        ContextThemeWrapper themeContext = new ContextThemeWrapper(this, K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
        // this is the top level activity element, it has no root
        @SuppressLint("InflateParams") View v = LayoutInflater.from(themeContext).inflate(R.layout.message_compose, null);
        TypedValue outValue = new TypedValue();
        // background color needs to be forced
        themeContext.getTheme().resolveAttribute(R.attr.messageViewBackgroundColor, outValue, true);
        v.setBackgroundColor(outValue.data);
        setContentView(v);
    } else {
        setContentView(R.layout.message_compose);
    }
    initializeActionBar();
    // on api level 15, setContentView() shows the progress bar for some reason...
    setProgressBarIndeterminateVisibility(false);
    final Intent intent = getIntent();
    String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
    relatedMessageReference = MessageReference.parse(messageReferenceString);
    final String accountUuid = (relatedMessageReference != null) ? relatedMessageReference.getAccountUuid() : intent.getStringExtra(EXTRA_ACCOUNT);
    account = Preferences.getPreferences(this).getAccount(accountUuid);
    if (account == null) {
        account = Preferences.getPreferences(this).getDefaultAccount();
    }
    if (account == null) {
        /*
             * There are no accounts set up. This should not have happened. Prompt the
             * user to set up an account as an acceptable bailout.
             */
        startActivity(new Intent(this, Accounts.class));
        changesMadeSinceLastSave = false;
        finish();
        return;
    }
    contacts = Contacts.getInstance(MessageCompose.this);
    chooseIdentityButton = (TextView) findViewById(R.id.identity);
    chooseIdentityButton.setOnClickListener(this);
    RecipientMvpView recipientMvpView = new RecipientMvpView(this);
    ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
    recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView, account, composePgpInlineDecider, new ReplyToParser(), this);
    recipientPresenter.updateCryptoStatus();
    subjectView = (EditText) findViewById(R.id.subject);
    subjectView.getInputExtras(true).putBoolean("allowEmoji", true);
    EolConvertingEditText upperSignature = (EolConvertingEditText) findViewById(R.id.upper_signature);
    EolConvertingEditText lowerSignature = (EolConvertingEditText) findViewById(R.id.lower_signature);
    QuotedMessageMvpView quotedMessageMvpView = new QuotedMessageMvpView(this);
    quotedMessagePresenter = new QuotedMessagePresenter(this, quotedMessageMvpView, account);
    attachmentPresenter = new AttachmentPresenter(getApplicationContext(), attachmentMvpView, getLoaderManager(), this);
    messageContentView = (EolConvertingEditText) findViewById(R.id.message_content);
    messageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
    attachmentsView = (LinearLayout) findViewById(R.id.attachments);
    TextWatcher draftNeedsChangingTextWatcher = new SimpleTextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMadeSinceLastSave = true;
        }
    };
    TextWatcher signTextWatcher = new SimpleTextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMadeSinceLastSave = true;
            signatureChanged = true;
        }
    };
    recipientMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
    quotedMessageMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
    subjectView.addTextChangedListener(draftNeedsChangingTextWatcher);
    messageContentView.addTextChangedListener(draftNeedsChangingTextWatcher);
    /*
         * We set this to invisible by default. Other methods will turn it back on if it's
         * needed.
         */
    quotedMessagePresenter.showOrHideQuotedText(QuotedTextMode.NONE);
    subjectView.setOnFocusChangeListener(this);
    messageContentView.setOnFocusChangeListener(this);
    if (savedInstanceState != null) {
        /*
             * This data gets used in onCreate, so grab it here instead of onRestoreInstanceState
             */
        relatedMessageProcessed = savedInstanceState.getBoolean(STATE_KEY_SOURCE_MESSAGE_PROCED, false);
    }
    if (initFromIntent(intent)) {
        action = Action.COMPOSE;
        changesMadeSinceLastSave = true;
    } else {
        String action = intent.getAction();
        if (ACTION_COMPOSE.equals(action)) {
            this.action = Action.COMPOSE;
        } else if (ACTION_REPLY.equals(action)) {
            this.action = Action.REPLY;
        } else if (ACTION_REPLY_ALL.equals(action)) {
            this.action = Action.REPLY_ALL;
        } else if (ACTION_FORWARD.equals(action)) {
            this.action = Action.FORWARD;
        } else if (ACTION_EDIT_DRAFT.equals(action)) {
            this.action = Action.EDIT_DRAFT;
        } else {
            // This shouldn't happen
            Timber.w("MessageCompose was started with an unsupported action");
            this.action = Action.COMPOSE;
        }
    }
    if (identity == null) {
        identity = account.getIdentity(0);
    }
    if (account.isSignatureBeforeQuotedText()) {
        signatureView = upperSignature;
        lowerSignature.setVisibility(View.GONE);
    } else {
        signatureView = lowerSignature;
        upperSignature.setVisibility(View.GONE);
    }
    updateSignature();
    signatureView.addTextChangedListener(signTextWatcher);
    if (!identity.getSignatureUse()) {
        signatureView.setVisibility(View.GONE);
    }
    requestReadReceipt = account.isMessageReadReceiptAlways();
    updateFrom();
    if (!relatedMessageProcessed) {
        if (action == Action.REPLY || action == Action.REPLY_ALL || action == Action.FORWARD || action == Action.EDIT_DRAFT) {
            messageLoaderHelper = new MessageLoaderHelper(this, getLoaderManager(), getFragmentManager(), messageLoaderCallbacks);
            internalMessageHandler.sendEmptyMessage(MSG_PROGRESS_ON);
            Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT);
            messageLoaderHelper.asyncStartOrResumeLoadingMessage(relatedMessageReference, cachedDecryptionResult);
        }
        if (action != Action.EDIT_DRAFT) {
            String alwaysBccString = account.getAlwaysBcc();
            if (!TextUtils.isEmpty(alwaysBccString)) {
                recipientPresenter.addBccAddresses(Address.parse(alwaysBccString));
            }
        }
    }
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        relatedMessageReference = relatedMessageReference.withModifiedFlag(Flag.ANSWERED);
    }
    if (action == Action.REPLY || action == Action.REPLY_ALL || action == Action.EDIT_DRAFT) {
        //change focus to message body.
        messageContentView.requestFocus();
    } else {
        // Explicitly set focus to "To:" input field (see issue 2998)
        recipientMvpView.requestFocusOnToField();
    }
    if (action == Action.FORWARD) {
        relatedMessageReference = relatedMessageReference.withModifiedFlag(Flag.FORWARDED);
    }
    updateMessageFormat();
    // Set font size of input controls
    int fontSize = K9.getFontSizes().getMessageComposeInput();
    recipientMvpView.setFontSizes(K9.getFontSizes(), fontSize);
    quotedMessageMvpView.setFontSizes(K9.getFontSizes(), fontSize);
    K9.getFontSizes().setViewTextSize(subjectView, fontSize);
    K9.getFontSizes().setViewTextSize(messageContentView, fontSize);
    K9.getFontSizes().setViewTextSize(signatureView, fontSize);
    updateMessageFormat();
    setTitle();
    currentMessageBuilder = (MessageBuilder) getLastNonConfigurationInstance();
    if (currentMessageBuilder != null) {
        setProgressBarIndeterminateVisibility(true);
        currentMessageBuilder.reattachCallback(this);
    }
}
Also used : ComposePgpInlineDecider(com.fsck.k9.message.ComposePgpInlineDecider) RecipientPresenter(com.fsck.k9.activity.compose.RecipientPresenter) EolConvertingEditText(com.fsck.k9.ui.EolConvertingEditText) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) View(android.view.View) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) TextView(android.widget.TextView) AttachmentMvpView(com.fsck.k9.activity.compose.AttachmentPresenter.AttachmentMvpView) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) SuppressLint(android.annotation.SuppressLint) QuotedMessagePresenter(com.fsck.k9.ui.compose.QuotedMessagePresenter) ReplyToParser(com.fsck.k9.helper.ReplyToParser) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) ContextThemeWrapper(android.view.ContextThemeWrapper) SuppressLint(android.annotation.SuppressLint) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) TextWatcher(android.text.TextWatcher) AttachmentPresenter(com.fsck.k9.activity.compose.AttachmentPresenter) TypedValue(android.util.TypedValue)

Aggregations

Address (com.fsck.k9.mail.Address)8 Contacts (com.fsck.k9.helper.Contacts)6 Test (org.junit.Test)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Cursor (android.database.Cursor)1 Parcelable (android.os.Parcelable)1 SpannableString (android.text.SpannableString)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 MenuItem (android.view.MenuItem)1 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)1 View (android.view.View)1