Refactor the floating header's positioning.

Maintains the existing behavior while simplifying the overall layout.

See go/all-apps-qsb-positioning for details.

Bug: 221418522
Test: manual
Change-Id: I25a737cdfa431e8eb3a00b639984caed70819252
This commit is contained in:
Luca Zuccarini
2022-03-16 11:09:56 +00:00
parent 7b799b8c85
commit 0c3961c367
2 changed files with 40 additions and 10 deletions

View File

@@ -175,22 +175,27 @@ public class ActivityAllAppsContainerView<T extends Context & AppLauncher
@Override
protected View replaceRVContainer(boolean showTabs) {
View rvContainer = super.replaceRVContainer(showTabs);
removeCustomRules(rvContainer);
if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
alignParentTop(rvContainer);
alignParentTop(rvContainer, showTabs);
layoutAboveSearchContainer(rvContainer);
} else {
layoutBelowSearchContainer(rvContainer);
layoutBelowSearchContainer(rvContainer, showTabs);
}
return rvContainer;
}
@Override
void setupHeader() {
super.setupHeader();
removeCustomRules(mHeader);
if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
alignParentTop(mHeader);
alignParentTop(mHeader, false /* includeTabsMargin */);
} else {
layoutBelowSearchContainer(mHeader);
layoutBelowSearchContainer(mHeader, false /* includeTabsMargin */);
}
}
@@ -226,31 +231,55 @@ public class ActivityAllAppsContainerView<T extends Context & AppLauncher
return super.getHeaderBottom() + mSearchContainer.getBottom();
}
private void layoutBelowSearchContainer(View v) {
private void layoutBelowSearchContainer(View v, boolean includeTabsMargin) {
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);
layoutParams.addRule(RelativeLayout.ALIGN_TOP, R.id.search_container_all_apps);
int topMargin = getContext().getResources().getDimensionPixelSize(
R.dimen.all_apps_header_top_margin);
if (includeTabsMargin) {
topMargin = topMargin + getContext().getResources().getDimensionPixelSize(
R.dimen.all_apps_header_pill_height);
}
layoutParams.topMargin = topMargin;
}
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) {
private void alignParentTop(View v, boolean includeTabsMargin) {
if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams)) {
return;
}
RelativeLayout.LayoutParams layoutParams = (LayoutParams) v.getLayoutParams();
layoutParams.removeRule(RelativeLayout.BELOW);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.topMargin =
includeTabsMargin
? getContext().getResources().getDimensionPixelSize(
R.dimen.all_apps_header_pill_height)
: 0;
}
private void removeCustomRules(View v) {
if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams)) {
return;
}
RelativeLayout.LayoutParams layoutParams = (LayoutParams) v.getLayoutParams();
layoutParams.removeRule(RelativeLayout.ABOVE);
layoutParams.removeRule(RelativeLayout.ALIGN_TOP);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
}
@Override