Java Code Examples for android.view.MenuItem#setOnMenuItemClickListener()

The following examples show how to use android.view.MenuItem#setOnMenuItemClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserContextMenuListener.java    From YiBo with Apache License 2.0 7 votes vote down vote up
private void analyzeUserMenu(final Adapter adapter, final User user, ContextMenu menu, final Context context) {
	menu.setHeaderTitle(R.string.menu_title_blog);
    int order = 0;

    MenuItem commentMenu = menu.add(0, 1, order++, R.string.menu_group_member_user_profile);
    Intent commentIntent = new Intent(context, ProfileActivity.class);
    commentIntent.putExtra("USER", user);
    commentMenu.setIntent(commentIntent);

    MenuItem unfollowMenu = menu.add(0, 2, order++, R.string.menu_group_member_unfollow);
    unfollowMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(MenuItem item) {
			CacheAdapter<User> cacheAdapter = (CacheAdapter<User>)AdapterUtil.getCacheAdapter(adapter);
			GroupMemberUnfollowTask task = new GroupMemberUnfollowTask(cacheAdapter, user);
			task.execute();
			return false;
		}
    });
    
    MenuItem messageMenu = menu.add(0, 2, order++, R.string.menu_group_member_message);
    Intent messageIntent = new Intent(context, EditDirectMessageActivity.class);
    messageIntent.putExtra("DISPLAY_NAME", user.getDisplayName());
	messageMenu.setIntent(messageIntent);
}
 
Example 2
Source File: ProductsActivity.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
    MenuItem searchItem = menu.findItem(R.id.imageview_search);
    searchItem.setOnMenuItemClickListener(new ShowSearchFieldOnClickListener(this));

    MenuItem sortItem = menu.findItem(R.id.imageview_sort);
    sortItem.setOnMenuItemClickListener(new SortProductsOnClickListener(this, listId));

    MenuItem deleteItem = menu.findItem(R.id.imageview_delete);
    deleteItem.setOnMenuItemClickListener(new ShowDeleteProductsOnClickListener(this, listId));

    sortItem.setVisible(menusVisible);
    deleteItem.setVisible(menusVisible);
    return super.onPrepareOptionsMenu(menu);
}
 
Example 3
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.hadis, menu);

    mSwitch = menu.findItem(R.id.favswitch);
    mFav = menu.findItem(R.id.fav);
    setCurrentPage(mPager.getCurrentItem());

    MenuItem item = menu.findItem(R.id.menu_item_share);
    item.setOnMenuItemClickListener(item1 -> {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
        return true;
    });

    item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example 4
Source File: Main.java    From redalert-android with Apache License 2.0 6 votes vote down vote up
void initializeSettingsButton(Menu OptionsMenu) {
    // Add refresh in Action Bar
    MenuItem settingsItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.settings));

    // Set up the view
    settingsItem.setIcon(R.drawable.ic_settings);

    // Specify the show flags
    MenuItemCompat.setShowAsAction(settingsItem, MenuItem.SHOW_AS_ACTION_ALWAYS);

    // On click, go to Settings
    settingsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // Start settings activity
            goToSettings(false);

            // Consume event
            return true;
        }
    });
}
 
Example 5
Source File: GetBooksActivity.java    From BookyMcBookface with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onLongClick(final View v) {

    PopupMenu p = new PopupMenu(this, v);
    MenuItem m = p.getMenu().add("Delete");

    m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            list.removeView(v);
            db.deleteWebSite((String)v.getTag());
            return true;
        }
    });
    p.show();
    return true;
}
 
Example 6
Source File: ActivityHome.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

	final MenuItem add = menu.add("Quit TinyGSN");

	add.setOnMenuItemClickListener(new OnMenuItemClickListener() {
		public boolean onMenuItemClick(final MenuItem item) {
			finish();
			return true;
		}
	});

	return super.onCreateOptionsMenu(menu);
}
 
Example 7
Source File: DialtactsActivity.java    From coursera-android with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.dialtacts_options, menu);

    // set up intents and onClick listeners
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);

    callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent());
    searchMenuItem.setOnMenuItemClickListener(mSearchMenuItemClickListener);
    filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener);
    addContactOptionMenuItem.setIntent(
            new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));

    return true;
}
 
