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:com.aimfire.gallery.ThumbsFragment.java

/**
 * delete current file/*from ww w. j av a  2 s  .c  o  m*/
 */
private void deleteFiles() {
    final SparseBooleanArray checkedItems = mGridView.getCheckedItemPositions();

    ArrayList<File> mediaFiles = new ArrayList<File>();
    for (int i = 0; i < checkedItems.size(); i++) {
        final boolean isChecked = checkedItems.valueAt(i);
        if (isChecked) {
            int position = checkedItems.keyAt(i);
            File file = new File(mMediaList.get(position));
            if (file.exists()) {
                mediaFiles.add(file);
            }
        }
    }
    final ArrayList<File> mediaFilesToDelete = mediaFiles;

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity(),
            R.style.AppCompatAlertDialogStyle);
    alertDialogBuilder.setTitle(R.string.delete);
    alertDialogBuilder.setMessage(mediaFilesToDelete.size() + " " + getString(R.string.warning_items_delete));

    alertDialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            /*
             * delete sbs/cvr, thumbnail, preview and exported files
             */
            for (File mediaFile : mediaFilesToDelete) {
                String mediaFilePath = mediaFile.getAbsolutePath();
                MediaScanner.deleteFile(mediaFilePath);
            }
            updateGridView(null, mGridView.getFirstVisiblePosition());
        }
    });

    alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //do nothing
        }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override// w w w. ja va 2s .co  m
protected void configureMenu11(Menu menu, int count, AbsListView lv) {
    super.configureMenu11(menu, count, lv);
    SparseBooleanArray checkedItemPositions = lv.getCheckedItemPositions();
    boolean hasSplit = false, hasNotVoid = false;
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i) && isSplitAtPosition(checkedItemPositions.keyAt(i))) {
            hasSplit = true;
            break;
        }
    }
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i) && isVoidAtPosition(checkedItemPositions.keyAt(i))) {
            hasNotVoid = true;
            break;
        }
    }
    configureMenuInternal(menu, hasSplit, hasNotVoid, count);
}

From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java

@Override
@Implemented(FabLayout.OnClickFabListener.class)
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
    Context context = getContext2();
    if (null == context || null == mRecyclerView || null == mHelper || !mRecyclerView.isInCustomChoice()) {
        return;/*from  w ww .  j a v a 2 s. co m*/
    }

    mModifyGiList.clear();
    SparseBooleanArray stateArray = mRecyclerView.getCheckedItemPositions();
    for (int i = 0, n = stateArray.size(); i < n; i++) {
        if (stateArray.valueAt(i)) {
            mModifyGiList.add(mHelper.getDataAt(stateArray.keyAt(i)));
        }
    }

    switch (position) {
    case 0: { // Delete
        DeleteDialogHelper helper = new DeleteDialogHelper();
        new AlertDialog.Builder(context).setTitle(R.string.delete_favorites_dialog_title)
                .setMessage(getString(R.string.delete_favorites_dialog_message, mModifyGiList.size()))
                .setPositiveButton(android.R.string.ok, helper).setOnCancelListener(helper).show();
        break;
    }
    case 1: { // Move
        MoveDialogHelper helper = new MoveDialogHelper();
        // First is local favorite, the other 10 is cloud favorite
        String[] array = new String[11];
        array[0] = getString(R.string.local_favorites);
        System.arraycopy(Settings.getFavCat(), 0, array, 1, 10);
        new AlertDialog.Builder(context).setTitle(R.string.move_favorites_dialog_title).setItems(array, helper)
                .setOnCancelListener(helper).show();
        break;
    }
    }
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

@AfterViews
void setUpChart() {
    auditChartPager.setAdapter(chartPagerAdapter);
    auditChartChoices.setAdapter(chartChoicesAdapter);

    auditChartChoices.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    checkUniqueChoice(0);/*ww w .  j a  va  2s.  c o  m*/

    auditChartPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            checkUniqueChoice(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    auditChartChoices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // Case of Total
            if (position == 0) {
                chartPagerAdapter.setCustomStat(null);
                auditChartPager.setCurrentItem(0, true);

                checkUniqueChoice(0);
                return;
            }

            final SparseBooleanArray checkedItemPositions = auditChartChoices.getCheckedItemPositions();

            List<Integer> selectedItems = new ArrayList<Integer>();
            for (int i = 0; i < checkedItemPositions.size(); i++) {
                // Item position in adapter
                int pos = checkedItemPositions.keyAt(i);

                if (pos != 0 && checkedItemPositions.valueAt(i)) {
                    selectedItems.add(pos);
                }
            }

            if (selectedItems.isEmpty()) {
                selectedItems.add(0);
            }

            // One choice checked (other than total)
            if (selectedItems.size() == 1) {
                int pos = selectedItems.get(0);

                chartPagerAdapter.setCustomStat(null);
                auditChartPager.setCurrentItem(pos, true);
            } else {
                // Multiple choices, build custom stats
                AccessibilityStats custom = new AccessibilityStats();

                for (int i : selectedItems) {
                    custom.plus(handicapAggregator.getStat(i - 1));
                }

                chartPagerAdapter.setCustomStat(custom);
                auditChartPager.setCurrentItem(0, true);

                auditChartChoices.clearChoices();
                for (int i : selectedItems) {
                    auditChartChoices.setItemChecked(i, true);
                }
            }
        }
    });
}

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

