Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.recents.model; |
| 18 | |
| 19 | import android.content.Intent; |
| 20 | import android.graphics.Bitmap; |
Winson Chung | 11e41ba | 2014-04-21 12:39:20 -0700 | [diff] [blame] | 21 | import android.graphics.drawable.BitmapDrawable; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | import android.graphics.drawable.Drawable; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /** |
| 26 | * A task represents the top most task in the system's task stack. |
| 27 | */ |
| 28 | public class Task { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 29 | /* Task callbacks */ |
| 30 | public interface TaskCallbacks { |
| 31 | /* Notifies when a task has been bound */ |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 32 | public void onTaskDataLoaded(boolean reloadingTaskData); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 33 | /* 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 Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 40 | public final Intent baseIntent; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 41 | public final int userId; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame^] | 42 | public long lastActiveTime; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 43 | |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame^] | 44 | public TaskKey(int id, Intent intent, int userId, long lastActiveTime) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 45 | this.id = id; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 46 | this.baseIntent = intent; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 47 | this.userId = userId; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame^] | 48 | this.lastActiveTime = lastActiveTime; |
| 49 | } |
| 50 | |
| 51 | public void updateLastActiveTime(long lastActiveTime) { |
| 52 | this.lastActiveTime = lastActiveTime; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object o) { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 57 | if (!(o instanceof TaskKey)) { |
| 58 | return false; |
| 59 | } |
| 60 | return id == ((TaskKey) o).id |
| 61 | && userId == ((TaskKey) o).userId; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 66 | return (id << 5) + userId; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String toString() { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 71 | return "Task.Key: " + id + ", " |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame^] | 72 | + "u: " + userId + ", " |
| 73 | + "lat: " + lastActiveTime + ", " |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 74 | + baseIntent.getComponent().getPackageName(); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | public TaskKey key; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 79 | public Drawable applicationIcon; |
Winson Chung | 11e41ba | 2014-04-21 12:39:20 -0700 | [diff] [blame] | 80 | public Drawable activityIcon; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 81 | public String activityLabel; |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 82 | public int colorPrimary; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 83 | public Bitmap thumbnail; |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 84 | public boolean isActive; |
Kenny Guy | 1f1cce1 | 2014-04-04 14:47:50 +0100 | [diff] [blame] | 85 | public int userId; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 86 | |
| 87 | TaskCallbacks mCb; |
| 88 | |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 89 | public Task() { |
| 90 | // Only used by RecentsService for task rect calculations. |
| 91 | } |
| 92 | |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 93 | public Task(int id, boolean isActive, Intent intent, String activityTitle, |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame^] | 94 | BitmapDrawable activityIcon, int colorPrimary, int userId, long lastActiveTime) { |
| 95 | this.key = new TaskKey(id, intent, userId, lastActiveTime); |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 96 | this.activityLabel = activityTitle; |
| 97 | this.activityIcon = activityIcon; |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 98 | this.colorPrimary = colorPrimary; |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 99 | this.isActive = isActive; |
Kenny Guy | 1f1cce1 | 2014-04-04 14:47:50 +0100 | [diff] [blame] | 100 | this.userId = userId; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** Set the callbacks */ |
| 104 | public void setCallbacks(TaskCallbacks cb) { |
| 105 | mCb = cb; |
| 106 | } |
| 107 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 108 | /** Notifies the callback listeners that this task has been loaded */ |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 109 | public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon, |
| 110 | boolean reloadingTaskData) { |
| 111 | this.applicationIcon = applicationIcon; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 112 | this.thumbnail = thumbnail; |
| 113 | if (mCb != null) { |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 114 | mCb.onTaskDataLoaded(reloadingTaskData); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | /** Notifies the callback listeners that this task has been unloaded */ |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 119 | public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) { |
| 120 | applicationIcon = defaultApplicationIcon; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 121 | thumbnail = defaultThumbnail; |
| 122 | if (mCb != null) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 123 | mCb.onTaskDataUnloaded(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 127 | @Override |
| 128 | public boolean equals(Object o) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 129 | // Check that the id matches |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 130 | Task t = (Task) o; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 131 | return key.equals(t.key); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public String toString() { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 136 | return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 137 | } |
| 138 | } |