mirror of https://github.com/tasks/tasks
Remove task decorations
parent
061861981b
commit
5374f67e89
@ -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];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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>
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue