diff --git a/res/layout/expand_preference.xml b/res/layout/expand_preference.xml deleted file mode 100644 index 729dfd99191..00000000000 --- a/res/layout/expand_preference.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml index 2930c83dff5..f598547f803 100644 --- a/res/xml/app_and_notification.xml +++ b/res/xml/app_and_notification.xml @@ -19,7 +19,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:key="apps_and_notification_screen" - android:title="@string/app_and_notification_dashboard_title"> + android:title="@string/app_and_notification_dashboard_title" + settings:initialExpandedChildrenCount="4"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index aa03bc7ef1b..36856718eac 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -19,7 +19,8 @@ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:key="display_settings_screen" android:title="@string/display_settings" - settings:keywords="@string/keywords_display"> + settings:keywords="@string/keywords_display" + settings:initialExpandedChildrenCount="4"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/installed_app_details.xml b/res/xml/installed_app_details.xml index 0836c19abc9..42822c03bbf 100644 --- a/res/xml/installed_app_details.xml +++ b/res/xml/installed_app_details.xml @@ -17,7 +17,9 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:key="installed_app_detail_settings_screen" + app:initialExpandedChildrenCount="6"> + android:title="@string/language_settings" + settings:initialExpandedChildrenCount="3" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/security_settings.xml b/res/xml/security_settings.xml index 228b7f1e3ee..aa4ca9d092f 100644 --- a/res/xml/security_settings.xml +++ b/res/xml/security_settings.xml @@ -14,7 +14,11 @@ limitations under the License. --> - + diff --git a/res/xml/security_settings_advanced_button.xml b/res/xml/security_settings_advanced_button.xml deleted file mode 100644 index 787b64e8513..00000000000 --- a/res/xml/security_settings_advanced_button.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml index 578edf6edc7..db88a8fd19a 100644 --- a/res/xml/sound_settings.xml +++ b/res/xml/sound_settings.xml @@ -19,59 +19,62 @@ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:title="@string/sound_settings" android:key="sound_settings" - settings:keywords="@string/keywords_sounds"> + settings:keywords="@string/keywords_sounds" + settings:initialExpandedChildrenCount="6"> - - - + + - - + + - - + + - - + + - - + + - - + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml index b4ad3a362c8..8b9d0cab093 100644 --- a/res/xml/system_dashboard_fragment.xml +++ b/res/xml/system_dashboard_fragment.xml @@ -16,8 +16,10 @@ + android:title="@string/header_category_system" + settings:initialExpandedChildrenCount="4"> (); private final Set mDashboardTilePrefKeys = new ArraySet<>(); - protected ProgressiveDisclosureMixin mProgressiveDisclosureMixin; protected DashboardFeatureProvider mDashboardFeatureProvider; private DashboardTilePlaceholderPreferenceController mPlaceholderPreferenceController; private boolean mListeningToCategoryChange; @@ -69,9 +68,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment super.onAttach(context); mDashboardFeatureProvider = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context); - mProgressiveDisclosureMixin = mDashboardFeatureProvider - .getProgressiveDisclosureMixin(context, this, getArguments()); - getLifecycle().addObserver(mProgressiveDisclosureMixin); List controllers = getPreferenceControllers(context); if (controllers == null) { @@ -140,8 +136,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment @Override public void notifySummaryChanged(Tile tile) { final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile); - final Preference pref = mProgressiveDisclosureMixin.findPreference( - getPreferenceScreen(), key); + final Preference pref = getPreferenceScreen().findPreference(key); if (pref == null) { Log.d(getLogTag(), String.format("Can't find pref by key %s, skipping update summary %s/%s", @@ -267,7 +262,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } final String key = controller.getPreferenceKey(); - final Preference preference = mProgressiveDisclosureMixin.findPreference(screen, key); + final Preference preference = screen.findPreference(key); if (preference == null) { Log.d(TAG, String.format("Cannot find preference with key %s in Controller %s", key, controller.getClass().getSimpleName())); @@ -290,7 +285,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // Add resource based tiles. displayResourceTiles(); - mProgressiveDisclosureMixin.collapse(getPreferenceScreen()); refreshDashboardTiles(TAG); } @@ -342,8 +336,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } if (mDashboardTilePrefKeys.contains(key)) { // Have the key already, will rebind. - final Preference preference = mProgressiveDisclosureMixin.findPreference( - screen, key); + final Preference preference = screen.findPreference(key); mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(), preference, tile, key, mPlaceholderPreferenceController.getOrder()); } else { @@ -351,7 +344,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment final Preference pref = new Preference(getPrefContext()); mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(), pref, tile, key, mPlaceholderPreferenceController.getOrder()); - mProgressiveDisclosureMixin.addPreference(screen, pref); + screen.addPreference(pref); mDashboardTilePrefKeys.add(key); } remove.remove(key); @@ -359,7 +352,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // Finally remove tiles that are gone. for (String key : remove) { mDashboardTilePrefKeys.remove(key); - mProgressiveDisclosureMixin.removePreference(screen, key); + final Preference preference = screen.findPreference(key); + if (preference != null) { + screen.removePreference(preference); + } } mSummaryLoader.setListening(true); } diff --git a/src/com/android/settings/dashboard/ExpandPreference.java b/src/com/android/settings/dashboard/ExpandPreference.java deleted file mode 100644 index 3939e746cc7..00000000000 --- a/src/com/android/settings/dashboard/ExpandPreference.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.dashboard; - -import android.content.Context; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceViewHolder; -import android.util.AttributeSet; - -import com.android.settings.R; - -public class ExpandPreference extends Preference { - - public ExpandPreference(Context context, AttributeSet attrs, - int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(); - } - - public ExpandPreference(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(); - } - - public ExpandPreference(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - public ExpandPreference(Context context) { - super(context); - init(); - } - - private void init() { - setLayoutResource(R.layout.expand_preference); - setIcon(R.drawable.ic_arrow_down_24dp); - setTitle(R.string.advanced_section_header); - setOrder(999); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { - super.onBindViewHolder(holder); - holder.setDividerAllowedAbove(false); - } -} diff --git a/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java b/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java deleted file mode 100644 index ba227418fc0..00000000000 --- a/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.dashboard; - -import android.content.Context; -import android.os.Bundle; -import android.support.annotation.VisibleForTesting; -import android.support.v14.preference.PreferenceFragment; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceGroup; -import android.support.v7.preference.PreferenceScreen; -import android.text.TextUtils; -import android.util.FeatureFlagUtils; -import android.util.Log; - -import com.android.internal.logging.nano.MetricsProto; -import com.android.settings.R; -import com.android.settings.core.instrumentation.Instrumentable; -import com.android.settings.core.instrumentation.MetricsFeatureProvider; -import com.android.settings.overlay.FeatureFactory; -import com.android.settingslib.core.lifecycle.LifecycleObserver; -import com.android.settingslib.core.lifecycle.events.OnCreate; -import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class ProgressiveDisclosureMixin implements Preference.OnPreferenceClickListener, - LifecycleObserver, OnCreate, OnSaveInstanceState { - - @VisibleForTesting - static final String FEATURE_FLAG_NEW_ADVANCE_BUTTON = "new_settings_advance_button"; - private static final String TAG = "ProgressiveDisclosure"; - private static final String STATE_USER_EXPANDED = "state_user_expanded"; - private static final int DEFAULT_TILE_LIMIT = 300; - - private final Context mContext; - // Collapsed preference sorted by order. - private final List mCollapsedPrefs = new ArrayList<>(); - private final MetricsFeatureProvider mMetricsFeatureProvider; - private final PreferenceFragment mFragment; - private /* final */ ExpandPreference mExpandButton; - - private int mTileLimit = DEFAULT_TILE_LIMIT; - private boolean mUserExpanded; - - public ProgressiveDisclosureMixin(Context context, - PreferenceFragment fragment, boolean keepExpanded) { - mContext = context; - mFragment = fragment; - mExpandButton = new ExpandPreference(context); - mExpandButton.setOnPreferenceClickListener(this); - mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); - mUserExpanded = keepExpanded; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - if (savedInstanceState != null) { - mUserExpanded = savedInstanceState.getBoolean(STATE_USER_EXPANDED, false); - } - } - - @Override - public void onSaveInstanceState(Bundle outState) { - outState.putBoolean(STATE_USER_EXPANDED, mUserExpanded); - } - - @Override - public boolean onPreferenceClick(Preference preference) { - if (preference instanceof ExpandPreference) { - final PreferenceScreen screen = mFragment.getPreferenceScreen(); - if (screen != null) { - screen.removePreference(preference); - for (Preference pref : mCollapsedPrefs) { - screen.addPreference(pref); - } - mCollapsedPrefs.clear(); - mUserExpanded = true; - final int metricsCategory; - if (mFragment instanceof Instrumentable) { - metricsCategory = ((Instrumentable) mFragment).getMetricsCategory(); - } else { - metricsCategory = MetricsProto.MetricsEvent.VIEW_UNKNOWN; - } - mMetricsFeatureProvider.actionWithSource(mContext, metricsCategory, - MetricsProto.MetricsEvent.ACTION_SETTINGS_ADVANCED_BUTTON_EXPAND); - } - } - return false; - } - - public boolean isEnabled() { - return !isV2Enabled(); - } - - public static boolean isV2Enabled() { - return FeatureFlagUtils.isEnabled(FEATURE_FLAG_NEW_ADVANCE_BUTTON); - } - - /** - * Sets the threshold to start collapsing preferences when there are too many. - */ - public void setTileLimit(int limit) { - if (isEnabled()) { - mTileLimit = limit; - } - } - - /** - * Whether the controller is in collapsed state. - */ - public boolean isCollapsed() { - return !mCollapsedPrefs.isEmpty(); - } - - /** - * Whether the screen should be collapsed. - */ - public boolean shouldCollapse(PreferenceScreen screen) { - return !mUserExpanded && screen.getPreferenceCount() > mTileLimit; - } - - /** - * Collapse extra preferences and show a "More" button - */ - public void collapse(PreferenceScreen screen) { - final int itemCount = screen.getPreferenceCount(); - if (!shouldCollapse(screen)) { - return; - } - if (!mCollapsedPrefs.isEmpty()) { - Log.w(TAG, "collapsed list should ALWAYS BE EMPTY before collapsing!"); - } - - for (int i = itemCount - 1; i >= mTileLimit; i--) { - final Preference preference = screen.getPreference(i); - addToCollapsedList(preference); - screen.removePreference(preference); - } - screen.addPreference(mExpandButton); - } - - /** - * Adds preference to screen. If there are too many preference on screen, adds it to - * collapsed list instead. - */ - public void addPreference(PreferenceScreen screen, Preference pref) { - // Either add to screen, or to collapsed list. - if (isCollapsed()) { - // insert the preference to right position. - final int lastPreferenceIndex = screen.getPreferenceCount() - 2; - if (lastPreferenceIndex >= 0) { - final Preference lastPreference = screen.getPreference(lastPreferenceIndex); - if (lastPreference.getOrder() > pref.getOrder()) { - // insert to screen and move the last pref to collapsed list. - screen.removePreference(lastPreference); - screen.addPreference(pref); - addToCollapsedList(lastPreference); - } else { - // Insert to collapsed list. - addToCollapsedList(pref); - } - } else { - // Couldn't find last preference on screen, just add to collapsed list. - addToCollapsedList(pref); - } - } else if (shouldCollapse(screen)) { - // About to have too many tiles on scree, collapse and add pref to collapsed list. - screen.addPreference(pref); - collapse(screen); - } else { - // No need to collapse, add to screen directly. - screen.addPreference(pref); - } - } - - /** - * Removes preference. If the preference is on screen, remove it from screen. If the - * preference is in collapsed list, remove it from list. - */ - public void removePreference(PreferenceScreen screen, String key) { - // Try removing from screen. - final Preference preference = screen.findPreference(key); - if (preference != null) { - screen.removePreference(preference); - return; - } - // Didn't find on screen, try removing from collapsed list. - for (int i = 0; i < mCollapsedPrefs.size(); i++) { - final Preference pref = mCollapsedPrefs.get(i); - if (TextUtils.equals(key, pref.getKey())) { - mCollapsedPrefs.remove(pref); - if (mCollapsedPrefs.isEmpty()) { - // Removed last element, remove expand button too. - screen.removePreference(mExpandButton); - } else { - updateExpandButtonSummary(); - } - return; - } - } - } - - /** - * Finds preference by key, either from screen or from collapsed list. - */ - public Preference findPreference(PreferenceScreen screen, CharSequence key) { - Preference preference = screen.findPreference(key); - if (preference != null) { - return preference; - } - for (int i = 0; i < mCollapsedPrefs.size(); i++) { - final Preference pref = mCollapsedPrefs.get(i); - if (TextUtils.equals(key, pref.getKey())) { - return pref; - } - if (pref instanceof PreferenceGroup) { - final Preference returnedPreference = ((PreferenceGroup) pref).findPreference(key); - if (returnedPreference != null) { - return returnedPreference; - } - } - } - Log.d(TAG, "Cannot find preference with key " + key); - return null; - } - - /** - * Add preference to collapsed list. - */ - @VisibleForTesting - void addToCollapsedList(Preference preference) { - // Insert preference based on it's order. - int insertionIndex = Collections.binarySearch(mCollapsedPrefs, preference); - if (insertionIndex < 0) { - insertionIndex = insertionIndex * -1 - 1; - } - mCollapsedPrefs.add(insertionIndex, preference); - updateExpandButtonSummary(); - } - - @VisibleForTesting - List getCollapsedPrefs() { - return mCollapsedPrefs; - } - - @VisibleForTesting - void updateExpandButtonSummary() { - final int size = mCollapsedPrefs.size(); - if (size == 0) { - mExpandButton.setSummary(null); - } else if (size == 1) { - mExpandButton.setSummary(mCollapsedPrefs.get(0).getTitle()); - } else { - CharSequence summary = mCollapsedPrefs.get(0).getTitle(); - for (int i = 1; i < size; i++) { - final CharSequence nextSummary = mCollapsedPrefs.get(i).getTitle(); - if (!TextUtils.isEmpty(nextSummary)) { - summary = mContext.getString(R.string.join_many_items_middle, summary, - nextSummary); - } - } - mExpandButton.setSummary(summary); - } - } -} diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java index 79f9deddfd8..bf611163d3f 100644 --- a/src/com/android/settings/language/LanguageAndInputSettings.java +++ b/src/com/android/settings/language/LanguageAndInputSettings.java @@ -64,13 +64,6 @@ public class LanguageAndInputSettings extends DashboardFragment { return TAG; } - @Override - public void onAttach(Context context) { - super.onAttach(context); - mProgressiveDisclosureMixin.setTileLimit(2); - - } - @Override public void onResume() { super.onResume(); @@ -86,8 +79,7 @@ public class LanguageAndInputSettings extends DashboardFragment { @Override protected int getPreferenceScreenResId() { - return mProgressiveDisclosureMixin.isEnabled() - ? R.xml.language_and_input : R.xml.language_and_input_new_advance_button; + return R.xml.language_and_input; } @Override diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java index 06f15bb3c62..a7243384a7c 100644 --- a/src/com/android/settings/notification/SoundSettings.java +++ b/src/com/android/settings/notification/SoundSettings.java @@ -54,12 +54,6 @@ public class SoundSettings extends DashboardFragment { private RingtonePreference mRequestPreference; - @Override - public void onAttach(Context context) { - super.onAttach(context); - mProgressiveDisclosureMixin.setTileLimit(1); - } - @Override public int getMetricsCategory() { return MetricsEvent.SOUND; @@ -109,8 +103,7 @@ public class SoundSettings extends DashboardFragment { @Override protected int getPreferenceScreenResId() { - return mProgressiveDisclosureMixin.isEnabled() - ? R.xml.sound_settings : R.xml.sound_settings_new_advance_button; + return R.xml.sound_settings; } @Override diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java index 3c700483d99..13ec15207bd 100644 --- a/src/com/android/settings/wifi/ConfigureWifiSettings.java +++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java @@ -23,6 +23,7 @@ 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; @@ -60,8 +61,8 @@ public class ConfigureWifiSettings extends DashboardFragment { } @Override - public void onAttach(Context context) { - super.onAttach(context); + public void onCreate(Bundle icicle) { + super.onCreate(icicle); int tileLimit = 1; if (mWifiWakeupPreferenceController.isAvailable()) { tileLimit++; @@ -69,7 +70,7 @@ public class ConfigureWifiSettings extends DashboardFragment { if (mUseOpenWifiPreferenceController.isAvailable()) { tileLimit++; } - mProgressiveDisclosureMixin.setTileLimit(tileLimit); + getPreferenceScreen().setInitialExpandedChildrenCount(tileLimit); } @Override diff --git a/tests/robotests/src/com/android/settings/DisplaySettingsTest.java b/tests/robotests/src/com/android/settings/DisplaySettingsTest.java index 3ee8feb1268..0d8cb92812b 100644 --- a/tests/robotests/src/com/android/settings/DisplaySettingsTest.java +++ b/tests/robotests/src/com/android/settings/DisplaySettingsTest.java @@ -6,7 +6,6 @@ import static org.mockito.Mockito.mock; import android.content.Context; -import com.android.settings.dashboard.ProgressiveDisclosureMixin; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.ShadowPowerManagerWrapper; @@ -30,8 +29,6 @@ public class DisplaySettingsTest { public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() { final Context context = RuntimeEnvironment.application; final DisplaySettings fragment = new DisplaySettings(); - ReflectionHelpers.setField(fragment, "mProgressiveDisclosureMixin", - mock(ProgressiveDisclosureMixin.class)); final List preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context, fragment.getPreferenceScreenResId()); final List preferenceKeys = new ArrayList<>(); diff --git a/tests/robotests/src/com/android/settings/applications/AppAndNotificationDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/AppAndNotificationDashboardFragmentTest.java index 269d840cac4..5a798f984c1 100644 --- a/tests/robotests/src/com/android/settings/applications/AppAndNotificationDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/applications/AppAndNotificationDashboardFragmentTest.java @@ -20,7 +20,6 @@ import android.content.Context; import android.os.UserManager; -import com.android.settings.dashboard.ProgressiveDisclosureMixin; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.testutils.XmlTestUtils; @@ -51,8 +50,6 @@ public class AppAndNotificationDashboardFragmentTest { final List niks = AppAndNotificationDashboardFragment.SEARCH_INDEX_DATA_PROVIDER .getNonIndexableKeys(context); AppAndNotificationDashboardFragment fragment = new AppAndNotificationDashboardFragment(); - ReflectionHelpers.setField(fragment, "mProgressiveDisclosureMixin", - mock(ProgressiveDisclosureMixin.class)); final int xmlId = fragment.getPreferenceScreenResId(); final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java index ea160dd355f..9ba0807b28b 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java @@ -67,8 +67,6 @@ public class DashboardFragmentTest { private DashboardCategory mDashboardCategory; @Mock private FakeFeatureFactory mFakeFeatureFactory; - @Mock - private ProgressiveDisclosureMixin mDisclosureMixin; private TestFragment mTestFragment; @Before @@ -79,9 +77,6 @@ public class DashboardFragmentTest { mDashboardCategory.tiles = new ArrayList<>(); mDashboardCategory.tiles.add(new Tile()); mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext()); - when(mFakeFeatureFactory.dashboardFeatureProvider.getProgressiveDisclosureMixin( - nullable(Context.class), eq(mTestFragment), nullable(Bundle.class))) - .thenReturn(mDisclosureMixin); when(mFakeFeatureFactory.dashboardFeatureProvider .getTilesForCategory(nullable(String.class))) .thenReturn(mDashboardCategory); @@ -110,8 +105,7 @@ public class DashboardFragmentTest { .thenReturn("test_key"); mTestFragment.onCreatePreferences(new Bundle(), "rootKey"); - verify(mDisclosureMixin).addPreference(nullable(PreferenceScreen.class), - nullable(Preference.class)); + verify(mTestFragment.mScreen).addPreference(nullable(Preference.class)); } @Test diff --git a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java b/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java deleted file mode 100644 index 3155ea90a33..00000000000 --- a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.dashboard; - -import android.content.Context; -import android.support.v14.preference.PreferenceFragment; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceManager; -import android.support.v7.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settings.testutils.SettingsRobolectricTestRunner; -import com.android.settings.TestConfig; -import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.testutils.shadow.SettingsShadowSystemProperties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.annotation.Config; -import org.robolectric.shadows.ShadowApplication; -import org.robolectric.util.ReflectionHelpers; - -import java.util.List; - -import static android.util.FeatureFlagUtils.FFLAG_PREFIX; -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(SettingsRobolectricTestRunner.class) -@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, - shadows = {SettingsShadowSystemProperties.class}) -public class ProgressiveDisclosureTest { - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private PreferenceFragment mPreferenceFragment; - @Mock - private ExpandPreference mExpandButton; - private PreferenceScreen mScreen; - private Context mAppContext; - private Preference mPreference; - private ProgressiveDisclosureMixin mMixin; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - FakeFeatureFactory.setupForTest(mContext); - mScreen = mPreferenceFragment.getPreferenceScreen(); - mAppContext = ShadowApplication.getInstance().getApplicationContext(); - mMixin = new ProgressiveDisclosureMixin(mAppContext, - mPreferenceFragment, false /* keepExpanded */); - ReflectionHelpers.setField(mMixin, "mExpandButton", mExpandButton); - mPreference = new Preference(mAppContext); - mPreference.setKey("test"); - } - - @After - public void tearDown() { - SettingsShadowSystemProperties.clear(); - } - - @Test - public void systemPropertySetForNewAdvancedButtonFeature_verifyIsDisabled() { - SettingsShadowSystemProperties.set( - FFLAG_PREFIX + ProgressiveDisclosureMixin.FEATURE_FLAG_NEW_ADVANCE_BUTTON, "true"); - assertThat(mMixin.isEnabled()).isFalse(); - } - - @Test - public void systemPropertyNotSet_verifyIsDisabled() { - SettingsShadowSystemProperties.set( - FFLAG_PREFIX + ProgressiveDisclosureMixin.FEATURE_FLAG_NEW_ADVANCE_BUTTON, "false"); - assertThat(mMixin.isEnabled()).isTrue(); - } - - @Test - public void shouldNotCollapse_lessPreferenceThanLimit() { - when(mScreen.getPreferenceCount()).thenReturn(5); - - mMixin.setTileLimit(10); - - assertThat(mMixin.shouldCollapse(mScreen)).isFalse(); - } - - @Test - public void shouldNotCollapse_preferenceCountSameAsThreshold() { - when(mScreen.getPreferenceCount()).thenReturn(5); - - mMixin.setTileLimit(5); - - assertThat(mMixin.shouldCollapse(mScreen)).isFalse(); - } - - @Test - public void shouldNotCollapse_whenStartAsExpanded() { - when(mScreen.getPreferenceCount()).thenReturn(5); - - mMixin = new ProgressiveDisclosureMixin(mAppContext, - mPreferenceFragment, true /* keepExpanded */); - mMixin.setTileLimit(10); - - assertThat(mMixin.shouldCollapse(mScreen)).isFalse(); - } - - @Test - public void shouldCollapse_morePreferenceThanLimit() { - when(mScreen.getPreferenceCount()).thenReturn(5); - mMixin.setTileLimit(3); - - assertThat(mMixin.shouldCollapse(mScreen)).isTrue(); - } - - @Test - public void findPreference_prefInCollapsedList_shouldFindIt() { - when(mScreen.findPreference(nullable(String.class))).thenReturn(null); - mMixin.addToCollapsedList(mPreference); - - Preference pref = mMixin.findPreference(mScreen, mPreference.getKey()); - - assertThat(pref).isNotNull(); - assertThat(pref).isSameAs(mPreference); - } - - @Test - public void findPreference_prefOnScreen_shouldFindIt() { - when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference); - - Preference pref = mMixin.findPreference(mScreen, mPreference.getKey()); - - assertThat(pref).isNotNull(); - assertThat(pref).isSameAs(mPreference); - } - - @Test - public void findPreference_prefNotInCollapsedListOrScreen_shouldNotFindIt() { - when(mScreen.findPreference(nullable(String.class))).thenReturn(null); - Preference pref = mMixin.findPreference(mScreen, mPreference.getKey()); - - assertThat(pref).isNull(); - } - - @Test - public void findPreference_prefRemovedFromCollapsedList_shouldNotFindIt() { - when(mScreen.findPreference(nullable(String.class))).thenReturn(null); - mMixin.addToCollapsedList(mPreference); - mMixin.removePreference(mPreferenceFragment.getPreferenceScreen(), mPreference.getKey()); - - Preference pref = mMixin.findPreference(mScreen, mPreference.getKey()); - - assertThat(pref).isNull(); - } - - @Test - public void findPreference_nestedPrefInCollapsedList_shouldFindIt() { - when(mScreen.findPreference(nullable(String.class))).thenReturn(null); - final PreferenceScreen prefGroup = spy(new PreferenceScreen(mAppContext, null)); - when(prefGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class)); - final Preference preference = mock(Preference.class); - when(preference.getKey()).thenReturn("TestKey"); - prefGroup.addPreference(preference); - mMixin.addToCollapsedList(prefGroup); - - Preference pref = mMixin.findPreference(mScreen, "TestKey"); - - assertThat(pref).isNotNull(); - assertThat(pref).isSameAs(preference); - } - - @Test - public void removePreference_shouldRemoveOnScreenPreference() { - when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference); - - mMixin.removePreference(mScreen, mPreference.getKey()); - - verify(mScreen).removePreference(mPreference); - } - - @Test - public void removeLastPreference_shouldRemoveExpandButtonToo() { - when(mScreen.findPreference(nullable(String.class))).thenReturn(null); - mMixin.addToCollapsedList(mPreference); - // Collapsed - assertThat(mMixin.isCollapsed()).isTrue(); - - mMixin.removePreference(mScreen, mPreference.getKey()); - - // Removing expand button - verify(mScreen).removePreference(any(Preference.class)); - // No longer collapsed - assertThat(mMixin.isCollapsed()).isFalse(); - } - - @Test - public void collapse_shouldDoNothingIfNotCollapsible() { - final PreferenceScreen screen = mPreferenceFragment.getPreferenceScreen(); - when(screen.getPreferenceCount()).thenReturn(5); - mMixin.setTileLimit(15); - - mMixin.collapse(screen); - assertThat(mMixin.isCollapsed()).isFalse(); - verify(mExpandButton, never()).setSummary(nullable(String.class)); - verify(screen, never()).addPreference(any(Preference.class)); - verify(screen, never()).removePreference(any(Preference.class)); - } - - @Test - public void collapse_shouldRemovePrefAndAddExpandButton() { - final PreferenceScreen screen = mPreferenceFragment.getPreferenceScreen(); - when(screen.getPreferenceCount()).thenReturn(5); - when(screen.getPreference(anyInt())).thenReturn(mPreference); - mMixin.setTileLimit(2); - - mMixin.collapse(screen); - - assertThat(mMixin.isCollapsed()).isTrue(); - verify(mExpandButton, atLeastOnce()).setSummary(nullable(String.class)); - verify(screen).addPreference(any(ExpandPreference.class)); - verify(screen, times(3)).removePreference(any(Preference.class)); - } - - @Test - public void addToCollapsedList_shouldAddInOrder() { - final Preference pref1 = new Preference(mAppContext); - final Preference pref2 = new Preference(mAppContext); - pref1.setOrder(10); - pref2.setOrder(20); - - // Pref1 has lower order than pref2, but add pref2 first. The collapsed list should maintain - // items in increasing order. - mMixin.addToCollapsedList(pref2); - mMixin.addToCollapsedList(pref1); - - List collapsedList = mMixin.getCollapsedPrefs(); - assertThat(collapsedList.get(0)).isSameAs(pref1); - assertThat(collapsedList.get(1)).isSameAs(pref2); - } - - @Test - public void addPreferenceWhenCollapsed_noPrefOnScreen_shouldAddToList() { - // Add something to collapsed list so we are in collapsed state. - mMixin.addToCollapsedList(new Preference(mAppContext)); - assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1); - - // Just 1 preference on screen: the more button - when(mScreen.getPreferenceCount()).thenReturn(1); - final Preference toBeAdded = new Preference(mAppContext); - toBeAdded.setOrder(100); - mMixin.addPreference(mScreen, toBeAdded); - - // Should have 2 prefs in collapsed list now - assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(2); - assertThat(mMixin.getCollapsedPrefs().get(0)).isSameAs(toBeAdded); - } - - @Test - public void addPreferenceWhenCollapsed_prefOrderLessThanLastOnScreen_shouldAddToScreen() { - final Preference lastPref = new Preference(mAppContext); - lastPref.setOrder(100); - // Add something to collapsed list so we are in collapsed state. - mMixin.addToCollapsedList(new Preference(mAppContext)); - verify(mExpandButton).setSummary(nullable(String.class)); - assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1); - - // 3 prefs on screen, 2 are real and the last one is more button. - when(mScreen.getPreferenceCount()).thenReturn(3); - when(mScreen.getPreference(1)).thenReturn(lastPref); - - final Preference toBeAdded = new Preference(mAppContext); - toBeAdded.setOrder(50); - mMixin.addPreference(mScreen, toBeAdded); - - verify(mScreen).removePreference(lastPref); - verify(mScreen).addPreference(toBeAdded); - assertThat(mMixin.getCollapsedPrefs().get(0)).isSameAs(lastPref); - } - - @Test - public void addPreferenceWhenCollapsed_prefOrderMoreThanLastOnScreen_shouldAddToList() { - final Preference lastPref = new Preference(mAppContext); - lastPref.setOrder(100); - // Add something to collapsed list so we are in collapsed state. - mMixin.addToCollapsedList(new Preference(mAppContext)); - verify(mExpandButton).setSummary(nullable(String.class)); - assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1); - - // 3 prefs on screen, 2 are real and the last one is more button. - when(mScreen.getPreferenceCount()).thenReturn(3); - when(mScreen.getPreference(1)).thenReturn(lastPref); - - final Preference toBeAdded = new Preference(mAppContext); - toBeAdded.setOrder(200); - mMixin.addPreference(mScreen, toBeAdded); - - verify(mScreen, never()).removePreference(any(Preference.class)); - verify(mScreen, never()).addPreference(any(Preference.class)); - verify(mExpandButton, times(2)).setSummary(nullable(String.class)); - assertThat(mMixin.getCollapsedPrefs().get(0)).isSameAs(toBeAdded); - } - - @Test - public void updateExpandSummary_noPref_noSummary() { - mMixin.updateExpandButtonSummary(); - - verify(mExpandButton).setSummary(null); - } - - @Test - public void updateExpandSummary_doNotIncludeEmptyPrefTitle() { - final Preference pref1 = new Preference(mAppContext); - pref1.setTitle("1"); - final Preference pref2 = new Preference(mAppContext); - pref2.setTitle(null); - final Preference pref3 = new Preference(mAppContext); - pref3.setTitle("3"); - final Preference pref4 = new Preference(mAppContext); - pref4.setTitle(""); - - mMixin.addToCollapsedList(pref1); - mMixin.addToCollapsedList(pref2); - mMixin.addToCollapsedList(pref3); - mMixin.addToCollapsedList(pref4); - - verify(mExpandButton).setSummary("1, 3"); - } - - @Test - public void updateExapndSummary_singlePref_expandSummarySameAsPrefTitle() { - final String TEST = "test"; - final Preference pref = new Preference(mAppContext); - pref.setTitle(TEST); - - mMixin.addToCollapsedList(pref); - verify(mExpandButton).setSummary(TEST); - } - - @Test - public void updateExapndSummary_multiPrefs_useCombinedPrefTitleAsSummary() { - final String TEST1 = "test1"; - final String TEST2 = "test2"; - final Preference pref1 = new Preference(mAppContext); - pref1.setTitle(TEST1); - final Preference pref2 = new Preference(mAppContext); - pref2.setTitle(TEST2); - - mMixin.addToCollapsedList(pref1); - mMixin.addToCollapsedList(pref2); - - verify(mExpandButton) - .setSummary(mAppContext.getString(R.string.join_many_items_middle, TEST1, TEST2)); - } -} diff --git a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java index 5c6e777395d..9cc20d6eaaa 100644 --- a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java +++ b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java @@ -43,7 +43,6 @@ import android.view.textservice.TextServicesManager; import com.android.settings.R; import com.android.settings.TestConfig; -import com.android.settings.dashboard.ProgressiveDisclosureMixin; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.XmlTestUtils; @@ -103,9 +102,6 @@ public class LanguageAndInputSettingsTest { @Test public void testGetPreferenceScreenResId() { - ProgressiveDisclosureMixin progessiveMixin = mock(ProgressiveDisclosureMixin.class); - when(progessiveMixin.isEnabled()).thenReturn(true); - ReflectionHelpers.setField(mFragment, "mProgressiveDisclosureMixin", progessiveMixin); assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(R.xml.language_and_input); } @@ -173,8 +169,6 @@ public class LanguageAndInputSettingsTest { final List niks = LanguageAndInputSettings.SEARCH_INDEX_DATA_PROVIDER .getNonIndexableKeys(context); LanguageAndInputSettings settings = new LanguageAndInputSettings(); - ReflectionHelpers.setField(settings, "mProgressiveDisclosureMixin", - mock(ProgressiveDisclosureMixin.class)); final int xmlId = settings.getPreferenceScreenResId(); final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); @@ -186,8 +180,6 @@ public class LanguageAndInputSettingsTest { public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() { final Context context = RuntimeEnvironment.application; final LanguageAndInputSettings fragment = new LanguageAndInputSettings(); - ReflectionHelpers.setField(fragment, "mProgressiveDisclosureMixin", - mock(ProgressiveDisclosureMixin.class)); final List preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context, fragment.getPreferenceScreenResId()); final List preferenceKeys = new ArrayList<>(); diff --git a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java index bd386468bc9..ec0b6eaf452 100644 --- a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java +++ b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java @@ -21,7 +21,6 @@ import android.content.Context; import android.media.AudioManager; import android.os.UserManager; import com.android.settings.R; -import com.android.settings.dashboard.ProgressiveDisclosureMixin; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.testutils.XmlTestUtils; @@ -62,8 +61,6 @@ public class SoundSettingsTest { final List niks = SoundSettings.SEARCH_INDEX_DATA_PROVIDER .getNonIndexableKeys(context); SoundSettings settings = new SoundSettings(); - ReflectionHelpers.setField(settings, "mProgressiveDisclosureMixin", - mock(ProgressiveDisclosureMixin.class)); final int xmlId = settings.getPreferenceScreenResId(); final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,