Search in sources :

Example 6 with Contacts

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

the class NotificationContentCreator method getMessageSender.

private String getMessageSender(Account account, Message message) {
    boolean isSelf = false;
    final Contacts contacts = K9.showContactName() ? Contacts.getInstance(context) : null;
    final Address[] fromAddresses = message.getFrom();
    if (fromAddresses != null) {
        isSelf = account.isAnIdentity(fromAddresses);
        if (!isSelf && fromAddresses.length > 0) {
            return MessageHelper.toFriendly(fromAddresses[0], contacts).toString();
        }
    }
    if (isSelf) {
        // show To: if the message was sent from me
        Address[] recipients = message.getRecipients(Message.RecipientType.TO);
        if (recipients != null && recipients.length > 0) {
            return context.getString(R.string.message_to_fmt, MessageHelper.toFriendly(recipients[0], contacts).toString());
        }
    }
    return null;
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address)

Example 7 with Contacts

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

the class MessageCompose method onMessageBuildSuccess.

@Override
public void onMessageBuildSuccess(MimeMessage message, boolean isDraft) {
    if (isDraft) {
        changesMadeSinceLastSave = false;
        currentMessageBuilder = null;
        if (action == Action.EDIT_DRAFT && relatedMessageReference != null) {
            message.setUid(relatedMessageReference.getUid());
        }
        // TODO more appropriate logic here? not sure
        boolean saveRemotely = !recipientPresenter.getCurrentCryptoStatus().shouldUsePgpMessageBuilder();
        new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler, message, draftId, saveRemotely).execute();
        if (finishAfterDraftSaved) {
            finish();
        } else {
            setProgressBarIndeterminateVisibility(false);
        }
    } else {
        currentMessageBuilder = null;
        new SendMessageTask(getApplicationContext(), account, contacts, message, draftId != INVALID_DRAFT_ID ? draftId : null, relatedMessageReference).execute();
        finish();
    }
}
Also used : SaveMessageTask(com.fsck.k9.activity.compose.SaveMessageTask)

Example 8 with Contacts

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

the class MessageTopView method shouldShowPicturesFromSender.

private boolean shouldShowPicturesFromSender(ShowPictures showPicturesSetting, Message message) {
    if (showPicturesSetting != ShowPictures.ONLY_FROM_CONTACTS) {
        return false;
    }
    String senderEmailAddress = getSenderEmailAddress(message);
    if (senderEmailAddress == null) {
        return false;
    }
    Contacts contacts = Contacts.getInstance(getContext());
    return contacts.isInContacts(senderEmailAddress);
}
Also used : Contacts(com.fsck.k9.helper.Contacts)

Example 9 with Contacts

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

the class MessageHelperTest method testToFriendlyArray.

