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