aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorMark Adamson <markadamson83@gmail.com>2014-01-14 22:40:01 +0000
committerMark Adamson <markadamson83@gmail.com>2014-01-14 22:40:01 +0000
commite0cb5de9f0c164f79254eb289d22bfb3d2a35d20 (patch)
treeea5144dccb2b44926f82c3ad35294173b302fadf /src/github/daneren2005
parentea358d70f22f57211bda1e255119bf681136ee95 (diff)
downloaddsub-e0cb5de9f0c164f79254eb289d22bfb3d2a35d20.tar.gz
dsub-e0cb5de9f0c164f79254eb289d22bfb3d2a35d20.tar.bz2
dsub-e0cb5de9f0c164f79254eb289d22bfb3d2a35d20.zip
Added optional "local network SSID" to server settings
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/activity/SettingsActivity.java8
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--src/github/daneren2005/dsub/util/Util.java16
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 51e64686..a6c416ca 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());