List of usage examples for android.view ActionMode setTitle
public abstract void setTitle(@StringRes int resId);
From source file:org.thialfihar.android.apg.ui.KeyListSecretFragment.java
/** * Define Adapter and Loader on create of Activity *//* w w w. j av a 2 s.c o m*/ @SuppressLint("NewApi") @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mKeyListSecretActivity = (KeyListSecretActivity) getActivity(); getListView().setOnItemClickListener(this); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(getString(R.string.list_empty)); /* * ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only * available for Android >= 3.0 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { android.view.MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.key_list_secret_multi, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { Set<Integer> positions = mAdapter.getCurrentCheckedPosition(); // get IDs for checked positions as long array long[] ids = new long[positions.size()]; int i = 0; for (int pos : positions) { ids[i] = mAdapter.getItemId(pos); i++; } switch (item.getItemId()) { case R.id.menu_key_list_public_multi_delete: { showDeleteKeyDialog(mode, ids); break; } case R.id.menu_key_list_public_multi_select_all: { // select all int localCount = getListView().getCount(); for (int k = 0; k < localCount; k++) { getListView().setItemChecked(k, true); } break; } } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearSelection(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mAdapter.setNewSelection(position, checked); } else { mAdapter.removeSelection(position); } int count = getListView().getCheckedItemCount(); String keysSelected = getResources().getQuantityString(R.plurals.key_list_selected_keys, count, count); mode.setTitle(keysSelected); } }); } // We have a menu item to show in action bar. setHasOptionsMenu(true); // Start out with a progress indicator. setListShown(false); // Create an empty adapter we will use to display the loaded data. mAdapter = new KeyListSecretAdapter(mKeyListSecretActivity, null, 0); setListAdapter(mAdapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
From source file:com.miz.mizuu.fragments.TvShowEpisodesFragment.java
public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); if (MizLib.isTablet(mContext) && !MizLib.isPortrait(mContext)) { v.findViewById(R.id.container).setBackgroundColor(Color.parseColor("#05FFFFFF")); }//w w w. ja va 2 s. com mAdapter = new ImageAdapter(mContext); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mGridView = (GridView) v.findViewById(R.id.gridView); mGridView.setColumnWidth(mImageThumbSize); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setEmptyView(v.findViewById(R.id.progress)); mGridView.setAdapter(mAdapter); if (mUseGridView) { // Calculate the total column width to set item heights by factor 1.5 mGridView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { mAdapter.setNumColumns(numColumns); mResizedWidth = (int) (((mGridView.getWidth() - (numColumns * mImageThumbSpacing)) / numColumns) * 1.1); // * 1.1 is a hack to make images look slightly less blurry mResizedHeight = (int) (mResizedWidth / 1.778); } } } }); } else { mGridView.setNumColumns(1); mAdapter.setNumColumns(1); } mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent i = new Intent(mContext, TvShowEpisodeDetails.class); i.putExtra(SHOW_ID, mShowId); i.putExtra("episode", mEpisodeLoader.getResults().get(arg2).getEpisode()); i.putExtra("season", mSeason); getActivity().startActivityForResult(i, 0); } }); mGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { mGridView.setItemChecked(position, true); return true; } }); mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.episodes_contextual, menu); mContextualActionBarEnabled = true; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.watched: changeWatchedStatus(true, new HashSet<Integer>(mCheckedEpisodes)); break; case R.id.unwatched: changeWatchedStatus(false, new HashSet<Integer>(mCheckedEpisodes)); break; case R.id.remove: removeSelectedEpisodes(new HashSet<Integer>(mCheckedEpisodes)); break; case R.id.identify: identify(new HashSet<Integer>(mCheckedEpisodes)); break; } mode.finish(); // Make the seasons grid refresh mBus.post(new com.miz.mizuu.TvShowEpisode()); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mContextualActionBarEnabled = false; mCheckedEpisodes.clear(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) mCheckedEpisodes.add(mEpisodeLoader.getResults().get(position).getEpisode()); else mCheckedEpisodes.remove(mEpisodeLoader.getResults().get(position).getEpisode()); int count = mCheckedEpisodes.size(); mode.setTitle( count + " " + getResources().getQuantityString(R.plurals.episodes_selected, count, count)); // Nasty hack to update the selected items highlight... mAdapter.notifyDataSetChanged(); } }); // The layout has been created - let's load the data loadEpisodes(); }
From source file:com.notepadlite.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void listNotes() { // Get number of files int numOfFiles = getNumOfNotes(getActivity().getFilesDir()); int numOfNotes = numOfFiles; // Get array of file names String[] listOfFiles = getListOfNotes(getActivity().getFilesDir()); ArrayList<String> listOfNotes = new ArrayList<>(); // Remove any files from the list that aren't notes for (int i = 0; i < numOfFiles; i++) { if (NumberUtils.isNumber(listOfFiles[i])) listOfNotes.add(listOfFiles[i]); else/*from w w w. j a v a 2 s .com*/ numOfNotes--; } // Declare ListView final ListView listView = (ListView) getActivity().findViewById(R.id.listView1); // 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.equals("date")) Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); // 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.equals("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); // 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.equals("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); // 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(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (sortBy.equals("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.equals("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } } }); // Make ListView handle contextual action bar final ArrayList<String> cab = new ArrayList<>(numOfNotes); 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_export: mode.finish(); // Action picked, so close the CAB listener.exportNote(cab.toArray()); return true; case R.id.action_delete: mode.finish(); // Action picked, so close the CAB listener.deleteNote(cab.toArray()); return true; 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) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.equals("date")) cab.add(finalListByDate[position]); if (sortBy.equals("name")) cab.add(finalListByName[position]); } else { if (sortBy.equals("date")) cab.remove(finalListByDate[position]); if (sortBy.equals("name")) cab.remove(finalListByName[position]); } // Update the title in CAB if (cab.size() == 0) mode.setTitle(""); else mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = (TextView) getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:com.anjalimacwan.fragment.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void listNotes() { // Get number of files int numOfFiles = getNumOfNotes(getActivity().getFilesDir()); int numOfNotes = numOfFiles; // Get array of file names String[] listOfFiles = getListOfNotes(getActivity().getFilesDir()); ArrayList<String> listOfNotes = new ArrayList<>(); // Remove any files from the list that aren't notes for (int i = 0; i < numOfFiles; i++) { if (NumberUtils.isNumber(listOfFiles[i])) listOfNotes.add(listOfFiles[i]); else//from w w w. ja va 2 s .co m numOfNotes--; } // Declare ListView final ListView listView = (ListView) getActivity().findViewById(R.id.listView1); // 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.equals("date")) Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); // 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.equals("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); // 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.equals("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); // 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(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (sortBy.equals("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.equals("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } } }); // Make ListView handle contextual action bar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final ArrayList<String> cab = new ArrayList<>(numOfNotes); 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_export: mode.finish(); // Action picked, so close the CAB listener.exportNote(cab.toArray()); return true; case R.id.action_delete: mode.finish(); // Action picked, so close the CAB listener.deleteNote(cab.toArray()); return true; 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) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.equals("date")) cab.add(finalListByDate[position]); if (sortBy.equals("name")) cab.add(finalListByName[position]); } else { if (sortBy.equals("date")) cab.remove(finalListByDate[position]); if (sortBy.equals("name")) cab.remove(finalListByName[position]); } // Update the title in CAB if (cab.size() == 0) mode.setTitle(""); else mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); } // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = (TextView) getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:org.thialfihar.android.apg.ui.KeyListPublicFragment.java
/** * Define Adapter and Loader on create of Activity *///ww w.java 2 s . c om @SuppressLint("NewApi") @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list); mStickyList.setOnItemClickListener(this); mStickyList.setAreHeadersSticky(true); mStickyList.setDrawingListUnderStickyHeader(false); mStickyList.setFastScrollEnabled(true); try { mStickyList.setFastScrollAlwaysVisible(true); } catch (ApiLevelTooLowException e) { } // this view is made visible if no data is available mStickyList.setEmptyView(getActivity().findViewById(R.id.empty)); /* * ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only * available for Android >= 3.0 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { android.view.MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.key_list_public_multi, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { Set<Integer> positions = mAdapter.getCurrentCheckedPosition(); // get IDs for checked positions as long array long[] ids = new long[positions.size()]; int i = 0; for (int pos : positions) { ids[i] = mAdapter.getItemId(pos); i++; } switch (item.getItemId()) { case R.id.menu_key_list_public_multi_encrypt: { encrypt(mode, ids); break; } case R.id.menu_key_list_public_multi_delete: { showDeleteKeyDialog(mode, ids); break; } case R.id.menu_key_list_public_multi_select_all: { // select all int localCount = mStickyList.getCount(); for (int k = 0; k < localCount; k++) { mStickyList.setItemChecked(k, true); } break; } } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearSelection(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mAdapter.setNewSelection(position, checked); } else { mAdapter.removeSelection(position); } int count = mAdapter.getCurrentCheckedPosition().size(); String keysSelected = getResources().getQuantityString(R.plurals.key_list_selected_keys, count, count); mode.setTitle(keysSelected); } }); } // NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading // Start out with a progress indicator. // setListShown(false); // Create an empty adapter we will use to display the loaded data. mAdapter = new KeyListPublicAdapter(getActivity(), null, Id.type.public_key, USER_ID_INDEX); mStickyList.setAdapter(mAdapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mRootView = container;// w w w. j a v a2 s. c o m final View view = inflater.inflate(R.layout.playlist_activity, container, false); mSearchView = (SearchView) view.findViewById(R.id.search); mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(final String newText) { mFilter = newText; if (newText != null && newText.isEmpty()) { mFilter = null; } if (mFilter != null) { mFilter = mFilter.toLowerCase(); } mList.setDragEnabled(mFilter == null); update(false); return false; } @Override public boolean onQueryTextSubmit(final String query) { // Hide the keyboard and give focus to the list final InputMethodManager imm = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); mList.requestFocus(); return true; } }); mList = (DragSortListView) view.findViewById(android.R.id.list); mList.requestFocus(); mList.setDropListener(mDropListener); mController = new DragSortController(mList); mController.setDragHandleId(R.id.cover); mController.setRemoveEnabled(false); mController.setSortEnabled(true); mController.setDragInitMode(1); mList.setFloatViewManager(mController); mList.setOnTouchListener(mController); mList.setDragEnabled(true); refreshListColorCacheHint(); mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { final SparseBooleanArray checkedItems = mList.getCheckedItemPositions(); final int count = mList.getCount(); final ListAdapter adapter = mList.getAdapter(); final int itemId = item.getItemId(); int j = 0; int[] positions = null; boolean result = true; if (itemId == R.id.menu_delete) { positions = new int[mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else if (itemId == R.id.menu_crop) { positions = new int[mList.getCount() - mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (!checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else { result = false; } if (j > 0) { QueueControl.run(QueueControl.REMOVE_BY_ID, positions); mode.finish(); } return result; } @Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.mpd_queuemenu, menu); return true; } @Override public void onDestroyActionMode(final ActionMode mode) { mActionMode = null; mController.setSortEnabled(true); } @Override public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id, final boolean checked) { final int selectCount = mList.getCheckedItemCount(); if (selectCount == 0) { mode.finish(); } if (selectCount == 1) { mode.setTitle(R.string.actionSongSelected); } else { mode.setTitle(getString(R.string.actionSongsSelected, selectCount)); } } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { mActionMode = mode; mController.setSortEnabled(false); return false; } }); return view; }
From source file:org.sufficientlysecure.keychain.ui.KeyListFragment.java
/** * Define Adapter and Loader on create of Activity *///w w w . j a va 2 s. c o m @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mStickyList.setOnItemClickListener(this); mStickyList.setAreHeadersSticky(true); mStickyList.setDrawingListUnderStickyHeader(false); mStickyList.setFastScrollEnabled(true); /* * Multi-selection is only available for Android >= 3.0 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mStickyList.setFastScrollAlwaysVisible(true); mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { android.view.MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.key_list_multi, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // get IDs for checked positions as long array long[] ids; switch (item.getItemId()) { case R.id.menu_key_list_multi_encrypt: { ids = mAdapter.getCurrentSelectedMasterKeyIds(); encrypt(mode, ids); break; } case R.id.menu_key_list_multi_delete: { ids = mAdapter.getCurrentSelectedMasterKeyIds(); showDeleteKeyDialog(mode, ids, mAdapter.isAnySecretSelected()); break; } case R.id.menu_key_list_multi_export: { ids = mAdapter.getCurrentSelectedMasterKeyIds(); ExportHelper mExportHelper = new ExportHelper((ActionBarActivity) getActivity()); mExportHelper.showExportKeysDialog(ids, Constants.Path.APP_DIR_FILE, mAdapter.isAnySecretSelected()); break; } case R.id.menu_key_list_multi_select_all: { // select all for (int i = 0; i < mStickyList.getCount(); i++) { mStickyList.setItemChecked(i, true); } break; } } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearSelection(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mAdapter.setNewSelection(position, checked); } else { mAdapter.removeSelection(position); } int count = mStickyList.getCheckedItemCount(); String keysSelected = getResources().getQuantityString(R.plurals.key_list_selected_keys, count, count); mode.setTitle(keysSelected); } }); } // We have a menu item to show in action bar. setHasOptionsMenu(true); // Start out with a progress indicator. setContentShown(false); // Create an empty adapter we will use to display the loaded data. mAdapter = new KeyListAdapter(getActivity(), null, 0); mStickyList.setAdapter(mAdapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
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 w w w.j ava2s.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:org.thialfihar.android.apg.ui.KeyListFragment.java
/** * Define Adapter and Loader on create of Activity *//*from w w w . ja v a2 s.com*/ @SuppressLint("NewApi") @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mStickyList.setOnItemClickListener(this); mStickyList.setAreHeadersSticky(true); mStickyList.setDrawingListUnderStickyHeader(false); mStickyList.setFastScrollEnabled(true); try { mStickyList.setFastScrollAlwaysVisible(true); } catch (ApiLevelTooLowException e) { } // this view is made visible if no data is available mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty)); /* * ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only * available for Android >= 3.0 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.key_list_multi, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // get IDs for checked positions as long array long[] ids; switch (item.getItemId()) { case R.id.menu_key_list_multi_encrypt: { ids = mAdapter.getCurrentSelectedMasterKeyIds(); encrypt(mode, ids); break; } case R.id.menu_key_list_multi_delete: { ids = mStickyList.getWrappedList().getCheckedItemIds(); showDeleteKeyDialog(mode, ids); break; } case R.id.menu_key_list_multi_export: { ids = mStickyList.getWrappedList().getCheckedItemIds(); long[] masterKeyIds = new long[2 * ids.length]; ArrayList<Long> allPubRowIds = ProviderHelper.getPublicKeyRingsRowIds(getActivity()); for (int i = 0; i < ids.length; i++) { if (allPubRowIds.contains(ids[i])) { masterKeyIds[i] = ProviderHelper.getPublicMasterKeyId(getActivity(), ids[i]); } else { masterKeyIds[i] = ProviderHelper.getSecretMasterKeyId(getActivity(), ids[i]); } } ExportHelper mExportHelper = new ExportHelper((ActionBarActivity) getActivity()); mExportHelper.showExportKeysDialog(masterKeyIds, Id.type.public_key, Constants.Path.APP_DIR_FILE_PUB, getString(R.string.also_export_secret_keys)); break; } case R.id.menu_key_list_multi_select_all: { // select all for (int i = 0; i < mStickyList.getCount(); i++) { mStickyList.setItemChecked(i, true); } break; } } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearSelection(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mAdapter.setNewSelection(position, checked); } else { mAdapter.removeSelection(position); } int count = mStickyList.getCheckedItemCount(); String keysSelected = getResources().getQuantityString(R.plurals.key_list_selected_keys, count, count); mode.setTitle(keysSelected); } }); } // We have a menu item to show in action bar. setHasOptionsMenu(true); // NOTE: Not supported by StickyListHeader, but reimplemented here // Start out with a progress indicator. setListShown(false); // Create an empty adapter we will use to display the loaded data. mAdapter = new KeyListAdapter(getActivity(), null, Id.type.public_key); mStickyList.setAdapter(mAdapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
public boolean onClick(int id, MenuItem item, View from) { super.onClick(id); if (from == null || !from.isShown()) from = findViewById(id);//from www . j a v a 2 s . c o m if (id != R.id.title_icon && id != android.R.id.home) ; toggleBookmarks(false); OpenFragment f = getSelectedFragment(); if (f != null && f.onClick(id, from)) return true; if (item != null && f != null && f.onOptionsItemSelected(item)) return true; if (DEBUG) Logger.LogDebug("OpenExplorer.onClick(0x" + Integer.toHexString(id) + "," + item + "," + from + ")"); switch (id) { case R.id.menu_debug: debugTest(); break; case R.id.title_icon: case android.R.id.home: toggleBookmarks(); return true; case R.id.menu_multi: if (getClipboard().isMultiselect()) { getClipboard().stopMultiselect(); //getClipboard().clear(); if (!BEFORE_HONEYCOMB && mActionMode != null) ((ActionMode) mActionMode).finish(); return true; } if (BEFORE_HONEYCOMB || !USE_ACTIONMODE) { getClipboard().startMultiselect(); } else { mActionMode = startActionMode(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { getClipboard().clear(); mActionMode = null; } public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(getString(R.string.s_menu_multi) + ": " + getClipboard().size() + " " + getString(R.string.s_files)); mode.getMenuInflater().inflate(R.menu.multiselect, menu); //MenuUtils.setMenuVisible(menu, false, R.id.menu_context_paste, R.id.menu_context_unzip); getDirContentFragment(true).changeMultiSelectState(true); return true; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (getClipboard().size() < 1) { mode.finish(); return true; } OpenPath file = getClipboard().get(0); //getMultiSelectHandler().getSelectedFiles(); getClipboard().clear(); return getDirContentFragment(false).executeMenu(item.getItemId(), mode, file); } }); } return true; case R.id.menu_view_carousel: changeViewMode(OpenExplorer.VIEW_CAROUSEL, true); return true; case R.id.menu_view_grid: changeViewMode(OpenExplorer.VIEW_GRID, true); return true; case R.id.menu_view_list: changeViewMode(OpenExplorer.VIEW_LIST, true); return true; case R.id.menu_view_fullscreen: getPreferences().setSetting("global", "pref_fullscreen", !getPreferences().getSetting("global", "pref_fullscreen", false)); goHome(); return true; case R.id.menu_view_split: setSetting("pref_basebar", !USE_SPLIT_ACTION_BAR); goHome(); return true; //case R.id.menu_global_ops_text: //case R.id.menu_global_ops_icon: case R.id.title_ops: refreshOperations(); showLogFrag(mOpsFragment, true); checkTitleSeparator(); return true; case R.id.title_log: if (mLogFragment == null) mLogFragment = new LogViewerFragment(); showLogFrag(mLogFragment, true); sendToLogView(null, 0); return true; /*case R.id.menu_root: if(RootManager.Default.isRoot()) { getPreferences().setSetting("global", "pref_root", false); showToast(getString(R.string.s_menu_root_disabled)); RootManager.Default.exitRoot(); item.setChecked(false); } else { if(RootManager.Default.isRoot() || RootManager.Default.requestRoot()) { getPreferences().setSetting("global", "pref_root", true); showToast(getString(R.string.s_menu_root) + "!"); item.setTitle(getString(R.string.s_menu_root) + "!"); } else { item.setChecked(false); showToast("Unable to achieve root."); } } return true; case R.id.menu_flush: ThumbnailCreator.flushCache(getApplicationContext(), true); OpenPath.flushDbCache(); goHome(); return true;*/ case R.id.menu_refresh: ContentFragment content = getDirContentFragment(true); if (content != null) { if (DEBUG && IS_DEBUG_BUILD) Logger.LogDebug("Refreshing " + content.getPath().getPath()); FileManager.removeOpenCache(content.getPath().getPath()); content.getPath().deleteFolderFromDb(); content.runUpdateTask(true); changePath(content.getPath(), false, true); } mBookmarks.refresh(); return true; case R.id.menu_settings: showPreferences(null); return true; case R.id.menu_search: onSearchRequested(); return true; /*case R.id.menu_favorites: toggleBookmarks(); return true;*/ case R.id.menu_multi_all_delete: DialogHandler.showConfirmationDialog(this, getResources().getString(R.string.s_confirm_delete, getClipboard().getCount() + " " + getResources().getString(R.string.s_files)), getResources().getString(R.string.s_menu_delete_all), new DialogInterface.OnClickListener() { // yes public void onClick(DialogInterface dialog, int which) { getEventHandler().deleteFile(getClipboard(), OpenExplorer.this, false); } }); break; case R.id.menu_multi_all_clear: getClipboard().clear(); return true; case R.id.menu_multi_all_copy: getClipboard().DeleteSource = false; getDirContentFragment(false).executeMenu(R.id.content_paste, null, getDirContentFragment(false).getPath()); break; case R.id.menu_multi_all_move: getClipboard().DeleteSource = true; getDirContentFragment(false).executeMenu(R.id.content_paste, null, getDirContentFragment(false).getPath()); break; case R.id.title_paste: case R.id.title_paste_icon: case R.id.title_paste_text: case R.id.content_paste: //if(BEFORE_HONEYCOMB) getClipboard().setCurrentPath(getCurrentPath()); onClipboardDropdown(from); return true; //getDirContentFragment(false).executeMenu(R.id.menu_paste, null, mLastPath, mClipboard); //return true; case R.id.menu_about: DialogHandler.showAboutDialog(this); return true; case R.id.menu_exit: DialogHandler.showConfirmationDialog(this, getString(R.string.s_alert_exit), getString(R.string.s_menu_exit), getPreferences(), "exit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return true; case R.id.menu_more: showMenu(mOptsMenu, ViewUtils.getFirstView(this, R.id.menu_more, R.id.base_bar, R.id.title_buttons, android.R.id.home), true); return true; default: if (f instanceof ContentFragment) { ContentFragment cf = (ContentFragment) f; if (item.getMenuInfo() != null && cf.onContextItemSelected(item)) return true; else if (cf.onClick(id, from)) return true; else if (cf.onOptionsItemSelected(item)) return true; return cf.executeMenu(id, null, getDirContentFragment(false).getPath()); } else if (f instanceof TextEditorFragment) ((TextEditorFragment) f).onClick(id, from); else if (f.onOptionsItemSelected(item)) return true; } //showToast("oops"); return false; //return super.onOptionsItemSelected(item); }