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

Commit 82d5a9af authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added FloatingAppBarScrollingViewBehavior"

parents 97a6c1f4 2f7f14f0
Loading
Loading
Loading
Loading
+8 −9
Original line number Original line Diff line number Diff line
@@ -21,24 +21,17 @@
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    android:layout_height="match_parent">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        app:elevation="0dp">
        <include layout="@layout/search_bar"/>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
    <androidx.core.widget.NestedScrollView
        android:id="@+id/main_content_scrollable_container"
        android:id="@+id/main_content_scrollable_container"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        app:layout_behavior="com.android.settings.widget.FloatingAppBarScrollingViewBehavior">


        <LinearLayout
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:orientation="vertical"
            android:paddingTop="@dimen/app_bar_height"
            android:descendantFocusability="blocksDescendants">
            android:descendantFocusability="blocksDescendants">


            <FrameLayout
            <FrameLayout
@@ -55,4 +48,10 @@


        </LinearLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>
    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include layout="@layout/search_bar"/>
    </com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+2 −0
Original line number Original line Diff line number Diff line
@@ -105,6 +105,8 @@
    <dimen name="search_bar_avatar_size">32dp</dimen>
    <dimen name="search_bar_avatar_size">32dp</dimen>
    <dimen name="search_bar_avatar_start_margin">4dp</dimen>
    <dimen name="search_bar_avatar_start_margin">4dp</dimen>
    <dimen name="search_bar_avatar_end_margin">16dp</dimen>
    <dimen name="search_bar_avatar_end_margin">16dp</dimen>
    <!-- appbar height is equal search bar height (48dp) plus search bar top and bottom margin  -->
    <dimen name="app_bar_height">80dp</dimen>


    <!-- Dimensions for Wifi Assistant Card -->
    <!-- Dimensions for Wifi Assistant Card -->
    <dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
    <dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
+61 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.VisibleForTesting;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.google.android.material.appbar.AppBarLayout;

/**
 * This scrolling view behavior will set the background of the {@link AppBarLayout} as
 * transparent and without the elevation. Also make header overlapped the scrolling child view.
 */
public class FloatingAppBarScrollingViewBehavior extends AppBarLayout.ScrollingViewBehavior {
    private boolean initialized;

    public FloatingAppBarScrollingViewBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        boolean changed = super.onDependentViewChanged(parent, child, dependency);
        if (!initialized && dependency instanceof AppBarLayout) {
            initialized = true;
            AppBarLayout appBarLayout = (AppBarLayout) dependency;
            setAppBarLayoutTransparent(appBarLayout);
        }
        return changed;
    }

    @VisibleForTesting
    void setAppBarLayoutTransparent(AppBarLayout appBarLayout) {
        appBarLayout.setBackgroundColor(Color.TRANSPARENT);
        appBarLayout.setTargetElevation(0);
    }

    @Override
    protected boolean shouldHeaderOverlapScrollingChild() {
        return true;
    }
}
+63 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.widget;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;

import com.google.android.material.appbar.AppBarLayout;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

@RunWith(SettingsRobolectricTestRunner.class)
public class FloatingAppBarScrollingViewBehaviorTest {

    private FloatingAppBarScrollingViewBehavior mScrollingViewBehavior;
    private Context mContext;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mScrollingViewBehavior = new FloatingAppBarScrollingViewBehavior(mContext,
                Robolectric.buildAttributeSet().build());
    }

    @Test
    public void shouldHeaderOverlapScrollingChild_returnTrue() {
        assertThat(mScrollingViewBehavior.shouldHeaderOverlapScrollingChild()).isTrue();
    }

    @Test
    public void setAppBarLayoutTransparent_backgroundDefaultAsWhite_shouldBeTransparent() {
        mContext.setTheme(R.style.Theme_Settings_Home);
        final AppBarLayout appBarLayout = new AppBarLayout(mContext);
        appBarLayout.setBackgroundColor(Color.WHITE);
        mScrollingViewBehavior.setAppBarLayoutTransparent(appBarLayout);
        assertThat(((ColorDrawable) appBarLayout.getBackground()).getColor()).isEqualTo(
                Color.TRANSPARENT);
    }
}