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.lgallardo.qbittorrentclient.ItemstFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    try {/*from w w  w .j ava 2 s  . c om*/

        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) {
                if (MainActivity.qb_version.equals("3.2.x")) {
                    menu.findItem(R.id.action_first_last_piece_prio).setVisible(true);
                    menu.findItem(R.id.action_sequential_download).setVisible(true);
                    menu.findItem(R.id.action_label_menu).setVisible(true);
                    menu.findItem(R.id.action_set_label).setVisible(true);
                    menu.findItem(R.id.action_delete_label).setVisible(true);

                    if (Integer.parseInt(MainActivity.qb_api) < 8) {
                        menu.findItem(R.id.action_delete_label).setVisible(false);
                    }

                } else {
                    menu.findItem(R.id.action_first_last_piece_prio).setVisible(false);
                    menu.findItem(R.id.action_sequential_download).setVisible(false);
                    menu.findItem(R.id.action_label_menu).setVisible(false);
                    menu.findItem(R.id.action_set_label).setVisible(false);
                    menu.findItem(R.id.action_delete_label).setVisible(false);
                }
                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_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_upload_rate_limit:

                    m.uploadRateLimitDialog(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_download_rate_limit:

                    m.downloadRateLimitDialog(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_first_last_piece_prio:

                    m.toggleFirstLastPiecePrio(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_set_label:

                    m.setLabelDialog(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_delete_label:

                    m.setLabel(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:org.digitalcampus.oppia.activity.DownloadMediaActivity.java

@SuppressWarnings("unchecked")
@Override/* w  ww  .jav  a2  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:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    PageHolder pageHolder = getPageHolder();
    ChanConfiguration configuration = getChanConfiguration();
    getAdapter().setSelectionModeEnabled(true);
    mode.setTitle(getString(R.string.text_selected_format, 0));
    int pasteResId = ResourceUtils.getSystemSelectionIcon(getActivity(), "actionModePasteDrawable",
            "ic_menu_paste_holo_dark");
    int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
    ChanConfiguration.Board board = configuration.safe().obtainBoard(pageHolder.boardName);
    menu.add(0, ACTION_MENU_MAKE_THREADSHOT, 0, R.string.action_make_threadshot)
            .setIcon(obtainIcon(R.attr.actionMakeThreadshot)).setShowAsAction(flags);
    if (replyable != null) {
        menu.add(0, ACTION_MENU_REPLY, 0, R.string.action_reply).setIcon(pasteResId).setShowAsAction(flags);
    }//from  w  w w  .  j  av  a  2s.c  o m
    if (board.allowDeleting) {
        ChanConfiguration.Deleting deleting = configuration.safe().obtainDeleting(pageHolder.boardName);
        if (deleting != null && deleting.multiplePosts) {
            menu.add(0, ACTION_MENU_DELETE_POSTS, 0, R.string.action_delete)
                    .setIcon(obtainIcon(R.attr.actionDelete)).setShowAsAction(flags);
        }
    }
    if (board.allowReporting) {
        ChanConfiguration.Reporting reporting = configuration.safe().obtainReporting(pageHolder.boardName);
        if (reporting != null && reporting.multiplePosts) {
            menu.add(0, ACTION_MENU_SEND_REPORT, 0, R.string.action_report)
                    .setIcon(obtainIcon(R.attr.actionReport)).setShowAsAction(flags);
        }
    }
    return true;
}

From source file:com.miz.mizuu.UnidentifiedTvShows.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mList = (ListView) findViewById(R.id.listView1);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        // Called when the user selects a contextual menu item
        @Override/*from  www  .j a  v a2 s  .c  o m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.identify:
                identifySelectedFiles();
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.unidentified, menu);

            return true;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mode = null;

            // Unselected the item
            mList.clearFocus();
            mList.clearChoices();
            mList.invalidate();
        }

        // Called each time the action mode is shown. Always called after onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true; // Return false if nothing is done
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " selected");
        }
    });
    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mList.setItemChecked(arg2, !mList.isItemChecked(arg2));
        }
    });

    loadData();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter(LocalBroadcastUtils.UPDATE_TV_SHOW_LIBRARY));
}

From source file:com.miz.mizuu.UnidentifiedFiles.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.unidentified_files_layout);

    mList = (ListView) findViewById(R.id.listView1);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        // Called when the user selects a contextual menu item
        @Override/*from  w  w w .  jav a 2 s.c  om*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.identify:
                identifySelectedFiles();
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.unidentified, menu);

            return true;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mode = null;

            // Unselected the item
            mList.clearFocus();
            mList.clearChoices();
            mList.invalidate();
        }

        // Called each time the action mode is shown. Always called after onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true; // Return false if nothing is done
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " selected");
        }
    });
    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mList.setItemChecked(arg2, !mList.isItemChecked(arg2));
        }
    });

    loadData();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("tvshow-episode-changed"));
}

From source file:com.forrestguice.suntimeswidget.TimeZoneDialog.java

/**
 * trigger the time zone ActionMode/*  w  w  w .  java2 s .c  o m*/
 * @param view the view that is triggering the ActionMode
 * @return true ActionMode started, false otherwise
 */
private boolean triggerTimeZoneActionMode(View view) {
    if (this.actionMode != null)
        return false;

    // ActionMode for HONEYCOMB (11) and above
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        Dialog dialog = getDialog();
        if (dialog == null)
            return false;

        View v = dialog.getWindow().getDecorView();
        if (v == null)
            return false;

        ActionMode actionMode = v
                .startActionMode(new WidgetTimezones.TimeZoneSpinnerSortAction(getContext(), spinner_timezone) {
                    @Override
                    public void onSortTimeZones(WidgetTimezones.TimeZoneItemAdapter result,
                            WidgetTimezones.TimeZoneSort sortMode) {
                        super.onSortTimeZones(result, sortMode);
                        spinner_timezone_adapter = result;
                        WidgetTimezones.selectTimeZone(spinner_timezone, spinner_timezone_adapter,
                                customTimezoneID);
                    }

                    @Override
                    public void onSaveSortMode(WidgetTimezones.TimeZoneSort sortMode) {
                        super.onSaveSortMode(sortMode);
                        AppSettings.setTimeZoneSortPref(getContext(), sortMode);
                    }

                    @Override
                    public void onDestroyActionMode(ActionMode mode) {
                        super.onDestroyActionMode(mode);
                        TimeZoneDialog.this.actionMode = null;
                    }
                });
        this.actionMode = actionMode;
        actionMode.setTitle(getString(R.string.timezone_sort_contextAction));

    } else {
        // LEGACY; ActionMode for pre HONEYCOMB
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        android.support.v7.view.ActionMode actionMode = activity.startSupportActionMode(
                new WidgetTimezones.TimeZoneSpinnerSortActionCompat(getContext(), spinner_timezone) {
                    @Override
                    public void onSortTimeZones(WidgetTimezones.TimeZoneItemAdapter result,
                            WidgetTimezones.TimeZoneSort sortMode) {
                        super.onSortTimeZones(result, sortMode);
                        spinner_timezone_adapter = result;
                        WidgetTimezones.selectTimeZone(spinner_timezone, spinner_timezone_adapter,
                                customTimezoneID);
                    }

                    @Override
                    public void onSaveSortMode(WidgetTimezones.TimeZoneSort sortMode) {
                        super.onSaveSortMode(sortMode);
                        AppSettings.setTimeZoneSortPref(context, sortMode);
                    }

                    @Override
                    public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {
                        super.onDestroyActionMode(mode);
                        TimeZoneDialog.this.actionMode = null;
                    }
                });
        if (actionMode != null) {
            this.actionMode = actionMode;
            actionMode.setTitle(getString(R.string.timezone_sort_contextAction));
        }
    }

    view.setSelected(true);
    return true;
}

From source file:com.openerp.addons.messages.Message.java

public void setupListView(List<OEListViewRows> message_list) {
    // Destroying pre-loaded instance and going to create new one
    lstview = null;/*from   ww w  . ja  va 2  s .  c  om*/

    // Fetching required messages for listview by filtering of requrement
    if (list != null && list.size() <= 0) {
        list = message_list;// getMessages(message_list);
    } else {
        rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE);
        rootView.findViewById(R.id.txvMessageAllReadMessage).setVisibility(View.GONE);
    }

    // Handling List View controls and keys
    String[] from = new String[] { "subject|type", "body", "starred", "author_id|email_from", "date",
            "model|type" };
    int[] to = new int[] { R.id.txvMessageSubject, R.id.txvMessageBody, R.id.imgMessageStarred,
            R.id.txvMessageFrom, R.id.txvMessageDate, R.id.txvMessageTag };

    // Creating instance for listAdapter
    listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_listview_items, list, from, to, db,
            true, new int[] { R.drawable.message_listview_bg_toread_selector,
                    R.drawable.message_listview_bg_tonotread_selector },
            "to_read");
    // Telling adapter to clean HTML text for key value
    listAdapter.cleanHtmlToTextOn("body");
    listAdapter.cleanDate("date", scope.User().getTimezone());
    // Setting callback handler for boolean field value change.
    listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred,
            R.drawable.ic_action_unstarred, updateStarred);
    listAdapter.addViewListener(new OEListViewOnCreateListener() {

        @Override
        public View listViewOnCreateListener(int position, View row_view, OEListViewRows row_data) {
            String model_name = row_data.getRow_data().get("model").toString();
            String model = model_name;
            String res_id = row_data.getRow_data().get("res_id").toString();
            if (model_name.equals("false")) {
                model_name = capitalizeString(row_data.getRow_data().get("type").toString());
            } else {
                String[] model_parts = TextUtils.split(model_name, "\\.");
                HashSet unique_parts = new HashSet(Arrays.asList(model_parts));
                model_name = capitalizeString(TextUtils.join(" ", unique_parts.toArray()));

            }
            TextView msgTag = (TextView) row_view.findViewById(R.id.txvMessageTag);
            int tag_color = 0;
            if (message_model_colors.containsKey(model_name)) {
                tag_color = message_model_colors.get(model_name);
            } else {
                tag_color = Color.parseColor(tag_colors[tag_color_count]);
                message_model_colors.put(model_name, tag_color);
                tag_color_count++;
                if (tag_color_count > tag_colors.length) {
                    tag_color_count = 0;
                }
            }
            if (model.equals("mail.group")) {
                if (UserGroups.group_names.containsKey("group_" + res_id)) {
                    model_name = UserGroups.group_names.get("group_" + res_id);
                    tag_color = UserGroups.menu_color.get("group_" + res_id);
                }
            }
            msgTag.setBackgroundColor(tag_color);
            msgTag.setText(model_name);
            TextView txvSubject = (TextView) row_view.findViewById(R.id.txvMessageSubject);
            TextView txvAuthor = (TextView) row_view.findViewById(R.id.txvMessageFrom);
            if (row_data.getRow_data().get("to_read").toString().equals("false")) {
                txvSubject.setTypeface(null, Typeface.NORMAL);
                txvSubject.setTextColor(Color.BLACK);

                txvAuthor.setTypeface(null, Typeface.NORMAL);
                txvAuthor.setTextColor(Color.BLACK);
            } else {
                txvSubject.setTypeface(null, Typeface.BOLD);
                txvSubject.setTextColor(Color.parseColor("#414141"));
                txvAuthor.setTypeface(null, Typeface.BOLD);
                txvAuthor.setTextColor(Color.parseColor("#414141"));
            }

            return row_view;
        }
    });

    // Creating instance for listview control
    lstview = (ListView) rootView.findViewById(R.id.lstMessages);
    // Providing adapter to listview
    scope.context().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            lstview.setAdapter(listAdapter);

        }
    });

    // Setting listview choice mode to multiple model
    lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    // Seeting item long click listern to activate action mode.
    lstview.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View view, int index, long arg3) {
            // TODO Auto-generated method stub

            OEListViewRows data = (OEListViewRows) lstview.getAdapter().getItem(index);

            Toast.makeText(scope.context(), data.getRow_id() + " id clicked", Toast.LENGTH_LONG).show();
            view.setSelected(true);
            if (mActionMode != null) {
                return false;
            }
            // Start the CAB using the ActionMode.Callback defined above
            mActionMode = scope.context().startActionMode(mActionModeCallback);
            selectedCounter++;
            view.setBackgroundResource(R.drawable.listitem_pressed);
            // lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            return true;

        }
    });

    // Setting multi choice selection listener
    lstview.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        HashMap<Integer, Boolean> selectedList = new HashMap<Integer, Boolean>();

        @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
            selectedList.put(position, checked);
            if (checked) {
                selectedCounter++;
            } else {
                selectedCounter--;
            }
            if (selectedCounter != 0) {
                mode.setTitle(selectedCounter + "");
            }

        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // Respond to clicks on the actions in the CAB
            HashMap<Integer, Integer> msg_pos = new HashMap<Integer, Integer>();
            OEDialog dialog = null;
            switch (item.getItemId()) {
            case R.id.menu_message_mark_unread_selected:
                Log.e("menu_message_context", "Mark as Unread");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_mark_read_selected:
                Log.e("menu_message_context", "Mark as Read");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, true);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_more_move_to_archive_selected:
                Log.e("menu_message_context", "Archive");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_more_add_star_selected:
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }

                markasTodoTask = new PerformOperation(msg_pos, true);
                markasTodoTask.execute((Void) null);

                mode.finish();

                return true;
            case R.id.menu_message_more_remove_star_selected:
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }

                markasTodoTask = new PerformOperation(msg_pos, false);
                markasTodoTask.execute((Void) null);
                mode.finish();
                return true;
            default:
                return false;
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate the menu for the CAB
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.menu_fragment_message_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            // Here you can make any necessary updates to the activity when
            // the CAB is removed. By default, selected items are
            // deselected/unchecked.

            /*
             * Perform Operation on Selected Ids.
             * 
             * row_ids are list of selected message Ids.
             */

            selectedList.clear();
            selectedCounter = 0;
            lstview.clearChoices();

        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            // Here you can perform updates to the CAB due to
            // an invalidate() request
            return false;
        }
    });
    lstview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
            // TODO Auto-generated method stub
            MessageDetail messageDetail = new MessageDetail();
            Bundle bundle = new Bundle();
            bundle.putInt("message_id", list.get(index).getRow_id());
            bundle.putInt("position", index);
            messageDetail.setArguments(bundle);
            scope.context().fragmentHandler.setBackStack(true, null);
            scope.context().fragmentHandler.replaceFragmnet(messageDetail);
            if (!type.equals("archive")) {
                list.remove(index);
            }
            listAdapter.refresh(list);
        }
    });

    // Getting Pull To Refresh Attacher from Main Activity
    mPullToRefreshAttacher = scope.context().getPullToRefreshAttacher();

    // Set the Refreshable View to be the ListView and the refresh listener
    // to be this.
    if (mPullToRefreshAttacher != null & lstview != null) {
        mPullToRefreshAttacher.setRefreshableView(lstview, this);
    }
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    context = this;

    swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeView.setEnabled(false);/*from w ww  . ja va2  s . c  o m*/

    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.edit:
                if (!toEdit.equalsIgnoreCase(Variables_it.NO_COURSE)) {
                    Intent i = new Intent(HomeActivity.this, EditCourseActivity.class);
                    i.putExtra(Variables_it.COURSE, toEdit);
                    i.putExtra(Variables_it.NAME, name);
                    startActivity(i);
                }
                toEdit = null;
                mode.finish(); // Automatically exists the action mode, when the user selects this action
                break;
            case R.id.delete:
                if (!toEdit.equalsIgnoreCase(Variables_it.NO_COURSE)) {
                    try {
                        manageCourse(name, 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, menu);
            return true;
        }
    };

    Bundle passed = getIntent().getExtras();
    name = passed.getString(Variables_it.NAME);
    TAGRead = passed.getString(Variables_it.TAG);

    imgUniroma2 = (ImageButton) findViewById(R.id.ivLogo2);
    imgUniroma2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Variables_it.SITE_TV));
            startActivity(browserIntent);
        }
    });

    nfctest = (TextView) findViewById(R.id.tvNFC);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (mNfcAdapter == null) {
        Toast.makeText(this, Variables_it.NFC_UNSUPPORTED, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (!mNfcAdapter.isEnabled()) {
        Toast.makeText(this, Variables_it.NFC_DISABLED, Toast.LENGTH_LONG).show();
    }

    lvCourses = (ListView) findViewById(R.id.lvCourses);

    if (name != null /*&& courses == null*/) {
        try {
            getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    profName = (TextView) findViewById(R.id.tvUserName);
    profName.setText(name);
    nfctest.setText(TAGRead);
    handleIntent(getIntent());
}

From source file:com.miz.mizuu.fragments.TvShowSeasonsFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mAdapter = new ImageAdapter(mContext);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progress);

    mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setEmptyView(v.findViewById(R.id.progress));
    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setAdapter(mAdapter);/* w w  w .  ja  va  2s  .c  om*/
    mGridView.setColumnWidth(mImageThumbSize);

    // 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);
                }
            }
        }
    });
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // Update the selected index variable
            mSelectedIndex = arg2;

            // Show the episode browser Activity for the given season
            getActivity().startActivityForResult(IntentUtils.getTvShowSeasonIntent(getActivity(), mShowId,
                    mItems.get(arg2).getSeason(), mItems.get(arg2).getEpisodeCount(), mToolbarColor), 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.seasons_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>(mCheckedSeasons));
                break;
            case R.id.unwatched:
                changeWatchedStatus(false, new HashSet<Integer>(mCheckedSeasons));
                break;
            case R.id.remove:
                removeSelectedSeasons(new HashSet<Integer>(mCheckedSeasons));
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mContextualActionBarEnabled = false;
            mCheckedSeasons.clear();
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                mCheckedSeasons.add(mItems.get(position).getSeason());
            } else {
                mCheckedSeasons.remove(mItems.get(position).getSeason());
            }

            int count = mCheckedSeasons.size();
            mode.setTitle(
                    count + " " + getResources().getQuantityString(R.plurals.seasons_selected, count, count));

            // Nasty hack to update the selected items highlight...
            mAdapter.notifyDataSetChanged();
        }
    });

    // The layout has been created - let's load the data
    loadSeasons();
}

