1 /* 2 * Copyright (C) 2018 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.launcher3.statehandlers; 18 19 import static com.android.launcher3.anim.Interpolators.LINEAR; 20 import static com.android.quickstep.AnimatedFloat.VALUE; 21 import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS; 22 23 import com.android.launcher3.BaseQuickstepLauncher; 24 import com.android.launcher3.LauncherState; 25 import com.android.launcher3.anim.PendingAnimation; 26 import com.android.launcher3.statemanager.StateManager.StateHandler; 27 import com.android.launcher3.states.StateAnimationConfig; 28 import com.android.launcher3.util.UiThreadHelper; 29 import com.android.quickstep.AnimatedFloat; 30 import com.android.quickstep.SysUINavigationMode; 31 import com.android.quickstep.SystemUiProxy; 32 33 /** 34 * State handler for animating back button alpha in two-button nav mode. 35 */ 36 public class BackButtonAlphaHandler implements StateHandler<LauncherState> { 37 38 private final BaseQuickstepLauncher mLauncher; 39 private final AnimatedFloat mBackAlpha = new AnimatedFloat(this::updateBackAlpha); 40 BackButtonAlphaHandler(BaseQuickstepLauncher launcher)41 public BackButtonAlphaHandler(BaseQuickstepLauncher launcher) { 42 mLauncher = launcher; 43 } 44 45 @Override setState(LauncherState state)46 public void setState(LauncherState state) { } 47 48 @Override setStateWithAnimation(LauncherState toState, StateAnimationConfig config, PendingAnimation animation)49 public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config, 50 PendingAnimation animation) { 51 if (SysUINavigationMode.getMode(mLauncher) != TWO_BUTTONS) { 52 return; 53 } 54 55 mBackAlpha.value = SystemUiProxy.INSTANCE.get(mLauncher).getLastNavButtonAlpha(); 56 animation.setFloat(mBackAlpha, VALUE, 57 mLauncher.shouldBackButtonBeHidden(toState) ? 0 : 1, LINEAR); 58 } 59 updateBackAlpha()60 private void updateBackAlpha() { 61 UiThreadHelper.setBackButtonAlphaAsync(mLauncher, 62 BaseQuickstepLauncher.SET_BACK_BUTTON_ALPHA, mBackAlpha.value, false /* animate */); 63 } 64 } 65