Task.java revision 8873754f66527d2cc9feab295dd4eef23298212a
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;
20a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guyimport android.content.ComponentName;
21303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.content.Intent;
22303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.graphics.Bitmap;
2393748a11cba1b44edbc2e888c997533461355594Winson Chungimport android.graphics.Color;
242dd7694681b7256e136d7f4d060be2858c48e835Winsonimport android.graphics.Rect;
25303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.graphics.drawable.Drawable;
26231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinsonimport android.view.ViewDebug;
27c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson
28eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winsonimport com.android.systemui.recents.Recents;
29eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winsonimport com.android.systemui.recents.misc.SystemServicesProxy;
30ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chungimport com.android.systemui.recents.misc.Utilities;
31303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
32b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chungimport java.util.ArrayList;
33a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guyimport java.util.Objects;
34a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy
35303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
36303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung/**
37303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * A task represents the top most task in the system's task stack.
38303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung */
39303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungpublic class Task {
4004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    /* Task callbacks */
4104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    public interface TaskCallbacks {
4204dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        /* Notifies when a task has been bound */
43b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        public void onTaskDataLoaded(Task task);
4404dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        /* Notifies when a task has been unbound */
4504dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        public void onTaskDataUnloaded();
46d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung        /* Notifies when a task's stack id has changed. */
47e7f138c7f0a190c86cec10fb32fa106aacae4093Winson        public void onTaskStackIdChanged();
48a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy    }
49a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy
5004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    /* The Task Key represents the unique primary key for the task */
5104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    public static class TaskKey {
52231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
5304dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        public final int id;
54231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
55d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung        public int stackId;
56231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
57c6a1623cc48581380b698ae87b43bfafb9c935baWinson Chung        public final Intent baseIntent;
58231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
594f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani        public final int userId;
60231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
61ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung        public long firstActiveTime;
62231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson        @ViewDebug.ExportedProperty(category="recents")
63f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung        public long lastActiveTime;
6404dfe0d26b944324ee920001f40d74cff47281d6Winson Chung
655500390a006f2bbea565068234774a36cea076c0Winson        private int mHashCode;
665500390a006f2bbea565068234774a36cea076c0Winson
67d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung        public TaskKey(int id, int stackId, Intent intent, int userId, long firstActiveTime,
68d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung                long lastActiveTime) {
6904dfe0d26b944324ee920001f40d74cff47281d6Winson Chung            this.id = id;
70d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung            this.stackId = stackId;
71c6a1623cc48581380b698ae87b43bfafb9c935baWinson Chung            this.baseIntent = intent;
724f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani            this.userId = userId;
73ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung            this.firstActiveTime = firstActiveTime;
74f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung            this.lastActiveTime = lastActiveTime;
755500390a006f2bbea565068234774a36cea076c0Winson            updateHashCode();
765500390a006f2bbea565068234774a36cea076c0Winson        }
775500390a006f2bbea565068234774a36cea076c0Winson
785500390a006f2bbea565068234774a36cea076c0Winson        public void setStackId(int stackId) {
795500390a006f2bbea565068234774a36cea076c0Winson            this.stackId = stackId;
805500390a006f2bbea565068234774a36cea076c0Winson            updateHashCode();
81f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung        }
82f1fbd77cf057e43926f9a0347692611386d09f40Winson Chung
83e7f138c7f0a190c86cec10fb32fa106aacae4093Winson        public ComponentName getComponent() {
84e7f138c7f0a190c86cec10fb32fa106aacae4093Winson            return this.baseIntent.getComponent();
85a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy        }
86a734fc1ecedb316fdf6deddc169b8b0bddab76bfKenny Guy
8704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        @Override
8804dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        public boolean equals(Object o) {
894f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani            if (!(o instanceof TaskKey)) {
904f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani                return false;
914f0a49e6b9ad1b00972dbe8a751263aa6c482538Amith Yamasani            }
92d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung            TaskKey otherKey = (TaskKey) o;
93d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung            return id == otherKey.id && stackId == otherKey.stackId && userId == otherKey.userId;
9404dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        }
9504dfe0d26b944324ee920001f40d74cff47281d6Winson Chung
9604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        @Override
9704dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        public int hashCode() {
985500390a006f2bbea565068234774a36cea076c0Winson            return mHashCode;
9904dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        }
10004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung
10104dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        @Override
10204dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        public String toString() {
1038873754f66527d2cc9feab295dd4eef23298212aWinson            return "t" + id + ", s" + stackId + ", u" + userId;
10404dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        }
1055500390a006f2bbea565068234774a36cea076c0Winson
1065500390a006f2bbea565068234774a36cea076c0Winson        private void updateHashCode() {
1075500390a006f2bbea565068234774a36cea076c0Winson            mHashCode = Objects.hash(id, stackId, userId);
1085500390a006f2bbea565068234774a36cea076c0Winson        }
10904dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    }
11004dfe0d26b944324ee920001f40d74cff47281d6Winson Chung
111231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(deepExport=true, prefix="key_")
11204dfe0d26b944324ee920001f40d74cff47281d6Winson Chung    public TaskKey key;
113296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung
114296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
115296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The group will be computed separately from the initialization of the task
116296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
117231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(deepExport=true, prefix="group_")
118ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung    public TaskGrouping group;
119296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
120296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The affiliationTaskId is the task id of the parent task or itself if it is not affiliated
121296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * with any task.
122296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
123231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
124296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public int affiliationTaskId;
125231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
126296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public int affiliationColor;
127296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung
128296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
129296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The icon is the task description icon (if provided), which falls back to the activity icon,
130296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * which can then fall back to the application icon.
131296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
132296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public Drawable icon;
133296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public Bitmap thumbnail;
134231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
135296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public String title;
136231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
137b7a42fda313b6e5d5e82591ea9fb5d1b30acfc55Benjamin Franz    public String contentDescription;
138231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
1395500390a006f2bbea565068234774a36cea076c0Winson    public String dismissDescription;
140231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
141f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung    public int colorPrimary;
142231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
1431af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung    public int colorBackground;
144231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
14593748a11cba1b44edbc2e888c997533461355594Winson Chung    public boolean useLightOnPrimaryColor;
146296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung
147296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
148296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The bounds of the task, used only if it is a freeform task.
149296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
150231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
151296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public Rect bounds;
152296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung
153296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
154296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The task description for this task, only used to reload task icons.
155296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
156296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public ActivityManager.TaskDescription taskDescription;
157296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung
158296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    /**
159296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     * The state isLaunchTarget will be set for the correct task upon launching Recents.
160296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung     */
161231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
162296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public boolean isLaunchTarget;
163231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
164296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public boolean isHistorical;
165231bc9c54a48921f9c6a1ae187969c9bfe9d121fWinson    @ViewDebug.ExportedProperty(category="recents")
1668be1634a543022bd6ee0c1e974d3201d452981e8Winson    public boolean isSystemApp;
167931845fcb3823ce175fcfc7c6ce2d9751102c331Winson    @ViewDebug.ExportedProperty(category="recents")
168931845fcb3823ce175fcfc7c6ce2d9751102c331Winson    public boolean isDockable;
169e7f138c7f0a190c86cec10fb32fa106aacae4093Winson
170b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    private ArrayList<TaskCallbacks> mCallbacks = new ArrayList<>();
171303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
1720d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung    public Task() {
17304400672962d2e12132f9465928cbf7615c147c4Winson Chung        // Do nothing
1740d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung    }
1750d767551c55d9e594a0b944bd1926c21a344b5aeWinson Chung
176296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung    public Task(TaskKey key, int affiliationTaskId, int affiliationColor, Drawable icon,
1775500390a006f2bbea565068234774a36cea076c0Winson                Bitmap thumbnail, String title, String contentDescription,
1781af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung                String dismissDescription, int colorPrimary, int colorBackground,
179931845fcb3823ce175fcfc7c6ce2d9751102c331Winson                boolean isHistorical, boolean isLaunchTarget, boolean isSystemApp,
180931845fcb3823ce175fcfc7c6ce2d9751102c331Winson                boolean isDockable, Rect bounds, ActivityManager.TaskDescription taskDescription) {
181296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        boolean isInAffiliationGroup = (affiliationTaskId != key.id);
182296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        boolean hasAffiliationGroupColor = isInAffiliationGroup && (affiliationColor != 0);
183a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung        this.key = key;
184296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.affiliationTaskId = affiliationTaskId;
185296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.affiliationColor = affiliationColor;
186296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.icon = icon;
187296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.thumbnail = thumbnail;
188296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.title = title;
189b7a42fda313b6e5d5e82591ea9fb5d1b30acfc55Benjamin Franz        this.contentDescription = contentDescription;
1905500390a006f2bbea565068234774a36cea076c0Winson        this.dismissDescription = dismissDescription;
191296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.colorPrimary = hasAffiliationGroupColor ? affiliationColor : colorPrimary;
1921af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung        this.colorBackground = colorBackground;
193ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung        this.useLightOnPrimaryColor = Utilities.computeContrastBetweenColors(this.colorPrimary,
19493748a11cba1b44edbc2e888c997533461355594Winson Chung                Color.WHITE) > 3f;
195296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.bounds = bounds;
196296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.taskDescription = taskDescription;
19765c851e6e9e08656744b6f66d3da188e3283b17dWinson        this.isLaunchTarget = isLaunchTarget;
198296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.isHistorical = isHistorical;
1998be1634a543022bd6ee0c1e974d3201d452981e8Winson        this.isSystemApp = isSystemApp;
200931845fcb3823ce175fcfc7c6ce2d9751102c331Winson        this.isDockable = isDockable;
201a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung    }
202a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung
2038873754f66527d2cc9feab295dd4eef23298212aWinson    /**
2048873754f66527d2cc9feab295dd4eef23298212aWinson     * Copies the metadata from another task, but retains the current callbacks.
2058873754f66527d2cc9feab295dd4eef23298212aWinson     */
206a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung    public void copyFrom(Task o) {
207a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung        this.key = o.key;
208296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.group = o.group;
209296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.affiliationTaskId = o.affiliationTaskId;
210296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.affiliationColor = o.affiliationColor;
211296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.icon = o.icon;
212296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.thumbnail = o.thumbnail;
213296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.title = o.title;
214b7a42fda313b6e5d5e82591ea9fb5d1b30acfc55Benjamin Franz        this.contentDescription = o.contentDescription;
2155500390a006f2bbea565068234774a36cea076c0Winson        this.dismissDescription = o.dismissDescription;
216a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung        this.colorPrimary = o.colorPrimary;
2171af8eda6ea1c89d44123b2bfd5fa0293bb9d68cbWinson Chung        this.colorBackground = o.colorBackground;
218a4ccb86ddc8f9f486aee25fb836f4aff97bf7679Winson Chung        this.useLightOnPrimaryColor = o.useLightOnPrimaryColor;
219296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.bounds = o.bounds;
220296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.isLaunchTarget = o.isLaunchTarget;
221296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.isHistorical = o.isHistorical;
2228be1634a543022bd6ee0c1e974d3201d452981e8Winson        this.isSystemApp = o.isSystemApp;
223931845fcb3823ce175fcfc7c6ce2d9751102c331Winson        this.isDockable = o.isDockable;
224303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
225303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
226b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    /**
227b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung     * Add a callback.
228b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung     */
229b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    public void addCallback(TaskCallbacks cb) {
230b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        if (!mCallbacks.contains(cb)) {
231b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung            mCallbacks.add(cb);
232b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        }
233b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    }
234b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung
235b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    /**
236b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung     * Remove a callback.
237b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung     */
238b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung    public void removeCallback(TaskCallbacks cb) {
239b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        mCallbacks.remove(cb);
240303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
241303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
242ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung    /** Set the grouping */
243ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung    public void setGroup(TaskGrouping group) {
244ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung        this.group = group;
245ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung    }
246ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chung
247eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson    /**
248eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson     * Updates the stack id of this task.
249eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson     */
250d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung    public void setStackId(int stackId) {
2515500390a006f2bbea565068234774a36cea076c0Winson        key.setStackId(stackId);
252b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        int callbackCount = mCallbacks.size();
253b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        for (int i = 0; i < callbackCount; i++) {
254b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung            mCallbacks.get(i).onTaskStackIdChanged();
255d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung        }
256d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung    }
257d16c565a607de754379fe699a4def21bd0e3de2fWinson Chung
258eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson    /**
259eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson     * Returns whether this task is on the freeform task stack.
260eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson     */
26123afcae84422ac7c9687b17a6193f74264361303Winson    public boolean isFreeformTask() {
262eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson        SystemServicesProxy ssp = Recents.getSystemServices();
263eca4ab6e99bcb2a7b31b8b4b1c3b5474297b6b25Winson        return ssp.hasFreeformWorkspaceSupport() && ssp.isFreeformStack(key.stackId);
26423afcae84422ac7c9687b17a6193f74264361303Winson    }
26523afcae84422ac7c9687b17a6193f74264361303Winson
2664d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung    /** Notifies the callback listeners that this task has been loaded */
2678eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung    public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon) {
268296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        this.icon = applicationIcon;
2694d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung        this.thumbnail = thumbnail;
270b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        int callbackCount = mCallbacks.size();
271b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung        for (int i = 0; i < callbackCount; i++) {
272b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung            mCallbacks.get(i).onTaskDataLoaded(this);
2734d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung        }
2744d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung    }
2754d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung
2764d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung    /** Notifies the callback listeners that this task has been unloaded */
2775e3e5d8945249cfeb8bd59de112be88954ba62bfWinson Chung    public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
278296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        icon = defaultApplicationIcon;
2794d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung        thumbnail = defaultThumbnail;
280f24f21695f5609d06402cf61e3500d408b99bdcbWinson        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
281b169ebd4c40b78d8a4c79e416c288af2ab5b5046Winson Chung            mCallbacks.get(i).onTaskDataUnloaded();
2824d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung        }
2834d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung    }
2844d7b092a866d2fce3e11b5a12cda2b87a83af52dWinson Chung
2852b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung    /**
2862b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung     * Returns whether this task is affiliated with another task.
2872b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung     */
2882b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung    public boolean isAffiliatedTask() {
289296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung        return key.id != affiliationTaskId;
2902b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung    }
2912b9ef6548be89d36ea7629f4a3d8ba7bba1422ceWinson Chung
292303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    @Override
293303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    public boolean equals(Object o) {
294a10370fc2eb8eb95631592160c5f6281b9d75722Winson Chung        // Check that the id matches
295303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        Task t = (Task) o;
29604dfe0d26b944324ee920001f40d74cff47281d6Winson Chung        return key.equals(t.key);
297303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
298303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
299303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    @Override
300303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    public String toString() {
3018873754f66527d2cc9feab295dd4eef23298212aWinson        return "[" + key.toString() + "] " + title;
302303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
303303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung}
304