本文整理汇总了Java中android.util.SparseBooleanArray.keyAt方法的典型用法代码示例。如果您正苦于以下问题:Java SparseBooleanArray.keyAt方法的具体用法?Java SparseBooleanArray.keyAt怎么用?Java SparseBooleanArray.keyAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.SparseBooleanArray
的用法示例。
在下文中一共展示了SparseBooleanArray.keyAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: 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);
}
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: findFirstSetIndex
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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;
}
示例7: insertionIndexForKey
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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;
}
示例8: onSetCardClicked
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
/**
* This is called by the presenter whenever a SET card is clicked by the user.
* If 3 cards are selected those indices are sent to the presenter
* who will check if they are a valid set.
*/
@Override
public void onSetCardClicked() {
mCheckedCount = getCheckedItemCount();
// If we have 3 items selected, check if they are a set
if (mCheckedCount == 3) {
SparseBooleanArray checkedItemPositions = getCheckedItemPositions();
int positionIndex = 0;
// Loop through SparseBooleanArray and grab the 3 positions that are checked
for (int i = 0; i < checkedItemPositions.size(); i++) {
if (checkedItemPositions.valueAt(i)) {
mCheckedPositions[positionIndex] = checkedItemPositions.keyAt(i);
positionIndex++;
}
}
// Submit the set instances to the presenter
mActionsListener.onSubmitSet(
mCheckedPositions[0],
mCheckedPositions[1],
mCheckedPositions[2]);
Log.d(LOG_TAG, String.format(
"Submitted set at positions %d, %d, %d",
mCheckedPositions[0],
mCheckedPositions[1],
mCheckedPositions[2]));
}
}
示例9: deleteTimeControls
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
private void deleteTimeControls() {
Log.d(TAG, "Requested to delete " + mTotalItemChecked + " time controls.");
boolean updateList = false;
int[] positions = new int[mTotalItemChecked];
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int tmpItemChecked = mItemChecked;
// Get position of checked items
int k = 0;
for (int i = 0; i < checked.size(); i++) {
// If checked
if (checked.valueAt(i)) {
int position = checked.keyAt(i) - mListView.getHeaderViewsCount();
Log.d(TAG, "Marking time control " + position + " to remove.");
positions[k] = position;
k++;
updateList = true;
// Update position of check item
if (position < mItemChecked) {
tmpItemChecked--;
} else if (position == mItemChecked) {
tmpItemChecked = 0;
}
}
}
mItemChecked = tmpItemChecked;
// If checked items found request their removal.
if (updateList) {
mListener.removeTimeControl(positions);
// Note: No need to notifyDataSetChanged as mListView will have adapters swap.
}
}
示例10: buildRunList
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
int rangeEnd, int[] runStart, int[] runEnd) {
int runCount = 0;
int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
if (i == -1)
return 0;
int position = cip.keyAt(i);
int currentRunStart = position;
int currentRunEnd = currentRunStart + 1;
for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
if (!cip.valueAt(i)) // not checked => not interesting
continue;
if (position == currentRunEnd) {
currentRunEnd++;
} else {
runStart[runCount] = currentRunStart;
runEnd[runCount] = currentRunEnd;
runCount++;
currentRunStart = position;
currentRunEnd = position + 1;
}
}
if (currentRunEnd == rangeEnd) {
// rangeStart and rangeEnd are equivalent positions so to be
// consistent we translate them to the same integer value. That way
// we can check whether a run covers the entire range by just
// checking if the start equals the end position.
currentRunEnd = rangeStart;
}
runStart[runCount] = currentRunStart;
runEnd[runCount] = currentRunEnd;
runCount++;
if (runCount > 1) {
if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
// The last run ends at the end of the range, and the first run
// starts at the beginning of the range. So they are actually
// part of the same run, except they wrap around the end of the
// range. To avoid adjacent runs, we need to merge them.
runStart[0] = runStart[runCount - 1];
runCount--;
}
}
return runCount;
}
示例11: buildRunList
import android.util.SparseBooleanArray; //导入方法依赖的package包/类
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
int rangeEnd, int[] runStart, int[] runEnd) {
int runCount = 0;
int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
if (i == -1)
return 0;
int position = cip.keyAt(i);
int currentRunStart = position;
int currentRunEnd = currentRunStart + 1;
for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
if (!cip.valueAt(i)) // not checked => not interesting
continue;
if (position == currentRunEnd) {
currentRunEnd++;
} else {
runStart[runCount] = currentRunStart;
runEnd[runCount] = currentRunEnd;
runCount++;
currentRunStart = position;
currentRunEnd = position + 1;
}
}
if (currentRunEnd == rangeEnd) {
// rangeStart and rangeEnd are equivalent positions so to be
// consistent we translate them to the same integer value. That way
// we can check whether a run covers the entire range by just
// checking if the start equals the end position.
currentRunEnd = rangeStart;
}
runStart[runCount] = currentRunStart;
runEnd[runCount] = currentRunEnd;
runCount++;
if (runCount > 1) {
if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
// The last run ends at the end of the range, and the first run
// starts at the beginning of the range. So they are actually
// part of the same run, except they wrap around the end of the
// range. To avoid adjacent runs, we need to merge them.
runStart[0] = runStart[runCount - 1];
runCount--;
}
}
return runCount;
}