2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.android
.systemui
.recents
.tv
.views
;
18 import android
.animation
.Animator
;
19 import android
.animation
.AnimatorSet
;
20 import android
.content
.Context
;
21 import android
.support
.v17
.leanback
.widget
.HorizontalGridView
;
22 import android
.util
.AttributeSet
;
23 import android
.view
.View
;
25 import com
.android
.systemui
.R
;
26 import com
.android
.systemui
.recents
.RecentsActivity
;
27 import com
.android
.systemui
.recents
.events
.EventBus
;
28 import com
.android
.systemui
.recents
.events
.ui
.AllTaskViewsDismissedEvent
;
29 import com
.android
.systemui
.recents
.model
.Task
;
30 import com
.android
.systemui
.recents
.model
.TaskStack
;
31 import com
.android
.systemui
.recents
.model
.TaskStack
.TaskStackCallbacks
;
32 import com
.android
.systemui
.recents
.views
.AnimationProps
;
35 * Horizontal Grid View Implementation to show the Task Stack for TV.
37 public class TaskStackHorizontalGridView
extends HorizontalGridView
implements TaskStackCallbacks
{
38 private static final int ANIMATION_DELAY_MS
= 50;
39 private static final int MSG_START_RECENT_ROW_FOCUS_ANIMATION
= 100;
40 private TaskStack mStack
;
41 private Task mFocusedTask
;
42 private AnimatorSet mRecentsRowFocusAnimation
;
44 public TaskStackHorizontalGridView(Context context
) {
48 public TaskStackHorizontalGridView(Context context
, AttributeSet attrs
) {
49 super(context
, attrs
);
53 protected void onAttachedToWindow() {
54 EventBus
.getDefault().register(this, RecentsActivity
.EVENT_BUS_PRIORITY
+ 1);
55 setWindowAlignment(WINDOW_ALIGN_NO_EDGE
);
56 setImportantForAccessibility(View
.IMPORTANT_FOR_ACCESSIBILITY_YES
);
57 super.onAttachedToWindow();
61 protected void onDetachedFromWindow() {
62 super.onDetachedFromWindow();
63 EventBus
.getDefault().unregister(this);
67 * Initializes the grid view.
70 public void init(TaskStack stack
) {
74 mStack
.setCallbacks(this);
79 * @return Returns the task stack.
81 public TaskStack
getStack() {
86 * @return - The focused task.
88 public Task
getFocusedTask() {
89 if (findFocus() != null) {
90 mFocusedTask
= ((TaskCardView
)findFocus()).getTask();
97 * @return Child view for given task
99 public TaskCardView
getChildViewForTask(Task task
) {
100 for (int i
= 0; i
< getChildCount(); i
++) {
101 TaskCardView tv
= (TaskCardView
) getChildAt(i
);
102 if (tv
.getTask() == task
) {
111 * Starts the Recents row's focus gain animation.
113 public void startFocusGainAnimation() {
114 for (int i
= 0; i
< getChildCount(); i
++) {
115 TaskCardView v
= (TaskCardView
) getChildAt(i
);
117 v
.getViewFocusAnimator().changeSize(true);
119 v
.getRecentsRowFocusAnimationHolder().startFocusGainAnimation();
124 * Starts the Recents row's focus loss animation.
126 public void startFocusLossAnimation() {
127 for (int i
= 0; i
< getChildCount(); i
++) {
128 TaskCardView v
= (TaskCardView
) getChildAt(i
);
130 v
.getViewFocusAnimator().changeSize(false);
132 v
.getRecentsRowFocusAnimationHolder().startFocusLossAnimation();
137 public void onStackTaskAdded(TaskStack stack
, Task newTask
) {
138 ((TaskStackHorizontalViewAdapter
) getAdapter()).addTaskAt(newTask
,
139 stack
.indexOfStackTask(newTask
));
143 public void onStackTaskRemoved(TaskStack stack
, Task removedTask
, Task newFrontMostTask
,
144 AnimationProps animation
, boolean fromDockGesture
) {
145 ((TaskStackHorizontalViewAdapter
) getAdapter()).removeTask(removedTask
);
146 if (mFocusedTask
== removedTask
) {
149 // If there are no remaining tasks, then just close recents
150 if (mStack
.getStackTaskCount() == 0) {
151 boolean shouldFinishActivity
= (mStack
.getStackTaskCount() == 0);
152 if (shouldFinishActivity
) {
153 EventBus
.getDefault().send(new AllTaskViewsDismissedEvent(fromDockGesture
154 ? R
.string
.recents_empty_message
155 : R
.string
.recents_empty_message_dismissed_all
));
161 public void onStackTasksRemoved(TaskStack stack
) {
166 public void onStackTasksUpdated(TaskStack stack
) {