android.view.MenuItem Java Examples
The following examples show how to use
android.view.MenuItem.
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: UserDetailActivity.java From Ruisi with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_add) { if (!App.isLogin(this)) { Snackbar.make(coordinatorLayout, "你还没有登录,无法进行操作", Snackbar.LENGTH_LONG) .setAction("点我登录", view -> startActivity(new Intent(getApplicationContext(), LoginActivity.class))).show(); } else { AddFriendDialog dialogFragment = AddFriendDialog.newInstance( this, username, imageUrl); dialogFragment.show(getSupportFragmentManager(), "add"); } } return super.onOptionsItemSelected(item); }
Example #2
Source File: MainActivity.java From BrokenView with MIT License | 6 votes |
private void initToolbar(){ toolbar = (Toolbar) this.findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: mBrokenView.reset(); refreshDate(); setOnTouchListener(); setViewVisible(); break; } return true; } }); }
Example #3
Source File: SearchBookActivity.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_book_source_manage: BookSourceActivity.startThis(this, requestSource); break; case android.R.id.home: SoftInputUtil.hideIMM(getCurrentFocus()); finish(); break; default: if (item.getGroupId() == R.id.source_group) { item.setChecked(true); if (Objects.equals(getString(R.string.all_source), item.getTitle().toString())) { MApplication.SEARCH_GROUP = null; } else { MApplication.SEARCH_GROUP = item.getTitle().toString(); } mPresenter.initSearchEngineS(MApplication.SEARCH_GROUP); } } return super.onOptionsItemSelected(item); }
Example #4
Source File: MainActivity.java From PagerTabIndicator with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.text: changeTabAdapter(TabAdapterType.TEXT); break; case R.id.image: changeTabAdapter(TabAdapterType.IMAGE); break; case R.id.web: changeTabAdapter(TabAdapterType.WEB); break; case R.id.custom: changeTabAdapter(TabAdapterType.CUSTOM); break; case R.id.custom_anim: changeTabAdapter(TabAdapterType.CUSTOM_ANIM); break; } return true; }
Example #5
Source File: AllTracksFragment.java From odyssey with GNU General Public License v3.0 | 6 votes |
/** * Hook called when an menu item in the context menu is selected. * * @param item The menu item that was selected. * @return True if the hook was consumed here. */ @Override public boolean onContextItemSelected(@NonNull MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); if (info == null) { return super.onContextItemSelected(item); } switch (item.getItemId()) { case R.id.fragment_all_tracks_action_enqueue: enqueueTrack(info.position, false); return true; case R.id.fragment_all_tracks_action_enqueueasnext: enqueueTrack(info.position, true); return true; case R.id.fragment_all_tracks_action_play: playTrack(info.position, false); return true; case R.id.fragment_all_tracks_showartist: showArtist(info.position); return true; default: return super.onContextItemSelected(item); } }
Example #6
Source File: CardFlipActivity.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Navigate "up" the demo structure to the launchpad activity. // See http://developer.android.com/design/patterns/navigation.html for more. NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); return true; case R.id.action_flip: flipCard(); return true; } return super.onOptionsItemSelected(item); }
Example #7
Source File: MainActivity.java From SmartProxy with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_activity_actions, menu); MenuItem menuItem = menu.findItem(R.id.menu_item_switch); if (menuItem == null) { return false; } switchProxy = (Switch) menuItem.getActionView(); if (switchProxy == null) { return false; } switchProxy.setChecked(LocalVpnService.IsRunning); switchProxy.setOnCheckedChangeListener(this); return true; }
Example #8
Source File: MainActivity.java From MultiStateView with Apache License 2.0 | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { // Handle the camera action } else if (id == R.id.nav_gallery) { } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #9
Source File: MainActivity.java From CoolChat with Apache License 2.0 | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.nav_menu_setting: startActivity(new Intent(MainActivity.this, SettingActivity.class)); break; default: showToast("暂未开发"); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); startActivity(new Intent(MainActivity.this, TestActivity.class)); break; } return true; }
Example #10
Source File: SwipeRefreshLayoutBasicFragment.java From android-SwipeRefreshLayoutBasic with Apache License 2.0 | 6 votes |
/** * Respond to the user's selection of the Refresh action item. Start the SwipeRefreshLayout * progress bar, then initiate the background task that refreshes the content. */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_refresh: Log.i(LOG_TAG, "Refresh menu item selected"); // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator if (!mSwipeRefreshLayout.isRefreshing()) { mSwipeRefreshLayout.setRefreshing(true); } // Start our refresh background task initiateRefresh(); return true; } return super.onOptionsItemSelected(item); }
Example #11
Source File: PicSelectActivity.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { this.finish(); return true; } else if (itemId == R.id.action_complete) { complete(); return true; } // case R.id.action_more: // // Get the ActionProvider for later usage // provider = (MoreActionProvider) menu.findItem(R.id.menu_share) // .getActionProvider(); // return true; return super.onOptionsItemSelected(item); }
Example #12
Source File: FriendsFragment.java From Abelana-Android with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); //Uses a built-in Android intent to display email addresses from your contacts if (id == R.id.action_find_friends) { Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_TYPE); startActivityForResult(intent, PICK_CONTACT_REQUEST); } /* Alternatively, the user can manually input an email address of a friend they'd like to follow. * Note, currently the user must already have the app for the follow to work. */ if (id == R.id.manual_friend_search) { showDialog(); } return super.onOptionsItemSelected(item); }
Example #13
Source File: Home.java From UberClone with MIT License | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); switch (id){ case R.id.nav_trip_history: showTripHistory(); break; case R.id.nav_updateInformation: showDialogUpdateInfo(); break; case R.id.nav_signOut: signOut(); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #14
Source File: QuotesFragment.java From coursera-android with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Show Toast Messages. Toast Messages are discussed in the lesson on user interface classes // return value true indicates that the menu click has been handled case R.id.detail_menu_item_main: Toast.makeText(getActivity().getApplicationContext(), "This action provided by the QuoteFragment", Toast.LENGTH_SHORT).show(); return true; case R.id.detail_menu_item_secondary: Toast.makeText(getActivity().getApplicationContext(), "This action is also provided by the QuoteFragment", Toast.LENGTH_SHORT).show(); return true; default: return super.onOptionsItemSelected(item); } }
Example #15
Source File: MainActivity.java From material-navigation-drawer with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. // AUTOMATICALLY ONLY ON 4.1+ !!! int id = item.getItemId(); if (id == android.R.id.home) { if (mDrawerToggle != null) return mDrawerToggle.onOptionsItemSelected(item); if (mSlidingLayout != null) { if (mSlidingLayout.isOpen()) mSlidingLayout.closePane(); else mSlidingLayout.openPane(); return true; } } return super.onOptionsItemSelected(item); }
Example #16
Source File: TagEditActivity.java From talk-android with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); break; case R.id.action_done: final String text = mEditText.getText().toString().trim(); if (!TextUtils.isEmpty(text)) { mPresenter.updateTag(mTagId, text); } break; } return super.onOptionsItemSelected(item); }
Example #17
Source File: PermissionsActivity.java From APDE with GNU General Public License v2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case android.R.id.home: if (isPreviewSetttings) { promptSaveDataPreviewSettings(); } else { finish(); } return true; case R.id.menu_new_permission: newPermission(); return true; case R.id.action_settings: launchSettings(); return true; default: return super.onOptionsItemSelected(item); } }
Example #18
Source File: TaskListActivity.java From batteryhub with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { startActivity(new Intent(this, SettingsActivity.class)); return true; } else if (id == R.id.action_sort_memory) { sortTasksBy(Config.SORT_BY_MEMORY, mSortOrderMemory); mSortOrderMemory = -mSortOrderMemory; return true; } else if (id == R.id.action_sort_name) { sortTasksBy(Config.SORT_BY_NAME, mSortOrderName); mSortOrderName = -mSortOrderName; return true; } return super.onOptionsItemSelected(item); }
Example #19
Source File: AlbumsFragment.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) { String sortOrder = null; switch (item.getItemId()) { case R.id.action_sort_order_album: sortOrder = AlbumSortOrder.ALBUM_A_Z; break; case R.id.action_sort_order_album_desc: sortOrder = AlbumSortOrder.ALBUM_Z_A; break; case R.id.action_sort_order_artist: sortOrder = AlbumSortOrder.ALBUM_ARTIST; break; } if (sortOrder != null) { item.setChecked(true); setSaveSortOrder(sortOrder); } return true; }
Example #20
Source File: VideoDetailsFragment.java From Loop with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.share: if (video != null) { // EventLogger.fire(ProductShareEvent.start(mProduct.getId())); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, String.format("I found this on Loop. Check it out.\n\n%s\n\n%s", video.getName(), video.getLink())); String title = getResources().getString(R.string.share_this_video); Intent chooser = Intent.createChooser(sendIntent, title); if (sendIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivityForResult(chooser, VIDEO_SHARE_REQUEST_CODE); } } return true; default: break; } return super.onOptionsItemSelected(item); }
Example #21
Source File: MainActivity.java From YourWeather with Apache License 2.0 | 5 votes |
/** * 初始化Navigation参数 */ private void initNavigation(){ mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()){ case R.id.add_city: Intent intentCity = new Intent(MainActivity.this,ChooseCity.class); startActivity(intentCity); break; case R.id.multi_cities: Toast.makeText(MainActivity.this, "此功能再下个版本添加!", Toast.LENGTH_SHORT).show(); break; case R.id.about: Intent intentAbout =new Intent(MainActivity.this,AboutActivity.class); startActivity(intentAbout); break; case R.id.setting: Intent intentSetting =new Intent(MainActivity.this,SettingActivity.class); startActivity(intentSetting); break; case R.id.exit: finish(); } return false; } }); }
Example #22
Source File: BookDetailFragment.java From barterli_android with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { if (mOwnedByUser) { inflater.inflate(R.menu.menu_logged_in_book_detail, menu); } else { inflater.inflate(R.menu.menu_book_detail, menu); } final MenuItem menuItem = menu.findItem(R.id.action_share); mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem); updateShareIntent(mBookTitle); }
Example #23
Source File: LegendActivity.java From satstat with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; } return super.onOptionsItemSelected(item); }
Example #24
Source File: MainActivity.java From InviZible with GNU General Public License v3.0 | 5 votes |
private void changeDrawerWithVersionAndDestination(NavigationView navigationView) { if (navigationView == null) { return; } MenuItem item = navigationView.getMenu().findItem(R.id.nav_Donate); if ((appVersion.startsWith("g") && accelerated) || appVersion.startsWith("p") || appVersion.startsWith("f")) { if (item != null) { item.setVisible(false); } } else { if (item != null) { item.setVisible(true); if (appVersion.startsWith("g")) { item.setTitle(R.string.premium); } } } item = navigationView.getMenu().findItem(R.id.nav_Code); if (appVersion.startsWith("l")) { if (item != null) { item.setVisible(true); } } else { if (item != null) { item.setVisible(false); } } }
Example #25
Source File: ChatRoomActivity.java From MessagingAndroidChat with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }
Example #26
Source File: BusReservationsActivity.java From KUAS-AP-Material with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); break; } return false; }
Example #27
Source File: MainActivity.java From BooheeScrollView with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id){ case R.id.normal: booheeScrollView.setAnimType(BooheeScrollView.NORMAL_ANIM); break; case R.id.rebound: booheeScrollView.setAnimType(BooheeScrollView.REBOUND_ANIM); break; } return true; }
Example #28
Source File: DrMIPSActivity.java From drmips with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.dr_mips, menu); mnuDelete = menu.findItem(R.id.mnuDelete); mnuStep = menu.findItem(R.id.mnuStep); mnuBackStep = menu.findItem(R.id.mnuBackStep); mnuRestart = menu.findItem(R.id.mnuRestart); mnuRun = menu.findItem(R.id.mnuRun); MenuItem mnuSwitchTheme = menu.findItem(R.id.mnuSwitchTheme); mnuSwitchTheme.setChecked(DrMIPS.getApplication().getCurrentTheme() == R.style.DarkTheme); mnuControlPath = menu.findItem(R.id.mnuControlPath); mnuControlPath.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.SHOW_CONTROL_PATH_PREF, DrMIPS.DEFAULT_SHOW_CONTROL_PATH)); mnuArrowsInWires = menu.findItem(R.id.mnuArrowsInWires); mnuArrowsInWires.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.SHOW_ARROWS_PREF, DrMIPS.DEFAULT_SHOW_ARROWS)); mnuPerformanceMode = menu.findItem(R.id.mnuPerformanceMode); mnuPerformanceMode.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.PERFORMANCE_MODE_PREF, DrMIPS.DEFAULT_PERFORMANCE_MODE)); mnuOverlayedData = menu.findItem(R.id.mnuOverlayedData); mnuOverlayedData.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_DATA_PREF, DrMIPS.DEFAULT_OVERLAYED_DATA)); mnuOverlayedShowNames = menu.findItem(R.id.mnuOverlayedShowNames); mnuOverlayedShowNames.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_SHOW_NAMES_PREF, DrMIPS.DEFAULT_OVERLAYED_SHOW_NAMES)); mnuOverlayedShowNames.setVisible(mnuOverlayedData.isChecked()); mnuOverlayedShowForAll = menu.findItem(R.id.mnuOverlayedShowForAll); mnuOverlayedShowForAll.setChecked(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_SHOW_FOR_ALL_PREF, DrMIPS.DEFAULT_OVERLAYED_SHOW_FOR_ALL)); mnuOverlayedShowForAll.setVisible(mnuOverlayedData.isChecked()); mnuRemoveLatencies = menu.findItem(R.id.mnuRemoveLatencies); mnuRemoveLatencies.setVisible(mnuPerformanceMode.isChecked()); mnuRestoreLatencies = menu.findItem(R.id.mnuRestoreLatencies); mnuRestoreLatencies.setVisible(mnuPerformanceMode.isChecked()); mnuDelete.setVisible(openFile != null); updateStepBackEnabled(); updateStepEnabled(); return true; }
Example #29
Source File: SettingActivity.java From Tick with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(item); } }
Example #30
Source File: MainActivity.java From AndroidButterKnifeSample with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }