Example usage for android.view ActionMode setSubtitle

List of usage examples for android.view ActionMode setSubtitle

Introduction

In this page you can find the example usage for android.view ActionMode setSubtitle.

Prototype

public abstract void setSubtitle(@StringRes int resId);

Source Link

Document

Set the subtitle of the action mode.

Usage

From source file:org.jraf.android.bikey.app.ride.list.RideListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setEmptyText(getString(R.string.ride_list_empty));

    ListView listView = getListView();
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override//w ww.ja  v  a  2  s . c  om
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.setTitle(R.string.ride_list_title);
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.ride_list_contextual, menu);
            return true;
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            // Enable share / edit if only one item is selected (can't share / edit several items at the same time)
            mode.getMenu().findItem(R.id.action_share).setVisible(quantity == 1);
            mode.getMenu().findItem(R.id.action_edit).setVisible(quantity == 1);
            // Enable merge only if several items are selected
            mode.getMenu().findItem(R.id.action_merge).setVisible(quantity > 1);
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            long[] checkedItemIds = getListView().getCheckedItemIds();
            long checkedItemId = checkedItemIds[0];
            Uri checkedItemUri = ContentUris.withAppendedId(RideColumns.CONTENT_URI, checkedItemId);
            switch (item.getItemId()) {
            case R.id.action_delete:
                getCallbacks().showDeleteDialog(checkedItemIds);
                mode.finish();
                return true;

            case R.id.action_share:
                getCallbacks().showShareDialog(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_edit:
                getCallbacks().edit(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_merge:
                getCallbacks().showMergeDialog(checkedItemIds);
                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }
    });
}

From source file:com.commonsware.cwac.masterdetail.MasterDetailController.java

void updateActionModeTitle(ActionMode mode) {
    mode.setTitle(getActionModeTitle());
    mode.setSubtitle(getActionModeSubtitle());
}

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();/*  ww w  .j av a 2s .c o  m*/

    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();
}

From source file:biz.wiz.android.wallet.ui.BlockListFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final StoredBlock storedBlock = adapter.getItem(position);

    activity.startActionMode(new ActionMode.Callback() {
        @Override/*from  ww w .  j a  v a 2s .  c o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.blocks_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            mode.setTitle(Integer.toString(storedBlock.getHeight()));
            mode.setSubtitle(storedBlock.getHeader().getHashAsString());

            return true;
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                        Constants.EXPLORE_BASE_URL + "block/" + storedBlock.getHeader().getHashAsString())));

                mode.finish();
                return true;
            }

            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
        }
    });
}

From source file:org.digitalcampus.oppia.activity.DownloadMediaActivity.java

@SuppressWarnings("unchecked")
@Override/*from w  w w.  j  a v a  2 s .  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_download_media);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Bundle bundle = this.getIntent().getExtras();
    if (bundle != null) {
        missingMedia = (ArrayList<Media>) bundle.getSerializable(DownloadMediaActivity.TAG);
    } else {
        missingMedia = new ArrayList<>();
    }

    mediaSelected = new ArrayList<>();

    dmla = new DownloadMediaListAdapter(this, missingMedia);
    dmla.setOnClickListener(new DownloadMediaListener());

    mediaList = (ListView) findViewById(R.id.missing_media_list);
    mediaList.setAdapter(dmla);

    mediaList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    mediaList.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            Log.v(TAG, "Count: " + mediaList.getCheckedItemCount());
            if (checked) {
                mediaSelected.add(missingMedia.get(position));
            } else {
                mediaSelected.remove(missingMedia.get(position));
            }

            int count = mediaSelected.size();
            mode.setSubtitle(count == 1 ? count + " item selected" : count + " items selected");

            for (Media m : mediaSelected) {
                if (!m.isDownloading()) {
                    downloadSelected.setText(getString(R.string.missing_media_download_selected));
                    break;
                }
            }

        }

        @Override
        public boolean onCreateActionMode(final ActionMode mode, Menu menu) {

            onPrepareOptionsMenu(menu);
            mode.setTitle(R.string.title_download_media);

            if (missingMediaContainer.getVisibility() != View.VISIBLE) {
                missingMediaContainer.setVisibility(View.VISIBLE);
                downloadSelected.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        DownloadMode downloadMode = downloadSelected.getText().equals(
                                getString(R.string.missing_media_download_selected)) ? DownloadMode.DOWNLOAD_ALL
                                        : DownloadMode.STOP_ALL;
                        downloadSelected.setText(downloadSelected.getText()
                                .equals(getString(R.string.missing_media_download_selected))
                                        ? getString(R.string.missing_media_stop_selected)
                                        : getString(R.string.missing_media_download_selected));

                        for (Media m : mediaSelected) {
                            downloadMedia(m, downloadMode);
                        }

                        mode.finish();
                    }
                });
                unselectAll.setOnClickListener(new OnClickListener() {

                    public void onClick(View view) {
                        mode.finish();
                    }
                });
                showDownloadMediaMessage();
            }

            dmla.setEnterOnMultiChoiceMode(true);
            dmla.notifyDataSetChanged();

            downloadSelected.setText(getString(R.string.missing_media_stop_selected));
            unselectAll.setText(getString(R.string.missing_media_unselect_all));
            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.menu_sort_by: {
                if (isSortByCourse) {
                    dmla.sortByFilename();
                    isSortByCourse = false;
                    item.setTitle(getString(R.string.menu_sort_by_course));
                } else {
                    dmla.sortByCourse();
                    isSortByCourse = true;
                    item.setTitle(getString(R.string.menu_sort_by_filename));
                }
                invalidateOptionsMenu();
                return true;
            }
            case R.id.menu_select_all:
                for (int i = 0; i < mediaList.getAdapter().getCount(); i++) {
                    if (!mediaList.isItemChecked(i)) {
                        mediaList.setItemChecked(i, true);
                    }
                }
                return true;
            default:
                return true;
            }
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mediaSelected.clear();
            hideDownloadMediaMessage();
            dmla.setEnterOnMultiChoiceMode(false);
            dmla.notifyDataSetChanged();
        }
    });

    missingMediaContainer = this.findViewById(R.id.home_messages);
    downloadSelected = (TextView) this.findViewById(R.id.download_selected);
    unselectAll = (TextView) this.findViewById(R.id.unselect_all);

    downloadViaPCBtn = (Button) this.findViewById(R.id.download_media_via_pc_btn);
    downloadViaPCBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            downloadViaPC();
        }
    });

    Editor e = prefs.edit();
    e.putLong(PrefsActivity.PREF_LAST_MEDIA_SCAN, 0);
    e.commit();

    emptyState = (TextView) findViewById(R.id.empty_state);
}

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// www .  j  a  va  2s . 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.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 ww .j  a  v  a2  s  .c  om
        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);
        }
    });
}