+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/connection_detail_layout"
- android:background="?android:attr/colorAccent"
- android:layout_width="match_parent"
- android:layout_height="144dp"
- android:gravity="center_vertical"
- android:orientation="horizontal">
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/ic_settings_widget_background"
- android:layout_marginLeft="72dp"
- android:elevation="2dp">
-
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"/>
-
- </FrameLayout>
-
- <TextView
- android:id="@android:id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="false"
- android:paddingLeft="20dp"
- android:textAppearance="@android:style/TextAppearance.Material.Medium"
- android:textColor="@android:color/white"/>
-
-</LinearLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
- <!-- Connected Network Header -->
- <Preference
- android:key="connection_detail"
- android:layout="@layout/connection_detail_pref"/>
+ <com.android.settings.applications.LayoutPreference
+ android:key="connection_header"
+ android:layout="@layout/settings_entity_header"
+ android:selectable="false"
+ android:order="-10000"/>
<!-- General Details Category -->
<PreferenceCategory
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
-import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.ImageView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
+import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.vpn2.ConnectivityManagerWrapper;
+import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDetailPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@VisibleForTesting
- static final String KEY_CONNECTION_DETAIL_PREF = "connection_detail";
+ static final String KEY_HEADER = "connection_header";
@VisibleForTesting
static final String KEY_BUTTONS_PREF = "buttons";
@VisibleForTesting
private Network mNetwork;
private NetworkInfo mNetworkInfo;
private NetworkCapabilities mNetworkCapabilities;
- private Context mPrefContext;
private int mRssi;
private String[] mSignalStr;
private final WifiConfiguration mWifiConfig;
private final MetricsFeatureProvider mMetricsFeatureProvider;
// UI elements - in order of appearance
- private Preference mConnectionDetailPref;
private LayoutPreference mButtonsPref;
+ private EntityHeaderController mEntityHeaderController;
private Button mForgetButton;
private Button mSignInButton;
private WifiDetailPreference mSignalStrengthPref;
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mPrefContext = screen.getPreferenceManager().getContext();
-
- mConnectionDetailPref = screen.findPreference(KEY_CONNECTION_DETAIL_PREF);
+ setupEntityHeader(screen);
mButtonsPref = (LayoutPreference) screen.findPreference(KEY_BUTTONS_PREF);
- mSignInButton = (Button) mButtonsPref.findViewById(R.id.signin_button);
+ mSignInButton = mButtonsPref.findViewById(R.id.signin_button);
mSignInButton.setText(R.string.support_sign_in_button_text);
mSignInButton.setOnClickListener(view -> signIntoNetwork());
mDnsPref = (WifiDetailPreference) screen.findPreference(KEY_DNS_PREF);
mIpv6Category = (PreferenceCategory) screen.findPreference(KEY_IPV6_CATEGORY);
- mIpv6AddressPref = (Preference) screen.findPreference(KEY_IPV6_ADDRESSES_PREF);
+ mIpv6AddressPref = screen.findPreference(KEY_IPV6_ADDRESSES_PREF);
mSecurityPref.setDetailText(mAccessPoint.getSecurityString(false /* concise */));
- mForgetButton = (Button) mButtonsPref.findViewById(R.id.forget_button);
+ mForgetButton = mButtonsPref.findViewById(R.id.forget_button);
mForgetButton.setText(R.string.forget);
mForgetButton.setOnClickListener(view -> forgetNetwork());
}
+ private void setupEntityHeader(PreferenceScreen screen) {
+ LayoutPreference headerPref = (LayoutPreference) screen.findPreference(KEY_HEADER);
+ mEntityHeaderController =
+ EntityHeaderController.newInstance(
+ mFragment.getActivity(), mFragment,
+ headerPref.findViewById(R.id.entity_header));
+
+ ImageView iconView = headerPref.findViewById(R.id.entity_header_icon);
+ iconView.setBackground(
+ mContext.getDrawable(R.drawable.ic_settings_widget_background));
+ iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+
+ mEntityHeaderController.setLabel(mAccessPoint.getSsidStr());
+ }
+
@Override
public void onResume() {
// Ensure mNetwork is set before any callbacks above are delivered, since our
private void refreshNetworkState() {
mAccessPoint.update(mWifiConfig, mWifiInfo, mNetworkInfo);
- mConnectionDetailPref.setTitle(mAccessPoint.getSettingsSummary());
+ mEntityHeaderController.setSummary(mAccessPoint.getSettingsSummary())
+ .done(mFragment.getActivity(), true /* rebind */);
}
private void refreshRssiViews() {
Drawable wifiIcon = NetworkBadging.getWifiIcon(
iconSignalLevel, NetworkBadging.BADGING_NONE, mContext.getTheme()).mutate();
- mConnectionDetailPref.setIcon(wifiIcon);
+ wifiIcon.setTint(Utils.getColorAccent(mContext));
+ mEntityHeaderController.setIcon(wifiIcon).done(mFragment.getActivity(), true /* rebind */);
Drawable wifiIconDark = wifiIcon.getConstantState().newDrawable().mutate();
wifiIconDark.setTint(mContext.getResources().getColor(
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
+import android.widget.ImageView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
+import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDetailPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wifi.AccessPoint;
import java.util.stream.Collectors;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = ShadowEntityHeaderController.class)
public class WifiDetailPreferenceControllerTest {
private static final int LEVEL = 1;
@Mock private WifiManager mockWifiManager;
@Mock private MetricsFeatureProvider mockMetricsFeatureProvider;
- @Mock private Preference mockConnectionDetailPref;
+ @Mock (answer = Answers.RETURNS_DEEP_STUBS)
+ private EntityHeaderController mockHeaderController;
+ @Mock (answer = Answers.RETURNS_DEEP_STUBS)
+ private LayoutPreference mockHeaderLayoutPreference;
+ @Mock private ImageView mockHeaderIcon;
+
@Mock private LayoutPreference mockButtonsPref;
@Mock private Button mockSignInButton;
@Mock private WifiDetailPreference mockSignalStrengthPref;
when(mockFragment.getActivity()).thenReturn(mockActivity);
+ ShadowEntityHeaderController.setUseMock(mockHeaderController);
+ // builder pattern
+ when(mockHeaderController.setRecyclerView(mockFragment.getListView(), mLifecycle))
+ .thenReturn(mockHeaderController);
+ when(mockHeaderController.setSummary(anyString())).thenReturn(mockHeaderController);
+
setupMockedPreferenceScreen();
mController = newWifiDetailPreferenceController();
}
private void setupMockedPreferenceScreen() {
when(mockScreen.getPreferenceManager().getContext()).thenReturn(mContext);
- when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_CONNECTION_DETAIL_PREF))
- .thenReturn(mockConnectionDetailPref);
+ when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_HEADER))
+ .thenReturn(mockHeaderLayoutPreference);
+ when(mockHeaderLayoutPreference.findViewById(R.id.entity_header_icon))
+ .thenReturn(mockHeaderIcon);
+
when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_BUTTONS_PREF))
.thenReturn(mockButtonsPref);
when(mockButtonsPref.findViewById(R.id.forget_button))
}
@Test
- public void connectionDetailPref_shouldHaveIconSet() {
+ public void entityHeader_shouldHaveIconSet() {
Drawable expectedIcon =
NetworkBadging.getWifiIcon(LEVEL, NetworkBadging.BADGING_NONE, mContext.getTheme());
displayAndResume();
- verify(mockConnectionDetailPref).setIcon(expectedIcon);
+ verify(mockHeaderController).setIcon(expectedIcon);
+ }
+
+ @Test
+ public void entityHeader_shouldHaveLabelSetToSsid() {
+ String label = "ssid";
+ when(mockAccessPoint.getSsidStr()).thenReturn(label);
+
+ displayAndResume();
+
+ verify(mockHeaderController).setLabel(label);
}
@Test
- public void connectionDetailPref_shouldHaveTitleSet() {
+ public void entityHeader_shouldHaveSummarySet() {
String summary = "summary";
when(mockAccessPoint.getSettingsSummary()).thenReturn(summary);
displayAndResume();
- verify(mockConnectionDetailPref).setTitle(summary);
+ verify(mockHeaderController).setSummary(summary);
}
@Test
String summary = "Connected, no Internet";
when(mockAccessPoint.getSettingsSummary()).thenReturn(summary);
- InOrder inOrder = inOrder(mockConnectionDetailPref);
+ InOrder inOrder = inOrder(mockHeaderController);
displayAndResume();
- inOrder.verify(mockConnectionDetailPref).setTitle(summary);
+ inOrder.verify(mockHeaderController).setSummary(summary);
// Check that an irrelevant capability update does not update the access point summary, as
// doing so could cause unnecessary jank...
summary = "Connected";
when(mockAccessPoint.getSettingsSummary()).thenReturn(summary);
updateNetworkCapabilities(nc);
- inOrder.verify(mockConnectionDetailPref, never()).setTitle(any());
+ inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class));
// ... but that if the network validates, then we do refresh.
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
updateNetworkCapabilities(nc);
- inOrder.verify(mockConnectionDetailPref).setTitle(summary);
+ inOrder.verify(mockHeaderController).setSummary(summary);
summary = "Connected, no Internet";
when(mockAccessPoint.getSettingsSummary()).thenReturn(summary);
// Another irrelevant update won't cause the UI to refresh...
updateNetworkCapabilities(nc);
- inOrder.verify(mockConnectionDetailPref, never()).setTitle(any());
+ inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class));
// ... but if the network is no longer validated, then we display "connected, no Internet".
nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
updateNetworkCapabilities(nc);
- inOrder.verify(mockConnectionDetailPref).setTitle(summary);
+ inOrder.verify(mockHeaderController).setSummary(summary);
}
@Test