Bundle internal router, settings to choose internal or remote
This commit is contained in:
@@ -307,11 +307,6 @@ public class EmailListActivity extends ActionBarActivity implements
|
||||
System.setProperty("i2p.dir.base", myDir);
|
||||
System.setProperty("i2p.dir.config", myDir);
|
||||
System.setProperty("wrapper.logfile", myDir + "/wrapper.log");
|
||||
|
||||
// Set the I2CP host/port
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
System.setProperty(I2PClient.PROP_TCP_HOST, prefs.getString("i2pbote.i2cp.tcp.host", "127.0.0.1"));
|
||||
System.setProperty(I2PClient.PROP_TCP_PORT, prefs.getString("i2pbote.i2cp.tcp.port", "7654"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package i2p.bote.android.config;
|
||||
import i2p.bote.Configuration;
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.SummaryEditTextPreference;
|
||||
import i2p.bote.email.EmailIdentity;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
|
||||
@@ -21,7 +22,12 @@ import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -207,10 +213,102 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
String settings = getArguments().getString("settings");
|
||||
if ("general".equals(settings)) {
|
||||
addPreferencesFromResource(R.xml.settings_general);
|
||||
|
||||
final PreferenceCategory i2pCat = (PreferenceCategory)findPreference("i2pCategory");
|
||||
CheckBoxPreference routerAuto = (CheckBoxPreference)findPreference("i2pbote.router.auto");
|
||||
|
||||
if (!routerAuto.isChecked()) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
}
|
||||
|
||||
routerAuto.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final Boolean checked = (Boolean) newValue;
|
||||
if (!checked.booleanValue()) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
} else {
|
||||
Preference p1 = i2pCat.findPreference("i2pbote.router.use");
|
||||
Preference p2 = i2pCat.findPreference("i2pbote.i2cp.tcp.host");
|
||||
Preference p3 = i2pCat.findPreference("i2pbote.i2cp.tcp.port");
|
||||
if (p1 != null)
|
||||
i2pCat.removePreference(p1);
|
||||
if (p2 != null)
|
||||
i2pCat.removePreference(p2);
|
||||
if (p3 != null)
|
||||
i2pCat.removePreference(p3);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupI2PCategory(Context context, PreferenceCategory i2pCat) {
|
||||
final ListPreference routerChoice = createRouterChoice(context);
|
||||
final EditTextPreference hostField = createHostField(context);
|
||||
final EditTextPreference portField = createPortField(context);
|
||||
i2pCat.addPreference(routerChoice);
|
||||
i2pCat.addPreference(hostField);
|
||||
i2pCat.addPreference(portField);
|
||||
|
||||
if ("remote".equals(routerChoice.getValue())) {
|
||||
hostField.setEnabled(true);
|
||||
portField.setEnabled(true);
|
||||
}
|
||||
|
||||
routerChoice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String val = newValue.toString();
|
||||
int index = routerChoice.findIndexOfValue(val);
|
||||
if (index == 2) {
|
||||
hostField.setEnabled(true);
|
||||
hostField.setText("127.0.0.1");
|
||||
portField.setEnabled(true);
|
||||
portField.setText("7654");
|
||||
} else {
|
||||
hostField.setEnabled(false);
|
||||
hostField.setText("internal");
|
||||
portField.setEnabled(false);
|
||||
portField.setText("internal");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ListPreference createRouterChoice(Context context) {
|
||||
ListPreference routerChoice = new ListPreference(context);
|
||||
routerChoice.setKey("i2pbote.router.use");
|
||||
routerChoice.setEntries(R.array.routerOptionNames);
|
||||
routerChoice.setEntryValues(R.array.routerOptions);
|
||||
routerChoice.setTitle("Router");
|
||||
routerChoice.setSummary("%s");
|
||||
routerChoice.setDialogTitle("Router to use");
|
||||
routerChoice.setDefaultValue("internal");
|
||||
return routerChoice;
|
||||
}
|
||||
|
||||
private static EditTextPreference createHostField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.host");
|
||||
p.setTitle(R.string.pref_title_i2cp_host);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
private static EditTextPreference createPortField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.port");
|
||||
p.setTitle(R.string.pref_title_i2cp_port);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Update list of identities in headers
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
package i2p.bote.android.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.RouterLaunch;
|
||||
import i2p.bote.I2PBote;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class BoteService extends Service {
|
||||
boolean mUseInternalRouter;
|
||||
RouterContext mRouterContext;
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// Init from settings
|
||||
Init init = new Init(this);
|
||||
mUseInternalRouter = init.initialize();
|
||||
if (mUseInternalRouter)
|
||||
new Thread(new RouterStarter()).start();
|
||||
I2PBote.getInstance().startUp();
|
||||
return START_STICKY;
|
||||
}
|
||||
@@ -20,5 +33,24 @@ public class BoteService extends Service {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
I2PBote.getInstance().shutDown();
|
||||
if (mUseInternalRouter)
|
||||
new Thread(new RouterStopper()).start();
|
||||
}
|
||||
|
||||
private class RouterStarter implements Runnable {
|
||||
public void run() {
|
||||
RouterLaunch.main(null);
|
||||
List<RouterContext> contexts = RouterContext.listContexts();
|
||||
mRouterContext = contexts.get(0);
|
||||
mRouterContext.router().setKillVMOnEnd(false);
|
||||
}
|
||||
}
|
||||
|
||||
private class RouterStopper implements Runnable {
|
||||
public void run() {
|
||||
RouterContext ctx = mRouterContext;
|
||||
if (ctx != null)
|
||||
ctx.router().shutdown(Router.EXIT_HARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user