Task.java revision a10370fc2eb8eb95631592160c5f6281b9d75722
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 String title; 64 public Drawable icon; 65 public Bitmap thumbnail; 66 public boolean isActive; 67 68 TaskCallbacks mCb; 69 70 public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon) { 71 this(id, isActive, intent, activityTitle, icon, null); 72 } 73 74 public Task(int id, boolean isActive, Intent intent, String activityTitle, Drawable icon, 75 Bitmap thumbnail) { 76 this.key = new TaskKey(id, intent); 77 this.title = activityTitle; 78 this.icon = icon; 79 this.thumbnail = thumbnail; 80 this.isActive = isActive; 81 } 82 83 /** Set the callbacks */ 84 public void setCallbacks(TaskCallbacks cb) { 85 mCb = cb; 86 } 87 88 /** Notifies the callback listeners that this task has been loaded */ 89 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable icon, boolean reloadingTaskData) { 90 this.icon = icon; 91 this.thumbnail = thumbnail; 92 if (mCb != null) { 93 mCb.onTaskDataLoaded(reloadingTaskData); 94 } 95 } 96 97 /** Notifies the callback listeners that this task has been unloaded */ 98 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultIcon) { 99 icon = defaultIcon; 100 thumbnail = defaultThumbnail; 101 if (mCb != null) { 102 mCb.onTaskDataUnloaded(); 103 } 104 } 105 106 @Override 107 public boolean equals(Object o) { 108 // Check that the id matches 109 Task t = (Task) o; 110 return key.equals(t.key); 111 } 112 113 @Override 114 public String toString() { 115 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; 116 } 117} 118