Fine tune the homepage scrolling behavior

Scroll to the highlight position before showing homepage.

Bug: 199017944
Bug: 204946469
Test: visual
Change-Id: I11708f42180a3af22855ac7b5f53460f737ed208
This commit is contained in:
Jason Chiu
2021-11-04 17:09:53 +08:00
parent 774c2181ea
commit ae5327d4bb
5 changed files with 58 additions and 18 deletions

View File

@@ -1197,6 +1197,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.security.LockscreenDashboardFragment" /> android:value="com.android.settings.security.LockscreenDashboardFragment" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_display"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -1223,6 +1225,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.deviceinfo.legal.ModuleLicensesDashboard" /> android:value="com.android.settings.deviceinfo.legal.ModuleLicensesDashboard" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_about_device"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -1243,6 +1247,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" /> android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -1266,6 +1272,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.managedomainurls.ManageDomainUrls" /> android:value="com.android.settings.applications.managedomainurls.ManageDomainUrls" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
</activity> </activity>
<activity android:name="Settings$AppMemoryUsageActivity" <activity android:name="Settings$AppMemoryUsageActivity"
@@ -1278,6 +1286,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ProcessStatsUi" /> android:value="com.android.settings.applications.ProcessStatsUi" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
</activity> </activity>
<activity <activity
@@ -1290,6 +1300,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" /> android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -1396,6 +1408,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" /> android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -1417,6 +1431,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" /> android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
@@ -2245,6 +2261,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.network.apn.ApnEditor" /> android:value="com.android.settings.network.apn.ApnEditor" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_network"/>
</activity> </activity>
<activity <activity
@@ -2273,6 +2291,8 @@
android:value="com.android.settings.development.DevelopmentSettingsDashboardFragment" /> android:value="com.android.settings.development.DevelopmentSettingsDashboardFragment" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_system"/>
</activity> </activity>
<!-- The opposite of DevelopmentSettingsActivity, it's no-op and only enabled when the real <!-- The opposite of DevelopmentSettingsActivity, it's no-op and only enabled when the real
@@ -2307,6 +2327,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.print.PrintSettingsFragment" /> android:value="com.android.settings.print.PrintSettingsFragment" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_connected_devices"/>
</activity> </activity>
<activity android:name="Settings$PrintJobSettingsActivity" <activity android:name="Settings$PrintJobSettingsActivity"
@@ -2319,6 +2341,8 @@
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.print.PrintJobSettingsFragment" /> android:value="com.android.settings.print.PrintJobSettingsFragment" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_connected_devices"/>
</activity> </activity>
<activity android:name=".development.AppPicker" <activity android:name=".development.AppPicker"
@@ -2339,7 +2363,10 @@
android:label="@string/accessor_info_title" /> android:label="@string/accessor_info_title" />
<activity android:name="Settings$WebViewAppPickerActivity" <activity android:name="Settings$WebViewAppPickerActivity"
android:label="@string/select_webview_provider_dialog_title" /> android:label="@string/select_webview_provider_dialog_title">
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_system"/>
</activity>
<activity android:name="Settings$BugReportHandlerPickerActivity" <activity android:name="Settings$BugReportHandlerPickerActivity"
android:label="@string/bug_report_handler_title" android:label="@string/bug_report_handler_title"
@@ -2353,6 +2380,8 @@
android:value="true" /> android:value="true" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.bugreporthandler.BugReportHandlerPicker" /> android:value="com.android.settings.bugreporthandler.BugReportHandlerPicker" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_system"/>
</activity> </activity>
<activity android:name=".bluetooth.BluetoothPairingDialog" <activity android:name=".bluetooth.BluetoothPairingDialog"

View File

@@ -95,7 +95,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
if (mHomepageView == null) { if (mHomepageView == null) {
return false; return false;
} else { } else {
mLoadedListeners.add(listener); if (!mLoadedListeners.contains(listener)) {
mLoadedListeners.add(listener);
}
return true; return true;
} }
} }
@@ -109,11 +111,13 @@ public class SettingsHomepageActivity extends FragmentActivity implements
return; return;
} }
Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion); Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion);
final View homepageView = mHomepageView;
mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE); mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE);
mHomepageView.setVisibility(View.VISIBLE);
mHomepageView = null; mHomepageView = null;
mLoadedListeners.forEach(listener -> listener.onHomepageLoaded()); mLoadedListeners.forEach(listener -> listener.onHomepageLoaded());
mLoadedListeners.clear(); mLoadedListeners.clear();
homepageView.setVisibility(View.VISIBLE);
} }
@Override @Override
@@ -195,7 +199,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
mSuggestionView = findViewById(R.id.suggestion_content); mSuggestionView = findViewById(R.id.suggestion_content);
mHomepageView = findViewById(R.id.settings_homepage_container); mHomepageView = findViewById(R.id.settings_homepage_container);
// Hide the homepage for preparing the suggestion. // Hide the homepage for preparing the suggestion.
mHomepageView.setVisibility(View.GONE); mHomepageView.setVisibility(View.INVISIBLE);
// Schedule a timer to show the homepage and hide the suggestion on timeout. // Schedule a timer to show the homepage and hide the suggestion on timeout.
mHomepageView.postDelayed(() -> showHomepageWithSuggestion(false), mHomepageView.postDelayed(() -> showHomepageWithSuggestion(false),
HOMEPAGE_LOADING_TIMEOUT_MS); HOMEPAGE_LOADING_TIMEOUT_MS);

