blob: cba9e5ab5675640d42ec0f549faf064b69c1f21e [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 Chung303e1ff2014-03-07 15:06:19 -080023
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;
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070041 public final int userId;
Winson Chungf1fbd772014-06-24 18:06:58 -070042 public long lastActiveTime;
Winson Chung04dfe0d2014-03-14 14:06:29 -070043
Winson Chungf1fbd772014-06-24 18:06:58 -070044 public TaskKey(int id, Intent intent, int userId, long lastActiveTime) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070045 this.id = id;
Winson Chungc6a16232014-04-01 14:04:48 -070046 this.baseIntent = intent;
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070047 this.userId = userId;
Winson Chungf1fbd772014-06-24 18:06:58 -070048 this.lastActiveTime = lastActiveTime;
49 }
50
51 public void updateLastActiveTime(long lastActiveTime) {
52 this.lastActiveTime = lastActiveTime;
Winson Chung04dfe0d2014-03-14 14:06:29 -070053 }
54
55 @Override
56 public boolean equals(Object o) {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070057 if (!(o instanceof TaskKey)) {
58 return false;
59 }
60 return id == ((TaskKey) o).id
61 && userId == ((TaskKey) o).userId;
Winson Chung04dfe0d2014-03-14 14:06:29 -070062 }
63
64 @Override
65 public int hashCode() {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070066 return (id << 5) + userId;
Winson Chung04dfe0d2014-03-14 14:06:29 -070067 }
68
69 @Override
70 public String toString() {
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070071 return "Task.Key: " + id + ", "
Winson Chungf1fbd772014-06-24 18:06:58 -070072 + "u: " + userId + ", "
73 + "lat: " + lastActiveTime + ", "
Amith Yamasani4f0a49e2014-04-10 13:48:15 -070074 + baseIntent.getComponent().getPackageName();
Winson Chung04dfe0d2014-03-14 14:06:29 -070075 }
76 }
77
78 public TaskKey key;
Winson Chung5e3e5d82014-04-02 15:44:55 -070079 public Drawable applicationIcon;
Winson Chung11e41ba2014-04-21 12:39:20 -070080 public Drawable activityIcon;
Winson Chung5e3e5d82014-04-02 15:44:55 -070081 public String activityLabel;
Winson Chungf5e22e72014-05-02 18:35:35 -070082 public int colorPrimary;
Winson Chung303e1ff2014-03-07 15:06:19 -080083 public Bitmap thumbnail;
Winson Chung4be04452014-03-24 17:22:30 -070084 public boolean isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +010085 public int userId;
Winson Chung303e1ff2014-03-07 15:06:19 -080086
87 TaskCallbacks mCb;
88
Winson Chung0d767552014-04-09 14:33:23 -070089 public Task() {
90 // Only used by RecentsService for task rect calculations.
91 }
92
Winson Chung5e3e5d82014-04-02 15:44:55 -070093 public Task(int id, boolean isActive, Intent intent, String activityTitle,
Winson Chungf1fbd772014-06-24 18:06:58 -070094 BitmapDrawable activityIcon, int colorPrimary, int userId, long lastActiveTime) {
95 this.key = new TaskKey(id, intent, userId, lastActiveTime);
Winson Chung5e3e5d82014-04-02 15:44:55 -070096 this.activityLabel = activityTitle;
97 this.activityIcon = activityIcon;
Winson Chungf5e22e72014-05-02 18:35:35 -070098 this.colorPrimary = colorPrimary;
Winson Chung4be04452014-03-24 17:22:30 -070099 this.isActive = isActive;
Kenny Guy1f1cce12014-04-04 14:47:50 +0100100 this.userId = userId;
Winson Chung303e1ff2014-03-07 15:06:19 -0800101 }
102
103 /** Set the callbacks */
104 public void setCallbacks(TaskCallbacks cb) {
105 mCb = cb;
106 }
107
Winson Chung4d7b0922014-03-13 17:14:17 -0700108 /** Notifies the callback listeners that this task has been loaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -0700109 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon,
110 boolean reloadingTaskData) {
111 this.applicationIcon = applicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -0700112 this.thumbnail = thumbnail;
113 if (mCb != null) {
Winson Chung4c71aef2014-03-21 15:15:11 -0700114 mCb.onTaskDataLoaded(reloadingTaskData);
Winson Chung4d7b0922014-03-13 17:14:17 -0700115 }
116 }
117
118 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -0700119 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
120 applicationIcon = defaultApplicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -0700121 thumbnail = defaultThumbnail;
122 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -0700123 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700124 }
125 }
126
Winson Chung303e1ff2014-03-07 15:06:19 -0800127 @Override
128 public boolean equals(Object o) {
Winson Chunga10370f2014-04-02 12:25:04 -0700129 // Check that the id matches
Winson Chung303e1ff2014-03-07 15:06:19 -0800130 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700131 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800132 }
133
134 @Override
135 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -0700136 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800137 }
138}