Loading src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +13 −9 Original line number Diff line number Diff line Loading @@ -191,7 +191,6 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> private float mBottomSheetAlpha = 1f; private boolean mForceBottomSheetVisible; private int mTabsProtectionAlpha; private float mTotalHeaderProtectionHeight; @Nullable private AllAppsTransitionController mAllAppsTransitionController; public ActivityAllAppsContainerView(Context context) { Loading Loading @@ -778,7 +777,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> protected void updateHeaderScroll(int scrolledOffset) { float prog1 = Utilities.boundToRange((float) scrolledOffset / mHeaderThreshold, 0f, 1f); int headerColor = getHeaderColor(prog1); int tabsAlpha = mHeader.getPeripheralProtectionHeight() == 0 ? 0 int tabsAlpha = mHeader.getPeripheralProtectionHeight(/* expectedHeight */ false) == 0 ? 0 : (int) (Utilities.boundToRange( (scrolledOffset + mHeader.mSnappedScrolledY) / mHeaderThreshold, 0f, 1f) * 255); Loading Loading @@ -1448,15 +1447,13 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> mTmpPath.reset(); mTmpPath.addRoundRect(mTmpRectF, mBottomSheetCornerRadii, Direction.CW); canvas.drawPath(mTmpPath, mHeaderPaint); mTotalHeaderProtectionHeight = headerBottomWithScaleOnTablet; } } else { canvas.drawRect(0, 0, canvas.getWidth(), headerBottomWithScaleOnPhone, mHeaderPaint); mTotalHeaderProtectionHeight = headerBottomWithScaleOnPhone; } // If tab exist (such as work profile), extend header with tab height final int tabsHeight = headerView.getPeripheralProtectionHeight(); final int tabsHeight = headerView.getPeripheralProtectionHeight(/* expectedHeight */ false); if (mTabsProtectionAlpha > 0 && tabsHeight != 0) { if (DEBUG_HEADER_PROTECTION) { mHeaderPaint.setColor(Color.BLUE); Loading @@ -1482,16 +1479,19 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> right, tabBottomWithScale, mHeaderPaint); mTotalHeaderProtectionHeight = tabBottomWithScale; } } /** * The height of the header protection is dynamically calculated during the time of drawing the * header. * The height of the header protection as if the user scrolled down the app list. */ float getHeaderProtectionHeight() { return mTotalHeaderProtectionHeight; float headerBottom = getHeaderBottom() - getTranslationY(); if (mUsingTabs) { return headerBottom + mHeader.getPeripheralProtectionHeight(/* expectedHeight */ true); } else { return headerBottom; } } /** Loading @@ -1515,6 +1515,10 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> return bottom + mHeader.getTop(); } boolean isUsingTabs() { return mUsingTabs; } /** * Returns a view that denotes the visible part of all apps container view. */ Loading src/com/android/launcher3/allapps/FloatingHeaderView.java +7 −2 Original line number Diff line number Diff line Loading @@ -466,9 +466,14 @@ public class FloatingHeaderView extends LinearLayout implements } /** * Returns visible height of FloatingHeaderView contents requiring header protection * Returns visible height of FloatingHeaderView contents requiring header protection or the * expected header protection height. */ int getPeripheralProtectionHeight() { int getPeripheralProtectionHeight(boolean expected) { if (expected) { return getTabLayout().getBottom() - getPaddingTop() + getPaddingBottom() - mMaxTranslation; } // we only want to show protection when work tab is available and header is either // collapsed or animating to/from collapsed state if (mTabsHidden || mFloatingRowsCollapsed || !mHeaderCollapsed) { Loading src/com/android/launcher3/allapps/PrivateProfileManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -495,9 +495,12 @@ public class PrivateProfileManager extends UserProfileManager { if (rowToExpandToWithRespectToHeader == -1) { rowToExpandToWithRespectToHeader = currentItem.rowIndex; } // If there are no tabs, decrease the row to scroll to by 1 since the header // may be cut off slightly. int rowToScrollTo = (int) Math.floor((double) (mAllApps.getHeight() - psHeaderHeight - mAllApps.getHeaderProtectionHeight()) / allAppsCellHeight); - mAllApps.getHeaderProtectionHeight()) / allAppsCellHeight) - (mAllApps.isUsingTabs() ? 0 : 1); int currentRowDistance = currentItem.rowIndex - rowToExpandToWithRespectToHeader; // rowToScrollTo - 1 since the item to scroll to is 0 indexed. if (currentRowDistance == rowToScrollTo - 1) { Loading tests/src/com/android/launcher3/allapps/PrivateSpaceHeaderViewTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,7 @@ public class PrivateSpaceHeaderViewTest { doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(true); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS); Loading @@ -310,6 +311,43 @@ public class PrivateSpaceHeaderViewTest { ALL_APPS_CELL_HEIGHT)); } @Test public void scrollForViewToBeVisibleInContainer_withHeaderNoTabs() { when(mAllAppsStore.getApps()).thenReturn(createAppInfoList()); PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager); when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED); when(privateProfileManager.splitIntoUserInstalledAndSystemApps()) .thenReturn(iteminfo -> iteminfo.componentName == null || !iteminfo.componentName.getPackageName() .equals(CAMERA_PACKAGE_NAME)); doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any()); doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager) .addPrivateSpaceHeader(any()); doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any()); doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(false); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS); mAlphabeticalAppsList.updateItemFilter(info -> info != null && info.user.equals(MAIN_HANDLE)); int rows = (int) (ALL_APPS_HEIGHT - PS_HEADER_HEIGHT - HEADER_PROTECTION_HEIGHT) - 1; int position = rows * NUM_APP_COLS - (NUM_APP_COLS-1) + 1; // The number of adapterItems should be the private space apps + one main app + header. assertEquals(NUM_PRIVATE_SPACE_APPS + 1 + 1, mAlphabeticalAppsList.getAdapterItems().size()); assertEquals(position, privateProfileManager.scrollForHeaderToBeVisibleInContainer( new AllAppsRecyclerView(mContext), mAlphabeticalAppsList.getAdapterItems(), PS_HEADER_HEIGHT, ALL_APPS_CELL_HEIGHT)); } @Test public void scrollForViewToBeVisibleInContainer_withHeaderAndLessAppRowSpace() { when(mAllAppsStore.getApps()).thenReturn(createAppInfoList()); Loading @@ -325,6 +363,7 @@ public class PrivateSpaceHeaderViewTest { doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any()); doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(true); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); Loading Loading
src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +13 −9 Original line number Diff line number Diff line Loading @@ -191,7 +191,6 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> private float mBottomSheetAlpha = 1f; private boolean mForceBottomSheetVisible; private int mTabsProtectionAlpha; private float mTotalHeaderProtectionHeight; @Nullable private AllAppsTransitionController mAllAppsTransitionController; public ActivityAllAppsContainerView(Context context) { Loading Loading @@ -778,7 +777,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> protected void updateHeaderScroll(int scrolledOffset) { float prog1 = Utilities.boundToRange((float) scrolledOffset / mHeaderThreshold, 0f, 1f); int headerColor = getHeaderColor(prog1); int tabsAlpha = mHeader.getPeripheralProtectionHeight() == 0 ? 0 int tabsAlpha = mHeader.getPeripheralProtectionHeight(/* expectedHeight */ false) == 0 ? 0 : (int) (Utilities.boundToRange( (scrolledOffset + mHeader.mSnappedScrolledY) / mHeaderThreshold, 0f, 1f) * 255); Loading Loading @@ -1448,15 +1447,13 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> mTmpPath.reset(); mTmpPath.addRoundRect(mTmpRectF, mBottomSheetCornerRadii, Direction.CW); canvas.drawPath(mTmpPath, mHeaderPaint); mTotalHeaderProtectionHeight = headerBottomWithScaleOnTablet; } } else { canvas.drawRect(0, 0, canvas.getWidth(), headerBottomWithScaleOnPhone, mHeaderPaint); mTotalHeaderProtectionHeight = headerBottomWithScaleOnPhone; } // If tab exist (such as work profile), extend header with tab height final int tabsHeight = headerView.getPeripheralProtectionHeight(); final int tabsHeight = headerView.getPeripheralProtectionHeight(/* expectedHeight */ false); if (mTabsProtectionAlpha > 0 && tabsHeight != 0) { if (DEBUG_HEADER_PROTECTION) { mHeaderPaint.setColor(Color.BLUE); Loading @@ -1482,16 +1479,19 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> right, tabBottomWithScale, mHeaderPaint); mTotalHeaderProtectionHeight = tabBottomWithScale; } } /** * The height of the header protection is dynamically calculated during the time of drawing the * header. * The height of the header protection as if the user scrolled down the app list. */ float getHeaderProtectionHeight() { return mTotalHeaderProtectionHeight; float headerBottom = getHeaderBottom() - getTranslationY(); if (mUsingTabs) { return headerBottom + mHeader.getPeripheralProtectionHeight(/* expectedHeight */ true); } else { return headerBottom; } } /** Loading @@ -1515,6 +1515,10 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext> return bottom + mHeader.getTop(); } boolean isUsingTabs() { return mUsingTabs; } /** * Returns a view that denotes the visible part of all apps container view. */ Loading
src/com/android/launcher3/allapps/FloatingHeaderView.java +7 −2 Original line number Diff line number Diff line Loading @@ -466,9 +466,14 @@ public class FloatingHeaderView extends LinearLayout implements } /** * Returns visible height of FloatingHeaderView contents requiring header protection * Returns visible height of FloatingHeaderView contents requiring header protection or the * expected header protection height. */ int getPeripheralProtectionHeight() { int getPeripheralProtectionHeight(boolean expected) { if (expected) { return getTabLayout().getBottom() - getPaddingTop() + getPaddingBottom() - mMaxTranslation; } // we only want to show protection when work tab is available and header is either // collapsed or animating to/from collapsed state if (mTabsHidden || mFloatingRowsCollapsed || !mHeaderCollapsed) { Loading
src/com/android/launcher3/allapps/PrivateProfileManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -495,9 +495,12 @@ public class PrivateProfileManager extends UserProfileManager { if (rowToExpandToWithRespectToHeader == -1) { rowToExpandToWithRespectToHeader = currentItem.rowIndex; } // If there are no tabs, decrease the row to scroll to by 1 since the header // may be cut off slightly. int rowToScrollTo = (int) Math.floor((double) (mAllApps.getHeight() - psHeaderHeight - mAllApps.getHeaderProtectionHeight()) / allAppsCellHeight); - mAllApps.getHeaderProtectionHeight()) / allAppsCellHeight) - (mAllApps.isUsingTabs() ? 0 : 1); int currentRowDistance = currentItem.rowIndex - rowToExpandToWithRespectToHeader; // rowToScrollTo - 1 since the item to scroll to is 0 indexed. if (currentRowDistance == rowToScrollTo - 1) { Loading
tests/src/com/android/launcher3/allapps/PrivateSpaceHeaderViewTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,7 @@ public class PrivateSpaceHeaderViewTest { doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(true); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS); Loading @@ -310,6 +311,43 @@ public class PrivateSpaceHeaderViewTest { ALL_APPS_CELL_HEIGHT)); } @Test public void scrollForViewToBeVisibleInContainer_withHeaderNoTabs() { when(mAllAppsStore.getApps()).thenReturn(createAppInfoList()); PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager); when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED); when(privateProfileManager.splitIntoUserInstalledAndSystemApps()) .thenReturn(iteminfo -> iteminfo.componentName == null || !iteminfo.componentName.getPackageName() .equals(CAMERA_PACKAGE_NAME)); doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any()); doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager) .addPrivateSpaceHeader(any()); doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any()); doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(false); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS); mAlphabeticalAppsList.updateItemFilter(info -> info != null && info.user.equals(MAIN_HANDLE)); int rows = (int) (ALL_APPS_HEIGHT - PS_HEADER_HEIGHT - HEADER_PROTECTION_HEIGHT) - 1; int position = rows * NUM_APP_COLS - (NUM_APP_COLS-1) + 1; // The number of adapterItems should be the private space apps + one main app + header. assertEquals(NUM_PRIVATE_SPACE_APPS + 1 + 1, mAlphabeticalAppsList.getAdapterItems().size()); assertEquals(position, privateProfileManager.scrollForHeaderToBeVisibleInContainer( new AllAppsRecyclerView(mContext), mAlphabeticalAppsList.getAdapterItems(), PS_HEADER_HEIGHT, ALL_APPS_CELL_HEIGHT)); } @Test public void scrollForViewToBeVisibleInContainer_withHeaderAndLessAppRowSpace() { when(mAllAppsStore.getApps()).thenReturn(createAppInfoList()); Loading @@ -325,6 +363,7 @@ public class PrivateSpaceHeaderViewTest { doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any()); doReturn(0).when(privateProfileManager).addSystemAppsDivider(any()); when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT); when(mAllApps.isUsingTabs()).thenReturn(true); when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT); mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore, null, privateProfileManager); Loading