Merge "Fix the higlighted settings not work properly from search" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3e2a7f6186
@@ -57,6 +57,8 @@ import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -112,9 +114,8 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
@VisibleForTesting
|
||||
ViewGroup mPinnedHeaderFrameLayout;
|
||||
|
||||
private AppBarLayout mAppBarLayout;
|
||||
private LayoutPreference mHeader;
|
||||
|
||||
private View mEmptyView;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private ArrayMap<String, Preference> mPreferenceCache;
|
||||
@@ -145,6 +146,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
Bundle savedInstanceState) {
|
||||
final View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
mPinnedHeaderFrameLayout = root.findViewById(R.id.pinned_header);
|
||||
mAppBarLayout = getActivity().findViewById(R.id.app_bar);
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -250,7 +252,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
return;
|
||||
}
|
||||
if (mAdapter != null) {
|
||||
mAdapter.requestHighlight(getView(), getListView());
|
||||
mAdapter.requestHighlight(getView(), getListView(), mAppBarLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,14 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter {
|
||||
|
||||
private static final String TAG = "HighlightableAdapter";
|
||||
@VisibleForTesting
|
||||
static final long DELAY_COLLAPSE_DURATION_MILLIS = 300L;
|
||||
@VisibleForTesting
|
||||
static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 600L;
|
||||
private static final long HIGHLIGHT_DURATION = 15000L;
|
||||
private static final long HIGHLIGHT_FADE_OUT_DURATION = 500L;
|
||||
@@ -115,7 +119,7 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
||||
View v = holder.itemView;
|
||||
if (position == mHighlightPosition
|
||||
&& (mHighlightKey != null
|
||||
&& TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
|
||||
&& TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
|
||||
// This position should be highlighted. If it's highlighted before - skip animation.
|
||||
addHighlightBackground(v, !mFadeInAnimated);
|
||||
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
|
||||
@@ -124,15 +128,26 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
||||
}
|
||||
}
|
||||
|
||||
public void requestHighlight(View root, RecyclerView recyclerView) {
|
||||
/**
|
||||
* A function can highlight a specific setting in recycler view.
|
||||
* note: Before highlighting a setting, screen collapses tool bar with an animation.
|
||||
*/
|
||||
public void requestHighlight(View root, RecyclerView recyclerView, AppBarLayout appBarLayout) {
|
||||
if (mHighlightRequested || recyclerView == null || TextUtils.isEmpty(mHighlightKey)) {
|
||||
return;
|
||||
}
|
||||
final int position = getPreferenceAdapterPosition(mHighlightKey);
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (appBarLayout != null) {
|
||||
root.postDelayed(() -> {
|
||||
appBarLayout.setExpanded(false, true);
|
||||
}, DELAY_COLLAPSE_DURATION_MILLIS);
|
||||
}
|
||||
|
||||
root.postDelayed(() -> {
|
||||
final int position = getPreferenceAdapterPosition(mHighlightKey);
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
mHighlightRequested = true;
|
||||
recyclerView.smoothScrollToPosition(position);
|
||||
mHighlightPosition = position;
|
||||
|
||||
Reference in New Issue
Block a user