Add static IP UI
Remove the existing UI and add per network static IP config option Change-Id: I9b8636e1559de9691144fdb54e20d40985896650
This commit is contained in:
@@ -18,21 +18,14 @@ package com.android.settings.wifi;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.System;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
@@ -41,24 +34,9 @@ public class AdvancedSettings extends PreferenceActivity
|
||||
|
||||
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
|
||||
private static final String KEY_USE_STATIC_IP = "use_static_ip";
|
||||
private static final String KEY_NUM_CHANNELS = "num_channels";
|
||||
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
||||
|
||||
private String[] mSettingNames = {
|
||||
System.WIFI_STATIC_IP, System.WIFI_STATIC_GATEWAY, System.WIFI_STATIC_NETMASK,
|
||||
System.WIFI_STATIC_DNS1, System.WIFI_STATIC_DNS2
|
||||
};
|
||||
|
||||
private String[] mPreferenceKeys = {
|
||||
"ip_address", "gateway", "netmask", "dns1", "dns2"
|
||||
};
|
||||
|
||||
private CheckBoxPreference mUseStaticIpCheckBox;
|
||||
|
||||
private static final int MENU_ITEM_SAVE = Menu.FIRST;
|
||||
private static final int MENU_ITEM_CANCEL = Menu.FIRST + 1;
|
||||
|
||||
//Tracks ro.debuggable (1 on userdebug builds)
|
||||
private static int DEBUGGABLE;
|
||||
|
||||
@@ -68,14 +46,6 @@ public class AdvancedSettings extends PreferenceActivity
|
||||
|
||||
addPreferencesFromResource(R.xml.wifi_advanced_settings);
|
||||
|
||||
mUseStaticIpCheckBox = (CheckBoxPreference) findPreference(KEY_USE_STATIC_IP);
|
||||
mUseStaticIpCheckBox.setOnPreferenceChangeListener(this);
|
||||
|
||||
for (int i = 0; i < mPreferenceKeys.length; i++) {
|
||||
Preference preference = findPreference(mPreferenceKeys[i]);
|
||||
preference.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0);
|
||||
|
||||
/**
|
||||
@@ -101,7 +71,6 @@ public class AdvancedSettings extends PreferenceActivity
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateUi();
|
||||
/**
|
||||
* Remove user control of regulatory domain
|
||||
* channel count settings in non userdebug builds
|
||||
@@ -155,16 +124,6 @@ public class AdvancedSettings extends PreferenceActivity
|
||||
pref.setValue(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
updateSettingsProvider();
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
if (key == null) return true;
|
||||
@@ -193,121 +152,11 @@ public class AdvancedSettings extends PreferenceActivity
|
||||
return false;
|
||||
}
|
||||
|
||||
} else if (key.equals(KEY_USE_STATIC_IP)) {
|
||||
boolean value = ((Boolean) newValue).booleanValue();
|
||||
|
||||
try {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.WIFI_USE_STATIC_IP, value ? 1 : 0);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
String value = (String) newValue;
|
||||
|
||||
if (!isIpAddress(value)) {
|
||||
Toast.makeText(this, R.string.wifi_ip_settings_invalid_ip, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
preference.setSummary(value);
|
||||
for (int i = 0; i < mSettingNames.length; i++) {
|
||||
if (key.equals(mPreferenceKeys[i])) {
|
||||
Settings.System.putString(getContentResolver(), mSettingNames[i], value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isIpAddress(String value) {
|
||||
|
||||
int start = 0;
|
||||
int end = value.indexOf('.');
|
||||
int numBlocks = 0;
|
||||
|
||||
while (start < value.length()) {
|
||||
|
||||
if (end == -1) {
|
||||
end = value.length();
|
||||
}
|
||||
|
||||
try {
|
||||
int block = Integer.parseInt(value.substring(start, end));
|
||||
if ((block > 255) || (block < 0)) {
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
numBlocks++;
|
||||
|
||||
start = end + 1;
|
||||
end = value.indexOf('.', start);
|
||||
}
|
||||
|
||||
return numBlocks == 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
menu.add(0, MENU_ITEM_SAVE, 0, R.string.wifi_ip_settings_menu_save)
|
||||
.setIcon(android.R.drawable.ic_menu_save);
|
||||
|
||||
menu.add(0, MENU_ITEM_CANCEL, 0, R.string.wifi_ip_settings_menu_cancel)
|
||||
.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case MENU_ITEM_SAVE:
|
||||
updateSettingsProvider();
|
||||
finish();
|
||||
return true;
|
||||
|
||||
case MENU_ITEM_CANCEL:
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void updateUi() {
|
||||
ContentResolver contentResolver = getContentResolver();
|
||||
|
||||
mUseStaticIpCheckBox.setChecked(System.getInt(contentResolver,
|
||||
System.WIFI_USE_STATIC_IP, 0) != 0);
|
||||
|
||||
for (int i = 0; i < mSettingNames.length; i++) {
|
||||
EditTextPreference preference = (EditTextPreference) findPreference(mPreferenceKeys[i]);
|
||||
String settingValue = System.getString(contentResolver, mSettingNames[i]);
|
||||
preference.setText(settingValue);
|
||||
preference.setSummary(settingValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSettingsProvider() {
|
||||
ContentResolver contentResolver = getContentResolver();
|
||||
|
||||
System.putInt(contentResolver, System.WIFI_USE_STATIC_IP,
|
||||
mUseStaticIpCheckBox.isChecked() ? 1 : 0);
|
||||
|
||||
for (int i = 0; i < mSettingNames.length; i++) {
|
||||
EditTextPreference preference = (EditTextPreference) findPreference(mPreferenceKeys[i]);
|
||||
System.putString(contentResolver, mSettingNames[i], preference.getText());
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshWifiInfo() {
|
||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
|
Reference in New Issue
Block a user