mirror of https://github.com/tasks/tasks
Sharing initial commit
parent
f4aa8093ad
commit
f46a92938a
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.sharing;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.timsu.astrid.R;
|
||||||
|
import com.todoroo.andlib.service.ContextManager;
|
||||||
|
import com.todoroo.astrid.api.AstridApiConstants;
|
||||||
|
import com.todoroo.astrid.api.TaskAction;
|
||||||
|
import com.todoroo.astrid.api.TaskDecoration;
|
||||||
|
import com.todoroo.astrid.core.PluginServices;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes {@link TaskDecoration} for timers
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SharingActionExposer extends BroadcastReceiver {
|
||||||
|
|
||||||
|
static final String EXTRA_TASK = "task"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
ContextManager.setContext(context);
|
||||||
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
||||||
|
if(taskId == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TITLE, Task.NOTES);
|
||||||
|
if(!task.containsNonNullValue(Task.NOTES) || TextUtils.isEmpty(task.getValue(Task.NOTES)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(AstridApiConstants.BROADCAST_REQUEST_ACTIONS.equals(intent.getAction())) {
|
||||||
|
sendAction(context, taskId);
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendAction(Context context, long taskId) {
|
||||||
|
final String label = context.getString(R.string.sharing_action);
|
||||||
|
final Drawable drawable = context.getResources().getDrawable(R.drawable.tango_share);
|
||||||
|
|
||||||
|
Bitmap icon = ((BitmapDrawable)drawable).getBitmap();
|
||||||
|
Intent newIntent = new Intent(context, getClass());
|
||||||
|
newIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
||||||
|
TaskAction action = new TaskAction(label,
|
||||||
|
PendingIntent.getBroadcast(context, (int)taskId, newIntent, 0), icon);
|
||||||
|
|
||||||
|
// transmit
|
||||||
|
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_ACTIONS);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, action);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
||||||
|
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.sharing;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.todoroo.astrid.api.AstridApiConstants;
|
||||||
|
import com.todoroo.astrid.core.PluginServices;
|
||||||
|
import com.todoroo.astrid.data.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes Task Detail for notes
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SharingDetailExposer extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
||||||
|
if(taskId == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean extended = intent.getBooleanExtra(AstridApiConstants.EXTRAS_EXTENDED, false);
|
||||||
|
String taskDetail = getTaskDetails(taskId, extended);
|
||||||
|
if(taskDetail == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// transmit
|
||||||
|
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DETAILS);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, taskDetail);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_EXTENDED, extended);
|
||||||
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
||||||
|
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskDetails(long id, boolean extended) {
|
||||||
|
Metadata metadata = PluginServices.getMetadataByTaskAndWithKey(id, SharingFields.METADATA_KEY);
|
||||||
|
if(metadata == null || extended)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if(metadata.getValue(SharingFields.PRIVACY) == SharingFields.PRIVACY_PUBLIC)
|
||||||
|
return "<img src='silk_world'/> Public"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package com.todoroo.astrid.sharing;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.Property.IntegerProperty;
|
||||||
|
import com.todoroo.andlib.data.Property.StringProperty;
|
||||||
|
import com.todoroo.astrid.data.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata entry for a task alarm
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SharingFields {
|
||||||
|
|
||||||
|
/** metadata key */
|
||||||
|
public static final String METADATA_KEY = "sharing"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/** online url */
|
||||||
|
public static final StringProperty URL = Metadata.VALUE1;
|
||||||
|
|
||||||
|
/** sharing privacy */
|
||||||
|
public static final IntegerProperty PRIVACY = new IntegerProperty(Metadata.TABLE,
|
||||||
|
Metadata.VALUE2.name);
|
||||||
|
|
||||||
|
// --- constants
|
||||||
|
|
||||||
|
/** this task is shared publicly */
|
||||||
|
public static final int PRIVACY_PUBLIC = 2;
|
||||||
|
|
||||||
|
/** this task is shared with a limited group */
|
||||||
|
public static final int PRIVACY_LIMITED = 2;
|
||||||
|
|
||||||
|
/** this task is private */
|
||||||
|
public static final int PRIVACY_PRIVATE = 1;
|
||||||
|
|
||||||
|
/** this alarm repeats itself until turned off */
|
||||||
|
public static final int TYPE_REPEATING = 2;
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 923 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||||
|
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- ============================================================= UI == -->
|
||||||
|
|
||||||
|
<!-- task action: Share -->
|
||||||
|
<string name="sharing_action">Share</string>
|
||||||
|
|
||||||
|
</resources>
|
||||||
|
|
||||||
Loading…
Reference in New Issue