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

The following are Jave code examples for showing how to use setOnMenuItemClickListener() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BlackList   File: SMSConversationsListFragment.java   View Source Code Vote up 7 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);

    MenuItem menuItem = menu.findItem(R.id.write_message);
    Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
    menuItem.setVisible(true);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // open SMS sending activity
            CustomFragmentActivity.show(getContext(),
                    getString(R.string.New_message),
                    SMSSendFragment.class, null);
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 2
Project: mobile-store   File: SelectAppsView.java   View Source Code Vote up 6 votes
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {

    inflater.inflate(R.menu.swap_next_search, menu);
    MenuItem nextMenuItem = menu.findItem(R.id.action_next);
    int flags = MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
    MenuItemCompat.setShowAsAction(nextMenuItem, flags);
    nextMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().onAppsSelected();
            return true;
        }
    });

    SearchView searchView = new SearchView(getActivity());

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    MenuItemCompat.setActionView(searchMenuItem, searchView);
    MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    searchView.setOnQueryTextListener(this);
    return true;
}
 
Example 3
Project: openlocate-android   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (showReloadPlacesButton) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        final MenuItem myActionMenuItem = menu.findItem(R.id.action_refresh);
        myActionMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                PlaceFragment placeFragment = (PlaceFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
                if (placeFragment.isAdded()) {
                    placeFragment.currentPlace();
                }
                return false;
            }
        });
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 4
Project: BlackList   File: SMSConversationFragment.java   View Source Code Vote up 6 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);

    MenuItem menuItem = menu.findItem(R.id.write_message);
    Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
    menuItem.setVisible(true);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // open activity with fragment of sending SMS
            openSMSSendActivity(contactName, contactNumber, messageEdit.getText().toString());
            messageEdit.setText("");
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 5
Project: SciChart.Android.Examples   File: ExampleActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.example_menu_drawer, menu);

    final MenuItem menuItem = menu.findItem(R.id.toggle_example_toolbar);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            drawerLayout.onMenuItemClick();
            return true;
        }
    });

    drawerLayout.setViewsClickableAction(new Action1<Boolean>() {
        @Override
        public void execute(Boolean isEnabled) {
            menuItem.setEnabled(isEnabled);
        }
    });

    return true;
}
 
Example 6
Project: BookyMcBookface   File: ReaderActivity.java   View Source Code Vote up 6 votes
protected void showToc() {
    Map<String,String> tocmap = book.getToc();
    PopupMenu tocmenu = new PopupMenu(this, findViewById(R.id.contents_button));
    for (final String point: tocmap.keySet()) {
        String text = tocmap.get(point);
        MenuItem m = tocmenu.getMenu().add(text);
        //Log.d("EPUB", "TOC2: " + text + ". File: " + point);
        m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                handleLink(point);
                return true;
            }
        });
    }
    if (tocmap.size()==0) {
        tocmenu.getMenu().add(R.string.no_toc_found);
    }

    tocmenu.show();

}
 
Example 7
Project: BookyMcBookface   File: GetBooksActivity.java   View Source Code Vote up 6 votes
@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 8
Project: cat-is-a-dog   File: ViewHabitActivity.java   View Source Code Vote up 6 votes
/**
 * Create menu items such as "delete" button
 * @param menu The menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final MenuItem deleteItem = menu.add(
            Menu.NONE, DELETE_BUTTON_ID, Menu.NONE, "Delete");
    MenuItemCompat.setShowAsAction(
            deleteItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
    deleteItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            confirmDelete();
            return true;
        }
    });
    return true;
}
 
Example 9
Project: CustomActionWebView   File: CustomActionWebView.java   View Source Code Vote up 6 votes
/**
 * 处理item,处理点击
 * @param actionMode
 */
private ActionMode resolveActionMode(ActionMode actionMode) {
    if (actionMode != null) {
        final Menu menu = actionMode.getMenu();
        mActionMode = actionMode;
        menu.clear();
        for (int i = 0; i < mActionList.size(); i++) {
            menu.add(mActionList.get(i));
        }
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    getSelectedData((String) item.getTitle());
                    releaseAction();
                    return true;
                }
            });
        }
    }
    mActionMode = actionMode;
    return actionMode;
}
 
Example 10
Project: GitHub   File: ColorsActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	super.onCreateOptionsMenu(menu);

	MenuItem reset = menu.add(R.string.menu_colors_reset);
	reset.setAlphabeticShortcut('r');
	reset.setNumericShortcut('1');
	reset.setIcon(android.R.drawable.ic_menu_revert);
	reset.setOnMenuItemClickListener(new OnMenuItemClickListener() {
		public boolean onMenuItemClick(MenuItem arg0) {
			// Reset each individual color to defaults.
			for (int i = 0; i < Colors.defaults.length; i++) {
				if (mColorList[i] != Colors.defaults[i]) {
					mHostDb.setGlobalColor(i, Colors.defaults[i]);
					mColorList[i] = Colors.defaults[i];
				}
			}
			mColorGrid.invalidateViews();

			// Reset the default FG/BG colors as well.
			mFgSpinner.setSelection(HostDatabase.DEFAULT_FG_COLOR);
			mBgSpinner.setSelection(HostDatabase.DEFAULT_BG_COLOR);
			mHostDb.setDefaultColorsForScheme(HostDatabase.DEFAULT_COLOR_SCHEME,
					HostDatabase.DEFAULT_FG_COLOR, HostDatabase.DEFAULT_BG_COLOR);

			return true;
		}
	});

	return true;
}
 
Example 11
Project: mobile-store   File: NfcView.java   View Source Code Vote up 5 votes
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
    inflater.inflate(R.menu.swap_skip, menu);
    MenuItem next = menu.findItem(R.id.action_next);
    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) {
            getActivity().showWifiQr();
            return true;
        }
    });
    return true;
}
 
Example 12
Project: mobile-store   File: JoinWifiView.java   View Source Code Vote up 5 votes
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
    inflater.inflate(R.menu.swap_next, menu);
    MenuItem next = menu.findItem(R.id.action_next);
    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) {
            getActivity().showSelectApps();
            return true;
        }
    });
    return true;
}
 
Example 13
Project: Phoenix-for-VK   File: FilterEditFragment.java   View Source Code Vote up 5 votes
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);

    View root = View.inflate(getActivity(), R.layout.sheet_filter_edirt, null);

    Toolbar toolbar = root.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.search_options);

    MenuItem saveItem = toolbar.getMenu().add(R.string.save);
    saveItem.setIcon(CurrentTheme.getDrawableFromAttribute(getActivity(), R.attr.toolbarOKIcon));
    saveItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    saveItem.setOnMenuItemClickListener(menuItem -> {
        onSaveClick();
        return true;
    });

    mEmptyText = root.findViewById(R.id.empty_text);

    RecyclerView mRecyclerView = root.findViewById(R.id.recycler_view);

    RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(manager);

    mAdapter = new SearchOptionsAdapter(mData);
    mAdapter.setOptionClickListener(this);

    mRecyclerView.setAdapter(mAdapter);
    resolveEmptyTextVisibility();

    dialog.setContentView(root);
}
 
Example 14
Project: FuelUp   File: EditVehicleActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem actionViewItem = menu.findItem(R.id.btn_removeVehicle_bar);
    actionViewItem.setTitle(getString(R.string.update));
    actionViewItem.setOnMenuItemClickListener(this);
    return super.onPrepareOptionsMenu(menu);
}
 
