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

Commit 3a9be3a6 authored by Mill Chen's avatar Mill Chen
Browse files

Disable scrolling behavior for collapsing toolbar

We intended to make subsetting pages disable the scrolling behavior
within the collapsing toolbar area. The collapsing toolbar is still
able to be expanded/collapsed depending on the content of page.

Fix: 191614437
Fix: 189003332
Test: manual test
Cannot scroll/drag with the collapsing toolbar area

Change-Id: Ifa545a1720c64be742f85b34188516eb9c6683df
parent ffc5989f
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -23,8 +23,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Toolbar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.resources.TextAppearanceConfig;

@@ -35,6 +38,7 @@ import com.google.android.material.resources.TextAppearanceConfig;
public class CollapsingToolbarBaseActivity extends SettingsTransitionActivity {

    private CollapsingToolbarLayout mCollapsingToolbarLayout;
    private AppBarLayout mAppBarLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -43,6 +47,8 @@ public class CollapsingToolbarBaseActivity extends SettingsTransitionActivity {
        TextAppearanceConfig.setShouldLoadFontSynchronously(true);
        super.setContentView(R.layout.collapsing_toolbar_base_layout);
        mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
        mAppBarLayout = findViewById(R.id.app_bar);
        disableCollapsingToolbarLayoutScrollingBehavior();

        final Toolbar toolbar = findViewById(R.id.action_bar);
        setActionBar(toolbar);
@@ -107,4 +113,18 @@ public class CollapsingToolbarBaseActivity extends SettingsTransitionActivity {
    public CollapsingToolbarLayout getCollapsingToolbarLayout() {
        return mCollapsingToolbarLayout;
    }

    private void disableCollapsingToolbarLayoutScrollingBehavior() {
        final CoordinatorLayout.LayoutParams params =
                (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
        final AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
        behavior.setDragCallback(
                new AppBarLayout.Behavior.DragCallback() {
                    @Override
                    public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
                        return false;
                    }
                });
        params.setBehavior(behavior);
    }
}