summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFan Zhang <zhfan@google.com>2018-02-20 11:25:56 -0800
committerFan Zhang <zhfan@google.com>2018-02-20 13:19:26 -0800
commit72456a9ea677b91389ba4ece88842b65c45d5107 (patch)
tree5658362b5855daed0d3b0eafdc647f7ec2168cd4
parent6f367a79cee128b49a353cf81efed1112572cc20 (diff)
downloadpackages_apps_Settings-72456a9ea677b91389ba4ece88842b65c45d5107.tar.gz
packages_apps_Settings-72456a9ea677b91389ba4ece88842b65c45d5107.tar.bz2
packages_apps_Settings-72456a9ea677b91389ba4ece88842b65c45d5107.zip
Fix search highlight
- Fragments should not have advanced button when coming from search. Change-Id: I10a192216b7ff702e73b791acbcc1eb1d71cb407 Fixes: 73348428 Test: robotests
-rw-r--r--src/com/android/settings/SettingsPreferenceFragment.java23
-rw-r--r--src/com/android/settings/deviceinfo/DeviceInfoSettings.java25
-rw-r--r--src/com/android/settings/location/LocationSettings.java10
-rw-r--r--src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java38
-rw-r--r--src/com/android/settings/wifi/ConfigureWifiSettings.java7
-rw-r--r--tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java58
6 files changed, 118 insertions, 43 deletions
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 2fceb6399a..245a341dac 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -135,19 +135,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
if (icicle != null) {
mPreferenceHighlighted = icicle.getBoolean(SAVE_HIGHLIGHTED_KEY);
}
- final Bundle arguments = getArguments();
-
- // Check if we should keep the preferences expanded.
- if (arguments != null) {
- final String highlightKey =
- arguments.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
- if (!TextUtils.isEmpty(highlightKey)) {
- final PreferenceScreen screen = getPreferenceScreen();
- if (screen != null) {
- screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- }
- }
- }
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(this /* host */);
}
@Override
@@ -264,6 +252,15 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
}
}
+ /**
+ * Returns initial expanded child count.
+ * <p/>
+ * Only override this method if the initial expanded child must be determined at run time.
+ */
+ public int getInitialExpandedChildCount() {
+ return 0;
+ }
+
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
updateEmptyView();
diff --git a/src/com/android/settings/deviceinfo/DeviceInfoSettings.java b/src/com/android/settings/deviceinfo/DeviceInfoSettings.java
index 9b99e8ba5a..79f57be090 100644
--- a/src/com/android/settings/deviceinfo/DeviceInfoSettings.java
+++ b/src/com/android/settings/deviceinfo/DeviceInfoSettings.java
@@ -20,14 +20,12 @@ import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
-import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import android.telephony.TelephonyManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController;
@@ -64,23 +62,12 @@ public class DeviceInfoSettings extends DashboardFragment implements Indexable {
}
@Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- final Bundle arguments = getArguments();
- // Do not override initial expand children count if we come from
- // search (EXTRA_FRAGMENT_ARG_KEY is set) - we need to display every if entry point
- // is search.
- if (arguments == null
- || !arguments.containsKey(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY)) {
-
- // Increase the number of children when the device contains more than 1 sim.
- final TelephonyManager telephonyManager = (TelephonyManager) getContext()
- .getSystemService(Context.TELEPHONY_SERVICE);
- final int numberOfChildren = Math.max(SIM_PREFERENCES_COUNT,
- SIM_PREFERENCES_COUNT * telephonyManager.getPhoneCount())
- + NON_SIM_PREFERENCES_COUNT;
- getPreferenceScreen().setInitialExpandedChildrenCount(numberOfChildren);
- }
+ public int getInitialExpandedChildCount() {
+ final TelephonyManager telephonyManager = (TelephonyManager) getContext()
+ .getSystemService(Context.TELEPHONY_SERVICE);
+ return Math.max(SIM_PREFERENCES_COUNT,
+ SIM_PREFERENCES_COUNT * telephonyManager.getPhoneCount())
+ + NON_SIM_PREFERENCES_COUNT;
}
@Override
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 510c1625a5..3e9c8af24d 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -67,15 +67,13 @@ public class LocationSettings extends DashboardFragment {
private LocationSwitchBarController mSwitchBarController;
@Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
+ public int getInitialExpandedChildCount() {
final RecentLocationApps recentLocationApps = new RecentLocationApps(getActivity());
- int locationRequestsApps = recentLocationApps.getAppList().size();
- int locationRequestsPrefs = locationRequestsApps == 0 ? 1 : locationRequestsApps;
- getPreferenceScreen().setInitialExpandedChildrenCount(locationRequestsPrefs + 2);
+ final int locationRequestsApps = recentLocationApps.getAppList().size();
+ final int locationRequestsPrefs = locationRequestsApps == 0 ? 1 : locationRequestsApps;
+ return locationRequestsPrefs + 2;
}
-
@Override
public int getMetricsCategory() {
return MetricsEvent.LOCATION;
diff --git a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
index e1999efef8..cad11b7004 100644
--- a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
+++ b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
@@ -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);
diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java
index 1607b74d46..3fd217169d 100644
--- a/src/com/android/settings/wifi/ConfigureWifiSettings.java
+++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java
@@ -23,7 +23,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiManager;
-import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -44,7 +43,6 @@ public class ConfigureWifiSettings extends DashboardFragment {
private static final String TAG = "ConfigureWifiSettings";
- public static final String KEY_WIFI_CONFIGURE = "wifi_configure_settings_screen";
public static final String KEY_IP_ADDRESS = "current_ip_address";
private WifiWakeupPreferenceController mWifiWakeupPreferenceController;
@@ -61,13 +59,12 @@ public class ConfigureWifiSettings extends DashboardFragment {
}
@Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
+ public int getInitialExpandedChildCount() {
int tileLimit = 2;
if (mUseOpenWifiPreferenceController.isAvailable()) {
tileLimit++;
}
- getPreferenceScreen().setInitialExpandedChildrenCount(tileLimit);
+ return tileLimit;
}
@Override
diff --git a/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java b/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
index e2fb6c16bf..fd5800fa3b 100644
--- a/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
@@ -27,12 +27,16 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
+import android.os.Bundle;
import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -55,6 +59,9 @@ public class HighlightablePreferenceGroupAdapterTest {
private View mRoot;
@Mock
private PreferenceCategory mPreferenceCatetory;
+ @Mock
+ private SettingsPreferenceFragment mFragment;
+
private Context mContext;
private HighlightablePreferenceGroupAdapter mAdapter;
private PreferenceViewHolder mViewHolder;
@@ -96,6 +103,57 @@ public class HighlightablePreferenceGroupAdapterTest {
}
@Test
+ public void adjustInitialExpandedChildCount_invalidInput_shouldNotadjust() {
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(null /* host */);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+ final Bundle args = new Bundle();
+ when(mFragment.getArguments()).thenReturn(args);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ when(mFragment.getArguments()).thenReturn(null);
+ when(mFragment.getPreferenceScreen()).thenReturn(screen);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+ verifyZeroInteractions(screen);
+ }
+
+ @Test
+ public void adjustInitialExpandedChildCount_hasHightlightKey_shouldExpandAllChildren() {
+ final Bundle args = new Bundle();
+ when(mFragment.getArguments()).thenReturn(args);
+ args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, "testkey");
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ when(mFragment.getPreferenceScreen()).thenReturn(screen);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+
+ verify(screen).setInitialExpandedChildrenCount(Integer.MAX_VALUE);
+ }
+
+ @Test
+ public void adjustInitialExpandedChildCount_noKeyOrChildCountOverride_shouldDoNothing() {
+ final Bundle args = new Bundle();
+ when(mFragment.getArguments()).thenReturn(args);
+ when(mFragment.getInitialExpandedChildCount()).thenReturn(-1);
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ when(mFragment.getPreferenceScreen()).thenReturn(screen);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+
+ verify(mFragment).getInitialExpandedChildCount();
+ verifyZeroInteractions(screen);
+ }
+
+ @Test
+ public void adjustInitialExpandedChildCount_hasCountOverride_shouldDoNothing() {
+ when(mFragment.getInitialExpandedChildCount()).thenReturn(10);
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ when(mFragment.getPreferenceScreen()).thenReturn(screen);
+ HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
+
+ verify(mFragment).getInitialExpandedChildCount();
+
+ verify(screen).setInitialExpandedChildrenCount(10);
+ }
+
+ @Test
public void updateBackground_notHighlightedRow_shouldNotSetHighlightedTag() {
ReflectionHelpers.setField(mAdapter, "mHighlightPosition", 10);