diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a0bb19fd..457ac40f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -26,6 +26,9 @@ + diff --git a/res/values/arrays.xml b/res/values/arrays.xml new file mode 100644 index 00000000..9d0f4cee --- /dev/null +++ b/res/values/arrays.xml @@ -0,0 +1,9 @@ + + + + 0 + 1 + 2 + 3 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 56e6d6f3..d130c574 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -19,4 +19,23 @@ To: Sent: Received: + + General + Auto-check mail + Check interval + %s minutes + Delivery status + Check delivery status of sent emails + Privacy + Hide locale + Use English for text added to outgoing emails (\'Re:\', \'wrote:\', etc.) + Sent time + Include sent time in outgoing emails + Routing + Relays + Use %s relays when sending mail + Minimum delay per hop + %s minutes + Maximum delay per hop + %s minutes diff --git a/res/xml/settings.xml b/res/xml/settings.xml new file mode 100644 index 00000000..737f372e --- /dev/null +++ b/res/xml/settings.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/i2p/bote/MailListActivity.java b/src/i2p/bote/MailListActivity.java index 3ff0c10b..8c1064d0 100644 --- a/src/i2p/bote/MailListActivity.java +++ b/src/i2p/bote/MailListActivity.java @@ -156,8 +156,15 @@ public class MailListActivity extends ActionBarActivity implements return true; } - // Handle action buttons and overflow - return super.onOptionsItemSelected(item); + switch (item.getItemId()) { + case R.id.action_settings: + Intent si = new Intent(this, SettingsActivity.class); + startActivity(si); + return true; + + default: + return super.onOptionsItemSelected(item); + } } @Override diff --git a/src/i2p/bote/SettingsActivity.java b/src/i2p/bote/SettingsActivity.java new file mode 100644 index 00000000..99f02b16 --- /dev/null +++ b/src/i2p/bote/SettingsActivity.java @@ -0,0 +1,78 @@ +package i2p.bote; + +import java.util.Iterator; +import java.util.Map; + +import android.annotation.SuppressLint; +import android.annotation.TargetApi; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; + +public class SettingsActivity extends PreferenceActivity { + + @SuppressLint("NewApi") + @SuppressWarnings("deprecation") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + addPreferencesFromResource(R.xml.settings); + } else { + // Display the fragment as the main content. + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new SettingsFragment()) + .commit(); + } + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public static class SettingsFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.settings); + } + } + + @Override + protected void onPause() { + Configuration config = I2PBote.getInstance().getConfiguration(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + + Map all = prefs.getAll(); + Iterator iterator = all.keySet().iterator(); + while (iterator.hasNext()) { + String x = iterator.next(); + android.util.Log.i("I2P-Bote", "Looking at setting " + x); + if (x.startsWith("i2pbote.")) // Skip over UI-related settings + continue; + else if ("autoMailCheckEnabled".equals(x)) + config.setAutoMailCheckEnabled(prefs.getBoolean(x, true)); + else if ("mailCheckInterval".equals(x)) + config.setMailCheckInterval(prefs.getInt(x, 30)); + else if ("deliveryCheckEnabled".equals(x)) + config.setDeliveryCheckEnabled(prefs.getBoolean(x, true)); + else if ("hideLocale".equals(x)) + config.setHideLocale(prefs.getBoolean(x, true)); + else if ("includeSentTime".equals(x)) + config.setIncludeSentTime(prefs.getBoolean(x, true)); + else if ("numSendHops".equals(x)) + config.setNumStoreHops(Integer.parseInt(prefs.getString(x, "0"))); + else if ("relayMinDelay".equals(x)) + config.setRelayMinDelay(prefs.getInt(x, 5)); + else if ("relayMaxDelay".equals(x)) + config.setRelayMaxDelay(prefs.getInt(x, 40)); + } + + config.save(); + + // Store the settings in Android + super.onPause(); + } +} diff --git a/src/i2p/bote/util/IntEditTextPreference.java b/src/i2p/bote/util/IntEditTextPreference.java new file mode 100644 index 00000000..d484ab11 --- /dev/null +++ b/src/i2p/bote/util/IntEditTextPreference.java @@ -0,0 +1,39 @@ +package i2p.bote.util; + +import android.content.Context; +import android.preference.EditTextPreference; +import android.text.InputType; +import android.util.AttributeSet; + +public class IntEditTextPreference extends EditTextPreference { + + public IntEditTextPreference(Context context) { + super(context); + getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); + } + + public IntEditTextPreference(Context context, AttributeSet attrs) { + super(context, attrs); + getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); + } + + public IntEditTextPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); + } + + @Override + public CharSequence getSummary() { + return String.format((String) super.getSummary(), getText()); + } + + @Override + protected String getPersistedString(String defaultReturnValue) { + return String.valueOf(getPersistedInt(-1)); + } + + @Override + protected boolean persistString(String value) { + return persistInt(Integer.valueOf(value)); + } +}