Search in sources :

Example 96 with ActionMode

use of android.view.ActionMode in project Klyph by jonathangerbaud.

the class AbsHListView method confirmCheckedPositionsById.

@TargetApi(16)
void confirmCheckedPositionsById() {
    // Clear out the positional check states, we'll rebuild it below from IDs.
    mCheckStates.clear();
    boolean checkedCountChanged = false;
    for (int checkedIndex = 0; checkedIndex < mCheckedIdStates.size(); checkedIndex++) {
        final long id = mCheckedIdStates.keyAt(checkedIndex);
        final int lastPos = mCheckedIdStates.valueAt(checkedIndex);
        final long lastPosId = mAdapter.getItemId(lastPos);
        if (id != lastPosId) {
            // Look around to see if the ID is nearby. If not, uncheck it.
            final int start = Math.max(0, lastPos - CHECK_POSITION_SEARCH_DISTANCE);
            final int end = Math.min(lastPos + CHECK_POSITION_SEARCH_DISTANCE, mItemCount);
            boolean found = false;
            for (int searchPos = start; searchPos < end; searchPos++) {
                final long searchId = mAdapter.getItemId(searchPos);
                if (id == searchId) {
                    found = true;
                    mCheckStates.put(searchPos, true);
                    mCheckedIdStates.setValueAt(checkedIndex, searchPos);
                    break;
                }
            }
            if (!found) {
                mCheckedIdStates.delete(id);
                checkedIndex--;
                mCheckedItemCount--;
                checkedCountChanged = true;
                if (android.os.Build.VERSION.SDK_INT > 11) {
                    if (mChoiceActionMode != null && mMultiChoiceModeCallback != null) {
                        ((MultiChoiceModeWrapper) mMultiChoiceModeCallback).onItemCheckedStateChanged((ActionMode) mChoiceActionMode, lastPos, id, false);
                    }
                }
            }
        } else {
            mCheckStates.put(lastPos, true);
        }
    }
    if (checkedCountChanged && mChoiceActionMode != null) {
        ((ActionMode) mChoiceActionMode).invalidate();
    }
}
Also used : ActionMode(android.view.ActionMode) MultiChoiceModeWrapper(it.sephiroth.android.library.util.v11.MultiChoiceModeWrapper) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Example 97 with ActionMode

use of android.view.ActionMode in project Notepad by farmerbb.

the class NoteListFragment method listNotes.

private void listNotes() {
    // Get number of files
    int numOfFiles = getNumOfNotes(getActivity().getFilesDir());
    int numOfNotes = numOfFiles;
    // Get array of file names
    String[] listOfFiles = getListOfNotes(getActivity().getFilesDir());
    ArrayList<String> listOfNotes = new ArrayList<>();
    // Remove any files from the list that aren't notes
    for (int i = 0; i < numOfFiles; i++) {
        if (NumberUtils.isNumber(listOfFiles[i]))
            listOfNotes.add(listOfFiles[i]);
        else
            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.equals("date"))
        Arrays.sort(listOfNotesByDate, Collections.reverseOrder());
    // 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.equals("name")) {
        // Copy titles array
        System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes);
        // Sort titles
        Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle);
        // 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.equals("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(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition());
            if (sortBy.equals("date")) {
                if (directEdit)
                    listener.editNote(finalListByDate[position]);
                else
                    listener.viewNote(finalListByDate[position]);
            } else if (sortBy.equals("name")) {
                if (directEdit)
                    listener.editNote(finalListByName[position]);
                else
                    listener.viewNote(finalListByName[position]);
            }
        }
    });
    // Make ListView handle contextual action bar
    final ArrayList<String> cab = new ArrayList<>(numOfNotes);
    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:
                    // Action picked, so close the CAB
                    mode.finish();
                    listener.exportNote(cab.toArray());
                    return true;
                case R.id.action_delete:
                    // Action picked, so close the CAB
                    mode.finish();
                    listener.deleteNote(cab.toArray());
                    return true;
                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.equals("date"))
                        cab.add(finalListByDate[position]);
                    if (sortBy.equals("name"))
                        cab.add(finalListByName[position]);
                } else {
                    if (sortBy.equals("date"))
                        cab.remove(finalListByDate[position]);
                    if (sortBy.equals("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 there are no saved notes, then display the empty view
    if (numOfNotes == 0) {
        TextView empty = (TextView) getActivity().findViewById(R.id.empty);
        listView.setEmptyView(empty);
    }
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) MenuInflater(android.view.MenuInflater) NoteListDateAdapter(com.farmerbb.notepad.adapter.NoteListDateAdapter) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) IOException(java.io.IOException) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) NoteListAdapter(com.farmerbb.notepad.adapter.NoteListAdapter) ActionMode(android.view.ActionMode) NoteListItem(com.farmerbb.notepad.util.NoteListItem) TextView(android.widget.TextView) Menu(android.view.Menu) MultiChoiceModeListener(android.widget.AbsListView.MultiChoiceModeListener)

