Task.java revision 4f0a49e6b9ad1b00972dbe8a751263aa6c482538
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 public final int userId; 41 42 public TaskKey(int id, Intent intent, int userId) { 43 this.id = id; 44 this.baseIntent = intent; 45 this.userId = userId; 46 } 47 48 @Override 49 public boolean equals(Object o) { 50 if (!(o instanceof TaskKey)) { 51 return false; 52 } 53 return id == ((TaskKey) o).id 54 && userId == ((TaskKey) o).userId; 55 } 56 57 @Override 58 public int hashCode() { 59 return (id << 5) + userId; 60 } 61 62 @Override 63 public String toString() { 64 return "Task.Key: " + id + ", " 65 + "u" + userId + ", " 66 + baseIntent.getComponent().getPackageName(); 67 } 68 } 69 70 public TaskKey key; 71 public Drawable applicationIcon; 72 public String activityLabel; 73 public Bitmap activityIcon; 74 public Bitmap thumbnail; 75 public boolean isActive; 76 public int userId; 77 78 TaskCallbacks mCb; 79 80 public Task(int id, boolean isActive, Intent intent, String activityTitle, 81 Bitmap activityIcon, int userId) { 82 this.key = new TaskKey(id, intent, userId); 83 this.activityLabel = activityTitle; 84 this.activityIcon = activityIcon; 85 this.isActive = isActive; 86 this.userId = userId; 87 } 88 89 /** Set the callbacks */ 90 public void setCallbacks(TaskCallbacks cb) { 91 mCb = cb; 92 } 93 94 /** Notifies the callback listeners that this task has been loaded */ 95 public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon, 96 boolean reloadingTaskData) { 97 this.applicationIcon = applicationIcon; 98 this.thumbnail = thumbnail; 99 if (mCb != null) { 100 mCb.onTaskDataLoaded(reloadingTaskData); 101 } 102 } 103 104 /** Notifies the callback listeners that this task has been unloaded */ 105 public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) { 106 applicationIcon = defaultApplicationIcon; 107 thumbnail = defaultThumbnail; 108 if (mCb != null) { 109 mCb.onTaskDataUnloaded(); 110 } 111 } 112 113 @Override 114 public boolean equals(Object o) { 115 // Check that the id matches 116 Task t = (Task) o; 117 return key.equals(t.key); 118 } 119 120 @Override 121 public String toString() { 122 return "Task: " + key.baseIntent.getComponent().getPackageName() + " [" + super.toString() + "]"; 123 } 124} 125