Added settings
This commit is contained in:
@ -26,6 +26,9 @@
|
||||
<activity
|
||||
android:name="i2p.bote.ViewEmailActivity"
|
||||
android:parentActivityName="i2p.bote.MailListActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.SettingsActivity"
|
||||
android:parentActivityName="i2p.bote.MailListActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
9
res/values/arrays.xml
Normal file
9
res/values/arrays.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="setting0to3">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -19,4 +19,23 @@
|
||||
<string name="email_to">To:</string>
|
||||
<string name="email_sent">Sent:</string>
|
||||
<string name="email_received">Received:</string>
|
||||
|
||||
<string name="pref_title_general">General</string>
|
||||
<string name="pref_title_autoMail">Auto-check mail</string>
|
||||
<string name="pref_title_checkInterval">Check interval</string>
|
||||
<string name="pref_summ_checkInterval">%s minutes</string>
|
||||
<string name="pref_title_delivery">Delivery status</string>
|
||||
<string name="pref_summ_delivery">Check delivery status of sent emails</string>
|
||||
<string name="pref_title_privacy">Privacy</string>
|
||||
<string name="pref_title_hideLocale">Hide locale</string>
|
||||
<string name="pref_summ_hideLocale">Use English for text added to outgoing emails (\'Re:\', \'wrote:\', etc.)</string>
|
||||
<string name="pref_title_sentTime">Sent time</string>
|
||||
<string name="pref_summ_sentTime">Include sent time in outgoing emails</string>
|
||||
<string name="pref_title_routing">Routing</string>
|
||||
<string name="pref_title_numHops">Relays</string>
|
||||
<string name="pref_summ_numHops">Use %s relays when sending mail</string>
|
||||
<string name="pref_title_minDelay">Minimum delay per hop</string>
|
||||
<string name="pref_summ_minDelay">%s minutes</string>
|
||||
<string name="pref_title_maxDelay">Maximum delay per hop</string>
|
||||
<string name="pref_summ_maxDelay">%s minutes</string>
|
||||
</resources>
|
||||
|
58
res/xml/settings.xml
Normal file
58
res/xml/settings.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_title_general" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="autoMailCheckEnabled"
|
||||
android:title="@string/pref_title_autoMail" />
|
||||
|
||||
<i2p.bote.util.IntEditTextPreference
|
||||
android:defaultValue="30"
|
||||
android:dependency="autoMailCheckEnabled"
|
||||
android:key="mailCheckInterval"
|
||||
android:summary="@string/pref_summ_checkInterval"
|
||||
android:title="@string/pref_title_checkInterval" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="deliveryCheckEnabled"
|
||||
android:summary="@string/pref_summ_delivery"
|
||||
android:title="@string/pref_title_delivery" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_title_privacy" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="hideLocale"
|
||||
android:summary="@string/pref_summ_hideLocale"
|
||||
android:title="@string/pref_title_hideLocale" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="includeSentTime"
|
||||
android:summary="@string/pref_summ_sentTime"
|
||||
android:title="@string/pref_title_sentTime" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_title_routing" >
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/setting0to3"
|
||||
android:entryValues="@array/setting0to3"
|
||||
android:key="numSendHops"
|
||||
android:summary="@string/pref_summ_numHops"
|
||||
android:title="@string/pref_title_numHops" />
|
||||
|
||||
<i2p.bote.util.IntEditTextPreference
|
||||
android:defaultValue="5"
|
||||
android:dependency="numSendHops"
|
||||
android:key="relayMinDelay"
|
||||
android:summary="@string/pref_summ_minDelay"
|
||||
android:title="@string/pref_title_minDelay" />
|
||||
<i2p.bote.util.IntEditTextPreference
|
||||
android:defaultValue="40"
|
||||
android:dependency="numSendHops"
|
||||
android:key="relayMaxDelay"
|
||||
android:summary="@string/pref_summ_maxDelay"
|
||||
android:title="@string/pref_title_maxDelay" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
@ -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
|
||||
|
78
src/i2p/bote/SettingsActivity.java
Normal file
78
src/i2p/bote/SettingsActivity.java
Normal file
@ -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<String, ?> all = prefs.getAll();
|
||||
Iterator<String> 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();
|
||||
}
|
||||
}
|
39
src/i2p/bote/util/IntEditTextPreference.java
Normal file
39
src/i2p/bote/util/IntEditTextPreference.java
Normal file
@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user