mirror of https://github.com/tasks/tasks
Inject Notifications
Remove TaskListContextMenuExtensionLoader, TaskContextActionExposerpull/189/head
parent
fa6060a40c
commit
7c90ac7aeb
@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.api;
|
|
||||||
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API for exposing context menu items associated with a task.
|
|
||||||
*
|
|
||||||
* Due to the limitations of the Android platform, this is currently
|
|
||||||
* internal-use only, though if it can be done well, I would be open to creating
|
|
||||||
* an external API. Internal API for exposing task decorations
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface TaskContextActionExposer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call context menu action
|
|
||||||
*/
|
|
||||||
public void invoke(Task task);
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.helper;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
|
|
||||||
import com.todoroo.astrid.api.AstridApiConstants;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TaskListContextMenuExtensionLoader {
|
|
||||||
|
|
||||||
public static class ContextMenuItem {
|
|
||||||
public CharSequence title;
|
|
||||||
public Intent intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContextMenuItem[] contextMenuItemCache = new ContextMenuItem[0];
|
|
||||||
|
|
||||||
public void loadContextMenuIntents(Context context) {
|
|
||||||
Intent queryIntent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
List<ResolveInfo> resolveInfoList = pm.queryBroadcastReceivers(queryIntent,
|
|
||||||
PackageManager.GET_META_DATA);
|
|
||||||
|
|
||||||
int length = resolveInfoList.size();
|
|
||||||
contextMenuItemCache = new ContextMenuItem[length];
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
ResolveInfo resolveInfo = resolveInfoList.get(i);
|
|
||||||
|
|
||||||
ContextMenuItem item = new ContextMenuItem();
|
|
||||||
|
|
||||||
item.intent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
|
|
||||||
item.intent.setClassName(resolveInfo.activityInfo.packageName,
|
|
||||||
resolveInfo.activityInfo.name);
|
|
||||||
item.title = resolveInfo.loadLabel(pm);
|
|
||||||
contextMenuItemCache[i] = item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadInNewThread(final Context context) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
loadContextMenuIntents(context);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContextMenuItem[] getList() {
|
|
||||||
return contextMenuItemCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package com.todoroo.astrid.reminders;
|
|
||||||
|
|
||||||
import com.todoroo.astrid.api.TaskContextActionExposer;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
|
|
||||||
public class MakeNotification implements TaskContextActionExposer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(Task task) {
|
|
||||||
new Notifications().showTaskNotification(task.getId(),
|
|
||||||
ReminderService.TYPE_SNOOZE, "test reminder");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
package com.todoroo.astrid.reminders;
|
|
||||||
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.service.ContextManager;
|
|
||||||
import com.todoroo.astrid.api.TaskContextActionExposer;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
|
|
||||||
import static org.tasks.date.DateTimeUtils.newDate;
|
|
||||||
|
|
||||||
public class WhenReminder implements TaskContextActionExposer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(Task task) {
|
|
||||||
ReminderService.AlarmScheduler original = ReminderService.getInstance().getScheduler();
|
|
||||||
ReminderService.getInstance().setScheduler(new ReminderService.AlarmScheduler() {
|
|
||||||
@Override
|
|
||||||
public void createAlarm(Task theTask, long time, int type) {
|
|
||||||
if(time == 0 || time == Long.MAX_VALUE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toast.makeText(ContextManager.getContext(), "Scheduled Alarm: " +
|
|
||||||
newDate(time), Toast.LENGTH_LONG).show();
|
|
||||||
ReminderService.getInstance().setScheduler(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ReminderService.getInstance().scheduleAlarm(task);
|
|
||||||
if(ReminderService.getInstance().getScheduler() != null) {
|
|
||||||
Toast.makeText(ContextManager.getContext(), "No alarms", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
ReminderService.getInstance().setScheduler(original);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue