use of android.view.MenuItem.OnMenuItemClickListener 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;
}
}
}
use of android.view.MenuItem.OnMenuItemClickListener in project Notes by MiCode.
the class NoteEditText method onCreateContextMenu.
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
if (urls.length == 1) {
int defaultResId = 0;
for (String schema : sSchemaActionResMap.keySet()) {
if (urls[0].getURL().indexOf(schema) >= 0) {
defaultResId = sSchemaActionResMap.get(schema);
break;
}
}
if (defaultResId == 0) {
defaultResId = R.string.note_link_other;
}
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// goto a new intent
urls[0].onClick(NoteEditText.this);
return true;
}
});
}
}
super.onCreateContextMenu(menu);
}
use of android.view.MenuItem.OnMenuItemClickListener in project platform_frameworks_base by android.
the class HelpUtils method prepareHelpMenuItem.
/**
* Prepares the help menu item by doing the following.
* - If the helpUrlString is empty or null, the help menu item is made invisible.
* - Otherwise, this makes the help menu item visible and sets the intent for the help menu
* item to view the URL.
*
* @return returns whether the help menu item has been made visible.
*/
public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem, String helpUriString, String backupContext) {
if (Global.getInt(activity.getContentResolver(), Global.DEVICE_PROVISIONED, 0) == 0) {
return false;
}
if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible.
helpMenuItem.setVisible(false);
// return that the help menu item is not visible (i.e. false)
return false;
} else {
final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// menu, and make it visible.
if (intent != null) {
helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(activity, MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK, intent.getStringExtra(EXTRA_CONTEXT));
try {
activity.startActivityForResult(intent, 0);
} catch (ActivityNotFoundException exc) {
Log.e(TAG, "No activity found for intent: " + intent);
}
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true);
} else {
helpMenuItem.setVisible(false);
return false;
}
// return that the help menu item is visible (i.e., true)
return true;
}
}
use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by crdroidandroid.
the class HelpUtils method prepareHelpMenuItem.
/**
* Prepares the help menu item by doing the following.
* - If the helpUrlString is empty or null, the help menu item is made invisible.
* - Otherwise, this makes the help menu item visible and sets the intent for the help menu
* item to view the URL.
*
* @return returns whether the help menu item has been made visible.
*/
public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem, String helpUriString, String backupContext) {
if (Global.getInt(activity.getContentResolver(), Global.DEVICE_PROVISIONED, 0) == 0) {
return false;
}
if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible.
helpMenuItem.setVisible(false);
// return that the help menu item is not visible (i.e. false)
return false;
} else {
final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// menu, and make it visible.
if (intent != null) {
helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(activity, MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK, intent.getStringExtra(EXTRA_CONTEXT));
try {
activity.startActivityForResult(intent, 0);
} catch (ActivityNotFoundException exc) {
Log.e(TAG, "No activity found for intent: " + intent);
}
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true);
} else {
helpMenuItem.setVisible(false);
return false;
}
// return that the help menu item is visible (i.e., true)
return true;
}
}
Aggregations