blob: 677334d7297be0328c105766b8b16715d3b22d39 [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 */
Winson Chung4c71aef2014-03-21 15:15:11 -070032 public void onTaskDataLoaded(boolean reloadingTaskData);
Winson Chung04dfe0d2014-03-14 14:06:29 -070033 /* 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;
Winson Chungc6a16232014-04-01 14:04:48 -070040 public final Intent baseIntent;
Winson Chung04dfe0d2014-03-14 14:06:29 -070041
42 public TaskKey(int id, Intent intent) {
43 this.id = id;
Winson Chungc6a16232014-04-01 14:04:48 -070044 this.baseIntent = intent;
Winson Chung04dfe0d2014-03-14 14:06:29 -070045 }
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() {
Winson Chungc6a16232014-04-01 14:04:48 -070059 return "Task.Key: " + id + ", " + baseIntent.getComponent().getPackageName();
Winson Chung04dfe0d2014-03-14 14:06:29 -070060 }
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;
Winson Chung4be04452014-03-24 17:22:30 -070067 public boolean isActive;
Winson Chung303e1ff2014-03-07 15:06:19 -080068
69 TaskCallbacks mCb;
70
Winson Chung4be04452014-03-24 17:22:30 -070071 public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon) {
72 this(id, isActive, intent, activityTitle, icon, null);
Winson Chung04dfe0d2014-03-14 14:06:29 -070073 }
74
Winson Chung4be04452014-03-24 17:22:30 -070075 public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon,
76 Bitmap thumbnail) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070077 this.key = new TaskKey(id, intent);
Winson Chung303e1ff2014-03-07 15:06:19 -080078 this.title = activityTitle;
79 this.icon = icon;
80 this.thumbnail = thumbnail;
Winson Chung4be04452014-03-24 17:22:30 -070081 this.isActive = isActive;
Winson Chung303e1ff2014-03-07 15:06:19 -080082 }
83
84 /** Set the callbacks */
85 public void setCallbacks(TaskCallbacks cb) {
86 mCb = cb;
87 }
88
Winson Chung4d7b0922014-03-13 17:14:17 -070089 /** Notifies the callback listeners that this task has been loaded */
Winson Chung4c71aef2014-03-21 15:15:11 -070090 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable icon, boolean reloadingTaskData) {
Winson Chung4d7b0922014-03-13 17:14:17 -070091 this.icon = icon;
92 this.thumbnail = thumbnail;
93 if (mCb != null) {
Winson Chung4c71aef2014-03-21 15:15:11 -070094 mCb.onTaskDataLoaded(reloadingTaskData);
Winson Chung4d7b0922014-03-13 17:14:17 -070095 }
96 }
97
98 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung04dfe0d2014-03-14 14:06:29 -070099 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultIcon) {
Winson Chung4d7b0922014-03-13 17:14:17 -0700100 icon = defaultIcon;
101 thumbnail = defaultThumbnail;
102 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700103 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700104 }
105 }
106
Winson Chung303e1ff2014-03-07 15:06:19 -0800107 @Override
108 public boolean equals(Object o) {
109 // If we have multiple task entries for the same task, then we do the simple object
110 // equality check
111 if (Constants.Values.RecentsTaskLoader.TaskEntryMultiplier > 1) {
112 return super.equals(o);
113 }
114
115 // Otherwise, check that the id and intent match (the other fields can be asynchronously
116 // loaded and is unsuitable to testing the identity of this Task)
117 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700118 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800119 }
120
121 @Override
122 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -0700123 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800124 }
125}