Disable collapse when fragment is opened from search
Change-Id: I9564dff4ec53256a0fe992055049cf65ce68e37b Fix: 36076953 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -16,8 +16,8 @@
|
|||||||
package com.android.settings.dashboard;
|
package com.android.settings.dashboard;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -78,7 +78,7 @@ public interface DashboardFeatureProvider {
|
|||||||
* Returns a {@link ProgressiveDisclosureMixin} for specified fragment.
|
* Returns a {@link ProgressiveDisclosureMixin} for specified fragment.
|
||||||
*/
|
*/
|
||||||
ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
|
ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
|
||||||
DashboardFragment fragment);
|
DashboardFragment fragment, Bundle args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns additional intent filter action for dashboard tiles
|
* Returns additional intent filter action for dashboard tiles
|
||||||
|
@@ -168,8 +168,12 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
|
public ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
|
||||||
DashboardFragment fragment) {
|
DashboardFragment fragment, Bundle args) {
|
||||||
return new ProgressiveDisclosureMixin(context, mMetricsFeatureProvider, fragment);
|
boolean keepExpanded = false;
|
||||||
|
if (args != null) {
|
||||||
|
keepExpanded = args.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY) != null;
|
||||||
|
}
|
||||||
|
return new ProgressiveDisclosureMixin(context, fragment, keepExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -69,7 +69,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
mDashboardFeatureProvider =
|
mDashboardFeatureProvider =
|
||||||
FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
|
FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
|
||||||
mProgressiveDisclosureMixin = mDashboardFeatureProvider
|
mProgressiveDisclosureMixin = mDashboardFeatureProvider
|
||||||
.getProgressiveDisclosureMixin(context, this);
|
.getProgressiveDisclosureMixin(context, this, getArguments());
|
||||||
getLifecycle().addObserver(mProgressiveDisclosureMixin);
|
getLifecycle().addObserver(mProgressiveDisclosureMixin);
|
||||||
|
|
||||||
List<PreferenceController> controllers = getPreferenceControllers(context);
|
List<PreferenceController> controllers = getPreferenceControllers(context);
|
||||||
|
@@ -33,6 +33,7 @@ import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
|||||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settings.core.lifecycle.events.OnCreate;
|
import com.android.settings.core.lifecycle.events.OnCreate;
|
||||||
import com.android.settings.core.lifecycle.events.OnSaveInstanceState;
|
import com.android.settings.core.lifecycle.events.OnSaveInstanceState;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -56,13 +57,13 @@ public class ProgressiveDisclosureMixin implements Preference.OnPreferenceClickL
|
|||||||
private boolean mUserExpanded;
|
private boolean mUserExpanded;
|
||||||
|
|
||||||
public ProgressiveDisclosureMixin(Context context,
|
public ProgressiveDisclosureMixin(Context context,
|
||||||
MetricsFeatureProvider metricsFeatureProvider,
|
PreferenceFragment fragment, boolean keepExpanded) {
|
||||||
PreferenceFragment fragment) {
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
mExpandButton = new ExpandPreference(context);
|
mExpandButton = new ExpandPreference(context);
|
||||||
mExpandButton.setOnPreferenceClickListener(this);
|
mExpandButton.setOnPreferenceClickListener(this);
|
||||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
|
mUserExpanded = keepExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,7 +120,7 @@ public class ProgressiveDisclosureMixin implements Preference.OnPreferenceClickL
|
|||||||
* Whether the screen should be collapsed.
|
* Whether the screen should be collapsed.
|
||||||
*/
|
*/
|
||||||
public boolean shouldCollapse(PreferenceScreen screen) {
|
public boolean shouldCollapse(PreferenceScreen screen) {
|
||||||
return screen.getPreferenceCount() >= mTileLimit && !mUserExpanded;
|
return !mUserExpanded && screen.getPreferenceCount() >= mTileLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -74,8 +74,8 @@ public class DashboardFragmentTest {
|
|||||||
mDashboardCategory.tiles = new ArrayList<>();
|
mDashboardCategory.tiles = new ArrayList<>();
|
||||||
mDashboardCategory.tiles.add(new Tile());
|
mDashboardCategory.tiles.add(new Tile());
|
||||||
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
||||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
when(mFakeFeatureFactory.dashboardFeatureProvider.getProgressiveDisclosureMixin(
|
||||||
.getProgressiveDisclosureMixin(any(Context.class), eq(mTestFragment)))
|
any(Context.class), eq(mTestFragment), any(Bundle.class)))
|
||||||
.thenReturn(mDisclosureMixin);
|
.thenReturn(mDisclosureMixin);
|
||||||
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
|
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
|
||||||
.thenReturn(mDashboardCategory);
|
.thenReturn(mDashboardCategory);
|
||||||
|
@@ -77,8 +77,7 @@ public class ProgressiveDisclosureTest {
|
|||||||
mAppContext = ShadowApplication.getInstance().getApplicationContext();
|
mAppContext = ShadowApplication.getInstance().getApplicationContext();
|
||||||
mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
|
mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
|
||||||
mMixin = new ProgressiveDisclosureMixin(mAppContext,
|
mMixin = new ProgressiveDisclosureMixin(mAppContext,
|
||||||
mFakeFeatureFactory.metricsFeatureProvider,
|
mPreferenceFragment, false /* keepExpanded */);
|
||||||
mPreferenceFragment);
|
|
||||||
ReflectionHelpers.setField(mMixin, "mExpandButton", mExpandButton);
|
ReflectionHelpers.setField(mMixin, "mExpandButton", mExpandButton);
|
||||||
mPreference = new Preference(mAppContext);
|
mPreference = new Preference(mAppContext);
|
||||||
mPreference.setKey("test");
|
mPreference.setKey("test");
|
||||||
@@ -93,6 +92,17 @@ public class ProgressiveDisclosureTest {
|
|||||||
assertThat(mMixin.shouldCollapse(mScreen)).isFalse();
|
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
|
@Test
|
||||||
public void shouldCollapse_morePreferenceThanLimit() {
|
public void shouldCollapse_morePreferenceThanLimit() {
|
||||||
when(mScreen.getPreferenceCount()).thenReturn(5);
|
when(mScreen.getPreferenceCount()).thenReturn(5);
|
||||||
|
Reference in New Issue
Block a user