mirror of https://github.com/tasks/tasks
Merge of default-calendar branch in launchpad from Sami Salonen. (lp:~ssalonen/astrid/default-calendar)
parent
6ee437ede1
commit
f1b9d9e42c
@ -1,117 +1,121 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/prefs_category_alerts">
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_quietStart"
|
||||
android:entries="@array/EPr_quiet_hours_start"
|
||||
android:entryValues="@array/EPr_quiet_hours_start_values"
|
||||
android:title="@string/prefs_quietStart_title"
|
||||
android:summary="@string/prefs_quietStart_desc" />
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_quietEnd"
|
||||
android:entries="@array/EPr_quiet_hours_end"
|
||||
android:entryValues="@array/EPr_quiet_hours_end_values"
|
||||
android:title="@string/prefs_quietEnd_title"
|
||||
android:summary="@string/prefs_quietEnd_desc" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_notif_annoy"
|
||||
android:title="@string/prefs_annoy_title"
|
||||
android:summary="@string/prefs_annoy_desc" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_notif_vibrate"
|
||||
android:title="@string/prefs_vibrate_title"
|
||||
android:summary="@string/prefs_vibrate_desc" />
|
||||
<EditTextPreference
|
||||
android:key="@string/p_notif_defaultRemind"
|
||||
android:title="@string/prefs_defaultRemind_title"
|
||||
android:summary="@string/prefs_defaultRemind_desc" />
|
||||
<RingtonePreference
|
||||
android:key="@string/p_notification_ringtone"
|
||||
android:title="@string/prefs_notification_title"
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_quietStart"
|
||||
android:entries="@array/EPr_quiet_hours_start"
|
||||
android:entryValues="@array/EPr_quiet_hours_start_values"
|
||||
android:title="@string/prefs_quietStart_title"
|
||||
android:summary="@string/prefs_quietStart_desc" />
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_quietEnd"
|
||||
android:entries="@array/EPr_quiet_hours_end"
|
||||
android:entryValues="@array/EPr_quiet_hours_end_values"
|
||||
android:title="@string/prefs_quietEnd_title"
|
||||
android:summary="@string/prefs_quietEnd_desc" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_notif_annoy"
|
||||
android:title="@string/prefs_annoy_title"
|
||||
android:summary="@string/prefs_annoy_desc" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_notif_vibrate"
|
||||
android:title="@string/prefs_vibrate_title"
|
||||
android:summary="@string/prefs_vibrate_desc" />
|
||||
<EditTextPreference
|
||||
android:key="@string/p_notif_defaultRemind"
|
||||
android:title="@string/prefs_defaultRemind_title"
|
||||
android:summary="@string/prefs_defaultRemind_desc" />
|
||||
<RingtonePreference
|
||||
android:key="@string/p_notification_ringtone"
|
||||
android:title="@string/prefs_notification_title"
|
||||
android:summary="@string/prefs_notification_desc"
|
||||
android:ringtoneType="notification"
|
||||
android:ringtoneType="notification"
|
||||
android:showDefault="true"
|
||||
android:showSilent="true" />
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_icon"
|
||||
android:entries="@array/notif_icon_entries"
|
||||
android:entryValues="@array/notif_icon_values"
|
||||
android:title="@string/prefs_notificon_title"
|
||||
android:summary="@string/prefs_notificon_desc" />
|
||||
|
||||
<ListPreference
|
||||
android:key="@string/p_notif_icon"
|
||||
android:entries="@array/notif_icon_entries"
|
||||
android:entryValues="@array/notif_icon_values"
|
||||
android:title="@string/prefs_notificon_title"
|
||||
android:summary="@string/prefs_notificon_desc" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/prefs_category_appearance">
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_colorize"
|
||||
android:title="@string/prefs_colorize_title"
|
||||
android:summary="@string/prefs_colorize_desc" />
|
||||
<ListPreference
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_colorize"
|
||||
android:title="@string/prefs_colorize_title"
|
||||
android:summary="@string/prefs_colorize_desc" />
|
||||
<ListPreference
|
||||
android:key="@string/p_fontSize"
|
||||
android:entries="@array/EPr_font_size"
|
||||
android:entryValues="@array/EPr_font_size"
|
||||
android:title="@string/prefs_fontSize_title"
|
||||
android:entries="@array/EPr_font_size"
|
||||
android:entryValues="@array/EPr_font_size"
|
||||
android:title="@string/prefs_fontSize_title"
|
||||
android:summary="@string/prefs_fontSize_desc" />
|
||||
<PreferenceScreen
|
||||
android:title="@string/displayedFields_PrefScreen_Title"
|
||||
android:summary="@string/displayedFields_PrefScreen_Desc">
|
||||
<CheckBoxPreference
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_deadlineVisible"
|
||||
android:title="@string/prefs_deadlineVisible_title"
|
||||
android:summary="@string/prefs_deadlineVisible_desc"
|
||||
android:defaultValue="@string/prefs_deadlineVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@string/prefs_deadlineVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_tagsVisible"
|
||||
android:title="@string/prefs_tagsVisible_title"
|
||||
android:summary="@string/prefs_tagsVisible_desc"
|
||||
android:defaultValue="@string/prefs_tagsVisible_default" />
|
||||
<CheckBoxPreference
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_importanceVisible"
|
||||
android:title="@string/prefs_importanceVisible_title"
|
||||
android:summary="@string/prefs_importanceVisible_desc"
|
||||
android:defaultValue="@string/prefs_importanceVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@string/prefs_importanceVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_timeVisible"
|
||||
android:title="@string/prefs_timeVisible_title"
|
||||
android:summary="@string/prefs_timeVisible_desc"
|
||||
android:defaultValue="@string/prefs_timeVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@string/prefs_timeVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_reminderVisible"
|
||||
android:title="@string/prefs_reminderVisible_title"
|
||||
android:summary="@string/prefs_reminderVisible_desc"
|
||||
android:defaultValue="@string/prefs_reminderVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@string/prefs_reminderVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_repeatVisible"
|
||||
android:title="@string/prefs_repeatVisible_title"
|
||||
android:summary="@string/prefs_repeatVisible_desc"
|
||||
android:defaultValue="@string/prefs_repeatVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@string/prefs_repeatVisible_default" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/prefs_notesVisible"
|
||||
android:title="@string/prefs_notesVisible_title"
|
||||
android:summary="@string/prefs_notesVisible_desc"
|
||||
android:defaultValue="@string/prefs_notesVisible_default" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/prefs_category_other">
|
||||
<CheckBoxPreference
|
||||
android:title="@string/prefs_category_other">
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_nagging"
|
||||
android:title="@string/prefs_nagging_title"
|
||||
android:summary="@string/prefs_nagging_desc"
|
||||
android:defaultValue="true" />
|
||||
<EditTextPreference
|
||||
android:key="@string/p_deadlineTime"
|
||||
android:title="@string/prefs_deadlineTime_title"
|
||||
<EditTextPreference
|
||||
android:key="@string/p_deadlineTime"
|
||||
android:title="@string/prefs_deadlineTime_title"
|
||||
android:summary="@string/prefs_deadlineTime_desc" />
|
||||
<CheckBoxPreference
|
||||
android:key="@string/p_backup"
|
||||
android:title="@string/prefs_backup_title"
|
||||
android:summary="@string/prefs_backup_desc"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference
|
||||
android:key="@string/prefs_defaultCalendar"
|
||||
android:title="@string/prefs_defaultCalendar_title"
|
||||
android:summary="@string/prefs_defaultCalendar_desc" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
@ -0,0 +1,179 @@
|
||||
package com.timsu.astrid.utilities;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
|
||||
public class Calendars {
|
||||
|
||||
// Private SDK
|
||||
private static final Uri CALENDAR_CONTENT_URI = Uri
|
||||
.parse("content://calendar/calendars"); // Calendars.CONTENT_URI
|
||||
|
||||
private static final String ID_COLUMN_NAME = "_id";
|
||||
private static final String DISPLAY_COLUMN_NAME = "displayName";
|
||||
private static final String ACCES_LEVEL_COLUMN_NAME = "access_level";
|
||||
|
||||
private static final String[] CALENDARS_PROJECTION = new String[] {
|
||||
ID_COLUMN_NAME, // Calendars._ID,
|
||||
DISPLAY_COLUMN_NAME // Calendars.DISPLAY_NAME
|
||||
};
|
||||
|
||||
// Only show calendars that the user can modify. Access level 500
|
||||
// corresponds to Calendars.CONTRIBUTOR_ACCESS
|
||||
private static final String CALENDARS_WHERE = ACCES_LEVEL_COLUMN_NAME + " >= 500";
|
||||
|
||||
private static final String CALENDARS_WHERE_ID = ACCES_LEVEL_COLUMN_NAME+" >= 500 AND" + ID_COLUMN_NAME +"=?";
|
||||
|
||||
private static final String CALENDARS_SORT = "displayName ASC";
|
||||
|
||||
/**
|
||||
* Ensures that the default calendar preference is pointing to
|
||||
* user-modifiable calendar that exists. If the calendar does not exist
|
||||
* anymore, the preference is reset to default value.
|
||||
*
|
||||
* @param context
|
||||
* Context
|
||||
*/
|
||||
public static void ensureValidDefaultCalendarPreference(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(context);
|
||||
Resources r = context.getResources();
|
||||
Editor editor = prefs.edit();
|
||||
// We default the 'defaultCalendar' setting when it is undefined
|
||||
// or when the calendar does not exist anymore
|
||||
if (!prefs.contains(r.getString(R.string.prefs_defaultCalendar))
|
||||
|| !Calendars.isCalendarPresent(context, prefs.getString(r
|
||||
.getString(R.string.prefs_defaultCalendar), null))) {
|
||||
editor.putString(r.getString(R.string.prefs_defaultCalendar), r
|
||||
.getString(R.string.prefs_defaultCalendar_default));
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all user-modifiable calendars to listPreference. Always includes
|
||||
* entry called "Astrid default" with calendar id of
|
||||
* prefs_defaultCalendar_default.
|
||||
*
|
||||
* @param context
|
||||
* context
|
||||
* @param listPreference
|
||||
* preference to init
|
||||
*/
|
||||
public static void initCalendarsPreference(Context context,
|
||||
ListPreference listPreference) {
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Resources r = context.getResources();
|
||||
Cursor c = cr.query(CALENDAR_CONTENT_URI, CALENDARS_PROJECTION,
|
||||
CALENDARS_WHERE, null, CALENDARS_SORT);
|
||||
|
||||
// Fetch the current setting. Invalid calendar id will
|
||||
// be changed to default value.
|
||||
String currentSetting = String.valueOf(Preferences
|
||||
.getDefaultCalendarIDSafe(context));
|
||||
|
||||
int currentSettingIndex = -1;
|
||||
|
||||
if (c == null) {
|
||||
// Something went wrong when querying calendars
|
||||
// Let's keep the "Astrid default" only.
|
||||
listPreference
|
||||
.setEntries(new String[] { r
|
||||
.getString(R.string.prefs_defaultCalendar_astrid_default) });
|
||||
listPreference.setEntryValues(new String[] { r
|
||||
.getString(R.string.prefs_defaultCalendar_default) });
|
||||
listPreference.setValueIndex(0);
|
||||
listPreference.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int calendarCount = c.getCount();
|
||||
|
||||
String[] entries = new String[calendarCount];
|
||||
String[] entryValues = new String[calendarCount];
|
||||
|
||||
|
||||
// Iterate calendars one by one, and fill up the list preference
|
||||
try {
|
||||
int row = 0;
|
||||
int idColumn = c.getColumnIndex(ID_COLUMN_NAME);
|
||||
int nameColumn = c.getColumnIndex(DISPLAY_COLUMN_NAME);
|
||||
while (c.moveToNext()) {
|
||||
String id = c.getString(idColumn);
|
||||
String name = c.getString(nameColumn);
|
||||
entries[row] = name;
|
||||
entryValues[row] = id;
|
||||
|
||||
// We found currently selected calendar
|
||||
if (currentSetting.equals(id)) {
|
||||
currentSettingIndex = row;
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
if (currentSettingIndex == -1) {
|
||||
// Should not happen!
|
||||
// Let's keep the "Astrid default" only.
|
||||
Log.d("astrid", "initCalendarsPreference: Unknown calendar.");
|
||||
listPreference
|
||||
.setEntries(new String[] { r
|
||||
.getString(R.string.prefs_defaultCalendar_astrid_default) });
|
||||
listPreference.setEntryValues(new String[] { r
|
||||
.getString(R.string.prefs_defaultCalendar_default) });
|
||||
listPreference.setValueIndex(0);
|
||||
listPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
listPreference.setEntries(entries);
|
||||
listPreference.setEntryValues(entryValues);
|
||||
|
||||
listPreference.setValueIndex(currentSettingIndex);
|
||||
listPreference.setEnabled(true);
|
||||
|
||||
} finally {
|
||||
c.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether user-modifiable calendar is present with a given id.
|
||||
*
|
||||
* @param context
|
||||
* Context
|
||||
* @param id
|
||||
* Calendar ID to search for
|
||||
* @return true, if user-modifiable calendar with the given id exists; false
|
||||
* otherwise.
|
||||
*/
|
||||
private static boolean isCalendarPresent(Context context, String id) {
|
||||
if (id == null)
|
||||
return false;
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Cursor c = null;
|
||||
|
||||
try {
|
||||
c = cr.query(CALENDAR_CONTENT_URI, CALENDARS_PROJECTION,
|
||||
CALENDARS_WHERE_ID, new String[] { id }, CALENDARS_SORT);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
return (c != null) && (c.getCount() != 0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue