Merge "Search results always highlight proper results" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2a32cb6a33
@@ -68,7 +68,8 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
private static final String TAG = "SettingsPreference";
|
||||
|
||||
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
|
||||
@VisibleForTesting
|
||||
static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
|
||||
|
||||
private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
|
||||
|
||||
@@ -86,7 +87,6 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
private String mPreferenceKey;
|
||||
private boolean mPreferenceHighlighted = false;
|
||||
|
||||
private RecyclerView.Adapter mCurrentRootAdapter;
|
||||
private boolean mIsDataSetObserverRegistered = false;
|
||||
@@ -130,10 +130,14 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
private View mEmptyView;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private HighlightablePreferenceGroupAdapter mAdapter;
|
||||
private ArrayMap<String, Preference> mPreferenceCache;
|
||||
private boolean mAnimationAllowed;
|
||||
|
||||
@VisibleForTesting
|
||||
public HighlightablePreferenceGroupAdapter mAdapter;
|
||||
@VisibleForTesting
|
||||
public boolean mPreferenceHighlighted = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -268,7 +272,12 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
public void highlightPreferenceIfNeeded() {
|
||||
if (isAdded() && !mPreferenceHighlighted &&!TextUtils.isEmpty(mPreferenceKey)) {
|
||||
highlightPreference(mPreferenceKey);
|
||||
getView().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
highlightPreference(mPreferenceKey);
|
||||
}
|
||||
}, DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,17 +408,13 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
private void highlightPreference(String key) {
|
||||
final int position = canUseListViewForHighLighting(key);
|
||||
if (position >= 0) {
|
||||
mPreferenceHighlighted = true;
|
||||
mLayoutManager.scrollToPosition(position);
|
||||
|
||||
getView().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter.highlight(position);
|
||||
}
|
||||
}, DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPreferenceHighlighted = true;
|
||||
mLayoutManager.scrollToPosition(position);
|
||||
mAdapter.highlight(position);
|
||||
}
|
||||
|
||||
private int findListPositionFromKey(PreferenceGroupAdapter adapter, String key) {
|
||||
@@ -765,6 +770,9 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
public static class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter {
|
||||
|
||||
@VisibleForTesting(otherwise=VisibleForTesting.NONE)
|
||||
int initialHighlightedPosition = -1;
|
||||
|
||||
private int mHighlightPosition = -1;
|
||||
|
||||
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup) {
|
||||
@@ -773,6 +781,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
|
||||
public void highlight(int position) {
|
||||
mHighlightPosition = position;
|
||||
initialHighlightedPosition = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user