From 627fd3928c12165a8edb71851286804eb2c93e24 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 3 Dec 2021 17:12:08 +0800 Subject: [PATCH] Improve the cold start performance The performance regressed since the previous change that hide the homepage view from using View.GONE to View.INVISIBLE This change only initializes the list views in the invisible homepage view to prevent a scroll flicker when scrolling is needed. Test: manual Bug: 206555277 Bug: 205823792 Change-Id: I8f173b135cfa1d27a1362d5fa8e3f338e2428ad2 --- .../homepage/SettingsHomepageActivity.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java index e25e1f50730..d5e82353bd3 100644 --- a/src/com/android/settings/homepage/SettingsHomepageActivity.java +++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java @@ -167,10 +167,13 @@ public class SettingsHomepageActivity extends FragmentActivity implements mCategoryMixin = new CategoryMixin(this); getLifecycle().addObserver(mCategoryMixin); + final String highlightMenuKey = getHighlightMenuKey(); // Only allow features on high ram devices. if (!getSystemService(ActivityManager.class).isLowRamDevice()) { initAvatarView(); - showSuggestionFragment(); + final boolean scrollNeeded = mIsEmbeddingActivityEnabled + && !TextUtils.equals(getString(DEFAULT_HIGHLIGHT_MENU_KEY), highlightMenuKey); + showSuggestionFragment(scrollNeeded); if (FeatureFlagUtils.isEnabled(this, FeatureFlags.CONTEXTUAL_HOME)) { showFragment(() -> new ContextualCardsFragment(), R.id.contextual_cards_content); } @@ -178,7 +181,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements mMainFragment = showFragment(() -> { final TopLevelSettings fragment = new TopLevelSettings(); fragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, - getHighlightMenuKey()); + highlightMenuKey); return fragment; }, R.id.main_content); @@ -265,7 +268,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements findViewById(R.id.settings_homepage_container).setBackgroundColor(color); } - private void showSuggestionFragment() { + private void showSuggestionFragment(boolean scrollNeeded) { final Class fragmentClass = FeatureFactory.getFactory(this) .getSuggestionFeatureProvider(this).getContextualSuggestionFragment(); if (fragmentClass == null) { @@ -275,8 +278,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements mSuggestionView = findViewById(R.id.suggestion_content); mTwoPaneSuggestionView = findViewById(R.id.two_pane_suggestion_content); mHomepageView = findViewById(R.id.settings_homepage_container); - // Hide the homepage for preparing the suggestion. - mHomepageView.setVisibility(View.INVISIBLE); + // Hide the homepage for preparing the suggestion. If scrolling is needed, the list views + // should be initialized in the invisible homepage view to prevent a scroll flicker. + mHomepageView.setVisibility(scrollNeeded ? View.INVISIBLE : View.GONE); // Schedule a timer to show the homepage and hide the suggestion on timeout. mHomepageView.postDelayed(() -> showHomepageWithSuggestion(false), HOMEPAGE_LOADING_TIMEOUT_MS);