Example usage for android.view ActionMode getMenuInflater

List of usage examples for android.view ActionMode getMenuInflater

Introduction

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

Prototype

public abstract MenuInflater getMenuInflater();

Source Link

Document

Returns a MenuInflater with the ActionMode's context.

Usage

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 .j a  va 2 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.farmerbb.notepad.fragment.NoteListFragment.java

private void listNotes() {
    // Get array of file names
    String[] listOfFiles = getActivity().getFilesDir().list();
    ArrayList<String> listOfNotes = new ArrayList<>();

    // Get number of files
    int numOfNotes = listOfFiles.length;

    // Remove any files from the list that aren't notes
    for (String listOfFile : listOfFiles) {
        if (NumberUtils.isCreatable(listOfFile))
            listOfNotes.add(listOfFile);
        else//  ww w .jav a2 s  .c o  m
            numOfNotes--;
    }

    // Create arrays of note lists
    String[] listOfNotesByDate = new String[numOfNotes];
    String[] listOfNotesByName = new String[numOfNotes];

    NoteListItem[] listOfTitlesByDate = new NoteListItem[numOfNotes];
    NoteListItem[] listOfTitlesByName = new NoteListItem[numOfNotes];

    ArrayList<NoteListItem> list = new ArrayList<>(numOfNotes);

    for (int i = 0; i < numOfNotes; i++) {
        listOfNotesByDate[i] = listOfNotes.get(i);
    }

    // If sort-by is "by date", sort in reverse order
    if (sortBy.startsWith("date")) {
        Arrays.sort(listOfNotesByDate, Collections.reverseOrder());
        if (sortBy.endsWith("reversed"))
            ArrayUtils.reverse(listOfNotesByDate);
    }

    // Get array of first lines of each note
    for (int i = 0; i < numOfNotes; i++) {
        try {
            String title = listener.loadNoteTitle(listOfNotesByDate[i]);
            String date = listener.loadNoteDate(listOfNotesByDate[i]);
            listOfTitlesByDate[i] = new NoteListItem(title, date);
        } catch (IOException e) {
            showToast(R.string.error_loading_list);
        }
    }

    // If sort-by is "by name", sort alphabetically
    if (sortBy.startsWith("name")) {
        // Copy titles array
        System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes);

        // Sort titles
        Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle);
        if (sortBy.endsWith("reversed"))
            ArrayUtils.reverse(listOfTitlesByName);

        // Initialize notes array
        for (int i = 0; i < numOfNotes; i++)
            listOfNotesByName[i] = "new";

        // Copy filenames array with new sort order of titles and nullify date arrays
        for (int i = 0; i < numOfNotes; i++) {
            for (int j = 0; j < numOfNotes; j++) {
                if (listOfTitlesByName[i].getNote().equals(listOfTitlesByDate[j].getNote())
                        && listOfNotesByName[i].equals("new")) {
                    listOfNotesByName[i] = listOfNotesByDate[j];
                    listOfNotesByDate[j] = "";
                    listOfTitlesByDate[j] = new NoteListItem("", "");
                }
            }
        }

        // Populate ArrayList with notes, showing name as first line of the notes
        list.addAll(Arrays.asList(listOfTitlesByName));
    } else if (sortBy.startsWith("date"))
        list.addAll(Arrays.asList(listOfTitlesByDate));

    // Create the custom adapters to bind the array to the ListView
    final NoteListDateAdapter dateAdapter = new NoteListDateAdapter(getActivity(), list);
    final NoteListAdapter adapter = new NoteListAdapter(getActivity(), list);

    // Display the ListView
    if (showDate)
        listView.setAdapter(dateAdapter);
    else
        listView.setAdapter(adapter);

    listView.setSelection(ScrollPositions.getInstance().getPosition());

    // Finalize arrays to prepare for handling clicked items
    final String[] finalListByDate = listOfNotesByDate;
    final String[] finalListByName = listOfNotesByName;

    // Make ListView handle clicked items
    listView.setClickable(true);
    listView.setOnItemClickListener((arg0, arg1, position, arg3) -> {
        ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition());

        if (sortBy.startsWith("date")) {
            if (directEdit)
                listener.editNote(finalListByDate[position]);
            else
                listener.viewNote(finalListByDate[position]);
        } else if (sortBy.startsWith("name")) {
            if (directEdit)
                listener.editNote(finalListByName[position]);
            else
                listener.viewNote(finalListByName[position]);
        }
    });

    // Make ListView handle contextual action bar
    final ArrayList<String> cab = listener.getCabArray();

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // Respond to clicks on the actions in the CAB
            switch (item.getItemId()) {
            case R.id.action_select_all:
                cab.clear();

                for (int i = 0; i < listView.getAdapter().getCount(); i++) {
                    listView.setItemChecked(i, true);
                }
                return false;
            case R.id.action_export:
                if (cab.size() > 0) {
                    mode.finish(); // Action picked, so close the CAB
                    listener.exportNotes();
                    return true;
                } else {
                    showToast(R.string.no_notes_to_export);
                    return false;
                }
            case R.id.action_delete:
                if (cab.size() > 0) {
                    mode.finish(); // Action picked, so close the CAB
                    listener.deleteNotes();
                    return true;
                } else {
                    showToast(R.string.no_notes_to_delete);
                    return false;
                }
            default:
                return false;
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            listener.hideFab();

            // Inflate the menu for the CAB
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.context_menu, menu);

            // Clear any old values from cab array
            cab.clear();

            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            listener.showFab();
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (position > -1) {
                // Add/remove filenames to cab array as they are checked/unchecked
                if (checked) {
                    if (sortBy.startsWith("date"))
                        cab.add(finalListByDate[position]);
                    if (sortBy.startsWith("name"))
                        cab.add(finalListByName[position]);
                } else {
                    if (sortBy.startsWith("date"))
                        cab.remove(finalListByDate[position]);
                    if (sortBy.startsWith("name"))
                        cab.remove(finalListByName[position]);
                }

                listView.setItemChecked(-1, false);
            }

            // Update the title in CAB
            mode.setTitle(cab.size() + " " + listener.getCabString(cab.size()));
        }

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

    if (cab.size() > 0) {
        List<String> cabClone = new ArrayList<>(cab);
        cab.clear();

        String[] array = null;
        if (sortBy.startsWith("date"))
            array = finalListByDate;
        if (sortBy.startsWith("name"))
            array = finalListByName;

        if (array != null) {
            for (String filename : cabClone) {
                for (int i = 0; i < array.length; i++) {
                    if (filename.equals(array[i]))
                        listView.setItemChecked(i, true);
                }
            }
        }
    }

    // If there are no saved notes, then display the empty view
    if (numOfNotes == 0) {
        TextView empty = getActivity().findViewById(R.id.empty);
        listView.setEmptyView(empty);
    }
}

