diff --git a/astrid/common-src/com/todoroo/andlib/widget/TodorooPreferences.java b/astrid/common-src/com/todoroo/andlib/widget/TodorooPreferences.java index 6c3101597..fcfa8da1d 100644 --- a/astrid/common-src/com/todoroo/andlib/widget/TodorooPreferences.java +++ b/astrid/common-src/com/todoroo/andlib/widget/TodorooPreferences.java @@ -11,6 +11,7 @@ import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; +import android.preference.RingtonePreference; import android.preference.Preference.OnPreferenceChangeListener; /** @@ -55,6 +56,9 @@ abstract public class TodorooPreferences extends PreferenceActivity { value = ((CheckBoxPreference)preference).isChecked(); else if(preference instanceof EditTextPreference) value = ((EditTextPreference)preference).getText(); + else if(preference instanceof RingtonePreference) { + value = getPreferenceManager().getSharedPreferences().getString(preference.getKey(), null); + } if(value != null) updatePreferences(preference, value); diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java index 1320eb72d..f99c5b662 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java @@ -22,7 +22,6 @@ package com.todoroo.astrid.reminders; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.widget.Toast; import com.timsu.astrid.R; import com.todoroo.andlib.sql.QueryTemplate; @@ -72,12 +71,11 @@ public class NotificationActivity extends Activity { new QueryTemplate().where(TaskCriteria.byId(id)), null); + String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.responses)); taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, itemFilter); + taskListIntent.putExtra(TaskListActivity.TOKEN_REMINDER, reminder); startActivity(taskListIntent); - String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.responses)); - Toast.makeText(this, reminder, Toast.LENGTH_LONG).show(); - finish(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index 41a76122c..9ee05bee8 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -17,7 +17,6 @@ import android.util.Log; import com.timsu.astrid.R; import com.timsu.astrid.data.task.TaskIdentifier; import com.timsu.astrid.utilities.Constants; -import com.timsu.astrid.utilities.Preferences; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; @@ -28,6 +27,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.model.Task; import com.todoroo.astrid.service.AstridDependencyInjector; +import com.todoroo.astrid.utility.Preferences; public class Notifications extends BroadcastReceiver { @@ -39,6 +39,11 @@ public class Notifications extends BroadcastReceiver { /** notification type extra */ static final String TYPE_KEY = "type"; //$NON-NLS-1$ + /** preference values */ + public static final int ICON_SET_PINK = 0; + public static final int ICON_SET_BORING = 1; + public static final int ICON_SET_ASTRID = 2; + // --- instance variables @Autowired @@ -136,11 +141,11 @@ public class Notifications extends BroadcastReceiver { // quiet hours? unless alarm clock boolean quietHours = false; - Integer quietHoursStart = Preferences.getQuietHourStart(context); - Integer quietHoursEnd = Preferences.getQuietHourEnd(context); + Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart); + Integer quietHoursEnd = Preferences.getIntegerFromString(R.string.p_rmd_quietEnd); if(quietHoursStart != null && quietHoursEnd != null && !nonstopMode) { int hour = new Date().getHours(); - if(quietHoursStart < quietHoursEnd) { + if(quietHoursStart <= quietHoursEnd) { if(hour >= quietHoursStart && hour < quietHoursEnd) quietHours = true; } else { // wrap across 24/hour boundary @@ -159,12 +164,15 @@ public class Notifications extends BroadcastReceiver { // set up properties (name and icon) for the notification String appName = r.getString(R.string.app_name); + Integer iconPreference = Preferences.getIntegerFromString(R.string.p_rmd_icon); + if(iconPreference == null) + iconPreference = ICON_SET_ASTRID; int icon; - switch(Preferences.getNotificationIconTheme(context)) { - case Preferences.ICON_SET_PINK: + switch(iconPreference) { + case ICON_SET_PINK: icon = R.drawable.notif_pink_alarm; break; - case Preferences.ICON_SET_BORING: + case ICON_SET_BORING: icon = R.drawable.notif_boring_alarm; break; default: @@ -179,7 +187,7 @@ public class Notifications extends BroadcastReceiver { reminder + " " + taskTitle, //$NON-NLS-1$ pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; - if(Preferences.isPersistenceMode(context)) { + if(Preferences.getBoolean(R.string.p_rmd_persistent, true)) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_SHOW_LIGHTS; notification.ledOffMS = 5000; @@ -208,11 +216,12 @@ public class Notifications extends BroadcastReceiver { if(quietHours) { notification.sound = null; } else { - Uri notificationSound = Preferences.getNotificationRingtone(context); + String notificationPreference = Preferences.getStringValue(R.string.p_rmd_ringtone); if(audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) { notification.sound = null; - } else if(notificationSound != null && - !notificationSound.toString().equals("")) { //$NON-NLS-1$ + } else if(notificationPreference != null && + notificationPreference.length() != 0) { + Uri notificationSound = Uri.parse(notificationPreference); notification.sound = notificationSound; } else { notification.defaults |= Notification.DEFAULT_SOUND; @@ -223,7 +232,7 @@ public class Notifications extends BroadcastReceiver { if(quietHours && (type == ReminderService.TYPE_RANDOM)) { notification.vibrate = null; } else { - if (Preferences.shouldVibrate(context) + if (Preferences.getBoolean(R.string.p_rmd_vibrate, true) && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION)) { notification.vibrate = new long[] {0, 1000, 500, 1000, 500, 1000}; } else { diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java index 6480421eb..ccf051716 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java @@ -9,6 +9,7 @@ import android.preference.Preference; import com.timsu.astrid.R; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.widget.TodorooPreferences; +import com.todoroo.astrid.utility.Preferences; /** * Displays the preference screen for users to edit their preferences @@ -33,23 +34,39 @@ public class ReminderPreferences extends TodorooPreferences { if(r.getString(R.string.p_rmd_quietStart).equals(preference.getKey())) { int index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_quiet_hours_start_values), (String)value); - if(index == -1) + Preference endPreference = findPreference(getString(R.string.p_rmd_quietEnd)); + if(index <= 0) { preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none)); - else { - String duration = r.getStringArray(R.array.EPr_quiet_hours_start)[index]; - preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_start_desc, duration)); + endPreference.setEnabled(false); + endPreference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none)); + } else { + String setting = r.getStringArray(R.array.EPr_quiet_hours_start)[index]; + preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_start_desc, setting)); + endPreference.setEnabled(true); + updatePreferences(endPreference, Preferences.getStringValue(endPreference.getKey())); } } else if(r.getString(R.string.p_rmd_quietEnd).equals(preference.getKey())) { int index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_quiet_hours_end_values), (String)value); - if(index == -1) + Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart); + if(index == -1 || quietHoursStart == null) preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none)); else { - String duration = r.getStringArray(R.array.EPr_quiet_hours_end)[index]; - preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_end_desc, duration)); + String setting = r.getStringArray(R.array.EPr_quiet_hours_end)[index]; + preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_end_desc, setting)); + } + } else if(r.getString(R.string.p_rmd_default_random_hours).equals(preference.getKey())) { + int index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_reminder_random_hours), (String)value); + if(index <= 0) + preference.setSummary(r.getString(R.string.rmd_EPr_defaultRemind_desc_disabled)); + else { + String setting = r.getStringArray(R.array.EPr_reminder_random)[index]; + preference.setSummary(r.getString(R.string.rmd_EPr_defaultRemind_desc, setting)); } } else if(r.getString(R.string.p_rmd_ringtone).equals(preference.getKey())) { - if(value == null) + if(value == null || "content://settings/system/notification_sound".equals(value)) preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_default)); + else if("".equals(value)) + preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_silent)); else preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_custom)); } else if(r.getString(R.string.p_rmd_persistent).equals(preference.getKey())) { @@ -57,6 +74,16 @@ public class ReminderPreferences extends TodorooPreferences { preference.setSummary(r.getString(R.string.rmd_EPr_persistent_desc_true)); else preference.setSummary(r.getString(R.string.rmd_EPr_persistent_desc_false)); + } else if(r.getString(R.string.p_rmd_vibrate).equals(preference.getKey())) { + if((Boolean)value) + preference.setSummary(r.getString(R.string.rmd_EPr_vibrate_desc_true)); + else + preference.setSummary(r.getString(R.string.rmd_EPr_vibrate_desc_false)); + } else if(r.getString(R.string.p_rmd_nagging).equals(preference.getKey())) { + if((Boolean)value) + preference.setSummary(r.getString(R.string.rmd_EPr_nagging_desc_true)); + else + preference.setSummary(r.getString(R.string.rmd_EPr_nagging_desc_false)); } } diff --git a/astrid/res/layout/task_edit_activity.xml b/astrid/res/layout/task_edit_activity.xml index 8c587c1e3..0e24d55dc 100644 --- a/astrid/res/layout/task_edit_activity.xml +++ b/astrid/res/layout/task_edit_activity.xml @@ -208,6 +208,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/repeat_label" + android:visibility="gone" style="@style/TextAppearance.GEN_EditLabel" /> @@ -276,29 +277,37 @@ android:layout_width="fill_parent" android:layout_height="fill_parent"> - - - -