Remove task decorations

pull/143/head
Alex Baker 12 years ago
parent 061861981b
commit 5374f67e89

@ -147,16 +147,6 @@ public class AstridApiConstants {
*/
public static final String BROADCAST_SEND_SYNC_ACTIONS = API_PACKAGE + ".SEND_SYNC_ACTIONS";
// --- Task Decorations API
/**
* Action name for broadcast intent sending decorations back to Astrid
* <li> EXTRAS_ADDON your add-on identifier
* <li> EXTRAS_TASK_ID id of the task
* <li> EXTRAS_RESPONSE a {@link TaskDecoration}
*/
public static final String BROADCAST_SEND_DECORATIONS = API_PACKAGE + ".SEND_DECORATIONS";
// --- Actions API
/**

@ -1,100 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.api;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.RemoteViews;
import android.widget.RemoteViews.RemoteView;
/**
* Represents a line of text displayed in the Task List
*
* @author Tim Su <tim@todoroo.com>
*
*/
public final class TaskDecoration implements Parcelable {
/**
* Place decoration between completion box and task title
*/
public static final int POSITION_LEFT = 0;
/**
* Place decoration between task title and importance bar
*/
public static final int POSITION_RIGHT = 1;
/**
* {@link RemoteView} decoration
*/
public RemoteViews decoration = null;
/**
* Decoration position
*/
public int position = POSITION_LEFT;
/**
* Decorated task background color. 0 is default
*/
public int color = 0;
/**
* Creates a TaskDetail object
* @param color
* color to use for text. Use <code>0</code> for default color
*/
public TaskDecoration(RemoteViews decoration, int position, int color) {
this.decoration = decoration;
this.position = position;
this.color = color;
}
// --- parcelable helpers
/**
* {@inheritDoc}
*/
@Override
public int describeContents() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(decoration, 0);
dest.writeInt(position);
dest.writeInt(color);
}
/**
* Parcelable creator
*/
public static final Parcelable.Creator<TaskDecoration> CREATOR = new Parcelable.Creator<TaskDecoration>() {
/**
* {@inheritDoc}
*/
@Override
public TaskDecoration createFromParcel(Parcel source) {
return new TaskDecoration((RemoteViews)source.readParcelable(
RemoteViews.class.getClassLoader()),
source.readInt(), source.readInt());
}
/**
* {@inheritDoc}
*/
@Override
public TaskDecoration[] newArray(int size) {
return new TaskDecoration[size];
}
};
}

