Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.recents.views; |
| 18 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 20 | import android.view.View; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 21 | |
| 22 | import com.android.systemui.Interpolators; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 23 | import com.android.systemui.R; |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 24 | import com.android.systemui.recents.Recents; |
| 25 | import com.android.systemui.recents.RecentsActivity; |
| 26 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 27 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 28 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 29 | import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent; |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 30 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
| 31 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 32 | |
| 33 | /** Manages the scrims for the various system bars. */ |
| 34 | public class SystemBarScrimViews { |
| 35 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 36 | private static final int DEFAULT_ANIMATION_DURATION = 150; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 37 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 38 | private Context mContext; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 39 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 40 | private View mNavBarScrimView; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 41 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 42 | private boolean mHasNavBarScrim; |
| 43 | private boolean mShouldAnimateNavBarScrim; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 44 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 45 | private int mNavBarScrimEnterDuration; |
| 46 | |
| 47 | public SystemBarScrimViews(RecentsActivity activity) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 48 | mContext = activity; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 49 | mNavBarScrimView = activity.findViewById(R.id.nav_bar_scrim); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 50 | mNavBarScrimView.forceHasOverlappingRendering(false); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 51 | mNavBarScrimEnterDuration = activity.getResources().getInteger( |
| 52 | R.integer.recents_nav_bar_scrim_enter_duration); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 56 | * Updates the nav bar scrim. |
| 57 | */ |
| 58 | public void updateNavBarScrim(boolean animateNavBarScrim, boolean hasStackTasks, |
| 59 | AnimationProps animation) { |
| 60 | prepareEnterRecentsAnimation(isNavBarScrimRequired(hasStackTasks), animateNavBarScrim); |
| 61 | if (animateNavBarScrim && animation != null) { |
| 62 | animateNavBarScrimVisibility(true, animation); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 67 | * Prepares the scrim views for animating when entering Recents. This will be called before |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 68 | * the first draw, unless we are updating the scrim on configuration change. |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 69 | */ |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 70 | private void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 71 | mHasNavBarScrim = hasNavBarScrim; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 72 | mShouldAnimateNavBarScrim = animateNavBarScrim; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 73 | |
| 74 | mNavBarScrimView.setVisibility(mHasNavBarScrim && !mShouldAnimateNavBarScrim ? |
| 75 | View.VISIBLE : View.INVISIBLE); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Animates the nav bar scrim visibility. |
| 80 | */ |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 81 | private void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 82 | int toY = 0; |
| 83 | if (visible) { |
| 84 | mNavBarScrimView.setVisibility(View.VISIBLE); |
| 85 | mNavBarScrimView.setTranslationY(mNavBarScrimView.getMeasuredHeight()); |
| 86 | } else { |
| 87 | toY = mNavBarScrimView.getMeasuredHeight(); |
| 88 | } |
| 89 | if (animation != AnimationProps.IMMEDIATE) { |
| 90 | mNavBarScrimView.animate() |
| 91 | .translationY(toY) |
| 92 | .setDuration(animation.getDuration(AnimationProps.BOUNDS)) |
| 93 | .setInterpolator(animation.getInterpolator(AnimationProps.BOUNDS)) |
| 94 | .start(); |
| 95 | } else { |
| 96 | mNavBarScrimView.setTranslationY(toY); |
| 97 | } |
| 98 | } |
| 99 | |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 100 | /** |
| 101 | * @return Whether to show the nav bar scrim. |
| 102 | */ |
| 103 | private boolean isNavBarScrimRequired(boolean hasStackTasks) { |
| 104 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 105 | return hasStackTasks && !ssp.hasTransposedNavBar() && !ssp.hasDockedTask(); |
| 106 | } |
| 107 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 108 | /**** EventBus events ****/ |
| 109 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Starts animating the scrim views when entering Recents. |
| 112 | */ |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 113 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 114 | if (mHasNavBarScrim) { |
| 115 | AnimationProps animation = mShouldAnimateNavBarScrim |
| 116 | ? new AnimationProps() |
| 117 | .setDuration(AnimationProps.BOUNDS, mNavBarScrimEnterDuration) |
| 118 | .setInterpolator(AnimationProps.BOUNDS, Interpolators.DECELERATE_QUINT) |
| 119 | : AnimationProps.IMMEDIATE; |
| 120 | animateNavBarScrimVisibility(true, animation); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Starts animating the scrim views when leaving Recents (either via launching a task, or |
| 126 | * going home). |
| 127 | */ |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 128 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 129 | if (mHasNavBarScrim) { |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 130 | AnimationProps animation = createBoundsAnimation( |
| 131 | TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 132 | animateNavBarScrimVisibility(false, animation); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 133 | } |
| 134 | } |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 135 | |
| 136 | public final void onBusEvent(DismissAllTaskViewsEvent event) { |
| 137 | if (mHasNavBarScrim) { |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 138 | AnimationProps animation = createBoundsAnimation( |
| 139 | TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION); |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 140 | animateNavBarScrimVisibility(false, animation); |
| 141 | } |
| 142 | } |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 143 | |
| 144 | public final void onBusEvent(ConfigurationChangedEvent event) { |
| 145 | animateScrimToCurrentNavBarState(event.hasStackTasks); |
| 146 | } |
| 147 | |
| 148 | public final void onBusEvent(MultiWindowStateChangedEvent event) { |
| 149 | animateScrimToCurrentNavBarState(event.hasStackTasks); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Animates the scrim to match the state of the current nav bar. |
| 154 | */ |
| 155 | private void animateScrimToCurrentNavBarState(boolean hasStackTasks) { |
| 156 | boolean hasNavBarScrim = isNavBarScrimRequired(hasStackTasks); |
| 157 | if (mHasNavBarScrim != hasNavBarScrim) { |
| 158 | AnimationProps animation = hasNavBarScrim |
| 159 | ? createBoundsAnimation(DEFAULT_ANIMATION_DURATION) |
| 160 | : AnimationProps.IMMEDIATE; |
| 161 | animateNavBarScrimVisibility(hasNavBarScrim, animation); |
| 162 | } |
| 163 | mHasNavBarScrim = hasNavBarScrim; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @return a default animation to aniamte the bounds of the scrim. |
| 168 | */ |
| 169 | private AnimationProps createBoundsAnimation(int duration) { |
| 170 | return new AnimationProps() |
| 171 | .setDuration(AnimationProps.BOUNDS, duration) |
| 172 | .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); |
| 173 | } |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 174 | } |