From 1710cbeb6e88200cdcda4292bc44aaeda1ac3daf Mon Sep 17 00:00:00 2001 From: Brandon Dayauon Date: Mon, 15 Jul 2024 19:10:21 -0700 Subject: [PATCH] Don't add floatingMaskView if it will not fit. See this screenshot for math explanation: https://screenshot.googleplex.com/9x256x5uk7qNZDg We use the Y values of the views to determine if the header will be clipped by the floating mask view. Also added logs for private space. bug:343478928 Test manually before: see bug. after: https://drive.google.com/file/d/1FZXDQG-hV-V3wErVR0-nVCMgjUDk910Z/view?usp=sharing Flag: com.android.launcher3.enable_private_space Change-Id: I025e4e62f9ba60e8493d2aceb139d2c4ed6a84dd --- .../allapps/PrivateProfileManager.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index aefb7e92d5..c1264d6135 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -364,6 +364,7 @@ public class PrivateProfileManager extends UserProfileManager { /** Add Private Space Header view elements based upon {@link UserProfileState} */ public void bindPrivateSpaceHeaderViewElements(RelativeLayout parent) { mPSHeader = parent; + Log.d(TAG, "bindPrivateSpaceHeaderViewElements: " + "Binding private space."); updateView(); if (mOnPSHeaderAdded != null) { MAIN_EXECUTOR.execute(mOnPSHeaderAdded); @@ -376,6 +377,8 @@ public class PrivateProfileManager extends UserProfileManager { if (mPSHeader == null) { return; } + Log.d(TAG, "bindPrivateSpaceHeaderViewElements: " + "Updating view with state: " + + getCurrentState()); mPSHeader.setAlpha(1); ViewGroup lockPill = mPSHeader.findViewById(R.id.ps_lock_unlock_button); assert lockPill != null; @@ -761,6 +764,9 @@ public class PrivateProfileManager extends UserProfileManager { alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { + if (mFloatingMaskView == null) { + return; + } mFloatingMaskView.setTranslationY((float) valueAnimator.getAnimatedValue()); } }); @@ -844,8 +850,22 @@ public class PrivateProfileManager extends UserProfileManager { if (!Flags.privateSpaceAddFloatingMaskView()) { return; } + // Use getLocationOnScreen() as simply checking for mPSHeader.getBottom() is only relative + // to its parent. + int[] psHeaderLocation = new int[2]; + mPSHeader.getLocationOnScreen(psHeaderLocation); + int psHeaderBottomY = psHeaderLocation[1] + mPsHeaderHeight; + // Calculate the topY of the floatingMaskView as if it was added. + int floatingMaskViewBottomBoxTopY = + (int) (mAllApps.getBottom() - getMainRecyclerView().getPaddingBottom()); + // Don't attach if the header will be clipped by the floating mask view. + if (psHeaderBottomY > floatingMaskViewBottomBoxTopY) { + mFloatingMaskView = null; + return; + } mFloatingMaskView = (FloatingMaskView) mAllApps.getLayoutInflater().inflate( R.layout.private_space_mask_view, mAllApps, false); + assert mFloatingMaskView != null; mAllApps.addView(mFloatingMaskView); // Translate off the screen first if its collapsing so this header view isn't visible to // user when animation starts.