Example usage for android.view MenuItem setIntent

List of usage examples for android.view MenuItem setIntent

Introduction

In this page you can find the example usage for android.view MenuItem setIntent.

Prototype

public MenuItem setIntent(Intent intent);

Source Link

Document

Change the Intent associated with this item.

Usage

From source file:com.silentcircle.contacts.utils.HelpUtils.java

/**
 * 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./*from  w w w  . j av  a2  s  .  c o  m*/
 *
 * @return returns whether the help menu item has been made visible.
 */
public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, String helpUrlString) {
    if (TextUtils.isEmpty(helpUrlString)) {
        // 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 {
        // The help url string exists, so first add in some extra query parameters.
        final Uri fullUri = uriWithAddedParameters(context, Uri.parse(helpUrlString));

        // Then, create an intent that will be fired when the user
        // selects this help menu item.
        Intent intent = new Intent(Intent.ACTION_VIEW, fullUri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

        // Set the intent to the help menu item, show the help menu item in the overflow
        // menu, and make it visible.
        helpMenuItem.setIntent(intent);
        MenuItemCompat.setShowAsAction(helpMenuItem, MenuItem.SHOW_AS_ACTION_NEVER);
        helpMenuItem.setVisible(true);

        // return that the help menu item is visible (i.e., true)
        return true;
    }
}

From source file:com.example.edwin.car2charge.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    MenuItem refresh = menu.findItem(R.id.refresh_option_item);
    refresh.setIntent(carDownloadIntent);
    refreshMenuId = refresh.getItemId();
    return true;//from   w ww.j  a  v a  2 s. c om
}

From source file:com.sagar.sunshine.DetailFragment.java

private void finishCreatingMenu(Menu menu) {
    MenuItem menuItem = menu.findItem(R.id.action_share);
    menuItem.setIntent(createShareForecastIntent());
}

From source file:org.getlantern.firetweet.menu.SupportAccountActionProvider.java

@Override
public void onPrepareSubMenu(final SubMenu subMenu) {
    subMenu.removeGroup(MENU_GROUP);//from w w  w  .j  a  v  a2 s. c  o m
    if (mAccounts == null)
        return;
    for (int i = 0, j = mAccounts.length; i < j; i++) {
        final ParcelableAccount account = mAccounts[i];
        final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name);
        final Intent intent = new Intent();
        intent.putExtra(EXTRA_ACCOUNT, account);
        item.setIntent(intent);
    }
    subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
    if (mAccountIds == null)
        return;
    for (int i = 0, j = subMenu.size(); i < j; i++) {
        final MenuItem item = subMenu.getItem(i);
        if (ArrayUtils.contains(mAccountIds, mAccounts[i].account_id)) {
            item.setChecked(true);
        }
    }
}

From source file:inforuh.eventfinder.ui.DetailActivity.java

private void createMenu(Menu menu, String message) {
    MenuItem item = menu.findItem(R.id.action_share);
    item.setIntent(createShareIntent(message));
}

From source file:org.mariotaku.twidere.menu.AccountToggleProvider.java

@Override
public void onPrepareSubMenu(final SubMenu subMenu) {
    subMenu.removeGroup(MENU_GROUP);/*  ww  w  .  j a va2 s .c  o  m*/
    if (mAccounts == null)
        return;
    for (int i = 0, j = mAccounts.length; i < j; i++) {
        final ParcelableAccount account = mAccounts[i];
        final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name);
        final Intent intent = new Intent();
        intent.putExtra(EXTRA_ACCOUNT, account);
        item.setIntent(intent);
    }
    subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
    for (int i = 0, j = subMenu.size(); i < j; i++) {
        final MenuItem item = subMenu.getItem(i);
        if (mAccounts[i].is_activated) {
            item.setChecked(true);
        }
    }
}

From source file:com.alboteanu.android.sunshine.app.DetailFragment.java

private void finishCreatingMenu(Menu menu) {
    // Retrieve the share menu item
    MenuItem menuItem = menu.findItem(R.id.action_share);
    menuItem.setIntent(createShareForecastIntent());
}

From source file:com.tcity.android.ui.overview.buildconfiguration.BuildConfigurationOverviewActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem item = menu.findItem(R.id.menu_settings);
    item.setIntent(new Intent(this, PreferenceActivity.class));

    return super.onCreateOptionsMenu(menu);
}

From source file:com.by_syk.lib.nanoiconpack.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_whats_new) {
        sp.save("hideLatest" + PkgUtil.getAppVer(this, "%1$s"), true);
        item.setIntent(new Intent(this, WhatsNewActivity.class));
        return super.onOptionsItemSelected(item);
    } else if (id == R.id.menu_search) {
        item.setIntent(new Intent(this, SearchActivity.class));
        return super.onOptionsItemSelected(item);
    } else if (id == R.id.menu_apply) {
        (new ApplyDialog()).show(getSupportFragmentManager(), "applyDialog");
        return true;
    } else if (id == R.id.menu_about) {
        item.setIntent(new Intent(this, AboutActivity.class));
        return super.onOptionsItemSelected(item);
    }/*ww w  .j  a v a 2s. co  m*/
    return super.onOptionsItemSelected(item);
}

From source file:org.zirco.ui.components.CustomPagerAdapter.java

private CustomWebView initializeWebView(CustomWebView webView) {

    webView.setOnTouchListener(mParentActivity);

    webView.setWebViewClient(new CustomWebViewClient(mParentActivity));
    webView.setWebChromeClient(new CustomWebChromeClient(mParentActivity, webView));

    webView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override/*  ww w. j av  a2s.c  o m*/
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            HitTestResult result = ((WebView) v).getHitTestResult();

            int resultType = result.getType();
            if ((resultType == HitTestResult.ANCHOR_TYPE) || (resultType == HitTestResult.IMAGE_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuOpen);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0, R.string.Main_MenuOpenNewTab);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyLinkUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownload);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareLinkUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            } else if (resultType == HitTestResult.IMAGE_TYPE) {
                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuViewImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyImageUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownloadImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareImageUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.EMAIL_TYPE) {

                Intent sendMail = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(WebView.SCHEME_MAILTO + result.getExtra()));

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.Main_MenuSendEmail);
                item.setIntent(sendMail);

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyEmailUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareEmailUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            }
        }
    });

    webView.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            mParentActivity.doDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
        }

    });

    return webView;
}