Example usage for android.view ActionMode setTitle

List of usage examples for android.view ActionMode setTitle

Introduction

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

Prototype

public abstract void setTitle(@StringRes int resId);

Source Link

Document

Set the title of the action mode.

Usage

From source file:com.github.jvanhie.discogsscrobbler.ReleaseListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setSelection() {
    mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setSelector(R.drawable.track_selector);
    mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override//from   w w w.  j  av a2  s.  c  o  m
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = getActivity().getMenuInflater();
            inflater.inflate(R.menu.list_cab, menu);
            return true;
        }

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

        @Override
        public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
            SparseBooleanArray checkedItems = mList.getCheckedItemPositions();
            final List<Release> releases = new ArrayList<Release>();
            if (checkedItems != null) {
                for (int i = 0; i < checkedItems.size(); i++) {
                    if (checkedItems.valueAt(i)) {
                        releases.add((Release) mList.getAdapter().getItem(checkedItems.keyAt(i)));
                    }
                }
            }
            switch (item.getItemId()) {
            case R.id.reload_release:
                mCallbacks.setRefreshVisible(true);
                mDiscogs.refreshReleases(releases, new Discogs.DiscogsWaiter() {
                    @Override
                    public void onResult(boolean success) {
                        if (success) {
                            Toast.makeText(getActivity(), "reloaded releases", Toast.LENGTH_SHORT).show();
                            loadList();
                        } else {
                            Toast.makeText(getActivity(), "Failed to reload requested releases!",
                                    Toast.LENGTH_SHORT).show();
                        }
                        mCallbacks.setRefreshVisible(false);
                    }
                });
                mode.finish();
                break;
            case R.id.delete_release:
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                // Add the buttons
                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User clicked OK button
                        mCallbacks.setRefreshVisible(true);
                        mDiscogs.removeReleases(releases, new Discogs.DiscogsWaiter() {
                            @Override
                            public void onResult(boolean success) {
                                if (success) {
                                    Toast.makeText(getActivity(), "Removed selected releases",
                                            Toast.LENGTH_SHORT).show();
                                    loadList();
                                } else {
                                    Toast.makeText(getActivity(), "Failed to remove selected releases!",
                                            Toast.LENGTH_SHORT).show();
                                }
                                mCallbacks.setRefreshVisible(false);
                            }
                        });
                        mode.finish();
                    }
                });
                builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mode.finish();
                    }
                });
                builder.setTitle(R.string.delete_releases_title).setMessage(R.string.delete_releases_message);
                AlertDialog dialog = builder.create();
                dialog.show();
                break;
            case R.id.cancel_selection:
                mode.finish();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {

        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " releases selected");

        }

    });
}