Example 8
Source File: UploadFragment.java    From abelana with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem uploadMenu = menu.add(R.string.upload_menu_action);
    uploadMenu.setIcon(R.drawable.ic_done_white_24dp);
    uploadMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    uploadMenu.setOnMenuItemClickListener(this);
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 9
Source File: ErrorsFragment.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
private void initToolbar() {
    if (!(requireActivity() instanceof QueueActivity)) return;
    QueueActivity activity = (QueueActivity) requireActivity();
    MenuItem redownloadAllMenu = activity.getToolbar().getMenu().findItem(R.id.action_redownload_all);
    redownloadAllMenu.setOnMenuItemClickListener(item -> {
        // Don't do anything if the queue is empty
        if (0 == itemAdapter.getAdapterItemCount()) return true;
            // Just do it if the queue has a single item
        else if (1 == itemAdapter.getAdapterItemCount()) redownloadAll();
            // Ask if there's more than 1 item
        else
            new MaterialAlertDialogBuilder(requireContext(), ThemeHelper.getIdForCurrentTheme(requireContext(), R.style.Theme_Light_Dialog))
                    .setIcon(R.drawable.ic_warning)
                    .setCancelable(false)
                    .setTitle(R.string.app_name)
                    .setMessage(getString(R.string.confirm_redownload_all, fastAdapter.getItemCount()))
                    .setPositiveButton(R.string.yes,
                            (dialog1, which) -> {
                                dialog1.dismiss();
                                redownloadAll();
                            })
                    .setNegativeButton(R.string.no,
                            (dialog12, which) -> dialog12.dismiss())
                    .create()
                    .show();
        return true;
    });
    MenuItem invertMenu = activity.getToolbar().getMenu().findItem(R.id.action_invert_queue);
    invertMenu.setOnMenuItemClickListener(item -> {
        viewModel.invertQueue();
        return true;
    });
}
 
Example 10
Source File: DappBrowserFragment.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private void setupMenu(View baseView)
{
    refresh = baseView.findViewById(R.id.refresh);
    final MenuItem reload = toolbar.getMenu().findItem(R.id.action_reload);
    final MenuItem share = toolbar.getMenu().findItem(R.id.action_share);
    final MenuItem scan = toolbar.getMenu().findItem(R.id.action_scan);
    final MenuItem add = toolbar.getMenu().findItem(R.id.action_add_to_my_dapps);

    if (reload != null) reload.setOnMenuItemClickListener(menuItem -> {
        reloadPage();
        return true;
    });
    if (share != null) share.setOnMenuItemClickListener(menuItem -> {
        if (web3.getUrl() != null && currentFragment != null && currentFragment.equals(DAPP_BROWSER)) {
            if (getContext() != null) viewModel.share(getContext(), web3.getUrl());
        }
        else
        {
            displayNothingToShare();
        }
        return true;
    });
    if (scan != null) scan.setOnMenuItemClickListener(menuItem -> {
        viewModel.startScan(getActivity());
        return true;
    });
    if (add != null) add.setOnMenuItemClickListener(menuItem -> {
        viewModel.addToMyDapps(getContext(), currentWebpageTitle, urlTv.getText().toString());
        return true;
    });
}
 
Example 11
Source File: General.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
void initializeShareButton(Menu OptionsMenu) {
    // Add share button
    MenuItem shareItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.share));

    // Set up the view
    shareItem.setIcon(R.drawable.ic_share);

    // Specify the show flags
    MenuItemCompat.setShowAsAction(shareItem, MenuItem.SHOW_AS_ACTION_ALWAYS);

    // On click, open share
    shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // Prepare share intent
            Intent shareIntent = new Intent(Intent.ACTION_SEND);

            // Set as text/plain
            shareIntent.setType("text/plain");

            // Add text
            shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.shareMessage));

            // Show chooser
            startActivity(Intent.createChooser(shareIntent, getString(R.string.shareDesc)));

            // Consume event
            return true;
        }
    });
}
 
Example 12
Source File: HeroListFragment.java    From tup.dota2recipe with Apache License 2.0 5 votes vote down vote up
/**
 * 创建英雄属性筛选子菜单
 * 
 * @param cMenu
 *            当前菜单项
 * @param cMenuQueryKeyId
 * @param cSubMenuKeysId
 *            当前菜单关联的子菜单项资源ID
 * @param cSubMenuValues
 *            当前菜单关联的子菜单项 Values
 * @param menuItemClickListener
 *            创建后的子菜单单击监听
 */
private void createHeroOptionsSubMenu(MenuItem cMenu, int cMenuQueryKeyId,
        int cSubMenuKeysId, String[] cSubMenuValues,
        MenuItem.OnMenuItemClickListener menuItemClickListener) {
    if (cMenu == null || menuItemClickListener == null) {
        return;
    }

    final SubMenu cSubMenu = cMenu.getSubMenu();
    final String[] cSubMenuKeys = this.getResources().getStringArray(cSubMenuKeysId);
    MenuItem cMenuItem = null;
    int cIndex = 0;
    for (String cMenuKey : cSubMenuKeys) {
        cMenuItem = cSubMenu.add(0, cIndex++, 0, cMenuKey);
        cMenuItem.setOnMenuItemClickListener(menuItemClickListener);
    }

    // 设置菜单默认值
    final String queryKey = menu_hero_query_keys[cMenuQueryKeyId];
    if (!queryKey.equals(KEY_MENU_HERO_QUERY_ALL)
            && !queryKey.equals(KEY_MENU_HERO_QUERY_DEFAULT)
            && cSubMenuKeys != null) {
        final int queryValueIndex = Utils.indexOf(cSubMenuValues, queryKey);
        if (queryValueIndex >= 0 && cSubMenuKeys.length > queryValueIndex) {
            cMenu.setTitle(cSubMenuKeys[queryValueIndex]);
        }
    }
}
 
Example 13
Source File: SwapWorkflowActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
private void setUpNextButton(Menu menu, @StringRes int titleResId) {
    MenuItem next = menu.findItem(R.id.action_next);
    CharSequence title = getString(titleResId);
    next.setTitle(title);
    next.setTitleCondensed(title);
    MenuItemCompat.setShowAsAction(next,
            MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            sendNext();
            return true;
        }
    });
}
 
Example 14
Source File: ItemsDetailActivity.java    From tup.dota2recipe with Apache License 2.0 5 votes vote down vote up
/**
 * fill MenuItem Check AddCollection
 */
private void tryFillMenuCheckAddCollection() {
    if (mMenuCheckAddCollection == null || mItemsItem == null) {
        return;
    }

    final MenuItem check = mMenuCheckAddCollection;
    check.setChecked(mItemsItem.hasFavorite == 1);
    Utils.configureStarredMenuItem(check, mItemsItem.isrecipe);
    if (mItemsItem.isrecipe) {
        return;
    }

    check.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final boolean isChecked = !item.isChecked();
            final ItemsItem items = mItemsItem;
            item.setChecked(isChecked);

            Utils.configureStarredMenuItem(item, items.isrecipe);
            items.hasFavorite = isChecked ? 1 : 0;
            if (isChecked) {
                final FavoriteItem c = new FavoriteItem();
                c.keyName = items.keyName;
                c.type = FavoriteItem.KEY_TYPE_ITEMS;
                DBAdapter.getInstance().addFavorite(c);
            } else {
                DBAdapter.getInstance().deleteFavorite(items.keyName);
            }
            return true;
        }
    });

}
 
Example 15
Source File: MainActivity.java    From Rainville with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mRainApplication.isMeizuDevice()) {
        getMenuInflater().inflate(R.menu.main, menu);
        MenuItem menuItem = menu.findItem(R.id.action_play);
        if (menuItem != null) {
            menuItem.setOnMenuItemClickListener(mFrontPanelFragment);
            mFrontPanelFragment.setPlayMenuItem(menuItem);
        }
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 16
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 5 votes vote down vote up
/**
 * Handle click events for the MenuItem.
 *
 * @param menuItem MenuItem that opens the search
 */
public void setMenuItem(@NonNull MenuItem menuItem) {
    menuItem.setOnMenuItemClickListener(item -> {
        showSearch();
        return true;
    });
}
 
Example 17
Source File: AlertView.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
void initializeShareButton(Menu OptionsMenu) {
    // Add refresh in Action Bar
    MenuItem shareItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.shareAlert));

    // Set up the view
    shareItem.setIcon(R.drawable.ic_share);

    // Specify the show flags
    MenuItemCompat.setShowAsAction(shareItem, MenuItem.SHOW_AS_ACTION_ALWAYS);

    // On click, open share
    shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // Prepare share intent
            Intent shareIntent = new Intent(Intent.ACTION_SEND);

            // Set as text/plain
            shareIntent.setType("text/plain");

            // Add text
            shareIntent.putExtra(Intent.EXTRA_TEXT, getShareMessage());

            // Show chooser
            startActivity(Intent.createChooser(shareIntent, getString(R.string.shareAlert)));

            // Consume event
            return true;
        }
    });
}
 
Example 18
Source File: QueueFragment.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
private void initToolbar() {
    if (!(requireActivity() instanceof QueueActivity)) return;
    QueueActivity activity = (QueueActivity) requireActivity();
    MenuItem cancelAllMenu = activity.getToolbar().getMenu().findItem(R.id.action_cancel_all);
    cancelAllMenu.setOnMenuItemClickListener(item -> {
        // Don't do anything if the queue is empty
        if (0 == itemAdapter.getAdapterItemCount()) return true;
            // Just do it if the queue has a single item
        else if (1 == itemAdapter.getAdapterItemCount()) onCancelAll();
            // Ask if there's more than 1 item
        else
            new MaterialAlertDialogBuilder(requireContext(), ThemeHelper.getIdForCurrentTheme(requireContext(), R.style.Theme_Light_Dialog))
                    .setIcon(R.drawable.ic_warning)
                    .setCancelable(false)
                    .setTitle(R.string.app_name)
                    .setMessage(R.string.confirm_cancel_all)
                    .setPositiveButton(R.string.yes,
                            (dialog1, which) -> {
                                dialog1.dismiss();
                                onCancelAll();
                            })
                    .setNegativeButton(R.string.no,
                            (dialog12, which) -> dialog12.dismiss())
                    .create()
                    .show();
        return true;
    });
    MenuItem settingsMenu = activity.getToolbar().getMenu().findItem(R.id.action_queue_prefs);
    settingsMenu.setOnMenuItemClickListener(item -> {
        onSettingsClick();
        return true;
    });
    MenuItem invertMenu = activity.getToolbar().getMenu().findItem(R.id.action_invert_queue);
    invertMenu.setOnMenuItemClickListener(item -> {
        viewModel.invertQueue();
        return true;
    });
    errorStatsMenu = activity.getToolbar().getMenu().findItem(R.id.action_error_stats);
    errorStatsMenu.setOnMenuItemClickListener(item -> {
        showErrorStats();
        return true;
    });
}
 