@ -62,7 +62,6 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.TaskContextActionExposer;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskListMetadataDao;
@ -570,8 +569,6 @@ public class TaskListFragment extends ListFragment implements OnSortSelectedList
getActivity().registerReceiver(detailReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_SEND_DETAILS));
getActivity().registerReceiver(detailReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_SEND_DECORATIONS));
getActivity().registerReceiver(refreshReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));
syncActionHelper.register();
@ -691,12 +688,7 @@ public class TaskListFragment extends ListFragment implements OnSortSelectedList
try {
Bundle receivedExtras = intent.getExtras();
long taskId = receivedExtras.getLong(AstridApiConstants.EXTRAS_TASK_ID);
String addOn = receivedExtras.getString(AstridApiConstants.EXTRAS_ADDON);
if (AstridApiConstants.BROADCAST_SEND_DECORATIONS.equals(intent.getAction())) {
TaskDecoration deco = receivedExtras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.decorationManager.addNew(taskId, addOn, deco);
} else if (AstridApiConstants.BROADCAST_SEND_DETAILS.equals(intent.getAction())) {
if (AstridApiConstants.BROADCAST_SEND_DETAILS.equals(intent.getAction())) {
String detail = receivedExtras.getString(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.addDetails(taskId, detail);
}

@ -13,7 +13,6 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.Html;
@ -56,14 +55,12 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.LinkActionExposer;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskAttachment;
import com.todoroo.astrid.files.FilesAction;
import com.todoroo.astrid.files.FilesControlSet;
import com.todoroo.astrid.helper.TaskAdapterAddOnManager;
import com.todoroo.astrid.notes.NotesAction;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.ThemeService;
@ -73,7 +70,6 @@ import com.todoroo.astrid.utility.Constants;
import org.tasks.R;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -203,10 +199,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final boolean titleOnlyLayout;
protected final int minRowHeight;
// --- task detail and decoration soft caches
public final DecorationManager decorationManager;
private final Map<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>());
/**
@ -244,8 +236,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
startDetailThread();
decorationManager = new DecorationManager();
scaleAnimation = new ScaleAnimation(1.4f, 1.0f, 1.4f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(100);
@ -844,7 +834,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
*/
public void flushCaches() {
completedItems.clear();
decorationManager.clearCache();
taskDetailLoader.clear();
startDetailThread();
}
@ -853,76 +842,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
return completedItems;
}
/**
* AddOnManager for TaskDecorations
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class DecorationManager extends TaskAdapterAddOnManager<TaskDecoration> {
public DecorationManager() {
super(fragment);
}
@Override
protected void draw(ViewHolder viewHolder, long taskId, Collection<TaskDecoration> decorations) {
if(decorations == null || viewHolder.task.getId() != taskId) {
return;
}
reset(viewHolder);
if(decorations.size() == 0) {
return;
}
int i = 0;
boolean colorSet = false;
if(viewHolder.decorations == null || viewHolder.decorations.length != decorations.size()) {
viewHolder.decorations = new View[decorations.size()];
}
for(TaskDecoration decoration : decorations) {
if(decoration.color != 0 && !colorSet) {
colorSet = true;
viewHolder.view.setBackgroundColor(decoration.color);
}
if(decoration.decoration != null) {
View view = decoration.decoration.apply(fragment.getActivity(), viewHolder.taskRow);
viewHolder.decorations[i] = view;
switch(decoration.position) {
case TaskDecoration.POSITION_LEFT: {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.completeBox);
view.setLayoutParams(params);
viewHolder.rowBody.addView(view);
break;
}
case TaskDecoration.POSITION_RIGHT:
viewHolder.taskRow.addView(view, viewHolder.taskRow.getChildCount());
}
}
i++;
}
}
private void reset(ViewHolder viewHolder) {
if(viewHolder.decorations != null) {
for(View view : viewHolder.decorations) {
viewHolder.rowBody.removeView(view);
viewHolder.taskRow.removeView(view);
}
viewHolder.decorations = null;
}
if(viewHolder.task.getId() == mostRecentlyMade) {
viewHolder.view.setBackgroundColor(Color.argb(30, 150, 150, 150));
} else {
viewHolder.view.setBackgroundResource(android.R.drawable.list_selector_background);
}
}
}
/* ======================================================================
* ======================================================= event handlers
* ====================================================================== */

@ -20,7 +20,6 @@ import android.text.util.Linkify;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FilesAction;
import com.todoroo.astrid.notes.NotesAction;
@ -31,7 +30,7 @@ import java.util.HashMap;
import java.util.List;
/**
* Exposes {@link TaskDecoration} for phone numbers, emails, urls, etc
* Exposes {@link TaskAction} for phone numbers, emails, urls, etc
*
* @author Tim Su <tim@todoroo.com>
*

@ -1,91 +0,0 @@
/**
*
*/
package com.todoroo.astrid.helper;
import android.support.v4.app.ListFragment;
import android.widget.ListView;
import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
abstract public class TaskAdapterAddOnManager<TYPE> {
private final ListFragment fragment;
protected TaskAdapterAddOnManager(ListFragment fragment) {
this.fragment = fragment;
}
private final Map<Long, LinkedHashMap<String, TYPE>> cache =
Collections.synchronizedMap(new HashMap<Long, LinkedHashMap<String, TYPE>>(0));
// --- interface
/** updates the given view */
abstract protected void draw(ViewHolder viewHolder, long taskId, Collection<TYPE> list);
/** on receive an intent */
public void addNew(long taskId, String addOn, TYPE item) {
if(item == null) {
return;
}
Collection<TYPE> cacheList = addIfNotExists(taskId, addOn, item);
if(cacheList != null) {
ListView listView = fragment.getListView();
// update view if it is visible
int length = listView.getChildCount();
for(int i = 0; i < length; i++) {
ViewHolder viewHolder = (ViewHolder) listView.getChildAt(i).getTag();
if(viewHolder == null || viewHolder.task.getId() != taskId) {
continue;
}
draw(viewHolder, taskId, cacheList);
break;
}
}
}
/**
* Clears the cache
*/
public void clearCache() {
cache.clear();
}
// --- internal goodies
/**
* Adds an item to the cache if it doesn't exist
* @return iterator if item was added, null if it already existed
*/
protected synchronized Collection<TYPE> addIfNotExists(long taskId, String addOn,
TYPE item) {
LinkedHashMap<String, TYPE> list = cache.get(taskId);
if(list == null) {
return null;
}
if(list.containsValue(item)) {
return null;
}
list.put(addOn, item);
return get(taskId);
}
/**
* Gets an item at the given index
*/
protected Collection<TYPE> get(long taskId) {
if(cache.get(taskId) == null) {
return null;
}
return cache.get(taskId).values();
}
}

@ -1,83 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.timers;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.SystemClock;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.RemoteViews;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.data.Task;
import org.tasks.R;
/**
* Exposes {@link TaskDecoration} for timers
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class TimerDecorationExposer {
private static final int TIMING_BG_COLOR = Color.argb(200, 220, 50, 0);
public TaskDecoration expose(Task task) {
if(task == null || (task.getElapsedSeconds() == 0 &&
task.getTimerStart() == 0)) {
return null;
}
TaskDecoration decoration;
RemoteViews remoteViews = new RemoteViews(ContextManager.getContext().getPackageName(),
R.layout.timer_decoration);
decoration = new TaskDecoration(remoteViews,
TaskDecoration.POSITION_LEFT, 0);
long elapsed = task.getElapsedSeconds() * 1000L;
if(task.getTimerStart() != 0) {
decoration.color = TIMING_BG_COLOR;
elapsed += DateUtilities.now() - task.getTimerStart();
decoration.decoration.setChronometer(R.id.timer, SystemClock.elapsedRealtime() -
elapsed, null, true);
decoration.decoration.setViewVisibility(R.id.timer, View.VISIBLE);
decoration.decoration.setViewVisibility(R.id.label, View.GONE);
} else {
// if timer is not started, make the chronometer just a text label,
// since we don't want the time to be displayed relative to elapsed
String format = buildFormat(elapsed);
decoration.color = 0;
decoration.decoration.setTextViewText(R.id.label, format);
decoration.decoration.setViewVisibility(R.id.timer, View.GONE);
decoration.decoration.setViewVisibility(R.id.label, View.VISIBLE);
}
return decoration;
}
public void updateDecoration(Context context, Task task) {
TaskDecoration decoration = expose(task);
if(decoration == null) {
return;
}
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_DECORATIONS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, TimerPlugin.IDENTIFIER);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, decoration);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
private String buildFormat(long elapsed) {
return DateUtils.formatElapsedTime(elapsed / 1000L);
}
}

@ -69,7 +69,6 @@ public class TimerPlugin extends BroadcastReceiver {
}
}
PluginServices.getTaskService().save(task);
new TimerDecorationExposer().updateDecoration(context, task);
// update notification
TimerPlugin.updateNotifications(context);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 621 B

@ -1,41 +0,0 @@
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="top"
android:layout_marginTop="-10dip"
android:paddingLeft="8dip">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center_horizontal"
android:scaleType="center"
android:src="@drawable/task_timer" />
<Chronometer android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:visibility="gone"
android:textColor="#5d8cbb"
android:textSize="10sp" />
<TextView android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:textColor="#5d8cbb"
android:textSize="10sp" />
</LinearLayout>

@ -140,14 +140,6 @@ public class AstridApiConstants {
*/
public static final String BROADCAST_REQUEST_DECORATIONS = PACKAGE + ".REQUEST_DECORATIONS";
/**
* Action name for broadcast intent sending decorations back to Astrid
* @extra EXTRAS_ADDON your add-on identifier
* @extra EXTRAS_TASK_ID id of the task
* @extra EXTRAS_RESPONSE a {@link TaskDecoration}
*/
public static final String BROADCAST_SEND_DECORATIONS = PACKAGE + ".SEND_DECORATIONS";
// --- Actions API
/**

Loading…
Cancel
Save