Merge "Use raw string when setting wifi preference title." into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-09-06 19:26:56 +00:00
committed by Android (Google) Code Review
2 changed files with 27 additions and 7 deletions

View File

@@ -160,7 +160,7 @@ public class AccessPointPreference extends Preference {
drawable.setLevel(mLevel); drawable.setLevel(mLevel);
} }
mTitleView = (TextView) view.findViewById(com.android.internal.R.id.title); mTitleView = (TextView) view.findViewById(android.R.id.title);
if (mTitleView != null) { if (mTitleView != null) {
// Attach to the end of the title view // Attach to the end of the title view
mTitleView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mBadge, null); mTitleView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mBadge, null);
@@ -231,12 +231,7 @@ public class AccessPointPreference extends Preference {
* Updates the title and summary; may indirectly call notifyChanged(). * Updates the title and summary; may indirectly call notifyChanged().
*/ */
public void refresh() { public void refresh() {
if (mForSavedNetworks) { setTitle(this, mAccessPoint, mForSavedNetworks);
setTitle(mAccessPoint.getConfigName());
} else {
setTitle(mAccessPoint.getSsid());
}
final Context context = getContext(); final Context context = getContext();
int level = mAccessPoint.getLevel(); int level = mAccessPoint.getLevel();
int wifiSpeed = mAccessPoint.getSpeed(); int wifiSpeed = mAccessPoint.getSpeed();
@@ -265,6 +260,15 @@ public class AccessPointPreference extends Preference {
} }
} }
@VisibleForTesting
static void setTitle(AccessPointPreference preference, AccessPoint ap, boolean savedNetworks) {
if (savedNetworks) {
preference.setTitle(ap.getConfigName());
} else {
preference.setTitle(ap.getSsidStr());
}
}
/** /**
* Helper method to generate content description string. * Helper method to generate content description string.
*/ */

View File

@@ -17,6 +17,7 @@ package com.android.settingslib.wifi;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -80,4 +81,19 @@ public class AccessPointPreferenceTest {
RuntimeEnvironment.application, pref, ap)) RuntimeEnvironment.application, pref, ap))
.isEqualTo("ssid,connected,Wifi signal full.,Secure network"); .isEqualTo("ssid,connected,Wifi signal full.,Secure network");
} }
@Test
public void refresh_setTitle_shouldUseSsidString() {
final String ssid = "ssid";
final String summary = "connected";
final int security = AccessPoint.SECURITY_WEP;
final AccessPoint ap = new TestAccessPointBuilder(mContext)
.setSsid(ssid)
.setSecurity(security)
.build();
final AccessPointPreference preference = mock(AccessPointPreference.class);
AccessPointPreference.setTitle(preference, ap, false /* savedNetwork */);
verify(preference).setTitle(ssid);
}
} }