From cf462e879a269431d5fc5663232f9b87aefa8057 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Mon, 31 Jan 2022 17:57:06 -0800 Subject: [PATCH] Adds ENABLE_FLOATING_SEARCH_BOX flag for All Apps. This defines how the All Apps screen should be laid out without anchoring to the search bar at the top, as follows: - Header view aligns to the top instead of below search bar. - Same for A-Z list. - Scroller is aligned to the header view to receive the above adjustments automatically. - A-Z list is set above search bar to not peek from below. - Search bar is set to align parent bottom and translates up with the keyboard. - Button to disable work apps is raised above the search bar. Bug: 213954333 Test: Manually with flag enabled/disabled, Always show keyboard enabled/disabled, and work profile enabled/disabled. Change-Id: If90bb39a890029fa7056367fe62bad0677f0b86e --- res/layout/all_apps.xml | 1 - res/layout/all_apps_content_layout.xml | 27 ---------- res/layout/all_apps_fast_scroller.xml | 4 +- res/layout/all_apps_rv_layout.xml | 1 - res/layout/all_apps_tabs.xml | 1 - .../allapps/ActivityAllAppsContainerView.java | 53 +++++++++++++++++++ .../allapps/BaseAllAppsContainerView.java | 10 ++-- .../launcher3/allapps/WorkProfileManager.java | 12 ++++- .../launcher3/config/FeatureFlags.java | 4 ++ 9 files changed, 76 insertions(+), 37 deletions(-) delete mode 100644 res/layout/all_apps_content_layout.xml diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml index 7f9f63ea18..6df62124b4 100644 --- a/res/layout/all_apps.xml +++ b/res/layout/all_apps.xml @@ -33,7 +33,6 @@ android:id="@+id/all_apps_header" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_below="@id/search_container_all_apps" android:clipToPadding="false" android:paddingTop="@dimen/all_apps_header_top_padding" android:paddingBottom="@dimen/all_apps_header_bottom_padding" diff --git a/res/layout/all_apps_content_layout.xml b/res/layout/all_apps_content_layout.xml deleted file mode 100644 index 5698977e3e..0000000000 --- a/res/layout/all_apps_content_layout.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/res/layout/all_apps_fast_scroller.xml b/res/layout/all_apps_fast_scroller.xml index 5537bc60a5..f6a61569ee 100644 --- a/res/layout/all_apps_fast_scroller.xml +++ b/res/layout/all_apps_fast_scroller.xml @@ -21,7 +21,7 @@ android:id="@+id/fast_scroller_popup" style="@style/FastScrollerPopup" android:layout_alignParentEnd="true" - android:layout_below="@+id/search_container_all_apps" + android:layout_alignTop="@+id/all_apps_header" android:layout_marginEnd="@dimen/fastscroll_popup_margin" /> diff --git a/res/layout/all_apps_rv_layout.xml b/res/layout/all_apps_rv_layout.xml index c353b361cf..26d8ecc4c6 100644 --- a/res/layout/all_apps_rv_layout.xml +++ b/res/layout/all_apps_rv_layout.xml @@ -19,7 +19,6 @@ android:id="@+id/apps_list_view" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_below="@id/search_container_all_apps" android:clipToPadding="false" android:descendantFocusability="afterDescendants" android:focusable="true" /> diff --git a/res/layout/all_apps_tabs.xml b/res/layout/all_apps_tabs.xml index de4a69d6cc..cf68f5149c 100644 --- a/res/layout/all_apps_tabs.xml +++ b/res/layout/all_apps_tabs.xml @@ -20,7 +20,6 @@ android:id="@+id/all_apps_tabs_view_pager" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_below="@id/search_container_all_apps" android:layout_gravity="center_horizontal|top" android:layout_marginTop="@dimen/all_apps_header_pill_height" android:clipChildren="true" diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 070b98ed75..fb87f8843e 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -21,6 +21,7 @@ import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.widget.RelativeLayout; import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.RecyclerView; @@ -176,6 +177,28 @@ public class ActivityAllAppsContainerView extend }); } + @Override + protected View replaceRVContainer(boolean showTabs) { + View rvContainer = super.replaceRVContainer(showTabs); + if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { + alignParentTop(rvContainer); + layoutAboveSearchContainer(rvContainer); + } else { + layoutBelowSearchContainer(rvContainer); + } + return rvContainer; + } + + @Override + void setupHeader() { + super.setupHeader(); + if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { + alignParentTop(mHeader); + } else { + layoutBelowSearchContainer(mHeader); + } + } + @Override protected void updateHeaderScroll(int scrolledOffset) { super.updateHeaderScroll(scrolledOffset); @@ -202,6 +225,36 @@ public class ActivityAllAppsContainerView extend @Override protected int getHeaderBottom() { + if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { + return super.getHeaderBottom(); + } return super.getHeaderBottom() + mSearchContainer.getBottom(); } + + private void layoutBelowSearchContainer(View v) { + if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams)) { + return; + } + RelativeLayout.LayoutParams layoutParams = (LayoutParams) v.getLayoutParams(); + layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP); + layoutParams.removeRule(RelativeLayout.ABOVE); + layoutParams.addRule(RelativeLayout.BELOW, R.id.search_container_all_apps); + } + + private void layoutAboveSearchContainer(View v) { + if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams)) { + return; + } + RelativeLayout.LayoutParams layoutParams = (LayoutParams) v.getLayoutParams(); + layoutParams.addRule(RelativeLayout.ABOVE, R.id.search_container_all_apps); + } + + private void alignParentTop(View v) { + if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams)) { + return; + } + RelativeLayout.LayoutParams layoutParams = (LayoutParams) v.getLayoutParams(); + layoutParams.removeRule(RelativeLayout.BELOW); + layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); + } } diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java index b257407161..e8dcdbd46b 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java @@ -368,8 +368,7 @@ public abstract class BaseAllAppsContainerView