Task.java revision 5e3e5d8945249cfeb8bd59de112be88954ba62bf
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 17package com.android.systemui.recents.model; 18 19import android.content.Intent; 20import android.graphics.Bitmap; 21import android.graphics.drawable.Drawable; 22 23 24/** 25 * A task represents the top most task in the system's task stack. 26 */ 27public class Task { 28 /* Task callbacks */ 29 public interface TaskCallbacks { 30 /* Notifies when a task has been bound */ 31 public void onTaskDataLoaded(boolean reloadingTaskData); 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; 39 public final Intent baseIntent; 40 41 public TaskKey(int id, Intent intent) { 42 this.id = id; 43 this.baseIntent = intent; 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() { 58 return "Task.Key: " + id + ", " + baseIntent.getComponent().getPackageName(); 59 } 60 } 61 62 public TaskKey key; 63 public Drawable applicationIcon; 64 public String activityLabel; 65 public Bitmap activityIcon; 66 public Bitmap thumbnail; 67 public boolean isActive; 68 69 TaskCallbacks mCb; 70 71 public Task(int id, boolean isActive, Intent intent, String activityTitle, 72 Bitmap activityIcon) { 73 this.key = new TaskKey(id, intent); 74 this.activityLabel = activityTitle; 75 this.activityIcon = activityIcon; 76 this.isActive = isActive; 77 } 78 79 /** Set the callbacks */ 80 public void setCallbacks(TaskCallbacks cb) { 81 mCb = cb; 82 } 83 84 /** Notifies the callback listeners that this task has been loaded */ 85 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon, 86 boolean reloadingTaskData) { 87 this.applicationIcon = applicationIcon; 88 this.thumbnail = thumbnail; 89 if (mCb != null) { 90 mCb.onTaskDataLoaded(reloadingTaskData); 91 } 92 } 93 94 /** Notifies the callback listeners that this task has been unloaded */ 95 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) { 96 applicationIcon = defaultApplicationIcon; 97 thumbnail = defaultThumbnail; 98 if (mCb != null) { 99 mCb.onTaskDataUnloaded(); 100 } 101 } 102 103 @Override 104 public boolean equals(Object o) { 105 // Check that the id matches 106 Task t = (Task) o; 107 return key.equals(t.key); 108 } 109 110 @Override 111 public String toString() { 112 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; 113 } 114} 115