cool new astrid reminder thing, polished up reminder settings

pull/14/head
Tim Su 14 years ago
parent d083f81c3e
commit 9df24b5fff

@ -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);

@ -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();
}
}

@ -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 {

@ -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));
}
}

@ -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" />
<LinearLayout
android:orientation="horizontal"
@ -217,13 +218,13 @@
<Button
android:id="@+id/repeat_value"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/repeat_interval"
android:layout_weight="1"
android:layout_marginRight="10dip"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
@ -276,29 +277,37 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- calendar integration -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/TEA_calendar_label"
style="@style/TextAppearance.GEN_EditLabel" />
<CheckBox
android:id="@+id/add_to_calendar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_addToCalendar_label" />
<Button
android:id="@+id/view_calendar_event"
<!-- calendar integration -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_showCalendar_label"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" />
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/TEA_calendar_label"
style="@style/TextAppearance.GEN_EditLabel" />
<CheckBox
android:id="@+id/add_to_calendar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_addToCalendar_label" />
<Button
android:id="@+id/view_calendar_event"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_showCalendar_label"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" />
</LinearLayout>
<!-- estimated time -->
<TextView

@ -57,6 +57,31 @@
android:layout_height="fill_parent"/>
</FrameLayout>
<!-- Reminder -->
<RelativeLayout android:id="@+id/reminderContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_weight="1">
<TextView android:id="@+id/reminderLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
style="@style/TextAppearance.TLA_Reminder"
android:background="@drawable/reminder_popup"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15px"
android:layout_below="@id/reminderLabel"
android:layout_alignParentRight="true"
android:src="@drawable/icon_blank" />
</RelativeLayout>
<!-- Footer -->
<LinearLayout

@ -73,6 +73,8 @@
<string name="rmd_EPr_ringtone_title">Notification Ringtone</string>
<!-- Notification Ringtone Description (when custom tone is set) -->
<string name="rmd_EPr_ringtone_desc_custom">Custom ringtone has been set</string>
<!-- Notification Ringtone Description (when silence is set) -->
<string name="rmd_EPr_ringtone_desc_silent">Ringtone set to silent</string>
<!-- Notification Ringtone Description (when custom tone is not set) -->
<string name="rmd_EPr_ringtone_desc_default">Default ringtone will be used</string>
@ -83,6 +85,33 @@
<!-- Notification Persistence Description (false) -->
<string name="rmd_EPr_persistent_desc_false">Notifications can be cleared with \"Clear All\" button</string>
<!-- Notification Icon Title -->
<string name="rmd_EPr_notificon_title">Notification Icon Set</string>
<!-- Notification Icon Description -->
<string name="rmd_Epr_notificon_desc">Choose Astrid\'s notification bar icon</string>
<!-- Vibrate Title -->
<string name="rmd_EPr_vibrate_title">Vibrate on Alert</string>
<!-- Vibrate Description (true) -->
<string name="rmd_EPr_vibrate_desc_true">Astrid will vibrate when sending notifications</string>
<!-- Vibrate Description (false) -->
<string name="rmd_EPr_vibrate_desc_false">Astrid will not vibrate when sending notifications</string>
<!-- Nagging Title -->
<string name="rmd_EPr_nagging_title">Astrid Reminders</string>
<!-- Nagging Description (true) -->
<string name="rmd_EPr_nagging_desc_true">Astrid will show up to give you an encouragement during reminders</string>
<!-- Nagging Description (false) -->
<string name="rmd_EPr_nagging_desc_false">Astrid not give you any encouragement messages</string>
<!-- Default Reminders Title -->
<string name="rmd_EPr_defaultRemind_title">Random Reminders</string>
<!-- Default Reminders Setting (disabled) -->
<string name="rmd_EPr_defaultRemind_desc_disabled">New tasks will have no random reminders</string>
<!-- Default Reminders Setting (%s => setting) -->
<string name="rmd_EPr_defaultRemind_desc">New tasks will remind randomly: %s</string>
<!-- Defaults Title -->
<string name="rmd_EPr_defaults_header">New Task Defaults</string>

@ -27,6 +27,11 @@
<item name="android:textSize">24sp</item>
<item name="android:gravity">center</item>
</style>
<style name="TextAppearance.TLA_Reminder">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#000000</item>
</style>
<!-- =========================== TaskAdapter =========================== -->

@ -18,11 +18,14 @@
android:title="@string/rmd_EPr_persistent_title"/>
<CheckBoxPreference
android:key="@string/p_rmd_vibrate"
android:title="@string/prefs_vibrate_title"
android:summary="@string/prefs_vibrate_desc" />
android:title="@string/rmd_EPr_vibrate_title"/>
<CheckBoxPreference
android:key="@string/p_rmd_nagging"
android:title="@string/rmd_EPr_nagging_title"
android:defaultValue="true" />
<ListPreference
android:key="@string/p_rmd_default_random_hours"
android:title="@string/prefs_defaultRemind_title"
android:title="@string/rmd_EPr_defaultRemind_title"
android:entries="@array/EPr_reminder_random"
android:entryValues="@array/EPr_reminder_random_hours"/>
<RingtonePreference
@ -31,10 +34,5 @@
android:ringtoneType="notification"
android:showDefault="true"
android:showSilent="true" />
<CheckBoxPreference
android:key="@string/p_rmd_nagging"
android:title="@string/prefs_nagging_title"
android:summary="@string/prefs_nagging_desc"
android:defaultValue="true" />
</PreferenceScreen>

@ -13,6 +13,7 @@ import android.preference.PreferenceManager;
import com.timsu.astrid.R;
@Deprecated
public class Preferences {
// pref keys

@ -103,6 +103,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
/** token for passing a {@link Filter} object through extras */
public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$
/** token for passing a reminder string through extras */
public static final String TOKEN_REMINDER = "reminder"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s title through extras */
public static final String TOKEN_FILTER_TITLE = "title"; //$NON-NLS-1$
@ -299,6 +302,12 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
startActivityForResult(intent, ACTIVITY_EDIT_TASK);
}
});
String reminder = getIntent().getStringExtra(TOKEN_REMINDER);
if(reminder != null) {
findViewById(R.id.reminderContainer).setVisibility(View.VISIBLE);
((TextView)findViewById(R.id.reminderLabel)).setText(reminder);
}
}
/**

Loading…
Cancel
Save