Merge lp:~ssalonen/astrid/default-calendar into lp:~tim-todoroo/astrid/2.x

Proposed by Sami Salonen
Status: Merged
Merge reported by: Tim Su
Merged at revision: not available
Proposed branch: lp:~ssalonen/astrid/default-calendar
Merge into: lp:~tim-todoroo/astrid/2.x
Diff against target: 2167 lines (+932/-672)
9 files modified
AndroidManifest.xml (+25/-26)
res/values/keys.xml (+18/-15)
res/values/strings.xml (+86/-81)
res/xml/preferences.xml (+70/-66)
src/com/timsu/astrid/activities/EditPreferences.java (+5/-0)
src/com/timsu/astrid/activities/TaskEdit.java (+9/-2)
src/com/timsu/astrid/utilities/Calendars.java (+179/-0)
src/com/timsu/astrid/utilities/Preferences.java (+536/-479)
src/com/timsu/astrid/utilities/StartupReceiver.java (+4/-3)
To merge this branch: bzr merge lp:~ssalonen/astrid/default-calendar
Reviewer Review Type Date Requested Status
Tim Su Approve
Review via email: mp+24610@code.launchpad.net

Description of the change

Added setting to change the calendar which is used for saving the events.

To post a comment you must log in.
lp:~ssalonen/astrid/default-calendar updated
275. By salski

Fixed crashes on platforms that does not support calendar API (e.g. emulator).

276. By salski

Added logging

277. By salski

Fixing debugging

Revision history for this message
Tim Su (tim-todoroo) :
Revision history for this message
Tim Su (tim-todoroo) wrote :

Looks good! I will test it on my phone tomorrow and if it works well it'll go into the next release. Thanks!

Revision history for this message
Sami Salonen (ssalonen) wrote :

Great to hear! Looking forward to it.

It might have problems with special calendars like Motorola Droid
Corporate calendar (?) but anyways it shouldn't crash

On Mon, May 24, 2010 at 11:18 AM, Tim Su <email address hidden> wrote:
> Looks good! I will test it on my phone tomorrow and if it works well it'll go into the next release. Thanks!
> --
> https://code.launchpad.net/~ssalonen/astrid/default-calendar/+merge/24610
> You are the owner of lp:~ssalonen/astrid/default-calendar.
>

--

Sami

Revision history for this message
Tim Su (tim-todoroo) wrote :

