blob: 0c3c528b223d50214d2e2cb7d3433b1ff6cd83b5 [file] [log] [blame]
Winson Chung303e1ff2014-03-07 15:06:19 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.recents.model;
18
19import android.content.Intent;
20import android.graphics.Bitmap;
21import android.graphics.drawable.Drawable;
22import com.android.systemui.recents.Constants;
23
24
25/**
26 * A task represents the top most task in the system's task stack.
27 */
28public class Task {
Winson Chung04dfe0d2014-03-14 14:06:29 -070029 /* Task callbacks */
30 public interface TaskCallbacks {
31 /* Notifies when a task has been bound */
32 public void onTaskDataLoaded();
33 /* Notifies when a task has been unbound */
34 public void onTaskDataUnloaded();
35 }
36
37 /* The Task Key represents the unique primary key for the task */
38 public static class TaskKey {
39 public final int id;
40 public final Intent intent;
41
42 public TaskKey(int id, Intent intent) {
43 this.id = id;
44 this.intent = intent;
45 }
46
47 @Override
48 public boolean equals(Object o) {
49 return hashCode() == o.hashCode();
50 }
51
52 @Override
53 public int hashCode() {
54 return id;
55 }
56
57 @Override
58 public String toString() {
59 return "Task.Key: " + id + ", " + intent.getComponent().getPackageName();
60 }
61 }
62
63 public TaskKey key;
Winson Chung303e1ff2014-03-07 15:06:19 -080064 public String title;
65 public Drawable icon;
66 public Bitmap thumbnail;
67
68 TaskCallbacks mCb;
69
Winson Chung04dfe0d2014-03-14 14:06:29 -070070 public Task(int id, Intent intent, String activityTitle) {
71 this(id, intent, activityTitle, null, null);
72 }
73
Winson Chung303e1ff2014-03-07 15:06:19 -080074 public Task(int id, Intent intent, String activityTitle, Drawable icon, Bitmap thumbnail) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070075 this.key = new TaskKey(id, intent);
Winson Chung303e1ff2014-03-07 15:06:19 -080076 this.title = activityTitle;
77 this.icon = icon;
78 this.thumbnail = thumbnail;
79 }
80
81 /** Set the callbacks */
82 public void setCallbacks(TaskCallbacks cb) {
83 mCb = cb;
84 }
85
Winson Chung4d7b0922014-03-13 17:14:17 -070086 /** Notifies the callback listeners that this task has been loaded */
Winson Chung04dfe0d2014-03-14 14:06:29 -070087 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable icon) {
Winson Chung4d7b0922014-03-13 17:14:17 -070088 this.icon = icon;
89 this.thumbnail = thumbnail;
90 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070091 mCb.onTaskDataLoaded();
Winson Chung4d7b0922014-03-13 17:14:17 -070092 }
93 }
94
95 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung04dfe0d2014-03-14 14:06:29 -070096 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultIcon) {
Winson Chung4d7b0922014-03-13 17:14:17 -070097 icon = defaultIcon;
98 thumbnail = defaultThumbnail;
99 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700100 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700101 }
102 }
103
Winson Chung303e1ff2014-03-07 15:06:19 -0800104 @Override
105 public boolean equals(Object o) {
106 // If we have multiple task entries for the same task, then we do the simple object
107 // equality check
108 if (Constants.Values.RecentsTaskLoader.TaskEntryMultiplier > 1) {
109 return super.equals(o);
110 }
111
112 // Otherwise, check that the id and intent match (the other fields can be asynchronously
113 // loaded and is unsuitable to testing the identity of this Task)
114 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700115 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800116 }
117
118 @Override
119 public String toString() {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700120 return "Task: " + key.intent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800121 }
122}