Example usage for android.view ActionMode finish

List of usage examples for android.view ActionMode finish

Introduction

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

Prototype

public abstract void finish();

Source Link

Document

Finish and close this action mode.

Usage

From source file:it.gulch.linuxday.android.widgets.BookmarksMultiChoiceModeListener.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
    case R.id.delete:
        // Remove multiple bookmarks at once
        long[] checkedItemIds = listView.getCheckedItemIds();
        List<Long> checkedItemIdsList = Arrays.asList(ArrayUtils.toObject(checkedItemIds));
        new RemoveBookmarksAsyncTask().execute(checkedItemIdsList);
        mode.finish();
        return true;
    }// w  w  w .j  av a2  s .  co  m

    return false;
}

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  w ww  .j  a  va 2s . 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  .  j a va 2  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("tvshow-episode-changed"));
}

From source file:org.thialfihar.android.apg.ui.KeyListSecretFragment.java

/**
 * Show dialog to delete key/*from ww w  .jav  a2 s.c om*/
 *
 * @param keyRingRowIds
 */
@TargetApi(11)
public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) {
    // Message is received after key is deleted
    Handler returnHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
                mode.finish();
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds,
            Id.type.secret_key);

    deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.FileActions.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_upload:
        upload(getFragment(), new ArrayList<File>(selectedFiles));
        mode.finish();
        selectedFiles.clear();/*from  w w  w.  j a v  a  2 s.co m*/
        return true;
    case R.id.menu_action_delete:
        delete(getFragment(), new ArrayList<File>(selectedFiles));
        mode.finish();
        selectedFiles.clear();
        return true;
    case R.id.menu_action_edit:
        edit(getFragment(), selectedFiles.get(0));
        mode.finish();
        selectedFiles.clear();
        return true;
    case R.id.menu_action_share:
        share(getFragment(), selectedFiles);
        mode.finish();
        selectedFiles.clear();
        return true;
    case R.id.menu_file_send:
        send(getFragment(), selectedFiles);
        mode.finish();
        selectedFiles.clear();
        return true;
    case R.id.menu_select_all:
        selectAll();
        return false;
    default:
        break;
    }
    return false;
}

From source file:org.mariotaku.twidere.util.StatusActionModeCallback.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.copyUrl: {
        final int start = textView.getSelectionStart(), end = textView.getSelectionEnd();
        final SpannableString string = SpannableString.valueOf(textView.getText());
        final URLSpan[] spans = string.getSpans(start, end, URLSpan.class);
        if (spans.length != 1)
            return true;
        ClipboardUtils.setText(context, spans[0].getURL());
        mode.finish();
        return true;
    }/*from  w ww  .  j a va  2 s .c  om*/
    }
    return false;
}

From source file:com.fusionx.lightirc.ui.UserListFragment.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    final List<WorldUser> selectedItems = getCheckedItems();
    final String nick = selectedItems.get(0).getNick();
    switch (item.getItemId()) {
    case R.id.fragment_userlist_cab_mention:
        mCallback.onMentionMultipleUsers(selectedItems);
        mode.finish();
        mCallback.closeDrawer();/*from  ww  w . j a  v  a2 s . c  om*/
        return true;
    case R.id.fragment_userlist_cab_pm: {
        onPrivateMessageUser(nick);
        return true;
    }
    case R.id.fragment_userlist_cab_whois:
        mChannel.getServer().getServerCallBus().sendUserWhois(nick);
        return true;
    default:
        return false;
    }
}

From source file:com.jbirdvegas.mgerrit.PatchSetViewerFragment.java

