add preference controlling how often proxy connects to relay. Still

need to add way to change timer when interval pref is changed and
other cleanup.
This commit is contained in:
Andy2 2010-08-23 18:39:47 -07:00
parent a34ccb424f
commit b586fa1a34
7 changed files with 69 additions and 5 deletions

View file

@ -35,6 +35,7 @@
<string name="key_default_dict">key_default_dict</string>
<string name="key_default_phonies">key_default_phonies2</string>
<string name="key_default_timerenabled">key_default_timerenabled</string>
<string name="key_connect_frequency">key_connect_frequency</string>
<!-- other -->
<string name="default_host">eehouse.org</string>
@ -59,4 +60,24 @@
<item>@string/phonies_disallow</item>
</string-array>
<string-array name="connect_frequencies">
<item>@string/connect_ten_seconds</item>
<item>@string/connect_fifteen_mins</item>
<item>@string/connect_thirty_mins</item>
<item>@string/connect_one_hour</item>
<item>@string/connect_six_hours</item>
<item>@string/connect_daily</item>
<item>@string/connect_never</item>
</string-array>
<string-array name="connect_frequencies_values">
<item>10</item>
<item>900</item>
<item>1800</item>
<item>3600</item>
<item>21600</item>
<item>86400</item>
<item>-1</item>
</string-array>
</resources>

View file

@ -364,4 +364,16 @@
<string name="changes_title">Recent changes</string>
<string name="changes_button">Recent changes</string>
<string name="relay_behavior">relay behavior</string>
<string name="relay_behavior_summary">relay behavior summary</string>
<string name="connect_frequency">connect_frequency</string>
<string name="connect_ten_seconds">10 seconds</string>
<string name="connect_fifteen_mins">15 minutes</string>
<string name="connect_thirty_mins">30 minutes</string>
<string name="connect_one_hour">Hourly</string>
<string name="connect_six_hours">Every six hours</string>
<string name="connect_daily">Once every day</string>
<string name="connect_never">Never connect</string>
</resources>

View file

@ -159,6 +159,17 @@
/>
</PreferenceScreen>
<PreferenceScreen android:title="@string/relay_behavior"
android:summary="@string/relay_behavior_summary"
>
<ListPreference android:key="@string/key_connect_frequency"
android:title="@string/connect_frequency"
android:entries="@array/connect_frequencies"
android:entryValues="@array/connect_frequencies_values"
android:defaultValue="60"
/>
</PreferenceScreen>
<PreferenceScreen android:title="@string/advanced"
android:summary="@string/advanced_summary"
>

View file

@ -28,7 +28,7 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME = "summaries";
private static final String DB_NAME = "xwdb";
private static final int DB_VERSION = 3;
private static final int DB_VERSION = 4;
public static final String FILE_NAME = "FILE_NAME";
public static final String NUM_MOVES = "NUM_MOVES";

View file

@ -48,7 +48,6 @@ import org.eehouse.android.xw4.jni.*;
public class GamesList extends ListActivity {
private static final int WARN_NODICT = Utils.DIALOG_LAST + 1;
private static final int CONFIRM_DELETE_ALL = Utils.DIALOG_LAST + 2;
private static final long CHECK_INTERVAL_SECONDS = 5;
private GameListAdapter m_adapter;
private String m_invalPath = null;
@ -142,9 +141,15 @@ public class GamesList extends ListActivity {
PendingIntent intent =
PendingIntent.getActivity( this, 0,
new Intent(this, RelayActivity.class), 0);
am.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP,
0, // first firing
CHECK_INTERVAL_SECONDS*1000, intent );
long interval_millis = 1000 *
CommonPrefs.getProxyInterval( this );
if ( interval_millis > 0 ) {
am.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP,
0, // first firing
interval_millis, intent );
} else {
am.cancel( intent );
}
}
@Override

View file

@ -118,6 +118,7 @@ public class PrefsActivity extends PreferenceActivity
R.string.key_initial_player_minutes,
R.string.key_default_dict,
R.string.key_default_phonies,
R.string.key_connect_frequency,
};
SharedPreferences sp
@ -190,6 +191,10 @@ public class PrefsActivity extends PreferenceActivity
Preference pref = getPreferenceScreen().findPreference( key );
String value = sp.getString( key, "" );
if ( ! value.equals("") ) {
if ( pref instanceof android.preference.ListPreference ) {
Utils.logf( "%s: want to do lookup of user string here",
key );
}
pref.setSummary( value );
}
}

View file

@ -181,6 +181,16 @@ public class CommonPrefs {
}
}
public static long getProxyInterval( Context context )
{
String value = getString( context, R.string.key_connect_frequency );
try {
return Long.parseLong( value );
} catch ( Exception ex ) {
return 25L;
}
}
public static String getDefaultDict( Context context )
{
String value = getString( context, R.string.key_default_dict );