Merge "Add additional preference items to WifiSettings for configuring Wi-Fi."
This commit is contained in:
committed by
Android (Google) Code Review
commit
889db88043
@@ -1634,6 +1634,8 @@
|
|||||||
<string name="wifi_cellular_data_fallback_summary">Use cellular data when Wi\u2011Fi has no Internet access. Data usage may apply.</string>
|
<string name="wifi_cellular_data_fallback_summary">Use cellular data when Wi\u2011Fi has no Internet access. Data usage may apply.</string>
|
||||||
<!-- Action bar text message to manually add a wifi network [CHAR LIMIT=20]-->
|
<!-- Action bar text message to manually add a wifi network [CHAR LIMIT=20]-->
|
||||||
<string name="wifi_add_network">Add network</string>
|
<string name="wifi_add_network">Add network</string>
|
||||||
|
<!-- Action bar title to open additional Wi-Fi settings-->
|
||||||
|
<string name="wifi_configure_settings_preference_title">Wi\u2011Fi preferences</string>
|
||||||
<!-- Header for the list of wifi networks-->
|
<!-- Header for the list of wifi networks-->
|
||||||
<string name="wifi_access_points">Wi\u2011Fi networks</string>
|
<string name="wifi_access_points">Wi\u2011Fi networks</string>
|
||||||
<!-- Menu option to do WPS Push Button [CHAR LIMIT=25]-->
|
<!-- Menu option to do WPS Push Button [CHAR LIMIT=25]-->
|
||||||
|
@@ -17,11 +17,6 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/wifi_configure_titlebar">
|
android:title="@string/wifi_configure_titlebar">
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="saved_networks"
|
|
||||||
android:title="@string/wifi_saved_access_points_label"
|
|
||||||
android:fragment="com.android.settings.wifi.SavedAccessPointsWifiSettings" />
|
|
||||||
|
|
||||||
<!-- android:dependency="enable_wifi" -->
|
<!-- android:dependency="enable_wifi" -->
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="sleep_policy"
|
android:key="sleep_policy"
|
||||||
|
@@ -14,14 +14,23 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||||
android:title="@string/wifi_settings"
|
android:title="@string/wifi_settings"
|
||||||
settings:keywords="@string/keywords_wifi">
|
settings:keywords="@string/keywords_wifi">
|
||||||
|
|
||||||
<!-- Needed so PreferenceGroupAdapter allows AccessPointPreference to be
|
<PreferenceCategory android:key="access_points"/>
|
||||||
recycled. Removed in onResume -->
|
|
||||||
<com.android.settings.wifi.LongPressAccessPointPreference
|
|
||||||
android:key="dummy" />
|
|
||||||
|
|
||||||
|
<PreferenceCategory android:key="additional_settings">
|
||||||
|
<Preference
|
||||||
|
android:key="configure_settings"
|
||||||
|
android:title="@string/wifi_configure_settings_preference_title"
|
||||||
|
android:fragment="com.android.settings.wifi.ConfigureWifiSettings" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="saved_networks"
|
||||||
|
android:title="@string/wifi_saved_access_points_label"
|
||||||
|
android:fragment="com.android.settings.wifi.SavedAccessPointsWifiSettings" />
|
||||||
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -58,7 +58,6 @@ public class ConfigureWifiSettings extends DashboardFragment {
|
|||||||
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||||
final List<PreferenceController> controllers = new ArrayList<>();
|
final List<PreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new WifiInfoPreferenceController(context, getLifecycle(), mWifiManager));
|
controllers.add(new WifiInfoPreferenceController(context, getLifecycle(), mWifiManager));
|
||||||
controllers.add(new SavedNetworkPreferenceController(context, mWifiManager));
|
|
||||||
controllers.add(new CellularFallbackPreferenceController(context));
|
controllers.add(new CellularFallbackPreferenceController(context));
|
||||||
controllers.add(new AllowRecommendationPreferenceController(context));
|
controllers.add(new AllowRecommendationPreferenceController(context));
|
||||||
controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
|
controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
|
||||||
|
119
src/com/android/settings/wifi/LinkablePreference.java
Normal file
119
src/com/android/settings/wifi/LinkablePreference.java
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.style.TextAppearanceSpan;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import com.android.settings.LinkifyUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A preference with a title that can have linkable content on click.
|
||||||
|
*/
|
||||||
|
public class LinkablePreference extends Preference {
|
||||||
|
|
||||||
|
private LinkifyUtils.OnClickListener mClickListener;
|
||||||
|
private CharSequence mContentTitle;
|
||||||
|
private CharSequence mContentDescription;
|
||||||
|
|
||||||
|
public LinkablePreference(Context ctx, AttributeSet attrs, int defStyle) {
|
||||||
|
super(ctx, attrs, defStyle);
|
||||||
|
setSelectable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkablePreference(Context ctx, AttributeSet attrs) {
|
||||||
|
super(ctx, attrs);
|
||||||
|
setSelectable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkablePreference(Context ctx) {
|
||||||
|
super(ctx);
|
||||||
|
setSelectable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
|
super.onBindViewHolder(view);
|
||||||
|
|
||||||
|
TextView textView = (TextView) view.findViewById(android.R.id.title);
|
||||||
|
if (textView == null || mContentTitle == null || mClickListener == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
textView.setSingleLine(false);
|
||||||
|
StringBuilder contentBuilder = new StringBuilder().append(mContentTitle);
|
||||||
|
if (mContentDescription != null) {
|
||||||
|
contentBuilder.append("\n\n");
|
||||||
|
contentBuilder.append(mContentDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean linked = LinkifyUtils.linkify(textView, contentBuilder, mClickListener);
|
||||||
|
if (linked && mContentTitle != null) {
|
||||||
|
// Embolden and enlarge the title.
|
||||||
|
Spannable boldSpan = (Spannable) textView.getText();
|
||||||
|
boldSpan.setSpan(
|
||||||
|
new TextAppearanceSpan(
|
||||||
|
getContext(), android.R.style.TextAppearance_Medium),
|
||||||
|
0,
|
||||||
|
mContentTitle.length(),
|
||||||
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
textView.setText(boldSpan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the linkable text for the Preference title.
|
||||||
|
* @param contentTitle text to set the Preference title.
|
||||||
|
* @param contentDescription description text to append underneath title, can be null.
|
||||||
|
* @param clickListener OnClickListener for the link portion of the text.
|
||||||
|
*/
|
||||||
|
public void setText(
|
||||||
|
CharSequence contentTitle,
|
||||||
|
@Nullable CharSequence contentDescription,
|
||||||
|
LinkifyUtils.OnClickListener clickListener) {
|
||||||
|
mContentTitle = contentTitle;
|
||||||
|
mContentDescription = contentDescription;
|
||||||
|
mClickListener = clickListener;
|
||||||
|
// sets the title so that the title TextView is not hidden in super.onBindViewHolder()
|
||||||
|
super.setTitle(contentTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the title of the LinkablePreference. resets linkable text for reusability.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setTitle(int titleResId) {
|
||||||
|
mContentTitle = null;
|
||||||
|
mContentDescription = null;
|
||||||
|
super.setTitle(titleResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the title of the LinkablePreference. resets linkable text for reusability.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setTitle(CharSequence title) {
|
||||||
|
mContentTitle = null;
|
||||||
|
mContentDescription = null;
|
||||||
|
super.setTitle(title);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link PreferenceController} that opens saved network subsetting.
|
|
||||||
*/
|
|
||||||
public class SavedNetworkPreferenceController extends PreferenceController {
|
|
||||||
|
|
||||||
private static final String KEY_SAVED_NETWORKS = "saved_networks";
|
|
||||||
|
|
||||||
private final WifiManager mWifiManager;
|
|
||||||
|
|
||||||
public SavedNetworkPreferenceController(Context context, WifiManager wifiManager) {
|
|
||||||
super(context);
|
|
||||||
mWifiManager = wifiManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
final List<WifiConfiguration> config = mWifiManager.getConfiguredNetworks();
|
|
||||||
return config != null && !config.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_SAVED_NETWORKS;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -40,11 +40,10 @@ import android.os.HandlerThread;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.text.Spannable;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.TextAppearanceSpan;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
@@ -53,8 +52,6 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.TextView.BufferType;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -102,7 +99,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
|
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
|
||||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
|
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
|
||||||
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
|
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
|
||||||
private static final int MENU_ID_CONFIGURE = Menu.FIRST + 10;
|
|
||||||
|
|
||||||
public static final int WIFI_DIALOG_ID = 1;
|
public static final int WIFI_DIALOG_ID = 1;
|
||||||
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
||||||
@@ -115,6 +111,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
||||||
|
|
||||||
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
|
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
|
||||||
|
private static final String PREF_KEY_ACCESS_POINTS = "access_points";
|
||||||
|
private static final String PREF_KEY_ADDITIONAL_SETTINGS = "additional_settings";
|
||||||
|
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
|
||||||
|
|
||||||
protected WifiManager mWifiManager;
|
protected WifiManager mWifiManager;
|
||||||
private WifiManager.ActionListener mConnectListener;
|
private WifiManager.ActionListener mConnectListener;
|
||||||
@@ -152,7 +151,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private HandlerThread mBgThread;
|
private HandlerThread mBgThread;
|
||||||
|
|
||||||
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
|
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
|
||||||
|
|
||||||
|
private PreferenceCategory mAccessPointsPreferenceCategory;
|
||||||
|
private PreferenceCategory mAdditionalSettingsPreferenceCategory;
|
||||||
private Preference mAddPreference;
|
private Preference mAddPreference;
|
||||||
|
private Preference mSavedNetworksPreference;
|
||||||
|
private LinkablePreference mStatusMessagePreference;
|
||||||
|
|
||||||
private MenuItem mScanMenuItem;
|
private MenuItem mScanMenuItem;
|
||||||
|
|
||||||
@@ -177,9 +181,18 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
getPreferenceManager().setPreferenceComparisonCallback(
|
getPreferenceManager().setPreferenceComparisonCallback(
|
||||||
new PreferenceManager.SimplePreferenceComparisonCallback());
|
new PreferenceManager.SimplePreferenceComparisonCallback());
|
||||||
addPreferencesFromResource(R.xml.wifi_settings);
|
addPreferencesFromResource(R.xml.wifi_settings);
|
||||||
mAddPreference = new Preference(getContext());
|
|
||||||
|
mAccessPointsPreferenceCategory =
|
||||||
|
(PreferenceCategory) findPreference(PREF_KEY_ACCESS_POINTS);
|
||||||
|
mAdditionalSettingsPreferenceCategory =
|
||||||
|
(PreferenceCategory) findPreference(PREF_KEY_ADDITIONAL_SETTINGS);
|
||||||
|
mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
|
||||||
|
|
||||||
|
Context prefContext = getPrefContext();
|
||||||
|
mAddPreference = new Preference(prefContext);
|
||||||
mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
|
mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
|
||||||
mAddPreference.setTitle(R.string.wifi_add_network);
|
mAddPreference.setTitle(R.string.wifi_add_network);
|
||||||
|
mStatusMessagePreference = new LinkablePreference(prefContext);
|
||||||
|
|
||||||
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
||||||
|
|
||||||
@@ -314,7 +327,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
removePreference("dummy");
|
|
||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.resume(activity);
|
mWifiEnabler.resume(activity);
|
||||||
}
|
}
|
||||||
@@ -346,14 +358,13 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
* @param menu
|
* @param menu
|
||||||
*/
|
*/
|
||||||
void addOptionsMenuItems(Menu menu) {
|
void addOptionsMenuItems(Menu menu) {
|
||||||
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
|
||||||
mScanMenuItem = menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh);
|
|
||||||
mScanMenuItem.setEnabled(wifiIsEnabled)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
menu.add(Menu.NONE, MENU_ID_CONFIGURE, 0, R.string.wifi_menu_configure)
|
|
||||||
.setIcon(R.drawable.ic_settings_24dp)
|
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
||||||
|
mScanMenuItem = menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
|
||||||
|
.setIcon(com.android.internal.R.drawable.ic_menu_refresh);
|
||||||
|
mScanMenuItem.setEnabled(wifiIsEnabled)
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,18 +435,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case MENU_ID_CONFIGURE:
|
|
||||||
if (getActivity() instanceof SettingsActivity) {
|
|
||||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
|
||||||
ConfigureWifiSettings.class.getCanonicalName(), null,
|
|
||||||
R.string.wifi_configure_titlebar, null, this, 0);
|
|
||||||
} else {
|
|
||||||
startFragment(this, ConfigureWifiSettings.class.getCanonicalName(),
|
|
||||||
R.string.wifi_configure_titlebar, -1 /* Do not request a results */,
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -622,10 +621,10 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
// Safeguard from some delayed event handling
|
// Safeguard from some delayed event handling
|
||||||
if (getActivity() == null) return;
|
if (getActivity() == null) return;
|
||||||
if (isUiRestricted()) {
|
if (isUiRestricted()) {
|
||||||
|
mAccessPointsPreferenceCategory.removeAll();
|
||||||
if (!isUiRestrictedByOnlyAdmin()) {
|
if (!isUiRestrictedByOnlyAdmin()) {
|
||||||
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
||||||
}
|
}
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int wifiState = mWifiManager.getWifiState();
|
final int wifiState = mWifiManager.getWifiState();
|
||||||
@@ -638,7 +637,8 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
boolean hasAvailableAccessPoints = false;
|
boolean hasAvailableAccessPoints = false;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
cacheRemoveAllPrefs(getPreferenceScreen());
|
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
|
||||||
|
cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
|
||||||
for (AccessPoint accessPoint : accessPoints) {
|
for (AccessPoint accessPoint : accessPoints) {
|
||||||
// Ignore access points that are out of range.
|
// Ignore access points that are out of range.
|
||||||
if (accessPoint.getLevel() != -1) {
|
if (accessPoint.getLevel() != -1) {
|
||||||
@@ -665,12 +665,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
onPreferenceTreeClick(preference);
|
onPreferenceTreeClick(preference);
|
||||||
mOpenSsid = null;
|
mOpenSsid = null;
|
||||||
}
|
}
|
||||||
getPreferenceScreen().addPreference(preference);
|
mAccessPointsPreferenceCategory.addPreference(preference);
|
||||||
accessPoint.setListener(this);
|
accessPoint.setListener(this);
|
||||||
preference.refresh();
|
preference.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeCachedPrefs(getPreferenceScreen());
|
removeCachedPrefs(mAccessPointsPreferenceCategory);
|
||||||
if (!hasAvailableAccessPoints) {
|
if (!hasAvailableAccessPoints) {
|
||||||
setProgressBarVisible(true);
|
setProgressBarVisible(true);
|
||||||
Preference pref = new Preference(getContext()) {
|
Preference pref = new Preference(getContext()) {
|
||||||
@@ -683,14 +683,16 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
};
|
};
|
||||||
pref.setSelectable(false);
|
pref.setSelectable(false);
|
||||||
pref.setSummary(R.string.wifi_empty_list_wifi_on);
|
pref.setSummary(R.string.wifi_empty_list_wifi_on);
|
||||||
pref.setOrder(0);
|
pref.setOrder(index++);
|
||||||
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
|
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
|
||||||
getPreferenceScreen().addPreference(pref);
|
mAccessPointsPreferenceCategory.addPreference(pref);
|
||||||
mAddPreference.setOrder(1);
|
mAddPreference.setOrder(index++);
|
||||||
getPreferenceScreen().addPreference(mAddPreference);
|
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||||
|
setSavedNetworkPreferenceVisibility();
|
||||||
} else {
|
} else {
|
||||||
mAddPreference.setOrder(index++);
|
mAddPreference.setOrder(index++);
|
||||||
getPreferenceScreen().addPreference(mAddPreference);
|
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||||
|
setSavedNetworkPreferenceVisibility();
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
}
|
}
|
||||||
if (mScanMenuItem != null) {
|
if (mScanMenuItem != null) {
|
||||||
@@ -699,7 +701,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiManager.WIFI_STATE_ENABLING:
|
case WifiManager.WIFI_STATE_ENABLING:
|
||||||
getPreferenceScreen().removeAll();
|
mAccessPointsPreferenceCategory.removeAll();
|
||||||
setProgressBarVisible(true);
|
setProgressBarVisible(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -710,6 +712,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
case WifiManager.WIFI_STATE_DISABLED:
|
case WifiManager.WIFI_STATE_DISABLED:
|
||||||
setOffMessage();
|
setOffMessage();
|
||||||
|
setSavedNetworkPreferenceVisibility();
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
if (mScanMenuItem != null) {
|
if (mScanMenuItem != null) {
|
||||||
mScanMenuItem.setEnabled(false);
|
mScanMenuItem.setEnabled(false);
|
||||||
@@ -718,17 +721,20 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setSavedNetworkPreferenceVisibility() {
|
||||||
|
if (mWifiTracker.doSavedNetworksExist()) {
|
||||||
|
mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
|
||||||
|
} else {
|
||||||
|
mAdditionalSettingsPreferenceCategory.removePreference(mSavedNetworksPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setOffMessage() {
|
private void setOffMessage() {
|
||||||
if (isUiRestricted()) {
|
if (isUiRestricted()) {
|
||||||
if (!isUiRestrictedByOnlyAdmin()) {
|
if (!isUiRestrictedByOnlyAdmin()) {
|
||||||
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
||||||
}
|
}
|
||||||
getPreferenceScreen().removeAll();
|
mAccessPointsPreferenceCategory.removeAll();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView emptyTextView = getEmptyTextView();
|
|
||||||
if (emptyTextView == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,35 +750,27 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
if (!wifiScanningMode) {
|
if (!wifiScanningMode) {
|
||||||
// Show only the brief text if the user is not allowed to configure scanning settings,
|
// Show only the brief text if the user is not allowed to configure scanning settings,
|
||||||
// or the scanning mode has been turned off.
|
// or the scanning mode has been turned off.
|
||||||
emptyTextView.setText(briefText, BufferType.SPANNABLE);
|
mStatusMessagePreference.setTitle(briefText);
|
||||||
} else {
|
} else {
|
||||||
// Append the description of scanning settings with link.
|
LinkifyUtils.OnClickListener clickListener = new LinkifyUtils.OnClickListener() {
|
||||||
final StringBuilder contentBuilder = new StringBuilder();
|
|
||||||
contentBuilder.append(briefText);
|
|
||||||
contentBuilder.append("\n\n");
|
|
||||||
contentBuilder.append(getText(R.string.wifi_scan_notify_text));
|
|
||||||
LinkifyUtils.linkify(emptyTextView, contentBuilder, new LinkifyUtils.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
final SettingsActivity activity =
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
(SettingsActivity) WifiSettings.this.getActivity();
|
|
||||||
activity.startPreferencePanel(ScanningSettings.class.getName(), null,
|
activity.startPreferencePanel(ScanningSettings.class.getName(), null,
|
||||||
R.string.location_scanning_screen_title, null, null, 0);
|
R.string.location_scanning_screen_title, null, null, 0);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
mStatusMessagePreference.setText(
|
||||||
|
briefText, getText(R.string.wifi_scan_notify_text), clickListener);
|
||||||
}
|
}
|
||||||
// Embolden and enlarge the brief description anyway.
|
mAccessPointsPreferenceCategory.removeAll();
|
||||||
Spannable boldSpan = (Spannable) emptyTextView.getText();
|
mAccessPointsPreferenceCategory.addPreference(mStatusMessagePreference);
|
||||||
boldSpan.setSpan(
|
|
||||||
new TextAppearanceSpan(getActivity(), android.R.style.TextAppearance_Medium), 0,
|
|
||||||
briefText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMessagePreference(int messageId) {
|
private void addMessagePreference(int messageId) {
|
||||||
TextView emptyTextView = getEmptyTextView();
|
mStatusMessagePreference.setTitle(messageId);
|
||||||
if (emptyTextView != null) emptyTextView.setText(messageId);
|
mAccessPointsPreferenceCategory.removeAll();
|
||||||
getPreferenceScreen().removeAll();
|
mAccessPointsPreferenceCategory.addPreference(mStatusMessagePreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setProgressBarVisible(boolean visible) {
|
protected void setProgressBarVisible(boolean visible) {
|
||||||
|
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class SavedNetworkPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
|
|
||||||
private SavedNetworkPreferenceController mController;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mController = new SavedNetworkPreferenceController(mContext, mWifiManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_noSavedNetwork_shouldReturnFalse() {
|
|
||||||
when(mWifiManager.getConfiguredNetworks()).thenReturn(null);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_hasSavedNetwork_shouldReturnTrue() {
|
|
||||||
List<WifiConfiguration> configs = mock(List.class);
|
|
||||||
when(configs.isEmpty()).thenReturn(false);
|
|
||||||
when(mWifiManager.getConfiguredNetworks()).thenReturn(configs);
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user