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