当前位置: 首页>>代码示例>>Java>>正文


Java SparseBooleanArray类代码示例

本文整理汇总了Java中android.util.SparseBooleanArray的典型用法代码示例。如果您正苦于以下问题:Java SparseBooleanArray类的具体用法?Java SparseBooleanArray怎么用?Java SparseBooleanArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SparseBooleanArray类属于android.util包,在下文中一共展示了SparseBooleanArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeCheckState

import android.util.SparseBooleanArray; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:34,代码来源:DragSortListView.java

示例2: getIds

import android.util.SparseBooleanArray; //导入依赖的package包/类
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;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:21,代码来源:ExpandableListViewCheckAdapter.java

示例3: checkXFully

import android.util.SparseBooleanArray; //导入依赖的package包/类
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;
}
 
开发者ID:ashwanijanghu,项目名称:ExoPlayer-Offline,代码行数:20,代码来源:FakeExtractorInput.java

示例4: onDestroyActionMode

import android.util.SparseBooleanArray; //导入依赖的package包/类
@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);
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:18,代码来源:MultiSelectionUtil.java

示例5: onItemClick

import android.util.SparseBooleanArray; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:23,代码来源:MultiSelectionUtil.java

示例6: removeCheckState

import android.util.SparseBooleanArray; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:34,代码来源:DragSortListView.java

示例7: onSaveInstanceState

import android.util.SparseBooleanArray; //导入依赖的package包/类
@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);
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:23,代码来源:GameFragment.java

示例8: deleteRows

import android.util.SparseBooleanArray; //导入依赖的package包/类
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();

    }
 
开发者ID:Rishabhk07,项目名称:multi-copy,代码行数:20,代码来源:NotesFragment.java

示例9: getIndexPathsForSelectedRows

import android.util.SparseBooleanArray; //导入依赖的package包/类
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;
}
 
开发者ID:hh-in-zhuzhou,项目名称:ShangHanLun,代码行数:21,代码来源:ATableView.java

示例10: init

import android.util.SparseBooleanArray; //导入依赖的package包/类
/**
 * 初始化属性
 */
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);
}
 
开发者ID:haihaio,项目名称:AmenEye,代码行数:27,代码来源:FoldableTextView.java

示例11: doInBackground

import android.util.SparseBooleanArray; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:mr-kojo,项目名称:Veggietizer,代码行数:32,代码来源:HistoryActivity.java

示例12: saveInstanceState

import android.util.SparseBooleanArray; //导入依赖的package包/类
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;
}
 
开发者ID:ChessCom,项目名称:android-chessclock,代码行数:17,代码来源:MultiSelectionUtil.java

示例13: TsExtractor

import android.util.SparseBooleanArray; //导入依赖的package包/类
/**
 * @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();
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:24,代码来源:TsExtractor.java

示例14: getDays

import android.util.SparseBooleanArray; //导入依赖的package包/类
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;
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:15,代码来源:ZenModeScheduleDaysSelection.java

示例15: State

import android.util.SparseBooleanArray; //导入依赖的package包/类
public State() {
    itemsFrames = new SparseArray<>();
    itemsAttached = new SparseBooleanArray();
    scrolledX = 0;
    scrolledY = 0;
    contentWidth = 0;
    contentHeight = 0;
    canScrollHorizontal = true;
    canScrollVertical = true;
    itemLineCount = 1;
    totalSpreadCount = 0;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:CustomLayoutManager.java


注:本文中的android.util.SparseBooleanArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。