diff --git a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java index 5e4ad180c..3f69986f0 100644 --- a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java +++ b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java @@ -89,6 +89,7 @@ public class C2DMReceiver extends BroadcastReceiver { notifyIntent = ShortcutActivity.createIntent(CoreFilterExposer.buildInboxFilter(context.getResources())); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_C2DM); PendingIntent pendingIntent = PendingIntent.getActivity(context, Constants.NOTIFICATION_ACTFM, notifyIntent, 0); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java index dd8a4793b..76e720592 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java @@ -63,6 +63,7 @@ import com.todoroo.astrid.actfm.sync.ActFmInvoker; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.gtasks.auth.ModernAuthManager; import com.todoroo.astrid.service.AstridDependencyInjector; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TaskService; /** @@ -162,6 +163,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { public void onClick(DialogInterface dialog, int which) { authenticate(email.getText().toString(), name.getText().toString(), ActFmInvoker.PROVIDER_PASSWORD, password.getText().toString()); + StatisticsService.reportEvent("actfm-signup-pw"); //$NON-NLS-1$ } }) .setNegativeButton(android.R.string.cancel, null) @@ -197,6 +199,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { public void onClick(DialogInterface dialog, int which) { authenticate(email.getText().toString(), null, ActFmInvoker.PROVIDER_PASSWORD, password.getText().toString()); + StatisticsService.reportEvent("actfm-login-pw"); //$NON-NLS-1$ } }) .setNegativeButton(android.R.string.cancel, null) @@ -253,6 +256,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { authenticate(email, name, ActFmInvoker.PROVIDER_FACEBOOK, facebook.getAccessToken()); + StatisticsService.reportEvent("actfm-login-fb"); //$NON-NLS-1$ } catch (FacebookError e) { handleError(e); } catch (JSONException e) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleActivity.java index 20e5efb02..7ebeed39f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleActivity.java @@ -43,6 +43,7 @@ import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.MetadataService; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.ThemeService; @@ -452,10 +453,11 @@ public class EditPeopleActivity extends Activity { int count = result.optInt("shared", 0); final String toast; - if(count > 0) + if(count > 0) { toast = getString(R.string.actfm_EPA_emailed_toast, getResources().getQuantityString(R.plurals.Npeople, count, count)); - else + StatisticsService.reportEvent("actfm-task-shared"); //$NON-NLS-1$ + } else toast = getString(R.string.actfm_EPA_saved_toast); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java index 0af837fff..0a46379ea 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java @@ -64,6 +64,7 @@ import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Update; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.ui.PeopleContainer; @@ -621,6 +622,8 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList addCommentField.setText(""); //$NON-NLS-1$ refreshUpdatesList(); + + StatisticsService.reportEvent("actfm-tag-comment"); //$NON-NLS-1$ } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java index 706bd1e65..2536144a5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java @@ -29,6 +29,7 @@ import com.todoroo.astrid.actfm.ActFmLoginActivity; import com.todoroo.astrid.actfm.ActFmPreferences; import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper; import com.todoroo.astrid.api.AstridApiConstants; +import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.notes.NoteMetadata; @@ -277,6 +278,13 @@ public class ActFmSyncProvider extends SyncProvider { @Override protected void write(ActFmTaskContainer task) throws IOException { + if(task.task.isSaved()) { + Task local = PluginServices.getTaskService().fetchById(task.task.getId(), Task.COMPLETION_DATE); + if(task.task.isCompleted() && !local.isCompleted()) + StatisticsService.reportEvent("actfm-task-completed"); //$NON-NLS-1$ + } else { + StatisticsService.reportEvent("actfm-task-created"); //$NON-NLS-1$ + } actFmDataService.saveTaskAndMetadata(task); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index cdeaa6531..aa98de41c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -49,6 +49,7 @@ import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; import com.todoroo.astrid.service.MetadataService; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.tags.TagService; @@ -464,6 +465,14 @@ public final class ActFmSyncService { readIds(locals, item, remote); JsonHelper.taskFromJson(item, remote, metadata); + if(remote.getValue(Task.USER_ID) == 0) { + if(!remote.isSaved()) + StatisticsService.reportEvent("actfm-task-created"); + else if(remote.isCompleted()) + StatisticsService.reportEvent("actfm-task-completed"); + } + + Flags.set(Flags.SUPPRESS_SYNC); taskService.save(remote); metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagService.KEY)); diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java index b3a70a080..dc9ae096a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java @@ -48,6 +48,7 @@ import com.todoroo.astrid.api.TextInputCriterion; import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.service.StatisticsService; /** * Activity that allows users to build custom filters @@ -237,6 +238,18 @@ public class CustomFilterActivity extends ListActivity { } } + @Override + protected void onStart() { + super.onStart(); + StatisticsService.sessionStart(this); + } + + @Override + protected void onStop() { + StatisticsService.sessionStop(this); + super.onStop(); + } + @Override protected void onResume() { super.onResume(); @@ -246,6 +259,7 @@ public class CustomFilterActivity extends ListActivity { @Override protected void onPause() { + StatisticsService.sessionPause(); super.onPause(); unregisterReceiver(filterCriteriaReceiver); } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java index 9708d44e5..8e39f8a1f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java @@ -547,8 +547,12 @@ public class GtasksSyncProvider extends SyncProvider { protected void write(GtasksTaskContainer task) throws IOException { // merge astrid dates with google dates if(task.task.isSaved()) { - Task local = PluginServices.getTaskService().fetchById(task.task.getId(), Task.DUE_DATE); + Task local = PluginServices.getTaskService().fetchById(task.task.getId(), Task.DUE_DATE, Task.COMPLETION_DATE); mergeDates(task.task, local); + if(task.task.isCompleted() && !local.isCompleted()) + StatisticsService.reportEvent("gtasks-task-completed"); //$NON-NLS-1$ + } else { + StatisticsService.reportEvent("gtasks-task-created"); //$NON-NLS-1$ } gtasksMetadataService.saveTaskAndMetadata(task); diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index f3ac43346..358c52e09 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -47,6 +47,7 @@ import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; import com.todoroo.astrid.service.MetadataService; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.utility.Flags; public class EditNoteActivity extends ListActivity { @@ -236,6 +237,8 @@ public class EditNoteActivity extends ListActivity { commentField.setText(""); //$NON-NLS-1$ setUpListAdapter(); + + StatisticsService.reportEvent("actfm-task-comment"); //$NON-NLS-1$ } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java index c438b5f51..a887879e2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java @@ -33,6 +33,7 @@ import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.ShortcutActivity; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; +import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; @@ -615,6 +616,13 @@ public class ProducteevSyncProvider extends SyncProvider 0) return; + StatisticsService.reportEvent("task-repeat"); //$NON-NLS-1$ + String recurrence = task.getValue(Task.RECURRENCE); if(recurrence != null && recurrence.length() > 0) { long newDueDate; diff --git a/astrid/plugin-src/com/todoroo/astrid/timers/TimerPlugin.java b/astrid/plugin-src/com/todoroo/astrid/timers/TimerPlugin.java index 462d07b50..1b8100408 100644 --- a/astrid/plugin-src/com/todoroo/astrid/timers/TimerPlugin.java +++ b/astrid/plugin-src/com/todoroo/astrid/timers/TimerPlugin.java @@ -19,6 +19,7 @@ import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.utility.Constants; public class TimerPlugin extends BroadcastReceiver { @@ -44,14 +45,17 @@ public class TimerPlugin extends BroadcastReceiver { */ public static void updateTimer(Context context, Task task, boolean start) { if(start) { - if(task.getValue(Task.TIMER_START) == 0) + if(task.getValue(Task.TIMER_START) == 0) { task.setValue(Task.TIMER_START, DateUtilities.now()); + StatisticsService.reportEvent("timer-start"); //$NON-NLS-1$ + } } else { if(task.getValue(Task.TIMER_START) > 0) { int newElapsed = (int)((DateUtilities.now() - task.getValue(Task.TIMER_START)) / 1000L); task.setValue(Task.TIMER_START, 0L); task.setValue(Task.ELAPSED_SECONDS, task.getValue(Task.ELAPSED_SECONDS) + newElapsed); + StatisticsService.reportEvent("timer-stop"); //$NON-NLS-1$ } } PluginServices.getTaskService().save(task); diff --git a/astrid/src/com/todoroo/astrid/activity/Eula.java b/astrid/src/com/todoroo/astrid/activity/Eula.java index cd065a8cb..69c3b58f3 100644 --- a/astrid/src/com/todoroo/astrid/activity/Eula.java +++ b/astrid/src/com/todoroo/astrid/activity/Eula.java @@ -26,6 +26,7 @@ import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.service.StartupService; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TaskService; /** @@ -95,6 +96,7 @@ public final class Eula { @SuppressWarnings("unused") private static void accept(Activity activity) { Preferences.setBoolean(PREFERENCE_EULA_ACCEPTED, true); + StatisticsService.reportEvent("eula-accepted"); //$NON-NLS-1$ } private static void refuse(Activity activity) { diff --git a/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java b/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java index 3727ac0be..e8b7ab48b 100644 --- a/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java @@ -241,9 +241,11 @@ public class FilterListActivity extends ExpandableListActivity { AndroidUtilities.callApiMethod(5, this, "overridePendingTransition", //$NON-NLS-1$ new Class[] { Integer.TYPE, Integer.TYPE }, R.anim.slide_left_in, R.anim.slide_left_out); + StatisticsService.reportEvent("filter-list"); //$NON-NLS-1$ return true; } else if(item instanceof SearchFilter) { onSearchRequested(); + StatisticsService.reportEvent("filter-search"); //$NON-NLS-1$ } else if(item instanceof IntentFilter) { try { ((IntentFilter)item).intent.send(); diff --git a/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java b/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java index 668db878b..04fec0399 100644 --- a/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java @@ -87,6 +87,9 @@ public class ShortcutActivity extends Activity { Intent taskListIntent = new Intent(this, TaskListActivity.class); + if(extras != null && extras.containsKey(TaskListActivity.TOKEN_SOURCE)) + taskListIntent.putExtra(TaskListActivity.TOKEN_SOURCE, extras.getInt(TaskListActivity.TOKEN_SOURCE)); + if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) { taskListIntent.setComponent(ComponentName.unflattenFromString(extras.getString(TOKEN_CUSTOM_CLASS))); taskListIntent.putExtras(intent.getExtras()); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index a7833dda6..3e1a1a931 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -69,6 +69,7 @@ import com.todoroo.andlib.widget.GestureService; import com.todoroo.andlib.widget.GestureService.GestureInterface; import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener; import com.todoroo.astrid.adapter.TaskAdapter; +import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener; import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; @@ -141,6 +142,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, /** token for passing a {@link Filter} object through extras */ public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$ + /** token for indicating source of TLA launch */ + public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$ + // --- instance variables @Autowired ExceptionService exceptionService; @@ -172,7 +176,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, private EditText quickAddBox; private Timer backgroundTimer; private final LinkedHashSet syncActions = new LinkedHashSet(); - + private boolean isInbox; private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); private VoiceInputAssistant voiceInputAssistant; @@ -218,6 +222,26 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, onNewIntent(getIntent()); Eula.showEula(this); + + if(getIntent().hasExtra(TOKEN_SOURCE)) { + switch(getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT)) { + case Constants.SOURCE_NOTIFICATION: + StatisticsService.reportEvent("launch-from-notification"); //$NON-NLS-1$ + break; + case Constants.SOURCE_OTHER: + StatisticsService.reportEvent("launch-from-other"); //$NON-NLS-1$ + break; + case Constants.SOURCE_PPWIDGET: + StatisticsService.reportEvent("launch-from-ppw"); //$NON-NLS-1$ + break; + case Constants.SOURCE_WIDGET: + StatisticsService.reportEvent("launch-from-widget"); //$NON-NLS-1$ + break; + case Constants.SOURCE_C2DM: + StatisticsService.reportEvent("launch-from-c2dm"); //$NON-NLS-1$ + break; + } + } } @Override @@ -227,10 +251,12 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, Bundle extras = intent.getExtras(); if(extras != null && extras.containsKey(TOKEN_FILTER)) { filter = extras.getParcelable(TOKEN_FILTER); + isInbox = true; } else { filter = CoreFilterExposer.buildInboxFilter(getResources()); findViewById(R.id.headerLogo).setVisibility(View.VISIBLE); findViewById(R.id.listLabel).setVisibility(View.GONE); + isInbox = false; } setUpTaskList(); @@ -671,7 +697,13 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, // set up list adapters taskAdapter = new TaskAdapter(this, R.layout.task_adapter_row, - currentCursor, sqlQueryTemplate, false, null); + currentCursor, sqlQueryTemplate, false, new OnCompletedTaskListener() { + @Override + public void onCompletedTask(Task item, boolean newState) { + if(newState == true) + onTaskCompleted(item); + } + }); setListAdapter(taskAdapter); getListView().setOnScrollListener(this); registerForContextMenu(getListView()); @@ -727,6 +759,18 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, * ============================================================== actions * ====================================================================== */ + /** + * A task was completed from the task adapter + * @param item task that was completed + */ + @SuppressWarnings("nls") + protected void onTaskCompleted(Task item) { + if(isInbox) + StatisticsService.reportEvent("task-completed-inbox"); + else + StatisticsService.reportEvent("task-completed-filter"); + } + /** * Quick-add a new task * @param title @@ -748,6 +792,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, selectCustomId(task.getId()); } + StatisticsService.reportEvent("task-created-tasklist"); return task; } catch (Exception e) { exceptionService.displayAndReportError(this, "quick-add-task", e); @@ -975,22 +1020,27 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, // handle my own menus switch (item.getItemId()) { case MENU_ADDONS_ID: + StatisticsService.reportEvent("tla-menu-addons"); //$NON-NLS-1$ intent = new Intent(this, AddOnActivity.class); startActivityForResult(intent, ACTIVITY_ADDONS); return true; case MENU_SETTINGS_ID: + StatisticsService.reportEvent("tla-menu-settings"); //$NON-NLS-1$ intent = new Intent(this, EditPreferences.class); startActivityForResult(intent, ACTIVITY_SETTINGS); return true; case MENU_SORT_ID: + StatisticsService.reportEvent("tla-menu-sort"); //$NON-NLS-1$ AlertDialog dialog = SortSelectionActivity.createDialog(this, this, sortFlags, sortSort); dialog.show(); return true; case MENU_SYNC_ID: + StatisticsService.reportEvent("tla-menu-sync"); //$NON-NLS-1$ performSyncAction(); return true; case MENU_HELP_ID: + StatisticsService.reportEvent("tla-menu-help"); //$NON-NLS-1$ intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.HELP_URL)); startActivity(intent); diff --git a/astrid/src/com/todoroo/astrid/adapter/AddOnAdapter.java b/astrid/src/com/todoroo/astrid/adapter/AddOnAdapter.java index 63bb7a335..10624ed78 100644 --- a/astrid/src/com/todoroo/astrid/adapter/AddOnAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/AddOnAdapter.java @@ -22,6 +22,7 @@ import android.widget.TextView; import com.timsu.astrid.R; import com.todoroo.astrid.data.AddOn; +import com.todoroo.astrid.service.StatisticsService; /** * Adapter for {@link AddOn}s @@ -50,9 +51,11 @@ public class AddOnAdapter extends ArrayAdapter { View.OnClickListener intentClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = (Intent) v.getTag(); - if(intent != null) - activity.startActivity(intent); + ButtonTag buttonTag = (ButtonTag) v.getTag(); + if(buttonTag != null) { + activity.startActivity(buttonTag.intent); + StatisticsService.reportEvent("addon-" + buttonTag.event); //$NON-NLS-1$ + } } }; @@ -91,6 +94,15 @@ public class AddOnAdapter extends ArrayAdapter { public ImageView installedIcon; } + private class ButtonTag { + String event; + Intent intent; + public ButtonTag(String message, Intent intent) { + this.event = message; + this.intent = intent; + } + } + private void initializeView(View convertView) { ViewHolder viewHolder = (ViewHolder) convertView.getTag(); AddOn item = viewHolder.item; @@ -105,7 +117,8 @@ public class AddOnAdapter extends ArrayAdapter { viewHolder.web.setVisibility(View.VISIBLE); Intent webPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getWebPage())); - viewHolder.web.setTag(webPageIntent); + viewHolder.web.setTag(new ButtonTag("web-" + item.getPackageName(), //$NON-NLS-1$ + webPageIntent)); Drawable icon = getIntentIcon(webPageIntent); if(icon == null) viewHolder.web.setImageResource( @@ -125,7 +138,8 @@ public class AddOnAdapter extends ArrayAdapter { Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + //$NON-NLS-1$ item.getPackageName())); - viewHolder.market.setTag(marketIntent); + viewHolder.market.setTag(new ButtonTag("market-" + item.getPackageName(), //$NON-NLS-1$ + marketIntent)); Drawable icon = getIntentIcon(marketIntent); if(icon == null) viewHolder.market.setImageResource( diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 3242f4257..d867bdd8f 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -1023,4 +1023,23 @@ public class TaskAdapter extends CursorAdapter implements Filterable { } } + /** + * Add a new listener + * @param newListener + */ + public void addOnCompletedTaskListener(final OnCompletedTaskListener newListener) { + if(this.onCompletedTaskListener == null) + this.onCompletedTaskListener = newListener; + else { + final OnCompletedTaskListener old = this.onCompletedTaskListener; + this.onCompletedTaskListener = new OnCompletedTaskListener() { + @Override + public void onCompletedTask(Task item, boolean newState) { + old.onCompletedTask(item, newState); + newListener.onCompletedTask(item, newState); + } + }; + } + } + } diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 504056e41..0bfbee69c 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -167,18 +167,12 @@ public class TaskDao extends DatabaseDao { public boolean save(Task task) { boolean saveSuccessful; - ContentValues values = task.getSetValues(); if (task.getId() == Task.NO_ID) { saveSuccessful = createNew(task); } else { saveSuccessful = saveExisting(task); } - if(saveSuccessful) { - task.markSaved(); - afterSave(task, values); - } - return saveSuccessful; } @@ -213,7 +207,11 @@ public class TaskDao extends DatabaseDao { Task.NOTIFY_AT_DEADLINE | Task.NOTIFY_AFTER_DEADLINE)); } - return super.createNew(item); + ContentValues values = item.getSetValues(); + boolean result = super.createNew(item); + if(result) + afterSave(item, values); + return result; } @Override @@ -226,7 +224,10 @@ public class TaskDao extends DatabaseDao { if(!values.containsKey(Task.MODIFICATION_DATE.name)) item.setValue(Task.MODIFICATION_DATE, DateUtilities.now()); } - return super.saveExisting(item); + boolean result = super.saveExisting(item); + if(result) + afterSave(item, values); + return result; } /** @@ -238,6 +239,7 @@ public class TaskDao extends DatabaseDao { if(values == null) return; + task.markSaved(); if(values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted()) afterComplete(task, values); else { @@ -260,8 +262,8 @@ public class TaskDao extends DatabaseDao { * @param values */ private static void afterComplete(Task task, ContentValues values) { + StatisticsService.reportEvent("task-completed"); //$NON-NLS-1$ Notifications.cancelNotifications(task.getId()); - StatisticsService.reportEvent("complete-task"); //$NON-NLS-1$ } } diff --git a/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java b/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java index 129026c5c..606d0656e 100644 --- a/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java +++ b/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java @@ -25,6 +25,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.AstridDependencyInjector; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService.Tag; @@ -263,9 +264,12 @@ public class Astrid2TaskProvider extends ContentProvider { task.setValue(Task.DUE_DATE, values.getAsLong(DEFINITE_DUE_DATE)); if(values.containsKey(IMPORTANCE)) task.setValue(Task.IMPORTANCE, values.getAsInteger(IMPORTANCE)); - if(values.containsKey(COMPLETED)) + if(values.containsKey(COMPLETED)) { task.setValue(Task.COMPLETION_DATE, values.getAsBoolean(COMPLETED) ? DateUtilities.now() : 0); + if(task.isCompleted()) + StatisticsService.reportEvent("task-completed-api2"); + } // map selection criteria String criteria = selection.replace(NAME, Task.TITLE.name). diff --git a/astrid/src/com/todoroo/astrid/provider/Astrid3ContentProvider.java b/astrid/src/com/todoroo/astrid/provider/Astrid3ContentProvider.java index b412a9726..9cfb71282 100644 --- a/astrid/src/com/todoroo/astrid/provider/Astrid3ContentProvider.java +++ b/astrid/src/com/todoroo/astrid/provider/Astrid3ContentProvider.java @@ -31,6 +31,7 @@ import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskApiDao; import com.todoroo.astrid.service.AstridDependencyInjector; +import com.todoroo.astrid.service.StatisticsService; /** * Astrid 3 Content Provider. There are two ways to use this content provider: @@ -324,6 +325,10 @@ public class Astrid3ContentProvider extends ContentProvider { helper.model.setId(id); helper.update(); helper.model.clear(); + + if(values.containsKey(Task.COMPLETION_DATE.name) && + values.getAsLong(Task.COMPLETION_DATE.name) > 0) + StatisticsService.reportEvent("task-completed-api3"); } getContext().getContentResolver().notifyChange(uri, null); diff --git a/astrid/src/com/todoroo/astrid/utility/Constants.java b/astrid/src/com/todoroo/astrid/utility/Constants.java index c96a0ea61..868a1db42 100644 --- a/astrid/src/com/todoroo/astrid/utility/Constants.java +++ b/astrid/src/com/todoroo/astrid/utility/Constants.java @@ -41,6 +41,15 @@ public final class Constants { */ public static final String HELP_URL = "http://weloveastrid.com/help-user-guide-astrid-v3/active-tasks/"; //$NON-NLS-1$ + // --- task list activity source strings + + public static final int SOURCE_OTHER = -1; + public static final int SOURCE_DEFAULT = 0; + public static final int SOURCE_NOTIFICATION = 1; + public static final int SOURCE_WIDGET = 2; + public static final int SOURCE_PPWIDGET = 3; + public static final int SOURCE_C2DM = 4; + // --- notification id's /** Notification Manager id for sync notifications */ @@ -59,4 +68,5 @@ public final class Constants { public static final int NOTIFICATION_ACTFM = -5; + } diff --git a/astrid/src/com/todoroo/astrid/widget/TasksWidget.java b/astrid/src/com/todoroo/astrid/widget/TasksWidget.java index bc68a44bc..61720f09f 100644 --- a/astrid/src/com/todoroo/astrid/widget/TasksWidget.java +++ b/astrid/src/com/todoroo/astrid/widget/TasksWidget.java @@ -35,6 +35,7 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.utility.AstridPreferences; +import com.todoroo.astrid.utility.Constants; public class TasksWidget extends AppWidgetProvider { @@ -204,6 +205,7 @@ public class TasksWidget extends AppWidgetProvider { Intent listIntent = new Intent(context, TaskListActivity.class); listIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); + listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET); if(filter != null) { listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter); listIntent.setType(filter.sqlQuery);