List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:com.example.testtab.fragment.TwitEyesPageFragment.java
public boolean onCreateOptionsMenu(Menu menu) { // boolean result = super.onCreateOptionsMenu(menu); // OPTION/*from w w w . j a v a2s . c om*/ MenuItem item0 = menu.add(0, MENU0_ID, Menu.NONE, R.string.menu0); item0.setIcon(R.drawable.home); // REFRESH MenuItem item1 = menu.add(0, MENU1_ID, Menu.NONE, R.string.menu1); item1.setIcon(R.drawable.cancel); // return result; return false; }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
public void RunRadio(String type, MenuItem item, Uri uri) { Log.d(String.valueOf(item), "menuitem Runradio"); Log.d(String.valueOf(uri), "uriRunradio"); if (radiostate == false) { // initialize buttons Log.d("inside Runradio", "function"); Log.d(String.valueOf(uri), "URI parameter"); startPlaying(type, uri);// w ww . j a v a2s .co m showProgressDialog(); item.setIcon(R.drawable.ic_stop); } else { stopPlaying(); item.setIcon(R.drawable.ic_play); } }
From source file:com.ota.updates.activities.MainActivity.java
/** * Sets up the NavigationView (drawer) icons * @param menu The menu item that relates to NavigationView (use getMenu() ) *//*from w ww . jav a 2 s .co m*/ private void setupNavigationViewIcons(Menu menu) { MenuItem otaUpdatesItem = menu.findItem(R.id.ota_updates); MenuItem otaVersionItem = menu.findItem(R.id.ota_versions); MenuItem otaAddonsItem = menu.findItem(R.id.ota_addons); MenuItem romWebsiteItem = menu.findItem(R.id.rom_webite); MenuItem romDonateItem = menu.findItem(R.id.rom_donate); MenuItem romInfoItem = menu.findItem(R.id.rom_information); MenuItem appSettingsItem = menu.findItem(R.id.app_settings); MenuItem appProItem = menu.findItem(R.id.app_pro); MenuItem appLicencesItem = menu.findItem(R.id.app_licences); MenuItem appGithubItem = menu.findItem(R.id.app_github); MenuItem appAboutItem = menu.findItem(R.id.app_about); otaUpdatesItem.setIcon(getNavigationViewIcon(R.string.fa_refresh)); otaVersionItem.setIcon(getNavigationViewIcon(R.string.fa_file_archive_o)); otaAddonsItem.setIcon(getNavigationViewIcon(R.string.fa_puzzle_piece)); romWebsiteItem.setIcon(getNavigationViewIcon(R.string.fa_globe)); romDonateItem.setIcon(getNavigationViewIcon(R.string.fa_money)); romInfoItem.setIcon(getNavigationViewIcon(R.string.fa_info)); appSettingsItem.setIcon(getNavigationViewIcon(R.string.fa_cog)); appProItem.setIcon(getNavigationViewIcon(R.string.fa_heart)); appLicencesItem.setIcon(getNavigationViewIcon(R.string.fa_file_text_o)); appGithubItem.setIcon(getNavigationViewIcon(R.string.fa_github)); appAboutItem.setIcon(getNavigationViewIcon(R.string.fa_question)); }
From source file:com.terracom.mumbleclient.channel.ChannelListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem muteItem = menu.findItem(R.id.menu_mute_button); MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button); try {//from w ww . j a va 2s . c o m if (getService() != null && getService().isConnected() && getService().getSessionUser() != null) { // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere int foregroundColor = getActivity().getTheme() .obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }) .getColor(0, -1); User self = getService().getSessionUser(); muteItem.setIcon(self.isSelfMuted() ? R.drawable.ic_action_microphone_muted : R.drawable.ic_action_microphone); deafenItem.setIcon( self.isSelfDeafened() ? R.drawable.ic_action_audio_muted : R.drawable.ic_action_audio); muteItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); deafenItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); } } catch (RemoteException e) { e.printStackTrace(); } /*try { if(getService() != null) { MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth); bluetoothItem.setChecked(getService().isBluetoothAvailable()); } } catch (RemoteException e) { e.printStackTrace(); }*/ }
From source file:th.in.ffc.person.PersonListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.add: Intent add = new Intent(Action.INSERT); add.addCategory(Category.PERSON); add.addCategory(Category.DEFAULT); if (mHcode != null) { add.putExtra(Person.HCODE, mHcode); }/* w w w. ja va 2 s. c o m*/ getFFCActivity().startActivity(add); break; case R.id.search: InputMethodManager imm = (InputMethodManager) getFFCActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); if (!mInput.isShown()) { mInput.setVisibility(View.VISIBLE); mInput.requestFocus(); imm.showSoftInput(mInput, InputMethodManager.SHOW_FORCED); item.setIcon(R.drawable.ic_action_close); } else { imm.hideSoftInputFromInputMethod(mInput.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); mInput.setVisibility(View.GONE); mInput.setText(null); item.setIcon(R.drawable.ic_action_search); } break; default: break; } return super.onOptionsItemSelected(item); }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { this.menu = menu; MenuItem itemNotification = menu.findItem(R.id.notifications); if (itemNotification != null) { if (notificationCount > 0) { itemNotification.setIcon(R.drawable.ic_bell_ring_white_24dp); } else {//from w ww.j a v a 2 s . co m itemNotification.setIcon(R.drawable.ic_bell_outline_white_24dp); } MenuItem itemConversation = menu.findItem(R.id.conversations); if (conversationCount > 0) { itemConversation.setIcon(R.drawable.ic_message_text_white_24dp); } else { itemConversation.setIcon(R.drawable.ic_message_text_outline_white_24dp); } } return super.onPrepareOptionsMenu(menu); }
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
private void initializeFilterMenu(Menu menu) { MenuItem item = menu.findItem(R.id.menuTransactionFilters); Drawable icon = new UIHelper(getActivity()).getIcon(GoogleMaterial.Icon.gmd_keyboard_arrow_down); item.setIcon(icon); // selection handled in onOptionsItemSelected }
From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java
private void finishCreatingMenu(Menu menu) { MenuItem item = menu.findItem(R.id.action_share); if (!isTabletPreference(context)) { mActionProvider = new ShareActionProvider(getActivity()) { @Override//w w w . ja v a 2s. c o m public View onCreateActionView() { return null; } }; item.setIcon(R.drawable.ic_share); } else { mActionProvider = new ShareActionProvider(getActivity()); } MenuItemCompat.setActionProvider(item, mActionProvider); if (mTrailerUri != null) mActionProvider.setShareIntent(createShareIntent()); }
From source file:de.gebatzens.sia.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(SIAApp.SIA_APP.school.getTheme()); super.onCreate(savedInstanceState); Log.w("ggvp", "CREATE NEW MAINACTIVITY"); //Debug.startMethodTracing("sia3"); SIAApp.SIA_APP.activity = this; savedState = savedInstanceState;//from www. j a v a2 s .c om final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments; Intent intent = getIntent(); if (intent != null && intent.getStringExtra("fragment") != null) { FragmentData frag = fragments .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0); SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag)); } if (intent != null && intent.getBooleanExtra("reload", false)) { SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); intent.removeExtra("reload"); } setContentView(R.layout.activity_main); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); mContent = getFragment(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData()); if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) { ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm); summerNavigationPalm.setImageResource(R.drawable.summer_palm); ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image); summerBackgroundImage.setImageResource(R.drawable.summer_background); } mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_refresh: ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true); SIAApp.SIA_APP.refreshAsync(new Runnable() { @Override public void run() { ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)) .setRefreshing(false); } }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); return true; case R.id.action_settings: Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); return true; case R.id.action_addToCalendar: showExamDialog(); return true; case R.id.action_help: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(getApplication().getString(R.string.help)); builder.setMessage(getApplication().getString(R.string.exam_explain)); builder.setPositiveButton(getApplication().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } return false; } }); updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.addDrawerListener(mDrawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationHeader = navigationView.getHeaderView(0); mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text); mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name); mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture); mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage()); mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link); mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewIn) { mDrawerLayout.closeDrawers(); Intent linkIntent = new Intent(Intent.ACTION_VIEW); linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website)); startActivity(linkIntent); } }); final Menu menu = navigationView.getMenu(); menu.clear(); for (int i = 0; i < fragments.size(); i++) { MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name); item.setIcon(fragments.get(i).getIconRes()); } menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings); menu.setGroupCheckable(R.id.fragments, true, true); menu.setGroupCheckable(R.id.settings, false, false); final Menu navMenu = navigationView.getMenu(); selectedItem = SIAApp.SIA_APP.getFragmentIndex(); if (selectedItem != -1) navMenu.getItem(selectedItem).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.settings_item) { mDrawerLayout.closeDrawers(); Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); } else { final int index = menuItem.getOrder(); if (SIAApp.SIA_APP.getFragmentIndex() != index) { SIAApp.SIA_APP.setFragmentIndex(index); menuItem.setChecked(true); updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString()); mContent = getFragment(); Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out); fadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.setVisibility(View.INVISIBLE); if (fragments.get(index).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index)); //removeAllFragments(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); snowView.updateSnow(); } @Override public void onAnimationRepeat(Animation animation) { } }); FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.startAnimation(fadeOut); mDrawerLayout.closeDrawers(); } else { mDrawerLayout.closeDrawers(); } } return true; } }); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < fragments.size(); i++) { Drawable drawable = getDrawable(fragments.get(i).getIconRes()); Bitmap icon; if (drawable instanceof VectorDrawable) { icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes()); } Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(connectedIcon); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#f5f5f5")); canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint); paint.setColorFilter( new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f), paint); Intent newTaskIntent = new Intent(this, MainActivity.class); newTaskIntent.setAction(Intent.ACTION_MAIN); newTaskIntent.putExtra("fragment", fragments.get(i).type.toString()); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name) .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name) .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); } } if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) { if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) { TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3) .show(getSupportFragmentManager(), "upgrade_dialog"); } SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply(); } snowView = (SnowView) findViewById(R.id.snow_view); shareToolbar = (Toolbar) findViewById(R.id.share_toolbar); shareToolbar.getMenu().clear(); shareToolbar.inflateMenu(R.menu.share_toolbar_menu); shareToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleShareToolbar(false); for (Shareable s : MainActivity.this.shared) { s.setMarked(false); } MainActivity.this.shared.clear(); mContent.updateFragment(); } }); shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleShareToolbar(false); HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>(); for (Shareable s : MainActivity.this.shared) { ArrayList<Shareable> list = dates.get(s.getDate()); if (list == null) { list = new ArrayList<Shareable>(); dates.put(s.getDate(), list); } list.add(s); s.setMarked(false); } MainActivity.this.shared.clear(); List<Date> dateList = new ArrayList<Date>(dates.keySet()); Collections.sort(dateList); String content = ""; for (Date key : dateList) { content += SubstListAdapter.translateDay(key) + "\n\n"; Collections.sort(dates.get(key)); for (Shareable s : dates.get(key)) { content += s.getShareContent() + "\n"; } content += "\n"; } content = content.substring(0, content.length() - 1); mContent.updateFragment(); if (item.getItemId() == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.entries), content); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.action_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); } return true; } }); if (shared.size() > 0) { shareToolbar.setVisibility(View.VISIBLE); updateShareToolbarText(); } // if a fragment is opened via a notification or a shortcut reset the shared entries // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment if (intent != null && intent.hasExtra("fragment")) { resetShareToolbar(); intent.removeExtra("fragment"); } }
From source file:com.cw.litenote.note.Note.java
void markCurrentSelected(MenuItem subItem, String str) { if (mPref_show_note_attribute.getString("KEY_PAGER_VIEW_MODE", "ALL").equalsIgnoreCase(str)) subItem.setIcon(R.drawable.btn_radio_on_holo_dark); else/* w w w .j av a 2 s. co m*/ subItem.setIcon(R.drawable.btn_radio_off_holo_dark); }