@Override
public boolean dispatchCommandMultiple(int command, SparseBooleanArray positions, Long[] itemIds) {
    MyExpenses ctx = (MyExpenses) getActivity();
    FragmentManager fm = ctx.getSupportFragmentManager();
    switch (command) {
    case R.id.DELETE_COMMAND:
        boolean hasReconciled = false, hasNotVoid = false;
        for (int i = 0; i < positions.size(); i++) {
            if (positions.valueAt(i)) {
                mTransactionsCursor.moveToPosition(positions.keyAt(i));
                CrStatus status;/*from   w ww . j av a 2 s  . co m*/
                try {
                    status = CrStatus.valueOf(mTransactionsCursor.getString(columnIndexCrStatus));
                } catch (IllegalArgumentException ex) {
                    status = CrStatus.UNRECONCILED;
                }
                if (status == CrStatus.RECONCILED) {
                    hasReconciled = true;
                }
                if (status != CrStatus.VOID) {
                    hasNotVoid = true;
                }
                if (hasNotVoid && hasReconciled)
                    break;
            }
        }
        String message = getResources().getQuantityString(R.plurals.warning_delete_transaction, itemIds.length,
                itemIds.length);
        if (hasReconciled) {
            message += " " + getString(R.string.warning_delete_reconciled);
        }
        Bundle b = new Bundle();
        b.putInt(ConfirmationDialogFragment.KEY_TITLE, R.string.dialog_title_warning_delete_transaction);
        b.putString(ConfirmationDialogFragment.KEY_MESSAGE, message);
        b.putInt(ConfirmationDialogFragment.KEY_COMMAND_POSITIVE, R.id.DELETE_COMMAND_DO);
        b.putInt(ConfirmationDialogFragment.KEY_COMMAND_NEGATIVE, R.id.CANCEL_CALLBACK_COMMAND);
        b.putInt(ConfirmationDialogFragment.KEY_POSITIVE_BUTTON_LABEL, R.string.menu_delete);
        if (hasNotVoid) {
            b.putInt(ConfirmationDialogFragment.KEY_CHECKBOX_LABEL, R.string.mark_void_instead_of_delete);
        }
        b.putLongArray(TaskExecutionFragment.KEY_OBJECT_IDS, ArrayUtils.toPrimitive(itemIds));
        ConfirmationDialogFragment.newInstance(b).show(getFragmentManager(), "DELETE_TRANSACTION");
        return true;
    /*    case R.id.CLONE_TRANSACTION_COMMAND:
          ctx.startTaskExecution(
              TaskExecutionFragment.TASK_CLONE,
              itemIds,
              null,
              0);
          break;*/
    case R.id.SPLIT_TRANSACTION_COMMAND:
        ctx.contribFeatureRequested(ContribFeature.SPLIT_TRANSACTION, itemIds);
        break;
    case R.id.UNDELETE_COMMAND:
        ctx.startTaskExecution(TaskExecutionFragment.TASK_UNDELETE_TRANSACTION, itemIds, null, 0);
        break;
    //super is handling deactivation of mActionMode
    }
    return super.dispatchCommandMultiple(command, positions, itemIds);
}

From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java

