List of usage examples for android.view MenuInflater inflate
public void inflate(@MenuRes int menuRes, Menu menu)
From source file:com.best.ui.Otpdescdetail.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { System.out.println("in onPrepareOptionsMenu of stops.java"); MenuInflater inflater = getMenuInflater(); menu.clear();/*w w w .jav a2 s .com*/ /*if((tripsDisplayed == false && tripsRouteDisplayed == false && searchResultDisplayed == false)||(tripsDisplayed==true && tripsRouteDisplayed == false)) { inflater.inflate(com.best.ui.R.menu.search, menu); return true; } */ if (iterlistdisplayed == false && busRouteDisplayed == true && individualModePage == false) { inflater.inflate(com.best.ui.R.menu.onlymap, menu); return true; } return false; }
From source file:com.gimranov.zandy.app.AttachmentActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.zotero_menu, menu); return true; }
From source file:fr.shywim.antoinedaniel.ui.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return false; }
From source file:com.farmerbb.notepad.fragment.NoteListFragment.java
private void listNotes() { // Get array of file names String[] listOfFiles = getActivity().getFilesDir().list(); ArrayList<String> listOfNotes = new ArrayList<>(); // Get number of files int numOfNotes = listOfFiles.length; // Remove any files from the list that aren't notes for (String listOfFile : listOfFiles) { if (NumberUtils.isCreatable(listOfFile)) listOfNotes.add(listOfFile); else/*from www. j a va 2 s . c o m*/ numOfNotes--; } // Create arrays of note lists String[] listOfNotesByDate = new String[numOfNotes]; String[] listOfNotesByName = new String[numOfNotes]; NoteListItem[] listOfTitlesByDate = new NoteListItem[numOfNotes]; NoteListItem[] listOfTitlesByName = new NoteListItem[numOfNotes]; ArrayList<NoteListItem> list = new ArrayList<>(numOfNotes); for (int i = 0; i < numOfNotes; i++) { listOfNotesByDate[i] = listOfNotes.get(i); } // If sort-by is "by date", sort in reverse order if (sortBy.startsWith("date")) { Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); if (sortBy.endsWith("reversed")) ArrayUtils.reverse(listOfNotesByDate); } // Get array of first lines of each note for (int i = 0; i < numOfNotes; i++) { try { String title = listener.loadNoteTitle(listOfNotesByDate[i]); String date = listener.loadNoteDate(listOfNotesByDate[i]); listOfTitlesByDate[i] = new NoteListItem(title, date); } catch (IOException e) { showToast(R.string.error_loading_list); } } // If sort-by is "by name", sort alphabetically if (sortBy.startsWith("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); if (sortBy.endsWith("reversed")) ArrayUtils.reverse(listOfTitlesByName); // Initialize notes array for (int i = 0; i < numOfNotes; i++) listOfNotesByName[i] = "new"; // Copy filenames array with new sort order of titles and nullify date arrays for (int i = 0; i < numOfNotes; i++) { for (int j = 0; j < numOfNotes; j++) { if (listOfTitlesByName[i].getNote().equals(listOfTitlesByDate[j].getNote()) && listOfNotesByName[i].equals("new")) { listOfNotesByName[i] = listOfNotesByDate[j]; listOfNotesByDate[j] = ""; listOfTitlesByDate[j] = new NoteListItem("", ""); } } } // Populate ArrayList with notes, showing name as first line of the notes list.addAll(Arrays.asList(listOfTitlesByName)); } else if (sortBy.startsWith("date")) list.addAll(Arrays.asList(listOfTitlesByDate)); // Create the custom adapters to bind the array to the ListView final NoteListDateAdapter dateAdapter = new NoteListDateAdapter(getActivity(), list); final NoteListAdapter adapter = new NoteListAdapter(getActivity(), list); // Display the ListView if (showDate) listView.setAdapter(dateAdapter); else listView.setAdapter(adapter); listView.setSelection(ScrollPositions.getInstance().getPosition()); // Finalize arrays to prepare for handling clicked items final String[] finalListByDate = listOfNotesByDate; final String[] finalListByName = listOfNotesByName; // Make ListView handle clicked items listView.setClickable(true); listView.setOnItemClickListener((arg0, arg1, position, arg3) -> { ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition()); if (sortBy.startsWith("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.startsWith("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } }); // Make ListView handle contextual action bar final ArrayList<String> cab = listener.getCabArray(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_select_all: cab.clear(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { listView.setItemChecked(i, true); } return false; case R.id.action_export: if (cab.size() > 0) { mode.finish(); // Action picked, so close the CAB listener.exportNotes(); return true; } else { showToast(R.string.no_notes_to_export); return false; } case R.id.action_delete: if (cab.size() > 0) { mode.finish(); // Action picked, so close the CAB listener.deleteNotes(); return true; } else { showToast(R.string.no_notes_to_delete); return false; } default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { listener.hideFab(); // Inflate the menu for the CAB MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); // Clear any old values from cab array cab.clear(); return true; } @Override public void onDestroyActionMode(ActionMode mode) { listener.showFab(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (position > -1) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.startsWith("date")) cab.add(finalListByDate[position]); if (sortBy.startsWith("name")) cab.add(finalListByName[position]); } else { if (sortBy.startsWith("date")) cab.remove(finalListByDate[position]); if (sortBy.startsWith("name")) cab.remove(finalListByName[position]); } listView.setItemChecked(-1, false); } // Update the title in CAB mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); if (cab.size() > 0) { List<String> cabClone = new ArrayList<>(cab); cab.clear(); String[] array = null; if (sortBy.startsWith("date")) array = finalListByDate; if (sortBy.startsWith("name")) array = finalListByName; if (array != null) { for (String filename : cabClone) { for (int i = 0; i < array.length; i++) { if (filename.equals(array[i])) listView.setItemChecked(i, true); } } } } // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:chaitanya.im.searchforreddit.LauncherActivity.java
public void showPopup(View view) { UtilMethods.hideKeyboard(this); PopupMenu popupMenu = new PopupMenu(this, view); MenuInflater inflater = popupMenu.getMenuInflater(); if (view.getId() == R.id.time_button) { inflater.inflate(R.menu.time_filter, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(timePopupListener); } else if (view.getId() == R.id.sort_button) { inflater.inflate(R.menu.sort_filter, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(sortPopupListener); }/*from w w w. j ava 2 s. c o m*/ popupMenu.show(); }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.menu_send_image, menu); }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.menu_settings, menu); return super.onCreateOptionsMenu(menu); }
From source file:com.gimranov.zandy.app.ItemActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.zotero_menu, menu); // Turn on sort item MenuItem sort = menu.findItem(R.id.do_sort); sort.setEnabled(true);/*from w w w. ja v a2 s . c o m*/ sort.setVisible(true); // Turn on search item MenuItem search = menu.findItem(R.id.do_search); search.setEnabled(true); search.setVisible(true); // Turn on identifier item MenuItem identifier = menu.findItem(R.id.do_identifier); identifier.setEnabled(true); identifier.setVisible(true); return true; }
From source file:com.andfchat.frontend.activities.ChatScreen.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_main_screen, menu); return super.onCreateOptionsMenu(menu); }
From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (!isTabletPreference(context)) { inflater.inflate(R.menu.menu_detail, menu); finishCreatingMenu(menu);//from w w w .j a v a 2s . c o m } }