Example 98 with ActionMode

use of android.view.ActionMode in project FileExplorer by MiCode.

the class FileViewInteractionHub method onOperationSelectAll.

public void onOperationSelectAll() {
    mCheckedFileNameList.clear();
    for (FileInfo f : mFileViewListener.getAllFiles()) {
        f.Selected = true;
        mCheckedFileNameList.add(f);
    }
    FileExplorerTabActivity fileExplorerTabActivity = (FileExplorerTabActivity) mContext;
    ActionMode mode = fileExplorerTabActivity.getActionMode();
    if (mode == null) {
        mode = fileExplorerTabActivity.startActionMode(new ModeCallback(mContext, this));
        fileExplorerTabActivity.setActionMode(mode);
        Util.updateActionModeTitle(mode, mContext, getSelectedFileList().size());
    }
    mFileViewListener.onDataChanged();
}
Also used : ActionMode(android.view.ActionMode) ModeCallback(net.micode.fileexplorer.FileListItem.ModeCallback)

Example 99 with ActionMode

use of android.view.ActionMode in project AndroidChromium by JackyAndroid.

the class LocationBarLayout method initializeControls.

@Override
public void initializeControls(WindowDelegate windowDelegate, ActionBarDelegate actionBarDelegate, WindowAndroid windowAndroid) {
    mWindowDelegate = windowDelegate;
    mActionModeController = new ActionModeController(getContext(), actionBarDelegate);
    mActionModeController.setCustomSelectionActionModeCallback(new ToolbarActionModeCallback() {

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            boolean retVal = super.onCreateActionMode(mode, menu);
            mode.getMenuInflater().inflate(R.menu.textselectionmenu, menu);
            return retVal;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (item.getItemId() == R.id.copy_url) {
                ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("url", mOriginalUrl);
                clipboard.setPrimaryClip(clip);
                mode.finish();
                return true;
            } else {
                return super.onActionItemClicked(mode, item);
            }
        }
    });
    mWindowAndroid = windowAndroid;
    // If the user focused the omnibox prior to the native libraries being initialized,
    // autocomplete will not always be enabled, so we force it enabled in that case.
    mUrlBar.setIgnoreTextChangesForAutocomplete(false);
}
Also used : ClipboardManager(android.content.ClipboardManager) ToolbarActionModeCallback(org.chromium.chrome.browser.toolbar.ToolbarActionModeCallback) ActionMode(android.view.ActionMode) ActionModeController(org.chromium.chrome.browser.toolbar.ActionModeController) MenuItem(android.view.MenuItem) Menu(android.view.Menu) ClipData(android.content.ClipData)

Aggregations

ActionMode (android.view.ActionMode)99 UiThreadTest (android.test.UiThreadTest)30 FloatingActionMode (com.android.internal.view.FloatingActionMode)15 StandaloneActionMode (com.android.internal.view.StandaloneActionMode)10 Menu (android.view.Menu)9 MenuItem (android.view.MenuItem)9 Animator (android.animation.Animator)6 Context (android.content.Context)6 Paint (android.graphics.Paint)6 View (android.view.View)6 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ObjectAnimator (android.animation.ObjectAnimator)5 Resources (android.content.res.Resources)5 TypedValue (android.util.TypedValue)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 ViewStub (android.view.ViewStub)5 PopupWindow (android.widget.PopupWindow)5 ActionBarContextView (com.android.internal.widget.ActionBarContextView)5 MenuInflater (android.view.MenuInflater)4 AdapterView (android.widget.AdapterView)3