Java 类android.util.SparseBooleanArray 实例源码

项目:ultrasonic    文件:DragSortListView.java   
/**
 * Use this when an item has been deleted, to move the check state of all
 * following items up one step. If you have a choiceMode which is not none,
 * this method must be called when the order of items changes in an
 * underlying adapter which does not have stable IDs (see
 * {@link ListAdapter#hasStableIds()}). This is because without IDs, the
 * ListView has no way of knowing which items have moved where, and cannot
 * update the check state accordingly.
 * 
 * See also further comments on {@link #moveCheckState(int, int)}.
 * 
 * @param position
 */
public void removeCheckState(int position) {
    SparseBooleanArray cip = getCheckedItemPositions();

    if (cip.size() == 0)
        return;
    int[] runStart = new int[cip.size()];
    int[] runEnd = new int[cip.size()];
    int rangeStart = position;
    int rangeEnd = cip.keyAt(cip.size() - 1) + 1;
    int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd);
    for (int i = 0; i != runCount; i++) {
        if (!(runStart[i] == position || (runEnd[i] < runStart[i] && runEnd[i] > position))) {
            // Only set a new check mark in front of this run if it does
            // not contain the deleted position. If it does, we only need
            // to make it one check mark shorter at the end.
            setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true);
        }
        setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false);
    }
}
项目:godlibrary    文件:ExpandableListViewCheckAdapter.java   
public ArrayMap<Integer, long[]> getIds() {
    ArrayMap<Integer, long[]> arrayMap = new ArrayMap<>();
    if (choiceMode == ListView.CHOICE_MODE_MULTIPLE) {
        for (Map.Entry<Integer, SparseBooleanArray> entry : multipleIds.entrySet()) {
            List<Integer> l = new ArrayList<>();
            SparseBooleanArray ids = entry.getValue();
            for (int i = 0; i < ids.size(); i++) {
                if (ids.valueAt(i)) {
                    l.add(ids.keyAt(i));
                }
            }
            long[] _ids = new long[l.size()];
            for (int i = 0; i < l.size(); i++) {
                _ids[i] = l.get(i);
            }
            arrayMap.put(entry.getKey(), _ids);
        }
    }
    return arrayMap;
}
项目:ExoPlayer-Offline    文件:FakeExtractorInput.java   
private boolean checkXFully(boolean allowEndOfInput, int position, int length,
    SparseBooleanArray failedPositions) throws IOException {
  if (simulateIOErrors && !failedPositions.get(position)) {
    failedPositions.put(position, true);
    peekPosition = readPosition;
    throw new SimulatedIOException("Simulated IO error at position: " + position);
  }
  if (length > 0 && position == data.length) {
    if (allowEndOfInput) {
      return false;
    }
    throw new EOFException();
  }
  if (position + length > data.length) {
    throw new EOFException("Attempted to move past end of data: (" + position + " + "
        + length + ") > " + data.length);
  }
  return true;
}
项目:easyfilemanager    文件:MultiSelectionUtil.java   
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    mListener.onDestroyActionMode(actionMode);
    // Clear all the checked items
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (checkedPositions != null) {
        for (int i = 0; i < checkedPositions.size(); i++) {
            mListView.setItemChecked(checkedPositions.keyAt(i), false);
        }
    }
    // Restore the original onItemClickListener
    mListView.setOnItemClickListener(mOldItemClickListener);
    // Clear the Action Mode
    mActionMode = null;
    // Reset the ListView's Choice Mode
    mListView.post(mSetChoiceModeNoneRunnable);
}
项目:easyfilemanager    文件:MultiSelectionUtil.java   
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    // Check to see what the new checked state is, and then notify the listener
    final boolean checked = mListView.isItemChecked(position);
    mListener.onItemCheckedStateChanged(mActionMode, position, id, checked);
    boolean hasCheckedItem = checked;
    // Check to see if we have any checked items
    if (!hasCheckedItem) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        if (checkedItemPositions != null) {
            // Iterate through the SparseBooleanArray to see if there is a checked item
            int i = 0;
            while (!hasCheckedItem && i < checkedItemPositions.size()) {
                hasCheckedItem = checkedItemPositions.valueAt(i++);
            }
        }
    }
    // If we don't have any checked items, finish the action mode
    if (!hasCheckedItem) {
        mActionMode.finish();
    }
}
项目:NoticeDog    文件:DragSortListView.java   
/**
 * Use this when an item has been deleted, to move the check state of all
 * following items up one step. If you have a choiceMode which is not none,
 * this method must be called when the order of items changes in an
 * underlying adapter which does not have stable IDs (see
 * {@link ListAdapter#hasStableIds()}). This is because without IDs, the
 * ListView has no way of knowing which items have moved where, and cannot
 * update the check state accordingly.
 * <p>
 * See also further comments on {@link #moveCheckState(int, int)}.
 *
 * @param position
 */
