List of usage examples for android.view ActionMode setTitle
public abstract void setTitle(@StringRes int resId);
From source file:com.miz.mizuu.fragments.MovieLibraryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.image_grid_fragment, container, false); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mEmptyLibraryLayout = v.findViewById(R.id.empty_library_layout); mEmptyLibraryTitle = (TextView) v.findViewById(R.id.empty_library_title); mEmptyLibraryTitle.setTypeface(TypefaceUtils.getRobotoCondensedRegular(mContext)); mEmptyLibraryDescription = (TextView) v.findViewById(R.id.empty_library_description); mEmptyLibraryDescription.setTypeface(TypefaceUtils.getRobotoLight(mContext)); mAdapter = new LoaderAdapter(mContext); mGridView = (ObservableGridView) v.findViewById(R.id.gridView); mGridView.setAdapter(mAdapter);// www . j a v a 2 s . c om mGridView.setColumnWidth(mImageThumbSize); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { viewMovieDetails(arg2, arg1); } }); // We only want to display the contextual menu if we're showing movies, not collections if (getArguments().getInt("type") != MovieLoader.COLLECTIONS) { mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { mAdapter.setItemChecked(position, checked); mode.setTitle(String.format(getString(R.string.selected), mAdapter.getCheckedItemCount())); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { getActivity().getMenuInflater().inflate(R.menu.movie_library_cab, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.movie_add_fav: MovieDatabaseUtils.setMoviesFavourite(mContext, mAdapter.getCheckedMovies(), true); break; case R.id.movie_remove_fav: MovieDatabaseUtils.setMoviesFavourite(mContext, mAdapter.getCheckedMovies(), false); break; case R.id.movie_watched: MovieDatabaseUtils.setMoviesWatched(mContext, mAdapter.getCheckedMovies(), true); break; case R.id.movie_unwatched: MovieDatabaseUtils.setMoviesWatched(mContext, mAdapter.getCheckedMovies(), false); break; case R.id.add_to_watchlist: MovieDatabaseUtils.setMoviesWatchlist(mContext, mAdapter.getCheckedMovies(), true); break; case R.id.remove_from_watchlist: MovieDatabaseUtils.setMoviesWatchlist(mContext, mAdapter.getCheckedMovies(), false); break; } if (!(id == R.id.watched_menu || id == R.id.watchlist_menu || id == R.id.favorite_menu)) { mode.finish(); LocalBroadcastUtils.updateMovieLibrary(mContext); } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearCheckedItems(); } }); } mMovieLoader = new MovieLoader(mContext, MovieLibraryType.fromInt(getArguments().getInt("type")), mCallback); mMovieLoader.load(); showProgressBar(); return v; }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvUserIdsFragment.java
public void enterEditMode() { FragmentActivity activity = getActivity(); if (activity == null) { return;//w w w .ja va2 s . co m } activity.startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mEditModeSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint); mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mEditModeSaveKeyringParcel.mAddUserIds, false); mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter); mUserIdsAddedLayout.setVisibility(View.VISIBLE); mUserIdAddFabLayout.setDisplayedChild(1); mUserIdsAdapter.setEditMode(mEditModeSaveKeyringParcel); getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this); mode.setTitle(R.string.title_edit_identities); mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { editKey(mode); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mEditModeSaveKeyringParcel = null; mUserIdsAdapter.setEditMode(null); mUserIdsAddedLayout.setVisibility(View.GONE); mUserIdAddFabLayout.setDisplayedChild(0); getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this); } }); }
From source file:org.spinsuite.bchat.view.FV_Thread.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (m_view != null) return m_view; // Inflate/*from w w w . j a v a 2s . c o m*/ m_view = inflater.inflate(R.layout.v_business_chat_thread, container, false); // Scroll lv_Thread = (ListView) m_view.findViewById(R.id.lv_Thread); et_Message = (EditText) m_view.findViewById(R.id.et_Message); ib_Send = (ImageButton) m_view.findViewById(R.id.ib_Send); // Listener ib_Send.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (et_Message.getText() == null || et_Message.getText().toString().trim().length() == 0) return; // Send Message sendMessage(null); } }); // Hide Separator lv_Thread.setDividerHeight(0); lv_Thread.setDivider(null); lv_Thread.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv_Thread.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) { DisplayBChatThreadItem item = (DisplayBChatThreadItem) m_ThreadAdapter.getItem(position); // Show Image String fileName = item.getFileName(); if (fileName != null && fileName.length() > 0) { String m_FilePath = Env.getBC_IMG_DirectoryPathName(m_ctx); File file = new File(m_FilePath + File.separator + fileName); // Show AttachmentHandler.showAttachment(m_ctx, Uri.fromFile(file)); } } }); // lv_Thread.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Capture total checked items final int checkedCount = lv_Thread.getCheckedItemCount(); // Set the CAB title according to total checked items mode.setTitle(checkedCount + " " + getString(R.string.BChat_Selected)); // Calls toggleSelection method from ListViewAdapter Class m_ThreadAdapter.toggleSelection(position); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: SparseBooleanArray selectedItems = m_ThreadAdapter.getSelectedItems(); StringBuffer inClause = new StringBuffer(); for (int i = (selectedItems.size() - 1); i >= 0; i--) { if (selectedItems.valueAt(i)) { DisplayBChatThreadItem selectedItem = m_ThreadAdapter.getItem(selectedItems.keyAt(i)); // Add Separator if (inClause.length() > 0) { inClause.append(", "); } // Add Value inClause.append("'").append(selectedItem.getSPS_BC_Message_UUID()).append("'"); // Remove Item m_ThreadAdapter.remove(selectedItem); } } // Delete Records in DB if (inClause.length() > 0) { BCMessageHandle.getInstance(m_ctx).deleteMessage(m_Request, "SPS_BC_Message_UUID IN(" + inClause.toString() + ")"); } mode.finish(); return true; case R.id.action_copy: selectedItems = m_ThreadAdapter.getSelectedItems(); boolean justOne = selectedItems.size() == 1; StringBuffer text = new StringBuffer(); for (int i = (selectedItems.size() - 1); i >= 0; i--) { if (selectedItems.valueAt(i)) { DisplayBChatThreadItem selectedItem = m_ThreadAdapter.getItem(selectedItems.keyAt(i)); // Valid File if (selectedItem.getFileName() != null) continue; // Add New Line if (text.length() > 0) { text.append(Env.NL); } // Add to Text if (justOne) { text.append(selectedItem.getText()); } else { text.append(selectedItem.getCopy()); } } } // Add To Clipboard if (text.length() > 0) { Env.setClipboardText(m_ctx, text.toString()); } mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.bc_thread_selected, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { m_ThreadAdapter.removeSelection(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); // Return return m_view; }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java
public void enterEditMode() { FragmentActivity activity = getActivity(); if (activity == null) { return;/*from w ww . j a v a 2s . c o m*/ } activity.startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mEditModeSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint); mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mEditModeSaveKeyringParcel.mAddSubKeys, false); mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter); mSubkeysAddedLayout.setVisibility(View.VISIBLE); mSubkeyAddFabLayout.setDisplayedChild(1); mSubkeysAdapter.setEditMode(mEditModeSaveKeyringParcel); getLoaderManager().restartLoader(LOADER_ID_SUBKEYS, null, ViewKeyAdvSubkeysFragment.this); mode.setTitle(R.string.title_edit_subkeys); mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { editKey(mode); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mEditModeSaveKeyringParcel = null; mSubkeysAdapter.setEditMode(null); mSubkeysAddedLayout.setVisibility(View.GONE); mSubkeyAddFabLayout.setDisplayedChild(0); getLoaderManager().restartLoader(LOADER_ID_SUBKEYS, null, ViewKeyAdvSubkeysFragment.this); } }); }
From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override//from w ww . ja v a2 s . co m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final Coin value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override/* w w w. j a v a 2 s . c o m*/ public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final Coin value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafePeercoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:foundme.uniroma2.it.professore.ReadMessageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_message); context = this; Bundle passed = getIntent().getExtras(); Title = passed.getString(Variables_it.COURSE); swipeMsg = (SwipeRefreshLayout) findViewById(R.id.swipe_msg); swipeMsg.setEnabled(false);//from w w w . j a v a 2 s. c o m lvMessaggi = (ListView) findViewById(R.id.lvmes); modeCallBack = new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.delete: if (!toEdit.equalsIgnoreCase(Variables_it.NO_MSG)) { try { deleteMsg(toEdit); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } toEdit = null; mode.finish(); break; } return false; } public void onDestroyActionMode(ActionMode mode) { viewList.setBackgroundColor(Color.TRANSPARENT); mode = null; } public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(Variables_it.OPTION); mode.getMenuInflater().inflate(R.menu.context, menu); return true; } }; try { getMsg(Title, true); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.luksprog.playground.fragment.ListCABFragment.java
@SuppressLint({ "NewApi", "NewApi" }) private void postHoneycombCAB() { getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override// w ww . j a v a2s.c o m public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ((ListView) parent).setItemChecked(position, ((ListView) parent).isItemChecked(position)); return false; } }); getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { private int nr = 0; @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { getActivity().getMenuInflater().inflate(R.menu.listcab_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.item1: Toast.makeText(getActivity(), "Option1 clicked", Toast.LENGTH_SHORT).show(); break; case R.id.item2: Toast.makeText(getActivity(), "Option2 clicked", Toast.LENGTH_SHORT).show(); break; } return false; } @Override public void onDestroyActionMode(ActionMode mode) { nr = 0; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { nr++; } else { nr--; } mode.setTitle(nr + " rows selected!"); } }); }
From source file:com.lgallardo.youtorrentcontroller.ItemstFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try {/* w w w . jav a 2s .c o m*/ getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); // Get adapter final TorrentListAdapter mAdapter = (TorrentListAdapter) this.getListAdapter(); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { private int nr = 0; @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { nr++; mAdapter.setNewSelection(position, checked); } else { nr--; mAdapter.removeSelection(position); } // Set title with number of items selected mode.setTitle("" + nr); } @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { nr = 0; MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.main_contextual_action_bar, menu); mSwipeRefreshLayout.setEnabled(false); ItemstFragment.mActionMode = actionMode; return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return true; } // This actions are click in the torrent list view (CAB) @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { AlertDialog.Builder builder; AlertDialog dialog; String hashes = null; final String hashesStr; // Get MainActivity final MainActivity m = (MainActivity) getActivity(); // Get hashes for (int i = 0; mAdapter.getCount() > i; i++) { if (mAdapter.isPositionChecked(i)) { if (hashes == null) { hashes = mAdapter.getData()[i].getHash(); } else { hashes = hashes + "|" + mAdapter.getData()[i].getHash(); } } } hashesStr = hashes; ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); switch (item.getItemId()) { case R.id.action_pause: m.pauseSelectedTorrents(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_stop: m.stopSelectedTorrents(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_resume: m.startSelectedTorrents(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_delete: if (!getActivity().isFinishing()) { builder = new AlertDialog.Builder(getActivity()); // Message builder.setMessage(R.string.dm_deleteSelectedTorrents) .setTitle(R.string.dt_deleteSelectedTorrents); // Cancel builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User canceled the dialog } }); // Ok builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog m.deleteSelectedTorrents(hashesStr); } }); // Create dialog dialog = builder.create(); // Show dialog dialog.show(); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); } return true; case R.id.action_delete_drive: if (!getActivity().isFinishing()) { builder = new AlertDialog.Builder(getActivity()); // Message builder.setMessage(R.string.dm_deleteDriveSelectedTorrents) .setTitle(R.string.dt_deleteDriveSelectedTorrents); // Cancel builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User canceled the dialog } }); // Ok builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog m.deleteDriveSelectedTorrents(hashesStr); } }); // Create dialog dialog = builder.create(); // Show dialog dialog.show(); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); } return true; case R.id.action_increase_prio: m.increasePrioTorrent(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_decrease_prio: m.decreasePrioTorrent(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_max_prio: m.maxPrioTorrent(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_min_prio: m.minPrioTorrent(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_recheck: m.recheckTorrents(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_sequential_download: m.toggleSequentialDownload(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; case R.id.action_firts_last_piece_prio: m.toggleFirstLastPiecePrio(hashes); // Clear selection nr = 0; // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); mAdapter.clearSelection(); mode.finish(); return true; default: // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); return true; } } @Override public void onDestroyActionMode(ActionMode actionMode) { if (mAdapter != null) { mAdapter.clearSelection(); } ItemstFragment.mActionMode = null; mSwipeRefreshLayout.setEnabled(true); } }); getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (MainActivity.listViewRefreshing) { return true; } getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); return false; } }); } catch (Exception e) { getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); } }
From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dataSource = new GameDataSource(getActivity()); dataSource.open();//from w w w . ja v a 2s .c om values = dataSource.getAllGames(); adapter = new MultipleRowAdapter(getActivity(), values); setListAdapter(adapter); final ListView listView = getListView(); listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are selected/de-selected, // such as update the title in the CAB //mode.setTag(); int selectionColor = getResources().getColor(R.color.colorPrimary); Log.w("TAG", "onItemCheckedStateChanged() " + checked + " " + position); mode.setSubtitle(listView.getCheckedItemCount() + " selected"); if (checked) { listView.getChildAt(position).setBackgroundColor(selectionColor); } else { listView.getChildAt(position) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { // Inflate the menu for the CAB Log.w("TAG", "onCreateActionMode"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_context, menu); mode.setTitle(getString(R.string.action_choose)); return true; } @Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_delete: deleteItems(listView.getCheckedItemPositions()); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(android.view.ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are deselected/unchecked. SparseBooleanArray checked = listView.getCheckedItemPositions(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { if (checked.get(i)) { listView.getChildAt(i) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } } }); // dataSource.close(); }