@Override
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
    Context context = getContext2();
    Activity activity = getActivity2();//ww  w  . j  a  v a  2s  .c o m
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == context || null == activity || null == recyclerView) {
        return;
    }

    if (0 == position) {
        recyclerView.checkAll();
    } else {
        List<DownloadInfo> list = mList;
        if (list == null) {
            return;
        }

        LongList gidList = null;
        List<DownloadInfo> downloadInfoList = null;
        boolean collectGid = position == 1 || position == 2 || position == 3; // Start, Stop, Delete
        boolean collectDownloadInfo = position == 3 || position == 4; // Delete or Move
        if (collectGid) {
            gidList = new LongList();
        }
        if (collectDownloadInfo) {
            downloadInfoList = new LinkedList<>();
        }

        SparseBooleanArray stateArray = recyclerView.getCheckedItemPositions();
        for (int i = 0, n = stateArray.size(); i < n; i++) {
            if (stateArray.valueAt(i)) {
                DownloadInfo info = list.get(stateArray.keyAt(i));
                if (collectDownloadInfo) {
                    downloadInfoList.add(info);
                }
                if (collectGid) {
                    gidList.add(info.gid);
                }
            }
        }

        switch (position) {
        case 1: { // Start
            Intent intent = new Intent(activity, DownloadService.class);
            intent.setAction(DownloadService.ACTION_START_RANGE);
            intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
            activity.startService(intent);
            // Cancel check mode
            recyclerView.outOfCustomChoiceMode();
            break;
        }
        case 2: { // Stop
            if (null != mDownloadManager) {
                mDownloadManager.stopRangeDownload(gidList);
            }
            // Cancel check mode
            recyclerView.outOfCustomChoiceMode();
            break;
        }
        case 3: { // Delete
            CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context,
                    getString(R.string.download_remove_dialog_message_2, gidList.size()),
                    getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles());
            DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(downloadInfoList, gidList, builder);
            builder.setTitle(R.string.download_remove_dialog_title)
                    .setPositiveButton(android.R.string.ok, helper).show();
            break;
        }
        case 4: {// Move
            List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList();
            List<String> labelList = new ArrayList<>(labelRawList.size() + 1);
            labelList.add(getString(R.string.default_download_label_name));
            for (int i = 0, n = labelRawList.size(); i < n; i++) {
                labelList.add(labelRawList.get(i).getLabel());
            }
            String[] labels = labelList.toArray(new String[labelList.size()]);

            MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);

            new AlertDialog.Builder(context).setTitle(R.string.download_move_dialog_title)
                    .setItems(labels, helper).show();
            break;
        }
        }
    }
}

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

@Override
protected void configureMenu11(Menu menu, int count, AbsListView lv) {
    super.configureMenu11(menu, count, lv);
    if (expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        boolean hasChildren = false;
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i)) {
                int position = checkedItemPositions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int groupPos = ExpandableListView.getPackedPositionGroup(pos);
                if (hasChildren(groupPos)) {
                    hasChildren = true;/*from   ww w  .j  a  v a2 s .co  m*/
                    break;
                }
            }
        }
        configureMenuInternal(menu, hasChildren);
    }
}

From source file:com.todotxt.todotxttouch.TodoTxtTouch.java

private ArrayList<Task> getCheckedTasks() {
    ArrayList<Task> result = new ArrayList<Task>();
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();

    for (int i = 0; i < checkedItems.size(); i++) {
        if (checkedItems.valueAt(i)) {
            result.add(m_adapter.getItem(checkedItems.keyAt(i)));
        }/*from   w  ww.j  a  v  a  2  s . co  m*/
    }

    return result;
}

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

