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