polished up the random reminder stuff

pull/14/head
Tim Su 14 years ago
parent 06ddddb478
commit a65133c44a

@ -75,7 +75,7 @@ public class NotificationActivity extends Activity {
taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, itemFilter);
startActivity(taskListIntent);
String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.reminder_responses));
String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.responses));
Toast.makeText(this, reminder, Toast.LENGTH_LONG).show();
finish();

@ -84,7 +84,7 @@ public final class ReminderService {
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_quietStart, 22);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_quietEnd, 10);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_default_random, 7);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_default_random_hours, 0);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_time, 12);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_nagging, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_persistent, true);

@ -151,11 +151,20 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_reminder_overdue" />
<CheckBox
android:id="@+id/reminder_random"
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_reminder_random" />
android:layout_height="fill_parent">
<CheckBox
android:id="@+id/reminder_random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/TEA_reminder_random" />
<Spinner
android:id="@+id/reminder_random_interval"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- reminder mode -->
<TextView

@ -51,8 +51,8 @@
<!-- reminder time when task doesn't have a due time (hour of day) -->
<string name="p_rmd_time">reminder_time</string>
<!-- default random reminder setting (in days) -->
<string name="p_rmd_default_random">notif_default_reminder</string>
<!-- default random reminder setting (in hours) -->
<string name="p_rmd_default_random_hours">notif_default_reminder</string>
<string-array name="notif_icon_values">
<!-- Corresponding to the constants in Preferences.java (do not edit) -->

@ -292,27 +292,6 @@ to the plugin creator for fastest service.
<!-- Repeat label when repeats are not set -->
<string name="TEA_repeat_value_unset">No Repeat Set</string>
<!-- Reminder header label -->
<string name="TEA_reminder_label">Remind me...</string>
<!-- Reminder @ deadline -->
<string name="TEA_reminder_due">... when it\'s time to start the task</string>
<!-- Reminder after deadline -->
<string name="TEA_reminder_overdue">... when task is overdue</string>
<!-- Reminder at random times (%s => time plural)-->
<string name="TEA_reminder_random">... randomly every %s</string>
<!-- Reminder alarm clock label -->
<string name="TEA_reminder_alarm_label">Ring/Vibrate Type:</string>
<!-- Reminder alarm clock toggle: off -->
<string name="TEA_reminder_alarm_off">Ring Once</string>
<!-- Reminder alarm clock toggle: on -->
<string name="TEA_reminder_alarm_on">Ring Until I Dismiss Alarm</string>
<!-- Tags label -->
<string name="TEA_tags_label">Tags:</string>

@ -4,10 +4,53 @@
<!-- Resources for built-in reminders plug-in -->
<!-- =============================================== task edit activity == -->
<!-- Reminder header label -->
<string name="TEA_reminder_label">Remind me...</string>
<!-- Reminder @ deadline -->
<string name="TEA_reminder_due">... when it\'s time to start the task</string>
<!-- Reminder after deadline -->
<string name="TEA_reminder_overdue">... when task is overdue</string>
<!-- Reminder at random times (%s => time plural)-->
<string name="TEA_reminder_random">... randomly every</string>
<!-- Reminder alarm clock label -->
<string name="TEA_reminder_alarm_label">Ring/Vibrate Type:</string>
<!-- Reminder alarm clock toggle: off -->
<string name="TEA_reminder_alarm_off">Ring Once</string>
<!-- Reminder alarm clock toggle: on -->
<string name="TEA_reminder_alarm_on">Ring Until I Dismiss Alarm</string>
<string-array name="TEA_reminder_random">
<!-- random reminder labels for edit page. -->
<item>hour</item>
<item>day</item>
<item>week</item>
<item>two weeks</item>
<item>month</item>
<item>two months</item>
</string-array>
<string-array name="TEA_reminder_random_hours">
<!-- values (in hours) associated with items above. -->
<item>1</item>
<item>24</item>
<item>168</item>
<item>336</item>
<item>730</item>
<item>1460</item>
</string-array>
<!-- ==================================================== notifications == -->
<!-- Name of filter when viewing a reminder -->
<string name="rmd_NoA_filter">Astrid: Reminder</string>
<string name="rmd_NoA_filter">Reminder!</string>
<!-- ============================================= reminder preferences == -->
@ -43,6 +86,28 @@
<!-- Defaults Title -->
<string name="rmd_EPr_defaults_header">New Task Defaults</string>
<string-array name="EPr_reminder_random">
<!-- random reminder labels for preference. -->
<item>disabled</item>
<item>hourly</item>
<item>daily</item>
<item>weekly</item>
<item>bi-weekly</item>
<item>monthly</item>
<item>bi-monthly</item>
</string-array>
<string-array name="EPr_reminder_random_hours">
<!-- values (in hours) associated with items above. -->
<item>0</item>
<item>1</item>
<item>24</item>
<item>168</item>
<item>336</item>
<item>730</item>
<item>1460</item>
</string-array>
<!-- =============================================== random reminders == -->
<string-array name="reminders">

@ -20,10 +20,11 @@
android:key="@string/p_rmd_vibrate"
android:title="@string/prefs_vibrate_title"
android:summary="@string/prefs_vibrate_desc" />
<EditTextPreference
android:key="@string/p_rmd_default_random"
<ListPreference
android:key="@string/p_rmd_default_random_hours"
android:title="@string/prefs_defaultRemind_title"
android:summary="@string/prefs_defaultRemind_desc" />
android:entries="@array/EPr_reminder_random"
android:entryValues="@array/EPr_reminder_random_hours"/>
<RingtonePreference
android:key="@string/p_rmd_ringtone"
android:title="@string/rmd_EPr_ringtone_title"

@ -38,6 +38,7 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences;
/**
@ -76,9 +77,6 @@ public class EditPreferences extends PreferenceActivity {
PreferenceScreen screen = getPreferenceScreen();
initializePreference(screen);
// debugging preferences
addDebugPreferences();
// load plug-ins
Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
PackageManager pm = getPackageManager();
@ -93,7 +91,7 @@ public class EditPreferences extends PreferenceActivity {
resolveInfo.activityInfo.name);
Preference preference = new Preference(this);
preference.setTitle(resolveInfo.loadLabel(pm));
preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
preference.setIntent(intent);
String application = resolveInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
@ -111,13 +109,17 @@ public class EditPreferences extends PreferenceActivity {
for(Preference preference : entry.getValue())
screen.addPreference(preference);
}
// debugging preferences
addDebugPreferences();
}
@SuppressWarnings("nls")
private void addDebugPreferences() {
if(!Constants.DEBUG)
return;
PreferenceCategory group = new PreferenceCategory(this);
group.setTitle("DEBUG");
getPreferenceScreen().addPreference(group);

@ -37,7 +37,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
@ -212,7 +211,9 @@ public final class TaskEditActivity extends TabActivity {
controls.add(new EditTextControlSet(Task.NOTES, R.id.notes));
controls.add( new ReminderControlSet(R.id.reminder_due,
R.id.reminder_overdue, R.id.reminder_random, R.id.reminder_alarm));
R.id.reminder_overdue, R.id.reminder_alarm));
controls.add( new RandomReminderControlSet(R.id.reminder_random,
R.id.reminder_random_interval));
controls.add(new TagsControlSet(R.id.tags_container));
controls.add(new RepeatControlSet(R.id.repeat_value, R.id.repeat_interval));
@ -963,6 +964,7 @@ public final class TaskEditActivity extends TabActivity {
}
}
/**
* Control set dealing with reminder settings
*
@ -970,20 +972,14 @@ public final class TaskEditActivity extends TabActivity {
*
*/
public class ReminderControlSet implements TaskEditControlSet {
private final CheckBox during, after, random;
private final CheckBox during, after;
private final Spinner mode;
private long periodic;
public ReminderControlSet(int duringId, int afterId, int randomId, int modeId) {
public ReminderControlSet(int duringId, int afterId, int modeId) {
during = (CheckBox)findViewById(duringId);
after = (CheckBox)findViewById(afterId);
random = (CheckBox)findViewById(randomId);
mode = (Spinner)findViewById(modeId);
periodic = Preferences.getIntegerFromString(R.string.p_rmd_default_random)
* DateUtilities.ONE_DAY;
updatePeriodicString();
String[] list = new String[] {
getString(R.string.TEA_reminder_alarm_off),
getString(R.string.TEA_reminder_alarm_on),
@ -994,15 +990,6 @@ public final class TaskEditActivity extends TabActivity {
mode.setAdapter(adapter);
}
@SuppressWarnings("nls")
private void updatePeriodicString() {
if(periodic == 0)
periodic = DateUtilities.ONE_WEEK;
String dateString = "<a href='#'>" + dateUtilities.getDurationString(periodic, 1, true) + "</a>";
random.setText(Html.fromHtml(getString(R.string.TEA_reminder_random,
dateString)));
}
public void setValue(int flags) {
during.setChecked((flags & Task.NOTIFY_AT_DEADLINE) > 0);
after.setChecked((flags &
@ -1025,18 +1012,87 @@ public final class TaskEditActivity extends TabActivity {
@Override
public void readFromModel() {
setValue(model.getValue(Task.REMINDER_FLAGS));
periodic = model.getValue(Task.REMINDER_PERIOD);
if(periodic > 0) {
random.setChecked(true);
updatePeriodicString();
}
}
@Override
public void writeToModel() {
model.setValue(Task.REMINDER_FLAGS, getValue());
if(random.isChecked())
model.setValue(Task.REMINDER_PERIOD, periodic);
}
}
/**
* Control set dealing with random reminder settings
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class RandomReminderControlSet implements TaskEditControlSet {
private final CheckBox settingCheckbox;
private final Spinner periodSpinner;
private final int[] hours;
public RandomReminderControlSet(int settingCheckboxId, int periodButtonId) {
settingCheckbox = (CheckBox)findViewById(settingCheckboxId);
periodSpinner = (Spinner)findViewById(periodButtonId);
periodSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
settingCheckbox.setChecked(true);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// ignore
}
});
// create adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
TaskEditActivity.this, android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.TEA_reminder_random));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
periodSpinner.setAdapter(adapter);
// create hour array
String[] hourStrings = getResources().getStringArray(R.array.TEA_reminder_random_hours);
hours = new int[hourStrings.length];
for(int i = 0; i < hours.length; i++)
hours[i] = Integer.parseInt(hourStrings[i]);
}
@Override
public void readFromModel() {
long time;
if(isNewTask()) {
time = Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours) *
DateUtilities.ONE_HOUR;
} else {
time = model.getValue(Task.REMINDER_PERIOD);
}
settingCheckbox.setChecked(time > 0);
if(time == 0) {
time = 7*24;
}
int i;
for(i = 0; i < hours.length - 1; i++)
if(hours[i] * DateUtilities.ONE_HOUR >= time)
break;
periodSpinner.setSelection(i);
}
@Override
public void writeToModel() {
if(settingCheckbox.isChecked()) {
int hourValue = hours[periodSpinner.getSelectedItemPosition()];
model.setValue(Task.REMINDER_PERIOD, hourValue * DateUtilities.ONE_HOUR);
} else
model.setValue(Task.REMINDER_PERIOD, 0L);
}
}

@ -151,7 +151,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
String title = extras.getString(TOKEN_FILTER_TITLE);
String sql = extras.getString(TOKEN_FILTER_SQL);
ContentValues values = extras.getParcelable(TOKEN_FILTER_VALUES);
filter = new Filter("", "", title, new QueryTemplate(), values);
filter = new Filter("", "", title, new QueryTemplate(), values); //$NON-NLS-1$ //$NON-NLS-2$
filter.sqlQuery = sql;
} else {
filter = CoreFilterExposer.buildInboxFilter(getResources());
@ -457,8 +457,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
R.string.TAd_contextDeleteTask);
if(Constants.DEBUG) {
menu.add("--- debug ---"); //$NON-NLS-1$
menu.add(id, CONTEXT_MENU_DEBUG, Menu.NONE,
"schedule alarm"); //$NON-NLS-1$
"when alarm?"); //$NON-NLS-1$
menu.add(id, CONTEXT_MENU_DEBUG + 1, Menu.NONE,
"make notification"); //$NON-NLS-1$
}
@ -539,19 +540,24 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
return true;
}
// --- debug
case CONTEXT_MENU_DEBUG: {
itemId = item.getGroupId();
Task task = new Task();
task.setId(itemId);
ReminderService reminderService = new ReminderService();
final ReminderService reminderService = new ReminderService();
reminderService.setScheduler(new AlarmScheduler() {
@Override
public void createAlarm(Task theTask, long time, int type) {
Toast.makeText(TaskListActivity.this, "Scheduled Alarm: " + //$NON-NLS-1$
new Date(time), Toast.LENGTH_LONG).show();
reminderService.setScheduler(null);
}
});
reminderService.scheduleAlarm(task);
if(reminderService.getScheduler() != null)
Toast.makeText(this, "No alarms", Toast.LENGTH_LONG).show(); //$NON-NLS-1$
return true;
}

@ -7,6 +7,8 @@ import java.util.Map.Entry;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@ -35,6 +37,7 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.Preferences;
public class Astrid2To3UpgradeHelper {
@ -160,6 +163,16 @@ public class Astrid2To3UpgradeHelper {
// --- clean up database
metadataService.cleanup();
// --- upgrade properties
SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit();
if(prefs.contains(context.getString(R.string.p_rmd_default_random_hours))) {
// convert days => hours
editor.putString(context.getString(R.string.p_rmd_default_random_hours),
Integer.toString(Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours) * 24));
}
database.close();
if(dialog != null)

Loading…
Cancel
Save