From af724fcea57d3d56f9a38cd0726b0d054fc5433b Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Thu, 9 May 2024 15:54:45 +0100 Subject: [PATCH] Fading PS container on hide. This change adds a fading effect to the PS container when Space is locked with "hide when locked" toggle enabled. Video: https://photos.app.goo.gl/pqhsvhfBqkTcbHXa9 GPU Profile Video: https://photos.app.goo.gl/V9yLYDH4EtAZZNrt8 before: https://drive.google.com/file/d/1bThcu34w2kgiJhgeGSmeZY_lVnMgCdsQ/view?usp=sharing after: https://drive.google.com/file/d/1ceI3A8UXyx7GYDfHGRkN8Wkzoi-01OVh/view?usp=sharing Bug: 299294792 Test: Manual Flash Flag: None Animation tweak. Change-Id: I742036f43605ca9a64f0d0a22c86b3fd69223456 --- .../allapps/PrivateProfileManager.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index a620490e4e..390f4de19a 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -104,6 +104,7 @@ public class PrivateProfileManager extends UserProfileManager { private static final int LOCK_TEXT_OPACITY_DELAY = 500; private static final int MASK_VIEW_DELAY = 400; private static final int NO_DELAY = 0; + private static final int CONTAINER_OPACITY_DURATION = 150; private final ActivityAllAppsContainerView mAllApps; private final Predicate mPrivateProfileMatcher; private final int mPsHeaderHeight; @@ -497,7 +498,10 @@ public class PrivateProfileManager extends UserProfileManager { return LinearSmoothScroller.SNAP_TO_END; } }; - smoothScroller.setTargetPosition(i); + // If privateSpaceHidden() then the entire container decorator will be invisible and + // we can directly move to an element above the header. There should always be one + // element, as PS is present in the bottom of All Apps. + smoothScroller.setTargetPosition(isPrivateSpaceHidden() ? i - 1 : i); RecyclerView.LayoutManager layoutManager = allAppsRecyclerView.getLayoutManager(); if (layoutManager != null) { startAnimationScroll(allAppsRecyclerView, layoutManager, smoothScroller); @@ -619,8 +623,11 @@ public class PrivateProfileManager extends UserProfileManager { float newAlpha = (float) valueAnimator.getAnimatedValue(); for (int i = 0; i < allAppsAdapterItems.size(); i++) { BaseAllAppsAdapter.AdapterItem currentItem = allAppsAdapterItems.get(i); + // When not hidden: Fade all PS items except header. + // When hidden: Fade all items. if (isPrivateSpaceItem(currentItem) && - currentItem.viewType != VIEW_TYPE_PRIVATE_SPACE_HEADER) { + (currentItem.viewType != VIEW_TYPE_PRIVATE_SPACE_HEADER + || isPrivateSpaceHidden())) { RecyclerView.ViewHolder viewHolder = allAppsRecyclerView.findViewHolderForAdapterPosition(i); if (viewHolder != null) { @@ -702,10 +709,9 @@ public class PrivateProfileManager extends UserProfileManager { translateFloatingMaskView(false)); } else { if (isPrivateSpaceHidden()) { - animatorSet.playSequentially(translateFloatingMaskView(false), - animateAlphaOfIcons(false), - animateCollapseAnimation(), - fadeOutHeaderAlpha()); + animatorSet.playSequentially(animateAlphaOfIcons(false), + animateAlphaOfPrivateSpaceContainer(), + animateCollapseAnimation()); } else { animatorSet.playSequentially(translateFloatingMaskView(true), animateAlphaOfIcons(false), @@ -715,22 +721,23 @@ public class PrivateProfileManager extends UserProfileManager { animatorSet.start(); } - /** Fades out the private space container. */ - private ValueAnimator fadeOutHeaderAlpha() { - if (mPSHeader == null) { - return new ValueAnimator(); - } - float from = 1; - float to = 0; - ValueAnimator alphaAnim = ObjectAnimator.ofFloat(from, to); - alphaAnim.setDuration(EXPAND_COLLAPSE_DURATION); - alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - if (mPSHeader != null) { - mPSHeader.setAlpha((float) valueAnimator.getAnimatedValue()); + /** Fades out the private space container (defined by its items' decorators). */ + private ValueAnimator animateAlphaOfPrivateSpaceContainer() { + int from = 255; // 100% opacity. + int to = 0; // No opacity. + ValueAnimator alphaAnim = ObjectAnimator.ofInt(from, to); + AllAppsRecyclerView allAppsRecyclerView = mAllApps.getActiveRecyclerView(); + List allAppsAdapterItems = + allAppsRecyclerView.getApps().getAdapterItems(); + alphaAnim.setDuration(CONTAINER_OPACITY_DURATION); + alphaAnim.addUpdateListener(valueAnimator -> { + for (BaseAllAppsAdapter.AdapterItem currentItem : allAppsAdapterItems) { + if (isPrivateSpaceItem(currentItem)) { + currentItem.setDecorationFillAlpha((int) valueAnimator.getAnimatedValue()); } } + // Invalidate the parent view, to redraw the decorations with changed alpha. + allAppsRecyclerView.invalidate(); }); return alphaAnim; }