public void removeCheckState(int position) {
    SparseBooleanArray cip = getCheckedItemPositions();

    if (cip.size() == 0)
        return;
    int[] runStart = new int[cip.size()];
    int[] runEnd = new int[cip.size()];
    int rangeStart = position;
    int rangeEnd = cip.keyAt(cip.size() - 1) + 1;
    int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd);
    for (int i = 0; i != runCount; i++) {
        if (!(runStart[i] == position || (runEnd[i] < runStart[i] && runEnd[i] > position))) {
            // Only set a new check mark in front of this run if it does
            // not contain the deleted position. If it does, we only need
            // to make it one check mark shorter at the end.
            setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true);
        }
        setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false);
    }
}
项目:TripleTap    文件:GameFragment.java   
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // Get the SetGame
    SetGame game = mActionsListener.getSetGame();

    SparseBooleanArray checkedItemPositions = getCheckedItemPositions();
    int positionIndex = 0;
    // Loop through SparseBooleanArray and grab the positions that are checked
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i)) {
            mCheckedPositions[positionIndex] = checkedItemPositions.keyAt(i);
            positionIndex++;
        }
    }

    // Bundle objects
    outState.putParcelable(getString(R.string.bundle_key_game), Parcels.wrap(game));
    outState.putIntArray(getString(R.string.bundle_key_checked_positions), mCheckedPositions);
    outState.putInt(getString(R.string.bundle_key_checked_count), mCheckedCount);
}
项目:multi-copy    文件:NotesFragment.java   
public void deleteRows(){
        //get Selected items
        SparseBooleanArray selected = notesAdapter.getmSelectedItems();

        //loop through selected items
        for (int i = (selected.size()-1) ;i >=0 ; i--){
            if (selected.valueAt(i)){
                //If the current id is selected remove the item via key
                deleteFromNoteRealm(selected.keyAt(i));
                notesAdapter.notifyDataSetChanged();
             }
        }

//        Toast.makeText(getContext(), selected.size() + " items deleted", Toast.LENGTH_SHORT).show();
        Snackbar snackbar = Snackbar.make(recyclerView,selected.size() + " Notes deleted",Snackbar.LENGTH_SHORT);
        snackbar.show();
        actionMode.finish();

    }