View File

@@ -201,7 +201,8 @@ public class TopLevelSettings extends DashboardFragment implements
@Override @Override
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) { protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(getContext())) { if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(getContext())
|| !(getActivity() instanceof SettingsHomepageActivity)) {
return super.onCreateAdapter(preferenceScreen); return super.onCreateAdapter(preferenceScreen);
} }

View File

@@ -94,7 +94,7 @@ public class SearchResultTrampoline extends Activity {
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) { if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
startActivity(intent); startActivity(intent);
} else if (isFromSettingsIntelligence(callingActivity)) { } else if (isSettingsIntelligence(callingActivity)) {
// Register SplitPairRule for SubSettings, set clearTop false to prevent unexpected back // Register SplitPairRule for SubSettings, set clearTop false to prevent unexpected back
// navigation behavior. // navigation behavior.
ActivityEmbeddingRulesController.registerSubSettingsPairRule(this, ActivityEmbeddingRulesController.registerSubSettingsPairRule(this,
@@ -104,7 +104,6 @@ public class SearchResultTrampoline extends Activity {
startActivity(intent); startActivity(intent);
} else { } else {
// Two-pane case // Two-pane case
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)); startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey));
} }
@@ -112,7 +111,7 @@ public class SearchResultTrampoline extends Activity {
finish(); finish();
} }
private boolean isFromSettingsIntelligence(ComponentName callingActivity) { private boolean isSettingsIntelligence(ComponentName callingActivity) {
return callingActivity != null && TextUtils.equals( return callingActivity != null && TextUtils.equals(
callingActivity.getPackageName(), callingActivity.getPackageName(),
FeatureFactory.getFactory(this).getSearchFeatureProvider() FeatureFactory.getFactory(this).getSearchFeatureProvider()

View File

@@ -38,7 +38,8 @@ import com.android.settings.homepage.SettingsHomepageActivity;
/** /**
* Adapter for highlighting top level preferences * Adapter for highlighting top level preferences
*/ */
public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapter { public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapter implements
SettingsHomepageActivity.HomepageLoadedListener {
private static final String TAG = "HighlightableTopLevelAdapter"; private static final String TAG = "HighlightableTopLevelAdapter";
@@ -60,6 +61,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
private String mHighlightKey; private String mHighlightKey;
private String mPreviousHighlightKey; private String mPreviousHighlightKey;
private int mHighlightPosition = RecyclerView.NO_POSITION; private int mHighlightPosition = RecyclerView.NO_POSITION;
private int mScrollPosition = RecyclerView.NO_POSITION;
private boolean mHighlightNeeded; private boolean mHighlightNeeded;
private boolean mScrolled; private boolean mScrolled;
@@ -135,9 +137,11 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
return; return;
} }
// Scroll before highlight if needed.
final boolean highlightNeeded = isHighlightNeeded(); final boolean highlightNeeded = isHighlightNeeded();
if (highlightNeeded) { if (highlightNeeded) {
scrollToPositionIfNeeded(position); mScrollPosition = position;
scroll();
} }
// Turn on/off highlight when screen split mode is changed. // Turn on/off highlight when screen split mode is changed.
@@ -189,26 +193,29 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
requestHighlight(); requestHighlight();
} }
private void scrollToPositionIfNeeded(int position) { @Override
if (mScrolled || position < 0) { public void onHomepageLoaded() {
scroll();
}
private void scroll() {
if (mScrolled || mScrollPosition < 0) {
return; return;
} }
if (mHomepageActivity.registerHomepageLoadedListenerIfNeeded( if (mHomepageActivity.registerHomepageLoadedListenerIfNeeded(this)) {
() -> scrollToPositionIfNeeded(position))) {
return; return;
} }
// Only when the recyclerView is loaded, it can be scrolled // Only when the recyclerView is loaded, it can be scrolled
final View view = mRecyclerView.getChildAt(position); final View view = mRecyclerView.getChildAt(mScrollPosition);
if (view == null) { if (view == null) {
mRecyclerView.postDelayed(() -> scrollToPositionIfNeeded(position), mRecyclerView.postDelayed(() -> scroll(), DELAY_HIGHLIGHT_DURATION_MILLIS);
DELAY_HIGHLIGHT_DURATION_MILLIS);
return; return;
} }
mScrolled = true; mScrolled = true;
Log.d(TAG, "Scroll to position " + position); Log.d(TAG, "Scroll to position " + mScrollPosition);
// Scroll to the top to reset the position. // Scroll to the top to reset the position.
mRecyclerView.nestedScrollBy(0, -mRecyclerView.getHeight()); mRecyclerView.nestedScrollBy(0, -mRecyclerView.getHeight());