Merge "Adjust homepage styles and layouts"

This commit is contained in:
Jason Chiu
2021-01-25 09:43:22 +00:00
committed by Android (Google) Code Review
9 changed files with 129 additions and 57 deletions

View File

@@ -27,7 +27,6 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toolbar;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
@@ -43,7 +42,6 @@ import com.android.settings.overlay.FeatureFactory;
public class SettingsHomepageActivity extends FragmentActivity {
private static final String TAG = "SettingsHomepageActivity";
private int mSearchBoxHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -56,7 +54,7 @@ public class SettingsHomepageActivity extends FragmentActivity {
final View appBar = findViewById(R.id.app_bar_container);
appBar.setMinimumHeight(getSearchBoxHeight());
setDefaultHomepageContainerPaddingTop();
initHomepageContainer();
final Toolbar toolbar = findViewById(R.id.search_action_bar);
FeatureFactory.getFactory(this).getSearchFeatureProvider()
@@ -89,8 +87,6 @@ public class SettingsHomepageActivity extends FragmentActivity {
try {
showFragment(fragment.newInstance(), R.id.contextual_suggestion_content);
setHomepageContainerTopOffset(getResources()
.getDimensionPixelSize(R.dimen.suggestion_height));
} catch (IllegalAccessException | InstantiationException e) {
Log.w(TAG, "Cannot show fragment", e);
}
@@ -109,33 +105,19 @@ public class SettingsHomepageActivity extends FragmentActivity {
fragmentTransaction.commit();
}
@VisibleForTesting
void setHomepageContainerTopOffset(int offset) {
private void initHomepageContainer() {
final View view = findViewById(R.id.homepage_container);
final int paddingTop = getSearchBoxHeight() + offset;
view.setPadding(0 /* left */, paddingTop, 0 /* right */, 0 /* bottom */);
// Prevent inner RecyclerView gets focus and invokes scrolling.
view.setFocusableInTouchMode(true);
view.requestFocus();
}
@VisibleForTesting
void setDefaultHomepageContainerPaddingTop() {
setHomepageContainerTopOffset(0);
}
@VisibleForTesting
int getSearchBoxHeight() {
if (mSearchBoxHeight != 0) {
return mSearchBoxHeight;
}
private int getSearchBoxHeight() {
final int searchBarHeight = getResources().getDimensionPixelSize(R.dimen.search_bar_height);
final int searchBarMargin = getResources().getDimensionPixelSize(R.dimen.search_bar_margin);
// The height of search box is the height of search bar(48dp) + top/bottom margins(24dp)
mSearchBoxHeight = searchBarHeight + searchBarMargin * 2;
return mSearchBoxHeight;
final int searchBarMarginTop = getResources().getDimensionPixelSize(
R.dimen.search_bar_margin);
final int searchBarMarginBottom = getResources().getDimensionPixelSize(
R.dimen.search_bar_margin_bottom);
return searchBarHeight + searchBarMarginTop + searchBarMarginBottom;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2021 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.
*/
public class HomepageAppBarScrollingViewBehavior extends AppBarLayout.ScrollingViewBehavior {
private boolean mInitialized;
public HomepageAppBarScrollingViewBehavior(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 (!mInitialized && dependency instanceof AppBarLayout) {
mInitialized = true;
AppBarLayout appBarLayout = (AppBarLayout) dependency;
setAppBarLayoutTransparent(appBarLayout);
}
return changed;
}
@VisibleForTesting
void setAppBarLayoutTransparent(AppBarLayout appBarLayout) {
appBarLayout.setBackgroundColor(Color.TRANSPARENT);
appBarLayout.setTargetElevation(0);
}
}