blob: a0ff3b7dda8cbb913bd356fe7d127cc18224c3b7 [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;
Winson Chung303e1ff2014-03-07 15:06:19 -080022
23
24/**
25 * A task represents the top most task in the system's task stack.
26 */
27public class Task {
Winson Chung04dfe0d2014-03-14 14:06:29 -070028 /* Task callbacks */
29 public interface TaskCallbacks {
30 /* Notifies when a task has been bound */
Winson Chung4c71aef2014-03-21 15:15:11 -070031 public void onTaskDataLoaded(boolean reloadingTaskData);
Winson Chung04dfe0d2014-03-14 14:06:29 -070032 /* Notifies when a task has been unbound */
33 public void onTaskDataUnloaded();
34 }
35
36 /* The Task Key represents the unique primary key for the task */
37 public static class TaskKey {
38 public final int id;
Winson Chungc6a16232014-04-01 14:04:48 -070039 public final Intent baseIntent;
Winson Chung04dfe0d2014-03-14 14:06:29 -070040
41 public TaskKey(int id, Intent intent) {
42 this.id = id;
Winson Chungc6a16232014-04-01 14:04:48 -070043 this.baseIntent = intent;
Winson Chung04dfe0d2014-03-14 14:06:29 -070044 }
45
46 @Override
47 public boolean equals(Object o) {
48 return hashCode() == o.hashCode();
49 }
50
51 @Override
52 public int hashCode() {
53 return id;
54 }
55
56 @Override
57 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -070058 return "Task.Key: " + id + ", " + baseIntent.getComponent().getPackageName();
Winson Chung04dfe0d2014-03-14 14:06:29 -070059 }
60 }
61
62 public TaskKey key;
Winson Chung5e3e5d82014-04-02 15:44:55 -070063 public Drawable applicationIcon;
64 public String activityLabel;
65 public Bitmap activityIcon;
Winson Chung303e1ff2014-03-07 15:06:19 -080066 public Bitmap thumbnail;
Winson Chung4be04452014-03-24 17:22:30 -070067 public boolean isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +010068 public int userId;
Winson Chung303e1ff2014-03-07 15:06:19 -080069
70 TaskCallbacks mCb;
71
Winson Chung5e3e5d82014-04-02 15:44:55 -070072 public Task(int id, boolean isActive, Intent intent, String activityTitle,
Kenny Guy1f1cce12014-04-04 14:47:50 +010073 Bitmap activityIcon, int userId) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070074 this.key = new TaskKey(id, intent);
Winson Chung5e3e5d82014-04-02 15:44:55 -070075 this.activityLabel = activityTitle;
76 this.activityIcon = activityIcon;
Winson Chung4be04452014-03-24 17:22:30 -070077 this.isActive = isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +010078 this.userId = userId;
Winson Chung303e1ff2014-03-07 15:06:19 -080079 }
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 Chung5e3e5d82014-04-02 15:44:55 -070087 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon,
88 boolean reloadingTaskData) {
89 this.applicationIcon = applicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -070090 this.thumbnail = thumbnail;
91 if (mCb != null) {
Winson Chung4c71aef2014-03-21 15:15:11 -070092 mCb.onTaskDataLoaded(reloadingTaskData);
Winson Chung4d7b0922014-03-13 17:14:17 -070093 }
94 }
95
96 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -070097 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
98 applicationIcon = defaultApplicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -070099 thumbnail = defaultThumbnail;
100 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700101 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700102 }
103 }
104
Winson Chung303e1ff2014-03-07 15:06:19 -0800105 @Override
106 public boolean equals(Object o) {
Winson Chunga10370f2014-04-02 12:25:04 -0700107 // Check that the id matches
Winson Chung303e1ff2014-03-07 15:06:19 -0800108 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700109 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800110 }
111
112 @Override
113 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -0700114 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800115 }
116}