1303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung/* 2303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Copyright (C) 2014 The Android Open Source Project 3303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * 4303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Licensed under the Apache License, Version 2.0 (the "License"); 5303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * you may not use this file except in compliance with the License. 6303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * You may obtain a copy of the License at 7303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * 8303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * http://www.apache.org/licenses/LICENSE-2.0 9303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * 10303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Unless required by applicable law or agreed to in writing, software 11303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * distributed under the License is distributed on an "AS IS" BASIS, 12303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * See the License for the specific language governing permissions and 14303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * limitations under the License. 15303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung */ 16303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 17303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungpackage com.android.systemui.recents.model; 18303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 19296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chungimport android.app.ActivityManager; 206f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggiimport android.app.ActivityManager.TaskThumbnail; 21a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guyimport android.content.ComponentName; 22303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.content.Intent; 2329379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggiimport android.content.pm.ActivityInfo; 24303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.graphics.Bitmap; 2593748a11cba1b44edbc2e888c997533461355594Winson Chungimport android.graphics.Color; 262dd7694681b7256e136d7f4d060be2858c48e835Winsonimport android.graphics.Rect; 27303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.graphics.drawable.Drawable; 28231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinsonimport android.view.ViewDebug; 29c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson 30eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winsonimport com.android.systemui.recents.Recents; 31eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winsonimport com.android.systemui.recents.misc.SystemServicesProxy; 32ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chungimport com.android.systemui.recents.misc.Utilities; 33303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 34d72c315d5eed3a684eee303364b97129cb821689Winsonimport java.io.PrintWriter; 35b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chungimport java.util.ArrayList; 36a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guyimport java.util.Objects; 37a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy 38303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 39303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung/** 40303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * A task represents the top most task in the system's task stack. 41303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung */ 42303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungpublic class Task { 43d72c315d5eed3a684eee303364b97129cb821689Winson 44d72c315d5eed3a684eee303364b97129cb821689Winson public static final String TAG = "Task"; 45d72c315d5eed3a684eee303364b97129cb821689Winson 4604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung /* Task callbacks */ 4704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public interface TaskCallbacks { 4804dfe0d26b944324ee920001f40d74cff47281d6Winson Chung /* Notifies when a task has been bound */ 49e2c77f903504766102fe545af40c3e4ebcb3adc7Jorim Jaggi public void onTaskDataLoaded(Task task, ThumbnailData thumbnailData); 5004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung /* Notifies when a task has been unbound */ 5104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public void onTaskDataUnloaded(); 52d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung /* Notifies when a task's stack id has changed. */ 53e7f138c7f0a190c86cec10fb32fa106aacae4093Winson public void onTaskStackIdChanged(); 54a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy } 55a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy 5604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung /* The Task Key represents the unique primary key for the task */ 5704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public static class TaskKey { 58231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 5904dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public final int id; 60231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 61d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung public int stackId; 62231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 63c6a1623cc48581380b698ae87b43bfafb9c935baWinson Chung public final Intent baseIntent; 64231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 654f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani public final int userId; 66231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 67ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung public long firstActiveTime; 68231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 69f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung public long lastActiveTime; 7004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung 715500390a006f2bbea565068234774a36cea076c0Winson private int mHashCode; 725500390a006f2bbea565068234774a36cea076c0Winson 73d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung public TaskKey(int id, int stackId, Intent intent, int userId, long firstActiveTime, 74d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung long lastActiveTime) { 7504dfe0d26b944324ee920001f40d74cff47281d6Winson Chung this.id = id; 76d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung this.stackId = stackId; 77c6a1623cc48581380b698ae87b43bfafb9c935baWinson Chung this.baseIntent = intent; 784f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani this.userId = userId; 79ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung this.firstActiveTime = firstActiveTime; 80f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung this.lastActiveTime = lastActiveTime; 815500390a006f2bbea565068234774a36cea076c0Winson updateHashCode(); 825500390a006f2bbea565068234774a36cea076c0Winson } 835500390a006f2bbea565068234774a36cea076c0Winson 845500390a006f2bbea565068234774a36cea076c0Winson public void setStackId(int stackId) { 855500390a006f2bbea565068234774a36cea076c0Winson this.stackId = stackId; 865500390a006f2bbea565068234774a36cea076c0Winson updateHashCode(); 87f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung } 88f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung 89e7f138c7f0a190c86cec10fb32fa106aacae4093Winson public ComponentName getComponent() { 90e7f138c7f0a190c86cec10fb32fa106aacae4093Winson return this.baseIntent.getComponent(); 91a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy } 92a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy 9304dfe0d26b944324ee920001f40d74cff47281d6Winson Chung @Override 9404dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public boolean equals(Object o) { 954f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani if (!(o instanceof TaskKey)) { 964f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani return false; 974f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani } 98d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung TaskKey otherKey = (TaskKey) o; 99d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung return id == otherKey.id && stackId == otherKey.stackId && userId == otherKey.userId; 10004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung } 10104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung 10204dfe0d26b944324ee920001f40d74cff47281d6Winson Chung @Override 10304dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public int hashCode() { 1045500390a006f2bbea565068234774a36cea076c0Winson return mHashCode; 10504dfe0d26b944324ee920001f40d74cff47281d6Winson Chung } 10604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung 10704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung @Override 10804dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public String toString() { 109d72c315d5eed3a684eee303364b97129cb821689Winson return "id=" + id + " stackId=" + stackId + " user=" + userId + " lastActiveTime=" + 110d72c315d5eed3a684eee303364b97129cb821689Winson lastActiveTime; 11104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung } 1125500390a006f2bbea565068234774a36cea076c0Winson 1135500390a006f2bbea565068234774a36cea076c0Winson private void updateHashCode() { 1145500390a006f2bbea565068234774a36cea076c0Winson mHashCode = Objects.hash(id, stackId, userId); 1155500390a006f2bbea565068234774a36cea076c0Winson } 11604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung } 11704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung 118231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(deepExport=true, prefix="key_") 11904dfe0d26b944324ee920001f40d74cff47281d6Winson Chung public TaskKey key; 120296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung 121296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 1226976f7bae901d81a354287088ae232ba7236f30eWinson * The temporary sort index in the stack, used when ordering the stack. 1236976f7bae901d81a354287088ae232ba7236f30eWinson */ 1246976f7bae901d81a354287088ae232ba7236f30eWinson public int temporarySortIndexInStack; 1256976f7bae901d81a354287088ae232ba7236f30eWinson 1266976f7bae901d81a354287088ae232ba7236f30eWinson /** 127296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The group will be computed separately from the initialization of the task 128296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 129231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(deepExport=true, prefix="group_") 130ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung public TaskGrouping group; 131296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 132296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The affiliationTaskId is the task id of the parent task or itself if it is not affiliated 133296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * with any task. 134296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 135231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 136296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public int affiliationTaskId; 137231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 138296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public int affiliationColor; 139296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung 140296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 141296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The icon is the task description icon (if provided), which falls back to the activity icon, 142296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * which can then fall back to the application icon. 143296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 144296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public Drawable icon; 1456f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi public ThumbnailData thumbnail; 146231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 147296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public String title; 148231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 149b92dd6358180eb7e6b7a57de1efa38e16597e650Winson public String titleDescription; 150231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 1515500390a006f2bbea565068234774a36cea076c0Winson public String dismissDescription; 152231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 153b92dd6358180eb7e6b7a57de1efa38e16597e650Winson public String appInfoDescription; 154b92dd6358180eb7e6b7a57de1efa38e16597e650Winson @ViewDebug.ExportedProperty(category="recents") 155f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung public int colorPrimary; 156231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 1571af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung public int colorBackground; 158231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 15993748a11cba1b44edbc2e888c997533461355594Winson Chung public boolean useLightOnPrimaryColor; 160296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung 161296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 162296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The bounds of the task, used only if it is a freeform task. 163296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 164231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 165296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public Rect bounds; 166296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung 167296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 168296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The task description for this task, only used to reload task icons. 169296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 170296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public ActivityManager.TaskDescription taskDescription; 171296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung 172296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung /** 173296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung * The state isLaunchTarget will be set for the correct task upon launching Recents. 174296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung */ 175231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 176296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public boolean isLaunchTarget; 177231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 1788f6ee48225ad1cdf966c8f406c85113b13833c7bWinson public boolean isStackTask; 179231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson @ViewDebug.ExportedProperty(category="recents") 1808be1634a543022bd6ee0c1e974d3201d452981e8Winson public boolean isSystemApp; 181931845fcb3823ce175fcfc7c6ce2d9751102c331Winson @ViewDebug.ExportedProperty(category="recents") 182931845fcb3823ce175fcfc7c6ce2d9751102c331Winson public boolean isDockable; 183e7f138c7f0a190c86cec10fb32fa106aacae4093Winson 18429379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi /** 18529379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi * Resize mode. See {@link ActivityInfo#resizeMode}. 18629379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi */ 18729379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi @ViewDebug.ExportedProperty(category="recents") 18829379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi public int resizeMode; 18929379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi 19029379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi @ViewDebug.ExportedProperty(category="recents") 19129379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi public ComponentName topActivity; 19229379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi 1939f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee @ViewDebug.ExportedProperty(category="recents") 1949f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee public boolean isLocked; 1959f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee 196b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung private ArrayList<TaskCallbacks> mCallbacks = new ArrayList<>(); 197303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 1980d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung public Task() { 19904400672962d2e12132f9465928cbf7615c147c4Winson Chung // Do nothing 2000d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung } 2010d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung 202296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung public Task(TaskKey key, int affiliationTaskId, int affiliationColor, Drawable icon, 2036f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi ThumbnailData thumbnail, String title, String titleDescription, 2046f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi String dismissDescription, String appInfoDescription, int colorPrimary, 2056f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi int colorBackground, boolean isLaunchTarget, boolean isStackTask, boolean isSystemApp, 2066f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi boolean isDockable, Rect bounds, ActivityManager.TaskDescription taskDescription, 2076f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi int resizeMode, ComponentName topActivity, boolean isLocked) { 208296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung boolean isInAffiliationGroup = (affiliationTaskId != key.id); 209296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung boolean hasAffiliationGroupColor = isInAffiliationGroup && (affiliationColor != 0); 210a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung this.key = key; 211296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.affiliationTaskId = affiliationTaskId; 212296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.affiliationColor = affiliationColor; 213296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.icon = icon; 214296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.thumbnail = thumbnail; 215296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.title = title; 216b92dd6358180eb7e6b7a57de1efa38e16597e650Winson this.titleDescription = titleDescription; 2175500390a006f2bbea565068234774a36cea076c0Winson this.dismissDescription = dismissDescription; 218b92dd6358180eb7e6b7a57de1efa38e16597e650Winson this.appInfoDescription = appInfoDescription; 219296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.colorPrimary = hasAffiliationGroupColor ? affiliationColor : colorPrimary; 2201af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung this.colorBackground = colorBackground; 221ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung this.useLightOnPrimaryColor = Utilities.computeContrastBetweenColors(this.colorPrimary, 22293748a11cba1b44edbc2e888c997533461355594Winson Chung Color.WHITE) > 3f; 223296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.bounds = bounds; 224296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.taskDescription = taskDescription; 22565c851e6e9e08656744b6f66d3da188e3283b17dWinson this.isLaunchTarget = isLaunchTarget; 2268f6ee48225ad1cdf966c8f406c85113b13833c7bWinson this.isStackTask = isStackTask; 2278be1634a543022bd6ee0c1e974d3201d452981e8Winson this.isSystemApp = isSystemApp; 228931845fcb3823ce175fcfc7c6ce2d9751102c331Winson this.isDockable = isDockable; 22929379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi this.resizeMode = resizeMode; 23029379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi this.topActivity = topActivity; 2319f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee this.isLocked = isLocked; 232a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung } 233a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung 2348873754f66527d2cc9feab295dd4eef23298212aWinson /** 2358873754f66527d2cc9feab295dd4eef23298212aWinson * Copies the metadata from another task, but retains the current callbacks. 2368873754f66527d2cc9feab295dd4eef23298212aWinson */ 237a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung public void copyFrom(Task o) { 238a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung this.key = o.key; 239296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.group = o.group; 240296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.affiliationTaskId = o.affiliationTaskId; 241296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.affiliationColor = o.affiliationColor; 242296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.icon = o.icon; 243296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.thumbnail = o.thumbnail; 244296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.title = o.title; 245b92dd6358180eb7e6b7a57de1efa38e16597e650Winson this.titleDescription = o.titleDescription; 2465500390a006f2bbea565068234774a36cea076c0Winson this.dismissDescription = o.dismissDescription; 247b92dd6358180eb7e6b7a57de1efa38e16597e650Winson this.appInfoDescription = o.appInfoDescription; 248a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung this.colorPrimary = o.colorPrimary; 2491af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung this.colorBackground = o.colorBackground; 250a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung this.useLightOnPrimaryColor = o.useLightOnPrimaryColor; 251296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.bounds = o.bounds; 252217009356efa2b854ab3981dff8d315a0d679c73Winson this.taskDescription = o.taskDescription; 253296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.isLaunchTarget = o.isLaunchTarget; 2548f6ee48225ad1cdf966c8f406c85113b13833c7bWinson this.isStackTask = o.isStackTask; 2558be1634a543022bd6ee0c1e974d3201d452981e8Winson this.isSystemApp = o.isSystemApp; 256931845fcb3823ce175fcfc7c6ce2d9751102c331Winson this.isDockable = o.isDockable; 25729379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi this.resizeMode = o.resizeMode; 2589f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee this.isLocked = o.isLocked; 25929379ec859bf7118dec9f3248c63ee369218ad6bJorim Jaggi this.topActivity = o.topActivity; 260303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung } 261303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 262b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung /** 263b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung * Add a callback. 264b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung */ 265b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung public void addCallback(TaskCallbacks cb) { 266b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung if (!mCallbacks.contains(cb)) { 267b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung mCallbacks.add(cb); 268b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung } 269b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung } 270b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung 271b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung /** 272b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung * Remove a callback. 273b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung */ 274b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung public void removeCallback(TaskCallbacks cb) { 275b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung mCallbacks.remove(cb); 276303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung } 277303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 278ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung /** Set the grouping */ 279ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung public void setGroup(TaskGrouping group) { 280ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung this.group = group; 281ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung } 282ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung 283eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson /** 284eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson * Updates the stack id of this task. 285eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson */ 286d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung public void setStackId(int stackId) { 2875500390a006f2bbea565068234774a36cea076c0Winson key.setStackId(stackId); 288b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung int callbackCount = mCallbacks.size(); 289b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung for (int i = 0; i < callbackCount; i++) { 290b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung mCallbacks.get(i).onTaskStackIdChanged(); 291d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung } 292d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung } 293d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung 294eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson /** 295eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson * Returns whether this task is on the freeform task stack. 296eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson */ 29723afcae84422ac7c9687b17a6193f74264361303Winson public boolean isFreeformTask() { 298eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson SystemServicesProxy ssp = Recents.getSystemServices(); 29936f3f0337de86baf8cf8a5fdd67a95e61dff4bcdWinson Chung return ssp.hasFreeformWorkspaceSupport() && ssp.isFreeformStack(key.stackId); 30023afcae84422ac7c9687b17a6193f74264361303Winson } 30123afcae84422ac7c9687b17a6193f74264361303Winson 3024d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung /** Notifies the callback listeners that this task has been loaded */ 303e2c77f903504766102fe545af40c3e4ebcb3adc7Jorim Jaggi public void notifyTaskDataLoaded(ThumbnailData thumbnailData, Drawable applicationIcon) { 304296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung this.icon = applicationIcon; 3056f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi this.thumbnail = thumbnailData; 306b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung int callbackCount = mCallbacks.size(); 307b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung for (int i = 0; i < callbackCount; i++) { 308e2c77f903504766102fe545af40c3e4ebcb3adc7Jorim Jaggi mCallbacks.get(i).onTaskDataLoaded(this, thumbnailData); 3094d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung } 3104d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung } 3114d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung 3124d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung /** Notifies the callback listeners that this task has been unloaded */ 3136f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi public void notifyTaskDataUnloaded(Drawable defaultApplicationIcon) { 314296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung icon = defaultApplicationIcon; 3156f9dbcb742ee930151444118dd61c2239efce09dJorim Jaggi thumbnail = null; 316f24f21695f5609d06402cf61e3500d408b99bdcbWinson for (int i = mCallbacks.size() - 1; i >= 0; i--) { 317b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung mCallbacks.get(i).onTaskDataUnloaded(); 3184d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung } 3194d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung } 3204d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung 3212b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung /** 3222b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung * Returns whether this task is affiliated with another task. 3232b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung */ 3242b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung public boolean isAffiliatedTask() { 325296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung return key.id != affiliationTaskId; 3262b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung } 3272b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung 328f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson /** 329f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson * Returns the top activity component. 330f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson */ 331f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson public ComponentName getTopComponent() { 332f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson return topActivity != null 333f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson ? topActivity 334f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson : key.baseIntent.getComponent(); 335f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson } 336f21c3dace89b168f5e5e4e96532d977b8b0a1cf5Winson 337303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung @Override 338303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung public boolean equals(Object o) { 339a10370fc2eb8eb95631592160c5f6281b9d75722Winson Chung // Check that the id matches 340303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung Task t = (Task) o; 34104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung return key.equals(t.key); 342303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung } 343303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung 344303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung @Override 345303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung public String toString() { 3468873754f66527d2cc9feab295dd4eef23298212aWinson return "[" + key.toString() + "] " + title; 347303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung } 348d72c315d5eed3a684eee303364b97129cb821689Winson 349d72c315d5eed3a684eee303364b97129cb821689Winson public void dump(String prefix, PrintWriter writer) { 350d72c315d5eed3a684eee303364b97129cb821689Winson writer.print(prefix); writer.print(key); 35129a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson if (isAffiliatedTask()) { 352d72c315d5eed3a684eee303364b97129cb821689Winson writer.print(" "); writer.print("affTaskId=" + affiliationTaskId); 353d72c315d5eed3a684eee303364b97129cb821689Winson } 35429a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson if (!isDockable) { 35529a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson writer.print(" dockable=N"); 35629a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson } 35729a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson if (isLaunchTarget) { 35829a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson writer.print(" launchTarget=Y"); 35929a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson } 36029a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson if (isFreeformTask()) { 36129a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson writer.print(" freeform=Y"); 36229a763b83c3a5cb65b2eb682e8404efc47e4dc19Winson } 3639f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee if (isLocked) { 3649f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee writer.print(" locked=Y"); 3659f4ab32b1c62d16f03d14a50f13f04ddb58c541fRobin Lee } 366d72c315d5eed3a684eee303364b97129cb821689Winson writer.print(" "); writer.print(title); 367d72c315d5eed3a684eee303364b97129cb821689Winson writer.println(); 368d72c315d5eed3a684eee303364b97129cb821689Winson } 369303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung} 370