Sharing initial commit

pull/14/head
Tim Su 15 years ago
parent f4aa8093ad
commit f46a92938a

@ -376,6 +376,20 @@
</intent-filter>
</receiver>
<!-- notes -->
<receiver android:name="com.todoroo.astrid.sharing.SharingDetailExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_DETAILS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.sharing.SharingActionExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_ACTIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- timers -->
<receiver android:name="com.todoroo.astrid.timers.TimerActionExposer">
<intent-filter>

@ -16,11 +16,9 @@
<booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/astrid"/>
<listEntry value="/astrid/AndroidManifest.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>

@ -1,10 +1,14 @@
package com.todoroo.astrid.core;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.MetadataService;
@ -73,4 +77,23 @@ public final class PluginServices {
public static StoreObjectDao getStoreObjectDao() {
return getInstance().storeObjectDao;
}
// -- helpers
/**
* Find the corresponding metadata for this task
*/
public static Metadata getMetadataByTaskAndWithKey(long taskId, String metadataKey) {
TodorooCursor<Metadata> cursor = PluginServices.getMetadataService().query(Query.select(
Metadata.PROPERTIES).where(MetadataCriteria.byTaskAndwithKey(taskId, metadataKey)));
try {
if(cursor.getCount() > 0)
return new Metadata(cursor);
else
return null;
} finally {
cursor.close();
}
}
}

@ -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…
Cancel
Save