下面列出了android.util.SparseBooleanArray#indexOfKey ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void updateGroupParticipants() {
SparseBooleanArray currentChatContactIds = new SparseBooleanArray();
for(int chatContactId : dcContext.getChatContacts(groupChatId)) {
currentChatContactIds.put(chatContactId, false);
}
Set<Recipient> recipients = getAdapter().getRecipients();
for(Recipient recipient : recipients) {
Address address = recipient.getAddress();
if(address.isDcContact()) {
int contactId = address.getDcContactId();
if(currentChatContactIds.indexOfKey(contactId) < 0) {
dcContext.addContactToChat(groupChatId, contactId);
} else {
currentChatContactIds.put(contactId, true);
}
}
}
for(int index = 0; index < currentChatContactIds.size(); index++) {
if (!currentChatContactIds.valueAt(index)) {
dcContext.removeContactFromChat(groupChatId, currentChatContactIds.keyAt(index));
}
}
}
public void onListItemClick(ListView listView, View view, int position, long id) {
SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
if (checkedItems.indexOfKey(position) >=0 && checkedItems.valueAt(checkedItems.indexOfKey(position))) {
if (position == 0 || position == 2) {
getListView().setItemChecked(1, true);
}
} else if (position == 1) {
if ((checkedItems.indexOfKey(0) >=0 && checkedItems.valueAt(checkedItems.indexOfKey(0))) || (checkedItems.indexOfKey(2) >=0 && checkedItems.valueAt(checkedItems.indexOfKey(2)))) {
getListView().setItemChecked(position, true);
}
}
for(int i = 0, size = getListView().getCheckedItemPositions().size(); i < size; i++) {
Boolean b = getListView().getCheckedItemPositions().valueAt(i);
if(b) {
clearDataButton.setEnabled(true);
return;
}
}
clearDataButton.setEnabled(false);
}
private static boolean areRendererDisabledFlagsEqual(
SparseBooleanArray first, SparseBooleanArray second) {
int firstSize = first.size();
if (second.size() != firstSize) {
return false;
}
// Only true values are put into rendererDisabledFlags, so we don't need to compare values.
for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
return false;
}
}
return true;
}
private static boolean areRendererDisabledFlagsEqual(
SparseBooleanArray first, SparseBooleanArray second) {
int firstSize = first.size();
if (second.size() != firstSize) {
return false;
}
// Only true values are put into rendererDisabledFlags, so we don't need to compare values.
for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
return false;
}
}
return true;
}
private static boolean areRendererDisabledFlagsEqual(
SparseBooleanArray first, SparseBooleanArray second) {
int firstSize = first.size();
if (second.size() != firstSize) {
return false;
}
// Only true values are put into rendererDisabledFlags, so we don't need to compare values.
for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
return false;
}
}
return true;
}
/**
* Checks whether a provided answer is correct.
*
* @param checkedItems The items that were selected.
* @param answerIds The actual correct answer ids.
* @return <code>true</code> if correct else <code>false</code>.
*/
public static boolean isAnswerCorrect(SparseBooleanArray checkedItems, int[] answerIds) {
if (null == checkedItems || null == answerIds) {
Log.i(TAG, "isAnswerCorrect got a null parameter input.");
return false;
}
for (int answer : answerIds) {
if (0 > checkedItems.indexOfKey(answer)) {
return false;
}
}
return checkedItems.size() == answerIds.length;
}
private static boolean areRendererDisabledFlagsEqual(
SparseBooleanArray first, SparseBooleanArray second) {
int firstSize = first.size();
if (second.size() != firstSize) {
return false;
}
// Only true values are put into rendererDisabledFlags, so we don't need to compare values.
for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
return false;
}
}
return true;
}
private static boolean areRendererDisabledFlagsEqual(
SparseBooleanArray first, SparseBooleanArray second) {
int firstSize = first.size();
if (second.size() != firstSize) {
return false;
}
// Only true values are put into rendererDisabledFlags, so we don't need to compare values.
for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
return false;
}
}
return true;
}