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:
@@ -38,7 +38,8 @@ import com.android.settings.homepage.SettingsHomepageActivity;
|
||||
/**
|
||||
* 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";
|
||||
|
||||
@@ -60,6 +61,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
private String mHighlightKey;
|
||||
private String mPreviousHighlightKey;
|
||||
private int mHighlightPosition = RecyclerView.NO_POSITION;
|
||||
private int mScrollPosition = RecyclerView.NO_POSITION;
|
||||
private boolean mHighlightNeeded;
|
||||
private boolean mScrolled;
|
||||
|
||||
@@ -135,9 +137,11 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
return;
|
||||
}
|
||||
|
||||
// Scroll before highlight if needed.
|
||||
final boolean highlightNeeded = isHighlightNeeded();
|
||||
if (highlightNeeded) {
|
||||
scrollToPositionIfNeeded(position);
|
||||
mScrollPosition = position;
|
||||
scroll();
|
||||
}
|
||||
|
||||
// Turn on/off highlight when screen split mode is changed.
|
||||
@@ -189,26 +193,29 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
requestHighlight();
|
||||
}
|
||||
|
||||
private void scrollToPositionIfNeeded(int position) {
|
||||
if (mScrolled || position < 0) {
|
||||
@Override
|
||||
public void onHomepageLoaded() {
|
||||
scroll();
|
||||
}
|
||||
|
||||
private void scroll() {
|
||||
if (mScrolled || mScrollPosition < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mHomepageActivity.registerHomepageLoadedListenerIfNeeded(
|
||||
() -> scrollToPositionIfNeeded(position))) {
|
||||
if (mHomepageActivity.registerHomepageLoadedListenerIfNeeded(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
mRecyclerView.postDelayed(() -> scrollToPositionIfNeeded(position),
|
||||
DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
mRecyclerView.postDelayed(() -> scroll(), DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
return;
|
||||
}
|
||||
|
||||
mScrolled = true;
|
||||
Log.d(TAG, "Scroll to position " + position);
|
||||
Log.d(TAG, "Scroll to position " + mScrollPosition);
|
||||
// Scroll to the top to reset the position.
|
||||
mRecyclerView.nestedScrollBy(0, -mRecyclerView.getHeight());
|
||||
|
||||
|
Reference in New Issue
Block a user