diff options
author | daneren2005 <daneren2005@gmail.com> | 2014-01-16 07:23:08 -0800 |
---|---|---|
committer | daneren2005 <daneren2005@gmail.com> | 2014-01-16 07:23:08 -0800 |
commit | 918647c81223e1c15e9bf97bd495d522d34a8e44 (patch) | |
tree | d71577ac3f24fcca231f099c378929c2d80798e7 /src | |
parent | f011b0afbe23f2bed11770abca1f5daa7ea6e895 (diff) | |
parent | e0cb5de9f0c164f79254eb289d22bfb3d2a35d20 (diff) | |
download | dsub-918647c81223e1c15e9bf97bd495d522d34a8e44.tar.gz dsub-918647c81223e1c15e9bf97bd495d522d34a8e44.tar.bz2 dsub-918647c81223e1c15e9bf97bd495d522d34a8e44.zip |
Merge pull request #248 from MarkAdamson/master
Added optional "local network SSID" to server settings
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/activity/SettingsActivity.java | 8 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Constants.java | 1 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Util.java | 16 |
3 files changed, 24 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index a1a58758..d72430e5 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -322,6 +322,10 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); + + final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(this); + serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); + serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(this); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); @@ -402,6 +406,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); + screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); @@ -533,6 +538,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private class ServerSettings { private EditTextPreference serverName; private EditTextPreference serverUrl; + private EditTextPreference serverLocalNetworkSSID; private EditTextPreference serverInternalUrl; private EditTextPreference username; private PreferenceScreen screen; @@ -542,6 +548,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer screen = (PreferenceScreen) findPreference("server" + instance); serverName = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_URL + instance); + serverLocalNetworkSSID = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverInternalUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); username = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_USERNAME + instance); @@ -594,6 +601,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer public void update() { serverName.setSummary(serverName.getText()); serverUrl.setSummary(serverUrl.getText()); + serverLocalNetworkSSID.setSummary(serverLocalNetworkSSID.getText()); serverInternalUrl.setSummary(serverInternalUrl.getText()); username.setSummary(username.getText()); screen.setSummary(serverUrl.getText()); diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 6eb859a8..1e56fbd4 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -77,6 +77,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SERVER_NAME = "serverName"; public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl"; public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl"; + public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID"; public static final String PREFERENCES_KEY_SERVER_VERSION = "serverVersion"; public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection"; public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser"; diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 6b7ec29c..57684d33 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -38,6 +38,7 @@ import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; @@ -65,6 +66,7 @@ import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; + import org.apache.http.HttpEntity; import java.io.ByteArrayOutputStream; @@ -358,7 +360,9 @@ public final class Util { StringBuilder builder = new StringBuilder(); String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); - if(allowAltAddress && Util.isWifiConnected(context)) { + if(allowAltAddress && + (prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, "").equals("") && Util.isWifiConnected(context)) + || prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, "").equals(Util.getSSID(context))) { String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); if(internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { serverUrl = internalUrl; @@ -847,6 +851,16 @@ public final class Util { boolean connected = networkInfo != null && networkInfo.isConnected(); return connected && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI); } + public static String getSSID(Context context) { + if (isWifiConnected(context)) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + if (wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) { + return wifiManager.getConnectionInfo().getSSID().replace("\"", ""); + } + return null; + } + return null; + } public static boolean isExternalStoragePresent() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); |