blob: ed2ab2a5b91f27d39a4678d761a56b2e8bc6dbea [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;
Winson Chung303e1ff2014-03-07 15:06:19 -080068
69 TaskCallbacks mCb;
70
Winson Chung5e3e5d82014-04-02 15:44:55 -070071 public Task(int id, boolean isActive, Intent intent, String activityTitle,
72 Bitmap activityIcon) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070073 this.key = new TaskKey(id, intent);
Winson Chung5e3e5d82014-04-02 15:44:55 -070074 this.activityLabel = activityTitle;
75 this.activityIcon = activityIcon;
Winson Chung4be04452014-03-24 17:22:30 -070076 this.isActive = isActive;
Winson Chung303e1ff2014-03-07 15:06:19 -080077 }
78
79 /** Set the callbacks */
80 public void setCallbacks(TaskCallbacks cb) {
81 mCb = cb;
82 }
83
Winson Chung4d7b0922014-03-13 17:14:17 -070084 /** Notifies the callback listeners that this task has been loaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -070085 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon,
86 boolean reloadingTaskData) {
87 this.applicationIcon = applicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -070088 this.thumbnail = thumbnail;
89 if (mCb != null) {
Winson Chung4c71aef2014-03-21 15:15:11 -070090 mCb.onTaskDataLoaded(reloadingTaskData);
Winson Chung4d7b0922014-03-13 17:14:17 -070091 }
92 }
93
94 /** Notifies the callback listeners that this task has been unloaded */
Winson Chung5e3e5d82014-04-02 15:44:55 -070095 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
96 applicationIcon = defaultApplicationIcon;
Winson Chung4d7b0922014-03-13 17:14:17 -070097 thumbnail = defaultThumbnail;
98 if (mCb != null) {
Winson Chung04dfe0d2014-03-14 14:06:29 -070099 mCb.onTaskDataUnloaded();
Winson Chung4d7b0922014-03-13 17:14:17 -0700100 }
101 }
102
Winson Chung303e1ff2014-03-07 15:06:19 -0800103 @Override
104 public boolean equals(Object o) {
Winson Chunga10370f2014-04-02 12:25:04 -0700105 // Check that the id matches
Winson Chung303e1ff2014-03-07 15:06:19 -0800106 Task t = (Task) o;
Winson Chung04dfe0d2014-03-14 14:06:29 -0700107 return key.equals(t.key);
Winson Chung303e1ff2014-03-07 15:06:19 -0800108 }
109
110 @Override
111 public String toString() {
Winson Chungc6a16232014-04-01 14:04:48 -0700112 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]";
Winson Chung303e1ff2014-03-07 15:06:19 -0800113 }
114}