Example usage for android.util SparseBooleanArray keyAt

List of usage examples for android.util SparseBooleanArray keyAt

Introduction

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

Prototype

public int keyAt(int index) 

Source Link

Document

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

Usage

From source file:com.gmail.taneza.ronald.carbs.myfoods.MyFoodsEditableFragment.java

private void deleteFromList(SparseBooleanArray selection) {
    ArrayList<FoodItem> itemsToDelete = new ArrayList<FoodItem>();
    for (int i = 0; i < selection.size(); i++) {
        itemsToDelete.add(getFoodItemAtPosition(getListView(), selection.keyAt(i)));
    }/*w  w w .  ja va2  s .  c  om*/

    mFoodDbAdapter.deleteMyFoodItems(itemsToDelete);
    restartLoader();
    mMyFoodsActivityNotifier.setItemDeleted();
}

From source file:org.gnucash.android.ui.export.ScheduledExportListFragment.java

/**
 * Unchecks all the checked items in the list
 *///from   www  .  ja v a2  s  .c  om
private void uncheckAllItems() {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    ListView listView = getListView();
    for (int i = 0; i < checkedPositions.size(); i++) {
        int position = checkedPositions.keyAt(i);
        listView.setItemChecked(position, false);
    }
}

From source file:com.android.gallery3d2.ingest.IngestService.java

protected void importSelectedItems(SparseBooleanArray selected, Adapter adapter) {
    List<MtpObjectInfo> importHandles = new ArrayList<MtpObjectInfo>();
    for (int i = 0; i < selected.size(); i++) {
        if (selected.valueAt(i)) {
            Object item = adapter.getItem(selected.keyAt(i));
            if (item instanceof MtpObjectInfo) {
                importHandles.add(((MtpObjectInfo) item));
            }//from  www. jav  a  2s  .co  m
        }
    }
    ImportTask task = new ImportTask(mDevice, importHandles, BucketNames.IMPORTED, this);
    task.setListener(this);
    mNotificationBuilder.setProgress(0, 0, true)
            .setContentText(getResources().getText(R.string.ingest_importing));
    startForeground(NotificationIds.INGEST_NOTIFICATION_IMPORTING, mNotificationBuilder.build());
    new Thread(task).start();
}

From source file:com.android.gallery3d.ingest.IngestService.java

protected void importSelectedItems(SparseBooleanArray selected, Adapter adapter) {
    List<IngestObjectInfo> importHandles = new ArrayList<IngestObjectInfo>();
    for (int i = 0; i < selected.size(); i++) {
        if (selected.valueAt(i)) {
            Object item = adapter.getItem(selected.keyAt(i));
            if (item instanceof IngestObjectInfo) {
                importHandles.add(((IngestObjectInfo) item));
            }/*from  w w  w .  java 2 s.  c  o  m*/
        }
    }
    ImportTask task = new ImportTask(mDevice, importHandles, mDevicePrettyName, this);
    task.setListener(this);
    mNotificationBuilder.setProgress(0, 0, true)
            .setContentText(getResources().getText(R.string.ingest_importing));
    startForeground(R.id.ingest_notification_importing, mNotificationBuilder.build());
    new Thread(task).start();
}

From source file:monakhv.android.samlib.AuthorTagsActivity.java

/**
 * User pre Ok button//www.j av  a 2s  .co  m
 *
 * @param view View
 */
public void okClick(View view) {

    SparseBooleanArray checked = getListView().getCheckedItemPositions();
    List<Integer> tags = new ArrayList<Integer>();
    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            Object o = getListView().getItemAtPosition(checked.keyAt(i));
            Cursor cur = (Cursor) o;//selected cursors
            Log.i(DEBUG_TAG, "selected: " + cur.getString(cur.getColumnIndex(SQLController.COL_TAG_NAME)));
            tags.add(cur.getInt(cur.getColumnIndex(SQLController.COL_ID)));
        }
    }
    AuthorController sql = new AuthorController(this);
    Author a = sql.getById(author_id);
    sql.syncTags(a, tags);
    helper.requestBackup();
    finish();
}

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

public List<Track> getSelectedTracks() {
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
    List<Track> tracks = new ArrayList<Track>();
    if (checkedItems != null) {
        for (int i = 0; i < checkedItems.size(); i++) {
            if (checkedItems.valueAt(i)) {
                tracks.add(mTracklist.get(checkedItems.keyAt(i)));
            }/*from  w w  w  .  ja v  a 2  s . co m*/
        }
    }
    //if no tracks are selected, return all
    if (tracks.size() == 0)
        tracks = mTracklist;
    return tracks;
}

From source file:com.muzima.view.cohort.FormTemplateWizardActivity.java

private boolean hasRegistrationFormSelected() {
    SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
    boolean registrationFormSelected = false;
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i)) {
            AvailableForm selectedForm = (AvailableForm) listView
                    .getItemAtPosition(checkedItemPositions.keyAt(i));
            if (selectedForm.isRegistrationForm()) {
                registrationFormSelected = true;
            }//  w w  w . j  av a2 s. c om
        }
    }
    return registrationFormSelected;
}

From source file:org.mariotaku.twidere.activity.support.DraftsActivity.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DELETE: {
        // TODO confim dialog and image removal
        final Where where = Where.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds()));
        mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null);
        break;//from  ww w  .  j  ava 2  s.  com
    }
    case MENU_SEND: {
        final Cursor c = mAdapter.getCursor();
        if (c == null || c.isClosed())
            return false;
        final SparseBooleanArray checked = mListView.getCheckedItemPositions();
        final List<DraftItem> list = new ArrayList<DraftItem>();
        final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c);
        for (int i = 0, j = checked.size(); i < j; i++) {
            if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) {
                list.add(new DraftItem(c, indices));
            }
        }
        if (sendDrafts(list)) {
            final Where where = Where.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:org.flerda.android.honeypad.NoteListFragment.java

public int getCheckedItemCount() {
    if (mIsV11) {
        return mLV.getCheckedItemCount();
    } else {//from   w  w w. ja v a2s . co m
        /** Slow count **/
        SparseBooleanArray sba = mLV.getCheckedItemPositions();
        int count = 0;
        int size = sba.size();
        for (int i = 0; i < size; i++) {
            int key = sba.keyAt(i);
            if (sba.get(key)) {
                count++;
            }
        }
        return count;
    }
}

From source file:com.commonsware.cwac.masterdetail.MasterDetailController.java

@SuppressWarnings("unchecked")
void removeChecked() {
    SparseBooleanArray checked = getListView().getCheckedItemPositions();

    ArrayList<Integer> positions = new ArrayList<Integer>();

    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            positions.add(checked.keyAt(i));
        }//from   www .ja v a 2s . com
    }

    Collections.sort(positions, Collections.reverseOrder());

    for (int position : positions) {
        removeModel(getModelCollection().get(position));
        getModelCollection().remove(position);
        ((ModelPagerAdapter) getPagerAdapter()).remove(position);
    }

    getListView().clearChoices();
    ((ModelPagerAdapter) getPagerAdapter()).notifyDataSetChanged();
}