Merge "Entity header: When screen scrolls, there should be shadow under the header." into pi-dev am: 00a2dcb8f9
am: 976280308d
Change-Id: I055b684dcb5056577e492a6d631c18a186257c4c
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 391dafc..fd17012 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -72,8 +72,6 @@
protected final String mPreferenceKey;
- protected Lifecycle mLifecycle;
-
/**
* Instantiate a controller as specified controller type and user-defined key.
* <p/>
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index ccfcff1..f0c2549 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -155,7 +155,7 @@
final Activity activity = getActivity();
final ArrayList<AbstractPreferenceController> controllers = new ArrayList<>();
mSummaryController =
- new DataUsageSummaryPreferenceController(context, this, activity);
+ new DataUsageSummaryPreferenceController(activity, getLifecycle(), this);
controllers.add(mSummaryController);
getLifecycle().addObserver(mSummaryController);
return controllers;
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 7fea16d..dea71fe 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -37,6 +37,7 @@
import android.util.RecurrenceRule;
import com.android.internal.util.CollectionUtils;
+import android.support.v7.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
@@ -63,8 +64,10 @@
private static final float RELATIVE_SIZE_LARGE = 1.25f * 1.25f; // (1/0.8)^2
private static final float RELATIVE_SIZE_SMALL = 1.0f / RELATIVE_SIZE_LARGE; // 0.8^2
- private final Fragment mFragment;
private final Activity mActivity;
+ private final EntityHeaderController mEntityHeaderController;
+ private final Lifecycle mLifecycle;
+ private final DataUsageSummary mDataUsageSummary;
private final DataUsageController mDataUsageController;
private final DataUsageInfoController mDataInfoController;
private final NetworkTemplate mDefaultTemplate;
@@ -96,27 +99,30 @@
private Intent mManageSubscriptionIntent;
- public DataUsageSummaryPreferenceController(Context context, Fragment fragment,
- Activity activity) {
- super(context, KEY);
+ public DataUsageSummaryPreferenceController(Activity activity,
+ Lifecycle lifecycle, DataUsageSummary dataUsageSummary) {
+ super(activity, KEY);
- mFragment = fragment;
mActivity = activity;
+ mEntityHeaderController = EntityHeaderController.newInstance(activity,
+ dataUsageSummary, null);
+ mLifecycle = lifecycle;
+ mDataUsageSummary = dataUsageSummary;
- final int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
- mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
- NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
+ final int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(activity);
+ mDefaultTemplate = DataUsageUtils.getDefaultTemplate(activity, defaultSubId);
+ NetworkPolicyManager policyManager = NetworkPolicyManager.from(activity);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
- mHasMobileData = DataUsageUtils.hasMobileData(context)
+ mHasMobileData = DataUsageUtils.hasMobileData(activity)
&& defaultSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- mDataUsageController = new DataUsageController(context);
+ mDataUsageController = new DataUsageController(activity);
mDataInfoController = new DataUsageInfoController();
if (mHasMobileData) {
mDataUsageTemplate = R.string.cell_data_template;
- } else if (DataUsageUtils.hasWifiRadio(context)) {
+ } else if (DataUsageUtils.hasWifiRadio(activity)) {
mDataUsageTemplate = R.string.wifi_data_template;
} else {
mDataUsageTemplate = R.string.ethernet_data_template;
@@ -128,15 +134,18 @@
@VisibleForTesting
DataUsageSummaryPreferenceController(
- Context context,
DataUsageController dataUsageController,
DataUsageInfoController dataInfoController,
NetworkTemplate defaultTemplate,
NetworkPolicyEditor policyEditor,
int dataUsageTemplate,
boolean hasMobileData,
- SubscriptionManager subscriptionManager) {
- super(context, KEY);
+ SubscriptionManager subscriptionManager,
+ Activity activity,
+ Lifecycle lifecycle,
+ EntityHeaderController entityHeaderController,
+ DataUsageSummary dataUsageSummary) {
+ super(activity, KEY);
mDataUsageController = dataUsageController;
mDataInfoController = dataInfoController;
mDefaultTemplate = defaultTemplate;
@@ -144,13 +153,17 @@
mDataUsageTemplate = dataUsageTemplate;
mHasMobileData = hasMobileData;
mSubscriptionManager = subscriptionManager;
- mFragment = null;
- mActivity = null;
+ mActivity = activity;
+ mLifecycle = lifecycle;
+ mEntityHeaderController = entityHeaderController;
+ mDataUsageSummary = dataUsageSummary;
}
@Override
public void onStart() {
- EntityHeaderController.newInstance(mActivity, mFragment, null).styleActionBar(mActivity);
+ RecyclerView view = mDataUsageSummary.getListView();
+ mEntityHeaderController.setRecyclerView(view, mLifecycle);
+ mEntityHeaderController.styleActionBar(mActivity);
}
@VisibleForTesting
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index 634fe65..cd7de00 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -25,27 +25,41 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkTemplate;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
+import com.android.settings.applications.AppInfoWithHeaderTest;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
+import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.NetworkPolicyEditor;
+import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.net.DataUsageController;
+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.Robolectric;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import java.util.concurrent.TimeUnit;
+import android.support.v7.widget.RecyclerView;
+
@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = ShadowEntityHeaderController.class)
public class DataUsageSummaryPreferenceControllerTest {
private static final long UPDATE_BACKOFF_MS = TimeUnit.MINUTES.toMillis(13);
@@ -68,7 +82,15 @@
private NetworkTemplate mNetworkTemplate;
@Mock
private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private Lifecycle mLifecycle;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private EntityHeaderController mHeaderController;
+ @Mock
+ private DataUsageSummary mDataUsageSummary;
+ private FakeFeatureFactory mFactory;
+ private Activity mActivity;
private Context mContext;
private DataUsageSummaryPreferenceController mController;
@@ -79,15 +101,27 @@
doReturn("%1$s %2%s").when(mContext)
.getString(com.android.internal.R.string.fileSizeSuffix);
+
+ mActivity = Robolectric.setupActivity(Activity.class);
+ mFactory = FakeFeatureFactory.setupForTest();
+ when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
+ .thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
+ ShadowEntityHeaderController.setUseMock(mHeaderController);
+
mController = new DataUsageSummaryPreferenceController(
- mContext,
mDataUsageController,
mDataInfoController,
mNetworkTemplate,
mPolicyEditor,
R.string.cell_data_template,
true,
- null);
+ null,
+ mActivity, null, null, null);
+ }
+
+ @After
+ public void tearDown() {
+ ShadowEntityHeaderController.reset();
}
@Test
@@ -240,14 +274,14 @@
@Test
public void testMobileData_preferenceAvailable() {
mController = new DataUsageSummaryPreferenceController(
- mContext,
mDataUsageController,
mDataInfoController,
mNetworkTemplate,
mPolicyEditor,
R.string.cell_data_template,
true,
- mSubscriptionManager);
+ mSubscriptionManager,
+ mActivity, null, null, null);
final SubscriptionInfo subInfo = new SubscriptionInfo(0, "123456", 0, "name", "carrier",
0, 0, "number", 0, null, 123, 456, "ZX");
@@ -258,19 +292,42 @@
@Test
public void testMobileData_preferenceDisabled() {
mController = new DataUsageSummaryPreferenceController(
- mContext,
mDataUsageController,
mDataInfoController,
mNetworkTemplate,
mPolicyEditor,
R.string.cell_data_template,
true,
- mSubscriptionManager);
+ mSubscriptionManager,
+ mActivity, null, null, null);
when(mSubscriptionManager.getDefaultDataSubscriptionInfo()).thenReturn(null);
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
+ @Test
+ public void testMobileData_entityHeaderSet() {
+ final RecyclerView recyclerView = new RecyclerView(mActivity);
+
+ mController = new DataUsageSummaryPreferenceController(
+ mDataUsageController,
+ mDataInfoController,
+ mNetworkTemplate,
+ mPolicyEditor,
+ R.string.cell_data_template,
+ true,
+ mSubscriptionManager,
+ mActivity, mLifecycle, mHeaderController, mDataUsageSummary);
+
+ when(mDataUsageSummary.getListView()).thenReturn(recyclerView);
+
+ mController.onStart();
+
+ verify(mHeaderController)
+ .setRecyclerView(any(RecyclerView.class), any(Lifecycle.class));
+ verify(mHeaderController).styleActionBar(any(Activity.class));
+ }
+
private DataUsageController.DataUsageInfo createTestDataUsageInfo(long now) {
DataUsageController.DataUsageInfo info = new DataUsageController.DataUsageInfo();
info.carrier = CARRIER_NAME;