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;
final String remountCommand="mount -o remount,rw /system";
final String copyToSystemCommand="cp "+info.sourceDir+" /system/app/FonBot.apk";
final String chmodSystemCommand="chmod 644 /system/app/FonBot.apk";
+ final String rmSystemCommand="rm /system/app/FonBot.apk";
final String copyToUserCommand="cp "+info.sourceDir+" /data/app/FonBot.apk";
final String chmodUserCommand="chmod 644 /data/app/FonBot.apk";
- final String rmCommand="rm "+info.sourceDir;
+ final String rmUserCommand="rm "+info.sourceDir;
if(isChecked){
Runtime.getRuntime().exec(new String[]{
"su", "-c",
- remountCommand+';'+copyToSystemCommand+';'+chmodSystemCommand+';'+rmCommand
+ remountCommand+';'+copyToSystemCommand+';'+chmodSystemCommand+';'+rmUserCommand
}).waitFor();
Toast.makeText(FonBotPreferenceActivity.this,
} else {
Runtime.getRuntime().exec(new String[]{
"su", "-c",
- remountCommand+';'+copyToUserCommand+';'+chmodUserCommand+';'+rmCommand
+ remountCommand+';'+copyToUserCommand+';'+chmodUserCommand+';'+rmSystemCommand
}).waitFor();
-
Toast.makeText(FonBotPreferenceActivity.this,
"Reboot to make FonBot a non-system application", Toast.LENGTH_LONG).show();
}
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