Fix search highlight

- Fragments should not have advanced button when coming from search.

Change-Id: I10a192216b7ff702e73b791acbcc1eb1d71cb407
Fixes: 73348428
Test: robotests
This commit is contained in:
Fan Zhang
2018-02-20 11:25:56 -08:00
parent 6f367a79ce
commit 72456a9ea6
6 changed files with 118 additions and 43 deletions

View File

@@ -16,10 +16,14 @@
package com.android.settings.widget;
import static com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceGroupAdapter;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
@@ -27,6 +31,7 @@ import android.util.TypedValue;
import android.view.View;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter {
@@ -41,6 +46,39 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
private boolean mHighlightRequested;
private int mHighlightPosition = RecyclerView.NO_POSITION;
/**
* Tries to override initial expanded child count.
* <p/>
* Initial expanded child count will be ignored if:
* 1. fragment contains request to highlight a particular row.
* 2. count value is invalid.
*/
public static void adjustInitialExpandedChildCount(SettingsPreferenceFragment host) {
if (host == null) {
return;
}
final PreferenceScreen screen = host.getPreferenceScreen();
if (screen == null) {
return;
}
final Bundle arguments = host.getArguments();
if (arguments != null) {
final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
if (!TextUtils.isEmpty(highlightKey)) {
// Has highlight row - expand everything
screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
return;
}
}
final int initialCount = host.getInitialExpandedChildCount();
if (initialCount <= 0) {
return;
}
screen.setInitialExpandedChildrenCount(initialCount);
}
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup, String key,
boolean highlightRequested) {
super(preferenceGroup);