项目:FireFiles    文件:MultiSelectionUtil.java   
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    mListener.onDestroyActionMode(actionMode);
    // Clear all the checked items
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (checkedPositions != null) {
        for (int i = 0; i < checkedPositions.size(); i++) {
            mListView.setItemChecked(checkedPositions.keyAt(i), false);
        }
    }
    // Restore the original onItemClickListener
    mListView.setOnItemClickListener(mOldItemClickListener);
    // Clear the Action Mode
    mActionMode = null;
    // Reset the ListView's Choice Mode
    mListView.post(mSetChoiceModeNoneRunnable);
}
项目:FireFiles    文件:MultiSelectionUtil.java   
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    // Check to see what the new checked state is, and then notify the listener
    final boolean checked = mListView.isItemChecked(position);
    mListener.onItemCheckedStateChanged(mActionMode, position, id, checked);
    boolean hasCheckedItem = checked;
    // Check to see if we have any checked items
    if (!hasCheckedItem) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        if (checkedItemPositions != null) {
            // Iterate through the SparseBooleanArray to see if there is a checked item
            int i = 0;
            while (!hasCheckedItem && i < checkedItemPositions.size()) {
                hasCheckedItem = checkedItemPositions.valueAt(i++);
            }
        }
    }
    // If we don't have any checked items, finish the action mode
    if (!hasCheckedItem) {
        mActionMode.finish();
    }
}
项目:ShangHanLun    文件:ATableView.java   
public NSIndexPath[] getIndexPathsForSelectedRows() {
    NSIndexPath[] indexPaths = null;

    SparseBooleanArray checkedList = getCheckedItemPositions();
    if (checkedList != null) {
        ArrayList<NSIndexPath> indexPathList = new ArrayList<NSIndexPath>();

        ATableViewAdapter adapter = getInternalAdapter();
        for (int i = 0; i < adapter.getCount(); i++) {
            if (checkedList.get(i)) {
                indexPathList.add(adapter.getIndexPath(i));
            }
        }

        indexPaths = indexPathList.toArray(new NSIndexPath[indexPathList
                .size()]);
    }

    return indexPaths;
}
项目:AmenEye    文件:FoldableTextView.java   
/**
 * 初始化属性
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.FoldableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.FoldableTextView_minLines, MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.FoldableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.FoldableTextView_toggleSrcOpen);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.FoldableTextView_toggleSrcClose);

    if (mExpandDrawable == null) {
        mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
    }
    if (mCollapseDrawable == null) {
        mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
    }
    contentTextColor = typedArray.getColor(R.styleable.FoldableTextView_textColors, DEFAULT_TEXT_COLOR);
    contentTextSize = typedArray.getDimension(R.styleable.FoldableTextView_textSize, DEFAULT_TEXT_SIZE);
    collapseExpandTextColor = typedArray.getColor(R.styleable.FoldableTextView_flagColor, DEFAULT_FLAG_COLOR);
    collapseExpandTextSize = typedArray.getDimension(R.styleable.FoldableTextView_flagSize, DEFAULT_TEXT_SIZE);
    gravity = typedArray.getInt(R.styleable.FoldableTextView_flagGravity, DEFAULT_FLAG_GRAVITY);
    typedArray.recycle();
    // default visibility is gone
    setVisibility(GONE);
}
项目:simple-share-android    文件:MultiSelectionUtil.java   
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    mListener.onDestroyActionMode(actionMode);
    // Clear all the checked items
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (checkedPositions != null) {
        for (int i = 0; i < checkedPositions.size(); i++) {
            mListView.setItemChecked(checkedPositions.keyAt(i), false);
        }
    }
    // Restore the original onItemClickListener
    mListView.setOnItemClickListener(mOldItemClickListener);
    // Clear the Action Mode
    mActionMode = null;
    // Reset the ListView's Choice Mode
    mListView.post(mSetChoiceModeNoneRunnable);
}
项目:simple-share-android    文件:MultiSelectionUtil.java   
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    // Check to see what the new checked state is, and then notify the listener
    final boolean checked = mListView.isItemChecked(position);
    mListener.onItemCheckedStateChanged(mActionMode, position, id, checked);
    boolean hasCheckedItem = checked;
    // Check to see if we have any checked items
    if (!hasCheckedItem) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        if (checkedItemPositions != null) {
            // Iterate through the SparseBooleanArray to see if there is a checked item
            int i = 0;
            while (!hasCheckedItem && i < checkedItemPositions.size()) {
                hasCheckedItem = checkedItemPositions.valueAt(i++);
            }
        }
    }
    // If we don't have any checked items, finish the action mode
    if (!hasCheckedItem) {
        mActionMode.finish();
    }
}
项目:Veggietizer    文件:HistoryActivity.java   
/**
 * Deletes the selected meat dish from the DB.
 *
 * @param params Unused.
 * @return Unused.
 */
