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 Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 21 | import android.view.View; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 22 | |
| 23 | import com.android.systemui.Interpolators; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 24 | import com.android.systemui.R; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 25 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 26 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 27 | import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 28 | |
| 29 | /** Manages the scrims for the various system bars. */ |
| 30 | public class SystemBarScrimViews { |
| 31 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 32 | Context mContext; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 33 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 34 | View mNavBarScrimView; |
| 35 | |
| 36 | boolean mHasNavBarScrim; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 37 | boolean mShouldAnimateNavBarScrim; |
| 38 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 39 | int mNavBarScrimEnterDuration; |
| 40 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 41 | public SystemBarScrimViews(Activity activity) { |
| 42 | mContext = activity; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 43 | mNavBarScrimView = activity.findViewById(R.id.nav_bar_scrim); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 44 | mNavBarScrimEnterDuration = activity.getResources().getInteger( |
| 45 | R.integer.recents_nav_bar_scrim_enter_duration); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * 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] | 50 | * the first draw, unless we are updating the scrim on configuration change. |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 51 | */ |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 52 | public void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) { |
| 53 | mHasNavBarScrim = hasNavBarScrim; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 54 | mShouldAnimateNavBarScrim = animateNavBarScrim; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 55 | |
| 56 | mNavBarScrimView.setVisibility(mHasNavBarScrim && !mShouldAnimateNavBarScrim ? |
| 57 | View.VISIBLE : View.INVISIBLE); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Animates the nav bar scrim visibility. |
| 62 | */ |
| 63 | public void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) { |
| 64 | int toY = 0; |
| 65 | if (visible) { |
| 66 | mNavBarScrimView.setVisibility(View.VISIBLE); |
| 67 | mNavBarScrimView.setTranslationY(mNavBarScrimView.getMeasuredHeight()); |
| 68 | } else { |
| 69 | toY = mNavBarScrimView.getMeasuredHeight(); |
| 70 | } |
| 71 | if (animation != AnimationProps.IMMEDIATE) { |
| 72 | mNavBarScrimView.animate() |
| 73 | .translationY(toY) |
| 74 | .setDuration(animation.getDuration(AnimationProps.BOUNDS)) |
| 75 | .setInterpolator(animation.getInterpolator(AnimationProps.BOUNDS)) |
| 76 | .start(); |
| 77 | } else { |
| 78 | mNavBarScrimView.setTranslationY(toY); |
| 79 | } |
| 80 | } |
| 81 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 82 | /**** EventBus events ****/ |
| 83 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Starts animating the scrim views when entering Recents. |
| 86 | */ |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 87 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 88 | if (mHasNavBarScrim) { |
| 89 | AnimationProps animation = mShouldAnimateNavBarScrim |
| 90 | ? new AnimationProps() |
| 91 | .setDuration(AnimationProps.BOUNDS, mNavBarScrimEnterDuration) |
| 92 | .setInterpolator(AnimationProps.BOUNDS, Interpolators.DECELERATE_QUINT) |
| 93 | : AnimationProps.IMMEDIATE; |
| 94 | animateNavBarScrimVisibility(true, animation); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Starts animating the scrim views when leaving Recents (either via launching a task, or |
| 100 | * going home). |
| 101 | */ |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 102 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 103 | if (mHasNavBarScrim) { |
| 104 | AnimationProps animation = new AnimationProps() |
| 105 | .setDuration(AnimationProps.BOUNDS, |
| 106 | TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION) |
| 107 | .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); |
| 108 | animateNavBarScrimVisibility(false, animation); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 111 | |
| 112 | public final void onBusEvent(DismissAllTaskViewsEvent event) { |
| 113 | if (mHasNavBarScrim) { |
| 114 | AnimationProps animation = new AnimationProps() |
| 115 | .setDuration(AnimationProps.BOUNDS, |
| 116 | TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION) |
| 117 | .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); |
| 118 | animateNavBarScrimVisibility(false, animation); |
| 119 | } |
| 120 | } |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 121 | } |