Example usage for android.util SparseBooleanArray valueAt

List of usage examples for android.util SparseBooleanArray valueAt

Introduction

In this page you can find the example usage for android.util SparseBooleanArray valueAt.

Prototype

public boolean valueAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the value from the indexth key-value mapping that this SparseBooleanArray stores.

Usage

From source file:org.mariotaku.twidere.fragment.DraftsFragment.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.delete: {
        final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment();
        final Bundle args = new Bundle();
        args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds());
        f.setArguments(args);/*ww  w. j a  va2 s  .  c om*/
        f.show(getChildFragmentManager(), "delete_drafts_confirm");
        break;
    }
    case R.id.send: {
        final Cursor c = mAdapter.getCursor();
        if (c == null || c.isClosed())
            return false;
        final SparseBooleanArray checked = mListView.getCheckedItemPositions();
        final List<Draft> list = new ArrayList<>();
        final DraftCursorIndices indices = new DraftCursorIndices(c);
        for (int i = 0, j = checked.size(); i < j; i++) {
            if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) {
                list.add(indices.newObject(c));
            }
        }
        if (sendDrafts(list)) {
            final Expression where = Expression.in(new Column(Drafts._ID),
                    new RawItemArray(mListView.getCheckedItemIds()));
            mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null);
        }
        break;
    }
    default: {
        return false;
    }
    }
    mode.finish();
    return true;
}

From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

private void deleteSelectedRecords() {
    RecordDAO recordDao = new RecordDAO(getActivity());
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    int deleteCount = 0;
    for (int i = 0; i < selected.size(); i++) {
        // Ignore the first item as it is help text.
        if (selected.keyAt(i) > 0) {

            if (selected.valueAt(i) == true) {
                Record record = ((RecordView) getListAdapter().getItem(selected.keyAt(i))).record;
                recordDao.delete(Record.class, record.getId());
                deleteCount++;/*from   www.  j a  v  a  2 s .c  om*/
            }
        }
    }
    if (deleteCount > 0) {
        String message = "%d records deleted";
        if (deleteCount == 1) {
            message = "%d record deleted";
        }
        Toast.makeText(getActivity(), String.format(message, deleteCount), Toast.LENGTH_SHORT).show();

    }

    finishActionMode();

    reload();

}

From source file:com.conferenceengineer.android.iosched.ui.SessionsFragment.java

private List<Integer> getCheckedSessionPositions() {
    List<Integer> checkedSessionPositions = new ArrayList<Integer>();
    ListView listView = getListView();
    if (listView == null) {
        return checkedSessionPositions;
    }// w ww  .j  a va 2  s  .co m

    SparseBooleanArray checkedPositionsBool = listView.getCheckedItemPositions();
    for (int i = 0; i < checkedPositionsBool.size(); i++) {
        if (checkedPositionsBool.valueAt(i)) {
            checkedSessionPositions.add(checkedPositionsBool.keyAt(i));
        }
    }

    return checkedSessionPositions;
}

From source file:org.totschnig.myexpenses.fragment.TemplatesList.java

@Override
protected void configureMenu11(Menu menu, int count, AbsListView lv) {
    super.configureMenu11(menu, count, lv);
    switch (lv.getId()) {
    case R.id.list:
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        boolean hasForeignExchangeTransfer = false, hasPlan = false;
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i) && isForeignExchangeTransfer(checkedItemPositions.keyAt(i))) {
                hasForeignExchangeTransfer = true;
                break;
            }//from www .j  a  v  a 2 s .  c om
        }
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i) && isPlan(checkedItemPositions.keyAt(i))) {
                hasPlan = true;
                break;
            }
        }
        configureMenuInternal(menu, count, hasForeignExchangeTransfer, hasPlan);
        break;
    case R.id.calendar_gridview:
        requirePlanMonthFragment().configureMenu11(menu, count, lv);
    }
}

From source file:org.dvbviewer.controller.ui.base.BaseListFragment.java

/**
 * Gets the checked item count.// www .j  a v  a 2s . c  o m
 *
 * @return the checked item count
 * @author RayBa
 * @date 07.04.2013
 */
public int getCheckedItemCount() {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    int count = 0;
    int size = checkedPositions.size();
    if (checkedPositions != null && size > 0) {
        for (int i = 0; i < size; i++) {
            if (checkedPositions.valueAt(i)) {
                count++;
            }
        }
    }
    return count;
}

From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

private void uploadSelectedRecords() {

    boolean allDrafts = true;
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    int count = countSelected();
    int index = 0;
    int[] recordIds = new int[count];
    for (int i = 0; i < selected.size(); i++) {
        // Ignore the first item as it is help text.
        if (selected.keyAt(i) > 0) {
            if (selected.valueAt(i) == true) {
                Record record = ((RecordView) getListAdapter().getItem(selected.keyAt(i))).record;
                if (record.getStatus() != Record.Status.DRAFT) {
                    allDrafts = false;//from   w ww .ja  v a 2s  .co  m
                }
                recordIds[index++] = record.getId();
            }
        }
    }

    if (allDrafts) {
        showDraftsError();
    } else {
        Intent intent = new Intent(getActivity(), UploadService.class);
        intent.putExtra(UploadService.RECORD_IDS_EXTRA, recordIds);
        getActivity().startService(intent);
    }
    finishActionMode();
}

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

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    int count = getListView().getCheckedItemCount();
    boolean aboutItemVisible = count == 1;
    boolean shareItemsVisible = count == 1;
    boolean deleteItemVisible = true;

    SparseBooleanArray checked = getListView().getCheckedItemPositions();
    int size = checked.size();
    for (int i = 0; i < size; i++) {
        if (checked.valueAt(i)) {
            int position = checked.keyAt(i);
            int adapterIndex = mergeAdapter.getAdapterIndex(position);
            switch (adapterIndex) {
            case ADAPTER_ACCOUNTS:
            case ADAPTER_PLACES:
                aboutItemVisible = shareItemsVisible = deleteItemVisible = false;
                break;

            case ADAPTER_SUBREDDITS:
                int adapterPosition = mergeAdapter.getAdapterPosition(position);
                String subreddit = subredditAdapter.getName(adapterPosition);
                boolean hasSidebar = Subreddits.hasSidebar(subreddit);
                aboutItemVisible &= hasSidebar;
                shareItemsVisible &= hasSidebar;
                deleteItemVisible &= hasSidebar;
                break;
            }/*  w  w  w  .j  a v  a2s.com*/
        }
    }

    if (aboutItemVisible || shareItemsVisible || deleteItemVisible) {
        prepareMode(mode, count);
        prepareAddItem(menu);
        prepareAboutItem(menu, aboutItemVisible);
        prepareDeleteItem(menu, deleteItemVisible);
        prepareShareItems(menu, shareItemsVisible);
    } else {
        mode.finish();
    }

    return true;
}

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

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

        @Override/*from   ww  w  .j  a  v  a  2  s  .  com*/
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = getActivity().getMenuInflater();
            inflater.inflate(R.menu.list_cab, menu);
            return true;
        }

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

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

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {

        }

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

        }

    });
}

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

@SuppressLint({ "InlinedApi", "NewApi" })
@Override/*  ww  w . j av  a  2 s  . com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_global_search, container, false);

    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.global_search_refresh_layout);
    mEmptyView = (SwipeRefreshLayout) view.findViewById(R.id.global_search_empty);

    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange);
    mEmptyView.setColorSchemeResources(R.color.orange);
    mSwipeRefreshLayout.setEnabled(true);
    mEmptyView.setEnabled(true);

    mEmptyText = (TextView) view.findViewById(R.id.global_search_empty_txt);
    mList = (ListView) view.findViewById(R.id.global_search);

    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SongSelectItem item = mAdapters.getLast().getItem(position);

            if (item.getLevel() == mMaxLevels - 1) {
                Message msg = Message.obtain();
                LinkedList<ClementineRemoteProtocolBuffer.SongMetadata> songs = new LinkedList<>();
                songs.add(GlobalSearchManager.getInstance().getRequest().getSongFromUrl(item.getUrl()));
                msg.obj = ClementineMessageFactory
                        .buildInsertSongs(App.Clementine.getPlaylistManager().getActivePlaylistId(), songs);
                App.ClementineConnection.mHandler.sendMessage(msg);

                String text = getActivity().getResources().getQuantityString(R.plurals.songs_added, 1, 1);
                Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
            } else {
                GlobalSearchQuery globalSearchQuery = new GlobalSearchQuery(getActivity(), mQueryId);
                globalSearchQuery.openDatabase();
                globalSearchQuery.setLevel(mAdapters.size());
                globalSearchQuery.setSelection(item.getSelection());
                mAdapters.add(new DynamicSongQueryAdapter(getActivity(), globalSearchQuery));
                showList();
            }
        }
    });
    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<>();

            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 songItem : selectedItems) {
                OnSongSelectFinishedListener listener;

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

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

                    break;
                default:
                    return false;
                }
                queryItems(songItem, listener);
            }
            mode.finish();
            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.global_search_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, 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) {
        }
    });

    GlobalSearchManager.getInstance().addOnGlobalSearchResponseListerner(this);

    setHasOptionsMenu(true);

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

    return view;
}

From source file:org.awesomeapp.messenger.ui.ContactsPickerActivity.java

private void multiFinish(SparseBooleanArray positions) {

    ArrayList<String> users = new ArrayList<String>();
    ArrayList<Integer> providers = new ArrayList<Integer>();
    ArrayList<Integer> accounts = new ArrayList<Integer>();

    for (int i = 0; i < positions.size(); i++) {
        if (positions.valueAt(i)) {
            Cursor cursor = (Cursor) mAdapter.getItem(i);

            users.add(cursor.getString(ContactListItem.COLUMN_CONTACT_USERNAME));
            providers.add((int) cursor.getLong(ContactListItem.COLUMN_CONTACT_PROVIDER));
            accounts.add((int) cursor.getLong(ContactListItem.COLUMN_CONTACT_ACCOUNT));
        }//ww w  . java2  s  .  c  om
    }

    Intent data = new Intent();
    data.putStringArrayListExtra(EXTRA_RESULT_USERNAMES, users);
    data.putIntegerArrayListExtra(EXTRA_RESULT_PROVIDER, providers);
    data.putIntegerArrayListExtra(EXTRA_RESULT_ACCOUNT, accounts);
    setResult(RESULT_OK, data);
    finish();
}