had to make some minor changes, but it works. we're transitioning to github, so you can see the merge i performed here: http://github.com/todoroo/astrid/commits/master

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AndroidManifest.xml'
2--- AndroidManifest.xml 2010-05-01 19:45:17 +0000
3+++ AndroidManifest.xml 2010-05-03 21:39:37 +0000
4@@ -1,21 +1,20 @@
5 <?xml version="1.0" encoding="utf-8"?>
6 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
7- package="com.timsu.astrid"
8- android:versionCode="130" android:versionName="2.13.4">
9-
10- <!-- ============================ Metadata ============================ -->
11-
12+ android:versionCode="130" android:versionName="2.13.4" package="com.timsu.astrid">
13+
14+ <!-- ============================ Metadata ============================ -->
15+
16 <uses-permission android:name="android.permission.VIBRATE"/>
17 <uses-permission android:name="android.permission.INTERNET"/>
18 <uses-permission android:name="android.permission.WRITE_CALENDAR" />
19 <uses-permission android:name="android.permission.READ_CALENDAR" />
20 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
21 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
22-
23+
24 <!-- For Flurry analytics -->
25 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
26 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
27-
28+
29 <!-- For Tasks provider -->
30 <permission android:name="com.timsu.astrid.permission.READ_TASKS"
31 android:permissionGroup="android.permission-group.MESSAGES"
32@@ -23,15 +22,15 @@
33 android:label="@string/read_tasks_permission"
34 android:description="@string/read_tasks_permission"/>
35 <uses-permission android:name="com.timsu.astrid.permission.READ_TASKS"/>
36-
37+
38 <uses-sdk android:minSdkVersion="3"
39 android:targetSdkVersion="4" />
40 <supports-screens />
41-
42+
43 <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
44-
45+
46 <!-- ======================== Activities ========================= -->
47-
48+
49 <!-- Activity that displays the task list -->
50 <activity android:name=".activities.TaskList">
51 <intent-filter>
52@@ -39,11 +38,11 @@
53 <category android:name="android.intent.category.LAUNCHER" />
54 </intent-filter>
55 </activity>
56-
57+
58 <!-- Activity that redirects to a task list, invoked by notifications -->
59 <activity android:name=".activities.TaskListNotify"
60 android:launchMode="singleTop" />
61-
62+
63 <!-- Activity that creates or edits tasks -->
64 <activity android:name=".activities.TaskEdit"
65 android:icon="@drawable/icon_add"
66@@ -58,7 +57,7 @@
67 <category android:name="android.intent.category.DEFAULT" />
68 <data android:mimeType="vnd.android.cursor.item/task" />
69 </intent-filter>
70-
71+
72 </activity>
73
74 <!-- Activity that views tags -->
75@@ -68,13 +67,13 @@
76 <category android:name="android.intent.category.DEFAULT" />
77 </intent-filter>
78 </activity>
79-
80+
81 <!-- Activity that lets users log in to sync providers -->
82 <activity android:name=".activities.SyncLoginActivity"/>
83
84 <!-- Activity that lets users edit app preferences -->
85 <activity android:name=".activities.EditPreferences"/>
86-
87+
88 <!-- Activity that lets users edit synchronization preferences -->
89 <activity android:name=".activities.SyncPreferences"/>
90
91@@ -90,15 +89,15 @@
92 </activity>
93
94 <!-- ======================== Receivers ========================= -->
95-
96+
97 <receiver android:name=".utilities.Notifications" />
98-
99+
100 <receiver android:name=".utilities.LocaleReceiver">
101 <intent-filter>
102 <action android:name="com.timsu.astrid.action.LOCALE_ALERT" />
103 </intent-filter>
104 </receiver>
105-
106+
107 <receiver android:name=".utilities.StartupReceiver">
108 <intent-filter>
109 <action android:name="android.intent.action.BOOT_COMPLETED" />
110@@ -116,14 +115,14 @@
111
112
113 <!-- ======================== Services ========================== -->
114-
115+
116 <service android:name=".appwidget.AstridAppWidgetProvider$UpdateService"></service>
117-
118+
119 <service android:name=".sync.SynchronizationService" />
120 <service android:name=".utilities.BackupService"/>
121
122 <!-- ======================== Providers ========================== -->
123-
124+
125 <provider
126 android:name=".provider.TasksProvider"
127 android:authorities="com.timsu.astrid.tasksprovider"
128@@ -131,7 +130,7 @@
129 android:grantUriPermissions="true"
130 android:readPermission="com.timsu.astrid.permission.READ_TASKS"
131 />
132-
133- </application>
134-
135-</manifest>
136+
137+ </application>
138+
139+</manifest>
140
141=== modified file 'res/values/keys.xml'
142--- res/values/keys.xml 2010-04-18 01:56:44 +0000
143+++ res/values/keys.xml 2010-05-03 21:39:37 +0000
144@@ -1,23 +1,23 @@
145 <?xml version="1.0" encoding="utf-8"?>
146 <!--
147 ASTRID: Android's Simple Task Recording Dashboard
148-
149+
150 Copyright (c) 2009 Tim Su
151-
152+
153 This program is free software; you can redistribute it and/or modify
154 it under the terms of the GNU General Public License as published by
155 the Free Software Foundation; either version 2 of the License, or
156 (at your option) any later version.
157-
158+
159 This program is distributed in the hope that it will be useful, but
160 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
161 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
162 for more details.
163-
164+
165 You should have received a copy of the GNU General Public License along
166 with this program; if not, write to the Free Software Foundation, Inc.,
167 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
168-
169+
170 -->
171 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
172
173@@ -30,28 +30,31 @@
174
175 <string name="p_notif_quietStart">notif_qstart</string>
176 <string name="p_notif_quietEnd">notif_qend</string>
177-
178+
179 <string name="p_notif_defaultRemind">notif_default_reminder</string>
180-
181+
182 <string name="p_notif_annoy">notif_annoy</string>
183
184 <string name="p_notif_vibrate">notif_vibrate</string>
185-
186+
187 <string name="p_notification_ringtone">notification_ringtone</string>
188-
189+
190 <string name="p_notif_icon">notif_theme</string>
191-
192+
193 <string name="p_colorize">colorize</string>
194-
195+
196 <string name="p_fontSize">font_size</string>
197-
198+
199 <string name="p_nagging">nagging</string>
200-
201+
202 <string name="p_deadlineTime">deadline_time</string>
203
204 <string name="p_backup">backup</string>
205-
206- <string name="prefs_titleVisible">titleVisible</string>
207+
208+ <string name="prefs_defaultCalendar">default_calendar_id</string>
209+ <string name="prefs_defaultCalendar_default">1</string>
210+
211+ <string name="prefs_titleVisible">titleVisible</string>
212 <string name="prefs_titleVisible_default">true</string>
213 <string name="prefs_deadlineVisible">deadlineVisible</string>
214 <string name="prefs_deadlineVisible_default">true</string>
215
216=== modified file 'res/values/strings.xml'
217--- res/values/strings.xml 2010-04-29 06:06:55 +0000
218+++ res/values/strings.xml 2010-05-03 21:39:37 +0000
219@@ -1,46 +1,46 @@
220 <?xml version="1.0" encoding="utf-8"?>
221 <!--
222 ASTRID: Android's Simple Task Recording Dashboard
223-
224+
225 Copyright (c) 2009 Tim Su
226-
227+
228 This program is free software; you can redistribute it and/or modify
229 it under the terms of the GNU General Public License as published by
230 the Free Software Foundation; either version 2 of the License, or
231 (at your option) any later version.
232-
233+
234 This program is distributed in the hope that it will be useful, but
235 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
236 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
237 for more details.
238-
239+
240 You should have received a copy of the GNU General Public License along
241 with this program; if not, write to the Free Software Foundation, Inc.,
242 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
243-
244+
245 -->
246 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
247
248 <!-- application -->
249 <string name="app_name">Astrid</string>
250-
251+
252 <!-- General String Constants -->
253 <skip />
254-
255+
256 <!-- Importance Labels -->
257 <string name="importance_1">!!!!</string>
258 <string name="importance_2">!!!</string>
259 <string name="importance_3">!!</string>
260 <string name="importance_4">!</string>
261-
262+
263 <!-- Repeat Interval Labels -->
264 <string name="repeat_days">Day(s)</string>
265 <string name="repeat_weeks">Week(s)</string>
266 <string name="repeat_months">Month(s)</string>
267 <string name="repeat_hours">Hour(s)</string>
268-
269+
270 <!-- Plurals -->
271-
272+
273 <plurals name="Ntasks">
274 <!-- plurals: tasks -->
275 <item quantity="one">1 Task</item>
276@@ -62,17 +62,17 @@
277 <item quantity="one">1 Tag</item>
278 <item quantity="other">%d Tags</item>
279 </plurals>
280-
281+
282 <!-- Time Constants -->
283-
284+
285 <!-- used for long due dates. c.f. Java's SimpleDateFormat -->
286- <string name="dateFormatter">MMM d</string>
287+ <string name="dateFormatter">MMM d</string>
288 <!-- used for alarms -->
289 <string name="alarmDateFormatter">M/dd HH:mm</string>
290 <!-- vertical labels are used in dialog boxes -->
291- <string name="daysVertical">D\na\ny\ns</string>
292+ <string name="daysVertical">D\na\ny\ns</string>
293 <string name="hoursVertical">H\no\nu\nr\ns</string>
294-
295+
296 <plurals name="Ndays">
297 <!-- plurals: days -->
298 <item quantity="one">1 Day</item>
299@@ -113,10 +113,10 @@
300 <item quantity="one">1 Sec</item>
301 <item quantity="other">%d Sec</item>
302 </plurals>
303-
304+
305 <!-- indicates time in past. %s is replaced by time unit i.e. 1 minute -->
306 <string name="ago_string">%s Ago</string>
307-
308+
309 <!-- TaskList -->
310 <skip />
311 <!-- title bar -->
312@@ -126,9 +126,9 @@
313 <string name="taskList_hiddenSuffix"> hidden</string>
314 <string name="addtask_label">New Task</string>
315 <string name="missing_tag">Could Not Find Requested Tag!</string>
316-
317+
318 <!-- text displayed in task list item -->
319-
320+
321 <!-- prefix to show that a task is hidden -->
322 <string name="taskList_hiddenPrefix">H</string>
323 <!-- i.e. Due in 4 days -->
324@@ -146,7 +146,7 @@
325 <string name="taskList_elapsedTimePrefix">Spent:</string>
326 <!-- time interval to set frequency to remind user -->
327 <string name="taskList_periodicReminderPrefix">Poke Every</string>
328-
329+
330 <!-- time interval to set repeated tasks-->
331 <string name="taskList_repeatPrefix">Repeats Every</string>
332 <!-- displayed when repeat is on remote server-->
333@@ -154,15 +154,15 @@
334 <string name="taskList_alarmPrefix">Next Alarm:</string>
335 <string name="taskList_tagsPrefix">Tags:</string>
336 <string name="taskList_notesPrefix">Notes:</string>
337-
338+
339 <!-- i.e. Created: <create date> -->
340 <string name="taskList_createdPrefix">Created:</string>
341-
342+
343 <!-- i.e. Deleted: <delete date> -->
344 <string name="taskList_deleted">Deleted</string>
345-
346+
347 <string name="quick_add_hint">Add New Task</string>
348-
349+
350 <!-- menu items -->
351 <string name="taskList_menu_insert">New Task</string>
352 <string name="taskList_menu_tags">Tags</string>
353@@ -183,7 +183,7 @@
354 <string name="taskList_context_startTimer">Start Timer</string>
355 <string name="taskList_context_stopTimer">Stop Timer</string>
356 <string name="taskList_context_postpone">Postpone</string>
357-
358+
359 <!-- filter menu items -->
360 <string name="taskList_filter_title">Sort/Filters</string>
361 <string name="taskList_filter_hidden">Hidden/Blocked Tasks</string>
362@@ -193,7 +193,7 @@
363 <string name="taskList_sort_alpha">Sort By Name</string>
364 <string name="taskList_sort_duedate">Sort By Due Date</string>
365 <string name="taskList_sort_reverse">Sort Reverse</string>
366-
367+
368 <string name="taskList_nonag_reminder">Select an Action:</string>
369 <string name="taskList_postpone_count">Times You\'ve Postponed: %d</string>
370 <string name="taskList_postpone_dialog">Postpone for how long?</string>
371@@ -205,19 +205,19 @@
372 <string name="taskEdit_titleGeneric">Astrid: Editing Task</string>
373 <string name="taskEdit_titlePrefix">Astrid: Editing </string>
374 <string name="taskEdit_label">Astrid: New Task</string>
375-
376+
377 <!-- tabs -->
378 <string name="taskEdit_tab_basic">Basic</string>
379 <string name="taskEdit_tab_dates">Dates</string>
380 <string name="taskEdit_tab_alerts">Alerts</string>
381-
382+
383 <!-- labels -->
384 <string name="name_label">Summary</string>
385 <string name="name_hint">Task Name</string>
386 <string name="importance_label">How Important is it?</string>
387 <string name="tags_label">Tags:</string>
388 <string name="tag_hint">Tag Name</string>
389-
390+
391 <string name="estimatedDuration_label">How Long Will it Take?</string>
392 <string name="elapsedDuration_label">Time Already Spent on Task</string>
393 <string name="definiteDueDate_label">Absolute Deadline</string>
394@@ -230,7 +230,7 @@
395 <string name="blockingOn_label">Hide Until This Task is Done</string>
396 <string name="notes_label">Notes</string>
397 <string name="notes_hint">Enter Task Notes</string>
398-
399+
400 <string name="notification_label">Periodic Reminders</string>
401 <string name="notification_prefix">Every</string>
402 <string name="flags_label">Notify me...</string>
403@@ -240,7 +240,7 @@
404 <string name="flag_nonstop">Alarm Clock Mode</string>
405 <string name="alerts_label">Fixed Reminders</string>
406 <string name="add_alert">Add New Reminder</string>
407-
408+
409 <!-- dialog boxes -->
410 <string name="hour_minutes_dialog">Time (hours : minutes)</string>
411 <string name="notification_dialog">Remind Me Every</string>
412@@ -253,7 +253,7 @@
413 \n
414 </string>
415 <string name="repeat_help_hide">Don't Show Help Anymore</string>
416-
417+
418 <!-- buttons -->
419 <string name="save_label">Save</string>
420 <string name="discard_label">Discard</string>
421@@ -262,17 +262,17 @@
422 <string name="blank_button_title">Click to Set</string>
423 <string name="startTimer_label">Start Timer</string>
424 <string name="stopTimer_label">Stop Timer</string>
425-
426+
427 <string name="taskEdit_menu_save">Save</string>
428 <string name="taskEdit_onTaskSave_Due">Task Saved: due in %s</string>
429 <string name="taskEdit_onTaskSave_Overdue">Task Saved: due %s ago</string>
430 <string name="taskEdit_onTaskSave_notDue">Task Saved</string>
431-
432+
433 <!-- TaskView -->
434 <skip />
435-
436+
437 <string name="taskView_notifyTitle">Astrid says...</string>
438-
439+
440 <!-- Tag List -->
441 <skip />
442 <string name="tagList_titlePrefix">Astrid: Tag View: </string>
443@@ -285,12 +285,12 @@
444 <string name="tagList_shortcut_created">Shortcut created on your home screen!</string>
445 <string name="tagList_shortcut_prefix">Tag:</string>
446 <string name="tagList_untagged">[untagged]</string>
447-
448+
449 <string name="tagList_menu_sortAlpha">Sort A-Z</string>
450 <string name="tagList_menu_sortSize">Sort by Size</string>
451-
452-
453- <!-- Synchronization -->
454+
455+
456+ <!-- Synchronization -->
457 <skip />
458 <string name="sync_pref_group">Synchronization Services</string>
459 <string name="sync_pref_group_actions">Actions</string>
460@@ -308,7 +308,7 @@
461 <string name="sync_bgwifi_desc">If set, auto-sync only happens when Wifi is active</string>
462 <string name="sync_error">Sync Error! Sorry for the inconvenience! Error:</string>
463 <string name="sync_upgrade_v99">
464-Astrid 2.7 now performs synchronization with RTM in the background. You will
465+Astrid 2.7 now performs synchronization with RTM in the background. You will
466 be directed to the preferences page to configure how often you want this to
467 occur (it is a minor drain on battery).
468 </string>
469@@ -327,23 +327,23 @@
470 <string name="sync_result_updated">Updated: %d</string>
471 <string name="sync_result_deleted">Deleted: %d</string>
472 <string name="sync_result_merged">Merged: %d</string>
473-
474+
475 <string name="sync_progress_remote">Reading Remote Data</string>
476 <string name="sync_progress_rxlist">Reading List: %s</string>
477 <string name="sync_progress_repeating">Synchronizing Repeating Task</string>
478 <string name="sync_progress_localtx">Transmitting: %s</string>
479 <string name="sync_progress_localdel">Locally Deleted Tasks</string>
480 <string name="sync_progress_remotetx">Receiving: %s</string>
481-
482+
483 <string name="rtm_login_label">Please Log In to RTM...</string>
484 <string name="rtm_login_error">
485 Sorry, there was an error verifying your login. Please try again.
486 \n\n
487-Error Message:
488+Error Message:
489 </string>
490-
491-
492- <!-- Dialog Boxes -->
493+
494+
495+ <!-- Dialog Boxes -->
496 <skip />
497 <string name="loading">Loading...</string>
498 <string name="updating">Updating List...</string>
499@@ -355,13 +355,13 @@
500 <string name="notify_snooze">Snooze...</string>
501 <string name="notify_no">Go Away!</string>
502 <string name="notify_snooze_title">Hours/minutes to snooze?</string>
503-
504- <string name="delete_title">Delete</string>
505+
506+ <string name="delete_title">Delete</string>
507 <string name="delete_this_task_title">Delete this task?</string>
508 <string name="delete_this_tag_title">Remove this tag from all tasks?</string>
509-
510+
511 <string name="stop_timer_title">Stop the timer?</string>
512-
513+
514 <string name="quick_tips">
515 Some things you may not know about Astrid:\n
516 \n
517@@ -372,10 +372,10 @@
518 \n
519 Thanks for using Astrid!\n
520 </string>
521-
522+
523 <!-- %s => name of the application -->
524 <string name="task_killer_help">
525-It looks like you are using an app that can kill processes (%s)! If you can,
526+It looks like you are using an app that can kill processes (%s)! If you can,
527 add Astrid to the exclusion list so it doesn\'t get killed. Otherwise,
528 Astrid might not let you know when your tasks are due.\n
529 </string>
530@@ -400,64 +400,64 @@
531 <string name="import_file_prompt">Select a File to Restore</string>
532 <!-- Locale Plugin -->
533 <skip />
534-
535+
536 <string name="locale_edit_alerts_title">Astrid Tag Alert</string>
537- <string name="locale_edit_intro">Astrid will send you a reminder
538+ <string name="locale_edit_intro">Astrid will send you a reminder
539 when you have uncompleted tasks with the following criteria:</string>
540 <string name="locale_pick_tag">Tagged with:</string>
541-
542- <!-- Notification -->
543+
544+ <!-- Notification -->
545 <skip />
546-
547+
548 <string name="notif_definiteDueDate">Absolute Deadline!</string>
549 <string name="notif_preferredDueDate">Goal Deadline!</string>
550 <string name="notif_timerStarted">Working on:</string>
551 <!-- $NUM is replaced with # of tasks + units, i.e. "1 task", $TAG is replaced with tag name -->
552 <string name="notif_tagNotification">You have $NUM tagged $TAG!</string>
553-
554- <!-- Error Messages -->
555+
556+ <!-- Error Messages -->
557 <skip />
558-
559+
560 <string name="error_opening">Could not find this item: </string>
561 <string name="error_saving">Could not save:s</string>
562 <string name="error_sdcard">Cannot access folder: %s</string>
563 <string name="error_sdcard_general">Cannot access your SD card!</string>
564-
565+
566 <skip />
567
568 <string name="prefs_category_alerts">Notifications</string>
569-
570+
571 <string name="prefs_quietStart_title">Quiet Hours Start</string>
572 <string name="prefs_quietStart_desc">Start time to silence notifications for periodic reminders</string>
573-
574+
575 <string name="prefs_quietEnd_title">Quiet Hours End</string>
576 <string name="prefs_quietEnd_desc">End time to silence notifications</string>
577-
578+
579 <string name="prefs_defaultRemind_title">Default Reminders</string>
580 <string name="prefs_defaultRemind_desc">For new tasks, default reminder in days (i.e. 7). Blank to disable</string>
581-
582+
583 <string name="prefs_annoy_title">Persistent Mode</string>
584 <string name="prefs_annoy_desc">If checked, LED and notifications must be cleared one at a time</string>
585-
586+
587 <string name="prefs_notification_title">Notification Ringtone</string>
588 <string name="prefs_notification_desc">Choose a ringtone for Astrid\'s alerts</string>
589
590 <string name="prefs_notificon_title">Notification Icons</string>
591 <string name="prefs_notificon_desc">Choose Astrid\'s notification bar icon</string>
592-
593+
594 <string name="prefs_vibrate_title">Vibrate on Alert</string>
595 <string name="prefs_vibrate_desc">If checked, Astrid will vibrate when sounding an alarm</string>
596-
597+
598 <string name="prefs_category_appearance">Appearance</string>
599-
600+
601 <string name="prefs_colorize_title">Colorize Task List</string>
602 <string name="prefs_colorize_desc">Different colors for different priorities</string>
603-
604+
605 <string name="prefs_fontSize_title">Task List Size</string>
606 <string name="prefs_fontSize_desc">Font size on the main listing page</string>
607
608 <string name="prefs_category_other">Other</string>
609-
610+
611 <string name="prefs_nagging_title">Nag Messages</string>
612 <string name="prefs_nagging_desc">Show Astrid\'s comments when viewing reminders and postponing tasks?</string>
613
614@@ -465,22 +465,27 @@
615 <string name="prefs_deadlineTime_desc"># of days from now to set new deadlines</string>
616
617 <string name="prefs_backup_title">Automatic Backups</string>
618-
619+
620 <!-- backup summary when there is no backup message -->
621 <string name="prefs_backup_desc">Perform daily backups to sdcard.</string>
622-
623+
624 <!-- backup failure message (%s -> error message) -->
625 <string name="prefs_backup_desc_failure">Last backup failed: %s</string>
626-
627+
628 <!-- backup failure error when error message is null -->
629 <string name="prefs_backup_desc_failure_null">Last backup failed, could not read SD card</string>
630-
631+
632 <!-- backup success message (%s -> date) -->
633 <string name="prefs_backup_desc_success">Latest backup was on %s</string>
634-
635+
636+ <string name="prefs_defaultCalendar_title">Calendar</string>
637+ <string name="prefs_defaultCalendar_desc">Calendar to store the events.</string>
638+ <string name="prefs_defaultCalendar_astrid_default">Astrid default</string>
639+
640+
641 <string name="displayedFields_PrefScreen_Title">Displayed Fields</string>
642 <string name="displayedFields_PrefScreen_Desc">Select the fields to show in task list</string>
643-
644+
645 <string name="prefs_titleVisible_title">Task Title</string>
646 <string name="prefs_titleVisible_desc">Task description</string>
647 <string name="prefs_deadlineVisible_title">Dates</string>
648@@ -504,14 +509,14 @@
649 <string name="marketplace_description">
650 Astrid is the highly-acclaimed open-source task list that is simple enough to not get in your way, powerful enough to help you get stuff done! Tags, reminders, RememberTheMilk sync, Locale plug-in &amp; more!
651 </string>
652-
653+
654 <!-- Automatically filled in by Launchpad: -->
655 <string name="about_translators">translator-credits</string>
656
657 <!-- Widget text when loading tasks -->
658 <string name="widget_loading">Loading...</string>
659-
660+
661 <!-- Permissions -->
662 <string name="read_tasks_permission">Read Astrid tasks</string>
663-
664+
665 </resources>
666
667=== modified file 'res/xml/preferences.xml'
668--- res/xml/preferences.xml 2010-04-20 19:12:26 +0000
669+++ res/xml/preferences.xml 2010-05-03 21:39:37 +0000
670@@ -1,117 +1,121 @@
671 <?xml version="1.0" encoding="utf-8"?>
672-<PreferenceScreen
673- xmlns:android="http://schemas.android.com/apk/res/android">
674-
675+<PreferenceScreen
676+ xmlns:android="http://schemas.android.com/apk/res/android">
677+
678 <PreferenceCategory
679 android:title="@string/prefs_category_alerts">
680- <ListPreference
681- android:key="@string/p_notif_quietStart"
682- android:entries="@array/EPr_quiet_hours_start"
683- android:entryValues="@array/EPr_quiet_hours_start_values"
684- android:title="@string/prefs_quietStart_title"
685- android:summary="@string/prefs_quietStart_desc" />
686- <ListPreference
687- android:key="@string/p_notif_quietEnd"
688- android:entries="@array/EPr_quiet_hours_end"
689- android:entryValues="@array/EPr_quiet_hours_end_values"
690- android:title="@string/prefs_quietEnd_title"
691- android:summary="@string/prefs_quietEnd_desc" />
692- <CheckBoxPreference
693- android:key="@string/p_notif_annoy"
694- android:title="@string/prefs_annoy_title"
695- android:summary="@string/prefs_annoy_desc" />
696- <CheckBoxPreference
697- android:key="@string/p_notif_vibrate"
698- android:title="@string/prefs_vibrate_title"
699- android:summary="@string/prefs_vibrate_desc" />
700- <EditTextPreference
701- android:key="@string/p_notif_defaultRemind"
702- android:title="@string/prefs_defaultRemind_title"
703- android:summary="@string/prefs_defaultRemind_desc" />
704- <RingtonePreference
705- android:key="@string/p_notification_ringtone"
706- android:title="@string/prefs_notification_title"
707+ <ListPreference
708+ android:key="@string/p_notif_quietStart"
709+ android:entries="@array/EPr_quiet_hours_start"
710+ android:entryValues="@array/EPr_quiet_hours_start_values"
711+ android:title="@string/prefs_quietStart_title"
712+ android:summary="@string/prefs_quietStart_desc" />
713+ <ListPreference
714+ android:key="@string/p_notif_quietEnd"
715+ android:entries="@array/EPr_quiet_hours_end"
716+ android:entryValues="@array/EPr_quiet_hours_end_values"
717+ android:title="@string/prefs_quietEnd_title"
718+ android:summary="@string/prefs_quietEnd_desc" />
719+ <CheckBoxPreference
720+ android:key="@string/p_notif_annoy"
721+ android:title="@string/prefs_annoy_title"
722+ android:summary="@string/prefs_annoy_desc" />
723+ <CheckBoxPreference
724+ android:key="@string/p_notif_vibrate"
725+ android:title="@string/prefs_vibrate_title"
726+ android:summary="@string/prefs_vibrate_desc" />
727+ <EditTextPreference
728+ android:key="@string/p_notif_defaultRemind"
729+ android:title="@string/prefs_defaultRemind_title"
730+ android:summary="@string/prefs_defaultRemind_desc" />
731+ <RingtonePreference
732+ android:key="@string/p_notification_ringtone"
733+ android:title="@string/prefs_notification_title"
734 android:summary="@string/prefs_notification_desc"
735- android:ringtoneType="notification"
736+ android:ringtoneType="notification"
737 android:showDefault="true"
738 android:showSilent="true" />
739- <ListPreference
740- android:key="@string/p_notif_icon"
741- android:entries="@array/notif_icon_entries"
742- android:entryValues="@array/notif_icon_values"
743- android:title="@string/prefs_notificon_title"
744- android:summary="@string/prefs_notificon_desc" />
745-
746+ <ListPreference
747+ android:key="@string/p_notif_icon"
748+ android:entries="@array/notif_icon_entries"
749+ android:entryValues="@array/notif_icon_values"
750+ android:title="@string/prefs_notificon_title"
751+ android:summary="@string/prefs_notificon_desc" />
752+
753 </PreferenceCategory>
754-
755+
756 <PreferenceCategory
757 android:title="@string/prefs_category_appearance">
758- <CheckBoxPreference
759- android:key="@string/p_colorize"
760- android:title="@string/prefs_colorize_title"
761- android:summary="@string/prefs_colorize_desc" />
762- <ListPreference
763+ <CheckBoxPreference
764+ android:key="@string/p_colorize"
765+ android:title="@string/prefs_colorize_title"
766+ android:summary="@string/prefs_colorize_desc" />
767+ <ListPreference
768 android:key="@string/p_fontSize"
769- android:entries="@array/EPr_font_size"
770- android:entryValues="@array/EPr_font_size"
771- android:title="@string/prefs_fontSize_title"
772+ android:entries="@array/EPr_font_size"
773+ android:entryValues="@array/EPr_font_size"
774+ android:title="@string/prefs_fontSize_title"
775 android:summary="@string/prefs_fontSize_desc" />
776 <PreferenceScreen
777 android:title="@string/displayedFields_PrefScreen_Title"
778 android:summary="@string/displayedFields_PrefScreen_Desc">
779- <CheckBoxPreference
780+ <CheckBoxPreference
781 android:key="@string/prefs_deadlineVisible"
782 android:title="@string/prefs_deadlineVisible_title"
783 android:summary="@string/prefs_deadlineVisible_desc"
784- android:defaultValue="@string/prefs_deadlineVisible_default" />
785- <CheckBoxPreference
786+ android:defaultValue="@string/prefs_deadlineVisible_default" />
787+ <CheckBoxPreference
788 android:key="@string/prefs_tagsVisible"
789 android:title="@string/prefs_tagsVisible_title"
790 android:summary="@string/prefs_tagsVisible_desc"
791 android:defaultValue="@string/prefs_tagsVisible_default" />
792- <CheckBoxPreference
793+ <CheckBoxPreference
794 android:key="@string/prefs_importanceVisible"
795 android:title="@string/prefs_importanceVisible_title"
796 android:summary="@string/prefs_importanceVisible_desc"
797- android:defaultValue="@string/prefs_importanceVisible_default" />
798- <CheckBoxPreference
799+ android:defaultValue="@string/prefs_importanceVisible_default" />
800+ <CheckBoxPreference
801 android:key="@string/prefs_timeVisible"
802 android:title="@string/prefs_timeVisible_title"
803 android:summary="@string/prefs_timeVisible_desc"
804- android:defaultValue="@string/prefs_timeVisible_default" />
805- <CheckBoxPreference
806+ android:defaultValue="@string/prefs_timeVisible_default" />
807+ <CheckBoxPreference
808 android:key="@string/prefs_reminderVisible"
809 android:title="@string/prefs_reminderVisible_title"
810 android:summary="@string/prefs_reminderVisible_desc"
811- android:defaultValue="@string/prefs_reminderVisible_default" />
812- <CheckBoxPreference
813+ android:defaultValue="@string/prefs_reminderVisible_default" />
814+ <CheckBoxPreference
815 android:key="@string/prefs_repeatVisible"
816 android:title="@string/prefs_repeatVisible_title"
817 android:summary="@string/prefs_repeatVisible_desc"
818- android:defaultValue="@string/prefs_repeatVisible_default" />
819- <CheckBoxPreference
820+ android:defaultValue="@string/prefs_repeatVisible_default" />
821+ <CheckBoxPreference
822 android:key="@string/prefs_notesVisible"
823 android:title="@string/prefs_notesVisible_title"
824 android:summary="@string/prefs_notesVisible_desc"
825 android:defaultValue="@string/prefs_notesVisible_default" />
826 </PreferenceScreen>
827 </PreferenceCategory>
828-
829+
830 <PreferenceCategory
831- android:title="@string/prefs_category_other">
832- <CheckBoxPreference
833+ android:title="@string/prefs_category_other">
834+ <CheckBoxPreference
835 android:key="@string/p_nagging"
836 android:title="@string/prefs_nagging_title"
837 android:summary="@string/prefs_nagging_desc"
838 android:defaultValue="true" />
839- <EditTextPreference
840- android:key="@string/p_deadlineTime"
841- android:title="@string/prefs_deadlineTime_title"
842+ <EditTextPreference
843+ android:key="@string/p_deadlineTime"
844+ android:title="@string/prefs_deadlineTime_title"
845 android:summary="@string/prefs_deadlineTime_desc" />
846 <CheckBoxPreference
847 android:key="@string/p_backup"
848 android:title="@string/prefs_backup_title"
849 android:summary="@string/prefs_backup_desc"
850 android:defaultValue="true" />
851+ <ListPreference
852+ android:key="@string/prefs_defaultCalendar"
853+ android:title="@string/prefs_defaultCalendar_title"
854+ android:summary="@string/prefs_defaultCalendar_desc" />
855 </PreferenceCategory>
856-</PreferenceScreen>
857\ No newline at end of file
858+</PreferenceScreen>
859\ No newline at end of file
860
861=== modified file 'src/com/timsu/astrid/activities/EditPreferences.java'
862--- src/com/timsu/astrid/activities/EditPreferences.java 2010-04-29 04:33:47 +0000
863+++ src/com/timsu/astrid/activities/EditPreferences.java 2010-05-03 21:39:37 +0000
864@@ -20,11 +20,13 @@
865 package com.timsu.astrid.activities;
866
867 import android.os.Bundle;
868+import android.preference.ListPreference;
869 import android.preference.Preference;
870 import android.preference.PreferenceActivity;
871
872 import com.flurry.android.FlurryAgent;
873 import com.timsu.astrid.R;
874+import com.timsu.astrid.utilities.Calendars;
875 import com.timsu.astrid.utilities.Constants;
876 import com.timsu.astrid.utilities.Preferences;
877
878@@ -45,6 +47,9 @@
879 String backupSummary = Preferences.getBackupSummary(this);
880 if(backupSummary != null && backupPreference != null)
881 backupPreference.setSummary(backupSummary);
882+
883+ ListPreference defaultCalendarPreference = (ListPreference) findPreference(getString(R.string.prefs_defaultCalendar));
884+ Calendars.initCalendarsPreference(this, defaultCalendarPreference);
885 }
886
887 @Override
888
889=== modified file 'src/com/timsu/astrid/activities/TaskEdit.java'
890--- src/com/timsu/astrid/activities/TaskEdit.java 2010-01-22 07:29:12 +0000
891+++ src/com/timsu/astrid/activities/TaskEdit.java 2010-05-03 21:39:37 +0000
892@@ -766,12 +766,13 @@
893 protected void onPause() {
894 // create calendar event
895 if(addToCalendar.isChecked() && model.getCalendarUri() == null) {
896+
897 Uri uri = Uri.parse("content://calendar/events");
898 ContentResolver cr = getContentResolver();
899
900 ContentValues values = new ContentValues();
901 values.put("title", name.getText().toString());
902- values.put("calendar_id", 1);
903+ values.put("calendar_id", Preferences.getDefaultCalendarIDSafe(this));
904 values.put("description", notes.getText().toString());
905 values.put("hasAlarm", 0);
906 values.put("transparency", 0);
907@@ -781,7 +782,13 @@
908 model.getDefiniteDueDate(), model.getEstimatedSeconds(),
909 values);
910
911- Uri result = cr.insert(uri, values);
912+ Uri result = null;
913+ try{
914+ result = cr.insert(uri, values);
915+ } catch(IllegalArgumentException e) {
916+ Log.e("astrid", "Error creating calendar event!", e);
917+ }
918+
919 if(result != null)
920 model.setCalendarUri(result.toString());
921 else
922
923=== added file 'src/com/timsu/astrid/utilities/Calendars.java'
924--- src/com/timsu/astrid/utilities/Calendars.java 1970-01-01 00:00:00 +0000
925+++ src/com/timsu/astrid/utilities/Calendars.java 2010-05-03 21:39:37 +0000
926@@ -0,0 +1,179 @@
927+package com.timsu.astrid.utilities;
928+
929+import android.content.ContentResolver;
930+import android.content.Context;
931+import android.content.SharedPreferences;
932+import android.content.SharedPreferences.Editor;
933+import android.content.res.Resources;
934+import android.database.Cursor;
935+import android.net.Uri;
936+import android.preference.ListPreference;
937+import android.preference.PreferenceManager;
938+import android.util.Log;
939+
940+import com.timsu.astrid.R;
941+
942+public class Calendars {
943+
944+ // Private SDK
945+ private static final Uri CALENDAR_CONTENT_URI = Uri
946+ .parse("content://calendar/calendars"); // Calendars.CONTENT_URI
947+
948+ private static final String ID_COLUMN_NAME = "_id";
949+ private static final String DISPLAY_COLUMN_NAME = "displayName";
950+ private static final String ACCES_LEVEL_COLUMN_NAME = "access_level";
951+
952+ private static final String[] CALENDARS_PROJECTION = new String[] {
953+ ID_COLUMN_NAME, // Calendars._ID,
954+ DISPLAY_COLUMN_NAME // Calendars.DISPLAY_NAME
955+ };
956+
957+ // Only show calendars that the user can modify. Access level 500
958+ // corresponds to Calendars.CONTRIBUTOR_ACCESS
959+ private static final String CALENDARS_WHERE = ACCES_LEVEL_COLUMN_NAME + " >= 500";
960+
961+ private static final String CALENDARS_WHERE_ID = ACCES_LEVEL_COLUMN_NAME+" >= 500 AND" + ID_COLUMN_NAME +"=?";
962+
963+ private static final String CALENDARS_SORT = "displayName ASC";
964+
965+ /**
966+ * Ensures that the default calendar preference is pointing to
967+ * user-modifiable calendar that exists. If the calendar does not exist
968+ * anymore, the preference is reset to default value.
969+ *
970+ * @param context
971+ * Context
972+ */
973+ public static void ensureValidDefaultCalendarPreference(Context context) {
974+ SharedPreferences prefs = PreferenceManager
975+ .getDefaultSharedPreferences(context);
976+ Resources r = context.getResources();
977+ Editor editor = prefs.edit();
978+ // We default the 'defaultCalendar' setting when it is undefined
979+ // or when the calendar does not exist anymore
980+ if (!prefs.contains(r.getString(R.string.prefs_defaultCalendar))
981+ || !Calendars.isCalendarPresent(context, prefs.getString(r
982+ .getString(R.string.prefs_defaultCalendar), null))) {
983+ editor.putString(r.getString(R.string.prefs_defaultCalendar), r
984+ .getString(R.string.prefs_defaultCalendar_default));
985+ editor.commit();
986+ }
987+ }
988+
989+ /**
990+ * Appends all user-modifiable calendars to listPreference. Always includes
991+ * entry called "Astrid default" with calendar id of
992+ * prefs_defaultCalendar_default.
993+ *
994+ * @param context
995+ * context
996+ * @param listPreference
997+ * preference to init
998+ */
999+ public static void initCalendarsPreference(Context context,
1000+ ListPreference listPreference) {
1001+
1002+ ContentResolver cr = context.getContentResolver();
1003+ Resources r = context.getResources();
1004+ Cursor c = cr.query(CALENDAR_CONTENT_URI, CALENDARS_PROJECTION,
1005+ CALENDARS_WHERE, null, CALENDARS_SORT);
1006+
1007+ // Fetch the current setting. Invalid calendar id will
1008+ // be changed to default value.
1009+ String currentSetting = String.valueOf(Preferences
1010+ .getDefaultCalendarIDSafe(context));
1011+
1012+ int currentSettingIndex = -1;
1013+
1014+ if (c == null) {
1015+ // Something went wrong when querying calendars
1016+ // Let's keep the "Astrid default" only.
1017+ listPreference
1018+ .setEntries(new String[] { r
1019+ .getString(R.string.prefs_defaultCalendar_astrid_default) });
1020+ listPreference.setEntryValues(new String[] { r
1021+ .getString(R.string.prefs_defaultCalendar_default) });
1022+ listPreference.setValueIndex(0);
1023+ listPreference.setEnabled(true);
1024+ return;
1025+ }
1026+
1027+ int calendarCount = c.getCount();
1028+
1029+ String[] entries = new String[calendarCount];
1030+ String[] entryValues = new String[calendarCount];
1031+
1032+
1033+ // Iterate calendars one by one, and fill up the list preference
1034+ try {
1035+ int row = 0;
1036+ int idColumn = c.getColumnIndex(ID_COLUMN_NAME);
1037+ int nameColumn = c.getColumnIndex(DISPLAY_COLUMN_NAME);
1038+ while (c.moveToNext()) {
1039+ String id = c.getString(idColumn);
1040+ String name = c.getString(nameColumn);
1041+ entries[row] = name;
1042+ entryValues[row] = id;
1043+
1044+ // We found currently selected calendar
1045+ if (currentSetting.equals(id)) {
1046+ currentSettingIndex = row;
1047+ }
1048+
1049+ row++;
1050+ }
1051+
1052+ if (currentSettingIndex == -1) {
1053+ // Should not happen!
1054+ // Let's keep the "Astrid default" only.
1055+ Log.d("astrid", "initCalendarsPreference: Unknown calendar.");
1056+ listPreference
1057+ .setEntries(new String[] { r
1058+ .getString(R.string.prefs_defaultCalendar_astrid_default) });
1059+ listPreference.setEntryValues(new String[] { r
1060+ .getString(R.string.prefs_defaultCalendar_default) });
1061+ listPreference.setValueIndex(0);
1062+ listPreference.setEnabled(true);
1063+ }
1064+
1065+ listPreference.setEntries(entries);
1066+ listPreference.setEntryValues(entryValues);
1067+
1068+ listPreference.setValueIndex(currentSettingIndex);
1069+ listPreference.setEnabled(true);
1070+
1071+ } finally {
1072+ c.deactivate();
1073+ }
1074+ }
1075+
1076+ /**
1077+ * Checks whether user-modifiable calendar is present with a given id.
1078+ *
1079+ * @param context
1080+ * Context
1081+ * @param id
1082+ * Calendar ID to search for
1083+ * @return true, if user-modifiable calendar with the given id exists; false
1084+ * otherwise.
1085+ */
1086+ private static boolean isCalendarPresent(Context context, String id) {
1087+ if (id == null)
1088+ return false;
1089+
1090+ ContentResolver cr = context.getContentResolver();
1091+ Cursor c = null;
1092+
1093+ try {
1094+ c = cr.query(CALENDAR_CONTENT_URI, CALENDARS_PROJECTION,
1095+ CALENDARS_WHERE_ID, new String[] { id }, CALENDARS_SORT);
1096+ } finally {
1097+ if (c != null) {
1098+ c.deactivate();
1099+ }
1100+ }
1101+
1102+ return (c != null) && (c.getCount() != 0);
1103+ }
1104+
1105+}
1106\ No newline at end of file
1107
1108=== modified file 'src/com/timsu/astrid/utilities/Preferences.java'
1109--- src/com/timsu/astrid/utilities/Preferences.java 2010-04-29 04:33:47 +0000
1110+++ src/com/timsu/astrid/utilities/Preferences.java 2010-05-03 21:39:37 +0000
1111@@ -14,487 +14,544 @@
1112
1113 public class Preferences {
1114
1115- // pref keys
1116- private static final String P_CURRENT_VERSION = "cv";
1117- private static final String P_SHOW_REPEAT_HELP = "repeathelp";
1118- private static final String P_TASK_LIST_SORT = "tlsort";
1119- private static final String P_SYNC_RTM_TOKEN = "rtmtoken";
1120- private static final String P_SYNC_RTM_LAST_SYNC = "rtmlastsync";
1121- private static final String P_SYNC_LAST_SYNC = "lastsync";
1122- private static final String P_SYNC_LAST_SYNC_ATTEMPT = "lastsyncattempt";
1123- private static final String P_LOCALE_LAST_NOTIFY = "locnot";
1124- private static final String P_DID_ANDROID_AND_ME_SURVEY = "aamsurvey";
1125- private static final String P_TASK_KILLER_HELP = "taskkiller";
1126- private static final String P_BACKUP_ERROR = "backupError";
1127-
1128- // pref values
1129- public static final int ICON_SET_PINK = 0;
1130- public static final int ICON_SET_BORING = 1;
1131- public static final int ICON_SET_ASTRID = 2;
1132-
1133- // default values
1134- private static final boolean DEFAULT_PERSISTENCE_MODE = true;
1135- private static final boolean DEFAULT_COLORIZE = false;
1136-
1137- /** Set preference defaults, if unset. called at startup */
1138- public static void setPreferenceDefaults(Context context) {
1139- SharedPreferences prefs = getPrefs(context);
1140- Resources r = context.getResources();
1141- Editor editor = prefs.edit();
1142-
1143- if(!prefs.contains(r.getString(R.string.p_notif_annoy))) {
1144- editor.putBoolean(r.getString(R.string.p_notif_annoy),
1145- DEFAULT_PERSISTENCE_MODE);
1146- }
1147- if(!prefs.contains(r.getString(R.string.p_fontSize))) {
1148- editor.putString(r.getString(R.string.p_fontSize), "20");
1149- }
1150- if(!prefs.contains(r.getString(R.string.p_deadlineTime))) {
1151- editor.putString(r.getString(R.string.p_deadlineTime), "1");
1152- }
1153- if(!prefs.contains(r.getString(R.string.p_notif_defaultRemind))) {
1154- editor.putString(r.getString(R.string.p_notif_defaultRemind), "0");
1155- }
1156- if(!prefs.contains(r.getString(R.string.p_colorize))) {
1157- editor.putBoolean(r.getString(R.string.p_colorize), DEFAULT_COLORIZE);
1158- }
1159- if(!prefs.contains(r.getString(R.string.p_notif_vibrate))) {
1160- editor.putBoolean(r.getString(R.string.p_notif_vibrate), true);
1161- }
1162- if (!prefs.contains(r.getString(R.string.p_backup))) {
1163- editor.putBoolean(r.getString(R.string.p_backup), true);
1164- }
1165- if (!prefs.contains(P_BACKUP_ERROR)) {
1166- editor.putString(P_BACKUP_ERROR, null);
1167- }
1168-
1169- setVisibilityPreferences(prefs, editor, r);
1170-
1171- editor.commit();
1172- }
1173-
1174- private static void setVisibilityPreferences(SharedPreferences p, Editor e, Resources r) {
1175- if(!p.contains(r.getString(R.string.prefs_titleVisible))) {
1176- e.putBoolean(r.getString(R.string.prefs_titleVisible),
1177- Boolean.parseBoolean(r.getString(R.string.prefs_titleVisible_default)));
1178- }
1179- if(!p.contains(r.getString(R.string.prefs_timeVisible))) {
1180- e.putBoolean(r.getString(R.string.prefs_timeVisible),
1181- Boolean.parseBoolean(r.getString(R.string.prefs_timeVisible_default)));
1182- }
1183- if(!p.contains(r.getString(R.string.prefs_deadlineVisible))) {
1184- e.putBoolean(r.getString(R.string.prefs_deadlineVisible),
1185- Boolean.parseBoolean(r.getString(R.string.prefs_deadlineVisible_default)));
1186- }
1187- if(!p.contains(r.getString(R.string.prefs_importanceVisible))) {
1188- e.putBoolean(r.getString(R.string.prefs_importanceVisible),
1189- Boolean.parseBoolean(r.getString(R.string.prefs_importanceVisible_default)));
1190- }
1191- if(!p.contains(r.getString(R.string.prefs_reminderVisible))) {
1192- e.putBoolean(r.getString(R.string.prefs_reminderVisible),
1193- Boolean.parseBoolean(r.getString(R.string.prefs_reminderVisible_default)));
1194- }
1195- if(!p.contains(r.getString(R.string.prefs_repeatVisible))) {
1196- e.putBoolean(r.getString(R.string.prefs_repeatVisible),
1197- Boolean.parseBoolean(r.getString(R.string.prefs_repeatVisible_default)));
1198- }
1199- if(!p.contains(r.getString(R.string.prefs_tagsVisible))) {
1200- e.putBoolean(r.getString(R.string.prefs_tagsVisible),
1201- Boolean.parseBoolean(r.getString(R.string.prefs_tagsVisible_default)));
1202- }
1203- if(!p.contains(r.getString(R.string.prefs_notesVisible))) {
1204- e.putBoolean(r.getString(R.string.prefs_notesVisible),
1205- Boolean.parseBoolean(r.getString(R.string.prefs_notesVisible_default)));
1206- }
1207- }
1208-
1209- // --- system preferences
1210-
1211- /** CurrentVersion: the currently installed version of Astrid */
1212- public static int getCurrentVersion(Context context) {
1213- return getPrefs(context).getInt(P_CURRENT_VERSION, 0);
1214- }
1215-
1216- /** CurrentVersion: the currently installed version of Astrid */
1217- public static void setCurrentVersion(Context context, int version) {
1218- Editor editor = getPrefs(context).edit();
1219- editor.putInt(P_CURRENT_VERSION, version);
1220- editor.commit();
1221- }
1222-
1223- /** TaskKillerHelp: whether we should show task killer help */
1224- public static boolean shouldShowTaskKillerHelp(Context context) {
1225- return getPrefs(context).getBoolean(P_TASK_KILLER_HELP, true);
1226- }
1227-
1228- /** TaskKillerHelp: whether we should show task killer help */
1229- public static void disableTaskKillerHelp(Context context) {
1230- Editor editor = getPrefs(context).edit();
1231- editor.putBoolean(P_TASK_KILLER_HELP, false);
1232- editor.commit();
1233- }
1234-
1235- /** ShowRepeatHelp: whether help dialog should be shown about repeats */
1236- public static boolean shouldShowRepeatHelp(Context context) {
1237- return getPrefs(context).getBoolean(P_SHOW_REPEAT_HELP, true);
1238- }
1239-
1240- public static void setShowRepeatHelp(Context context, boolean setting) {
1241- Editor editor = getPrefs(context).edit();
1242- editor.putBoolean(P_SHOW_REPEAT_HELP, setting);
1243- editor.commit();
1244- }
1245-
1246- public static boolean is24HourFormat(Context context) {
1247- String value = android.provider.Settings.System.getString(context.getContentResolver(),
1248- android.provider.Settings.System.TIME_12_24);
1249- boolean b24 = !(value == null || value.equals("12"));
1250- return b24;
1251- }
1252-
1253- public static SimpleDateFormat getTimeFormat(Context context) {
1254- String value;
1255- if (is24HourFormat(context)) {
1256- value = "H:mm";
1257- } else {
1258- value = "h:mm a";
1259- }
1260-
1261- return new SimpleDateFormat(value);
1262- }
1263-
1264- public static SimpleDateFormat getDateFormat(Context context) {
1265- String value = android.provider.Settings.System.getString(context.getContentResolver(),
1266- android.provider.Settings.System.DATE_FORMAT);
1267-
1268- if(value == null) {
1269- value = "MMM d, yyyy";
1270- }
1271-
1272- // if there is not already day-of-week indicator, add this
1273- if(!value.contains("E"))
1274- value = "EEE, " + value;
1275-
1276- try {
1277- return new SimpleDateFormat(value);
1278- } catch (IllegalArgumentException e) {
1279- return new SimpleDateFormat("EEE, MMM d, yyyy");
1280- }
1281- }
1282-
1283- // --- notification settings
1284-
1285- /** returns hour at which quiet hours start, or null if not set */
1286- public static Integer getQuietHourStart(Context context) {
1287- return getIntegerValue(context, R.string.p_notif_quietStart);
1288- }
1289-
1290- /** returns hour at which quiet hours start, or null if not set */
1291- public static Integer getQuietHourEnd(Context context) {
1292- return getIntegerValue(context, R.string.p_notif_quietEnd);
1293- }
1294-
1295- /** returns hour at which quiet hours start, or null if not set */
1296- public static int getNotificationIconTheme(Context context) {
1297- Integer index = getIntegerValue(context, R.string.p_notif_icon);
1298- if(index == null)
1299- index = 0;
1300- return index;
1301- }
1302-
1303- /** Get notification ring tone, or null if not set */
1304- public static Uri getNotificationRingtone(Context context) {
1305- Resources r = context.getResources();
1306- String value = getPrefs(context).getString(r.getString(
1307- R.string.p_notification_ringtone), "");
1308-
1309- try {
1310+ // pref keys
1311+ private static final String P_CURRENT_VERSION = "cv";
1312+ private static final String P_SHOW_REPEAT_HELP = "repeathelp";
1313+ private static final String P_TASK_LIST_SORT = "tlsort";
1314+ private static final String P_SYNC_RTM_TOKEN = "rtmtoken";
1315+ private static final String P_SYNC_RTM_LAST_SYNC = "rtmlastsync";
1316+ private static final String P_SYNC_LAST_SYNC = "lastsync";
1317+ private static final String P_SYNC_LAST_SYNC_ATTEMPT = "lastsyncattempt";
1318+ private static final String P_LOCALE_LAST_NOTIFY = "locnot";
1319+ private static final String P_DID_ANDROID_AND_ME_SURVEY = "aamsurvey";
1320+ private static final String P_TASK_KILLER_HELP = "taskkiller";
1321+ private static final String P_BACKUP_ERROR = "backupError";
1322+
1323+ // pref values
1324+ public static final int ICON_SET_PINK = 0;
1325+ public static final int ICON_SET_BORING = 1;
1326+ public static final int ICON_SET_ASTRID = 2;
1327+
1328+ // default values
1329+ private static final boolean DEFAULT_PERSISTENCE_MODE = true;
1330+ private static final boolean DEFAULT_COLORIZE = false;
1331+
1332+ /** Set preference defaults, if unset. called at startup */
1333+ public static void setPreferenceDefaults(Context context) {
1334+ SharedPreferences prefs = getPrefs(context);
1335+ Resources r = context.getResources();
1336+ Editor editor = prefs.edit();
1337+
1338+ if (!prefs.contains(r.getString(R.string.p_notif_annoy))) {
1339+ editor.putBoolean(r.getString(R.string.p_notif_annoy),
1340+ DEFAULT_PERSISTENCE_MODE);
1341+ }
1342+ if (!prefs.contains(r.getString(R.string.p_fontSize))) {
1343+ editor.putString(r.getString(R.string.p_fontSize), "20");
1344+ }
1345+ if (!prefs.contains(r.getString(R.string.p_deadlineTime))) {
1346+ editor.putString(r.getString(R.string.p_deadlineTime), "1");
1347+ }
1348+ if (!prefs.contains(r.getString(R.string.p_notif_defaultRemind))) {
1349+ editor.putString(r.getString(R.string.p_notif_defaultRemind), "0");
1350+ }
1351+ if (!prefs.contains(r.getString(R.string.p_colorize))) {
1352+ editor.putBoolean(r.getString(R.string.p_colorize),
1353+ DEFAULT_COLORIZE);
1354+ }
1355+ if (!prefs.contains(r.getString(R.string.p_notif_vibrate))) {
1356+ editor.putBoolean(r.getString(R.string.p_notif_vibrate), true);
1357+ }
1358+ if (!prefs.contains(r.getString(R.string.p_backup))) {
1359+ editor.putBoolean(r.getString(R.string.p_backup), true);
1360+ }
1361+ if (!prefs.contains(P_BACKUP_ERROR)) {
1362+ editor.putString(P_BACKUP_ERROR, null);
1363+ }
1364+
1365+ Calendars.ensureValidDefaultCalendarPreference(context);
1366+
1367+ setVisibilityPreferences(prefs, editor, r);
1368+
1369+ editor.commit();
1370+ }
1371+
1372+ private static void setVisibilityPreferences(SharedPreferences p, Editor e,
1373+ Resources r) {
1374+ if (!p.contains(r.getString(R.string.prefs_titleVisible))) {
1375+ e.putBoolean(r.getString(R.string.prefs_titleVisible), Boolean
1376+ .parseBoolean(r
1377+ .getString(R.string.prefs_titleVisible_default)));
1378+ }
1379+ if (!p.contains(r.getString(R.string.prefs_timeVisible))) {
1380+ e.putBoolean(r.getString(R.string.prefs_timeVisible), Boolean
1381+ .parseBoolean(r
1382+ .getString(R.string.prefs_timeVisible_default)));
1383+ }
1384+ if (!p.contains(r.getString(R.string.prefs_deadlineVisible))) {
1385+ e
1386+ .putBoolean(
1387+ r.getString(R.string.prefs_deadlineVisible),
1388+ Boolean
1389+ .parseBoolean(r
1390+ .getString(R.string.prefs_deadlineVisible_default)));
1391+ }
1392+ if (!p.contains(r.getString(R.string.prefs_importanceVisible))) {
1393+ e
1394+ .putBoolean(
1395+ r.getString(R.string.prefs_importanceVisible),
1396+ Boolean
1397+ .parseBoolean(r
1398+ .getString(R.string.prefs_importanceVisible_default)));
1399+ }
1400+ if (!p.contains(r.getString(R.string.prefs_reminderVisible))) {
1401+ e
1402+ .putBoolean(
1403+ r.getString(R.string.prefs_reminderVisible),
1404+ Boolean
1405+ .parseBoolean(r
1406+ .getString(R.string.prefs_reminderVisible_default)));
1407+ }
1408+ if (!p.contains(r.getString(R.string.prefs_repeatVisible))) {
1409+ e.putBoolean(r.getString(R.string.prefs_repeatVisible), Boolean
1410+ .parseBoolean(r
1411+ .getString(R.string.prefs_repeatVisible_default)));
1412+ }
1413+ if (!p.contains(r.getString(R.string.prefs_tagsVisible))) {
1414+ e.putBoolean(r.getString(R.string.prefs_tagsVisible), Boolean
1415+ .parseBoolean(r
1416+ .getString(R.string.prefs_tagsVisible_default)));
1417+ }
1418+ if (!p.contains(r.getString(R.string.prefs_notesVisible))) {
1419+ e.putBoolean(r.getString(R.string.prefs_notesVisible), Boolean
1420+ .parseBoolean(r
1421+ .getString(R.string.prefs_notesVisible_default)));
1422+ }
1423+ }
1424+
1425+ // --- system preferences
1426+
1427+ /** CurrentVersion: the currently installed version of Astrid */
1428+ public static int getCurrentVersion(Context context) {
1429+ return getPrefs(context).getInt(P_CURRENT_VERSION, 0);
1430+ }
1431+
1432+ /** CurrentVersion: the currently installed version of Astrid */
1433+ public static void setCurrentVersion(Context context, int version) {
1434+ Editor editor = getPrefs(context).edit();
1435+ editor.putInt(P_CURRENT_VERSION, version);
1436+ editor.commit();
1437+ }
1438+
1439+ /** TaskKillerHelp: whether we should show task killer help */
1440+ public static boolean shouldShowTaskKillerHelp(Context context) {
1441+ return getPrefs(context).getBoolean(P_TASK_KILLER_HELP, true);
1442+ }
1443+
1444+ /** TaskKillerHelp: whether we should show task killer help */
1445+ public static void disableTaskKillerHelp(Context context) {
1446+ Editor editor = getPrefs(context).edit();
1447+ editor.putBoolean(P_TASK_KILLER_HELP, false);
1448+ editor.commit();
1449+ }
1450+
1451+ /** ShowRepeatHelp: whether help dialog should be shown about repeats */
1452+ public static boolean shouldShowRepeatHelp(Context context) {
1453+ return getPrefs(context).getBoolean(P_SHOW_REPEAT_HELP, true);
1454+ }
1455+
1456+ public static void setShowRepeatHelp(Context context, boolean setting) {
1457+ Editor editor = getPrefs(context).edit();
1458+ editor.putBoolean(P_SHOW_REPEAT_HELP, setting);
1459+ editor.commit();
1460+ }
1461+
1462+ public static boolean is24HourFormat(Context context) {
1463+ String value = android.provider.Settings.System.getString(context
1464+ .getContentResolver(),
1465+ android.provider.Settings.System.TIME_12_24);
1466+ boolean b24 = !(value == null || value.equals("12"));
1467+ return b24;
1468+ }
1469+
1470+ public static SimpleDateFormat getTimeFormat(Context context) {
1471+ String value;
1472+ if (is24HourFormat(context)) {
1473+ value = "H:mm";
1474+ } else {
1475+ value = "h:mm a";
1476+ }
1477+
1478+ return new SimpleDateFormat(value);
1479+ }
1480+
1481+ public static SimpleDateFormat getDateFormat(Context context) {
1482+ String value = android.provider.Settings.System.getString(context
1483+ .getContentResolver(),
1484+ android.provider.Settings.System.DATE_FORMAT);
1485+
1486+ if (value == null) {
1487+ value = "MMM d, yyyy";
1488+ }
1489+
1490+ // if there is not already day-of-week indicator, add this
1491+ if (!value.contains("E"))
1492+ value = "EEE, " + value;
1493+
1494+ try {
1495+ return new SimpleDateFormat(value);
1496+ } catch (IllegalArgumentException e) {
1497+ return new SimpleDateFormat("EEE, MMM d, yyyy");
1498+ }
1499+ }
1500+
1501+ // --- notification settings
1502+
1503+ /** returns hour at which quiet hours start, or null if not set */
1504+ public static Integer getQuietHourStart(Context context) {
1505+ return getIntegerValue(context, R.string.p_notif_quietStart);
1506+ }
1507+
1508+ /** returns hour at which quiet hours start, or null if not set */
1509+ public static Integer getQuietHourEnd(Context context) {
1510+ return getIntegerValue(context, R.string.p_notif_quietEnd);
1511+ }
1512+
1513+ /** returns hour at which quiet hours start, or null if not set */
1514+ public static int getNotificationIconTheme(Context context) {
1515+ Integer index = getIntegerValue(context, R.string.p_notif_icon);
1516+ if (index == null)
1517+ index = 0;
1518+ return index;
1519+ }
1520+
1521+ /** Get notification ring tone, or null if not set */
1522+ public static Uri getNotificationRingtone(Context context) {
1523+ Resources r = context.getResources();
1524+ String value = getPrefs(context).getString(
1525+ r.getString(R.string.p_notification_ringtone), "");
1526+
1527+ try {
1528 return Uri.parse(value);
1529 } catch (RuntimeException e) {
1530 return null;
1531 }
1532- }
1533-
1534- /** Get perstence mode setting */
1535- public static boolean isPersistenceMode(Context context) {
1536- Resources r = context.getResources();
1537- return getPrefs(context).getBoolean(r.getString(
1538- R.string.p_notif_annoy), DEFAULT_PERSISTENCE_MODE);
1539- }
1540-
1541- /** Get vibration mode setting */
1542- public static boolean shouldVibrate(Context context) {
1543- Resources r = context.getResources();
1544- return getPrefs(context).getBoolean(r.getString(
1545- R.string.p_notif_vibrate), true);
1546- }
1547-
1548- /** Return # of days to remind by default */
1549- public static Integer getDefaultReminder(Context context) {
1550- return getIntegerValue(context, R.string.p_notif_defaultRemind);
1551- }
1552-
1553- // --- postpone count & settings
1554-
1555- /** whether nags for postponing and other things should be shown */
1556- public static boolean shouldShowNags(Context context) {
1557- return getPrefs(context).getBoolean(context.getResources().
1558- getString(R.string.p_nagging), true);
1559- }
1560-
1561- // --- appearance settings
1562-
1563- /** returns the font size user wants on the front page */
1564- public static Integer getTaskListFontSize(Context context) {
1565- return getIntegerValue(context, R.string.p_fontSize);
1566- }
1567-
1568- /** Return # of days from now to set deadlines by default */
1569- public static Integer getDefaultDeadlineDays(Context context) {
1570- return getIntegerValue(context, R.string.p_deadlineTime);
1571- }
1572-
1573- /** Get perstence mode setting */
1574- public static boolean isColorize(Context context) {
1575- Resources r = context.getResources();
1576- return getPrefs(context).getBoolean(r.getString(
1577- R.string.p_colorize), DEFAULT_COLORIZE);
1578- }
1579-
1580- /** TaskListSort: the sorting method for the task list */
1581- public static int getTaskListSort(Context context) {
1582- return getPrefs(context).getInt(P_TASK_LIST_SORT, 0);
1583- }
1584-
1585- /** TaskListSort: the sorting method for the task list */
1586- public static void setTaskListSort(Context context, int value) {
1587- Editor editor = getPrefs(context).edit();
1588- editor.putInt(P_TASK_LIST_SORT, value);
1589- editor.commit();
1590- }
1591-
1592- /** TagListSort: the sorting method for the tag list */
1593- public static int getTagListSort(Context context) {
1594- return getPrefs(context).getInt(P_TASK_LIST_SORT, 0);
1595- }
1596-
1597- /** TagListSort: the sorting method for the tag list */
1598- public static void setTagListSort(Context context, int value) {
1599- Editor editor = getPrefs(context).edit();
1600- editor.putInt(P_TASK_LIST_SORT, value);
1601- editor.commit();
1602- }
1603-
1604- // --- backup preferences
1605-
1606- public static boolean isBackupEnabled(Context context) {
1607- Resources r = context.getResources();
1608- return getPrefs(context).getBoolean(r.getString(R.string.p_backup), true);
1609- }
1610-
1611- /**
1612- * @return error when doing backup, empty string if successful, or null
1613- * if no backup has been attempted
1614- */
1615- public static String getBackupSummary(Context context) {
1616- return getPrefs(context).getString(P_BACKUP_ERROR, null);
1617- }
1618-
1619- public static void setBackupSummary(Context context, String newValue) {
1620- Editor editor = getPrefs(context).edit();
1621- editor.putString(P_BACKUP_ERROR, newValue);
1622- editor.commit();
1623- }
1624-
1625- // --- synchronization preferences
1626-
1627- /** RTM authentication token, or null if doesn't exist */
1628- public static String getSyncRTMToken(Context context) {
1629- return getPrefs(context).getString(P_SYNC_RTM_TOKEN, null);
1630- }
1631-
1632- /** Sets the RTM authentication token. Set to null to clear. */
1633- public static void setSyncRTMToken(Context context, String setting) {
1634- Editor editor = getPrefs(context).edit();
1635- editor.putString(P_SYNC_RTM_TOKEN, setting);
1636- editor.commit();
1637- }
1638-
1639- /** RTM Last Successful Sync Date, or null */
1640- public static Date getSyncRTMLastSync(Context context) {
1641- Long value = getPrefs(context).getLong(P_SYNC_RTM_LAST_SYNC, 0);
1642- if(value == 0)
1643- return null;
1644- return new Date(value);
1645- }
1646-
1647- /** Set RTM Last Successful Sync Date */
1648- public static void setSyncRTMLastSync(Context context, Date date) {
1649- if(date == null) {
1650- clearPref(context, P_SYNC_RTM_LAST_SYNC);
1651- return;
1652- }
1653-
1654- Editor editor = getPrefs(context).edit();
1655- editor.putLong(P_SYNC_RTM_LAST_SYNC, date.getTime());
1656- editor.commit();
1657- }
1658-
1659- /** Should sync with RTM? */
1660- public static boolean shouldSyncRTM(Context context) {
1661- Resources r = context.getResources();
1662- return getPrefs(context).getBoolean(r.getString(
1663- R.string.p_sync_rtm), false);
1664- }
1665-
1666- /** Should display sync shortcut? */
1667- public static boolean shouldDisplaySyncButton(Context context) {
1668- Resources r = context.getResources();
1669- return getPrefs(context).getBoolean(r.getString(
1670- R.string.p_sync_button), false);
1671- }
1672-
1673- /** Should hide sync dialog boxes? */
1674- public static boolean shouldSuppressSyncDialogs(Context context) {
1675- Resources r = context.getResources();
1676- return getPrefs(context).getBoolean(r.getString(
1677- R.string.p_sync_quiet), false);
1678- }
1679-
1680- /** Reads the frequency, in seconds, auto-sync should occur.
1681- * @return seconds duration, or null if not desired */
1682- public static Integer getSyncAutoSyncFrequency(Context context) {
1683- Integer time = getIntegerValue(context, R.string.p_sync_interval);
1684- if(time != null && time == 0)
1685- time = null;
1686- return time;
1687- }
1688-
1689- /** Reads the old auto */
1690- public static Float getSyncOldAutoSyncFrequency(Context context) {
1691- return getFloatValue(context, R.string.p_sync_every_old);
1692- }
1693-
1694- /** Sets the auto-sync frequency to the desired value */
1695- public static void setSyncAutoSyncFrequency(Context context, int value) {
1696- Editor editor = getPrefs(context).edit();
1697- editor.putString(context.getResources().getString(R.string.p_sync_interval),
1698- Integer.toString(value));
1699- editor.commit();
1700- }
1701-
1702- /** Last Auto-Sync Date, or null */
1703- public static Date getSyncLastSync(Context context) {
1704- Long value = getPrefs(context).getLong(P_SYNC_LAST_SYNC, 0);
1705- if(value == 0)
1706- return null;
1707- return new Date(value);
1708- }
1709-
1710- /** Last Successful Auto-Sync Date, or null */
1711- public static Date getSyncLastSyncAttempt(Context context) {
1712- Long value = getPrefs(context).getLong(P_SYNC_LAST_SYNC_ATTEMPT, 0);
1713- if(value == 0)
1714- return null;
1715- return new Date(value);
1716- }
1717-
1718- /** Set Last Sync Date */
1719- public static void setSyncLastSync(Context context, Date date) {
1720- if(date == null) {
1721- clearPref(context, P_SYNC_LAST_SYNC);
1722- return;
1723- }
1724-
1725- Editor editor = getPrefs(context).edit();
1726- editor.putLong(P_SYNC_LAST_SYNC, date.getTime());
1727- editor.commit();
1728- }
1729-
1730- /** Set Last Auto-Sync Attempt Date */
1731- public static void setSyncLastSyncAttempt(Context context, Date date) {
1732- Editor editor = getPrefs(context).edit();
1733- editor.putLong(P_SYNC_LAST_SYNC_ATTEMPT, date.getTime());
1734- editor.commit();
1735- }
1736-
1737- // --- locale
1738-
1739- public static void setLocaleLastAlertTime(Context context, long tag, long time) {
1740- Editor editor = getPrefs(context).edit();
1741- editor.putLong(P_LOCALE_LAST_NOTIFY + tag, time);
1742- editor.commit();
1743- }
1744-
1745- public static long getLocaleLastAlertTime(Context context, long tag) {
1746- return getPrefs(context).getLong(P_LOCALE_LAST_NOTIFY + tag, 0);
1747- }
1748-
1749- // --- misc
1750-
1751- /** Get setting */
1752- public static boolean didAAMSurvey(Context context) {
1753- return getPrefs(context).getBoolean(P_DID_ANDROID_AND_ME_SURVEY, false);
1754- }
1755-
1756- /** Set setting */
1757- public static void setDidAAMSurvey(Context context, boolean value) {
1758- Editor editor = getPrefs(context).edit();
1759- editor.putBoolean(P_DID_ANDROID_AND_ME_SURVEY, value);
1760- editor.commit();
1761- }
1762-
1763- // --- helper methods
1764-
1765- /** Clear the given preference */
1766- private static void clearPref(Context context, String key) {
1767- Editor editor = getPrefs(context).edit();
1768- editor.remove(key);
1769- editor.commit();
1770- }
1771-
1772- /** Get preferences object from the context */
1773- private static SharedPreferences getPrefs(Context context) {
1774- return PreferenceManager.getDefaultSharedPreferences(context);
1775- }
1776-
1777- /** Gets an integer value from a string resource id. Returns null
1778- * if the value is not set or not an integer.
1779- *
1780- * @param context
1781- * @param keyResource resource from string.xml
1782- * @return integer value, or null on error
1783- */
1784- private static Integer getIntegerValue(Context context, int keyResource) {
1785- Resources r = context.getResources();
1786- String value = getPrefs(context).getString(r.getString(keyResource), "");
1787-
1788- try {
1789- return Integer.parseInt(value);
1790- } catch (Exception e) {
1791- return null;
1792- }
1793- }
1794-
1795- /** Gets an float value from a string resource id. Returns null
1796- * if the value is not set or not an flat.
1797- *
1798- * @param context
1799- * @param keyResource resource from string.xml
1800- * @return
1801- */
1802- private static Float getFloatValue(Context context, int keyResource) {
1803- Resources r = context.getResources();
1804- String value = getPrefs(context).getString(r.getString(keyResource), "");
1805-
1806- try {
1807- return Float.parseFloat(value);
1808- } catch (Exception e) {
1809- return null;
1810- }
1811- }
1812-
1813- public static TaskFieldsVisibility getTaskFieldsVisibility(Context context) {
1814- return TaskFieldsVisibility.getFromPreferences(context, getPrefs(context));
1815- }
1816+ }
1817+
1818+ /** Get perstence mode setting */
1819+ public static boolean isPersistenceMode(Context context) {
1820+ Resources r = context.getResources();
1821+ return getPrefs(context).getBoolean(
1822+ r.getString(R.string.p_notif_annoy), DEFAULT_PERSISTENCE_MODE);
1823+ }
1824+
1825+ /** Get vibration mode setting */
1826+ public static boolean shouldVibrate(Context context) {
1827+ Resources r = context.getResources();
1828+ return getPrefs(context).getBoolean(
1829+ r.getString(R.string.p_notif_vibrate), true);
1830+ }
1831+
1832+ /** Return # of days to remind by default */
1833+ public static Integer getDefaultReminder(Context context) {
1834+ return getIntegerValue(context, R.string.p_notif_defaultRemind);
1835+ }
1836+
1837+ // --- postpone count & settings
1838+
1839+ /** whether nags for postponing and other things should be shown */
1840+ public static boolean shouldShowNags(Context context) {
1841+ return getPrefs(context).getBoolean(
1842+ context.getResources().getString(R.string.p_nagging), true);
1843+ }
1844+
1845+ // --- appearance settings
1846+
1847+ /** returns the font size user wants on the front page */
1848+ public static Integer getTaskListFontSize(Context context) {
1849+ return getIntegerValue(context, R.string.p_fontSize);
1850+ }
1851+
1852+ /** Return # of days from now to set deadlines by default */
1853+ public static Integer getDefaultDeadlineDays(Context context) {
1854+ return getIntegerValue(context, R.string.p_deadlineTime);
1855+ }
1856+
1857+ /** Get perstence mode setting */
1858+ public static boolean isColorize(Context context) {
1859+ Resources r = context.getResources();
1860+ return getPrefs(context).getBoolean(r.getString(R.string.p_colorize),
1861+ DEFAULT_COLORIZE);
1862+ }
1863+
1864+ /** TaskListSort: the sorting method for the task list */
1865+ public static int getTaskListSort(Context context) {
1866+ return getPrefs(context).getInt(P_TASK_LIST_SORT, 0);
1867+ }
1868+
1869+ /** TaskListSort: the sorting method for the task list */
1870+ public static void setTaskListSort(Context context, int value) {
1871+ Editor editor = getPrefs(context).edit();
1872+ editor.putInt(P_TASK_LIST_SORT, value);
1873+ editor.commit();
1874+ }
1875+
1876+ /** TagListSort: the sorting method for the tag list */
1877+ public static int getTagListSort(Context context) {
1878+ return getPrefs(context).getInt(P_TASK_LIST_SORT, 0);
1879+ }
1880+
1881+ /** TagListSort: the sorting method for the tag list */
1882+ public static void setTagListSort(Context context, int value) {
1883+ Editor editor = getPrefs(context).edit();
1884+ editor.putInt(P_TASK_LIST_SORT, value);
1885+ editor.commit();
1886+ }
1887+
1888+ // --- backup preferences
1889+
1890+ public static boolean isBackupEnabled(Context context) {
1891+ Resources r = context.getResources();
1892+ return getPrefs(context).getBoolean(r.getString(R.string.p_backup),
1893+ true);
1894+ }
1895+
1896+ /**
1897+ * @return error when doing backup, empty string if successful, or null if
1898+ * no backup has been attempted
1899+ */
1900+ public static String getBackupSummary(Context context) {
1901+ return getPrefs(context).getString(P_BACKUP_ERROR, null);
1902+ }
1903+
1904+ public static void setBackupSummary(Context context, String newValue) {
1905+ Editor editor = getPrefs(context).edit();
1906+ editor.putString(P_BACKUP_ERROR, newValue);
1907+ editor.commit();
1908+ }
1909+
1910+ // --- synchronization preferences
1911+
1912+ /** RTM authentication token, or null if doesn't exist */
1913+ public static String getSyncRTMToken(Context context) {
1914+ return getPrefs(context).getString(P_SYNC_RTM_TOKEN, null);
1915+ }
1916+
1917+ /** Sets the RTM authentication token. Set to null to clear. */
1918+ public static void setSyncRTMToken(Context context, String setting) {
1919+ Editor editor = getPrefs(context).edit();
1920+ editor.putString(P_SYNC_RTM_TOKEN, setting);
1921+ editor.commit();
1922+ }
1923+
1924+ /** RTM Last Successful Sync Date, or null */
1925+ public static Date getSyncRTMLastSync(Context context) {
1926+ Long value = getPrefs(context).getLong(P_SYNC_RTM_LAST_SYNC, 0);
1927+ if (value == 0)
1928+ return null;
1929+ return new Date(value);
1930+ }
1931+
1932+ /** Set RTM Last Successful Sync Date */
1933+ public static void setSyncRTMLastSync(Context context, Date date) {
1934+ if (date == null) {
1935+ clearPref(context, P_SYNC_RTM_LAST_SYNC);
1936+ return;
1937+ }
1938+
1939+ Editor editor = getPrefs(context).edit();
1940+ editor.putLong(P_SYNC_RTM_LAST_SYNC, date.getTime());
1941+ editor.commit();
1942+ }
1943+
1944+ /** Should sync with RTM? */
1945+ public static boolean shouldSyncRTM(Context context) {
1946+ Resources r = context.getResources();
1947+ return getPrefs(context).getBoolean(r.getString(R.string.p_sync_rtm),
1948+ false);
1949+ }
1950+
1951+ /** Should display sync shortcut? */
1952+ public static boolean shouldDisplaySyncButton(Context context) {
1953+ Resources r = context.getResources();
1954+ return getPrefs(context).getBoolean(
1955+ r.getString(R.string.p_sync_button), false);
1956+ }
1957+
1958+ /** Should hide sync dialog boxes? */
1959+ public static boolean shouldSuppressSyncDialogs(Context context) {
1960+ Resources r = context.getResources();
1961+ return getPrefs(context).getBoolean(r.getString(R.string.p_sync_quiet),
1962+ false);
1963+ }
1964+
1965+ /**
1966+ * Reads the frequency, in seconds, auto-sync should occur.
1967+ *
1968+ * @return seconds duration, or null if not desired
1969+ */
1970+ public static Integer getSyncAutoSyncFrequency(Context context) {
1971+ Integer time = getIntegerValue(context, R.string.p_sync_interval);
1972+ if (time != null && time == 0)
1973+ time = null;
1974+ return time;
1975+ }
1976+
1977+ /** Reads the old auto */
1978+ public static Float getSyncOldAutoSyncFrequency(Context context) {
1979+ return getFloatValue(context, R.string.p_sync_every_old);
1980+ }
1981+
1982+ /** Sets the auto-sync frequency to the desired value */
1983+ public static void setSyncAutoSyncFrequency(Context context, int value) {
1984+ Editor editor = getPrefs(context).edit();
1985+ editor.putString(context.getResources().getString(
1986+ R.string.p_sync_interval), Integer.toString(value));
1987+ editor.commit();
1988+ }
1989+
1990+ /** Last Auto-Sync Date, or null */
1991+ public static Date getSyncLastSync(Context context) {
1992+ Long value = getPrefs(context).getLong(P_SYNC_LAST_SYNC, 0);
1993+ if (value == 0)
1994+ return null;
1995+ return new Date(value);
1996+ }
1997+
1998+ /** Last Successful Auto-Sync Date, or null */
1999+ public static Date getSyncLastSyncAttempt(Context context) {
2000+ Long value = getPrefs(context).getLong(P_SYNC_LAST_SYNC_ATTEMPT, 0);
2001+ if (value == 0)
2002+ return null;
2003+ return new Date(value);
2004+ }
2005+
2006+ /** Set Last Sync Date */
2007+ public static void setSyncLastSync(Context context, Date date) {
2008+ if (date == null) {
2009+ clearPref(context, P_SYNC_LAST_SYNC);
2010+ return;
2011+ }
2012+
2013+ Editor editor = getPrefs(context).edit();
2014+ editor.putLong(P_SYNC_LAST_SYNC, date.getTime());
2015+ editor.commit();
2016+ }
2017+
2018+ /** Set Last Auto-Sync Attempt Date */
2019+ public static void setSyncLastSyncAttempt(Context context, Date date) {
2020+ Editor editor = getPrefs(context).edit();
2021+ editor.putLong(P_SYNC_LAST_SYNC_ATTEMPT, date.getTime());
2022+ editor.commit();
2023+ }
2024+
2025+ // --- locale
2026+
2027+ public static void setLocaleLastAlertTime(Context context, long tag,
2028+ long time) {
2029+ Editor editor = getPrefs(context).edit();
2030+ editor.putLong(P_LOCALE_LAST_NOTIFY + tag, time);
2031+ editor.commit();
2032+ }
2033+
2034+ public static long getLocaleLastAlertTime(Context context, long tag) {
2035+ return getPrefs(context).getLong(P_LOCALE_LAST_NOTIFY + tag, 0);
2036+ }
2037+
2038+ // --- misc
2039+
2040+ /** Get setting */
2041+ public static boolean didAAMSurvey(Context context) {
2042+ return getPrefs(context).getBoolean(P_DID_ANDROID_AND_ME_SURVEY, false);
2043+ }
2044+
2045+ /** Set setting */
2046+ public static void setDidAAMSurvey(Context context, boolean value) {
2047+ Editor editor = getPrefs(context).edit();
2048+ editor.putBoolean(P_DID_ANDROID_AND_ME_SURVEY, value);
2049+ editor.commit();
2050+ }
2051+
2052+ /** Get default calendar id. */
2053+ public static String getDefaultCalendarID(Context context) {
2054+ Resources r = context.getResources();
2055+ return getPrefs(context).getString(
2056+ r.getString(R.string.prefs_defaultCalendar),
2057+ r.getString(R.string.prefs_defaultCalendar_default));
2058+ }
2059+
2060+ /** Get default calendar id. Returns default value if the calendar does not exist anymore.*/
2061+ public static String getDefaultCalendarIDSafe(Context context) {
2062+ Calendars.ensureValidDefaultCalendarPreference(context);
2063+ return getDefaultCalendarID(context);
2064+ }
2065+
2066+ /** Set default calendar id */
2067+ public static void setDefaultCalendarID(Context context, String value) {
2068+ Resources r = context.getResources();
2069+ Editor editor = getPrefs(context).edit();
2070+ editor.putString(r.getString(R.string.prefs_defaultCalendar), value);
2071+ editor.commit();
2072+ }
2073+
2074+ // --- helper methods
2075+
2076+ /** Clear the given preference */
2077+ private static void clearPref(Context context, String key) {
2078+ Editor editor = getPrefs(context).edit();
2079+ editor.remove(key);
2080+ editor.commit();
2081+ }
2082+
2083+ /** Get preferences object from the context */
2084+ private static SharedPreferences getPrefs(Context context) {
2085+ return PreferenceManager.getDefaultSharedPreferences(context);
2086+ }
2087+
2088+ /**
2089+ * Gets an integer value from a string resource id. Returns null if the
2090+ * value is not set or not an integer.
2091+ *
2092+ * @param context
2093+ * @param keyResource
2094+ * resource from string.xml
2095+ * @return integer value, or null on error
2096+ */
2097+ private static Integer getIntegerValue(Context context, int keyResource) {
2098+ Resources r = context.getResources();
2099+ String value = getPrefs(context)
2100+ .getString(r.getString(keyResource), "");
2101+
2102+ try {
2103+ return Integer.parseInt(value);
2104+ } catch (Exception e) {
2105+ return null;
2106+ }
2107+ }
2108+
2109+ /**
2110+ * Gets an float value from a string resource id. Returns null if the value
2111+ * is not set or not an flat.
2112+ *
2113+ * @param context
2114+ * @param keyResource
2115+ * resource from string.xml
2116+ * @return
2117+ */
2118+ private static Float getFloatValue(Context context, int keyResource) {
2119+ Resources r = context.getResources();
2120+ String value = getPrefs(context)
2121+ .getString(r.getString(keyResource), "");
2122+
2123+ try {
2124+ return Float.parseFloat(value);
2125+ } catch (Exception e) {
2126+ return null;
2127+ }
2128+ }
2129+
2130+ public static TaskFieldsVisibility getTaskFieldsVisibility(Context context) {
2131+ return TaskFieldsVisibility.getFromPreferences(context,
2132+ getPrefs(context));
2133+ }
2134 }
2135
2136=== modified file 'src/com/timsu/astrid/utilities/StartupReceiver.java'
2137--- src/com/timsu/astrid/utilities/StartupReceiver.java 2010-04-18 01:56:44 +0000
2138+++ src/com/timsu/astrid/utilities/StartupReceiver.java 2010-05-03 21:39:37 +0000
2139@@ -1,5 +1,7 @@
2140 package com.timsu.astrid.utilities;
2141
2142+import java.util.List;
2143+
2144 import android.Manifest;
2145 import android.app.AlarmManager;
2146 import android.app.AlertDialog;
2147@@ -7,18 +9,17 @@
2148 import android.content.BroadcastReceiver;
2149 import android.content.Context;
2150 import android.content.DialogInterface;
2151+import android.content.Intent;
2152 import android.content.DialogInterface.OnClickListener;
2153-import android.content.Intent;
2154 import android.content.pm.PackageInfo;
2155 import android.content.pm.PackageManager;
2156 import android.util.Log;
2157+
2158 import com.timsu.astrid.R;
2159 import com.timsu.astrid.activities.SyncPreferences;
2160 import com.timsu.astrid.appwidget.AstridAppWidgetProvider.UpdateService;
2161 import com.timsu.astrid.sync.SynchronizationService;
2162
2163-import java.util.List;
2164-
2165 public class StartupReceiver extends BroadcastReceiver {
2166
2167 private static boolean hasStartedUp = false;

Subscribers

People subscribed via source and target branches

to all changes: