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:net.seedboxer.seedroid.activities.fragments.DownloadsFragment.java

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // Notice how the ListView api is lame
    // You can use mListView.getCheckedItemIds() if the adapter
    // has stable ids, e.g you're using a CursorAdaptor
    SparseBooleanArray checked = getListView().getCheckedItemPositions();
    boolean hasCheckedElement = false;
    for (int i = 0; i < checked.size() && !hasCheckedElement; i++) {
        hasCheckedElement = checked.valueAt(i);
    }/*from  w w  w.java  2 s.co  m*/

    if (hasCheckedElement) {
        if (mActionMode == null) {
            mActionMode = getView().startActionMode(new ModeCallback());
        }
    } else {
        if (mActionMode != null) {
            mActionMode.finish();
        }
    }
}

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   w w w  . j a v  a 2s .  c  o  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:monakhv.android.samlib.AuthorTagsActivity.java

/**
 * User pre Ok button//from w  w w.  ja va2 s.  c o  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.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));
            }/*  w ww  .java2s . c om*/
        }
    }
    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: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 ww w  . ja v a2s. c o m*/
        }
    }
    //if no tracks are selected, return all
    if (tracks.size() == 0)
        tracks = mTracklist;
    return tracks;
}

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

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.delete: {
        final SharedPreferences.Editor editor = mHostMapping.edit();
        final SparseBooleanArray array = mListView.getCheckedItemPositions();
        if (array == null)
            return false;
        for (int i = 0, size = array.size(); i < size; i++) {
            if (array.valueAt(i)) {
                editor.remove(mAdapter.getItem(i));
            }/*from   w w w  .ja  va2s  . co  m*/
        }
        editor.apply();
        reloadHostMappings();
        break;
    }
    default: {
        return false;
    }
    }
    mode.finish();
    return true;
}

From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java

private void deleteItems(SparseBooleanArray positions) {

    SparseBooleanArray chkItems = positions;
    //ArrayList<Game> selItems = new ArrayList<Game>();
    ArrayList<Long> selItems = new ArrayList<Long>();
    for (int i = 0; i < chkItems.size(); i++) {
        int position = chkItems.keyAt(i);
        if (chkItems.valueAt(i)) {
            selItems.add(adapter.getItem(position).getId());
        }//from  www. ja  v a2  s  .  c om
    }
    DeleteGameTask task = new DeleteGameTask();
    Long[] longs = new Long[selItems.size()];
    longs = selItems.toArray(longs);
    task.execute(longs);

    /*
            for(Game g:selItems) {
    dataSource.deleteGame(g);
    mListener.onMultipleItemsDeletion();
    //dataSource.deleteSchedule(context, s);
    //updateDB();
            }*/
}

From source file:co.juliansuarez.libwizardpager.wizard.ui.MultipleChoiceFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    ArrayList<String> selections = new ArrayList<String>();
    ArrayList<Choice> choices = new ArrayList<Choice>();

    Boolean skipNextPage = false;
    for (int i = 0; i < checkedPositions.size(); i++) {
        if (checkedPositions.valueAt(i)) {
            String item = getListAdapter().getItem(checkedPositions.keyAt(i)).toString();
            selections.add(item);/*from  w ww  .  ja  v  a  2  s  .  co  m*/

            Choice c = mPage.getChoice(item);
            choices.add(c);

            if (c.skipNextPage()) {
                skipNextPage = true;
            }
        }
    }
    mPage.getData().putBoolean(Page.SKIP_NEXT_PAGE, skipNextPage);
    mPage.getData().putParcelableArrayList(Page.CHOICE_DATA_KEY, choices);
    mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections);
    mPage.notifyDataChanged();
}

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   w  w  w .  j ava 2  s  .  c o  m
    }
    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: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));
        }//www.  java 2  s.  c  o m
    }

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