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; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | |
| 23 | |
| 24 | /** |
| 25 | * A task represents the top most task in the system's task stack. |
| 26 | */ |
| 27 | public class Task { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 28 | /* Task callbacks */ |
| 29 | public interface TaskCallbacks { |
| 30 | /* Notifies when a task has been bound */ |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 31 | public void onTaskDataLoaded(boolean reloadingTaskData); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 32 | /* 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 Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 39 | public final Intent baseIntent; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 40 | |
| 41 | public TaskKey(int id, Intent intent) { |
| 42 | this.id = id; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 43 | this.baseIntent = intent; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 44 | } |
| 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 Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 58 | return "Task.Key: " + id + ", " + baseIntent.getComponent().getPackageName(); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | public TaskKey key; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame^] | 63 | public Drawable applicationIcon; |
| 64 | public String activityLabel; |
| 65 | public Bitmap activityIcon; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 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 | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame^] | 71 | public Task(int id, boolean isActive, Intent intent, String activityTitle, |
| 72 | Bitmap activityIcon) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 73 | this.key = new TaskKey(id, intent); |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame^] | 74 | this.activityLabel = activityTitle; |
| 75 | this.activityIcon = activityIcon; |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 76 | this.isActive = isActive; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** Set the callbacks */ |
| 80 | public void setCallbacks(TaskCallbacks cb) { |
| 81 | mCb = cb; |
| 82 | } |
| 83 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 84 | /** Notifies the callback listeners that this task has been loaded */ |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame^] | 85 | public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon, |
| 86 | boolean reloadingTaskData) { |
| 87 | this.applicationIcon = applicationIcon; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 88 | this.thumbnail = thumbnail; |
| 89 | if (mCb != null) { |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 90 | mCb.onTaskDataLoaded(reloadingTaskData); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | /** Notifies the callback listeners that this task has been unloaded */ |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame^] | 95 | public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) { |
| 96 | applicationIcon = defaultApplicationIcon; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 97 | thumbnail = defaultThumbnail; |
| 98 | if (mCb != null) { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 99 | mCb.onTaskDataUnloaded(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 103 | @Override |
| 104 | public boolean equals(Object o) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 105 | // Check that the id matches |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 106 | Task t = (Task) o; |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 107 | return key.equals(t.key); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public String toString() { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 112 | return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 113 | } |
| 114 | } |