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 19 import android.app.Activity; 20 import android.view.View; 21 import com.android.systemui.R; 22 import com.android.systemui.recents.RecentsConfiguration; 23 24 /** Manages the scrims for the various system bars. */ 25 public class SystemBarScrimViews { 26 27 RecentsConfiguration mConfig; 28 29 View mStatusBarScrimView; 30 View mNavBarScrimView; 31 32 boolean mHasNavBarScrim; 33 boolean mShouldAnimateStatusBarScrim; 34 boolean mHasStatusBarScrim; 35 boolean mShouldAnimateNavBarScrim; 36 37 public SystemBarScrimViews(Activity activity, RecentsConfiguration config) { 38 mConfig = config; 39 mStatusBarScrimView = activity.findViewById(R.id.status_bar_scrim); 40 mNavBarScrimView = activity.findViewById(R.id.nav_bar_scrim); 41 } 42 43 /** 44 * Prepares the scrim views for animating when entering Recents. This will be called before 45 * the first draw. 46 */ 47 public void prepareEnterRecentsAnimation() { 48 mHasNavBarScrim = mConfig.hasNavBarScrim(); 49 mShouldAnimateNavBarScrim = mConfig.shouldAnimateNavBarScrim(); 50 mHasStatusBarScrim = mConfig.hasStatusBarScrim(); 51 mShouldAnimateStatusBarScrim = mConfig.shouldAnimateStatusBarScrim(); 52 53 mNavBarScrimView.setVisibility(mHasNavBarScrim && !mShouldAnimateNavBarScrim ? 54 View.VISIBLE : View.INVISIBLE); 55 mStatusBarScrimView.setVisibility(mHasStatusBarScrim && !mShouldAnimateStatusBarScrim ? 56 View.VISIBLE : View.INVISIBLE); 57 } 58 59 /** 60 * Starts animating the scrim views when entering Recents. 61 */ 62 public void startEnterRecentsAnimation() { 63 if (mHasStatusBarScrim && mShouldAnimateStatusBarScrim) { 64 mStatusBarScrimView.setTranslationY(-mStatusBarScrimView.getMeasuredHeight()); 65 mStatusBarScrimView.animate() 66 .translationY(0) 67 .setStartDelay(mConfig.launchedFromHome ? 68 mConfig.transitionEnterFromHomeDelay : 69 mConfig.transitionEnterFromAppDelay) 70 .setDuration(mConfig.navBarScrimEnterDuration) 71 .setInterpolator(mConfig.quintOutInterpolator) 72 .withStartAction(new Runnable() { 73 @Override 74 public void run() { 75 mStatusBarScrimView.setVisibility(View.VISIBLE); 76 } 77 }) 78 .start(); 79 } 80 if (mHasNavBarScrim && mShouldAnimateNavBarScrim) { 81 mNavBarScrimView.setTranslationY(mNavBarScrimView.getMeasuredHeight()); 82 mNavBarScrimView.animate() 83 .translationY(0) 84 .setStartDelay(mConfig.launchedFromHome ? 85 mConfig.transitionEnterFromHomeDelay : 86 mConfig.transitionEnterFromAppDelay) 87 .setDuration(mConfig.navBarScrimEnterDuration) 88 .setInterpolator(mConfig.quintOutInterpolator) 89 .withStartAction(new Runnable() { 90 @Override 91 public void run() { 92 mNavBarScrimView.setVisibility(View.VISIBLE); 93 } 94 }) 95 .start(); 96 } 97 } 98 99 /** 100 * Starts animating the scrim views when leaving Recents (either via launching a task, or 101 * going home). 102 */ 103 public void startExitRecentsAnimation() { 104 if (mHasStatusBarScrim && mShouldAnimateStatusBarScrim) { 105 mStatusBarScrimView.animate() 106 .translationY(-mStatusBarScrimView.getMeasuredHeight()) 107 .setStartDelay(0) 108 .setDuration(mConfig.taskViewExitToAppDuration) 109 .setInterpolator(mConfig.fastOutSlowInInterpolator) 110 .start(); 111 } 112 if (mHasNavBarScrim && mShouldAnimateNavBarScrim) { 113 mNavBarScrimView.animate() 114 .translationY(mNavBarScrimView.getMeasuredHeight()) 115 .setStartDelay(0) 116 .setDuration(mConfig.taskViewExitToAppDuration) 117 .setInterpolator(mConfig.fastOutSlowInInterpolator) 118 .start(); 119 } 120 } 121 } 122