1 /* 2 * Copyright (C) 2019 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 package com.android.quickstep; 17 18 import androidx.annotation.NonNull; 19 import androidx.recyclerview.widget.RecyclerView.ViewHolder; 20 21 import com.android.quickstep.views.TaskItemView; 22 import com.android.systemui.shared.recents.model.Task; 23 24 import java.util.Optional; 25 26 /** 27 * A recycler view holder that holds the task view and binds {@link Task} content (app title, icon, 28 * etc.) to the view. 29 */ 30 public final class TaskHolder extends ViewHolder { 31 32 private final TaskItemView mTaskItemView; 33 private Task mTask; 34 TaskHolder(TaskItemView itemView)35 public TaskHolder(TaskItemView itemView) { 36 super(itemView); 37 mTaskItemView = itemView; 38 } 39 getTaskItemView()40 public TaskItemView getTaskItemView() { 41 return mTaskItemView; 42 } 43 44 /** 45 * Bind the task model to the holder. This will take the current task content in the task 46 * object (i.e. icon, thumbnail, label) and either apply the content immediately or simply bind 47 * the content to animate to at a later time. If the task does not have all its content loaded, 48 * the view will prepare appropriate default placeholders and it is the callers responsibility 49 * to change them at a later time. 50 * 51 * Regardless of whether it is animating, input handlers will be bound immediately (see 52 * {@link TaskActionController}). 53 * 54 * @param task the task to bind to the view 55 * @param willAnimate true if UI should animate in later, false if it should apply immediately 56 */ bindTask(@onNull Task task, boolean willAnimate)57 public void bindTask(@NonNull Task task, boolean willAnimate) { 58 mTask = task; 59 if (willAnimate) { 60 mTaskItemView.startContentAnimation(task.icon, task.thumbnail, task.titleDescription); 61 } else { 62 mTaskItemView.setIcon(task.icon); 63 mTaskItemView.setThumbnail(task.thumbnail); 64 mTaskItemView.setLabel(task.titleDescription); 65 } 66 } 67 68 /** 69 * Bind a generic empty UI to the holder to make it clear that the item is loading/unbound and 70 * should not be expected to react to user input. 71 */ bindEmptyUi()72 public void bindEmptyUi() { 73 mTask = null; 74 mTaskItemView.resetToEmptyUi(); 75 } 76 77 /** 78 * Gets the task currently bound to this view. May be null if task holder is in a loading state. 79 * 80 * @return the current task 81 */ getTask()82 public Optional<Task> getTask() { 83 return Optional.ofNullable(mTask); 84 } 85 } 86