blob: 6b63b6114e8934c0e865126035f3806e2d55cde2 [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;
Winson Chung11e41ba2014-04-21 12:39:20 -070021import android.graphics.drawable.BitmapDrawable;
Winson Chung303e1ff2014-03-07 15:06:19 -080022import android.graphics.drawable.Drawable;
Winson Chung8eaeb7d2014-06-25 15:10:59 -070023import com.android.systemui.recents.Utilities;
Winson Chung303e1ff2014-03-07 15:06:19 -080024
25
26/**
27 * A task represents the top most task in the system's task stack.
28 */
29public class Task {
Winson Chung04dfe0d2014-03-14 14:06:29 -070030 /* Task callbacks */
31 public interface TaskCallbacks {
32 /* Notifies when a task has been bound */
Winson Chung8eaeb7d2014-06-25 15:10:59 -070033 public void onTaskDataLoaded();
Winson Chung04dfe0d2014-03-14 14:06:29 -070034 /* Notifies when a task has been unbound */
35 public void onTaskDataUnloaded();
36 }
37
38 /* The Task Key represents the unique primary key for the task */
39 public static class TaskKey {
40 public final int id;
Winson Chungc6a16232014-04-01 14:04:48 -070041 public final Intent baseIntent;
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070042 public final int userId;
Winson Chungf1fbd772014-06-24 18:06:58 -070043 public long lastActiveTime;
Winson Chung04dfe0d2014-03-14 14:06:29 -070044
Winson Chungf1fbd772014-06-24 18:06:58 -070045 public TaskKey(int id, Intent intent, int userId, long lastActiveTime) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070046 this.id = id;
Winson Chungc6a16232014-04-01 14:04:48 -070047 this.baseIntent = intent;
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070048 this.userId = userId;
Winson Chungf1fbd772014-06-24 18:06:58 -070049 this.lastActiveTime = lastActiveTime;
50 }
51
52 public void updateLastActiveTime(long lastActiveTime) {
53 this.lastActiveTime = lastActiveTime;
Winson Chung04dfe0d2014-03-14 14:06:29 -070054 }
55
56 @Override
57 public boolean equals(Object o) {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070058 if (!(o instanceof TaskKey)) {
59 return false;
60 }
61 return id == ((TaskKey) o).id
62 && userId == ((TaskKey) o).userId;
Winson Chung04dfe0d2014-03-14 14:06:29 -070063 }
64
65 @Override
66 public int hashCode() {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070067 return (id << 5) + userId;
Winson Chung04dfe0d2014-03-14 14:06:29 -070068 }
69
70 @Override
71 public String toString() {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070072 return "Task.Key: " + id + ", "
Winson Chungf1fbd772014-06-24 18:06:58 -070073 + "u: " + userId + ", "
74 + "lat: " + lastActiveTime + ", "
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070075 + baseIntent.getComponent().getPackageName();
Winson Chung04dfe0d2014-03-14 14:06:29 -070076 }
77 }
78
79 public TaskKey key;
Winson Chung5e3e5d82014-04-02 15:44:55 -070080 public Drawable applicationIcon;
Winson Chung11e41ba2014-04-21 12:39:20 -070081 public Drawable activityIcon;
Winson Chung5e3e5d82014-04-02 15:44:55 -070082 public String activityLabel;
Winson Chungf5e22e72014-05-02 18:35:35 -070083 public int colorPrimary;
Winson Chung8eaeb7d2014-06-25 15:10:59 -070084 public int colorPrimaryGreyscale;
Winson Chung303e1ff2014-03-07 15:06:19 -080085 public Bitmap thumbnail;
Winson Chung4be04452014-03-24 17:22:30 -070086 public boolean isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +010087 public int userId;
Winson Chung303e1ff2014-03-07 15:06:19 -080088
89 TaskCallbacks mCb;
90
Winson Chung0d767552014-04-09 14:33:23 -070091 public Task() {
92 // Only used by RecentsService for task rect calculations.
93 }
94
Winson Chung5e3e5d82014-04-02 15:44:55 -070095 public Task(int id, boolean isActive, Intent intent, String activityTitle,
Winson Chungf1fbd772014-06-24 18:06:58 -070096 BitmapDrawable activityIcon, int colorPrimary, int userId, long lastActiveTime) {
97 this.key = new TaskKey(id, intent, userId, lastActiveTime);
Winson Chung5e3e5d82014-04-02 15:44:55 -070098 this.activityLabel = activityTitle;
99 this.activityIcon = activityIcon;
Winson Chungf5e22e72014-05-02 18:35:35 -0700100 this.colorPrimary = colorPrimary;
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700101 this.colorPrimaryGreyscale = Utilities.colorToGreyscale(colorPrimary);
Winson Chung4be04452014-03-24 17:22:30 -0700102 this.isActive = isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +0100103 this.userId = userId;
Winson Chung303e1ff2014-03-07 15:06:19 -0800104 }
105
106 /** Set the callbacks */
107 public void setCallbacks(TaskCallbacks cb) {
108 mCb = cb;
109 }
110
Winson Chung4d7b0922014-03-13 17:14:17 -0700111 /** Notifies the callback listeners that this task has been loaded */
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700112 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon) {
Winson Chung5e3e5d82014-04-02 15:44:55 -0700113 this.applicationIcon = applicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -0700114 this.thumbnail = thumbnail;
115 if (mCb != null) {
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700116 mCb.onTaskDataLoaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700117 }
118 }
119
120 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -0700121 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
122 applicationIcon = defaultApplicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -0700123 thumbnail = defaultThumbnail;
124 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700125 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700126 }
127 }
128
Winson Chung303e1ff2014-03-07 15:06:19 -0800129 @Override
130 public boolean equals(Object o) {
Winson Chunga10370f2014-04-02 12:25:04 -0700131 // Check that the id matches
Winson Chung303e1ff2014-03-07 15:06:19 -0800132 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700133 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800134 }
135
136 @Override
137 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -0700138 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800139 }
140}