當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。