@Override
public boolean dispatchCommandMultiple(int command, SparseBooleanArray positions, Long[] itemIds) {
    ManageCategories ctx = (ManageCategories) getActivity();
    ArrayList<Long> idList;
    switch (command) {
    case R.id.DELETE_COMMAND:
        int mappedTransactionsCount = 0, mappedTemplatesCount = 0, hasChildrenCount = 0;
        idList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            Cursor c;/*from ww  w.  j av a  2s. com*/
            if (positions.valueAt(i)) {
                boolean deletable = true;
                int position = positions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int type = ExpandableListView.getPackedPositionType(pos);
                int group = ExpandableListView.getPackedPositionGroup(pos),
                        child = ExpandableListView.getPackedPositionChild(pos);
                if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                    c = mAdapter.getChild(group, child);
                    c.moveToPosition(child);
                } else {
                    c = mGroupCursor;
                    c.moveToPosition(group);
                }
                long itemId = c.getLong(c.getColumnIndex(KEY_ROWID));
                Bundle extras = ctx.getIntent().getExtras();
                if ((extras != null && extras.getLong(KEY_ROWID) == itemId)
                        || c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TRANSACTIONS)) > 0) {
                    mappedTransactionsCount++;
                    deletable = false;
                } else if (c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TEMPLATES)) > 0) {
                    mappedTemplatesCount++;
                    deletable = false;
                }
                if (deletable) {
                    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP
                            && c.getInt(c.getColumnIndex(KEY_CHILD_COUNT)) > 0) {
                        hasChildrenCount++;
                    }
                    idList.add(itemId);
                }
            }
        }
        if (!idList.isEmpty()) {
            Long[] objectIds = idList.toArray(new Long[idList.size()]);
            if (hasChildrenCount > 0) {
                MessageDialogFragment
                        .newInstance(R.string.dialog_title_warning_delete_main_category,
                                getResources().getQuantityString(R.plurals.warning_delete_main_category,
                                        hasChildrenCount, hasChildrenCount),
                                new MessageDialogFragment.Button(android.R.string.yes, R.id.DELETE_COMMAND_DO,
                                        objectIds),
                                null,
                                new MessageDialogFragment.Button(android.R.string.no,
                                        R.id.CANCEL_CALLBACK_COMMAND, null))
                        .show(ctx.getSupportFragmentManager(), "DELETE_CATEGORY");
            } else {
                ctx.dispatchCommand(R.id.DELETE_COMMAND_DO, objectIds);
            }
        }
        if (mappedTransactionsCount > 0 || mappedTemplatesCount > 0) {
            String message = "";
            if (mappedTransactionsCount > 0)
                message += getResources().getQuantityString(R.plurals.not_deletable_mapped_transactions,
                        mappedTransactionsCount, mappedTransactionsCount);
            if (mappedTemplatesCount > 0)
                message += getResources().getQuantityString(R.plurals.not_deletable_mapped_templates,
                        mappedTemplatesCount, mappedTemplatesCount);
            Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.SELECT_COMMAND_MULTIPLE:
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            Cursor c;
            if (positions.valueAt(i)) {
                int position = positions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int type = ExpandableListView.getPackedPositionType(pos);
                int group = ExpandableListView.getPackedPositionGroup(pos),
                        child = ExpandableListView.getPackedPositionChild(pos);
                if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                    c = mAdapter.getChild(group, child);
                    c.moveToPosition(child);
                } else {
                    c = mGroupCursor;
                    c.moveToPosition(group);
                }
                labelList.add(c.getString(c.getColumnIndex(KEY_LABEL)));
            }
        }
        Intent intent = new Intent();
        intent.putExtra(KEY_CATID, ArrayUtils.toPrimitive(itemIds));
        intent.putExtra(KEY_LABEL, TextUtils.join(",", labelList));
        ctx.setResult(ManageCategories.RESULT_FIRST_USER, intent);
        ctx.finish();
        return true;
    case R.id.MOVE_COMMAND:
        final Long[] excludedIds;
        final boolean inGroup = expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP;
        if (inGroup) {
            excludedIds = itemIds;
        } else {
            idList = new ArrayList<>();
            for (int i = 0; i < positions.size(); i++) {
                if (positions.valueAt(i)) {
                    int position = positions.keyAt(i);
                    long pos = mListView.getExpandableListPosition(position);
                    int group = ExpandableListView.getPackedPositionGroup(pos);
                    mGroupCursor.moveToPosition(group);
                    idList.add(mGroupCursor.getLong(mGroupCursor.getColumnIndex(KEY_ROWID)));
                }
            }
            excludedIds = idList.toArray(new Long[idList.size()]);
        }
        Bundle args = new Bundle(3);
        args.putBoolean(SelectMainCategoryDialogFragment.KEY_WITH_ROOT, !inGroup);
        args.putLongArray(SelectMainCategoryDialogFragment.KEY_EXCLUDED_ID,
                ArrayUtils.toPrimitive(excludedIds));
        args.putLongArray(TaskExecutionFragment.KEY_OBJECT_IDS, ArrayUtils.toPrimitive(itemIds));
        SelectMainCategoryDialogFragment.newInstance(args).show(getFragmentManager(), "SELECT_TARGET");
        return true;
    }
    return false;
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

@NotNull
private List<Task> getCheckedTasks() {
    ArrayList<Task> checkedTasks = new ArrayList<Task>();
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
    if (checkedItems == null) {
        return checkedTasks;
    }/*w ww  .  jav a  2  s .c  o m*/
    for (int i = 0; i < checkedItems.size(); i++) {
        if (checkedItems.valueAt(i)) {
            Task t = getTaskAt(checkedItems.keyAt(i));
            // Ignore headers
            if (t != null) {
                checkedTasks.add(getTaskAt(checkedItems.keyAt(i)));
            }
        }
    }
    return checkedTasks;
}