From source file:org.brandroid.openmanager.fragments.ContentFragment.java

public boolean createContextMenu(final OpenPath file, final AdapterView<?> list, final View view, final int pos,
        final int xOffset, final int yOffset) {
    Logger.LogInfo(getClassName() + ".onItemLongClick: " + file);

    final OpenContextMenuInfo info = new OpenContextMenuInfo(file);

    if (!OpenExplorer.USE_PRETTY_CONTEXT_MENUS) {
        if (Build.VERSION.SDK_INT > 10) {
            final PopupMenu pop = new PopupMenu(view.getContext(), view);
            pop.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    if (onOptionsItemSelected(item)) {
                        pop.dismiss();/*from   w w  w  . j  av  a 2s. co  m*/
                        return true;
                    } else if (getExplorer() != null)
                        return getExplorer().onIconContextItemSelected(pop, item, item.getMenuInfo(), view);
                    return false;
                }
            });
            pop.getMenuInflater().inflate(R.menu.context_file, pop.getMenu());
            onPrepareOptionsMenu(pop.getMenu());
            if (DEBUG)
                Logger.LogDebug("PopupMenu.show()");
            pop.show();
            return true;
        } else
            return list.showContextMenu();
    } else if (OpenExplorer.BEFORE_HONEYCOMB || !OpenExplorer.USE_ACTIONMODE) {

        try {
            //View anchor = view; //view.findViewById(R.id.content_context_helper);
            //if(anchor == null) anchor = view;
            //view.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            //Rect r = new Rect(view.getLeft(),view.getTop(),view.getMeasuredWidth(),view.getMeasuredHeight());
            MenuBuilder cmm = IconContextMenu.newMenu(list.getContext(), R.menu.context_file);
            if (!file.canRead()) {
                MenuUtils.setMenuEnabled(cmm, false);
                MenuUtils.setMenuEnabled(cmm, true, R.id.menu_context_info);
            }
            MenuUtils.setMenuEnabled(cmm, file.canWrite(), R.id.menu_context_paste, R.id.menu_context_cut,
                    R.id.menu_context_delete, R.id.menu_context_rename);
            onPrepareOptionsMenu(cmm);

            //if(!file.isArchive()) hideItem(cmm, R.id.menu_context_unzip);
            if (getClipboard().size() > 0)
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_multi);
            else
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_context_paste);
            MenuUtils.setMenuEnabled(cmm, !file.isDirectory(), R.id.menu_context_edit, R.id.menu_context_view);
            final IconContextMenu cm = new IconContextMenu(list.getContext(), cmm, view);
            //cm.setAnchor(anchor);
            cm.setNumColumns(2);
            cm.setOnIconContextItemSelectedListener(getExplorer());
            cm.setInfo(info);
            cm.setTextLayout(R.layout.context_item);
            cm.setTitle(file.getName());
            if (!cm.show()) //r.left, r.top);
                return list.showContextMenu();
            else
                return true;
        } catch (Exception e) {
            Logger.LogWarning("Couldn't show Iconified menu.", e);
            return list.showContextMenu();
        }
    }

    if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
        if (!file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {
                    //@Override
                    public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                        return false;
                    }

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);

                        mActionModeSelected = true;
                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        //ArrayList<OpenPath> files = new ArrayList<OpenPath>();

                        //OpenPath file = mLastPath.getChild(mode.getTitle().toString());
                        //files.add(file);

                        if (item.getItemId() != R.id.menu_context_cut && item.getItemId() != R.id.menu_multi
                                && item.getItemId() != R.id.menu_context_copy) {
                            mode.finish();
                            mActionModeSelected = false;
                        }
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }
        return true;

    }

    if (file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
        if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {

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

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);
                        menu.findItem(R.id.menu_context_paste).setEnabled(getClipboard().size() > 0);
                        //menu.findItem(R.id.menu_context_unzip).setEnabled(mHoldingZip);

                        mActionModeSelected = true;

                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }

        return true;
    }

    return false;
}

