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