@Override
protected Void doInBackground(Void... params) {
    SparseBooleanArray checkedEntries = listView.getCheckedItemPositions();
    Adapter adapter = listView.getAdapter();
    List<View> viewsToDelete = new LinkedList<>();
    List<Long> meatDishesToDelete = new LinkedList<>();

    for (int i = 0; i < adapter.getCount(); i++) {
        if (checkedEntries.get(i)) {
            viewsToDelete.add(adapter.getView(i, null, null));
        }
    }

    entriesToDelete = viewsToDelete.size();

    for (View v : viewsToDelete) {
        String meatDishesToDeleteStr = v.findViewById(R.id.imageView_history)
                .getContentDescription().toString();

        meatDishesToDelete.add(Long.valueOf(meatDishesToDeleteStr));
    }

    Model.deleteMeatDishes(getApplicationContext(), meatDishesToDelete);
    return null;
}
项目:android-chessclock    文件:MultiSelectionUtil.java   
public boolean saveInstanceState(Bundle outBundle) {
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (mActionMode != null && checkedPositions != null) {
        ArrayList<Integer> positions = new ArrayList<Integer>();
        for (int i = 0; i < checkedPositions.size(); i++) {
            if (checkedPositions.valueAt(i)) {
                int position = checkedPositions.keyAt(i);
                positions.add(position);
            }
        }

        outBundle.putIntegerArrayList(getStateKey(), positions);
        return true;
    }
    return false;
}
项目:Exoplayer2Radio    文件:TsExtractor.java   
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(@Mode int mode, TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(BUFFER_SIZE);
  tsScratch = new ParsableBitArray(new byte[3]);
  trackIds = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  resetPayloadReaders();
}
项目:lineagex86    文件:ZenModeScheduleDaysSelection.java   
private int[] getDays() {
    final SparseBooleanArray rt = new SparseBooleanArray(mDays.size());
    for (int i = 0; i < mDays.size(); i++) {
        final int day = mDays.keyAt(i);
        if (!mDays.valueAt(i)) continue;
        rt.put(day, true);
    }
    final int[] rta = new int[rt.size()];
    for (int i = 0; i < rta.length; i++) {
        rta[i] = rt.keyAt(i);
    }
    Arrays.sort(rta);
    return rta;
}
项目:GitHub    文件:CustomLayoutManager.java   
public State() {
    itemsFrames = new SparseArray<>();
    itemsAttached = new SparseBooleanArray();
    scrolledX = 0;
    scrolledY = 0;
    contentWidth = 0;
    contentHeight = 0;
    canScrollHorizontal = true;
    canScrollVertical = true;
    itemLineCount = 1;
    totalSpreadCount = 0;
}
项目:codedemos    文件:EmptyUtil.java   
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
项目:ultrasonic    文件:DragSortListView.java   
private static int findFirstSetIndex(SparseBooleanArray sba, int rangeStart, int rangeEnd) {
    int size = sba.size();
    int i = insertionIndexForKey(sba, rangeStart);
    while (i < size && sba.keyAt(i) < rangeEnd && !sba.valueAt(i))
        i++;
    if (i == size || sba.keyAt(i) >= rangeEnd)
        return -1;
    return i;
}
项目:ultrasonic    文件:DragSortListView.java   
private static int insertionIndexForKey(SparseBooleanArray sba, int key) {
    int low = 0;
    int high = sba.size();
    while (high - low > 0) {
        int middle = (low + high) >> 1;
        if (sba.keyAt(middle) < key)
            low = middle + 1;
        else
            high = middle;
    }
    return low;
}
项目:Android-UtilCode    文件:EmptyUtils.java   
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
项目:Android-UtilCode    文件:EmptyUtilsTest.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void isEmpty() throws Exception {
    String string = "";
    String string1 = " ";
    int[][] arr = new int[][]{};
    int[] arr1 = null;
    LinkedList<Integer> list = new LinkedList<>();
    HashMap<String,Integer> map = new HashMap<>();
    SparseArray<String> sa = new SparseArray<>();
    SparseBooleanArray sba = new SparseBooleanArray();
    SparseIntArray sia = new SparseIntArray();
    SparseLongArray sla = new SparseLongArray();

    assertThat(EmptyUtils.isEmpty(string)).isTrue();
    assertThat(EmptyUtils.isEmpty(string1)).isFalse();
    assertThat(EmptyUtils.isEmpty(arr)).isTrue();
    assertThat(EmptyUtils.isEmpty(arr1)).isTrue();
    assertThat(EmptyUtils.isEmpty(list)).isTrue();
    assertThat(EmptyUtils.isEmpty(map)).isTrue();
    assertThat(EmptyUtils.isEmpty(sa)).isTrue();
    assertThat(EmptyUtils.isEmpty(sba)).isTrue();
    assertThat(EmptyUtils.isEmpty(sia)).isTrue();
    assertThat(EmptyUtils.isEmpty(sla)).isTrue();

    assertThat(!EmptyUtils.isNotEmpty(string)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(string1)).isFalse();
    assertThat(!EmptyUtils.isNotEmpty(arr)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(arr1)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(list)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(map)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sa)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sba)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sia)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sla)).isTrue();
}
项目:SimpleNotes    文件:MultiChoiceImplementation.java   
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();
    switch (menuItem.getItemId()) {
        case R.id.delete_all_action:
            //SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();
            // Перебираем с конца, чтобы не нарушать порядок нумерации в списке
            for (int i = (sparseBooleanArray.size() - 1); i >= 0; i--) {
                if (sparseBooleanArray.valueAt(i)) {
                    parentActivity.notes.remove(sparseBooleanArray.keyAt(i));
                }
            }
            actionMode.finish();
            parentActivity.adapter.notifyDataSetChanged();
            parentActivity.listView.smoothScrollToPosition(0);
            Toast.makeText(parentActivity, R.string.deleted_successfully_toast, Toast.LENGTH_LONG).show();
            return true;
        case R.id.copy_all_action:
            StringBuilder textToCopy = new StringBuilder("");
            String label = "Notes text";
            for (int i = 0; i < sparseBooleanArray.size(); i++) {
                if (sparseBooleanArray.valueAt(i)) {
                    textToCopy.append(parentActivity.notes.get(sparseBooleanArray.keyAt(i)).getText());
                    textToCopy.append("\n");
                }
            }
            ClipboardManager clipboard = (ClipboardManager) parentActivity.getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(label, textToCopy.toString());
            clipboard.setPrimaryClip(clip);
            actionMode.finish();
            Toast.makeText(parentActivity, R.string.copied_to_clipboard_toast, Toast.LENGTH_LONG).show();
            return true;
        default:
            return false;
    }
}
项目:godlibrary    文件:FragmentListView.java   
public long[] getCheckedItemIds() {
    SparseBooleanArray ids = adapterCheckLin.getCheckedItemIds();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < ids.size(); i++) {
        if (ids.valueAt(i)) {
            list.add(ids.keyAt(i));
        }
    }
    long[] _ids = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        _ids[i] = list.get(i);
    }
    return _ids;
}
项目:godlibrary    文件:CheckLayout.java   
public static long[] getCheckedItemIds(ListView listview) {
    List<Integer> list = new ArrayList<>();
    //listview.getCheckedItemPositions(); 为触发过选择的item ,选中 为true 取消false
    SparseBooleanArray sp = listview.getCheckedItemPositions();
    for (int i = 0; i < sp.size(); i++) {
        if (sp.valueAt(i)) {
            list.add(sp.keyAt(i));
        }
    }
    long[] ids = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        ids[i] = list.get(i);
    }
    return ids;
}
项目:airgram    文件:TsExtractor.java   
public TsExtractor(PtsTimestampAdjuster ptsTimestampAdjuster, int workaroundFlags) {
  this.ptsTimestampAdjuster = ptsTimestampAdjuster;
  this.workaroundFlags = workaroundFlags;
  tsPacketBuffer = new ParsableByteArray(TS_PACKET_SIZE);
  tsScratch = new ParsableBitArray(new byte[3]);
  tsPayloadReaders = new SparseArray<>();
  tsPayloadReaders.put(TS_PAT_PID, new PatReader());
  streamTypes = new SparseBooleanArray();
}
项目:markor    文件:MarkorSingleton.java   
public void copySelectedNotes(SparseBooleanArray checkedIndices, BaseAdapter notesAdapter, String destination) {
    for (int i = 0; i < checkedIndices.size(); i++) {
        if (checkedIndices.valueAt(i)) {
            File file = (File) notesAdapter.getItem(checkedIndices.keyAt(i));
            copyFile(file, destination);
        }
    }
}
项目:Quran    文件:QuranListAdapter.java   
public QuranListAdapter(Context context, RecyclerView recyclerView,
                        QuranRow[] items, boolean isEditable) {
  inflater = LayoutInflater.from(context);
  this.recyclerView = recyclerView;
  elements = items;
  this.context = context;
  checkedState = new SparseBooleanArray();
  this.isEditable = isEditable;
}
项目:Quran    文件:QariDownloadInfo.java   
QariDownloadInfo(QariItem item, List<Integer> suras) {
  this.qariItem = item;
  this.partialSuras = new SparseBooleanArray();
  this.downloadedSuras = new SparseBooleanArray();
  for (int i = 0, surasSize = suras.size(); i < surasSize; i++) {
    Integer sura = suras.get(i);
    this.downloadedSuras.put(sura, true);
  }
}
项目:ExoPlayer-Offline    文件:FakeExtractorInput.java   
private FakeExtractorInput(byte[] data, boolean simulateUnknownLength,
    boolean simulatePartialReads, boolean simulateIOErrors) {
  this.data = data;
  this.simulateUnknownLength = simulateUnknownLength;
  this.simulatePartialReads = simulatePartialReads;
  this.simulateIOErrors = simulateIOErrors;
  partiallySatisfiedTargetPositions = new SparseBooleanArray();
  failedReadPositions = new SparseBooleanArray();
  failedPeekPositions = new SparseBooleanArray();
}
项目:SpaceRace    文件:ScoreCounter.java   
@NonNull
public Map<LatLng, SparseBooleanArray> getAnswerCorrectnessMap () {
    Map<LatLng, SparseBooleanArray> res = new HashMap<>();

    for (LatLng id : pointMap.keySet()) {
        SparseBooleanArray isCorrectList = new SparseBooleanArray();

        for (Score score : pointMap.get(id)) {
            isCorrectList.put(score.getQuestionId(), score.isCorrect());
        }
    }
    return res;
}
项目:RLibrary    文件:ExpandableTextView.java   
/**
 * 在列表中, 使用此方法设置文本信息
 */
