From 4ba48cdb8b35ba93d70303a4c24ded03ff731927 Mon Sep 17 00:00:00 2001 From: Nick Chameyev Date: Fri, 13 Aug 2021 14:41:19 +0100 Subject: [PATCH] Add quick search bar width unfold animation Adds unfold animation to quick search bar in launcher which changes the width of the quick search bar from 70% to 100%. Bug: 193795041 Test: manual Change-Id: I8c55ca1cc5b5894847503beac8ecd8adec3e5674 --- .../LauncherUnfoldAnimationController.java | 33 +++++++++++++++-- .../util/HorizontalInsettableView.java | 35 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/com/android/launcher3/util/HorizontalInsettableView.java diff --git a/quickstep/src/com/android/quickstep/util/LauncherUnfoldAnimationController.java b/quickstep/src/com/android/quickstep/util/LauncherUnfoldAnimationController.java index ea1ece86d4..d0fb9e5901 100644 --- a/quickstep/src/com/android/quickstep/util/LauncherUnfoldAnimationController.java +++ b/quickstep/src/com/android/quickstep/util/LauncherUnfoldAnimationController.java @@ -15,10 +15,15 @@ */ package com.android.quickstep.util; +import static com.android.launcher3.Utilities.comp; + +import android.annotation.Nullable; import android.view.ViewTreeObserver; import android.view.WindowManager; +import com.android.launcher3.Hotseat; import com.android.launcher3.Launcher; +import com.android.launcher3.util.HorizontalInsettableView; import com.android.unfold.UnfoldTransitionProgressProvider; import com.android.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener; @@ -27,10 +32,17 @@ import com.android.unfold.UnfoldTransitionProgressProvider.TransitionProgressLis */ public class LauncherUnfoldAnimationController { + // Percentage of the width of the quick search bar that will be reduced + // from the both sides of the bar when progress is 0 + private static final float MAX_WIDTH_INSET_FRACTION = 0.15f; + private final Launcher mLauncher; private final UnfoldTransitionProgressProvider mUnfoldTransitionProgressProvider; private final UnfoldMoveFromCenterWorkspaceAnimator mMoveFromCenterWorkspaceAnimation; + @Nullable + private HorizontalInsettableView mQsbInsettable; + private final AnimationListener mAnimationListener = new AnimationListener(); private boolean mIsTransitionRunning = false; @@ -51,6 +63,11 @@ public class LauncherUnfoldAnimationController { * Called when launcher is resumed */ public void onResume() { + Hotseat hotseat = mLauncher.getHotseat(); + if (hotseat != null && hotseat.getQsb() instanceof HorizontalInsettableView) { + mQsbInsettable = (HorizontalInsettableView) hotseat.getQsb(); + } + final ViewTreeObserver obs = mLauncher.getWorkspace().getViewTreeObserver(); obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override @@ -68,12 +85,13 @@ public class LauncherUnfoldAnimationController { * Called when launcher activity is paused */ public void onPause() { - mIsReadyToPlayAnimation = false; - if (mIsTransitionRunning) { mIsTransitionRunning = false; - mMoveFromCenterWorkspaceAnimation.onTransitionFinished(); + mAnimationListener.onTransitionFinished(); } + + mIsReadyToPlayAnimation = false; + mQsbInsettable = null; } /** @@ -109,6 +127,10 @@ public class LauncherUnfoldAnimationController { public void onTransitionFinished() { if (mIsReadyToPlayAnimation) { mMoveFromCenterWorkspaceAnimation.onTransitionFinished(); + + if (mQsbInsettable != null) { + mQsbInsettable.setHorizontalInsets(0); + } } mIsTransitionRunning = false; @@ -117,6 +139,11 @@ public class LauncherUnfoldAnimationController { @Override public void onTransitionProgress(float progress) { mMoveFromCenterWorkspaceAnimation.onTransitionProgress(progress); + + if (mQsbInsettable != null) { + float insetPercentage = comp(progress) * MAX_WIDTH_INSET_FRACTION; + mQsbInsettable.setHorizontalInsets(insetPercentage); + } } } } diff --git a/src/com/android/launcher3/util/HorizontalInsettableView.java b/src/com/android/launcher3/util/HorizontalInsettableView.java new file mode 100644 index 0000000000..7979bc0f25 --- /dev/null +++ b/src/com/android/launcher3/util/HorizontalInsettableView.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.util; + +/** + * Allows the implementing view to add insets to the left and right. + */ +public interface HorizontalInsettableView { + + /** + * Sets left and right insets for the view so it looks like the width of the view is + * reduced when inset is increased. + * + * The inset is calculated based on the width of the view: e.g. when the width of + * the view is 100px then if we apply 0.15f horizontal inset percentage the rendered width + * of the view will be 70px with 15px of padding on the left and right sides. + * + * @param insetPercentage width percentage to inset the content from the left and from the right + */ + void setHorizontalInsets(float insetPercentage); + +}