Example 15
Project: BookyMcBookface   File: ReaderActivity.java   View Source Code Vote up 5 votes
private void selectFontSize() {
    final int defsize = webView.getSettings().getDefaultFontSize();
    int minsize = webView.getSettings().getMinimumFontSize();
    final float scale = getResources().getDisplayMetrics().density;


   // Log.d("READER", "def " + defsize + " " + scale);
    final PopupMenu sizemenu = new PopupMenu(this, findViewById(R.id.zoom_button));
    for (int size=minsize; size<=36; size+=2) {
        final int s = size;

        MenuItem mi = sizemenu.getMenu().add(" "+size);
        mi.setCheckable(true);
        mi.setChecked(size==defsize);

        mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                Log.d("READER", "def " + (defsize-s));
                int scrolloffset = (int)(-webView.getScrollY()*(defsize - s)/scale/2.7);
                Log.d("READER", "scrollby " + scrolloffset);

                setFontSize(s);

                //attempt to adjust the scroll to keep the same text position.
                //  needs much work
                webView.scrollBy(0, scrolloffset);
                sizemenu.dismiss();
                return true;
            }
        });
    }
    sizemenu.show();


}
 
Example 16
Project: UnforgetIt   File: TaskViewAdapter.java   View Source Code Vote up 5 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    menu.setHeaderTitle(R.string.context_menu_title);
    MenuItem editMenuItem = menu.add(0, ID_EDIT, 0, R.string.edit);
    MenuItem deleteMenuItem = menu.add(0, ID_DELETE, 0, R.string.delete);

    editMenuItem.setOnMenuItemClickListener(this);
    deleteMenuItem.setOnMenuItemClickListener(this);
}
 
Example 17
Project: boohee_v5.6   File: SupportMenuInflater.java   View Source Code Vote up 5 votes
private void setItem(MenuItem item) {
    item.setChecked(this.itemChecked).setVisible(this.itemVisible).setEnabled(this.itemEnabled).setCheckable(this.itemCheckable >= 1).setTitleCondensed(this.itemTitleCondensed).setIcon(this.itemIconResId).setAlphabeticShortcut(this.itemAlphabeticShortcut).setNumericShortcut(this.itemNumericShortcut);
    if (this.itemShowAsAction >= 0) {
        MenuItemCompat.setShowAsAction(item, this.itemShowAsAction);
    }
    if (this.itemListenerMethodName != null) {
        if (SupportMenuInflater.this.mContext.isRestricted()) {
            throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
        }
        item.setOnMenuItemClickListener(new InflatedOnMenuItemClickListener(SupportMenuInflater.this.getRealOwner(), this.itemListenerMethodName));
    }
    if (item instanceof MenuItemImpl) {
        MenuItemImpl impl = (MenuItemImpl) item;
    }
    if (this.itemCheckable >= 2) {
        if (item instanceof MenuItemImpl) {
            ((MenuItemImpl) item).setExclusiveCheckable(true);
        } else if (item instanceof MenuItemWrapperICS) {
            ((MenuItemWrapperICS) item).setExclusiveCheckable(true);
        }
    }
    boolean actionViewSpecified = false;
    if (this.itemActionViewClassName != null) {
        MenuItemCompat.setActionView(item, (View) newInstance(this.itemActionViewClassName, SupportMenuInflater.ACTION_VIEW_CONSTRUCTOR_SIGNATURE, SupportMenuInflater.this.mActionViewConstructorArguments));
        actionViewSpecified = true;
    }
    if (this.itemActionViewLayout > 0) {
        if (actionViewSpecified) {
            Log.w(SupportMenuInflater.LOG_TAG, "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
        } else {
            MenuItemCompat.setActionView(item, this.itemActionViewLayout);
        }
    }
    if (this.itemActionProvider != null) {
        MenuItemCompat.setActionProvider(item, this.itemActionProvider);
    }
}
 
Example 18
Project: KakaoBot   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem feedback = menu.findItem(R.id.action_feedback);
    feedback.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:[email protected]"));
            startActivity(intent);
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example 19
Project: tuxguitar   File: TGContextMenuBase.java   View Source Code Vote up 4 votes
public void initializeItem(ContextMenu menu, int id, TGActionProcessorListener actionProcessor, boolean enabled, boolean checked) {
	MenuItem menuItem = menu.findItem(id);
	menuItem.setOnMenuItemClickListener(actionProcessor);
	menuItem.setEnabled(enabled);
	menuItem.setChecked(checked);
}