public void setText(CharSequence text, SparseBooleanArray collapsedStatus, int position) {
    mCollapsedStatus = collapsedStatus;
    mPosition = position;
    boolean isCollapsed = collapsedStatus.get(position, true);
    clearAnimation();
    mCollapsed = isCollapsed;
    //mButton.setImageDrawable(mCollapsed ? mExpandDrawable : mCollapseDrawable);
    setText(text);
    getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
    requestLayout();
}
项目:NoticeDog    文件:DragSortListView.java   
private static int findFirstSetIndex(SparseBooleanArray sba, int rangeStart, int rangeEnd) {
    int size = sba.size();
    int i = insertionIndexForKey(sba, rangeStart);
    while (i < size && sba.keyAt(i) < rangeEnd && !sba.valueAt(i))
        i++;
    if (i == size || sba.keyAt(i) >= rangeEnd)
        return -1;
    return i;
}
项目:NoticeDog    文件:DragSortListView.java   
private static int insertionIndexForKey(SparseBooleanArray sba, int key) {
    int low = 0;
    int high = sba.size();
    while (high - low > 0) {
        int middle = (low + high) >> 1;
        if (sba.keyAt(middle) < key)
            low = middle + 1;
        else
            high = middle;
    }
    return low;
}
项目:WhatsAppStatusSaver    文件:FloatAdapter.java   
public FloatAdapter(Context context, ArrayList<String> statuses){
    mContext = context;
    statusPaths = statuses;
    selectedPicturesStatuses = new ArrayList<>();
    selectedVidoesStatuses = new ArrayList<>();
    mPicturesCheckStates = new SparseBooleanArray(statuses.size());
    mVideosCheckStates = new SparseBooleanArray(statuses.size());
}
项目:AndroidUtilCode-master    文件:EmptyUtils.java   
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
项目:AndroidUtilCode-master    文件:EmptyUtilsTest.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void isEmpty() throws Exception {
    String string = "";
    String string1 = " ";
    int[][] arr = new int[][]{};
    int[] arr1 = null;
    LinkedList<Integer> list = new LinkedList<>();
    HashMap<String,Integer> map = new HashMap<>();
    SparseArray<String> sa = new SparseArray<>();
    SparseBooleanArray sba = new SparseBooleanArray();
    SparseIntArray sia = new SparseIntArray();
    SparseLongArray sla = new SparseLongArray();

    assertThat(EmptyUtils.isEmpty(string)).isTrue();
    assertThat(EmptyUtils.isEmpty(string1)).isFalse();
    assertThat(EmptyUtils.isEmpty(arr)).isTrue();
    assertThat(EmptyUtils.isEmpty(arr1)).isTrue();
    assertThat(EmptyUtils.isEmpty(list)).isTrue();
    assertThat(EmptyUtils.isEmpty(map)).isTrue();
    assertThat(EmptyUtils.isEmpty(sa)).isTrue();
    assertThat(EmptyUtils.isEmpty(sba)).isTrue();
    assertThat(EmptyUtils.isEmpty(sia)).isTrue();
    assertThat(EmptyUtils.isEmpty(sla)).isTrue();

    assertThat(!EmptyUtils.isNotEmpty(string)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(string1)).isFalse();
    assertThat(!EmptyUtils.isNotEmpty(arr)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(arr1)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(list)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(map)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sa)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sba)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sia)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sla)).isTrue();
}
项目:orgzly-android    文件:ListViewUtils.java   
public static TreeSet<Long> getCheckedIds(ListView listView) {
    TreeSet<Long> ids = new TreeSet<>();

    SparseBooleanArray checked = listView.getCheckedItemPositions();

    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            long id = listView.getItemIdAtPosition(checked.keyAt(i));
            ids.add(id);
        }
    }

    return ids;
}