From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    mRootView = container;//from   w  ww .  j  av a2s .c  o m
    final View view = inflater.inflate(R.layout.playlist_activity, container, false);
    mSearchView = (SearchView) view.findViewById(R.id.search);
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(final String newText) {
            mFilter = newText;
            if (newText != null && newText.isEmpty()) {
                mFilter = null;
            }
            if (mFilter != null) {
                mFilter = mFilter.toLowerCase();
            }
            mList.setDragEnabled(mFilter == null);
            update(false);
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(final String query) {
            // Hide the keyboard and give focus to the list
            final InputMethodManager imm = (InputMethodManager) mActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
            mList.requestFocus();
            return true;
        }
    });
    mList = (DragSortListView) view.findViewById(android.R.id.list);
    mList.requestFocus();
    mList.setDropListener(mDropListener);
    mController = new DragSortController(mList);
    mController.setDragHandleId(R.id.cover);
    mController.setRemoveEnabled(false);
    mController.setSortEnabled(true);
    mController.setDragInitMode(1);

    mList.setFloatViewManager(mController);
    mList.setOnTouchListener(mController);
    mList.setDragEnabled(true);

    refreshListColorCacheHint();
    mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {

            final SparseBooleanArray checkedItems = mList.getCheckedItemPositions();
            final int count = mList.getCount();
            final ListAdapter adapter = mList.getAdapter();
            final int itemId = item.getItemId();
            int j = 0;
            int[] positions = null;
            boolean result = true;

            if (itemId == R.id.menu_delete) {
                positions = new int[mList.getCheckedItemCount()];
                for (int i = 0; i < count && j < positions.length; i++) {
                    if (checkedItems.get(i)) {
                        positions[j] = ((Music) adapter.getItem(i)).getSongId();
                        j++;
                    }
                }
            } else if (itemId == R.id.menu_crop) {
                positions = new int[mList.getCount() - mList.getCheckedItemCount()];
                for (int i = 0; i < count && j < positions.length; i++) {
                    if (!checkedItems.get(i)) {
                        positions[j] = ((Music) adapter.getItem(i)).getSongId();
                        j++;
                    }
                }
            } else {
                result = false;
            }

            if (j > 0) {
                QueueControl.run(QueueControl.REMOVE_BY_ID, positions);
                mode.finish();
            }

            return result;
        }

        @Override
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.mpd_queuemenu, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            mActionMode = null;
            mController.setSortEnabled(true);
        }

        @Override
        public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id,
                final boolean checked) {
            final int selectCount = mList.getCheckedItemCount();
            if (selectCount == 0) {
                mode.finish();
            }
            if (selectCount == 1) {
                mode.setTitle(R.string.actionSongSelected);
            } else {
                mode.setTitle(getString(R.string.actionSongsSelected, selectCount));
            }
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            mActionMode = mode;
            mController.setSortEnabled(false);
            return false;
        }
    });

    return view;
}