@Test
public void testToFriendlyArray() throws Exception {
    Address address1 = new Address("test@testor.com", "Tim Testor");
    Address address2 = new Address("foo@bar.com", "Foo Bar");
    Address[] addresses = new Address[] { address1, address2 };
    assertEquals("Tim Testor,Foo Bar", MessageHelper.toFriendly(addresses, contacts).toString());
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 10 with Contacts

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

the class MessageContainerView method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu);
    WebView webview = (WebView) v;
    WebView.HitTestResult result = webview.getHitTestResult();
    if (result == null) {
        return;
    }
    int type = result.getType();
    Context context = getContext();
    switch(type) {
        case HitTestResult.SRC_ANCHOR_TYPE:
            {
                final String url = result.getExtra();
                OnMenuItemClickListener listener = new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch(item.getItemId()) {
                            case MENU_ITEM_LINK_VIEW:
                                {
                                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                                    startActivityIfAvailable(getContext(), intent);
                                    break;
                                }
                            case MENU_ITEM_LINK_SHARE:
                                {
                                    Intent intent = new Intent(Intent.ACTION_SEND);
                                    intent.setType("text/plain");
                                    intent.putExtra(Intent.EXTRA_TEXT, url);
                                    startActivityIfAvailable(getContext(), intent);
                                    break;
                                }
                            case MENU_ITEM_LINK_COPY:
                                {
                                    String label = getContext().getString(R.string.webview_contextmenu_link_clipboard_label);
                                    mClipboardManager.setText(label, url);
                                    break;
                                }
                        }
                        return true;
                    }
                };
                menu.setHeaderTitle(url);
                menu.add(Menu.NONE, MENU_ITEM_LINK_VIEW, 0, context.getString(R.string.webview_contextmenu_link_view_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_LINK_SHARE, 1, context.getString(R.string.webview_contextmenu_link_share_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_LINK_COPY, 2, context.getString(R.string.webview_contextmenu_link_copy_action)).setOnMenuItemClickListener(listener);
                break;
            }
        case HitTestResult.IMAGE_TYPE:
        case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
            {
                final Uri uri = Uri.parse(result.getExtra());
                if (uri == null) {
                    return;
                }
                final AttachmentViewInfo attachmentViewInfo = getAttachmentViewInfoIfCidUri(uri);
                final boolean inlineImage = attachmentViewInfo != null;
                OnMenuItemClickListener listener = new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch(item.getItemId()) {
                            case MENU_ITEM_IMAGE_VIEW:
                                {
                                    if (inlineImage) {
                                        attachmentCallback.onViewAttachment(attachmentViewInfo);
                                    } else {
                                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                        startActivityIfAvailable(getContext(), intent);
                                    }
                                    break;
                                }
                            case MENU_ITEM_IMAGE_SAVE:
                                {
                                    if (inlineImage) {
                                        attachmentCallback.onSaveAttachment(attachmentViewInfo);
                                    } else {
                                        //TODO: Use download manager
                                        new DownloadImageTask(getContext()).execute(uri.toString());
                                    }
                                    break;
                                }
                            case MENU_ITEM_IMAGE_COPY:
                                {
                                    String label = getContext().getString(R.string.webview_contextmenu_image_clipboard_label);
                                    mClipboardManager.setText(label, uri.toString());
                                    break;
                                }
                        }
                        return true;
                    }
                };
                menu.setHeaderTitle(inlineImage ? context.getString(R.string.webview_contextmenu_image_title) : uri.toString());
                menu.add(Menu.NONE, MENU_ITEM_IMAGE_VIEW, 0, context.getString(R.string.webview_contextmenu_image_view_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_IMAGE_SAVE, 1, inlineImage ? context.getString(R.string.webview_contextmenu_image_save_action) : context.getString(R.string.webview_contextmenu_image_download_action)).setOnMenuItemClickListener(listener);
                if (!inlineImage) {
                    menu.add(Menu.NONE, MENU_ITEM_IMAGE_COPY, 2, context.getString(R.string.webview_contextmenu_image_copy_action)).setOnMenuItemClickListener(listener);
                }
                break;
            }
        case HitTestResult.PHONE_TYPE:
            {
                final String phoneNumber = result.getExtra();
                OnMenuItemClickListener listener = new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch(item.getItemId()) {
                            case MENU_ITEM_PHONE_CALL:
                                {
                                    Uri uri = Uri.parse(WebView.SCHEME_TEL + phoneNumber);
                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                    startActivityIfAvailable(getContext(), intent);
                                    break;
                                }
                            case MENU_ITEM_PHONE_SAVE:
                                {
                                    Contacts contacts = Contacts.getInstance(getContext());
                                    contacts.addPhoneContact(phoneNumber);
                                    break;
                                }
                            case MENU_ITEM_PHONE_COPY:
                                {
                                    String label = getContext().getString(R.string.webview_contextmenu_phone_clipboard_label);
                                    mClipboardManager.setText(label, phoneNumber);
                                    break;
                                }
                        }
                        return true;
                    }
                };
                menu.setHeaderTitle(phoneNumber);
                menu.add(Menu.NONE, MENU_ITEM_PHONE_CALL, 0, context.getString(R.string.webview_contextmenu_phone_call_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_PHONE_SAVE, 1, context.getString(R.string.webview_contextmenu_phone_save_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_PHONE_COPY, 2, context.getString(R.string.webview_contextmenu_phone_copy_action)).setOnMenuItemClickListener(listener);
                break;
            }
        case WebView.HitTestResult.EMAIL_TYPE:
            {
                final String email = result.getExtra();
                OnMenuItemClickListener listener = new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch(item.getItemId()) {
                            case MENU_ITEM_EMAIL_SEND:
                                {
                                    Uri uri = Uri.parse(WebView.SCHEME_MAILTO + email);
                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                    startActivityIfAvailable(getContext(), intent);
                                    break;
                                }
                            case MENU_ITEM_EMAIL_SAVE:
                                {
                                    Contacts contacts = Contacts.getInstance(getContext());
                                    contacts.createContact(new Address(email));
                                    break;
                                }
                            case MENU_ITEM_EMAIL_COPY:
                                {
                                    String label = getContext().getString(R.string.webview_contextmenu_email_clipboard_label);
                                    mClipboardManager.setText(label, email);
                                    break;
                                }
                        }
                        return true;
                    }
                };
                menu.setHeaderTitle(email);
                menu.add(Menu.NONE, MENU_ITEM_EMAIL_SEND, 0, context.getString(R.string.webview_contextmenu_email_send_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_EMAIL_SAVE, 1, context.getString(R.string.webview_contextmenu_email_save_action)).setOnMenuItemClickListener(listener);
                menu.add(Menu.NONE, MENU_ITEM_EMAIL_COPY, 2, context.getString(R.string.webview_contextmenu_email_copy_action)).setOnMenuItemClickListener(listener);
                break;
            }
    }
}
Also used : Context(android.content.Context) Address(com.fsck.k9.mail.Address) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Uri(android.net.Uri) HitTestResult(android.webkit.WebView.HitTestResult) Contacts(com.fsck.k9.helper.Contacts) MessageWebView(com.fsck.k9.view.MessageWebView) WebView(android.webkit.WebView) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo)

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