Make server protocol configurable
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 29 Jul 2013 08:26:13 +0000 (11:26 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 29 Jul 2013 08:26:13 +0000 (11:26 +0300)
res/xml/prefs.xml
src/ro/ieval/fonbot/FonBotPreferenceActivity.java
src/ro/ieval/fonbot/Utils.java

index ceaf223e9609746a19c5c4d5b422cec5aad588fb..cc881fe5617010c943854d69ea71dd0f2ecd59df 100644 (file)
@@ -6,7 +6,8 @@
     <CheckBoxPreference android:title="Device administration" android:summaryOn="Device administration is enabled." android:key="admin" android:summaryOff="Device administration is disabled. Some commands require device administration."/>
        <CheckBoxPreference android:key="foreground" android:title="Run service in foreground" android:summaryOn="The FonBot service is kept in foreground. " android:summaryOff="The FonBot service is not kept in foreground."/>
     <CheckBoxPreference android:key="system" android:summaryOff="FonBot is not a system app. Changing this requires root and busybox" android:title="System App" android:summaryOn="FonBot is a system app. Changing this requires root and busybox"/>
-    
+
+       <EditTextPreference android:dialogTitle="Server protocol" android:title="Server protocol" android:dialogMessage="Server protocol. Do not change unless you know what you are doing!" android:key="protocol" android:defaultValue="https" android:summary="https"/>
     <EditTextPreference android:dialogTitle="Server hostname" android:title="Server hostname" android:dialogMessage="Server hostname. Do not change unless you know what you are doing!" android:key="hostname" android:defaultValue="fonbot.ieval.ro" android:summary="fonbot.ieval.ro"/>
     <EditTextPreference android:dialogMessage="Server port. Do not change unless you know what you are doing!" android:dialogTitle="Server port" android:title="Server port" android:summary="443" android:defaultValue="7777" android:key="port"/>
 </PreferenceScreen>
index 05a6c65403bf710837a63461139a26c7afc4a655..89b8682055c949050d33f68535abd65a61da3344 100644 (file)
@@ -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() {
index 5f7f69c464bdd72c408d7caf2e6025963b9780e7..5c54f86e89b8ca38cfc5572eca732918fe05db90 100644 (file)
@@ -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;
        }
 
This page took 0.013469 seconds and 4 git commands to generate.