Example usage for android.util SparseBooleanArray size

List of usage examples for android.util SparseBooleanArray size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of key-value mappings that this SparseBooleanArray currently stores.

Usage

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));
            }// ww w.j a  v a  2 s .  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.vmihalachi.turboeditor.fragment.NavigationDrawerListFragment.java

/**
 * {@inheritDoc}//from   w ww . j  ava  2 s  . c  om
 */
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.im_remove:
        // File paths saved in preferences
        String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
        // We get the checked positions
        SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
        // If we have some checked positions
        if (checkedItems != null) {
            for (int i = 0; i < checkedItems.size(); i++) {
                // check if the value is checked
                if (checkedItems.valueAt(i)) {
                    // remove the checked path, but don't refresh the list
                    removePath(savedPaths[checkedItems.keyAt(i)], false);
                }
            }
            // In the end refresh the list
            refreshList();
        }
        // Close the action mode
        actionMode.finish();
        return true;
    default:
        return false;
    }
}

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)));
    }/*from w w  w  .  j  a  v  a  2  s.  co  m*/

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

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

/**
 * User pre Ok button//  w  w w  .j  a va2s. c  om
 *
 * @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. j  a v a  2s  .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: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 a2 s  .  c  o  m
        }
    }
    //if no tracks are selected, return all
    if (tracks.size() == 0)
        tracks = mTracklist;
    return tracks;
}

From source file:com.serenegiant.aceparrot.ScriptFragment.java

/**
 * ???//from  w  ww .j  ava2 s.co  m
 * @return
 */
private ScriptHelper.ScriptRec[] getSelectedScripts() {
    ScriptHelper.ScriptRec[] result = null;
    if (mScriptListView != null) {
        final SparseBooleanArray ids = mScriptListView.getCheckedItemPositions();
        final int n = ids != null ? ids.size() : 0;
        if (n > 0) {
            final List<ScriptHelper.ScriptRec> list = new ArrayList<ScriptHelper.ScriptRec>();
            for (int i = 0; i < n; i++) {
                if (ids.valueAt(i)) {
                    final Object obj = mScriptListView.getItemAtPosition(ids.keyAt(i));
                    if (obj instanceof ScriptHelper.ScriptRec) {
                        list.add((ScriptHelper.ScriptRec) obj);
                    }
                }
            }
            final int m = list.size();
            if (m > 0) {
                result = new ScriptHelper.ScriptRec[m];
                list.toArray(result);
            }
        }
    }
    return result;
}

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));
            }//  www.  j a v  a2s .c  o m
        }
        editor.apply();
        reloadHostMappings();
        break;
    }
    default: {
        return false;
    }
    }
    mode.finish();
    return true;
}

From source file:org.creativecommons.thelist.activities.CategoryListActivity.java

public void saveUserCategories() {
    SparseBooleanArray positions = mGridView.getCheckedItemPositions();
    int length = positions.size();
    //Array of user selected categories
    List<Integer> userCategories = new ArrayList<>();

    for (int i = 0; i < length; i++) {
        int itemPosition = positions.keyAt(i);
        boolean value = positions.get(itemPosition);

        if (value) {
            CategoryListItem catItem = (CategoryListItem) mGridView.getItemAtPosition(itemPosition);
            int catId = catItem.getCategoryID();
            userCategories.add(catId);//from  ww w .ja  va 2 s  .c o m
            Log.v(TAG, "ITEM ADDED");
        }
    }

    Intent intent;

    if (mCurrentUser.isTempUser()) { //TEMP USER
        //Save user categories to shared preferences
        mSharedPref.saveSharedPreference(SharedPreferencesMethods.CATEGORY_PREFERENCE_KEY,
                userCategories.toString());

        if (mSharedPref.getUserItemCount() == 0) {
            intent = new Intent(CategoryListActivity.this, RandomActivity.class);
            startActivity(intent);
        } else {
            intent = new Intent(CategoryListActivity.this, DrawerActivity.class);
            startActivity(intent);
        }
    } else {
        intent = new Intent(CategoryListActivity.this, DrawerActivity.class);
        startActivity(intent);
    }
}

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