use of android.util.SparseBooleanArray in project platform_frameworks_base by android.
the class RecentTasks method syncPersistentTaskIdsLocked.
private void syncPersistentTaskIdsLocked() {
for (int i = mPersistedTaskIds.size() - 1; i >= 0; i--) {
int userId = mPersistedTaskIds.keyAt(i);
if (mUsersWithRecentsLoaded.get(userId)) {
// Recents are loaded only after task ids are loaded. Therefore, the set of taskids
// referenced here should not be null.
mPersistedTaskIds.valueAt(i).clear();
}
}
for (int i = size() - 1; i >= 0; i--) {
TaskRecord task = get(i);
if (task.isPersistable && (task.stack == null || !task.stack.isHomeStack())) {
// TODO Investigate why it can happen. For now initialize with an empty set
if (mPersistedTaskIds.get(task.userId) == null) {
Slog.wtf(TAG, "No task ids found for userId " + task.userId + ". task=" + task + " mPersistedTaskIds=" + mPersistedTaskIds);
mPersistedTaskIds.put(task.userId, new SparseBooleanArray());
}
mPersistedTaskIds.get(task.userId).put(task.taskId, true);
}
}
}
use of android.util.SparseBooleanArray in project platform_frameworks_base by android.
the class TaskPersister method loadPersistedTaskIdsForUser.
@NonNull
SparseBooleanArray loadPersistedTaskIdsForUser(int userId) {
if (mTaskIdsInFile.get(userId) != null) {
return mTaskIdsInFile.get(userId).clone();
}
final SparseBooleanArray persistedTaskIds = new SparseBooleanArray();
synchronized (mIoLock) {
BufferedReader reader = null;
String line;
try {
reader = new BufferedReader(new FileReader(getUserPersistedTaskIdsFile(userId)));
while ((line = reader.readLine()) != null) {
for (String taskIdString : line.split("\\s+")) {
int id = Integer.parseInt(taskIdString);
persistedTaskIds.put(id, true);
}
}
} catch (FileNotFoundException e) {
// File doesn't exist. Ignore.
} catch (Exception e) {
Slog.e(TAG, "Error while reading taskIds file for user " + userId, e);
} finally {
IoUtils.closeQuietly(reader);
}
}
mTaskIdsInFile.put(userId, persistedTaskIds);
return persistedTaskIds.clone();
}
use of android.util.SparseBooleanArray in project android-topeka by googlesamples.
the class MultiSelectQuizView method getBundleableAnswer.
private boolean[] getBundleableAnswer() {
SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
final int answerSize = checkedItemPositions.size();
if (0 == answerSize) {
return null;
}
final int optionsSize = getQuiz().getOptions().length;
boolean[] bundleableAnswer = new boolean[optionsSize];
int key;
for (int i = 0; i < answerSize; i++) {
key = checkedItemPositions.keyAt(i);
bundleableAnswer[key] = checkedItemPositions.valueAt(i);
}
return bundleableAnswer;
}
use of android.util.SparseBooleanArray in project android-topeka by googlesamples.
the class SelectItemQuizView method isAnswerCorrect.
@Override
protected boolean isAnswerCorrect() {
final SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
final int[] answer = getQuiz().getAnswer();
return AnswerHelper.isAnswerCorrect(checkedItemPositions, answer);
}
use of android.util.SparseBooleanArray in project android-topeka by googlesamples.
the class ToggleTranslateQuizView method isAnswerCorrect.
@Override
protected boolean isAnswerCorrect() {
final SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
final int[] answer = getQuiz().getAnswer();
return AnswerHelper.isAnswerCorrect(checkedItemPositions, answer);
}
Aggregations