From: Marius Gavrilescu Date: Tue, 5 Mar 2013 22:32:22 +0000 (+0200) Subject: Let user change server hostname/port X-Git-Tag: 0.000_001~61 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=957f71184c0e535794763fc73102fe3289cf47ed;p=fonbot.git Let user change server hostname/port --- diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index b289fc9..a962a76 100644 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file diff --git a/src/ro/ieval/fonbot/FonBotPreferenceActivity.java b/src/ro/ieval/fonbot/FonBotPreferenceActivity.java index 848a436..8754825 100644 --- a/src/ro/ieval/fonbot/FonBotPreferenceActivity.java +++ b/src/ro/ieval/fonbot/FonBotPreferenceActivity.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; @@ -137,6 +138,37 @@ public final class FonBotPreferenceActivity extends PreferenceActivity { return true; } }); + + final EditTextPreference hostnamePreference=(EditTextPreference) findPreference("hostname"); + hostnamePreference.setSummary(hostnamePreference.getText()); + hostnamePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(final @Nullable Preference preference, final @Nullable Object newValue) { + if(newValue==null) + return false; + + hostnamePreference.setSummary(newValue.toString()); + return true; + } + }); + + final EditTextPreference portPreference=(EditTextPreference) findPreference("port"); + portPreference.setSummary(portPreference.getText()); + portPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(final @Nullable Preference preference, final @Nullable Object newValue) { + if(newValue==null) + return false; + + try{ + Integer.parseInt(newValue.toString()); + } catch (NumberFormatException e){ + return false; + } + portPreference.setSummary(newValue.toString()); + return true; + } + }); } @Override diff --git a/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java b/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java index a40f7ed..e278481 100644 --- a/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java +++ b/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java @@ -14,6 +14,7 @@ import org.eclipse.jdt.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; +import android.preference.PreferenceManager; import android.util.Log; /* @@ -127,7 +128,9 @@ public final class SendHttpMessageAsyncTask extends AsyncTask