use of com.fsck.k9.mail.Address 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:
{
new ShareCompat.IntentBuilder(getContext()).setType("text/plain").setText(url).startChooser();
break;
}
case MENU_ITEM_LINK_COPY:
{
String label = getContext().getString(R.string.webview_contextmenu_link_clipboard_label);
clipboardManager.setText(label, url);
break;
}
case MENU_ITEM_LINK_TEXT_COPY:
{
LinkTextHandler linkTextHandler = DI.get(LinkTextHandler.class);
Message message = linkTextHandler.obtainMessage();
webview.requestFocusNodeHref(message);
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);
menu.add(Menu.NONE, MENU_ITEM_LINK_TEXT_COPY, 3, context.getString(R.string.webview_contextmenu_link_text_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 {
downloadImage(uri);
}
break;
}
case MENU_ITEM_IMAGE_COPY:
{
String label = getContext().getString(R.string.webview_contextmenu_image_clipboard_label);
clipboardManager.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);
clipboardManager.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);
clipboardManager.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;
}
}
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageHeader method onAddSenderToContacts.
private void onAddSenderToContacts() {
if (mMessage != null) {
try {
final Address senderEmail = mMessage.getFrom()[0];
mContacts.createContact(senderEmail);
} catch (Exception e) {
Timber.e(e, "Couldn't create contact");
}
}
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class ListHeaders method getListPostAddresses.
public static Address[] getListPostAddresses(Message message) {
String[] headerValues = message.getHeader(LIST_POST_HEADER);
if (headerValues.length < 1) {
return new Address[0];
}
List<Address> listPostAddresses = new ArrayList<>();
for (String headerValue : headerValues) {
Address address = extractAddress(headerValue);
if (address != null) {
listPostAddresses.add(address);
}
}
return listPostAddresses.toArray(new Address[listPostAddresses.size()]);
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class RecipientSelectView method getAddresses.
public Address[] getAddresses() {
List<Recipient> recipients = getObjects();
Address[] address = new Address[recipients.size()];
for (int i = 0; i < address.length; i++) {
address[i] = recipients.get(i).address;
}
return address;
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class RecipientLoaderTest method setupQueryCryptoProvider.
private void setupQueryCryptoProvider(String queriedAddress, Address... contactAddresses) {
MatrixCursor cursor = new MatrixCursor(PROJECTION_CRYPTO_ADDRESSES);
for (Address contactAddress : contactAddresses) {
cursor.addRow(new String[] { queriedAddress, contactAddress.toString() });
}
when(contentResolver.query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")), aryEq(PROJECTION_CRYPTO_ADDRESSES), nullable(String.class), aryEq(new String[] { queriedAddress }), nullable(String.class))).thenReturn(cursor);
}
Aggregations