Merge "Adjust homepage styles and layouts"
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
android:layout_marginTop="@dimen/search_bar_margin"
|
||||
android:layout_marginStart="@dimen/search_bar_margin"
|
||||
android:layout_marginEnd="@dimen/search_bar_margin"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginBottom="@dimen/search_bar_margin_bottom"
|
||||
app:layout_scrollFlags="scroll|enterAlways">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
@@ -23,6 +23,7 @@
|
||||
android:transitionGroup="true">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
android:theme="@style/Theme.CollapsingToolbar.Settings">
|
||||
|
@@ -27,7 +27,7 @@
|
||||
android:id="@+id/main_content_scrollable_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.android.settings.widget.FloatingAppBarScrollingViewBehavior">
|
||||
app:layout_behavior="com.android.settings.widget.HomepageAppBarScrollingViewBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/homepage_container"
|
||||
@@ -53,6 +53,7 @@
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:touchscreenBlocksFocus="false"
|
||||
|
@@ -131,6 +131,7 @@
|
||||
|
||||
<!-- Search bar and avatar -->
|
||||
<dimen name="search_bar_margin">24dp</dimen>
|
||||
<dimen name="search_bar_margin_bottom">16dp</dimen>
|
||||
<dimen name="search_bar_height">48dp</dimen>
|
||||
<dimen name="search_bar_text_size">16sp</dimen>
|
||||
<dimen name="search_bar_card_elevation">2dp</dimen>
|
||||
@@ -138,7 +139,7 @@
|
||||
<dimen name="avatar_length">@dimen/search_bar_height</dimen>
|
||||
|
||||
<!-- Contextual suggestions -->
|
||||
<dimen name="suggestion_height">224dp</dimen>
|
||||
<dimen name="suggestion_height">232dp</dimen>
|
||||
<dimen name="suggestion_padding_horizontal">24dp</dimen>
|
||||
<dimen name="suggestion_padding_bottom">8dp</dimen>
|
||||
<dimen name="suggestion_button_margin_top">16dp</dimen>
|
||||
|
@@ -792,7 +792,7 @@
|
||||
<style name="ContextualSuggestionText" parent="@android:style/TextAppearance.DeviceDefault">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textSize">32sp</item>
|
||||
<item name="android:textSize">36sp</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
|
||||
</style>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -54,32 +53,6 @@ public class SettingsHomepageActivityTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultHomepageContainerPaddingTop_shouldSetSearchBoxHeight() {
|
||||
final SettingsHomepageActivity activity = Robolectric.buildActivity(
|
||||
SettingsHomepageActivity.class).create().get();
|
||||
final View view = activity.findViewById(R.id.homepage_container);
|
||||
|
||||
activity.setDefaultHomepageContainerPaddingTop();
|
||||
|
||||
final int actualPaddingTop = view.getPaddingTop();
|
||||
assertThat(actualPaddingTop).isEqualTo(activity.getSearchBoxHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHomepageContainerTopOffset_shouldBeSetPaddingTop() {
|
||||
final SettingsHomepageActivity activity = Robolectric.buildActivity(
|
||||
SettingsHomepageActivity.class).create().get();
|
||||
final View view = activity.findViewById(R.id.homepage_container);
|
||||
final int offset = activity.getResources().getDimensionPixelSize(
|
||||
R.dimen.suggestion_height);
|
||||
|
||||
activity.setHomepageContainerTopOffset(offset);
|
||||
|
||||
final int actualPaddingTop = view.getPaddingTop();
|
||||
assertThat(actualPaddingTop).isEqualTo(activity.getSearchBoxHeight() + offset);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launch_shouldHaveAnimationForIaFragment() {
|
||||
final SettingsHomepageActivity activity = Robolectric.buildActivity(
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 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.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.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HomepageAppBarScrollingViewBehaviorTest {
|
||||
|
||||
private HomepageAppBarScrollingViewBehavior mScrollingViewBehavior;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mScrollingViewBehavior = new HomepageAppBarScrollingViewBehavior(mContext,
|
||||
Robolectric.buildAttributeSet().build());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user