List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:de.enlightened.peris.CategoriesFragment.java
@Override public final void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); if ((this.userid != null) && (menu != null)) { if (this.subforumId == null || this.subforumId.contentEquals("participated") || this.subforumId.contentEquals("favs") || this.subforumId.contentEquals("search")) { final MenuItem item = menu.findItem(R.id.cat_mark_read); if (item != null) { item.setVisible(false);//from w ww. ja v a 2 s . c o m } } else { final MenuItem item = menu.findItem(R.id.cat_mark_read); if (item != null) { if (ThemeSetter.getForegroundDark(this.background)) { item.setIcon(R.drawable.ic_action_read_dark); } } } if (this.subforumId == null || this.subforumId.contentEquals("participated") || this.subforumId.contentEquals("favs") || this.subforumId.contentEquals("userrecent") || this.subforumId.contentEquals("search")) { final MenuItem item2 = menu.findItem(R.id.cat_new_thread); if (item2 != null) { item2.setVisible(false); } } else { final MenuItem item2 = menu.findItem(R.id.cat_new_thread); if (item2 != null) { if (ThemeSetter.getForegroundDark(this.background)) { item2.setIcon(R.drawable.ic_action_new_dark); } } } final MenuItem browserItem = menu.findItem(R.id.cat_open_browser); if (this.shareURL == null) { browserItem.setVisible(false); } else { browserItem.setVisible(true); } } }
From source file:de.enlightened.peris.PerisMain.java
@Override public final boolean onCreateOptionsMenu(final Menu menu) { final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); final MenuItem searchMenuItem = menu.findItem(R.id.search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); if (this.serverUserid == null || !getString(R.string.subforum_id).contentEquals("0")) { searchView.setVisibility(View.GONE); } else {/*from w ww .j a va 2 s. c o m*/ if (ThemeSetter.getForegroundDark(this.background)) { searchMenuItem.setIcon(R.drawable.ic_action_search_dark); } } searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(final View view, final boolean queryTextFocused) { if (!queryTextFocused) { searchMenuItem.collapseActionView(); searchView.setQuery("", false); } } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(final String newText) { // TODO Auto-generated method stub return false; } @SuppressWarnings("checkstyle:requirethis") public boolean onQueryTextSubmit(final String query) { if (getActionBar() != null) { getActionBar().setSubtitle(baseSubtitle); } searchMenuItem.collapseActionView(); searchView.setQuery("", false); final Bundle bundle = new Bundle(); bundle.putString("subforum_name", (String) "Search - " + query); bundle.putString("subforum_id", (String) "search"); bundle.putString("query", (String) query); bundle.putString("background", (String) background); bundle.putString("icon", (String) "n/a"); bundle.putString("inTab", (String) "N"); loadCategory(bundle, "SEARCH_QUERY", false); return false; } }); return true; }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // ??//from ww w . j a va 2 s. co m MenuItem actionItem = menu.add(Menu.NONE, MENU_ID.SETTING.ordinal(), MENU_ID.SETTING.ordinal(), this.getString(R.string.menu_title_setting)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); actionItem.setIcon(MENU_ID.SETTING.getDrawableResId()); // Twitter? actionItem = menu.add(Menu.NONE, MENU_ID.TWITTER.ordinal(), MENU_ID.TWITTER.ordinal(), this.getString(R.string.menu_title_share)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); actionItem.setIcon(MENU_ID.TWITTER.getDrawableResId()); // Facebook actionItem = menu.add(Menu.NONE, MENU_ID.FACEBOOK.ordinal(), MENU_ID.FACEBOOK.ordinal(), this.getString(R.string.menu_title_facebook)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); actionItem.setIcon(MENU_ID.FACEBOOK.getDrawableResId()); if (enableNewFunction) { // HISTORY actionItem = menu.add(Menu.NONE, MENU_ID.HISTORY.ordinal(), MENU_ID.HISTORY.ordinal(), this.getString(R.string.menu_title_history)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); actionItem.setIcon(MENU_ID.HISTORY.getDrawableResId()); } // LINE actionItem = menu.add(Menu.NONE, MENU_ID.LINE.ordinal(), MENU_ID.LINE.ordinal(), this.getString(R.string.menu_title_line)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); actionItem.setIcon(MENU_ID.LINE.getDrawableResId()); // FEEDBACK actionItem = menu.add(Menu.NONE, MENU_ID.FEEDBACK.ordinal(), MENU_ID.FEEDBACK.ordinal(), this.getString(R.string.menu_title_feedback)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); actionItem.setIcon(MENU_ID.FEEDBACK.getDrawableResId()); // LICENSE actionItem = menu.add(Menu.NONE, MENU_ID.LICENSE.ordinal(), MENU_ID.LICENSE.ordinal(), this.getString(R.string.menu_title_license)); actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); actionItem.setIcon(MENU_ID.LICENSE.getDrawableResId()); return true; }
From source file:com.zhengde163.netguard.ActivityLog.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final File pcap_file = new File(getCacheDir(), "netguard.pcap"); switch (item.getItemId()) { case android.R.id.home: Log.i(TAG, "Up"); NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_protocol_udp: // item.setChecked(!item.isChecked()); boolean protocol_udp = prefs.getBoolean("proto_udp", true); protocol_udp = !protocol_udp;/*w w w. j av a 2 s.c o m*/ if (protocol_udp) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("proto_udp", protocol_udp).apply(); updateAdapter(); return true; case R.id.menu_protocol_tcp: boolean proto_tcp = prefs.getBoolean("proto_tcp", true); proto_tcp = !proto_tcp; if (proto_tcp) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("proto_tcp", proto_tcp).apply(); updateAdapter(); return true; case R.id.menu_protocol_other: boolean proto_other = prefs.getBoolean("proto_other", true); proto_other = !proto_other; if (proto_other) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("proto_other", proto_other).apply(); updateAdapter(); return true; case R.id.menu_traffic_allowed: boolean traffic_allowed = prefs.getBoolean("traffic_allowed", true); traffic_allowed = !traffic_allowed; if (traffic_allowed) { item.setIcon(R.drawable.checked); } else item.setIcon(R.drawable.check); prefs.edit().putBoolean("filter", traffic_allowed).apply(); prefs.edit().putBoolean("traffic_allowed", traffic_allowed).apply(); updateAdapter(); return true; case R.id.menu_traffic_blocked: boolean traffic_blocked = prefs.getBoolean("traffic_blocked", true); traffic_blocked = !traffic_blocked; if (traffic_blocked) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("traffic_blocked", traffic_blocked).apply(); updateAdapter(); return true; case R.id.menu_log_live: boolean refresh = prefs.getBoolean("live", true); refresh = !refresh; live = refresh; if (refresh) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("live", refresh).apply(); if (live) { DatabaseHelper.getInstance(this).addLogChangedListener(listener); updateAdapter(); } else DatabaseHelper.getInstance(this).removeLogChangedListener(listener); return true; case R.id.menu_refresh: updateAdapter(); return true; case R.id.menu_log_resolve: boolean resolve = prefs.getBoolean("resolve", false); resolve = !resolve; if (resolve) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("resolve", resolve).apply(); adapter.setResolve(resolve); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_organization: boolean organization = prefs.getBoolean("organization", false); organization = !organization; if (organization) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("organization", organization).apply(); adapter.setOrganization(organization); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_clear: new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... objects) { DatabaseHelper.getInstance(ActivityLog.this).clearLog(); if (prefs.getBoolean("pcap", false)) { ServiceSinkhole.setPcap(false, ActivityLog.this); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); ServiceSinkhole.setPcap(true, ActivityLog.this); } else { if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); } return null; } @Override protected void onPostExecute(Object result) { if (running) updateAdapter(); } }.execute(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_view_as_grid) { Intent i = new Intent(POIMapActivity.this, POIGridActivity.class); i.putExtra("playOn", mActionPlay); i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // finish(); overridePendingTransition(0, 0); startActivityForResult(i, 1);//from w w w . j a v a 2s .c o m overridePendingTransition(0, 0); } else if (id == R.id.action_directions) { if (mActionDirections == 1) { // cancel directions action item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } else if (mActionDirections == 0) { // set directions action on item.setIcon(R.drawable.ic_action_directions_pressed); mActionDirections = 1; gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage); if (gmm.myLocationEnabled && gmm.internetEnabled) { Toast.makeText(POIMapActivity.this, POIMapActivity.this.getResources().getString(R.string.tap_route_destination), Toast.LENGTH_SHORT).show(); } else { tvMapMessage.setBackgroundColor( POIMapActivity.this.getResources().getColor(R.color.red_transparent)); item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); } } else { // mActionDirections == 3 item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } } else if (id == R.id.action_play) { if (mActionPlay) { // cancel play mode gmm.addAllMarkers(POIMapActivity.this); item.setIcon(R.drawable.ic_action_play); mActionPlay = false; miDirections.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } else { gmm.addPlayMarkers(POIMapActivity.this); item.setIcon(R.drawable.ic_action_pause_red); if (gmm.activePOIMarker != null) { drawUserDestRoute(gmm.activePOIMarker.getPosition()); } mActionPlay = true; } } else if (id == R.id.action_google_map_type) { // get google map type names String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names); // creating and Building the Dialog AlertDialog.Builder builderMapType = new AlertDialog.Builder(this); builderMapType.setTitle(getResources().getString(R.string.action_google_map_type)); builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item != selectedMapType) { switchGoogleMapType(item); // save selected type in settings SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(POIMapActivity.this); SharedPreferences.Editor editor = preferences.edit(); editor.putString("googleMapType", String.valueOf(item)); editor.commit(); } mapTypeDialog.dismiss(); } }); mapTypeDialog = builderMapType.create(); mapTypeDialog.show(); } else if (id == R.id.action_legal_notices) { String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext()); AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this); licenseDialog.setTitle(getString(R.string.action_legal_notices)); licenseDialog.setMessage(licenseInfo); licenseDialog.show(); } else if (id == R.id.action_scan_qr_code) { handleQRcodeScanRequest(); } else if (id == R.id.action_about) { String about = getString(R.string.about_application); AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(POIMapActivity.this).create(); alertDialog.setTitle(getString(R.string.action_about)); alertDialog.setMessage(Html.fromHtml(about)); alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } return super.onOptionsItemSelected(item); }
From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java
private void toggleStar(MenuItem item) { Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.add_favorite, Snackbar.LENGTH_SHORT);/*from ww w. j a v a 2 s. co m*/ Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.remove_favorite, Snackbar.LENGTH_SHORT); added_snackbar.addCallback(new Snackbar.Callback() { @Override public void onShown(Snackbar snackbar) { super.onShown(snackbar); snackbar.getView().setContentDescription("added to favorites"); snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT); } }); removed_snackbar.addCallback(new Snackbar.Callback() { @Override public void onShown(Snackbar snackbar) { super.onShown(snackbar); snackbar.getView().setContentDescription("removed from favorites"); snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT); } }); if (mIsStarred) { item.setIcon(R.drawable.ic_menu_star); item.setTitle("Favorite checkbox, not checked"); viewModel.setIsStarredFor(mId, 0); removed_snackbar.show(); mIsStarred = false; } else { item.setIcon(R.drawable.ic_menu_star_on); item.setTitle("Favorite checkbox, checked"); viewModel.setIsStarredFor(mId, 1); added_snackbar.show(); mIsStarred = true; } }
From source file:org.readium.sdk.android.biblemesh.WebViewActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.web_view, menu); MenuItem mo_previous = menu.findItem(R.id.mo_previous); MenuItem mo_next = menu.findItem(R.id.mo_next); MenuItem mo_play = menu.findItem(R.id.mo_play); MenuItem mo_pause = menu.findItem(R.id.mo_pause); // show menu only when its reasonable mo_previous.setVisible(mIsMoAvailable); mo_next.setVisible(mIsMoAvailable);//ww w .j a v a 2s .c o m if (mIsMoAvailable) { mo_play.setVisible(!mIsMoPlaying); mo_pause.setVisible(mIsMoPlaying); } Typeface face = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf"); TextDrawable faIcon = new TextDrawable(this); faIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); faIcon.setTextAlign(Layout.Alignment.ALIGN_CENTER); faIcon.setTextColor(Color.parseColor("#ffffff")); faIcon.setTypeface(face); faIcon.setText(getResources().getText(R.string.fa_cog)); TextDrawable faIcon2 = new TextDrawable(this); faIcon2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); faIcon2.setTextAlign(Layout.Alignment.ALIGN_CENTER); faIcon2.setTextColor(Color.parseColor("#ffffff")); faIcon2.setTypeface(face); faIcon2.setText(getResources().getText(R.string.fa_toc)); MenuItem menuItem = menu.findItem(R.id.settings); menuItem.setIcon(faIcon); MenuItem menuItem2 = menu.findItem(R.id.toc); menuItem2.setIcon(faIcon2); /*MenuItem menuItem3 = menu.findItem(R.id.toc); item.setOnMenuItemClickListener ( new MenuItem.OnMenuItemClickListener () { public boolean onMenuItemClick(MenuItem item) { return (showDirectory(item)); } } );*/ return true; }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.image_details, menu); MenuItem shareMenuItem = menu.findItem(R.id.action_share); if (shareMenuItem != null) { ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat .getActionProvider(shareMenuItem); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, pageUri.toString()); shareActionProvider.setShareIntent(shareIntent); shareMenuItem.setIcon(R.drawable.ic_action_share); }/*from www . j a va 2s . com*/ return super.onCreateOptionsMenu(menu); }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java
/** Handles item selections */ @Override/*from w w w. j a v a 2 s . c o m*/ public boolean onOptionsItemSelected(MenuItem item) { Resources res = this.getResources(); switch (item.getItemId()) { case android.R.id.home: closeStudyOptions(); return true; case MENU_PREFERENCES: startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE); } return true; case MENU_ROTATE: if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } return true; case MENU_NIGHT: SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this); if (preferences.getBoolean("invertedColors", false)) { preferences.edit().putBoolean("invertedColors", false).commit(); item.setIcon(R.drawable.ic_menu_night); } else { preferences.edit().putBoolean("invertedColors", true).commit(); item.setIcon(R.drawable.ic_menu_night_checked); } return true; case DeckPicker.MENU_CREATE_DYNAMIC_DECK: StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this); builder.setTitle(res.getString(R.string.new_deck)); mDialogEditText = new EditText(StudyOptionsActivity.this); ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames(); int n = 1; String cramDeckName = "Cram 1"; while (names.contains(cramDeckName)) { n++; cramDeckName = "Cram " + n; } mDialogEditText.setText(cramDeckName); // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter }); builder.setView(mDialogEditText, false, false); builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { long id; Bundle initialConfig = new Bundle(); try { initialConfig.putString("searchSuffix", "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'"); id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString()); AnkiDroidApp.getCol().getDecks().get(id); } catch (JSONException e) { throw new RuntimeException(e); } loadContent(false, initialConfig); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.create().show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.lyrics, menu); MenuItem saveMenuItem = menu.findItem(R.id.save_action); if (saveMenuItem != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && sharedPref.getBoolean("pref_auto_save", true)) { String[] metadata = new String[] { mLyrics.getArtist(), mLyrics.getTrack(), mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() }; if (!DatabaseHelper.presenceCheck(((MainLyricActivity) getActivity()).database, metadata)) { lyricsPresentInDB = true; new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics); }//from www . j ava 2 s .c om 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 (mLyrics != null) { resyncMenuItem.setVisible(mLyrics.isLRC()); convertMenuItem.setVisible(mLyrics.isLRC()); } }