From source file:com.veniosg.dir.android.fragment.SideNavFragment.java

private void setListChoiceListener() {
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override/*w w w  .  ja v a 2 s  .  com*/
        public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
            menu.clear();
            mode.getMenuInflater().inflate(R.menu.cab_bookmarks, menu);

            if (getListView().getCheckedItemCount() != 1) {
                menu.removeItem(R.id.menu_open_parent);
            }
            return true;
        }

        @Override
        public void onDestroyActionMode(android.view.ActionMode mode) {
            setStatusBarColour(getActivity(), false);
        }

        @Override
        public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
            setStatusBarColour(getActivity(), true);
            return true;
        }

        @Override
        public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_delete:
                long[] ids = getListView().getCheckedItemIds();
                for (long id : ids) {
                    getListView().getContext().getContentResolver().delete(BookmarkProvider.CONTENT_URI,
                            BookmarkProvider._ID + "=?", new String[] { "" + id });
                }
                mode.finish();
                return true;

            case R.id.menu_open_parent:
                int pos = 0;
                SparseBooleanArray checked = getListView().getCheckedItemPositions();
                for (int i = 0; i < getListView().getCount(); i++) {
                    if (checked.get(i)) {
                        pos = i;
                    }
                }

                String path = ((Cursor) getListAdapter().getItem(pos)).getString(2);
                ((BookmarkContract) getActivity()).onBookmarkSelected(new File(path).getParent());
                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onItemCheckedStateChanged(android.view.ActionMode mode, int position, long id,
                boolean checked) {
            if (getListView().getCheckedItemCount() != 0) {

                mode.setTitle(getListView().getCheckedItemCount() + " " + getString(R.string.selected));

                // Force actions' refresh
                mode.invalidate();
            }
        }
    });
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
}