List of usage examples for android.view MenuItem setVisible
public MenuItem setVisible(boolean visible);
From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java
/** * Load the menu from the movement_detail.xml file. * //from w w w . j a v a2 s.co m * Activates and deactivates the put and drop menu buttons depending of the * movement. * * @param menu * Menu to be inflated with the menu inflater. */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.movement_detail, menu); MenuItem item; item = menu.findItem(R.id.action_get_from_moneybox); item.setVisible(MovementsManager.canGetMovement(_movement)); item.setEnabled(item.isVisible()); item = menu.findItem(R.id.action_drop_to_moneybox); item.setVisible(MovementsManager.canDropMovement(_movement)); item.setEnabled(item.isVisible()); item = menu.findItem(R.id.action_delete_movement); item.setVisible(MovementsManager.canDeleteMovement(_movement)); item.setEnabled(item.isVisible()); return true; }
From source file:app.umitems.greenclock.DeskClock.java
private void updateMenu(Menu menu) { // Hide "help" if we don't have a URI for it. MenuItem help = menu.findItem(R.id.menu_item_help); if (help != null) { Utils.prepareHelpMenuItem(this, help); }/* ww w .j a v a2s . co m*/ // Hide "lights out" for timer. MenuItem nightMode = menu.findItem(R.id.menu_item_night_mode); if (mActionBar.getSelectedNavigationIndex() == ALARM_TAB_INDEX) { nightMode.setVisible(false); } else if (mActionBar.getSelectedNavigationIndex() == CLOCK_TAB_INDEX) { nightMode.setVisible(true); } }
From source file:de.aw.monma.wertpapier.FragmentWertpapierBuchungenListe.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_wp_buchungen, menu); if (mWPID == NOID) { // SearchView nur zeigen, wenn nicht auf ein WP eingeschraenkt MenuItem item = menu.findItem(R.id.menu_List_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(this); item.setVisible(true); }/*from ww w . j a va2 s .c o m*/ }
From source file:com.granita.tasks.ViewTaskFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { /*//from w w w. ja v a2s .c o m * Don't show any options if we don't have a task to show. */ if (mTaskUri != null) { inflater.inflate(R.menu.view_task_fragment_menu, menu); if (mContentSet != null) { Integer status = TaskFieldAdapters.STATUS.get(mContentSet); if (status != null) { mOldStatus = status; } if (TaskFieldAdapters.IS_CLOSED.get(mContentSet) || status != null && status == Tasks.STATUS_COMPLETED) { // we disable the edit option, because the task is completed and the action button shows the edit option. MenuItem item = menu.findItem(R.id.edit_task); item.setEnabled(false); item.setVisible(false); } } } }
From source file:me.acristoffers.tracker.activities.PackageListActivity.java
@Override public void onCardViewClicked(final me.acristoffers.tracker.Package pkg) { if (PackageListAdapter.isSelecting) { if (selection.contains(pkg)) { final ArrayList<Package> removeList = new ArrayList<>(); for (final Package p : selection) { if (p.equals(pkg)) { removeList.add(p);//from www. j a va 2 s . c o m } } selection.removeAll(removeList); } else { selection.add(pkg); } if (actionMode != null) { final Menu menu = actionMode.getMenu(); if (menu != null) { final MenuItem menuItem = menu.findItem(R.id.edit); if (menuItem != null) { menuItem.setVisible(selection.size() == 1); } } if (selection.isEmpty()) { actionMode.finish(); } } } else { if (isTablet) { final Bundle args = new Bundle(); args.putString(PackageDetailsActivity.PACKAGE_CODE, pkg.getCod()); final PackageDetailsFragment fragment = new PackageDetailsFragment(); fragment.setArguments(args); final FragmentManager supportFragmentManager = getSupportFragmentManager(); if (supportFragmentManager != null) { final FragmentTransaction transaction = supportFragmentManager.beginTransaction(); transaction.replace(R.id.package_details, fragment); transaction.addToBackStack(null); transaction.commit(); } packageListFragment.reloadData(); } else { final Intent intent = new Intent(this, PackageDetailsActivity.class); intent.putExtra(PackageDetailsActivity.PACKAGE_CODE, pkg.getCod()); startActivity(intent); } } }
From source file:com.battlelancer.seriesguide.ui.MovieDetailsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (mMovieDetails != null) { boolean isLightTheme = SeriesGuidePreferences.THEME == R.style.Theme_SeriesGuide_Light; inflater.inflate(isLightTheme ? R.menu.movie_details_menu_light : R.menu.movie_details_menu, menu); // hide Google Play button in Amazon version if (Utils.isAmazonVersion()) { MenuItem playStoreItem = menu.findItem(R.id.menu_open_google_play); playStoreItem.setEnabled(false); playStoreItem.setVisible(false); }//from w ww. j ava2 s . c o m } }
From source file:com.battlelancer.seriesguide.ui.MovieDetailsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (mMovieDetails != null) { boolean isEnableShare = mMovieDetails.tmdbMovie() != null && !TextUtils.isEmpty(mMovieDetails.tmdbMovie().title); MenuItem shareItem = menu.findItem(R.id.menu_movie_share); shareItem.setEnabled(isEnableShare); shareItem.setVisible(isEnableShare); if (!Utils.isAmazonVersion()) { MenuItem playStoreItem = menu.findItem(R.id.menu_open_google_play); playStoreItem.setEnabled(isEnableShare); playStoreItem.setVisible(isEnableShare); }/*from w ww . ja v a 2 s . c om*/ boolean isEnableImdb = mMovieDetails.traktMovie() != null && !TextUtils.isEmpty(mMovieDetails.traktMovie().imdb_id); MenuItem imdbItem = menu.findItem(R.id.menu_open_imdb); imdbItem.setEnabled(isEnableImdb); imdbItem.setVisible(isEnableImdb); boolean isEnableYoutube = mTrailers != null && mTrailers.youtube.size() > 0; MenuItem youtubeItem = menu.findItem(R.id.menu_open_youtube); youtubeItem.setEnabled(isEnableYoutube); youtubeItem.setVisible(isEnableYoutube); } }
From source file:de.azapps.mirakel.main_activity.task_fragment.TaskFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { this.cabState = null; this.markedFiles = new LongSparseArray<>(); this.markedSubtasks = new LongSparseArray<>(); this.main = (MainActivity) getActivity(); View view;//from w ww . jav a 2s . c om this.updateThread = new Runnable() { @Override public void run() { TaskFragment.this.detailView.update(TaskFragment.this.task); } }; try { view = inflater.inflate(R.layout.task_fragment, container, false); } catch (final Exception e) { Log.w(TaskFragment.TAG, "Failed do inflate layout", e); return null; } this.detailView = (TaskDetailView) view.findViewById(R.id.task_fragment_view); this.detailView.setOnTaskChangedListner(new OnTaskChangedListner() { @Override public void onTaskChanged(final Task newTask) { if (TaskFragment.this.main.getTasksFragment() != null && TaskFragment.this.main.getListFragment() != null) { TaskFragment.this.main.getTasksFragment().updateList(); TaskFragment.this.main.getListFragment().update(); } } }); this.detailView.setOnSubtaskClick(new OnTaskClickListener() { @Override public void onTaskClick(final Task t) { TaskFragment.this.main.setCurrentTask(t); } }); this.detailView.setFragmentManager(new NeedFragmentManager() { @Override public FragmentManager getFragmentManager() { return TaskFragment.this.main.getSupportFragmentManager(); } }); if (MirakelCommonPreferences.useBtnCamera() && Helpers.isIntentAvailable(this.main, MediaStore.ACTION_IMAGE_CAPTURE)) { this.detailView.setAudioButtonClick(new View.OnClickListener() { @Override public void onClick(final View v) { TaskDialogHelpers.handleAudioRecord(getActivity(), TaskFragment.this.task, new ExecInterfaceWithTask() { @Override public void exec(final Task t) { update(t); } }); } }); this.detailView.setCameraButtonClick(new View.OnClickListener() { @Override public void onClick(final View v) { try { final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final Uri fileUri = FileUtils.getOutputMediaFileUri(FileUtils.MEDIA_TYPE_IMAGE); if (fileUri == null) { return; } TaskFragment.this.main.setFileUri(fileUri); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); getActivity().startActivityForResult(cameraIntent, MainActivity.RESULT_ADD_PICTURE); } catch (final ActivityNotFoundException a) { ErrorReporter.report(ErrorType.PHOTO_NO_CAMERA); } catch (final IOException e) { if (e.getMessage().equals(FileUtils.ERROR_NO_MEDIA_DIR)) { ErrorReporter.report(ErrorType.PHOTO_NO_MEDIA_DIRECTORY); } } } }); } if (this.task != null) { update(this.task); } this.detailView.setOnSubtaskMarked(new OnTaskMarkedListener() { @Override public void markTask(final View v, final Task t, final boolean marked) { if (t == null || TaskFragment.this.cabState != null && TaskFragment.this.cabState != ActionbarState.SUBTASK) { return; } if (marked) { TaskFragment.this.cabState = ActionbarState.SUBTASK; if (mActionMode == null) { main.startActionMode(mActionModeCallback); } v.setBackgroundColor(Helpers.getHighlightedColor(getActivity())); TaskFragment.this.markedSubtasks.put(t.getId(), t); } else { Log.d(TaskFragment.TAG, "not marked"); v.setBackgroundColor(getActivity().getResources().getColor(android.R.color.transparent)); TaskFragment.this.markedSubtasks.remove(t.getId()); if (TaskFragment.this.markedSubtasks.size() == 0 && mActionMode != null) { mActionMode.finish(); } } if (TaskFragment.this.mMenu != null) { final MenuItem item = TaskFragment.this.mMenu.findItem(R.id.edit_task); if (mActionMode != null && item != null) { item.setVisible(TaskFragment.this.markedSubtasks.size() == 1); } } } }); this.detailView.setOnFileMarked(new OnFileMarkedListener() { @Override public void markFile(final View v, final FileMirakel e, final boolean marked) { if (e == null || TaskFragment.this.cabState != null && TaskFragment.this.cabState != ActionbarState.FILE) { return; } if (marked) { TaskFragment.this.cabState = ActionbarState.FILE; if (mActionMode == null) { main.startActionMode(mActionModeCallback); } v.setBackgroundColor(Helpers.getHighlightedColor(getActivity())); TaskFragment.this.markedFiles.put(e.getId(), e); } else { v.setBackgroundColor(getActivity().getResources().getColor(android.R.color.transparent)); TaskFragment.this.markedFiles.remove(e.getId()); if (TaskFragment.this.markedFiles.size() == 0 && mActionMode != null) { mActionMode.finish(); } } } }); this.detailView.setOnFileClicked(new OnFileClickListener() { @Override public void clickOnFile(final FileMirakel file) { final Context context = getActivity(); String[] items; if (FileUtils.isAudio(file.getFileUri())) { items = context.getResources().getStringArray(R.array.audio_playback_options); } else { TaskDialogHelpers.openFile(context, file); return; } new AlertDialog.Builder(context).setTitle(R.string.audio_playback_select_title) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { switch (which) { case 0: // Open TaskDialogHelpers.openFile(context, file); break; default: // playback TaskDialogHelpers.playbackFile(getActivity(), file, which == 1); break; } } }).show(); return; } }); this.detailView.update(this.main.getCurrentTask()); return view; }
From source file:de.hackerspacebremen.StartActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean result = true; switch (item.getItemId()) { case R.id.settings: final Intent intent = new Intent(this, SettingActivity.class); startActivity(intent);//from w w w .ja va 2 s .co m break; case R.id.change: this.manageFragment(FragmentState.CHANGE_SHOWN, null); item.setVisible(false); break; // case R.id.map: // this.manageFragment(FragmentState.MAP_SHOWN, null); // item.setVisible(false); // break; // case R.id.news: // this.manageFragment(FragmentState.NEWS_SHOWN, null); // item.setVisible(false); // break; case R.id.about: // use support library with fragment dialog instead final FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction(); final DialogFragment newFragment = new AboutDialogFragment(); newFragment.show(transaction, "dialog"); break; case R.id.refresh: EventBus.getDefault().post(new RefreshEvent()); break; default: result = super.onOptionsItemSelected(item); } return result; }
From source file:de.k3b.android.toGoZip.SettingsActivity.java
private void updateMenuItem(Menu menu, int cmd, int menuTitle, boolean visible) { MenuItem item = menu.findItem(cmd); if (item != null) { if ((visible) && (menuTitle != 0)) { item.setTitle(getString(menuTitle, SettingsImpl.getZipFile())); }//from w w w.j a v a 2s. com item.setVisible(visible); } }