From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_playlist, container, false);

    mPlaylists = mPlaylistManager.getAllPlaylists();

    mList = (ListView) view.findViewById(R.id.songs);
    mEmptyPlaylist = view.findViewById(R.id.playlist_empty);

    // Add Spinner to toolbar
    mPlaylistsSpinner = (Spinner) getActivity().findViewById(R.id.toolbar_spinner);

    mPlaylistsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  w  w  w .j av  a2 s  .  c  o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            updateSongList();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    updatePlaylistSpinner();

    // Create the adapter
    mAdapter = new PlaylistSongAdapter(getActivity(), R.layout.item_playlist, getSelectedPlaylistSongs());

    mList.setOnItemClickListener(oiclSong);
    mList.setAdapter(mAdapter);

    mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) {
            SparseBooleanArray checkedPositions = mList.getCheckedItemPositions();
            LinkedList<MySong> selectedSongs = new LinkedList<>();

            for (int i = 0; i < checkedPositions.size(); ++i) {
                int position = checkedPositions.keyAt(i);
                if (checkedPositions.valueAt(i)) {
                    selectedSongs.add(getSelectedPlaylistSongs().get(position));
                }
            }

            if (!selectedSongs.isEmpty()) {
                switch (item.getItemId()) {
                case R.id.playlist_context_play:
                    playSong(selectedSongs.get(0));

                    mode.finish();
                    return true;
                case R.id.playlist_context_download:
                    LinkedList<String> urls = new LinkedList<>();
                    for (MySong s : selectedSongs) {
                        urls.add(s.getUrl());
                    }
                    if (!urls.isEmpty()) {
                        DownloadManager.getInstance().addJob(
                                ClementineMessageFactory.buildDownloadSongsMessage(DownloadItem.Urls, urls));
                    }
                    mode.finish();
                    return true;
                case R.id.playlist_context_remove:
                    Message msg = Message.obtain();
                    msg.obj = ClementineMessageFactory.buildRemoveMultipleSongsFromPlaylist(getPlaylistId(),
                            selectedSongs);
                    App.ClementineConnection.mHandler.sendMessage(msg);
                    mode.finish();
                    return true;
                default:
                    return false;
                }
            }
            return false;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) {
            android.view.MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.playlist_context_menu, menu);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status));

            return true;
        }

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

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark));
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        }
    });

    // Filter the results
    mAdapter.getFilter().filter(mFilterText);

    mActionBar.setTitle("");
    mActionBar.setSubtitle("");

    return view;
}

From source file:de.qspool.clementineremote.ui.fragments.LibraryFragment.java

@SuppressLint({ "InlinedApi", "NewApi" })
@Override//from ww  w  .  java2  s  . com
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_library, container, false);

    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.library_refresh_layout);
    mEmptyLibrary = (SwipeRefreshLayout) view.findViewById(R.id.library_refresh_empty_layout);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mEmptyLibrary.setOnRefreshListener(this);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange);
    mEmptyLibrary.setColorSchemeResources(R.color.orange);

    mList = (ListView) view.findViewById(R.id.library);

    mLibraryEmptyText = (TextView) mEmptyLibrary.findViewById(R.id.library_empty_txt);

    mList.setOnItemClickListener(oiclLibraryClick);
    mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override
        public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) {
            SparseBooleanArray checkedPositions = mList.getCheckedItemPositions();
            final LinkedList<SongSelectItem> selectedItems = new LinkedList<>();
            final LinkedList<String> urls = new LinkedList<>();
            mLibraryQueriesDone = 0;

            for (int i = 0; i < checkedPositions.size(); ++i) {
                int position = checkedPositions.keyAt(i);
                if (checkedPositions.valueAt(i)) {
                    selectedItems.add(mAdapters.getLast().getItem(position));
                }
            }

            for (SongSelectItem libraryItem : selectedItems) {
                OnSongSelectFinishedListener listener;

                switch (item.getItemId()) {
                case R.id.library_context_add:

                    listener = new OnSongSelectFinishedListener() {
                        @Override
                        public void OnSongSelectFinished(LinkedList<SongSelectItem> l) {
                            addSongsToPlaylist(l);
                        }
                    };

                    break;
                case R.id.library_context_download:
                    listener = new OnSongSelectFinishedListener() {
                        @Override
                        public void OnSongSelectFinished(LinkedList<SongSelectItem> l) {
                            for (SongSelectItem libItem : l) {
                                urls.add(libItem.getUrl());
                            }
                            mLibraryQueriesDone++;

                            // Have we got all queries?
                            if (mLibraryQueriesDone == selectedItems.size() && !urls.isEmpty()) {
                                DownloadManager.getInstance()
                                        .addJob(ClementineMessageFactory.buildDownloadSongsMessage(
                                                ClementineRemoteProtocolBuffer.DownloadItem.Urls, urls));
                            }

                        }
                    };

                    break;
                default:
                    return false;
                }
                queryLibraryItems(libraryItem, listener);
            }
            mode.finish();
            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) {
            android.view.MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.library_context_menu, menu);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status));
            }

            return true;
        }

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

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark));
            }
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        }
    });

    createRootAdapter();

    showList();

    mActionBar.setTitle("");
    mActionBar.setSubtitle("/");

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    prefs.registerOnSharedPreferenceChangeListener(this);

    setHasOptionsMenu(true);

    return view;
}

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/*w w w  . ja v  a 2s.c om*/
    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.brandroid.openmanager.activities.OpenExplorer.java

