mirror of https://github.com/tasks/tasks
Merge Sam's 121009_sb_calendar_assistant branch
commit
759b0f427c
@ -0,0 +1,230 @@
|
||||
package com.todoroo.astrid.gcal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.data.TodorooCursor;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.andlib.sql.Query;
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
||||
import com.todoroo.astrid.activity.EditPreferences;
|
||||
import com.todoroo.astrid.activity.TaskListActivity;
|
||||
import com.todoroo.astrid.activity.TaskListFragment;
|
||||
import com.todoroo.astrid.dao.UserDao;
|
||||
import com.todoroo.astrid.data.TagData;
|
||||
import com.todoroo.astrid.data.User;
|
||||
import com.todoroo.astrid.service.TagDataService;
|
||||
import com.todoroo.astrid.service.ThemeService;
|
||||
|
||||
public class CalendarAlarmListCreator extends Activity {
|
||||
|
||||
public static final String TOKEN_LIST_NAME = "listName"; //$NON-NLS-1$
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
private TagDataService tagDataService;
|
||||
|
||||
@Autowired
|
||||
private ActFmPreferenceService actFmPreferenceService;
|
||||
|
||||
private ArrayList<String> names;
|
||||
private ArrayList<String> emails;
|
||||
private HashMap<String, User> emailsToUsers;
|
||||
|
||||
private String tagName;
|
||||
private TextView inviteAll;
|
||||
private TextView moreOptions;
|
||||
private TextView ignoreButton;
|
||||
private View dismissButton;
|
||||
private View ignoreSettingsButton;
|
||||
|
||||
private final OnClickListener dismissListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TagData tagData = new TagData();
|
||||
tagData.setValue(TagData.NAME, tagName);
|
||||
tagDataService.save(tagData);
|
||||
dismissWithAnimation();
|
||||
}
|
||||
};
|
||||
|
||||
private void dismissWithAnimation() {
|
||||
finish();
|
||||
AndroidUtilities.callOverridePendingTransition(CalendarAlarmListCreator.this, 0, android.R.anim.fade_out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
setContentView(R.layout.calendar_alarm_list_creator);
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
tagName = intent.getStringExtra(TOKEN_LIST_NAME);
|
||||
inviteAll = (TextView) findViewById(R.id.invite_all);
|
||||
moreOptions = (TextView) findViewById(R.id.list_settings);
|
||||
ignoreButton = (TextView) findViewById(R.id.ignore);
|
||||
dismissButton = findViewById(R.id.dismiss);
|
||||
ignoreSettingsButton = findViewById(R.id.ignore_settings);
|
||||
emails = intent.getStringArrayListExtra(CalendarReminderActivity.TOKEN_EMAILS);
|
||||
names = intent.getStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES);
|
||||
|
||||
initializeUserMap();
|
||||
|
||||
setupUi();
|
||||
|
||||
addListeners();
|
||||
}
|
||||
|
||||
private void initializeUserMap() {
|
||||
emailsToUsers = new HashMap<String, User>();
|
||||
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES).where(User.EMAIL.in(emails.toArray(new String[emails.size()]))));
|
||||
try {
|
||||
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
|
||||
User u = new User(users);
|
||||
emailsToUsers.put(u.getValue(User.EMAIL), u);
|
||||
}
|
||||
} finally {
|
||||
users.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupUi() {
|
||||
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
|
||||
StringBuilder builder = new StringBuilder(getString(R.string.CRA_created_list_dialog, tagName));
|
||||
String attendeesString = buildAttendeesString();
|
||||
int color = ThemeService.getThemeColor();
|
||||
|
||||
String title;
|
||||
if (!TextUtils.isEmpty(attendeesString)) {
|
||||
builder.append(" ") //$NON-NLS-1$
|
||||
.append(attendeesString)
|
||||
.append(" ") //$NON-NLS-1$
|
||||
.append(getString(R.string.CRA_invitation_prompt));
|
||||
inviteAll.setBackgroundColor(getResources().getColor(color));
|
||||
title = getString(R.string.CRA_share_list_title);
|
||||
} else {
|
||||
title = getString(R.string.CRA_list_created_title);
|
||||
moreOptions.setBackgroundColor(getResources().getColor(color));
|
||||
inviteAll.setVisibility(View.GONE);
|
||||
ignoreButton.setVisibility(View.GONE);
|
||||
ignoreSettingsButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
((TextView) findViewById(R.id.reminder_title))
|
||||
.setText(title);
|
||||
|
||||
dialogView.setText(builder.toString());
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
ignoreButton.setOnClickListener(dismissListener);
|
||||
dismissButton.setOnClickListener(dismissListener);
|
||||
|
||||
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent editPreferences = new Intent(CalendarAlarmListCreator.this, EditPreferences.class);
|
||||
startActivity(editPreferences);
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
});
|
||||
|
||||
inviteAll.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Set members json and save
|
||||
if (!actFmPreferenceService.isLoggedIn()) {
|
||||
moreOptions.performClick();
|
||||
return;
|
||||
} else {
|
||||
JSONArray membersArray = buildMembersArray();
|
||||
TagData tagData = new TagData();
|
||||
tagData.setValue(TagData.NAME, tagName);
|
||||
tagData.setValue(TagData.MEMBERS, membersArray.toString());
|
||||
tagData.setValue(TagData.MEMBER_COUNT, membersArray.length());
|
||||
tagDataService.save(tagData);
|
||||
dismissWithAnimation();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
moreOptions.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(CalendarAlarmListCreator.this, TaskListActivity.class);
|
||||
intent.putExtra(TaskListFragment.TOKEN_NEW_LIST_NAME, tagName);
|
||||
intent.putExtra(TaskListFragment.TOKEN_NEW_LIST_MEMBERS, buildMembersArray().toString());
|
||||
intent.putExtra(TaskListFragment.TOKEN_NEW_LIST, true);
|
||||
startActivity(intent);
|
||||
dismissWithAnimation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String buildAttendeesString() {
|
||||
if (emails.size() == 0) {
|
||||
return ""; //$NON-NLS-1$
|
||||
} else if (emails.size() == 1) {
|
||||
String displayName = getDisplayName(0);
|
||||
return getString(R.string.CRA_one_attendee, displayName);
|
||||
} else { // emails.size() >= 2
|
||||
String displayName1 = getDisplayName(0);
|
||||
String displayName2 = getDisplayName(1);
|
||||
|
||||
int extras = emails.size() - 2;
|
||||
if (extras > 0)
|
||||
return getString(R.string.CRA_many_attendees, displayName1, displayName2, extras);
|
||||
else
|
||||
return getString(R.string.CRA_two_attendees, displayName1, displayName2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JSONArray buildMembersArray() {
|
||||
JSONArray array = new JSONArray();
|
||||
for (String email : emails) {
|
||||
JSONObject member = new JSONObject();
|
||||
try {
|
||||
member.put("email", email); //$NON-NLS-1$
|
||||
array.put(member);
|
||||
} catch (JSONException e) {
|
||||
Log.e(CalendarAlarmScheduler.TAG, "Error creating json member " + email, e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private String getDisplayName(int index) {
|
||||
String name = names.get(index);
|
||||
if (!TextUtils.isEmpty(name))
|
||||
return name;
|
||||
String email = emails.get(index);
|
||||
if (emailsToUsers.containsKey(email)) {
|
||||
User u = emailsToUsers.get(email);
|
||||
String userName = u.getValue(User.NAME);
|
||||
if (!TextUtils.isEmpty(userName))
|
||||
return userName;
|
||||
}
|
||||
return email;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,154 @@
|
||||
package com.todoroo.astrid.gcal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class CalendarAlarmReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final int REQUEST_CODE_CAL_REMINDER = 100;
|
||||
public static final String BROADCAST_CALENDAR_REMINDER = Constants.PACKAGE + ".CALENDAR_EVENT";
|
||||
|
||||
private static final String[] EVENTS_PROJECTION = {
|
||||
Calendars.EVENTS_DTSTART_COL,
|
||||
Calendars.EVENTS_DTEND_COL,
|
||||
Calendars.EVENTS_NAME_COL,
|
||||
};
|
||||
|
||||
private static final String[] ATTENDEES_PROJECTION = {
|
||||
Calendars.ATTENDEES_NAME_COL,
|
||||
Calendars.ATTENDEES_EMAIL_COL,
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!Preferences.getBoolean(R.string.p_calendar_reminders, true))
|
||||
return;
|
||||
try {
|
||||
Uri data = intent.getData();
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
String uriString = data.toString();
|
||||
int pathIndex = uriString.indexOf("://");
|
||||
if (pathIndex > 0)
|
||||
pathIndex += 3;
|
||||
else return;
|
||||
long eventId = Long.parseLong(uriString.substring(pathIndex));
|
||||
boolean fromPostpone = CalendarAlarmScheduler.URI_PREFIX_POSTPONE.equals(data.getScheme());
|
||||
if (eventId > 0) {
|
||||
showCalReminder(context, eventId, fromPostpone);
|
||||
}
|
||||
} catch (IllegalArgumentException e) { // Some cursor read failed, or badly formed uri
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void showCalReminder(Context context,
|
||||
long eventId, boolean fromPostpone) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
|
||||
|
||||
String[] eventArg = new String[] { Long.toString(eventId) };
|
||||
Cursor event = cr.query(eventUri,
|
||||
EVENTS_PROJECTION,
|
||||
Calendars.ID_COLUMN_NAME + " = ?",
|
||||
eventArg,
|
||||
null);
|
||||
try {
|
||||
if (event.moveToFirst()) {
|
||||
int dtstartIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
|
||||
int dtendIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTEND_COL);
|
||||
int titleIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_NAME_COL);
|
||||
|
||||
String title = event.getString(titleIndex);
|
||||
long startTime = event.getLong(dtstartIndex);
|
||||
long endTime = event.getLong(dtendIndex);
|
||||
|
||||
boolean shouldShowReminder;
|
||||
if (fromPostpone) {
|
||||
long timeAfter = DateUtilities.now() - endTime;
|
||||
shouldShowReminder = (timeAfter > DateUtilities.ONE_MINUTE * 2);
|
||||
} else {
|
||||
long timeUntil = startTime - DateUtilities.now();
|
||||
shouldShowReminder = (timeUntil > 0 && timeUntil < DateUtilities.ONE_MINUTE * 20);
|
||||
}
|
||||
|
||||
if (shouldShowReminder) {
|
||||
// Get attendees
|
||||
Cursor attendees = cr.query(Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_ATTENDEES),
|
||||
ATTENDEES_PROJECTION,
|
||||
Calendars.ATTENDEES_EVENT_ID_COL + " = ? ",
|
||||
eventArg,
|
||||
null);
|
||||
try {
|
||||
// Do something with attendees
|
||||
int emailIndex = attendees.getColumnIndexOrThrow(Calendars.ATTENDEES_EMAIL_COL);
|
||||
int nameIndex = attendees.getColumnIndexOrThrow(Calendars.ATTENDEES_NAME_COL);
|
||||
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
ArrayList<String> emails = new ArrayList<String>();
|
||||
|
||||
Account[] accountArray = AccountManager.get(context).getAccounts();
|
||||
Set<String> phoneAccounts = new HashSet<String>();
|
||||
for (Account a : accountArray) {
|
||||
phoneAccounts.add(a.name);
|
||||
}
|
||||
String astridUser = ActFmPreferenceService.thisUser().optString("email");
|
||||
if (!TextUtils.isEmpty(astridUser))
|
||||
phoneAccounts.add(astridUser);
|
||||
|
||||
for (attendees.moveToFirst(); !attendees.isAfterLast(); attendees.moveToNext()) {
|
||||
String name = attendees.getString(nameIndex);
|
||||
String email = attendees.getString(emailIndex);
|
||||
if (!TextUtils.isEmpty(email)) {
|
||||
if (phoneAccounts.contains(email))
|
||||
continue;
|
||||
if (Constants.DEBUG)
|
||||
Log.w(CalendarAlarmScheduler.TAG, "Attendee: " + name + ", email: " + email);
|
||||
names.add(name);
|
||||
emails.add(email);
|
||||
}
|
||||
}
|
||||
|
||||
if (emails.size() > 0) {
|
||||
Intent reminderActivity = new Intent(context, CalendarReminderActivity.class);
|
||||
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES, names);
|
||||
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_EMAILS, emails);
|
||||
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_ID, eventId);
|
||||
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_NAME, title);
|
||||
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_START_TIME, startTime);
|
||||
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_END_TIME, endTime);
|
||||
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, fromPostpone);
|
||||
reminderActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
context.startActivity(reminderActivity);
|
||||
}
|
||||
} finally {
|
||||
attendees.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
event.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.todoroo.astrid.gcal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class CalendarAlarmScheduler {
|
||||
|
||||
public static final String TAG = "calendar-alarm";
|
||||
|
||||
public static final String URI_PREFIX = "cal-reminder";
|
||||
public static final String URI_PREFIX_POSTPONE = "cal-postpone";
|
||||
|
||||
public static void scheduleAllCalendarAlarms(Context context) {
|
||||
if (!Preferences.getBoolean(R.string.p_calendar_reminders, true))
|
||||
return;
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
|
||||
long now = DateUtilities.now();
|
||||
|
||||
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
Cursor events = cr.query(Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS),
|
||||
new String[] { Calendars.ID_COLUMN_NAME, Calendars.EVENTS_DTSTART_COL },
|
||||
Calendars.EVENTS_DTSTART_COL + " > ? AND " + Calendars.EVENTS_DTSTART_COL + " < ?",
|
||||
new String[] { Long.toString(now + DateUtilities.ONE_MINUTE * 20), Long.toString(now + DateUtilities.ONE_DAY) },
|
||||
null);
|
||||
try {
|
||||
if (events.getCount() > 0) {
|
||||
int idIndex = events.getColumnIndex(Calendars.ID_COLUMN_NAME);
|
||||
int dtstartIndex = events.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
|
||||
|
||||
for (events.moveToFirst(); !events.isAfterLast(); events.moveToNext()) {
|
||||
Intent eventAlarm = new Intent(context, CalendarAlarmReceiver.class);
|
||||
eventAlarm.setAction(CalendarAlarmReceiver.BROADCAST_CALENDAR_REMINDER);
|
||||
|
||||
long start = events.getLong(dtstartIndex);
|
||||
long id = events.getLong(idIndex);
|
||||
|
||||
eventAlarm.setData(Uri.parse(URI_PREFIX + "://" + id));
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
|
||||
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, eventAlarm, 0);
|
||||
|
||||
am.cancel(pendingIntent);
|
||||
|
||||
long alarmTime = start - DateUtilities.ONE_MINUTE * 15;
|
||||
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingIntent);
|
||||
|
||||
if (Constants.DEBUG)
|
||||
Log.w(TAG, "Scheduling calendar alarm for " + new Date(alarmTime));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Schedule alarm to recheck and reschedule calendar alarms in 12 hours
|
||||
Intent rescheduleAlarm = new Intent(CalendarStartupReceiver.BROADCAST_RESCHEDULE_CAL_ALARMS);
|
||||
PendingIntent pendingReschedule = PendingIntent.getBroadcast(context, 0,
|
||||
rescheduleAlarm, 0);
|
||||
am.cancel(pendingReschedule);
|
||||
am.set(AlarmManager.RTC, DateUtilities.now() + DateUtilities.ONE_HOUR * 12, pendingReschedule);
|
||||
} finally {
|
||||
events.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,249 @@
|
||||
package com.todoroo.astrid.gcal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.andlib.utility.DialogUtilities;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.activity.EditPreferences;
|
||||
import com.todoroo.astrid.activity.TaskListActivity;
|
||||
import com.todoroo.astrid.activity.TaskListFragment;
|
||||
import com.todoroo.astrid.api.FilterWithCustomIntent;
|
||||
import com.todoroo.astrid.data.TagData;
|
||||
import com.todoroo.astrid.service.StartupService;
|
||||
import com.todoroo.astrid.service.TagDataService;
|
||||
import com.todoroo.astrid.service.ThemeService;
|
||||
import com.todoroo.astrid.tags.TagFilterExposer;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class CalendarReminderActivity extends Activity {
|
||||
|
||||
public static final String TOKEN_NAMES = "names";
|
||||
public static final String TOKEN_EMAILS = "emails";
|
||||
public static final String TOKEN_EVENT_ID = "eventId";
|
||||
public static final String TOKEN_EVENT_NAME = "eventName";
|
||||
public static final String TOKEN_EVENT_START_TIME = "eventStartTime";
|
||||
public static final String TOKEN_EVENT_END_TIME = "eventEndTime";
|
||||
|
||||
public static final String TOKEN_FROM_POSTPONE = "fromPostpone";
|
||||
|
||||
private static final String PREF_IGNORE_PRESSES = "calEventsIgnored";
|
||||
|
||||
// Prompt user to ignore all missed calls after this many ignore presses
|
||||
private static final int IGNORE_PROMPT_COUNT = 3;
|
||||
|
||||
@Autowired
|
||||
private TagDataService tagDataService;
|
||||
|
||||
private String eventName;
|
||||
private long startTime;
|
||||
private long endTime;
|
||||
private long eventId;
|
||||
|
||||
private boolean fromPostpone;
|
||||
|
||||
private TextView ignoreButton;
|
||||
private TextView createListButton;
|
||||
private TextView postponeButton;
|
||||
private View dismissButton;
|
||||
private View ignoreSettingsButton;
|
||||
|
||||
private final OnClickListener dismissListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
AndroidUtilities.callOverridePendingTransition(CalendarReminderActivity.this, 0, android.R.anim.fade_out);
|
||||
}
|
||||
};
|
||||
|
||||
private final OnClickListener ignoreListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
// Check for number of ignore presses
|
||||
int ignorePresses = Preferences.getInt(PREF_IGNORE_PRESSES, 0);
|
||||
ignorePresses++;
|
||||
if (ignorePresses == IGNORE_PROMPT_COUNT) {
|
||||
DialogUtilities.okCancelCustomDialog(CalendarReminderActivity.this,
|
||||
getString(R.string.CRA_ignore_title),
|
||||
getString(R.string.CRA_ignore_body),
|
||||
R.string.CRA_ignore_all,
|
||||
R.string.CRA_ignore_this,
|
||||
0,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Preferences.setBoolean(R.string.p_calendar_reminders, false);
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
},
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
Preferences.setInt(PREF_IGNORE_PRESSES, ignorePresses);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
new StartupService().onStartupApplication(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
|
||||
setContentView(R.layout.calendar_reminder_activity);
|
||||
|
||||
|
||||
Intent intent = getIntent();
|
||||
fromPostpone = intent.getBooleanExtra(TOKEN_FROM_POSTPONE, false);
|
||||
eventId = intent.getLongExtra(TOKEN_EVENT_ID, -1);
|
||||
eventName = intent.getStringExtra(TOKEN_EVENT_NAME);
|
||||
startTime = intent.getLongExtra(TOKEN_EVENT_START_TIME, DateUtilities.now());
|
||||
endTime = intent.getLongExtra(TOKEN_EVENT_END_TIME, DateUtilities.now() + DateUtilities.ONE_HOUR);
|
||||
|
||||
createListButton = (TextView) findViewById(R.id.create_list);
|
||||
postponeButton = (TextView) findViewById(R.id.postpone);
|
||||
ignoreButton = (TextView) findViewById(R.id.ignore);
|
||||
ignoreSettingsButton = findViewById(R.id.ignore_settings);
|
||||
dismissButton = findViewById(R.id.dismiss);
|
||||
|
||||
setupUi();
|
||||
|
||||
addListeners();
|
||||
}
|
||||
|
||||
private void setupUi() {
|
||||
((TextView) findViewById(R.id.reminder_title))
|
||||
.setText(getString(R.string.CRA_title));
|
||||
|
||||
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
|
||||
String speechText;
|
||||
if (fromPostpone)
|
||||
speechText = getString(R.string.CRA_speech_bubble_end, eventName);
|
||||
else
|
||||
speechText = getString(R.string.CRA_speech_bubble_start, eventName);
|
||||
|
||||
dialogView.setText(speechText);
|
||||
|
||||
createListButton.setBackgroundColor(getResources().getColor(ThemeService.getThemeColor()));
|
||||
|
||||
if (fromPostpone)
|
||||
postponeButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
ignoreButton.setOnClickListener(ignoreListener);
|
||||
dismissButton.setOnClickListener(dismissListener);
|
||||
|
||||
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent editPreferences = new Intent(CalendarReminderActivity.this, EditPreferences.class);
|
||||
startActivity(editPreferences);
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
});
|
||||
|
||||
if (!fromPostpone)
|
||||
postponeButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
postpone();
|
||||
}
|
||||
});
|
||||
|
||||
createListButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String listName = getString(R.string.CRA_default_list_name, eventName);
|
||||
TagData existing = tagDataService.getTag(listName, TagData.PROPERTIES);
|
||||
if (existing != null) {
|
||||
listExists(existing);
|
||||
} else {
|
||||
createNewList(listName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void listExists(final TagData tag) {
|
||||
DialogUtilities.okCancelCustomDialog(this,
|
||||
getString(R.string.CRA_list_exists_title),
|
||||
getString(R.string.CRA_list_exists_body, tag.getValue(TagData.NAME)),
|
||||
R.string.CRA_create_new,
|
||||
R.string.CRA_use_existing,
|
||||
0,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
createNewList(tag.getValue(TagData.NAME) + " "
|
||||
+ DateUtilities.getDateStringHideYear(CalendarReminderActivity.this, new Date(startTime)));
|
||||
}
|
||||
},
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FilterWithCustomIntent filter = TagFilterExposer.filterFromTagData(CalendarReminderActivity.this, tag);
|
||||
|
||||
Intent listIntent = new Intent(CalendarReminderActivity.this, TaskListActivity.class);
|
||||
listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
|
||||
listIntent.putExtras(filter.customExtras);
|
||||
|
||||
startActivity(listIntent);
|
||||
dismissButton.performClick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createNewList(String name) {
|
||||
Intent newListIntent = new Intent(this, CalendarAlarmListCreator.class);
|
||||
newListIntent.putStringArrayListExtra(TOKEN_NAMES, getIntent().getStringArrayListExtra(TOKEN_NAMES));
|
||||
newListIntent.putStringArrayListExtra(TOKEN_EMAILS, getIntent().getStringArrayListExtra(TOKEN_EMAILS));
|
||||
newListIntent.putExtra(CalendarAlarmListCreator.TOKEN_LIST_NAME, name);
|
||||
|
||||
startActivity(newListIntent);
|
||||
dismissButton.performClick(); // finish with animation
|
||||
}
|
||||
|
||||
private void postpone() {
|
||||
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
|
||||
Intent eventAlarm = new Intent(this, CalendarAlarmReceiver.class);
|
||||
eventAlarm.setAction(CalendarAlarmReceiver.BROADCAST_CALENDAR_REMINDER);
|
||||
eventAlarm.setData(Uri.parse(CalendarAlarmScheduler.URI_PREFIX_POSTPONE + "://" + eventId));
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
|
||||
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, eventAlarm, 0);
|
||||
|
||||
am.cancel(pendingIntent);
|
||||
|
||||
long alarmTime = endTime + DateUtilities.ONE_MINUTE * 5;
|
||||
if (Constants.DEBUG)
|
||||
Log.w(CalendarAlarmScheduler.TAG, "Scheduling calendar alarm for " + new Date(alarmTime));
|
||||
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingIntent);
|
||||
dismissButton.performClick();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.todoroo.astrid.gcal;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
|
||||
public class CalendarStartupReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String BROADCAST_RESCHEDULE_CAL_ALARMS = AstridApiConstants.PACKAGE + ".SCHEDULE_CAL_REMINDERS"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ContextManager.setContext(context);
|
||||
scheduleCalendarAlarms(context);
|
||||
}
|
||||
|
||||
public static void scheduleCalendarAlarms(final Context context) {
|
||||
if (!Preferences.getBoolean(R.string.p_calendar_reminders, true))
|
||||
return;
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CalendarAlarmScheduler.scheduleAllCalendarAlarms(context);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/reminder_dialog_background">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="15dip"
|
||||
android:layout_marginLeft="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="1dip"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/CRA_share_list_title"/>
|
||||
<ImageView
|
||||
android:id="@+id/dismiss"
|
||||
android:layout_width="25dip"
|
||||
android:layout_height="25dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_menu_close"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/calendar_reminder_speech_bubble"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<include layout="@layout/astrid_speech_bubble" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/invite_all"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/CRA_invite_attendees"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/list_settings"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:background="#707070"
|
||||
android:text="@string/CRA_more_options"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ignore"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/CRA_dont_invite"
|
||||
android:background="#707070"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ignore_settings"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_width="35dip"
|
||||
android:layout_height="35dip"
|
||||
android:padding="4dip"
|
||||
android:background="@android:color/transparent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/single_gear"/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/reminder_dialog_background">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="15dip"
|
||||
android:layout_marginLeft="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="1dip"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/CRA_title"/>
|
||||
<ImageView
|
||||
android:id="@+id/dismiss"
|
||||
android:layout_width="25dip"
|
||||
android:layout_height="25dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_menu_close"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/calendar_reminder_speech_bubble"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<include layout="@layout/astrid_speech_bubble" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/create_list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/CRA_create_list"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/postpone"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:background="#707070"
|
||||
android:text="@string/CRA_postpone"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ignore"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/CRA_ignore"
|
||||
android:background="#707070"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ignore_settings"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_width="35dip"
|
||||
android:layout_height="35dip"
|
||||
android:padding="4dip"
|
||||
android:background="@android:color/transparent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/single_gear"/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<include layout="@layout/astrid_calendar_list_creator_view"/>
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<include layout="@layout/astrid_calendar_reminder_view"/>
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue