Adjust homepage styles and layouts

- Fine tune the header text size and position
- Fix the header overlapping problem on the homepage and collapsing
  toolbar pages when configuration changes by adding android:id.
- New AppBarScrollingViewBehavior for the homepage to avoid manually
  offsetting the IA
- Correct the formula of counting search box height

Test: robotest, manual
Fixes: 177967923
Fixes: 177968564
Change-Id: Id3ed44f4296fa2a19d6890b009d3881a5c140bbd
This commit is contained in:
Jason Chiu
2021-01-22 13:40:08 +08:00
parent 5a8b96a2af
commit b56ea7e9e3
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;
}
}