List of usage examples for android.view MenuItem setTitle
public MenuItem setTitle(@StringRes int title);
From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java
private void flipTracking(MenuItem item) { SharedPreferences.Editor editor = getSharedPreferences(AppConstants.PREFS_FILE, Context.MODE_PRIVATE) .edit();/*from ww w. j a va2 s. c o m*/ trackingEnabled = !trackingEnabled; editor.putBoolean(AppConstants.TRACKING, trackingEnabled); editor.apply(); if (trackingEnabled) { item.setTitle(getResources().getString(R.string.disable_tracking)); } else { item.setTitle(getResources().getString(R.string.enable_tracking)); } }
From source file:org.hawkular.client.android.fragment.AlertsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_time_hour: case R.id.menu_time_day: case R.id.menu_time_week: case R.id.menu_time_month: case R.id.menu_time_year: alertsTimeMenu = menuItem.getItemId(); menuItem.setChecked(true);//from w w w . j a v a2 s.com setUpAlertsForced(); return true; case R.id.show_hide_res: isActionPlus = !isActionPlus; setUpAlerts(alertsDump); if (isActionPlus) { menuItem.setTitle(R.string.hide_resolved); } else { menuItem.setTitle(R.string.show_resolved); } return true; default: return super.onOptionsItemSelected(menuItem); } }
From source file:com.veniosg.dir.android.fragment.SimpleFileListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { if (getActivity() == null) { return;/*w ww. j a va 2s . c o m*/ } boolean showMediaScanMenuItem = getMediaScanFromPreference(getActivity()); if (hasScanner() && !isScannerRunning() && showMediaScanMenuItem) { // We only know about ".nomedia" once scanning is finished. boolean noMedia = isMediaScannerDisabledForPath(); menu.findItem(R.id.menu_media_scan_include).setVisible(noMedia); menu.findItem(R.id.menu_media_scan_exclude).setVisible(!noMedia); } else { menu.findItem(R.id.menu_media_scan_include).setVisible(false); menu.findItem(R.id.menu_media_scan_exclude).setVisible(false); } CopyHelper copyHelper = ((FileManagerApplication) getActivity().getApplication()).getCopyHelper(); MenuItem pasteAction = menu.findItem(R.id.menu_paste); if (copyHelper.canPaste()) { int stringResource = (copyHelper.getOperationType() == COPY ? R.plurals.menu_copy_items_to : R.plurals.menu_move_items_to); pasteAction.setTitle(getResources().getQuantityString(stringResource, copyHelper.getItemCount(), copyHelper.getItemCount())); pasteAction.getIcon().setLevel(copyHelper.getItemCount()); pasteAction.setVisible(true); menu.findItem(R.id.menu_clear_clipboard).setVisible(true); } else { pasteAction.setVisible(false); menu.findItem(R.id.menu_clear_clipboard).setVisible(false); } }
From source file:org.libreoffice.ui.LibreOfficeUIActivity.java
public void sortFiles(MenuItem item) { switch (item.getItemId()) { case R.id.menu_sort_az: if (sortMode == FileUtilities.SORT_AZ) { sortMode = FileUtilities.SORT_ZA; item.setTitle(R.string.sort_az); } else {//from ww w .j a v a 2 s.co m sortMode = FileUtilities.SORT_AZ; item.setTitle(R.string.sort_za); } break; case R.id.menu_sort_modified: if (sortMode == FileUtilities.SORT_NEWEST) { sortMode = FileUtilities.SORT_OLDEST; item.setTitle(R.string.sort_newest); } else { sortMode = FileUtilities.SORT_NEWEST; item.setTitle(R.string.sort_oldest); } break; case R.id.menu_sort_size: if (sortMode == FileUtilities.SORT_LARGEST) { sortMode = FileUtilities.SORT_SMALLEST; item.setTitle(R.string.sort_largest); } else { sortMode = FileUtilities.SORT_LARGEST; item.setTitle(R.string.sort_smallest); } break; default: break; } this.onResume(); }
From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java
@Override public void onTransactionMenuClick(final View view, final Transaction tx) { final boolean txSent = tx.getValue(wallet).signum() < 0; final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet); final byte[] txSerialized = tx.unsafeBitcoinSerialize(); final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION; final PopupMenu popupMenu = new PopupMenu(activity, view); popupMenu.inflate(R.menu.wallet_transactions_context); final MenuItem editAddressMenuItem = popupMenu.getMenu() .findItem(R.id.wallet_transactions_context_edit_address); if (!txRotation && txAddress != null) { editAddressMenuItem.setVisible(true); final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toString()) == null; final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160()); if (isOwn) editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive); else/* w w w. j ava2 s . c o m*/ editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit); } else { editAddressMenuItem.setVisible(false); } popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr) .setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES); popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee) .setVisible(RaiseFeeDialogFragment.feeCanBeRaised(wallet, tx)); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); return true; case R.id.wallet_transactions_context_browse: if (!txRotation) startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(config.getBlockExplorer(), "tx/" + tx.getHashAsString()))); else startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI)); return true; case R.id.wallet_transactions_context_raise_fee: RaiseFeeDialogFragment.show(getFragmentManager(), tx); return true; } return false; } private void handleEditAddress(final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress); } private void handleShowQr() { final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); popupMenu.show(); }
From source file:com.koushikdutta.superuser.FragmentMain.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem mode = menu.add(Menu.NONE, Menu.NONE, 100, R.string.list_mode); mode.setTitle(pref.getBoolean("grid_mode", true) ? R.string.list_mode : R.string.grid_mode); mode.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); mode.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override//from w w w . j a v a2s.com public boolean onMenuItemClick(MenuItem menuItem) { if (pref.edit().putBoolean("grid_mode", !pref.getBoolean("grid_mode", true)).commit()) getActivity().recreate(); return true; } }); if (!gridMode) return; MenuItem gridSize = menu.add(Menu.NONE, Menu.NONE, 101, R.string.grid_size); gridSize.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); gridSize.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int sizePort = pref.getInt("grid_size_port", 3); int sizeLand = pref.getInt("grid_size_land", 4); final AlertDialog.Builder builder = new AlertDialog.Builder(context); View parent = LayoutInflater.from(context).inflate(R.layout.dialog_settings_grid_size, null); final AppCompatSeekBar seekPort = (AppCompatSeekBar) parent.findViewById(R.id.seek_port); seekPort.setProgress(sizePort - 3); final AppCompatSeekBar seekLand = (AppCompatSeekBar) parent.findViewById(R.id.seek_land); seekLand.setProgress(sizeLand - 3); builder.setView(parent); builder.setPositiveButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SharedPreferences.Editor editor = pref.edit(); editor.putInt("grid_size_port", seekPort.getProgress() + 3); editor.putInt("grid_size_land", seekLand.getProgress() + 3).apply(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { int val = seekPort.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } else if (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int val = seekLand.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } } }); builder.show(); return true; } }); }
From source file:com.zion.htf.ui.fragment.ArtistDetailsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem addAlarmItem = menu.findItem(R.id.action_addAlarm); MenuItem editAlarmItem = menu.findItem(R.id.action_editAlarm); MenuItem toggleFavorite = menu.findItem(R.id.action_toggle_favorite); boolean areAlarmsEnabled = 0 != this.setId; boolean hasAlarm = null != this.alarm; // Add / edit alarm button if (null != addAlarmItem) { addAlarmItem.setVisible(areAlarmsEnabled && !hasAlarm); addAlarmItem.setEnabled(areAlarmsEnabled && !hasAlarm); }// w w w .ja v a 2s. co m if (null != editAlarmItem) { editAlarmItem.setVisible(areAlarmsEnabled && hasAlarm); editAlarmItem.setEnabled(areAlarmsEnabled && hasAlarm); } // Favorite button if (this.artist.isFavorite()) { toggleFavorite.setTitle(R.string.action_unset_favorite); toggleFavorite.setIcon(R.drawable.ic_menu_favorite); } else { toggleFavorite.setTitle(R.string.action_set_favorite); toggleFavorite.setIcon(R.drawable.ic_menu_not_favorite); } }
From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java
private void flipNotifications(MenuItem item) { SharedPreferences.Editor editor = getSharedPreferences(AppConstants.PREFS_FILE, Context.MODE_PRIVATE) .edit();/*from w w w.ja va 2s . c o m*/ notificationEnabled = !notificationEnabled; editor.putBoolean(AppConstants.NOTIFICATIONS, notificationEnabled); editor.apply(); if (trackingEnabled) { item.setTitle(getResources().getString(R.string.disable_notifications)); } else { item.setTitle(getResources().getString(R.string.enable_notifications)); } }
From source file:com.cw.litenote.note.Note.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // System.out.println("Note / _onCreateOptionsMenu"); // inflate menu getMenuInflater().inflate(R.menu.pager_menu, menu); mMenu = menu;// ww w. jav a 2 s . c o m // menu item: checked status // get checked or not int isChecked = mDb_page.getNoteMarking(NoteUi.getFocus_notePos(), true); if (isChecked == 0) menu.findItem(R.id.VIEW_NOTE_CHECK).setIcon(R.drawable.btn_check_off_holo_dark); else menu.findItem(R.id.VIEW_NOTE_CHECK).setIcon(R.drawable.btn_check_on_holo_dark); // menu item: view mode markCurrentSelected(menu.findItem(R.id.VIEW_ALL), "ALL"); markCurrentSelected(menu.findItem(R.id.VIEW_PICTURE), "PICTURE_ONLY"); markCurrentSelected(menu.findItem(R.id.VIEW_TEXT), "TEXT_ONLY"); // menu item: previous MenuItem itemPrev = menu.findItem(R.id.ACTION_PREVIOUS); itemPrev.setEnabled(viewPager.getCurrentItem() > 0); itemPrev.getIcon().setAlpha(viewPager.getCurrentItem() > 0 ? 255 : 30); // menu item: Next or Finish MenuItem itemNext = menu.findItem(R.id.ACTION_NEXT); itemNext.setTitle((viewPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.view_note_slide_action_finish : R.string.view_note_slide_action_next); // set Disable and Gray for Last item boolean isLastOne = (viewPager.getCurrentItem() == (mPagerAdapter.getCount() - 1)); if (isLastOne) itemNext.setEnabled(false); itemNext.getIcon().setAlpha(isLastOne ? 30 : 255); return true; }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java
/** * {@inheritDoc}/*from w ww. jav a 2s . c o m*/ */ @Override public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Get the MenuInflater. final MenuInflater inflater = getActivity().getMenuInflater(); // Cast the menuInfo object to something we understand. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; // Get the item relating to the selected item. selectedStop = ad.getItem(info.position); final String name; if (selectedStop.locality != null) { name = getString(R.string.busstop_locality, selectedStop.stopName, selectedStop.locality, selectedStop.stopCode); } else { name = getString(R.string.busstop, selectedStop.stopName, selectedStop.stopCode); } // Set the title of the context menu. menu.setHeaderTitle(name); // Inflate the menu from XML. inflater.inflate(R.menu.neareststops_context_menu, menu); // Title depends on whether it's already a favourite or not. MenuItem item = menu.findItem(R.id.neareststops_context_menu_favourite); if (sd.getFavouriteStopExists(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_context_remasfav); } else { item.setTitle(R.string.neareststops_context_addasfav); } // Title depends on whether a proximity alert has already been added or // not. item = menu.findItem(R.id.neareststops_context_menu_prox_alert); if (sd.isActiveProximityAlert(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_menu_prox_rem); } else { item.setTitle(R.string.neareststops_menu_prox_add); } // Title depends on whether a time alert has already been added or not. item = menu.findItem(R.id.neareststops_context_menu_time_alert); if (sd.isActiveTimeAlert(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_menu_time_rem); } else { item.setTitle(R.string.neareststops_menu_time_add); } // If the Google Play Services is not available, then don't show the // option to show the stop on the map. item = menu.findItem(R.id.neareststops_context_menu_showonmap); if (!GenericUtils.isGoogleMapsAvailable(getActivity())) { item.setVisible(false); } }