From 1443a92948e04e18b32a49e3f60fb1a31f6fa871 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 29 Jul 2013 11:26:13 +0300 Subject: [PATCH] Make server protocol configurable --- res/xml/prefs.xml | 3 ++- src/ro/ieval/fonbot/FonBotPreferenceActivity.java | 13 +++++++++++++ src/ro/ieval/fonbot/Utils.java | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index ceaf223..cc881fe 100644 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -6,7 +6,8 @@ - + + diff --git a/src/ro/ieval/fonbot/FonBotPreferenceActivity.java b/src/ro/ieval/fonbot/FonBotPreferenceActivity.java index 05a6c65..89b8682 100644 --- a/src/ro/ieval/fonbot/FonBotPreferenceActivity.java +++ b/src/ro/ieval/fonbot/FonBotPreferenceActivity.java @@ -139,6 +139,19 @@ public final class FonBotPreferenceActivity extends PreferenceActivity { } }); + final EditTextPreference protocolPreference=(EditTextPreference) findPreference("protocol"); + protocolPreference.setSummary(protocolPreference.getText()); + protocolPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(final @Nullable Preference preference, final @Nullable Object newValue) { + if(newValue==null) + return false; + + protocolPreference.setSummary(newValue.toString()); + return true; + } + }); + final EditTextPreference hostnamePreference=(EditTextPreference) findPreference("hostname"); hostnamePreference.setSummary(hostnamePreference.getText()); hostnamePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { diff --git a/src/ro/ieval/fonbot/Utils.java b/src/ro/ieval/fonbot/Utils.java index 5f7f69c..5c54f86 100644 --- a/src/ro/ieval/fonbot/Utils.java +++ b/src/ro/ieval/fonbot/Utils.java @@ -382,9 +382,10 @@ public final class Utils { * @throws MalformedURLException if the user preferences create an invalid URL */ public static URL getServerURL(final Context context, final String path) throws MalformedURLException{ + final String protocol=PreferenceManager.getDefaultSharedPreferences(context).getString("protocol", "https"); final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro"); final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "443")); - final URL url=new URL("http", hostname, port, path); + final URL url=new URL(protocol, hostname, port, path); return url; } -- 2.39.2