Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e813d37 authored by Luca Zuccarini's avatar Luca Zuccarini Committed by Android (Google) Code Review
Browse files

Merge "Refactor the floating header's positioning." into tm-dev

parents db2c7265 0c3961c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
    <dimen name="all_apps_header_pill_corner_radius">12dp</dimen>
    <dimen name="all_apps_header_tab_height">48dp</dimen>
    <dimen name="all_apps_tabs_indicator_height">2dp</dimen>
    <dimen name="all_apps_header_top_margin">33dp</dimen>
    <dimen name="all_apps_header_top_padding">36dp</dimen>
    <dimen name="all_apps_header_bottom_padding">6dp</dimen>
    <dimen name="all_apps_work_profile_tab_footer_top_padding">16dp</dimen>
+39 −10
Original line number Diff line number Diff line
@@ -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