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; |
| 21 | import android.graphics.drawable.Drawable; |
| 22 | import com.android.systemui.recents.Constants; |
| 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; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 41 | |
| 42 | public TaskKey(int id, Intent intent) { |
| 43 | this.id = id; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame^] | 44 | this.baseIntent = intent; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean equals(Object o) { |
| 49 | return hashCode() == o.hashCode(); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public int hashCode() { |
| 54 | return id; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame^] | 59 | return "Task.Key: " + id + ", " + baseIntent.getComponent().getPackageName(); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | public TaskKey key; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 64 | public String title; |
| 65 | public Drawable icon; |
| 66 | public Bitmap thumbnail; |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 67 | public boolean isActive; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 68 | |
| 69 | TaskCallbacks mCb; |
| 70 | |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 71 | public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon) { |
| 72 | this(id, isActive, intent, activityTitle, icon, null); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 75 | public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon, |
| 76 | Bitmap thumbnail) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 77 | this.key = new TaskKey(id, intent); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 78 | this.title = activityTitle; |
| 79 | this.icon = icon; |
| 80 | this.thumbnail = thumbnail; |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 81 | this.isActive = isActive; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** Set the callbacks */ |
| 85 | public void setCallbacks(TaskCallbacks cb) { |
| 86 | mCb = cb; |
| 87 | } |
| 88 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 89 | /** Notifies the callback listeners that this task has been loaded */ |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 90 | public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable icon, boolean reloadingTaskData) { |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 91 | this.icon = icon; |
| 92 | this.thumbnail = thumbnail; |
| 93 | if (mCb != null) { |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 94 | mCb.onTaskDataLoaded(reloadingTaskData); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | /** Notifies the callback listeners that this task has been unloaded */ |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 99 | public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultIcon) { |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 100 | icon = defaultIcon; |
| 101 | thumbnail = defaultThumbnail; |
| 102 | if (mCb != null) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 103 | mCb.onTaskDataUnloaded(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 107 | @Override |
| 108 | public boolean equals(Object o) { |
| 109 | // If we have multiple task entries for the same task, then we do the simple object |
| 110 | // equality check |
| 111 | if (Constants.Values.RecentsTaskLoader.TaskEntryMultiplier > 1) { |
| 112 | return super.equals(o); |
| 113 | } |
| 114 | |
| 115 | // Otherwise, check that the id and intent match (the other fields can be asynchronously |
| 116 | // loaded and is unsuitable to testing the identity of this Task) |
| 117 | Task t = (Task) o; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 118 | return key.equals(t.key); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public String toString() { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame^] | 123 | return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 124 | } |
| 125 | } |