private void init() {
    View currentFragment = this.getView();

    ExpandableListView mListView = (ExpandableListView) currentFragment.findViewById(R.id.commit_cards);
    disconnectedView = currentFragment.findViewById(R.id.disconnected_view);

    sIsLegacyVersion = !Config.isDiffSupported(mParent);

    mAdapter = new CommitDetailsAdapter(mParent);
    mListView.setAdapter(mAdapter);//from   w  w  w  .j a  v  a  2 s .  co  m

    // Child click listeners (relevant for the changes cards)
    mListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mFilesCAB = new FilesCAB(mParent, !sIsLegacyVersion);
    mAdapter.setContextualActionBar(mFilesCAB);
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ExpandableListView listView = (ExpandableListView) parent;
            long pos = listView.getExpandableListPosition(position);
            int groupPos = ExpandableListView.getPackedPositionGroup(pos);
            int childPos = ExpandableListView.getPackedPositionChild(pos);

            if (!mAdapter.isLongClickSupported(groupPos, childPos)) {
                return false;
            }

            // In case this is a group view and does not have the change number tagged
            view.setTag(R.id.changeID, mSelectedChange);
            FilesCAB.TagHolder holder = new FilesCAB.TagHolder(view, mContext, groupPos, childPos >= 0);

            // Set the title to be shown in the action bar
            if (holder.filePath != null) {
                mFilesCAB.setTitle(holder.filePath);
            } else {
                String s = mParent.getResources().getString(R.string.change_detail_heading);
                mFilesCAB.setTitle(String.format(s, holder.changeNumber.intValue()));
            }

            mFilesCAB.setActionMode(getActivity().startActionMode(mFilesCAB));
            ActionMode actionMode = mFilesCAB.getActionMode();

            // Call requires API 14 (ICS)
            actionMode.setTag(holder);
            view.setSelected(true);
            return true;
        }
    });
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            // This is only valid for the changed files group
            int childItemType = mAdapter.getChildType(groupPosition, childPosition);
            if (childItemType != CommitDetailsAdapter.Cards.CHANGED_FILES.ordinal()) {
                return false;
            }
            // View the diff and close the CAB if a change diff could be viewed
            boolean diffLaunched = PatchSetChangesCard.onViewClicked(mParent, v);
            if (diffLaunched) {
                ActionMode mode = mFilesCAB.getActionMode();
                if (mode != null)
                    mode.finish();
            }
            return diffLaunched;
        }
    });

    mUrl = new GerritURL();

    Button retryButton = (Button) currentFragment.findViewById(R.id.btn_retry);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (sIsLegacyVersion)
                sendRequest(GerritService.DataType.Commit);
            else
                sendRequest(GerritService.DataType.LegacyCommitDetails);
        }
    });

    if (getArguments() == null) {
        /** This should be the default value of {@link ChangeListFragment.mSelectedStatus } */
        setStatus(JSONCommit.Status.NEW.toString());
        loadChange(true);
    } else {
        Bundle args = getArguments();
        setStatus(args.getString(STATUS));
        String changeid = args.getString(CHANGE_ID);
        mChangeNumber = args.getInt(CHANGE_NO);

        if (changeid != null && !changeid.isEmpty()) {
            loadChange(changeid);
        }
    }

    mEventBus = EventBus.getDefault();
}

From source file:com.btmura.android.reddit.app.AccountListFragment.java

private void handleDelete(ActionMode mode) {
    SparseBooleanArray checked = getListView().getCheckedItemPositions();
    int checkedCount = getListView().getCheckedItemCount();
    String[] accountNames = new String[checkedCount];
    int count = adapter.getCount();
    int j = 0;//from   ww  w .j  a  v  a 2 s  . c o m
    for (int i = 0; i < count; i++) {
        if (checked.get(i)) {
            accountNames[j++] = adapter.getItem(i).getAccountName();
        }
    }
    removeAccounts(accountNames);
    mode.finish();
}

From source file:br.com.android.cotuca.toptask.Activitys.MSimplesActivity.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    TarefaDAO tarefas = TarefaDAO.getInstance(this);

    if (id == R.id.acction_concluir_tarefa) {
        tarefas.concluirTarefa(tarefaSelecionada);
        tarefaSelecionada = null;/*from   www . j a  v a2  s .  co  m*/
        this.selectItem(0);
        mode.finish();
        return true;

    } else if (id == R.id.acction_editar_tarefa) {
        Intent iEditar = new Intent(this, EditarTarefa.class);
        Bundle dados = new Bundle();

        dados.putInt(Tags.B_ACAO, Tags.ACAO_EDITAR);
        dados.putString(ContratoTarefas.Colunas.NOME, tarefaSelecionada.getNome());
        dados.putString(ContratoTarefas.Colunas.DESCRICAO, tarefaSelecionada.getDescricao());
        dados.putString(ContratoTarefas.Colunas.DATA_ENTREGA, tarefaSelecionada.getDataEntrega());
        dados.putInt(Tags.ID_TAREFA, tarefaSelecionada.getID());
        dados.putInt(ContratoTarefas.Colunas.PROJETO, idProjetoSelecionado);
        dados.putInt(ContratoTarefas.Colunas.DONO, idUsuarioSelecionado);

        dados.putInt(ContratoTarefas.Colunas.TEMPO_FEITO, tarefaSelecionada.getTempoFeito());
        dados.putInt(ContratoTarefas.Colunas.TEMPO_LIMITE, tarefaSelecionada.getTempoLimite());

        iEditar.putExtras(dados);

        startActivity(iEditar);

        tarefaSelecionada = null;
        this.selectItem(0);
        mode.finish();
        return true;

    } else if (id == R.id.acction_excluir_tarefa) {

        tarefas.delete(tarefaSelecionada);
        tarefaSelecionada = null;
        this.selectItem(0);

        mode.finish();
        return true;
    } else if (id == R.id.acction_fazendo_tarefa) {

        tarefas.fazendoTarefa(tarefaSelecionada);
        tarefaSelecionada = null;
        this.selectItem(0);
        mode.finish();
        return true;

    }

    return false;
}