List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean ret = super.onPrepareOptionsMenu(menu); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { toolbar.getMenu().findItem(R.id.scan_btn).setVisible(false); toolbar.getMenu().findItem(R.id.state_bt_btn).setVisible(false); toolbar.getMenu().findItem(R.id.reset_snoop_file).setVisible(false); nvDrawer.getMenu().findItem(R.id.scan_btn_nv).setVisible(true); if (mScanType == ScanType.CLASSIC_SCAN) { nvDrawer.getMenu().findItem(R.id.change_settings) .setTitle(getString(R.string.scan_settings_type_classic_scan)); } else {/*from w w w . j a v a 2s . c om*/ nvDrawer.getMenu().findItem(R.id.change_settings) .setTitle(getString(R.string.scan_settings_type_ble_scan)); } if (Build.VERSION.SDK_INT <= 22) { nvDrawer.getMenu().findItem(R.id.reset_snoop_file_nv).setVisible(true); } MenuItem stateBtn = nvDrawer.getMenu().findItem(R.id.state_bt_btn_nv); stateBtn.setVisible(true); if (mBluetoothAdapter.isEnabled()) { stateBtn.setIcon(R.drawable.ic_bluetooth); } else { stateBtn.setIcon(R.drawable.ic_bluetooth_disabled); } stateBtn.setTitle(getResources().getString(R.string.menu_item_title_enable_bluetooth_portrait)); } return ret; }
From source file:com.android.calendar.AllInOneActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); mOptionsMenu = menu;/*from w w w. j a v a 2 s .c o m*/ getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu); // Add additional options (if any). Integer extensionMenuRes = mExtensions.getExtensionMenuResource(menu); if (extensionMenuRes != null) { getMenuInflater().inflate(extensionMenuRes, menu); } MenuItem item = menu.findItem(R.id.action_import); item.setVisible(ImportActivity.hasThingsToImport(this)); mSearchMenu = menu.findItem(R.id.action_search); mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchMenu); if (mSearchView != null) { Utils.setUpSearchView(mSearchView, this); mSearchView.setOnQueryTextListener(this); mSearchView.setOnSuggestionListener(this); } // Hide the "show/hide controls" button if this is a phone // or the view type is "Month" or "Agenda". mControlsMenu = menu.findItem(R.id.action_hide_controls); if (!mShowCalendarControls) { if (mControlsMenu != null) { mControlsMenu.setVisible(false); mControlsMenu.setEnabled(false); } } else if (mControlsMenu != null && mController != null && (mController.getViewType() == ViewType.MONTH || mController.getViewType() == ViewType.AGENDA)) { mControlsMenu.setVisible(false); mControlsMenu.setEnabled(false); } else if (mControlsMenu != null) { mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); } MenuItem menuItem = menu.findItem(R.id.action_today); if (Utils.isJellybeanOrLater()) { // replace the default top layer drawable of the today icon with a // custom drawable that shows the day of the month of today LayerDrawable icon = (LayerDrawable) menuItem.getIcon(); Utils.setTodayIcon(icon, this, mTimeZone); } else { menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light); } return true; }
From source file:com.agenmate.lollipop.addedit.AddEditFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: getActivity().onBackPressed();/*from www .j a v a 2 s .c o m*/ return true; case R.id.action_save: String title = emptyStringChecker(titleEdit.getText().toString()); if (title == null) { Snackbar.make(background, "Title can't be Empty", Snackbar.LENGTH_LONG).show(); return true; } String description = emptyStringChecker(descEdit.getText().toString()); int priority = getPriority(); long dueAt = getDueDate(); if (dueAt < 0) { Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG) .show(); return true; } presenter.saveTask(title, description, priority, selectedColor, dueAt, hasAlarm, isCompleted); return true; case R.id.action_alarm: if (!hasAlarm) { if (getDueDate() < 0) { Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG) .show(); return true; } } boolean setWhite = selectedColor == 0 || selectedColor == 5 || selectedColor == 6; item.setIcon(hasAlarm ? R.drawable.ic_alarm_off : R.drawable.ic_alarm_on); Drawable drawable = item.getIcon(); drawable.mutate(); drawable.setColorFilter(setWhite ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP); hasAlarm = !hasAlarm; return true; case R.id.action_delete: presenter.deleteTask(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java
/** * {@inheritDoc}//from w w w .j a v a2 s . c om */ @Override public boolean onPrepareOptionsMenu(final Menu menu) { // Hide the EQ option if it can't be opened MenuItem fav = menu.findItem(R.id.menu_favorite); final Intent intent = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); if (getPackageManager().resolveActivity(intent, 0) == null) { final MenuItem effects = menu.findItem(R.id.menu_audio_player_equalizer); effects.setVisible(false); } if (MusicUtils.mService != null && MusicUtils.getCurrentAudioId() != -1) { if (MusicUtils.isFavorite()) { fav.setIcon(R.drawable.ic_favorited); } else { fav.setIcon(R.drawable.ic_unfavorited); // Theme chooser } } return true; }
From source file:knayi.delevadriver.AvaliableJobDetailActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item = menu.add("Icon"); item.setIcon(R.drawable.deleva_dispatcher_white_noeffects_04); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); return super.onCreateOptionsMenu(menu); }
From source file:com.SpeechEd.SpeechEdEditActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuItem item; item = menu.add(0, CMD_SAVE, 0, R.string.menu_save); item.setIcon(R.drawable.menu_save); item = menu.add(0, CMD_RESET, 0, R.string.menu_reset); item.setIcon(R.drawable.menu_reset); item = menu.add(0, CMD_ABOUT, 0, R.string.menu_about); item.setIcon(R.drawable.menu_about); return true;//from ww w .j ava 2s . c o m }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity == null) return;// w ww .j a v a 2 s. c om CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) mainActivity .findViewById(R.id.toolbar_layout); toolbarLayout.setTitle(getString(R.string.app_name)); if (((DrawerLayout) mainActivity.drawer) // drawer is locked .getDrawerLockMode(mainActivity.drawerView) == DrawerLayout.LOCK_MODE_LOCKED_CLOSED) return; inflater.inflate(lyrics, menu); // Get the SearchView and set the searchable configuration final MaterialSuggestionsSearchView materialSearchView = (MaterialSuggestionsSearchView) mainActivity .findViewById(R.id.material_search_view); materialSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(final String query) { materialSearchView.setSuggestions(null); materialSearchView.requestFocus(); materialSearchView.post(new Runnable() { @Override public void run() { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(materialSearchView.getWindowToken(), 0); } }); materialSearchView.postDelayed(new Runnable() { @Override public void run() { ((MainActivity) getActivity()).search(query); materialSearchView.setSuggestions(null); } }, 90); mExpandedSearchView = false; return true; } @Override public boolean onQueryTextChange(String newText) { if (!materialSearchView.hasSuggestions()) materialSearchView.setSuggestions(materialSearchView.getHistory()); return true; } }); materialSearchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() { @Override public void onSearchViewShown() { if (getActivity() == null) return; ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true); mExpandedSearchView = true; } @Override public void onSearchViewClosed() { mExpandedSearchView = false; } }); final Resources resources = getResources(); final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); int statusBarHeight; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) statusBarHeight = 0; else if (resourceId > 0) statusBarHeight = resources.getDimensionPixelSize(resourceId); else statusBarHeight = (int) Math.ceil((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 24 : 25) * resources.getDisplayMetrics().density); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) materialSearchView.getLayoutParams(); lp.setMargins(lp.leftMargin, statusBarHeight, lp.rightMargin, lp.bottomMargin); materialSearchView.setLayoutParams(lp); MenuItem searchItem = menu.findItem(R.id.action_search); materialSearchView.setMenuItem(searchItem); if (!materialSearchView.isSearchOpen() && mExpandedSearchView) { materialSearchView.showSearch(); mExpandedSearchView = false; } else if (!mExpandedSearchView) materialSearchView.closeSearch(); materialSearchView.setHint(getString(R.string.search_hint)); if (mSearchQuery != null && !mSearchQuery.equals("")) { searchItem.expandActionView(); materialSearchView.setQuery(mSearchQuery, false); if (mSearchFocused) materialSearchView.requestFocus(); else materialSearchView.clearFocus(); mSearchQuery = null; } Lyrics storedLyrics = mLyrics == null ? null : DatabaseHelper.getInstance(getActivity()).get(new String[] { mLyrics.getArtist(), mLyrics.getTitle(), mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() }); MenuItem saveMenuItem = menu.findItem(R.id.save_action); if (saveMenuItem != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (mLyrics == null) saveMenuItem.setVisible(false); else if (mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && sharedPref.getBoolean("pref_auto_save", true)) { if (storedLyrics == null || (mLyrics.isLRC() && !storedLyrics.isLRC())) { lyricsPresentInDB = true; new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics); } saveMenuItem.setVisible(false); } else { saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save); saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action); } } MenuItem resyncMenuItem = menu.findItem(R.id.resync_action); MenuItem convertMenuItem = menu.findItem(R.id.convert_action); if (resyncMenuItem != null) resyncMenuItem.setVisible(mLyrics != null && mLyrics.isLRC()); if (convertMenuItem != null) { Lyrics stored = mLyrics == null || mLyrics.isLRC() ? null : storedLyrics; convertMenuItem .setVisible((mLyrics != null && (mLyrics.isLRC())) || (stored != null && stored.isLRC())); convertMenuItem.setTitle(stored == null ? R.string.full_text_action : R.string.pref_lrc); } MenuItem shareMenuItem = menu.findItem(R.id.share_action); if (shareMenuItem != null) shareMenuItem.setVisible( mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && mLyrics.getURL() != null); }
From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { //change the current path in fragment if (mCurrentFragment == null) { mCurrentFragment = mFragmentOnes[0]; }/*from ww w. j av a 2s . c om*/ if (SharedData.IS_IN_COPY_MODE) { if (item.getItemId() == R.id.cancel_menu_item) { SharedData.IS_IN_COPY_MODE = false; invalidateOptionsMenu(); openOptionsMenu(); } else if (item.getItemId() == R.id.paste_here_menu_item) { SharedData.IS_IN_COPY_MODE = false; invalidateOptionsMenu(); openOptionsMenu(); removeNoFilesFragment(); mCurrentFragment.executeCopyTask(); } return true; } if (item.getItemId() == R.id.open_source_menu_item) { startActivity(new Intent(this, AboutActivity.class)); } else if (item.getItemId() == R.id.backup_menu_item) { showBackupDialog(); } else if (item.getItemId() == R.id.refresh_menu_item) { UiUtils.reloadData(mCurrentFragment.getmFileAdapter()); } else if (item.getItemId() == R.id.items_view_menu_item) { if (SharedData.LINEAR_LAYOUTMANAGER) { SharedData.LINEAR_LAYOUTMANAGER = false; item.setIcon(ContextCompat.getDrawable(this, R.drawable.ic_listview)); } else { SharedData.LINEAR_LAYOUTMANAGER = true; item.setIcon(ContextCompat.getDrawable(this, R.drawable.ic_gridview)); } viewChanged = true; mCurrentFragment.toggleLayout(); } else if (item.getItemId() == R.id.keydetails_menu_item) { startActivity(new Intent(this, KeyDetailsActivity.class)); } else if (item.getItemId() == R.id.prefs_menu_item) { startActivity(new Intent(this, PreferencesActivity.class)); } return true; }
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
private void startScanSetup() { MenuItem item; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { item = nvDrawer.getMenu().findItem(R.id.scan_btn_nv); } else {/*w w w .j a v a 2 s . c o m*/ item = toolbar.getMenu().findItem(R.id.scan_btn); } if (item != null) { item.setIcon(R.drawable.ic_portable_wifi_off); item.setTitle(getResources().getString(R.string.menu_item_title_stop_scan)); } Toast.makeText(HciDebuggerActivity.this, getResources().getString(R.string.toast_scan_start), Toast.LENGTH_SHORT).show(); }
From source file:com.zhengde163.netguard.ActivityMain.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "Menu=" + item.getTitle()); // Handle item selection SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); switch (item.getItemId()) { case R.id.menu_app_user: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_user", item.isChecked()).apply(); return true; case R.id.menu_app_system: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_system", item.isChecked()).apply(); return true; case R.id.menu_app_nointernet: boolean nointernet = prefs.getBoolean("show_nointernet", true); nointernet = !nointernet;//w ww .j a va 2 s. c om if (nointernet) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("show_nointernet", nointernet).apply(); return true; case R.id.menu_app_disabled: boolean disabled = prefs.getBoolean("show_disabled", true); disabled = !disabled; if (disabled) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("show_disabled", disabled).apply(); return true; case R.id.menu_sort_name: item.setChecked(true); item.setIcon(R.drawable.singlechecked); menu_data.setIcon(R.drawable.singlecheck); prefs.edit().putString("sort", "name").apply(); return true; case R.id.menu_sort_data: item.setChecked(true); item.setIcon(R.drawable.singlechecked); menu_name.setIcon(R.drawable.singlecheck); prefs.edit().putString("sort", "data").apply(); return true; case R.id.menu_log: startActivity(new Intent(this, ActivityLog.class)); return true; case R.id.menu_settings: startActivity(new Intent(this, ActivitySettings.class)); return true; case R.id.menu_legend: menu_legend(); return true; case R.id.login_again: startActivity(new Intent(ActivityMain.this, LoginAgain.class)); return true; default: return super.onOptionsItemSelected(item); } }