TaskGrouping.java revision 083baf99ff1228e96ede96aac88c8200c4fdc2b2
1package com.android.systemui.recents.model; 2 3import java.util.ArrayList; 4import java.util.HashMap; 5 6/** Represents a grouping of tasks witihin a stack. */ 7public class TaskGrouping { 8 9 int affiliation; 10 long latestActiveTimeInGroup; 11 12 Task.TaskKey mFrontMostTaskKey; 13 ArrayList<Task.TaskKey> mTaskKeys = new ArrayList<Task.TaskKey>(); 14 HashMap<Task.TaskKey, Integer> mTaskKeyIndices = new HashMap<Task.TaskKey, Integer>(); 15 16 /** Creates a group with a specified affiliation. */ 17 public TaskGrouping(int affiliation) { 18 this.affiliation = affiliation; 19 } 20 21 /** Adds a new task to this group. */ 22 void addTask(Task t) { 23 mTaskKeys.add(t.key); 24 if (t.key.lastActiveTime > latestActiveTimeInGroup) { 25 latestActiveTimeInGroup = t.key.lastActiveTime; 26 } 27 t.setGroup(this); 28 updateTaskIndices(); 29 } 30 31 /** Removes a task from this group. */ 32 void removeTask(Task t) { 33 mTaskKeys.remove(t.key); 34 latestActiveTimeInGroup = 0; 35 int taskCount = mTaskKeys.size(); 36 for (int i = 0; i < taskCount; i++) { 37 long lastActiveTime = mTaskKeys.get(i).lastActiveTime; 38 if (lastActiveTime > latestActiveTimeInGroup) { 39 latestActiveTimeInGroup = lastActiveTime; 40 } 41 } 42 t.setGroup(null); 43 updateTaskIndices(); 44 } 45 46 /** Gets the front task */ 47 public boolean isFrontMostTask(Task t) { 48 return (t.key == mFrontMostTaskKey); 49 } 50 51 /** Finds the index of a given task in a group. */ 52 public int indexOf(Task t) { 53 return mTaskKeyIndices.get(t.key); 54 } 55 56 /** Returns the number of tasks in this group. */ 57 public int getTaskCount() { return mTaskKeys.size(); } 58 59 /** Updates the mapping of tasks to indices. */ 60 private void updateTaskIndices() { 61 if (mTaskKeys.isEmpty()) { 62 mFrontMostTaskKey = null; 63 mTaskKeyIndices.clear(); 64 return; 65 } 66 67 mFrontMostTaskKey = mTaskKeys.get(mTaskKeys.size() - 1); 68 mTaskKeyIndices.clear(); 69 int taskCount = mTaskKeys.size(); 70 for (int i = 0; i < taskCount; i++) { 71 Task.TaskKey k = mTaskKeys.get(i); 72 mTaskKeyIndices.put(k, i); 73 } 74 } 75} 76