Search in sources :

Example 1 with OnMenuItemClickListener

use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by DirtyUnicorns.

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;
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) Intent(android.content.Intent) MenuItem(android.view.MenuItem)

Example 2 with OnMenuItemClickListener

use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by AOSPA.

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;
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) Intent(android.content.Intent) MenuItem(android.view.MenuItem)

Example 3 with OnMenuItemClickListener

use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by ResurrectionRemix.

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;
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) Intent(android.content.Intent) MenuItem(android.view.MenuItem)

Example 4 with OnMenuItemClickListener

use of android.view.MenuItem.OnMenuItemClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DreamSettings method createMenuItem.

private MenuItem createMenuItem(Menu menu, int titleRes, int actionEnum, boolean isEnabled, final Runnable onClick) {
    MenuItem item = menu.add(titleRes);
    item.setShowAsAction(actionEnum);
    item.setEnabled(isEnabled);
    item.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            onClick.run();
            return true;
        }
    });
    return item;
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MenuItem(android.view.MenuItem)

Example 5 with OnMenuItemClickListener

use of android.view.MenuItem.OnMenuItemClickListener in project AndroidChromium by JackyAndroid.

the class SnippetArticleViewHolder method createContextMenu.

@Override
protected void createContextMenu(ContextMenu menu) {
    RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.CardLongPressed", mArticle.mPosition);
    mArticle.recordAgeAndScore("NewTabPage.Snippets.CardLongPressed");
    OnMenuItemClickListener listener = new ContextMenuItemClickListener(mArticle, mNewTabPageManager, getRecyclerView());
    // Create a context menu akin to the one shown for MostVisitedItems.
    if (mNewTabPageManager.isOpenInNewWindowEnabled()) {
        addContextMenuItem(menu, ID_OPEN_IN_NEW_WINDOW, R.string.contextmenu_open_in_other_window, listener);
    }
    addContextMenuItem(menu, ID_OPEN_IN_NEW_TAB, R.string.contextmenu_open_in_new_tab, listener);
    if (mNewTabPageManager.isOpenInIncognitoEnabled()) {
        addContextMenuItem(menu, ID_OPEN_IN_INCOGNITO_TAB, R.string.contextmenu_open_in_incognito_tab, listener);
    }
    // TODO(peconn): Only show 'Save for Offline' for appropriate snippet types.
    if (SnippetsConfig.isSaveToOfflineEnabled() && OfflinePageBridge.canSavePage(mArticle.mUrl)) {
        addContextMenuItem(menu, ID_SAVE_FOR_OFFLINE, R.string.contextmenu_save_link, listener);
    }
    addContextMenuItem(menu, ID_REMOVE, R.string.remove, listener);
    // Disable touch events on the RecyclerView while the context menu is open. This is to
    // prevent the user long pressing to get the context menu then on the same press scrolling
    // or swiping to dismiss an item (eg. https://crbug.com/638854, 638555, 636296)
    final NewTabPageRecyclerView recyclerView = (NewTabPageRecyclerView) itemView.getParent();
    recyclerView.setTouchEnabled(false);
    mNewTabPageManager.addContextMenuCloseCallback(new Callback<Menu>() {

        @Override
        public void onResult(Menu result) {
            recyclerView.setTouchEnabled(true);
            mNewTabPageManager.removeContextMenuCloseCallback(this);
        }
    });
}
Also used : NewTabPageRecyclerView(org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu)

Aggregations

OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)9 MenuItem (android.view.MenuItem)8 Intent (android.content.Intent)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 Context (android.content.Context)1 Uri (android.net.Uri)1 Spanned (android.text.Spanned)1 URLSpan (android.text.style.URLSpan)1 ContextMenu (android.view.ContextMenu)1 Menu (android.view.Menu)1 WebView (android.webkit.WebView)1 HitTestResult (android.webkit.WebView.HitTestResult)1 Contacts (com.fsck.k9.helper.Contacts)1 Address (com.fsck.k9.mail.Address)1 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)1 MessageWebView (com.fsck.k9.view.MessageWebView)1 NewTabPageRecyclerView (org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView)1