public boolean onClick(int id, MenuItem item, View from) {
    super.onClick(id);
    if (from == null || !from.isShown())
        from = findViewById(id);/*www .  j a va2s . c  om*/
    if (id != R.id.title_icon && id != android.R.id.home)
        ;
    toggleBookmarks(false);
    OpenFragment f = getSelectedFragment();
    if (f != null && f.onClick(id, from))
        return true;
    if (item != null && f != null && f.onOptionsItemSelected(item))
        return true;
    if (DEBUG)
        Logger.LogDebug("OpenExplorer.onClick(0x" + Integer.toHexString(id) + "," + item + "," + from + ")");
    switch (id) {
    case R.id.menu_debug:
        debugTest();
        break;
    case R.id.title_icon:
    case android.R.id.home:
        toggleBookmarks();
        return true;

    case R.id.menu_multi:
        if (getClipboard().isMultiselect()) {
            getClipboard().stopMultiselect();
            //getClipboard().clear();
            if (!BEFORE_HONEYCOMB && mActionMode != null)
                ((ActionMode) mActionMode).finish();
            return true;
        }

        if (BEFORE_HONEYCOMB || !USE_ACTIONMODE) {
            getClipboard().startMultiselect();
        } else {
            mActionMode = startActionMode(new ActionMode.Callback() {

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

                public void onDestroyActionMode(ActionMode mode) {
                    getClipboard().clear();
                    mActionMode = null;
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    mode.setTitle(getString(R.string.s_menu_multi) + ": " + getClipboard().size() + " "
                            + getString(R.string.s_files));
                    mode.getMenuInflater().inflate(R.menu.multiselect, menu);
                    //MenuUtils.setMenuVisible(menu, false, R.id.menu_context_paste, R.id.menu_context_unzip);
                    getDirContentFragment(true).changeMultiSelectState(true);
                    return true;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    if (getClipboard().size() < 1) {
                        mode.finish();
                        return true;
                    }
                    OpenPath file = getClipboard().get(0); //getMultiSelectHandler().getSelectedFiles();

                    getClipboard().clear();

                    return getDirContentFragment(false).executeMenu(item.getItemId(), mode, file);
                }
            });
        }
        return true;

    case R.id.menu_view_carousel:
        changeViewMode(OpenExplorer.VIEW_CAROUSEL, true);
        return true;

    case R.id.menu_view_grid:
        changeViewMode(OpenExplorer.VIEW_GRID, true);
        return true;

    case R.id.menu_view_list:
        changeViewMode(OpenExplorer.VIEW_LIST, true);
        return true;

    case R.id.menu_view_fullscreen:
        getPreferences().setSetting("global", "pref_fullscreen",
                !getPreferences().getSetting("global", "pref_fullscreen", false));
        goHome();
        return true;

    case R.id.menu_view_split:
        setSetting("pref_basebar", !USE_SPLIT_ACTION_BAR);
        goHome();
        return true;

    //case R.id.menu_global_ops_text:
    //case R.id.menu_global_ops_icon:
    case R.id.title_ops:
        refreshOperations();
        showLogFrag(mOpsFragment, true);
        checkTitleSeparator();
        return true;

    case R.id.title_log:
        if (mLogFragment == null)
            mLogFragment = new LogViewerFragment();
        showLogFrag(mLogFragment, true);
        sendToLogView(null, 0);
        return true;

    /*case R.id.menu_root:
    if(RootManager.Default.isRoot())
    {
       getPreferences().setSetting("global", "pref_root", false);
       showToast(getString(R.string.s_menu_root_disabled));
       RootManager.Default.exitRoot();
       item.setChecked(false);
    } else
    {
       if(RootManager.Default.isRoot() || RootManager.Default.requestRoot())
       {
          getPreferences().setSetting("global", "pref_root", true);
          showToast(getString(R.string.s_menu_root) + "!");
          item.setTitle(getString(R.string.s_menu_root) + "!");
       } else {
          item.setChecked(false);
          showToast("Unable to achieve root.");
       }
    }
    return true;
            
    case R.id.menu_flush:
    ThumbnailCreator.flushCache(getApplicationContext(), true);
    OpenPath.flushDbCache();
    goHome();
    return true;*/

    case R.id.menu_refresh:
        ContentFragment content = getDirContentFragment(true);
        if (content != null) {
            if (DEBUG && IS_DEBUG_BUILD)
                Logger.LogDebug("Refreshing " + content.getPath().getPath());
            FileManager.removeOpenCache(content.getPath().getPath());
            content.getPath().deleteFolderFromDb();
            content.runUpdateTask(true);
            changePath(content.getPath(), false, true);
        }
        mBookmarks.refresh();
        return true;

    case R.id.menu_settings:
        showPreferences(null);
        return true;

    case R.id.menu_search:
        onSearchRequested();
        return true;

    /*case R.id.menu_favorites:
    toggleBookmarks();
    return true;*/

    case R.id.menu_multi_all_delete:
        DialogHandler.showConfirmationDialog(this,
                getResources().getString(R.string.s_confirm_delete,
                        getClipboard().getCount() + " " + getResources().getString(R.string.s_files)),
                getResources().getString(R.string.s_menu_delete_all), new DialogInterface.OnClickListener() { // yes
                    public void onClick(DialogInterface dialog, int which) {
                        getEventHandler().deleteFile(getClipboard(), OpenExplorer.this, false);
                    }
                });
        break;

    case R.id.menu_multi_all_clear:
        getClipboard().clear();
        return true;

    case R.id.menu_multi_all_copy:
        getClipboard().DeleteSource = false;
        getDirContentFragment(false).executeMenu(R.id.content_paste, null,
                getDirContentFragment(false).getPath());
        break;

    case R.id.menu_multi_all_move:
        getClipboard().DeleteSource = true;
        getDirContentFragment(false).executeMenu(R.id.content_paste, null,
                getDirContentFragment(false).getPath());
        break;

    case R.id.title_paste:
    case R.id.title_paste_icon:
    case R.id.title_paste_text:
    case R.id.content_paste:
        //if(BEFORE_HONEYCOMB)
        getClipboard().setCurrentPath(getCurrentPath());
        onClipboardDropdown(from);
        return true;

    //getDirContentFragment(false).executeMenu(R.id.menu_paste, null, mLastPath, mClipboard);
    //return true;

    case R.id.menu_about:
        DialogHandler.showAboutDialog(this);
        return true;

    case R.id.menu_exit:
        DialogHandler.showConfirmationDialog(this, getString(R.string.s_alert_exit),
                getString(R.string.s_menu_exit), getPreferences(), "exit",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
        return true;
    case R.id.menu_more:
        showMenu(mOptsMenu, ViewUtils.getFirstView(this, R.id.menu_more, R.id.base_bar, R.id.title_buttons,
                android.R.id.home), true);
        return true;

    default:
        if (f instanceof ContentFragment) {
            ContentFragment cf = (ContentFragment) f;
            if (item.getMenuInfo() != null && cf.onContextItemSelected(item))
                return true;
            else if (cf.onClick(id, from))
                return true;
            else if (cf.onOptionsItemSelected(item))
                return true;
            return cf.executeMenu(id, null, getDirContentFragment(false).getPath());
        } else if (f instanceof TextEditorFragment)
            ((TextEditorFragment) f).onClick(id, from);
        else if (f.onOptionsItemSelected(item))
            return true;
    }

    //showToast("oops");
    return false;
    //return super.onOptionsItemSelected(item);
}

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;/*  www  . ja  va 2  s  .  c  o m*/

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