use of android.util.ArrayMap in project android_frameworks_base by AOSPA.
the class TaskStack method createTaskKeyMapFromList.
/**
* Given a list of tasks, returns a map of each task's key to the task.
*/
private ArrayMap<Task.TaskKey, Task> createTaskKeyMapFromList(List<Task> tasks) {
ArrayMap<Task.TaskKey, Task> map = new ArrayMap<>(tasks.size());
int taskCount = tasks.size();
for (int i = 0; i < taskCount; i++) {
Task task = tasks.get(i);
map.put(task.key, task);
}
return map;
}
use of android.util.ArrayMap in project android_frameworks_base by AOSPA.
the class TaskStack method createAffiliatedGroupings.
/**
* Temporary: This method will simulate affiliation groups
*/
void createAffiliatedGroupings(Context context) {
mGroups.clear();
mAffinitiesGroups.clear();
if (RecentsDebugFlags.Static.EnableMockTaskGroups) {
ArrayMap<Task.TaskKey, Task> taskMap = new ArrayMap<>();
// Sort all tasks by increasing firstActiveTime of the task
ArrayList<Task> tasks = mStackTaskList.getTasks();
Collections.sort(tasks, new Comparator<Task>() {
@Override
public int compare(Task task, Task task2) {
return Long.compare(task.key.firstActiveTime, task2.key.firstActiveTime);
}
});
// Create groups when sequential packages are the same
NamedCounter counter = new NamedCounter("task-group", "");
int taskCount = tasks.size();
String prevPackage = "";
int prevAffiliation = -1;
Random r = new Random();
int groupCountDown = RecentsDebugFlags.Static.MockTaskGroupsTaskCount;
for (int i = 0; i < taskCount; i++) {
Task t = tasks.get(i);
String packageName = t.key.getComponent().getPackageName();
packageName = "pkg";
TaskGrouping group;
if (packageName.equals(prevPackage) && groupCountDown > 0) {
group = getGroupWithAffiliation(prevAffiliation);
groupCountDown--;
} else {
int affiliation = IndividualTaskIdOffset + t.key.id;
group = new TaskGrouping(affiliation);
addGroup(group);
prevAffiliation = affiliation;
prevPackage = packageName;
groupCountDown = RecentsDebugFlags.Static.MockTaskGroupsTaskCount;
}
group.addTask(t);
taskMap.put(t.key, t);
}
// Sort groups by increasing latestActiveTime of the group
Collections.sort(mGroups, new Comparator<TaskGrouping>() {
@Override
public int compare(TaskGrouping taskGrouping, TaskGrouping taskGrouping2) {
return Long.compare(taskGrouping.latestActiveTimeInGroup, taskGrouping2.latestActiveTimeInGroup);
}
});
// Sort group tasks by increasing firstActiveTime of the task, and also build a new list
// of tasks
int taskIndex = 0;
int groupCount = mGroups.size();
for (int i = 0; i < groupCount; i++) {
TaskGrouping group = mGroups.get(i);
Collections.sort(group.mTaskKeys, new Comparator<Task.TaskKey>() {
@Override
public int compare(Task.TaskKey taskKey, Task.TaskKey taskKey2) {
return Long.compare(taskKey.firstActiveTime, taskKey2.firstActiveTime);
}
});
ArrayList<Task.TaskKey> groupTasks = group.mTaskKeys;
int groupTaskCount = groupTasks.size();
for (int j = 0; j < groupTaskCount; j++) {
tasks.set(taskIndex, taskMap.get(groupTasks.get(j)));
taskIndex++;
}
}
mStackTaskList.set(tasks);
} else {
// Create the task groups
ArrayMap<Task.TaskKey, Task> tasksMap = new ArrayMap<>();
ArrayList<Task> tasks = mStackTaskList.getTasks();
int taskCount = tasks.size();
for (int i = 0; i < taskCount; i++) {
Task t = tasks.get(i);
TaskGrouping group;
if (RecentsDebugFlags.Static.EnableAffiliatedTaskGroups) {
int affiliation = t.affiliationTaskId > 0 ? t.affiliationTaskId : IndividualTaskIdOffset + t.key.id;
if (mAffinitiesGroups.containsKey(affiliation)) {
group = getGroupWithAffiliation(affiliation);
} else {
group = new TaskGrouping(affiliation);
addGroup(group);
}
} else {
group = new TaskGrouping(t.key.id);
addGroup(group);
}
group.addTask(t);
tasksMap.put(t.key, t);
}
// Update the task colors for each of the groups
float minAlpha = context.getResources().getFloat(R.dimen.recents_task_affiliation_color_min_alpha_percentage);
int taskGroupCount = mGroups.size();
for (int i = 0; i < taskGroupCount; i++) {
TaskGrouping group = mGroups.get(i);
taskCount = group.getTaskCount();
// Ignore the groups that only have one task
if (taskCount <= 1)
continue;
// Calculate the group color distribution
int affiliationColor = tasksMap.get(group.mTaskKeys.get(0)).affiliationColor;
float alphaStep = (1f - minAlpha) / taskCount;
float alpha = 1f;
for (int j = 0; j < taskCount; j++) {
Task t = tasksMap.get(group.mTaskKeys.get(j));
t.colorPrimary = Utilities.getColorWithOverlay(affiliationColor, Color.WHITE, alpha);
alpha -= alphaStep;
}
}
}
}
use of android.util.ArrayMap in project android_frameworks_base by AOSPA.
the class DefaultPermissionGrantPolicy method readDefaultPermissionExceptionsLPw.
@NonNull
private ArrayMap<String, List<DefaultPermissionGrant>> readDefaultPermissionExceptionsLPw() {
File dir = new File(Environment.getRootDirectory(), "etc/default-permissions");
if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
return new ArrayMap<>(0);
}
File[] files = dir.listFiles();
if (files == null) {
return new ArrayMap<>(0);
}
ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>();
// Iterate over the files in the directory and scan .xml files
for (File file : files) {
if (!file.getPath().endsWith(".xml")) {
Slog.i(TAG, "Non-xml file " + file + " in " + dir + " directory, ignoring");
continue;
}
if (!file.canRead()) {
Slog.w(TAG, "Default permissions file " + file + " cannot be read");
continue;
}
try (InputStream str = new BufferedInputStream(new FileInputStream(file))) {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(str, null);
parse(parser, grantExceptions);
} catch (XmlPullParserException | IOException e) {
Slog.w(TAG, "Error reading default permissions file " + file, e);
}
}
return grantExceptions;
}
use of android.util.ArrayMap in project android by JetBrains.
the class UnitTest method exceptions.
@Test
public void exceptions() {
try {
ArrayMap map = new ArrayMap();
map.isEmpty();
fail();
} catch (RuntimeException e) {
assertEquals(RuntimeException.class, e.getClass());
assertTrue(e.getMessage().contains("isEmpty"));
assertTrue(e.getMessage().contains("not mocked"));
}
try {
Debug.getThreadAllocCount();
fail();
} catch (RuntimeException e) {
assertEquals(RuntimeException.class, e.getClass());
assertTrue(e.getMessage().contains("getThreadAllocCount"));
assertTrue(e.getMessage().contains("not mocked"));
}
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class InputMethodUtils method parseInputMethodsAndSubtypesString.
/**
* Parses the setting stored input methods and subtypes string value.
*
* @param inputMethodsAndSubtypesString The input method subtypes value stored in settings.
* @return Map from input method ID to set of input method subtypes IDs.
*/
@VisibleForTesting
public static ArrayMap<String, ArraySet<String>> parseInputMethodsAndSubtypesString(@Nullable final String inputMethodsAndSubtypesString) {
final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<>();
if (TextUtils.isEmpty(inputMethodsAndSubtypesString)) {
return imeMap;
}
final SimpleStringSplitter typeSplitter = new SimpleStringSplitter(INPUT_METHOD_SEPARATOR);
final SimpleStringSplitter subtypeSplitter = new SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATOR);
List<Pair<String, ArrayList<String>>> allImeSettings = InputMethodSettings.buildInputMethodsAndSubtypeList(inputMethodsAndSubtypesString, typeSplitter, subtypeSplitter);
for (Pair<String, ArrayList<String>> ime : allImeSettings) {
ArraySet<String> subtypes = new ArraySet<>();
if (ime.second != null) {
subtypes.addAll(ime.second);
}
imeMap.put(ime.first, subtypes);
}
return imeMap;
}
Aggregations