<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="poll_on_screen_on" android:summaryOff="The server is not polled when the screen is turned on" android:summaryOn="The server is polled when the screen is turned on" android:title="Poll server on screen on"/>
<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 hostname" android:title="Server hostname" android:dialogMessage="Server hostname. Do not change unless you know what you are doing!" android:key="hostname" android:defaultValue="ieval.ro" android:summary="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="7777" android:defaultValue="7777" android:key="port"/>
</PreferenceScreen>
\ No newline at end of file
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;
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
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
+import android.preference.PreferenceManager;
import android.util.Log;
/*
msg=data;
try {
- final URL url=new URL("http://ieval.ro:7777/");
+ final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro");
+ final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777"));
+ final URL url=new URL("http", hostname, port, "/");
final HttpURLConnection conn=(HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(msg.length);