Merge "Add quick search bar width unfold animation" into sc-v2-dev am: caa713bc1a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15547447 Change-Id: I97f1262eb7302cbf7c244cd187969fb3822c4d60
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user