Merge "Change header of wifi detail page to "Network info"."
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 96560a0..df2168d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1971,6 +1971,8 @@
<string name="wifi_advanced_ip_address_title">IP address</string>
<!-- Wifi Network Details -->
+ <!-- Wifi details title-->
+ <string name="wifi_details_title">Network info</string>
<!-- Wifi details preference title to display router IP subnet mask -->
<string name="wifi_details_subnet_mask">Subnet mask</string>
<!-- Wifi details preference title to display router DNS info -->
diff --git a/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java b/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java
new file mode 100644
index 0000000..81413d2
--- /dev/null
+++ b/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 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.wifi.details;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import com.android.settings.R;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnCreate;
+
+/**
+ * ActionBar lifecycle observer for {@link WifiNetworkDetailsFragment}.
+ */
+public class WifiDetailActionBarObserver implements LifecycleObserver, OnCreate {
+
+ private final Fragment mFragment;
+ private final Context mContext;
+
+ public WifiDetailActionBarObserver(Context context, Fragment fragment) {
+ mContext = context;
+ mFragment = fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ if (mFragment.getActivity() != null) {
+ mFragment.getActivity().getActionBar()
+ .setTitle(mContext.getString(R.string.wifi_details_title));
+ }
+ }
+}
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 0016010..8145d77 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -21,15 +21,14 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
-
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.wifi.AccessPoint;
-
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -39,13 +38,18 @@
* {@link AccessPoint#saveWifiState(Bundle)} in order to properly render this page.
*/
public class WifiNetworkDetailsFragment extends DashboardFragment {
+
private static final String TAG = "WifiNetworkDetailsFrg";
private AccessPoint mAccessPoint;
private WifiDetailPreferenceController mWifiDetailPreferenceController;
+ private WifiDetailActionBarObserver mWifiDetailActionBarObserver;
@Override
public void onAttach(Context context) {
+ mWifiDetailActionBarObserver = new WifiDetailActionBarObserver(context, this);
+ getLifecycle().addObserver(mWifiDetailActionBarObserver);
+
mAccessPoint = new AccessPoint(context, getArguments());
super.onAttach(context);
}
@@ -78,8 +82,6 @@
context.getSystemService(WifiManager.class),
mMetricsFeatureProvider);
- ArrayList<AbstractPreferenceController> controllers = new ArrayList(1);
- controllers.add(mWifiDetailPreferenceController);
- return controllers;
+ return new ArrayList<>(Collections.singletonList(mWifiDetailPreferenceController));
}
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java
new file mode 100644
index 0000000..c573d3c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 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.wifi.details;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WifiDetailActionBarObserverTest {
+
+ @Mock private Bundle mockBundle;
+ @Mock private Activity mockActivity;
+ @Mock private ActionBar mockActionBar;
+ @Mock private WifiNetworkDetailsFragment mockFragment;
+
+ private Context mContext = RuntimeEnvironment.application;
+ private Lifecycle mLifecycle;
+ private WifiDetailActionBarObserver mObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mLifecycle = new Lifecycle();
+
+ when(mockFragment.getActivity()).thenReturn(mockActivity);
+ when(mockActivity.getActionBar()).thenReturn(mockActionBar);
+
+ mObserver = new WifiDetailActionBarObserver(mContext, mockFragment);
+ mLifecycle.addObserver(mObserver);
+ }
+
+ @Test
+ public void actionBarIsSetToNetworkInfo() {
+ mLifecycle.onCreate(mockBundle);
+
+ verify(mockActionBar).setTitle(mContext.getString(R.string.wifi_details_title));
+ }
+}