Example 19
Source File: FragmentMainFeatured.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((IToolbarHolder) getActivity()).getToolbar().setVisibility(View.VISIBLE);

    //Init fragments views
    View view = inflater.inflate(R.layout.fragment_main_featured, container, false);
    lnInternetError = (LinearLayout) view.findViewById(R.id.lnInternetError);
    pbLoadingFeatured = (ProgressBar) view.findViewById(R.id.pbLoadingFeatured);
    rvMain = (AutofitRecyclerView) view.findViewById(R.id.rvMain);
    lvMain = (ListView) view.findViewById(R.id.lvMain);
    lvMain.setOnItemClickListener(this);

    //Toolbar
    if (getActivity() instanceof IToolbarHolder) {
        MenuItem searchMenuItem = ((IToolbarHolder) getActivity()).getToolbar().getMenu().findItem(R.id.action_search);
        searchMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                FragmentSearch fragmentSearch = new FragmentSearch();
                fragmentSearch.setSearchType(MediaItemType.RADIO);
                IFragmentsManager iFragmentsManager = (IFragmentsManager) getActivity();
                if (iFragmentsManager != null) {
                    iFragmentsManager.showFragment(R.id.fl_content, fragmentSearch, FragmentSearch.TAG);
                }
                return false;
            }
        });
    }

    //Featured adapter
    mediaItemsAdapter = new MediaItemsAdapter(getActivity(), R.layout.card_media_item_vertical,
            R.layout.media_item_title, RadioItem.withOnlyBannersHeader());
    if (getActivity() instanceof IFragmentsManager) {
        mediaItemsAdapter.setFragmentsManager((IFragmentsManager) getActivity());
    }
    mediaItemsAdapter.setRoundedButtonsLayout(R.layout.rounded_buttons_item);
    mediaItemsAdapter.setContentLoadListener(this);
    mediaItemsAdapter.setiRoundButtonClicked(iRoundButtonClicked);

    //Featured recycle view
    rvMain.setHasFixedSize(true);
    rvMain.setAdapter(mediaItemsAdapter);
    rvMain.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            int viewType = mediaItemsAdapter.getItemViewType(position);
            if (currentRoundBtnMode > 0) {
                return viewType != MediaItemsAdapter.HEADER ? 1 : rvMain.getSpanCount();
            } else {
                return (viewType != MediaItemsAdapter.HEADER && viewType != MediaItemsAdapter.BANNERS_LAYOUT
                        && viewType != MediaItemsAdapter.ROUNDED_BUTTONS) ? 1 : rvMain.getSpanCount();
            }
        }
    });
    rvMain.setVisibility(View.INVISIBLE);

    //Load tops from remote server
    showTops();

    //Open search fragment backed from other activity which was started from search
    if (getActivity().getIntent().hasExtra(ActivityPlayer.ACTIVITY_STARTED_FROM_IN_DEPTH)) {
        FragmentSearch.openFromIntent(getActivity());
    }

    currentRoundBtnMode = -1;

    return view;
}
 
Example 20
Source File: AbstractActivity.java    From aedict with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Adds a menu item to given menu which launches given activity.
 * 
 * @param context
 *            the owning context
 * @param menu
 *            the menu
 * @param caption
 *            the menu item caption
 * @param icon
 *            the menu item icon
 * @param activity
 *            the activity to launch.
 */
public static void addActivityLauncher(final Activity context, final Menu menu, final int caption, final int icon, final Class<? extends Activity> activity) {
	final MenuItem item2 = menu.add(caption);
	item2.setIcon(icon);
	item2.setOnMenuItemClickListener(AndroidUtils.safe(context, new MenuItem.OnMenuItemClickListener() {

		public boolean onMenuItemClick(MenuItem item) {
			final Intent intent = new Intent(context, activity);
			context.startActivity(intent);
			return true;
		}
	}));
}