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:org.gnucash.android.ui.export.ScheduledExportListFragment.java

/**
 * Unchecks all the checked items in the list
 *//*  w  w  w . j  a  v  a 2 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: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  a  v  a2  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:org.flerda.android.honeypad.NoteListFragment.java

public int getCheckedItemCount() {
    if (mIsV11) {
        return mLV.getCheckedItemCount();
    } else {/* w  w w . j  av a2  s . c  om*/
        /** 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));
        }/* ww  w.  ja  va  2s  . 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();
}

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

private int countSelected() {

    int count = 0;
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    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)) {
                count++;/*from  w w  w  . j  a v  a  2  s. c om*/
            }
        }
    }
    return count;
}

From source file:com.bitants.wally.fragments.SavedImagesFragment.java

@Override
public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
    if (R.id.menu_delete == item.getItemId()) {

        int size = 0;

        SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems();
        for (int i = 0; i < checkedItems.size(); i++) {
            if (checkedItems.valueAt(i)) {
                size++;/*from w  w  w.  j a  v a2  s .co  m*/
            }
        }

        String quantityString = getResources().getQuantityString(R.plurals.wallpapers, size);
        String title = String.format(getString(R.string.dialog_delete_title), quantityString);

        FragmentManager fragmentManager = getFragmentManager();

        if (fragmentManager != null) {
            final MaterialDialogFragment materialDialogFragment = new MaterialDialogFragment();
            materialDialogFragment.setPrimaryColor(getResources().getColor(R.color.Dialog_Button_Delete));
            materialDialogFragment.setTitle(title);
            materialDialogFragment.setPositiveButton(R.string.dialog_delete_positive,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems();
                            for (int index = 0; index < checkedItems.size(); index++) {
                                if (checkedItems.valueAt(index)) {
                                    Uri contentUri = recyclerSavedImagesAdapter
                                            .getItem(checkedItems.keyAt(index));
                                    getActivity().getContentResolver().delete(contentUri, null, null);
                                }
                            }
                            mode.finish();
                            getImages(0, null);
                            getActivity().sendBroadcast(new Intent(FileReceiver.GET_FILES));
                        }
                    });
            materialDialogFragment.setNegativeButton(R.string.dialog_delete_negative,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            materialDialogFragment.dismiss();
                        }
                    });
            materialDialogFragment.show(fragmentManager, MaterialDialogFragment.TAG);
        }

    }
    return false;
}

From source file:com.musenkishi.wally.fragments.SavedImagesFragment.java

@Override
public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
    if (R.id.menu_delete == item.getItemId()) {

        int size = 0;

        SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems();
        for (int i = 0; i < checkedItems.size(); i++) {
            if (checkedItems.valueAt(i)) {
                size++;//from   w  w w . j a v a2  s .c  o m
            }
        }

        String quantityString = getResources().getQuantityString(R.plurals.wallpapers, size);
        String title = String.format(getString(R.string.dialog_delete_title), quantityString);

        FragmentManager fragmentManager = getFragmentManager();

        if (fragmentManager != null) {
            final MaterialDialogFragment materialDialogFragment = new MaterialDialogFragment();
            materialDialogFragment.setPrimaryColor(getResources().getColor(R.color.Dialog_Button_Delete));
            materialDialogFragment.setTitle(title);
            materialDialogFragment.setPositiveButton(R.string.dialog_delete_positive,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems();
                            for (int index = 0; index < checkedItems.size(); index++) {
                                if (checkedItems.valueAt(index)) {
                                    Uri contentUri = recyclerSavedImagesAdapter
                                            .getItem(checkedItems.keyAt(index));
                                    getActivity().getContentResolver().delete(contentUri, null, null);
                                }
                            }
                            mode.finish();
                            getImages(0, null);
                            getActivity().sendBroadcast(new Intent(FileChangeReceiver.FILES_CHANGED));
                        }
                    });
            materialDialogFragment.setNegativeButton(R.string.dialog_delete_negative,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            materialDialogFragment.dismiss();
                        }
                    });
            materialDialogFragment.show(fragmentManager, MaterialDialogFragment.TAG);
        }

    }
    return false;
}

From source file:org.ymegane.android.approom.AppDisplayFragment.java

private void updateMultipleChoiceState(int position) {
    adapter.toggleCheckState(position);/* w w  w.  ja  v  a 2  s  .  c  om*/
    adapter.notifyDataSetChanged();
    if (adapter.getCheckedStates().size() <= 0) {
        actionMode.finish();
        return;
    }
    SparseBooleanArray checkedItems = adapter.getCheckedStates();

    actionMode.setSubtitle(getString(R.string.action_mode_subtitle_share, checkedItems.size()));

    StringBuilder appListStr = new StringBuilder();
    for (int idx = 0; idx < checkedItems.size(); idx++) {
        int pos = checkedItems.keyAt(idx);
        AppInfo appInfo = (AppInfo) gridAppView.getItemAtPosition(pos);
        appListStr.append(appInfo.appName).append(":").append(AppLinkBase.LINK_HTTP_DETAIL)
                .append(appInfo.packageName).append("\n\n");
    }

    shareActionProvider.setShareIntent(CommonUtil.createShareIntent(appListStr.toString()));
}

From source file:com.sakisds.icymonitor.activities.ConnectionActivity.java

private void deleteSelectedItems(final SparseBooleanArray checked) {
    String message = getResources().getQuantityString(R.plurals.deleteComputers, checked.size());

    new AlertDialog.Builder(this).setMessage(message).setCancelable(false)
            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ListView listView = getListView();

                    int cntChoice = listView.getCount();

                    int removedCount = 0;

                    for (int i = 0; i < cntChoice; i++) {
                        if (checked.get(i)) {
                            mData[i].setToBeRemoved();
                            removedCount++;
                        }//w ww  . ja  va  2s .  c  om
                    }

                    List resultData = new LinkedList();
                    for (ComputerInfo comp : mData) {
                        if (!comp.isToBeRemoved()) {
                            //noinspection unchecked
                            resultData.add(comp);
                        }
                    }

                    int newLen = mData.length - removedCount;

                    SharedPreferences.Editor editor = mSettings.edit();
                    editor.putInt("serverCount", newLen);

                    ComputerInfo[] names = (ComputerInfo[]) resultData.toArray(mData);

                    // Save to settings
                    for (int i = 0; i < newLen; i++) {
                        editor.putString("server_" + String.valueOf(i) + "_name", names[i].getName());
                        editor.putString("server_" + String.valueOf(i) + "_address", names[i].getAddress());
                        editor.putInt("server_" + String.valueOf(i) + "_type", names[i].getType());
                    }
                    editor.commit();

                    refreshListAdapter();
                }
            }).setNegativeButton(R.string.no, null).show();
}

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++;/*www . ja  va 2s . com*/
            }
        }
    }
    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();

}