1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.documentsui.ui; 18 19 import android.content.Context; 20 import android.graphics.Color; 21 import android.util.AttributeSet; 22 import android.view.View; 23 24 import androidx.annotation.VisibleForTesting; 25 import androidx.coordinatorlayout.widget.CoordinatorLayout; 26 27 import com.google.android.material.appbar.AppBarLayout; 28 29 /** 30 * This scrolling view behavior will set the background of the {@link AppBarLayout} as 31 * transparent and without the elevation. Also make header overlapped the scrolling child view. 32 */ 33 public class SearchBarScrollingViewBehavior extends AppBarLayout.ScrollingViewBehavior { 34 private boolean mInitialized; 35 SearchBarScrollingViewBehavior(Context context, AttributeSet attrs)36 public SearchBarScrollingViewBehavior(Context context, AttributeSet attrs) { 37 super(context, attrs); 38 } 39 40 @Override onDependentViewChanged(CoordinatorLayout parent, View child, View dependency)41 public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { 42 final boolean changed = super.onDependentViewChanged(parent, child, dependency); 43 if (!mInitialized && dependency instanceof AppBarLayout) { 44 mInitialized = true; 45 final AppBarLayout appBarLayout = (AppBarLayout) dependency; 46 setAppBarLayoutTransparent(appBarLayout); 47 } 48 return changed; 49 } 50 setAppBarLayoutTransparent(AppBarLayout appBarLayout)51 private void setAppBarLayoutTransparent(AppBarLayout appBarLayout) { 52 appBarLayout.setBackgroundColor(Color.TRANSPARENT); 53 appBarLayout.setTargetElevation(0); 54 } 55 56 @Override shouldHeaderOverlapScrollingChild()57 protected boolean shouldHeaderOverlapScrollingChild() { 58 return true; 59 } 60 } 61 62