Reformat wifisettings fragment.
Bug: 111875856 Test: rebuild Change-Id: I9f8d5aaab0dc5015416084aac273c4f01e52a4ed
This commit is contained in:
@@ -47,6 +47,10 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.LinkifyUtils;
|
import com.android.settings.LinkifyUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -72,10 +76,6 @@ import com.android.settingslib.wifi.WifiTrackerFactory;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceCategory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two types of UI are provided here.
|
* Two types of UI are provided here.
|
||||||
*
|
*
|
||||||
@@ -252,60 +252,63 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
mConnectListener = new WifiManager.ActionListener() {
|
mConnectListener = new WifiManager.ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void onFailure(int reason) {
|
@Override
|
||||||
Activity activity = getActivity();
|
public void onFailure(int reason) {
|
||||||
if (activity != null) {
|
Activity activity = getActivity();
|
||||||
Toast.makeText(activity,
|
if (activity != null) {
|
||||||
R.string.wifi_failed_connect_message,
|
Toast.makeText(activity,
|
||||||
Toast.LENGTH_SHORT).show();
|
R.string.wifi_failed_connect_message,
|
||||||
}
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
mSaveListener = new WifiManager.ActionListener() {
|
mSaveListener = new WifiManager.ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void onFailure(int reason) {
|
@Override
|
||||||
Activity activity = getActivity();
|
public void onFailure(int reason) {
|
||||||
if (activity != null) {
|
Activity activity = getActivity();
|
||||||
Toast.makeText(activity,
|
if (activity != null) {
|
||||||
R.string.wifi_failed_save_message,
|
Toast.makeText(activity,
|
||||||
Toast.LENGTH_SHORT).show();
|
R.string.wifi_failed_save_message,
|
||||||
}
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
mForgetListener = new WifiManager.ActionListener() {
|
mForgetListener = new WifiManager.ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void onFailure(int reason) {
|
@Override
|
||||||
Activity activity = getActivity();
|
public void onFailure(int reason) {
|
||||||
if (activity != null) {
|
Activity activity = getActivity();
|
||||||
Toast.makeText(activity,
|
if (activity != null) {
|
||||||
R.string.wifi_failed_forget_message,
|
Toast.makeText(activity,
|
||||||
Toast.LENGTH_SHORT).show();
|
R.string.wifi_failed_forget_message,
|
||||||
}
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mDialogMode = savedInstanceState.getInt(SAVE_DIALOG_MODE);
|
mDialogMode = savedInstanceState.getInt(SAVE_DIALOG_MODE);
|
||||||
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
||||||
mAccessPointSavedState =
|
mAccessPointSavedState =
|
||||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState.containsKey(SAVED_WIFI_NFC_DIALOG_STATE)) {
|
if (savedInstanceState.containsKey(SAVED_WIFI_NFC_DIALOG_STATE)) {
|
||||||
mWifiNfcDialogSavedState =
|
mWifiNfcDialogSavedState =
|
||||||
savedInstanceState.getBundle(SAVED_WIFI_NFC_DIALOG_STATE);
|
savedInstanceState.getBundle(SAVED_WIFI_NFC_DIALOG_STATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +374,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private WifiEnabler createWifiEnabler() {
|
private WifiEnabler createWifiEnabler() {
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
return new WifiEnabler(activity, new SwitchBarController(activity.getSwitchBar()),
|
return new WifiEnabler(activity, new SwitchBarController(activity.getSwitchBar()),
|
||||||
mMetricsFeatureProvider);
|
mMetricsFeatureProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -449,38 +452,38 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
|
||||||
Preference preference = (Preference) view.getTag();
|
Preference preference = (Preference) view.getTag();
|
||||||
|
|
||||||
if (preference instanceof LongPressAccessPointPreference) {
|
if (preference instanceof LongPressAccessPointPreference) {
|
||||||
mSelectedAccessPoint =
|
mSelectedAccessPoint =
|
||||||
((LongPressAccessPointPreference) preference).getAccessPoint();
|
((LongPressAccessPointPreference) preference).getAccessPoint();
|
||||||
menu.setHeaderTitle(mSelectedAccessPoint.getSsid());
|
menu.setHeaderTitle(mSelectedAccessPoint.getSsid());
|
||||||
if (mSelectedAccessPoint.isConnectable()) {
|
if (mSelectedAccessPoint.isConnectable()) {
|
||||||
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
|
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiConfiguration config = mSelectedAccessPoint.getConfig();
|
WifiConfiguration config = mSelectedAccessPoint.getConfig();
|
||||||
// Some configs are ineditable
|
// Some configs are ineditable
|
||||||
if (WifiUtils.isNetworkLockedDown(getActivity(), config)) {
|
if (WifiUtils.isNetworkLockedDown(getActivity(), config)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
|
if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
|
||||||
// Allow forgetting a network if either the network is saved or ephemerally
|
// Allow forgetting a network if either the network is saved or ephemerally
|
||||||
// connected. (In the latter case, "forget" blacklists the network so it won't
|
// connected. (In the latter case, "forget" blacklists the network so it won't
|
||||||
// be used again, ephemerally).
|
// be used again, ephemerally).
|
||||||
menu.add(Menu.NONE, MENU_ID_FORGET, 0, R.string.wifi_menu_forget);
|
menu.add(Menu.NONE, MENU_ID_FORGET, 0, R.string.wifi_menu_forget);
|
||||||
}
|
}
|
||||||
if (mSelectedAccessPoint.isSaved()) {
|
if (mSelectedAccessPoint.isSaved()) {
|
||||||
menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
|
menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
|
||||||
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
||||||
if (nfcAdapter != null && nfcAdapter.isEnabled() &&
|
if (nfcAdapter != null && nfcAdapter.isEnabled() &&
|
||||||
mSelectedAccessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
|
mSelectedAccessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
|
||||||
// Only allow writing of NFC tags for password-protected networks.
|
// Only allow writing of NFC tags for password-protected networks.
|
||||||
menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc);
|
menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -954,11 +957,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
ContentResolver contentResolver = getContentResolver();
|
ContentResolver contentResolver = getContentResolver();
|
||||||
return Settings.Global.getInt(contentResolver,
|
return Settings.Global.getInt(contentResolver,
|
||||||
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
|
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& Settings.Global.getInt(contentResolver,
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& Settings.Global.getInt(contentResolver,
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
||||||
&& !powerManager.isPowerSaveMode();
|
&& !powerManager.isPowerSaveMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1119,25 +1122,26 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
@Override
|
@Override
|
||||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||||
final List<SearchIndexableRaw> result = new ArrayList<>();
|
boolean enabled) {
|
||||||
final Resources res = context.getResources();
|
final List<SearchIndexableRaw> result = new ArrayList<>();
|
||||||
|
final Resources res = context.getResources();
|
||||||
|
|
||||||
// Add fragment title if we are showing this fragment
|
// Add fragment title if we are showing this fragment
|
||||||
if (res.getBoolean(R.bool.config_show_wifi_settings)) {
|
if (res.getBoolean(R.bool.config_show_wifi_settings)) {
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||||
data.title = res.getString(R.string.wifi_settings);
|
data.title = res.getString(R.string.wifi_settings);
|
||||||
data.screenTitle = res.getString(R.string.wifi_settings);
|
data.screenTitle = res.getString(R.string.wifi_settings);
|
||||||
data.keywords = res.getString(R.string.keywords_wifi);
|
data.keywords = res.getString(R.string.keywords_wifi);
|
||||||
data.key = DATA_KEY_REFERENCE;
|
data.key = DATA_KEY_REFERENCE;
|
||||||
result.add(data);
|
result.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static class SummaryProvider
|
private static class SummaryProvider
|
||||||
implements SummaryLoader.SummaryProvider, OnSummaryChangeListener {
|
implements SummaryLoader.SummaryProvider, OnSummaryChangeListener {
|
||||||
@@ -1170,7 +1174,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
= new SummaryLoader.SummaryProviderFactory() {
|
= new SummaryLoader.SummaryProviderFactory() {
|
||||||
@Override
|
@Override
|
||||||
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
||||||
SummaryLoader summaryLoader) {
|
SummaryLoader summaryLoader) {
|
||||||
return new SummaryProvider(activity, summaryLoader);
|
return new SummaryProvider(activity, summaryLoader);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user