trying out new icon things in details

pull/14/head
Tim Su 16 years ago
parent 0ae7d4ddd2
commit 76b85c3efe

@ -1,89 +1,89 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.AND; import static com.todoroo.andlib.sql.SqlConstants.AND;
import static com.todoroo.andlib.sql.SqlConstants.EXISTS; import static com.todoroo.andlib.sql.SqlConstants.EXISTS;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.NOT; import static com.todoroo.andlib.sql.SqlConstants.NOT;
import static com.todoroo.andlib.sql.SqlConstants.OR; import static com.todoroo.andlib.sql.SqlConstants.OR;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public abstract class Criterion { public abstract class Criterion {
protected final Operator operator; protected final Operator operator;
Criterion(Operator operator) { Criterion(Operator operator) {
this.operator = operator; this.operator = operator;
} }
public static Criterion all = new Criterion(Operator.exists) { public static Criterion all = new Criterion(Operator.exists) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(1); sb.append(1);
} }
}; };
public static Criterion none = new Criterion(Operator.exists) { public static Criterion none = new Criterion(Operator.exists) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(0); sb.append(0);
} }
}; };
public static Criterion and(final Criterion criterion, final Criterion... criterions) { public static Criterion and(final Criterion criterion, final Criterion... criterions) {
return new Criterion(Operator.and) { return new Criterion(Operator.and) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(criterion); sb.append(criterion);
for (Criterion c : criterions) { for (Criterion c : criterions) {
sb.append(SPACE).append(AND).append(SPACE).append(c); sb.append(SPACE).append(AND).append(SPACE).append(c);
} }
} }
}; };
} }
public static Criterion or(final Criterion criterion, final Criterion... criterions) { public static Criterion or(final Criterion criterion, final Criterion... criterions) {
return new Criterion(Operator.or) { return new Criterion(Operator.or) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(criterion); sb.append(criterion);
for (Criterion c : criterions) { for (Criterion c : criterions) {
sb.append(SPACE).append(OR).append(SPACE).append(c.toString()); sb.append(SPACE).append(OR).append(SPACE).append(c.toString());
} }
} }
}; };
} }
public static Criterion exists(final Query query) { public static Criterion exists(final Query query) {
return new Criterion(Operator.exists) { return new Criterion(Operator.exists) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(EXISTS).append(SPACE).append(LEFT_PARENTHESIS).append(query).append(RIGHT_PARENTHESIS); sb.append(EXISTS).append(SPACE).append(LEFT_PARENTHESIS).append(query).append(RIGHT_PARENTHESIS);
} }
}; };
} }
public static Criterion not(final Criterion criterion) { public static Criterion not(final Criterion criterion) {
return new Criterion(Operator.not) { return new Criterion(Operator.not) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(NOT).append(SPACE); sb.append(NOT).append(SPACE);
criterion.populate(sb); criterion.populate(sb);
} }
}; };
} }
protected abstract void populate(StringBuilder sb); protected abstract void populate(StringBuilder sb);
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(LEFT_PARENTHESIS); StringBuilder builder = new StringBuilder(LEFT_PARENTHESIS);
populate(builder); populate(builder);
builder.append(RIGHT_PARENTHESIS); builder.append(RIGHT_PARENTHESIS);
return builder.toString(); return builder.toString();
} }
} }

@ -1,67 +1,67 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.AS; import static com.todoroo.andlib.sql.SqlConstants.AS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public abstract class DBObject<T extends DBObject<?>> implements Cloneable { public abstract class DBObject<T extends DBObject<?>> implements Cloneable {
protected String alias; protected String alias;
protected final String expression; protected final String expression;
protected DBObject(String expression){ protected DBObject(String expression){
this.expression = expression; this.expression = expression;
} }
public T as(String newAlias) { public T as(String newAlias) {
try { try {
T clone = (T) clone(); T clone = (T) clone();
clone.alias = newAlias; clone.alias = newAlias;
return clone; return clone;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public boolean hasAlias() { public boolean hasAlias() {
return alias != null; return alias != null;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
DBObject<?> dbObject = (DBObject<?>) o; DBObject<?> dbObject = (DBObject<?>) o;
if (alias != null ? !alias.equals(dbObject.alias) : dbObject.alias != null) return false; if (alias != null ? !alias.equals(dbObject.alias) : dbObject.alias != null) return false;
if (expression != null ? !expression.equals(dbObject.expression) : dbObject.expression != null) return false; if (expression != null ? !expression.equals(dbObject.expression) : dbObject.expression != null) return false;
return true; return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = alias != null ? alias.hashCode() : 0; int result = alias != null ? alias.hashCode() : 0;
result = 31 * result + (expression != null ? expression.hashCode() : 0); result = 31 * result + (expression != null ? expression.hashCode() : 0);
return result; return result;
} }
@Override @Override
public final String toString() { public final String toString() {
if (hasAlias()) { if (hasAlias()) {
return alias; return alias;
} }
return expression; return expression;
} }
public final String toStringInSelect() { public final String toStringInSelect() {
StringBuilder sb = new StringBuilder(expression); StringBuilder sb = new StringBuilder(expression);
if (hasAlias()) { if (hasAlias()) {
sb.append(SPACE).append(AS).append(SPACE).append(alias); sb.append(SPACE).append(AS).append(SPACE).append(alias);
} else { } else {
int pos = expression.indexOf('.'); int pos = expression.indexOf('.');
if(pos > 0) if(pos > 0)
sb.append(SPACE).append(AS).append(SPACE).append(expression.substring(pos + 1)); sb.append(SPACE).append(AS).append(SPACE).append(expression.substring(pos + 1));
} }
return sb.toString(); return sb.toString();
} }
} }

@ -1,7 +1,7 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
public class EqCriterion extends UnaryCriterion { public class EqCriterion extends UnaryCriterion {
EqCriterion(Field field, Object value) { EqCriterion(Field field, Object value) {
super(field, Operator.eq, value); super(field, Operator.eq, value);
} }
} }

@ -1,95 +1,95 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.AND; import static com.todoroo.andlib.sql.SqlConstants.AND;
import static com.todoroo.andlib.sql.SqlConstants.BETWEEN; import static com.todoroo.andlib.sql.SqlConstants.BETWEEN;
import static com.todoroo.andlib.sql.SqlConstants.COMMA; import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class Field extends DBObject<Field> { public class Field extends DBObject<Field> {
protected Field(String expression) { protected Field(String expression) {
super(expression); super(expression);
} }
public static Field field(String expression) { public static Field field(String expression) {
return new Field(expression); return new Field(expression);
} }
public Criterion eq(Object value) { public Criterion eq(Object value) {
if(value == null) if(value == null)
return UnaryCriterion.isNull(this); return UnaryCriterion.isNull(this);
return UnaryCriterion.eq(this, value); return UnaryCriterion.eq(this, value);
} }
public Criterion neq(Object value) { public Criterion neq(Object value) {
if(value == null) if(value == null)
return UnaryCriterion.isNotNull(this); return UnaryCriterion.isNotNull(this);
return UnaryCriterion.neq(this, value); return UnaryCriterion.neq(this, value);
} }
public Criterion gt(Object value) { public Criterion gt(Object value) {
return UnaryCriterion.gt(this, value); return UnaryCriterion.gt(this, value);
} }
public Criterion lt(final Object value) { public Criterion lt(final Object value) {
return UnaryCriterion.lt(this, value); return UnaryCriterion.lt(this, value);
} }
public Criterion isNull() { public Criterion isNull() {
return UnaryCriterion.isNull(this); return UnaryCriterion.isNull(this);
} }
public Criterion isNotNull() { public Criterion isNotNull() {
return UnaryCriterion.isNotNull(this); return UnaryCriterion.isNotNull(this);
} }
public Criterion between(final Object lower, final Object upper) { public Criterion between(final Object lower, final Object upper) {
final Field field = this; final Field field = this;
return new Criterion(null) { return new Criterion(null) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(field).append(SPACE).append(BETWEEN).append(SPACE).append(lower).append(SPACE).append(AND) sb.append(field).append(SPACE).append(BETWEEN).append(SPACE).append(lower).append(SPACE).append(AND)
.append(SPACE).append(upper); .append(SPACE).append(upper);
} }
}; };
} }
public Criterion like(final String value) { public Criterion like(final String value) {
return UnaryCriterion.like(this, value); return UnaryCriterion.like(this, value);
} }
public Criterion like(String value, String escape) { public Criterion like(String value, String escape) {
return UnaryCriterion.like(this, value, escape); return UnaryCriterion.like(this, value, escape);
} }
public <T> Criterion in(final T... value) { public <T> Criterion in(final T... value) {
final Field field = this; final Field field = this;
return new Criterion(Operator.in) { return new Criterion(Operator.in) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS); sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS);
for (T t : value) { for (T t : value) {
sb.append(t.toString()).append(COMMA); sb.append(t.toString()).append(COMMA);
} }
sb.deleteCharAt(sb.length() - 1).append(RIGHT_PARENTHESIS); sb.deleteCharAt(sb.length() - 1).append(RIGHT_PARENTHESIS);
} }
}; };
} }
public Criterion in(final Query query) { public Criterion in(final Query query) {
final Field field = this; final Field field = this;
return new Criterion(Operator.in) { return new Criterion(Operator.in) {
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS).append(query) sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS).append(query)
.append(RIGHT_PARENTHESIS); .append(RIGHT_PARENTHESIS);
} }
}; };
} }
} }

@ -1,14 +1,14 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class GroupBy { public class GroupBy {
private List<Field> fields = new ArrayList<Field>(); private List<Field> fields = new ArrayList<Field>();
public static GroupBy groupBy(Field field) { public static GroupBy groupBy(Field field) {
GroupBy groupBy = new GroupBy(); GroupBy groupBy = new GroupBy();
groupBy.fields.add(field); groupBy.fields.add(field);
return groupBy; return groupBy;
} }
} }

@ -1,43 +1,43 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.JOIN; import static com.todoroo.andlib.sql.SqlConstants.JOIN;
import static com.todoroo.andlib.sql.SqlConstants.ON; import static com.todoroo.andlib.sql.SqlConstants.ON;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class Join { public class Join {
private final SqlTable joinTable; private final SqlTable joinTable;
private final JoinType joinType; private final JoinType joinType;
private final Criterion[] criterions; private final Criterion[] criterions;
private Join(SqlTable table, JoinType joinType, Criterion... criterions) { private Join(SqlTable table, JoinType joinType, Criterion... criterions) {
joinTable = table; joinTable = table;
this.joinType = joinType; this.joinType = joinType;
this.criterions = criterions; this.criterions = criterions;
} }
public static Join inner(SqlTable expression, Criterion... criterions) { public static Join inner(SqlTable expression, Criterion... criterions) {
return new Join(expression, JoinType.INNER, criterions); return new Join(expression, JoinType.INNER, criterions);
} }
public static Join left(SqlTable table, Criterion... criterions) { public static Join left(SqlTable table, Criterion... criterions) {
return new Join(table, JoinType.LEFT, criterions); return new Join(table, JoinType.LEFT, criterions);
} }
public static Join right(SqlTable table, Criterion... criterions) { public static Join right(SqlTable table, Criterion... criterions) {
return new Join(table, JoinType.RIGHT, criterions); return new Join(table, JoinType.RIGHT, criterions);
} }
public static Join out(SqlTable table, Criterion... criterions) { public static Join out(SqlTable table, Criterion... criterions) {
return new Join(table, JoinType.OUT, criterions); return new Join(table, JoinType.OUT, criterions);
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(joinType).append(SPACE).append(JOIN).append(SPACE).append(joinTable).append(SPACE).append(ON); sb.append(joinType).append(SPACE).append(JOIN).append(SPACE).append(joinTable).append(SPACE).append(ON);
for (Criterion criterion : criterions) { for (Criterion criterion : criterions) {
sb.append(SPACE).append(criterion); sb.append(SPACE).append(criterion);
} }
return sb.toString(); return sb.toString();
} }
} }

@ -1,5 +1,5 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
public enum JoinType { public enum JoinType {
INNER, LEFT, RIGHT, OUT INNER, LEFT, RIGHT, OUT
} }

@ -1,57 +1,57 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public final class Operator { public final class Operator {
private final String operator; private final String operator;
public static final Operator eq = new Operator("="); public static final Operator eq = new Operator("=");
public static final Operator neq = new Operator("<>"); public static final Operator neq = new Operator("<>");
public static final Operator isNull = new Operator("IS NULL"); public static final Operator isNull = new Operator("IS NULL");
public static final Operator isNotNull = new Operator("IS NOT NULL"); public static final Operator isNotNull = new Operator("IS NOT NULL");
public static final Operator gt = new Operator(">"); public static final Operator gt = new Operator(">");
public static final Operator lt = new Operator("<"); public static final Operator lt = new Operator("<");
public static final Operator gte = new Operator(">="); public static final Operator gte = new Operator(">=");
public static final Operator lte = new Operator("<="); public static final Operator lte = new Operator("<=");
public static final Operator and = new Operator("AND"); public static final Operator and = new Operator("AND");
public static final Operator or = new Operator("OR"); public static final Operator or = new Operator("OR");
public static final Operator not = new Operator("NOT"); public static final Operator not = new Operator("NOT");
public static final Operator exists = new Operator("EXISTS"); public static final Operator exists = new Operator("EXISTS");
public static final Operator like = new Operator("LIKE"); public static final Operator like = new Operator("LIKE");
public static final Operator in = new Operator("IN"); public static final Operator in = new Operator("IN");
private static final Map<Operator, Operator> contraryRegistry = new HashMap<Operator, Operator>(); private static final Map<Operator, Operator> contraryRegistry = new HashMap<Operator, Operator>();
static { static {
contraryRegistry.put(eq, neq); contraryRegistry.put(eq, neq);
contraryRegistry.put(neq, eq); contraryRegistry.put(neq, eq);
contraryRegistry.put(isNull, isNotNull); contraryRegistry.put(isNull, isNotNull);
contraryRegistry.put(isNotNull, isNull); contraryRegistry.put(isNotNull, isNull);
contraryRegistry.put(gt, lte); contraryRegistry.put(gt, lte);
contraryRegistry.put(lte, gt); contraryRegistry.put(lte, gt);
contraryRegistry.put(lt, gte); contraryRegistry.put(lt, gte);
contraryRegistry.put(gte, lt); contraryRegistry.put(gte, lt);
} }
private Operator(String operator) { private Operator(String operator) {
this.operator = operator; this.operator = operator;
} }
public Operator getContrary() { public Operator getContrary() {
if(!contraryRegistry.containsKey(this)){ if(!contraryRegistry.containsKey(this)){
Operator opposite = new Operator(not.toString() + SPACE + this.toString()); Operator opposite = new Operator(not.toString() + SPACE + this.toString());
contraryRegistry.put(this, opposite); contraryRegistry.put(this, opposite);
contraryRegistry.put(opposite, this); contraryRegistry.put(opposite, this);
} }
return contraryRegistry.get(this); return contraryRegistry.get(this);
} }
@Override @Override
public String toString() { public String toString() {
return this.operator.toString(); return this.operator.toString();
} }
} }

@ -1,5 +1,5 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
public enum OrderType { public enum OrderType {
DESC, ASC DESC, ASC
} }

@ -1,205 +1,205 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.ALL; import static com.todoroo.andlib.sql.SqlConstants.ALL;
import static com.todoroo.andlib.sql.SqlConstants.COMMA; import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.FROM; import static com.todoroo.andlib.sql.SqlConstants.FROM;
import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY; import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.LIMIT; import static com.todoroo.andlib.sql.SqlConstants.LIMIT;
import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY; import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SELECT; import static com.todoroo.andlib.sql.SqlConstants.SELECT;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.WHERE; import static com.todoroo.andlib.sql.SqlConstants.WHERE;
import static com.todoroo.andlib.sql.SqlTable.table; import static com.todoroo.andlib.sql.SqlTable.table;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import java.util.ArrayList; import java.util.ArrayList;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
public final class Query { public final class Query {
private SqlTable table; private SqlTable table;
private String queryTemplate = null; private String queryTemplate = null;
private final ArrayList<Criterion> criterions = new ArrayList<Criterion>(); private final ArrayList<Criterion> criterions = new ArrayList<Criterion>();
private final ArrayList<Field> fields = new ArrayList<Field>(); private final ArrayList<Field> fields = new ArrayList<Field>();
private final ArrayList<Join> joins = new ArrayList<Join>(); private final ArrayList<Join> joins = new ArrayList<Join>();
private final ArrayList<Field> groupBies = new ArrayList<Field>(); private final ArrayList<Field> groupBies = new ArrayList<Field>();
private final ArrayList<Order> orders = new ArrayList<Order>(); private final ArrayList<Order> orders = new ArrayList<Order>();
private final ArrayList<Criterion> havings = new ArrayList<Criterion>(); private final ArrayList<Criterion> havings = new ArrayList<Criterion>();
private int limits = -1; private int limits = -1;
private Query(Field... fields) { private Query(Field... fields) {
this.fields.addAll(asList(fields)); this.fields.addAll(asList(fields));
} }
public static Query select(Field... fields) { public static Query select(Field... fields) {
return new Query(fields); return new Query(fields);
} }
public Query from(SqlTable fromTable) { public Query from(SqlTable fromTable) {
this.table = fromTable; this.table = fromTable;
return this; return this;
} }
public Query join(Join... join) { public Query join(Join... join) {
joins.addAll(asList(join)); joins.addAll(asList(join));
return this; return this;
} }
public Query where(Criterion criterion) { public Query where(Criterion criterion) {
criterions.add(criterion); criterions.add(criterion);
return this; return this;
} }
public Query groupBy(Field... groupBy) { public Query groupBy(Field... groupBy) {
groupBies.addAll(asList(groupBy)); groupBies.addAll(asList(groupBy));
return this; return this;
} }
public Query orderBy(Order... order) { public Query orderBy(Order... order) {
orders.addAll(asList(order)); orders.addAll(asList(order));
return this; return this;
} }
public Query limit(int limit) { public Query limit(int limit) {
limits = limit; limits = limit;
return this; return this;
} }
public Query appendSelectFields(Property<?>... selectFields) { public Query appendSelectFields(Property<?>... selectFields) {
this.fields.addAll(asList(selectFields)); this.fields.addAll(asList(selectFields));
return this; return this;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
return this == o || !(o == null || getClass() != o.getClass()) && this.toString().equals(o.toString()); return this == o || !(o == null || getClass() != o.getClass()) && this.toString().equals(o.toString());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return toString().hashCode(); return toString().hashCode();
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
visitSelectClause(sql); visitSelectClause(sql);
visitFromClause(sql); visitFromClause(sql);
visitJoinClause(sql); visitJoinClause(sql);
if(queryTemplate == null) { if(queryTemplate == null) {
visitWhereClause(sql); visitWhereClause(sql);
visitGroupByClause(sql); visitGroupByClause(sql);
visitOrderByClause(sql); visitOrderByClause(sql);
visitLimitClause(sql); visitLimitClause(sql);
} else { } else {
if(groupBies.size() > 0 || orders.size() > 0 || if(groupBies.size() > 0 || orders.size() > 0 ||
havings.size() > 0) havings.size() > 0)
throw new IllegalStateException("Can't have extras AND query template"); //$NON-NLS-1$ throw new IllegalStateException("Can't have extras AND query template"); //$NON-NLS-1$
sql.append(queryTemplate); sql.append(queryTemplate);
} }
return sql.toString(); return sql.toString();
} }
private void visitOrderByClause(StringBuilder sql) { private void visitOrderByClause(StringBuilder sql) {
if (orders.isEmpty()) { if (orders.isEmpty()) {
return; return;
} }
sql.append(ORDER_BY); sql.append(ORDER_BY);
for (Order order : orders) { for (Order order : orders) {
sql.append(SPACE).append(order).append(COMMA); sql.append(SPACE).append(order).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
private void visitGroupByClause(StringBuilder sql) { private void visitGroupByClause(StringBuilder sql) {
if (groupBies.isEmpty()) { if (groupBies.isEmpty()) {
return; return;
} }
sql.append(GROUP_BY); sql.append(GROUP_BY);
for (Field groupBy : groupBies) { for (Field groupBy : groupBies) {
sql.append(SPACE).append(groupBy).append(COMMA); sql.append(SPACE).append(groupBy).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
if (havings.isEmpty()) { if (havings.isEmpty()) {
return; return;
} }
sql.append("HAVING"); sql.append("HAVING");
for (Criterion havingCriterion : havings) { for (Criterion havingCriterion : havings) {
sql.append(SPACE).append(havingCriterion).append(COMMA); sql.append(SPACE).append(havingCriterion).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
} }
private void visitWhereClause(StringBuilder sql) { private void visitWhereClause(StringBuilder sql) {
if (criterions.isEmpty()) { if (criterions.isEmpty()) {
return; return;
} }
sql.append(WHERE); sql.append(WHERE);
for (Criterion criterion : criterions) { for (Criterion criterion : criterions) {
sql.append(SPACE).append(criterion).append(SPACE); sql.append(SPACE).append(criterion).append(SPACE);
} }
} }
private void visitJoinClause(StringBuilder sql) { private void visitJoinClause(StringBuilder sql) {
for (Join join : joins) { for (Join join : joins) {
sql.append(join).append(SPACE); sql.append(join).append(SPACE);
} }
} }
private void visitFromClause(StringBuilder sql) { private void visitFromClause(StringBuilder sql) {
if (table == null) { if (table == null) {
return; return;
} }
sql.append(FROM).append(SPACE).append(table).append(SPACE); sql.append(FROM).append(SPACE).append(table).append(SPACE);
} }
private void visitSelectClause(StringBuilder sql) { private void visitSelectClause(StringBuilder sql) {
sql.append(SELECT).append(SPACE); sql.append(SELECT).append(SPACE);
if (fields.isEmpty()) { if (fields.isEmpty()) {
sql.append(ALL).append(SPACE); sql.append(ALL).append(SPACE);
return; return;
} }
for (Field field : fields) { for (Field field : fields) {
sql.append(field.toStringInSelect()).append(COMMA); sql.append(field.toStringInSelect()).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
} }
private void visitLimitClause(StringBuilder sql) { private void visitLimitClause(StringBuilder sql) {
if(limits > -1) if(limits > -1)
sql.append(LIMIT).append(SPACE).append(limits).append(SPACE); sql.append(LIMIT).append(SPACE).append(limits).append(SPACE);
} }
public SqlTable as(String alias) { public SqlTable as(String alias) {
return table(LEFT_PARENTHESIS + this.toString() + RIGHT_PARENTHESIS).as(alias); return table(LEFT_PARENTHESIS + this.toString() + RIGHT_PARENTHESIS).as(alias);
} }
public Query having(Criterion criterion) { public Query having(Criterion criterion) {
this.havings.add(criterion); this.havings.add(criterion);
return this; return this;
} }
/** /**
* Gets a list of fields returned by this query * Gets a list of fields returned by this query
* @return * @return
*/ */
public Property<?>[] getFields() { public Property<?>[] getFields() {
return fields.toArray(new Property<?>[fields.size()]); return fields.toArray(new Property<?>[fields.size()]);
} }
/** /**
* Add the SQL query template (comes after the "from") * Add the SQL query template (comes after the "from")
* @param sqlQuery * @param sqlQuery
* @return * @return
*/ */
public Query withQueryTemplate(String template) { public Query withQueryTemplate(String template) {
queryTemplate = template; queryTemplate = template;
return this; return this;
} }
} }

@ -1,117 +1,117 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.COMMA; import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY; import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY;
import static com.todoroo.andlib.sql.SqlConstants.LIMIT; import static com.todoroo.andlib.sql.SqlConstants.LIMIT;
import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY; import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.WHERE; import static com.todoroo.andlib.sql.SqlConstants.WHERE;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Query Template returns a bunch of criteria that allows a query to be * Query Template returns a bunch of criteria that allows a query to be
* constructed * constructed
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public final class QueryTemplate { public final class QueryTemplate {
private final ArrayList<Criterion> criterions = new ArrayList<Criterion>(); private final ArrayList<Criterion> criterions = new ArrayList<Criterion>();
private final ArrayList<Join> joins = new ArrayList<Join>(); private final ArrayList<Join> joins = new ArrayList<Join>();
private final ArrayList<Field> groupBies = new ArrayList<Field>(); private final ArrayList<Field> groupBies = new ArrayList<Field>();
private final ArrayList<Order> orders = new ArrayList<Order>(); private final ArrayList<Order> orders = new ArrayList<Order>();
private final ArrayList<Criterion> havings = new ArrayList<Criterion>(); private final ArrayList<Criterion> havings = new ArrayList<Criterion>();
private Integer limit = null; private Integer limit = null;
public QueryTemplate join(Join... join) { public QueryTemplate join(Join... join) {
joins.addAll(asList(join)); joins.addAll(asList(join));
return this; return this;
} }
public QueryTemplate where(Criterion criterion) { public QueryTemplate where(Criterion criterion) {
criterions.add(criterion); criterions.add(criterion);
return this; return this;
} }
public QueryTemplate groupBy(Field... groupBy) { public QueryTemplate groupBy(Field... groupBy) {
groupBies.addAll(asList(groupBy)); groupBies.addAll(asList(groupBy));
return this; return this;
} }
public QueryTemplate orderBy(Order... order) { public QueryTemplate orderBy(Order... order) {
orders.addAll(asList(order)); orders.addAll(asList(order));
return this; return this;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
visitJoinClause(sql); visitJoinClause(sql);
visitWhereClause(sql); visitWhereClause(sql);
visitGroupByClause(sql); visitGroupByClause(sql);
visitOrderByClause(sql); visitOrderByClause(sql);
if(limit != null) if(limit != null)
sql.append(LIMIT).append(SPACE).append(limit); sql.append(LIMIT).append(SPACE).append(limit);
return sql.toString(); return sql.toString();
} }
private void visitOrderByClause(StringBuilder sql) { private void visitOrderByClause(StringBuilder sql) {
if (orders.isEmpty()) { if (orders.isEmpty()) {
return; return;
} }
sql.append(ORDER_BY); sql.append(ORDER_BY);
for (Order order : orders) { for (Order order : orders) {
sql.append(SPACE).append(order).append(COMMA); sql.append(SPACE).append(order).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
private void visitGroupByClause(StringBuilder sql) { private void visitGroupByClause(StringBuilder sql) {
if (groupBies.isEmpty()) { if (groupBies.isEmpty()) {
return; return;
} }
sql.append(GROUP_BY); sql.append(GROUP_BY);
for (Field groupBy : groupBies) { for (Field groupBy : groupBies) {
sql.append(SPACE).append(groupBy).append(COMMA); sql.append(SPACE).append(groupBy).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
if (havings.isEmpty()) { if (havings.isEmpty()) {
return; return;
} }
sql.append("HAVING"); sql.append("HAVING");
for (Criterion havingCriterion : havings) { for (Criterion havingCriterion : havings) {
sql.append(SPACE).append(havingCriterion).append(COMMA); sql.append(SPACE).append(havingCriterion).append(COMMA);
} }
sql.deleteCharAt(sql.length() - 1).append(SPACE); sql.deleteCharAt(sql.length() - 1).append(SPACE);
} }
private void visitWhereClause(StringBuilder sql) { private void visitWhereClause(StringBuilder sql) {
if (criterions.isEmpty()) { if (criterions.isEmpty()) {
return; return;
} }
sql.append(WHERE); sql.append(WHERE);
for (Criterion criterion : criterions) { for (Criterion criterion : criterions) {
sql.append(SPACE).append(criterion).append(SPACE); sql.append(SPACE).append(criterion).append(SPACE);
} }
} }
private void visitJoinClause(StringBuilder sql) { private void visitJoinClause(StringBuilder sql) {
for (Join join : joins) { for (Join join : joins) {
sql.append(join).append(SPACE); sql.append(join).append(SPACE);
} }
} }
public QueryTemplate having(Criterion criterion) { public QueryTemplate having(Criterion criterion) {
this.havings.add(criterion); this.havings.add(criterion);
return this; return this;
} }
public QueryTemplate limit(int limitValue) { public QueryTemplate limit(int limitValue) {
this.limit = limitValue; this.limit = limitValue;
return this; return this;
} }
} }

@ -1,25 +1,25 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public final class SqlConstants { public final class SqlConstants {
static final String SELECT = "SELECT"; static final String SELECT = "SELECT";
static final String SPACE = " "; static final String SPACE = " ";
static final String AS = "AS"; static final String AS = "AS";
static final String COMMA = ","; static final String COMMA = ",";
static final String FROM = "FROM"; static final String FROM = "FROM";
static final String ON = "ON"; static final String ON = "ON";
static final String JOIN = "JOIN"; static final String JOIN = "JOIN";
static final String ALL = "*"; static final String ALL = "*";
static final String LEFT_PARENTHESIS = "("; static final String LEFT_PARENTHESIS = "(";
static final String RIGHT_PARENTHESIS = ")"; static final String RIGHT_PARENTHESIS = ")";
static final String AND = "AND"; static final String AND = "AND";
static final String BETWEEN = "BETWEEN"; static final String BETWEEN = "BETWEEN";
static final String LIKE = "LIKE"; static final String LIKE = "LIKE";
static final String OR = "OR"; static final String OR = "OR";
static final String ORDER_BY = "ORDER BY"; static final String ORDER_BY = "ORDER BY";
static final String GROUP_BY = "GROUP BY"; static final String GROUP_BY = "GROUP BY";
static final String WHERE = "WHERE"; static final String WHERE = "WHERE";
public static final String EXISTS = "EXISTS"; public static final String EXISTS = "EXISTS";
public static final String NOT = "NOT"; public static final String NOT = "NOT";
public static final String LIMIT = "LIMIT"; public static final String LIMIT = "LIMIT";
} }

@ -1,20 +1,20 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
public class SqlTable extends DBObject<SqlTable> { public class SqlTable extends DBObject<SqlTable> {
protected SqlTable(String expression) { protected SqlTable(String expression) {
super(expression); super(expression);
} }
public static SqlTable table(String table) { public static SqlTable table(String table) {
return new SqlTable(table); return new SqlTable(table);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
protected String fieldExpression(String fieldName) { protected String fieldExpression(String fieldName) {
if (hasAlias()) { if (hasAlias()) {
return alias + "." + fieldName; return alias + "." + fieldName;
} }
return expression+"."+fieldName; return expression+"."+fieldName;
} }
} }

@ -1,107 +1,107 @@
package com.todoroo.andlib.sql; package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.SqlConstants.SPACE; import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class UnaryCriterion extends Criterion { public class UnaryCriterion extends Criterion {
protected final Field expression; protected final Field expression;
protected final Object value; protected final Object value;
UnaryCriterion(Field expression, Operator operator, Object value) { UnaryCriterion(Field expression, Operator operator, Object value) {
super(operator); super(operator);
this.expression = expression; this.expression = expression;
this.value = value; this.value = value;
} }
@Override @Override
protected void populate(StringBuilder sb) { protected void populate(StringBuilder sb) {
beforePopulateOperator(sb); beforePopulateOperator(sb);
populateOperator(sb); populateOperator(sb);
afterPopulateOperator(sb); afterPopulateOperator(sb);
} }
public static Criterion eq(Field expression, Object value) { public static Criterion eq(Field expression, Object value) {
return new UnaryCriterion(expression, Operator.eq, value); return new UnaryCriterion(expression, Operator.eq, value);
} }
protected void beforePopulateOperator(StringBuilder sb) { protected void beforePopulateOperator(StringBuilder sb) {
sb.append(expression); sb.append(expression);
} }
protected void populateOperator(StringBuilder sb) { protected void populateOperator(StringBuilder sb) {
sb.append(operator); sb.append(operator);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
protected void afterPopulateOperator(StringBuilder sb) { protected void afterPopulateOperator(StringBuilder sb) {
if(value == null) if(value == null)
return; return;
else if(value instanceof String) else if(value instanceof String)
sb.append("'").append(sanitize((String) value)).append("'"); sb.append("'").append(sanitize((String) value)).append("'");
else else
sb.append(value); sb.append(value);
} }
/** /**
* Sanitize the given input for SQL * Sanitize the given input for SQL
* @param input * @param input
* @return * @return
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static String sanitize(String input) { public static String sanitize(String input) {
return input.replace("'", "''"); return input.replace("'", "''");
} }
public static Criterion neq(Field field, Object value) { public static Criterion neq(Field field, Object value) {
return new UnaryCriterion(field, Operator.neq, value); return new UnaryCriterion(field, Operator.neq, value);
} }
public static Criterion gt(Field field, Object value) { public static Criterion gt(Field field, Object value) {
return new UnaryCriterion(field, Operator.gt, value); return new UnaryCriterion(field, Operator.gt, value);
} }
public static Criterion lt(Field field, Object value) { public static Criterion lt(Field field, Object value) {
return new UnaryCriterion(field, Operator.lt, value); return new UnaryCriterion(field, Operator.lt, value);
} }
public static Criterion isNull(Field field) { public static Criterion isNull(Field field) {
return new UnaryCriterion(field, Operator.isNull, null) { return new UnaryCriterion(field, Operator.isNull, null) {
@Override @Override
protected void populateOperator(StringBuilder sb) { protected void populateOperator(StringBuilder sb) {
sb.append(SPACE).append(operator); sb.append(SPACE).append(operator);
} }
}; };
} }
public static Criterion isNotNull(Field field) { public static Criterion isNotNull(Field field) {
return new UnaryCriterion(field, Operator.isNotNull, null) { return new UnaryCriterion(field, Operator.isNotNull, null) {
@Override @Override
protected void populateOperator(StringBuilder sb) { protected void populateOperator(StringBuilder sb) {
sb.append(SPACE).append(operator); sb.append(SPACE).append(operator);
} }
}; };
} }
public static Criterion like(Field field, String value) { public static Criterion like(Field field, String value) {
return new UnaryCriterion(field, Operator.like, value) { return new UnaryCriterion(field, Operator.like, value) {
@Override @Override
protected void populateOperator(StringBuilder sb) { protected void populateOperator(StringBuilder sb) {
sb.append(SPACE).append(operator).append(SPACE); sb.append(SPACE).append(operator).append(SPACE);
} }
}; };
} }
public static Criterion like(Field field, String value, final String escape) { public static Criterion like(Field field, String value, final String escape) {
return new UnaryCriterion(field, Operator.like, value) { return new UnaryCriterion(field, Operator.like, value) {
@Override @Override
protected void populateOperator(StringBuilder sb) { protected void populateOperator(StringBuilder sb) {
sb.append(SPACE).append(operator).append(SPACE); sb.append(SPACE).append(operator).append(SPACE);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
protected void afterPopulateOperator(StringBuilder sb) { protected void afterPopulateOperator(StringBuilder sb) {
super.afterPopulateOperator(sb); super.afterPopulateOperator(sb);
sb.append(SPACE).append("ESCAPE").append(" '").append(sanitize(escape)).append("'"); sb.append(SPACE).append("ESCAPE").append(" '").append(sanitize(escape)).append("'");
} }
}; };
} }
} }

@ -1,146 +1,146 @@
package com.todoroo.astrid.gcal; package com.todoroo.astrid.gcal;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class Calendars { public class Calendars {
public static final String CALENDAR_CONTENT_CALENDARS = "calendars"; public static final String CALENDAR_CONTENT_CALENDARS = "calendars";
public static final String CALENDAR_CONTENT_EVENTS = "events"; public static final String CALENDAR_CONTENT_EVENTS = "events";
private static final String ID_COLUMN_NAME = "_id"; private static final String ID_COLUMN_NAME = "_id";
private static final String DISPLAY_COLUMN_NAME = "displayName"; private static final String DISPLAY_COLUMN_NAME = "displayName";
private static final String ACCES_LEVEL_COLUMN_NAME = "access_level"; private static final String ACCES_LEVEL_COLUMN_NAME = "access_level";
private static final String[] CALENDARS_PROJECTION = new String[] { private static final String[] CALENDARS_PROJECTION = new String[] {
ID_COLUMN_NAME, // Calendars._ID, ID_COLUMN_NAME, // Calendars._ID,
DISPLAY_COLUMN_NAME // Calendars.DISPLAY_NAME DISPLAY_COLUMN_NAME // Calendars.DISPLAY_NAME
}; };
// Only show calendars that the user can modify. Access level 500 // Only show calendars that the user can modify. Access level 500
// corresponds to Calendars.CONTRIBUTOR_ACCESS // corresponds to Calendars.CONTRIBUTOR_ACCESS
private static final String CALENDARS_WHERE = ACCES_LEVEL_COLUMN_NAME + ">= 500"; private static final String CALENDARS_WHERE = ACCES_LEVEL_COLUMN_NAME + ">= 500";
private static final String CALENDARS_SORT = "displayName ASC"; private static final String CALENDARS_SORT = "displayName ASC";
// --- api access // --- api access
/** Return content uri for calendars /** Return content uri for calendars
* @param table provider table, something like calendars, events * @param table provider table, something like calendars, events
*/ */
public static Uri getCalendarContentUri(String table) { public static Uri getCalendarContentUri(String table) {
if(AndroidUtilities.getSdkVersion() >= 8) if(AndroidUtilities.getSdkVersion() >= 8)
return Uri.parse("content://com.android.calendar/" + table); return Uri.parse("content://com.android.calendar/" + table);
else else
return Uri.parse("content://calendar/" + table); return Uri.parse("content://calendar/" + table);
} }
/** Return calendar package name */ /** Return calendar package name */
public static String getCalendarPackage() { public static String getCalendarPackage() {
if(AndroidUtilities.getSdkVersion() >= 8) if(AndroidUtilities.getSdkVersion() >= 8)
return "com.google.android.calendar"; return "com.google.android.calendar";
else else
return "com.android.calendar"; return "com.android.calendar";
} }
// --- helper data structure // --- helper data structure
/** /**
* Helper class for working with the results of getCalendars * Helper class for working with the results of getCalendars
*/ */
public static class CalendarResult { public static class CalendarResult {
/** calendar names */ /** calendar names */
public String[] calendars; public String[] calendars;
/** calendar ids. null entry -> use default */ /** calendar ids. null entry -> use default */
public String[] calendarIds; public String[] calendarIds;
/** default selection index */ /** default selection index */
public int defaultIndex = -1; public int defaultIndex = -1;
} }
/** /**
* Appends all user-modifiable calendars to listPreference. Always includes * Appends all user-modifiable calendars to listPreference. Always includes
* entry called "Astrid default" with calendar id of * entry called "Astrid default" with calendar id of
* prefs_defaultCalendar_default. * prefs_defaultCalendar_default.
* *
* @param context * @param context
* context * context
* @param listPreference * @param listPreference
* preference to init * preference to init
*/ */
public static CalendarResult getCalendars() { public static CalendarResult getCalendars() {
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
ContentResolver cr = context.getContentResolver(); ContentResolver cr = context.getContentResolver();
Resources r = context.getResources(); Resources r = context.getResources();
Cursor c = cr.query(getCalendarContentUri(CALENDAR_CONTENT_CALENDARS), CALENDARS_PROJECTION, Cursor c = cr.query(getCalendarContentUri(CALENDAR_CONTENT_CALENDARS), CALENDARS_PROJECTION,
CALENDARS_WHERE, null, CALENDARS_SORT); CALENDARS_WHERE, null, CALENDARS_SORT);
try { try {
// Fetch the current setting. Invalid calendar id will // Fetch the current setting. Invalid calendar id will
// be changed to default value. // be changed to default value.
String defaultSetting = Preferences.getStringValue(R.string.gcal_p_default); String defaultSetting = Preferences.getStringValue(R.string.gcal_p_default);
CalendarResult result = new CalendarResult(); CalendarResult result = new CalendarResult();
if (c == null || c.getCount() == 0) { if (c == null || c.getCount() == 0) {
// Something went wrong when querying calendars. Only offer them // Something went wrong when querying calendars. Only offer them
// the system default choice // the system default choice
result.calendars = new String[] { result.calendars = new String[] {
r.getString(R.string.gcal_GCP_default) }; r.getString(R.string.gcal_GCP_default) };
result.calendarIds = new String[] { null }; result.calendarIds = new String[] { null };
result.defaultIndex = 0; result.defaultIndex = 0;
return result; return result;
} }
int calendarCount = c.getCount(); int calendarCount = c.getCount();
result.calendars = new String[calendarCount]; result.calendars = new String[calendarCount];
result.calendarIds = new String[calendarCount]; result.calendarIds = new String[calendarCount];
// Iterate calendars one by one, and fill up the list preference // Iterate calendars one by one, and fill up the list preference
int row = 0; int row = 0;
int idColumn = c.getColumnIndex(ID_COLUMN_NAME); int idColumn = c.getColumnIndex(ID_COLUMN_NAME);
int nameColumn = c.getColumnIndex(DISPLAY_COLUMN_NAME); int nameColumn = c.getColumnIndex(DISPLAY_COLUMN_NAME);
while (c.moveToNext()) { while (c.moveToNext()) {
String id = c.getString(idColumn); String id = c.getString(idColumn);
String name = c.getString(nameColumn); String name = c.getString(nameColumn);
result.calendars[row] = name; result.calendars[row] = name;
result.calendarIds[row] = id; result.calendarIds[row] = id;
// We found currently selected calendar // We found currently selected calendar
if (defaultSetting != null && defaultSetting.equals(id)) { if (defaultSetting != null && defaultSetting.equals(id)) {
result.defaultIndex = row; result.defaultIndex = row;
} }
row++; row++;
} }
if (result.defaultIndex == -1 || result.defaultIndex >= calendarCount) { if (result.defaultIndex == -1 || result.defaultIndex >= calendarCount) {
result.defaultIndex = 0; result.defaultIndex = 0;
} }
return result; return result;
} finally { } finally {
if(c != null) if(c != null)
c.close(); c.close();
} }
} }
/** /**
* sets the default calendar for future use * sets the default calendar for future use
* @param defaultCalendar default calendar id * @param defaultCalendar default calendar id
*/ */
public static void setDefaultCalendar(String defaultCalendar) { public static void setDefaultCalendar(String defaultCalendar) {
Preferences.setString(R.string.gcal_p_default, defaultCalendar); Preferences.setString(R.string.gcal_p_default, defaultCalendar);
} }
} }

@ -62,7 +62,7 @@ public class NoteDetailExposer extends BroadcastReceiver implements DetailExpose
if(notes.length() == 0) if(notes.length() == 0)
return null; return null;
return notes; return "<img src='silk_note'/> " + notes; //$NON-NLS-1$
} }
@Override @Override

@ -7,7 +7,6 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
@ -76,8 +75,7 @@ public class ProducteevDetailExposer extends BroadcastReceiver implements Detail
!= Preferences.getLong(ProducteevUtilities.PREF_DEFAULT_DASHBOARD, 0L) && != Preferences.getLong(ProducteevUtilities.PREF_DEFAULT_DASHBOARD, 0L) &&
ownerDashboard != null) { ownerDashboard != null) {
String dashboardName = ownerDashboard.getValue(ProducteevDashboard.NAME); String dashboardName = ownerDashboard.getValue(ProducteevDashboard.NAME);
builder.append(context.getString(R.string.producteev_TLA_dashboard, builder.append("<img src='silk_script'/> ").append(dashboardName).append(TaskAdapter.DETAIL_SEPARATOR); //$NON-NLS-1$
dashboardName)).append(TaskAdapter.DETAIL_SEPARATOR);
} }
// display responsible user if not current one // display responsible user if not current one
@ -88,8 +86,7 @@ public class ProducteevDetailExposer extends BroadcastReceiver implements Detail
if(index > -1) { if(index > -1) {
String user = users.substring(users.indexOf(',', index) + 1, String user = users.substring(users.indexOf(',', index) + 1,
users.indexOf(';', index + 1)); users.indexOf(';', index + 1));
builder.append(context.getString(R.string.producteev_TLA_responsible, builder.append("<img src='silk_user_gray'/> ").append(user).append(TaskAdapter.DETAIL_SEPARATOR); //$NON-NLS-1$
user)).append(TaskAdapter.DETAIL_SEPARATOR);
} }
} }
} else { } else {

@ -1,149 +1,149 @@
/* /*
* ASTRID: Android's Simple Task Recording Dashboard * ASTRID: Android's Simple Task Recording Dashboard
* *
* Copyright (c) 2009 Tim Su * Copyright (c) 2009 Tim Su
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.todoroo.astrid.reminders; package com.todoroo.astrid.reminders;
import java.util.Date; import java.util.Date;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener; import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
/** /**
* This activity is launched when a user opens up a notification from the * This activity is launched when a user opens up a notification from the
* tray. It launches the appropriate activity based on the passed in parameters. * tray. It launches the appropriate activity based on the passed in parameters.
* *
* @author timsu * @author timsu
* *
*/ */
public class NotificationActivity extends TaskListActivity implements OnTimeSetListener { public class NotificationActivity extends TaskListActivity implements OnTimeSetListener {
// --- constants // --- constants
/** task id from notification */ /** task id from notification */
public static final String TOKEN_ID = "id"; //$NON-NLS-1$ public static final String TOKEN_ID = "id"; //$NON-NLS-1$
// --- implementation // --- implementation
private long taskId; private long taskId;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
populateFilter(getIntent()); populateFilter(getIntent());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
displayNotificationPopup(); displayNotificationPopup();
} }
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
populateFilter(intent); populateFilter(intent);
super.onNewIntent(intent); super.onNewIntent(intent);
} }
private void populateFilter(Intent intent) { private void populateFilter(Intent intent) {
taskId = intent.getLongExtra(TOKEN_ID, -1); taskId = intent.getLongExtra(TOKEN_ID, -1);
if(taskId == -1) if(taskId == -1)
return; return;
Filter itemFilter = new Filter(getString(R.string.rmd_NoA_filter), Filter itemFilter = new Filter(getString(R.string.rmd_NoA_filter),
getString(R.string.rmd_NoA_filter), getString(R.string.rmd_NoA_filter),
new QueryTemplate().where(TaskCriteria.byId(taskId)), new QueryTemplate().where(TaskCriteria.byId(taskId)),
null); null);
intent.putExtra(TaskListActivity.TOKEN_FILTER, itemFilter); intent.putExtra(TaskListActivity.TOKEN_FILTER, itemFilter);
} }
/** /**
* Set up the UI for this activity * Set up the UI for this activity
*/ */
private void displayNotificationPopup() { private void displayNotificationPopup() {
// hide quick add // hide quick add
findViewById(R.id.taskListFooter).setVisibility(View.GONE); findViewById(R.id.taskListFooter).setVisibility(View.GONE);
// instantiate reminder window // instantiate reminder window
ViewGroup parent = (ViewGroup) findViewById(R.id.taskListParent); ViewGroup parent = (ViewGroup) findViewById(R.id.taskListParent);
getLayoutInflater().inflate(R.layout.notification_control, parent, true); getLayoutInflater().inflate(R.layout.notification_control, parent, true);
String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.reminder_responses)); String reminder = Notifications.getRandomReminder(getResources().getStringArray(R.array.reminder_responses));
if(Preferences.getBoolean(R.string.p_rmd_nagging, true)) if(Preferences.getBoolean(R.string.p_rmd_nagging, true))
((TextView)findViewById(R.id.reminderLabel)).setText(reminder); ((TextView)findViewById(R.id.reminderLabel)).setText(reminder);
else { else {
findViewById(R.id.reminderLabel).setVisibility(View.GONE); findViewById(R.id.reminderLabel).setVisibility(View.GONE);
findViewById(R.id.astridIcon).setVisibility(View.GONE); findViewById(R.id.astridIcon).setVisibility(View.GONE);
} }
// set up listeners // set up listeners
((Button)findViewById(R.id.goAway)).setOnClickListener(new OnClickListener() { ((Button)findViewById(R.id.goAway)).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
finish(); finish();
} }
}); });
((Button)findViewById(R.id.snooze)).setOnClickListener(new OnClickListener() { ((Button)findViewById(R.id.snooze)).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
snooze(); snooze();
} }
}); });
} }
/** /**
* Snooze and re-trigger this alarm * Snooze and re-trigger this alarm
*/ */
private void snooze() { private void snooze() {
Date now = new Date(); Date now = new Date();
now.setHours(now.getHours() + 1); now.setHours(now.getHours() + 1);
int hour = now.getHours(); int hour = now.getHours();
int minute = now.getMinutes(); int minute = now.getMinutes();
TimePickerDialog timePicker = new TimePickerDialog(this, this, TimePickerDialog timePicker = new TimePickerDialog(this, this,
hour, minute, DateUtilities.is24HourFormat(this)); hour, minute, DateUtilities.is24HourFormat(this));
timePicker.show(); timePicker.show();
} }
/** snooze timer set */ /** snooze timer set */
@Override @Override
public void onTimeSet(TimePicker picker, int hours, int minutes) { public void onTimeSet(TimePicker picker, int hours, int minutes) {
Date alarmTime = new Date(); Date alarmTime = new Date();
alarmTime.setHours(hours); alarmTime.setHours(hours);
alarmTime.setMinutes(minutes); alarmTime.setMinutes(minutes);
if(alarmTime.getTime() < DateUtilities.now()) if(alarmTime.getTime() < DateUtilities.now())
alarmTime.setDate(alarmTime.getDate() + 1); alarmTime.setDate(alarmTime.getDate() + 1);
ReminderService.getInstance().scheduleSnoozeAlarm(taskId, alarmTime.getTime()); ReminderService.getInstance().scheduleSnoozeAlarm(taskId, alarmTime.getTime());
finish(); finish();
} }
} }

@ -114,7 +114,7 @@ public class RepeatDetailExposer extends BroadcastReceiver implements DetailExpo
else else
detail = context.getString(R.string.repeat_detail_duedate, interval); detail = context.getString(R.string.repeat_detail_duedate, interval);
return detail; return "<img src='silk_date'/> " + detail; //$NON-NLS-1$
} }
return null; return null;
} }

@ -1,128 +1,128 @@
package com.todoroo.astrid.rmilk; package com.todoroo.astrid.rmilk;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.rmilk.sync.RTMSyncProvider; import com.todoroo.astrid.rmilk.sync.RTMSyncProvider;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
/** /**
* SynchronizationService is the service that performs Astrid's background * SynchronizationService is the service that performs Astrid's background
* synchronization with online task managers. Starting this service * synchronization with online task managers. Starting this service
* schedules a repeating alarm which handles the synchronization * schedules a repeating alarm which handles the synchronization
* *
* @author Tim Su * @author Tim Su
* *
*/ */
public class MilkBackgroundService extends Service { public class MilkBackgroundService extends Service {
/** Minimum time before an auto-sync */ /** Minimum time before an auto-sync */
private static final long AUTO_SYNC_MIN_OFFSET = 5*60*1000L; private static final long AUTO_SYNC_MIN_OFFSET = 5*60*1000L;
/** alarm identifier */ /** alarm identifier */
private static final String SYNC_ACTION = "sync"; //$NON-NLS-1$ private static final String SYNC_ACTION = "sync"; //$NON-NLS-1$
// --- BroadcastReceiver abstract methods // --- BroadcastReceiver abstract methods
/** Receive the alarm - start the synchronize service! */ /** Receive the alarm - start the synchronize service! */
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
if(SYNC_ACTION.equals(intent.getAction())) if(SYNC_ACTION.equals(intent.getAction()))
startSynchronization(this); startSynchronization(this);
} }
/** Start the actual synchronization */ /** Start the actual synchronization */
private void startSynchronization(Context context) { private void startSynchronization(Context context) {
if(context == null || context.getResources() == null) if(context == null || context.getResources() == null)
return; return;
ContextManager.setContext(context); ContextManager.setContext(context);
if(MilkUtilities.isOngoing()) if(MilkUtilities.isOngoing())
return; return;
new RTMSyncProvider().synchronize(context); new RTMSyncProvider().synchronize(context);
} }
// --- alarm management // --- alarm management
/** /**
* Schedules repeating alarm for auto-synchronization * Schedules repeating alarm for auto-synchronization
*/ */
public static void scheduleService() { public static void scheduleService() {
int syncFrequencySeconds = Preferences.getIntegerFromString( int syncFrequencySeconds = Preferences.getIntegerFromString(
R.string.rmilk_MPr_interval_key, -1); R.string.rmilk_MPr_interval_key, -1);
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
if(syncFrequencySeconds <= 0) { if(syncFrequencySeconds <= 0) {
unscheduleService(context); unscheduleService(context);
return; return;
} }
// figure out synchronization frequency // figure out synchronization frequency
long interval = 1000L * syncFrequencySeconds; long interval = 1000L * syncFrequencySeconds;
long offset = computeNextSyncOffset(interval); long offset = computeNextSyncOffset(interval);
// give a little padding // give a little padding
offset = Math.max(offset, AUTO_SYNC_MIN_OFFSET); offset = Math.max(offset, AUTO_SYNC_MIN_OFFSET);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT); createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
Log.i("Astrid", "Autosync set for " + offset / 1000 //$NON-NLS-1$ //$NON-NLS-2$ Log.i("Astrid", "Autosync set for " + offset / 1000 //$NON-NLS-1$ //$NON-NLS-2$
+ " seconds repeating every " + syncFrequencySeconds); //$NON-NLS-1$ + " seconds repeating every " + syncFrequencySeconds); //$NON-NLS-1$
// cancel all existing // cancel all existing
am.cancel(pendingIntent); am.cancel(pendingIntent);
// schedule new // schedule new
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + offset, am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + offset,
interval, pendingIntent); interval, pendingIntent);
} }
/** /**
* Removes repeating alarm for auto-synchronization * Removes repeating alarm for auto-synchronization
*/ */
private static void unscheduleService(Context context) { private static void unscheduleService(Context context) {
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT); createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pendingIntent); am.cancel(pendingIntent);
} }
/** Create the alarm intent */ /** Create the alarm intent */
private static Intent createAlarmIntent(Context context) { private static Intent createAlarmIntent(Context context) {
Intent intent = new Intent(context, MilkBackgroundService.class); Intent intent = new Intent(context, MilkBackgroundService.class);
intent.setAction(SYNC_ACTION); intent.setAction(SYNC_ACTION);
return intent; return intent;
} }
// --- utility methods // --- utility methods
private static long computeNextSyncOffset(long interval) { private static long computeNextSyncOffset(long interval) {
// figure out last synchronize time // figure out last synchronize time
long lastSyncDate = MilkUtilities.getLastSyncDate(); long lastSyncDate = MilkUtilities.getLastSyncDate();
// if user never synchronized, give them a full offset period before bg sync // if user never synchronized, give them a full offset period before bg sync
if(lastSyncDate != 0) if(lastSyncDate != 0)
return Math.max(0, lastSyncDate + interval - DateUtilities.now()); return Math.max(0, lastSyncDate + interval - DateUtilities.now());
else else
return interval; return interval;
} }
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return null; return null;
} }
} }

@ -66,9 +66,8 @@ public class MilkDetailExposer extends BroadcastReceiver implements DetailExpose
if(listName == null) if(listName == null)
return null; return null;
if(listId > 0) { if(listId > 0 && !"Inbox".equals(listName)) { //$NON-NLS-1$
builder.append(context.getString(R.string.rmilk_TLA_list, builder.append("<img src='silk_script'/> ").append(listName).append(TaskAdapter.DETAIL_SEPARATOR); //$NON-NLS-1$
listName)).append(TaskAdapter.DETAIL_SEPARATOR);
} }
int repeat = metadata.getValue(MilkTask.REPEATING); int repeat = metadata.getValue(MilkTask.REPEATING);

@ -1,106 +1,106 @@
/* /*
* Copyright 2007, MetaDimensional Technologies Inc. * Copyright 2007, MetaDimensional Technologies Inc.
* *
* *
* This file is part of the RememberTheMilk Java API. * This file is part of the RememberTheMilk Java API.
* *
* The RememberTheMilk Java API is free software; you can redistribute it * The RememberTheMilk Java API is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License * and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of the * as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* The RememberTheMilk Java API is distributed in the hope that it will be * The RememberTheMilk Java API is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.todoroo.astrid.rmilk.api.data; package com.todoroo.astrid.rmilk.api.data;
import java.util.Date; import java.util.Date;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.EntityReference; import org.w3c.dom.EntityReference;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import android.util.Log; import android.util.Log;
/** /**
* Represents a single task note. * Represents a single task note.
* *
* @author Edouard Mercier * @author Edouard Mercier
* @since 2008.04.22 * @since 2008.04.22
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class RtmTaskNote public class RtmTaskNote
extends RtmData extends RtmData
{ {
private final String id; private final String id;
private final Date created; private final Date created;
private final Date modified; private final Date modified;
private final String title; private final String title;
private String text; private String text;
public RtmTaskNote(Element element) public RtmTaskNote(Element element)
{ {
id = element.getAttribute("id"); id = element.getAttribute("id");
created = parseDate(element.getAttribute("created")); created = parseDate(element.getAttribute("created"));
modified = parseDate(element.getAttribute("modified")); modified = parseDate(element.getAttribute("modified"));
title = element.getAttribute("title"); title = element.getAttribute("title");
// The note text itself might be split across multiple children of the // The note text itself might be split across multiple children of the
// note element, so get all of the children. // note element, so get all of the children.
for (int i=0; i < element.getChildNodes().getLength(); i++) { for (int i=0; i < element.getChildNodes().getLength(); i++) {
Object innerNote = element.getChildNodes().item(i); Object innerNote = element.getChildNodes().item(i);
if(innerNote instanceof EntityReference) // this node is empty if(innerNote instanceof EntityReference) // this node is empty
continue; continue;
if(!(innerNote instanceof Text)) { if(!(innerNote instanceof Text)) {
Log.w("rtm-note", "Expected text type, got " + innerNote.getClass()); Log.w("rtm-note", "Expected text type, got " + innerNote.getClass());
continue; continue;
} }
Text innerText = (Text) innerNote; Text innerText = (Text) innerNote;
if (text == null) if (text == null)
text = innerText.getData(); text = innerText.getData();
else else
text = text.concat(innerText.getData()); text = text.concat(innerText.getData());
} }
} }
public String getId() public String getId()
{ {
return id; return id;
} }
public Date getCreated() public Date getCreated()
{ {
return created; return created;
} }
public Date getModified() public Date getModified()
{ {
return modified; return modified;
} }
public String getTitle() public String getTitle()
{ {
return title; return title;
} }
public String getText() public String getText()
{ {
return text; return text;
} }
} }

@ -7,7 +7,6 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.timsu.astrid.R;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.DetailExposer; import com.todoroo.astrid.api.DetailExposer;
@ -49,7 +48,7 @@ public class TagDetailExposer extends BroadcastReceiver implements DetailExposer
if(tagList.length() == 0) if(tagList.length() == 0)
return null; return null;
return context.getString(R.string.tag_TLA_detail, tagList); return "<img src='silk_tag_pink'/> " + tagList; //$NON-NLS-1$
} }
@Override @Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

@ -1,50 +1,50 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/background_gradient"> android:background="@drawable/background_gradient">
<!-- =================================================== tab: installed == --> <!-- =================================================== tab: installed == -->
<FrameLayout android:id="@+id/tab_installed" <FrameLayout android:id="@+id/tab_installed"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<TextView android:id="@+id/empty_installed" <TextView android:id="@+id/empty_installed"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="center" android:gravity="center"
android:text="@string/TEA_no_addons" android:text="@string/TEA_no_addons"
style="@style/TextAppearance.TLA_NoItems" /> style="@style/TextAppearance.TLA_NoItems" />
<ListView android:id="@+id/installed" <ListView android:id="@+id/installed"
android:paddingRight="8dip" android:paddingRight="8dip"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" /> android:layout_height="fill_parent" />
</FrameLayout> </FrameLayout>
<!-- =================================================== tab: available == --> <!-- =================================================== tab: available == -->
<FrameLayout android:id="@+id/tab_available" <FrameLayout android:id="@+id/tab_available"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<TextView android:id="@+id/empty_available" <TextView android:id="@+id/empty_available"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="center" android:gravity="center"
android:text="@string/TEA_no_addons" android:text="@string/TEA_no_addons"
style="@style/TextAppearance.TLA_NoItems" /> style="@style/TextAppearance.TLA_NoItems" />
<ListView android:id="@+id/available" <ListView android:id="@+id/available"
android:paddingRight="8dip" android:paddingRight="8dip"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" /> android:layout_height="fill_parent" />
</FrameLayout> </FrameLayout>
</FrameLayout> </FrameLayout>

@ -1,304 +1,304 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/background_gradient"> android:background="@drawable/background_gradient">
<!-- ======================================================= tab: basic == --> <!-- ======================================================= tab: basic == -->
<ScrollView <ScrollView
android:id="@+id/tab_basic" android:id="@+id/tab_basic"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<LinearLayout <LinearLayout
android:id="@+id/event" android:id="@+id/event"
android:paddingRight="8dip" android:paddingRight="8dip"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<!-- title --> <!-- title -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_title_label" android:text="@string/TEA_title_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<EditText <EditText
android:id="@+id/title" android:id="@+id/title"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/TEA_title_hint" android:hint="@string/TEA_title_hint"
android:autoText="true" android:autoText="true"
android:capitalize="sentences" /> android:capitalize="sentences" />
<!-- importance --> <!-- importance -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_importance_label" android:text="@string/TEA_importance_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<LinearLayout <LinearLayout
android:id="@+id/importance_container" android:id="@+id/importance_container"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
</LinearLayout> </LinearLayout>
<!-- urgency --> <!-- urgency -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_urgency_label" android:text="@string/TEA_urgency_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<Spinner <Spinner
android:id="@+id/urgency" android:id="@+id/urgency"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<!-- tags --> <!-- tags -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_tags_label" android:text="@string/TEA_tags_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<LinearLayout <LinearLayout
android:id="@+id/tags_container" android:id="@+id/tags_container"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="5dip" android:paddingBottom="5dip"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<!-- separator --> <!-- separator -->
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="1dip" android:layout_height="1dip"
android:padding="5dip" android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" /> android:background="@android:drawable/divider_horizontal_dark" />
<!-- notes --> <!-- notes -->
<TextView <TextView
android:paddingTop="5dip" android:paddingTop="5dip"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_note_label" android:text="@string/TEA_note_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<EditText <EditText
android:id="@+id/notes" android:id="@+id/notes"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:scrollbars="vertical" android:scrollbars="vertical"
android:gravity="top" android:gravity="top"
android:hint="@string/TEA_notes_hint" android:hint="@string/TEA_notes_hint"
android:autoText="true" android:autoText="true"
android:capitalize="sentences" android:capitalize="sentences"
android:singleLine="false" /> android:singleLine="false" />
<!-- buttons --> <!-- buttons -->
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dip" android:layout_marginTop="10dip"
android:padding="5dip" android:padding="5dip"
android:background="@drawable/edit_header" android:background="@drawable/edit_header"
android:baselineAligned="false"> android:baselineAligned="false">
<ImageButton <ImageButton
android:id="@+id/save_basic" android:id="@+id/save_basic"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_save" /> android:src="@drawable/tango_save" />
<ImageButton <ImageButton
android:id="@+id/discard_basic" android:id="@+id/discard_basic"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_stop" /> android:src="@drawable/tango_stop" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<!-- ======================================================= tab: extra == --> <!-- ======================================================= tab: extra == -->
<ScrollView <ScrollView
android:id="@+id/tab_extra" android:id="@+id/tab_extra"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<LinearLayout <LinearLayout
android:paddingRight="8dip" android:paddingRight="8dip"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<!-- reminders --> <!-- reminders -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_reminder_label" android:text="@string/TEA_reminder_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<CheckBox <CheckBox
android:id="@+id/reminder_due" android:id="@+id/reminder_due"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_reminder_due" /> android:text="@string/TEA_reminder_due" />
<CheckBox <CheckBox
android:id="@+id/reminder_overdue" android:id="@+id/reminder_overdue"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_reminder_overdue" /> android:text="@string/TEA_reminder_overdue" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<CheckBox <CheckBox
android:id="@+id/reminder_random" android:id="@+id/reminder_random"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_reminder_random" /> android:text="@string/TEA_reminder_random" />
<Spinner <Spinner
android:id="@+id/reminder_random_interval" android:id="@+id/reminder_random_interval"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
<!-- reminder mode --> <!-- reminder mode -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_reminder_alarm_label" android:text="@string/TEA_reminder_alarm_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<Spinner <Spinner
android:id="@+id/reminder_alarm" android:id="@+id/reminder_alarm"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<!-- separator --> <!-- separator -->
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="1dip" android:layout_height="1dip"
android:padding="5dip" android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" /> android:background="@android:drawable/divider_horizontal_dark" />
<!-- hide until --> <!-- hide until -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_hideUntil_label" android:text="@string/TEA_hideUntil_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<Spinner <Spinner
android:id="@+id/hideUntil" android:id="@+id/hideUntil"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<!-- add-ons --> <!-- add-ons -->
<LinearLayout android:id="@+id/tab_extra_addons" <LinearLayout android:id="@+id/tab_extra_addons"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" /> android:orientation="vertical" />
<!-- buttons --> <!-- buttons -->
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dip" android:layout_marginTop="10dip"
android:padding="5dip" android:padding="5dip"
android:background="@drawable/edit_header" android:background="@drawable/edit_header"
android:baselineAligned="false"> android:baselineAligned="false">
<ImageButton <ImageButton
android:id="@+id/save_extra" android:id="@+id/save_extra"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_save" /> android:src="@drawable/tango_save" />
<ImageButton <ImageButton
android:id="@+id/discard_extra" android:id="@+id/discard_extra"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_stop" /> android:src="@drawable/tango_stop" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<!-- ===================================================== tab: add-ons == --> <!-- ===================================================== tab: add-ons == -->
<LinearLayout <LinearLayout
android:id="@+id/tab_addons" android:id="@+id/tab_addons"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> android:orientation="vertical">
<ScrollView <ScrollView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="100"> android:layout_weight="100">
<!-- add-ons --> <!-- add-ons -->
<LinearLayout android:id="@+id/tab_addons_addons" <LinearLayout android:id="@+id/tab_addons_addons"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" /> android:orientation="vertical" />
</ScrollView> </ScrollView>
<LinearLayout android:id="@+id/addons_empty" <LinearLayout android:id="@+id/addons_empty"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="100" android:layout_weight="100"
android:gravity="center" android:gravity="center"
android:visibility="gone" android:visibility="gone"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="20dip" android:padding="20dip"
android:src="@drawable/icon_pp" /> android:src="@drawable/icon_pp" />
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/TEA_no_addons" android:text="@string/TEA_no_addons"
android:padding="10dip" android:padding="10dip"
android:gravity="center" android:gravity="center"
style="@style/TextAppearance.TLA_NoItems" /> style="@style/TextAppearance.TLA_NoItems" />
<Button android:id="@+id/addons_button" <Button android:id="@+id/addons_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dip" android:padding="10dip"
android:text="@string/TEA_addons_button" /> android:text="@string/TEA_addons_button" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_marginTop="10dip" android:layout_marginTop="10dip"
android:padding="5dip" android:padding="5dip"
android:orientation="horizontal" android:orientation="horizontal"
android:background="@drawable/edit_header" android:background="@drawable/edit_header"
android:baselineAligned="false"> android:baselineAligned="false">
<ImageButton <ImageButton
android:id="@+id/save_addons" android:id="@+id/save_addons"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_save" /> android:src="@drawable/tango_save" />
<ImageButton <ImageButton
android:id="@+id/discard_addons" android:id="@+id/discard_addons"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/tango_stop" /> android:src="@drawable/tango_stop" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

@ -37,9 +37,9 @@
<string name="repeat_detail_byday">$I on $D</string> <string name="repeat_detail_byday">$I on $D</string>
<!-- task detail for repeat from due date (%s -> interval) --> <!-- task detail for repeat from due date (%s -> interval) -->
<string name="repeat_detail_duedate">Repeats every %s</string> <string name="repeat_detail_duedate">Every %s</string>
<!-- task detail for repeat from completion date (%s -> interval) --> <!-- task detail for repeat from completion date (%s -> interval) -->
<string name="repeat_detail_completion">Repeats %s after completion</string> <string name="repeat_detail_completion">%s after completion</string>
</resources> </resources>

@ -11,11 +11,6 @@
<!-- Tags hint --> <!-- Tags hint -->
<string name="TEA_tag_hint">Tag Name</string> <string name="TEA_tag_hint">Tag Name</string>
<!-- ===================================================== Task Details == -->
<!-- tag text that displays in task list. %s => tag name -->
<string name="tag_TLA_detail">Tags: %s</string>
<!-- ========================================================== Filters == --> <!-- ========================================================== Filters == -->

@ -1,63 +1,63 @@
/* /*
* ASTRID: Android's Simple Task Recording Dashboard * ASTRID: Android's Simple Task Recording Dashboard
* *
* Copyright (c) 2009 Tim Su * Copyright (c) 2009 Tim Su
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.timsu.astrid.activities; package com.timsu.astrid.activities;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListActivity;
/** /**
* Legacy task shortcut, takes users to the updated {@link TaskListActivity}. * Legacy task shortcut, takes users to the updated {@link TaskListActivity}.
* This activity is around so users with existing desktop icons will * This activity is around so users with existing desktop icons will
* be able to still launch Astrid. * be able to still launch Astrid.
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public class TaskList extends Activity { public class TaskList extends Activity {
// --- implementation // --- implementation
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
launchTaskList(getIntent()); launchTaskList(getIntent());
} }
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
launchTaskList(intent); launchTaskList(intent);
} }
/** /**
* intent: ignored for now * intent: ignored for now
* @param intent * @param intent
*/ */
private void launchTaskList(Intent intent) { private void launchTaskList(Intent intent) {
Intent taskListIntent = new Intent(this, TaskListActivity.class); Intent taskListIntent = new Intent(this, TaskListActivity.class);
startActivity(taskListIntent); startActivity(taskListIntent);
finish(); finish();
} }
} }

@ -1,144 +1,144 @@
/* /*
* ASTRID: Android's Simple Task Recording Dashboard * ASTRID: Android's Simple Task Recording Dashboard
* *
* Copyright (c) 2009 Tim Su * Copyright (c) 2009 Tim Su
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.todoroo.astrid.activity; package com.todoroo.astrid.activity;
import java.util.Map.Entry; import java.util.Map.Entry;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
/** /**
* This activity is launched when a user opens up a notification from the * This activity is launched when a user opens up a notification from the
* tray. It launches the appropriate activity based on the passed in parameters. * tray. It launches the appropriate activity based on the passed in parameters.
* *
* @author timsu * @author timsu
* *
*/ */
public class ShortcutActivity extends Activity { public class ShortcutActivity extends Activity {
// --- constants // --- constants
/** token for passing a {@link Filter}'s title through extras */ /** token for passing a {@link Filter}'s title through extras */
public static final String TOKEN_FILTER_TITLE = "title"; //$NON-NLS-1$ public static final String TOKEN_FILTER_TITLE = "title"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s sql through extras */ /** token for passing a {@link Filter}'s sql through extras */
public static final String TOKEN_FILTER_SQL = "sql"; //$NON-NLS-1$ public static final String TOKEN_FILTER_SQL = "sql"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras as string */ /** token for passing a {@link Filter}'s values for new tasks through extras as string */
@Deprecated @Deprecated
public static final String TOKEN_FILTER_VALUES = "v4nt"; //$NON-NLS-1$ public static final String TOKEN_FILTER_VALUES = "v4nt"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras as exploded ContentValues */ /** token for passing a {@link Filter}'s values for new tasks through extras as exploded ContentValues */
public static final String TOKEN_FILTER_VALUES_ITEM = "v4ntp_"; //$NON-NLS-1$ public static final String TOKEN_FILTER_VALUES_ITEM = "v4ntp_"; //$NON-NLS-1$
// --- implementation // --- implementation
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
launchTaskList(getIntent()); launchTaskList(getIntent());
} }
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
launchTaskList(intent); launchTaskList(intent);
} }
private void launchTaskList(Intent intent) { private void launchTaskList(Intent intent) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if(extras != null && extras.containsKey(TOKEN_FILTER_SQL)) { if(extras != null && extras.containsKey(TOKEN_FILTER_SQL)) {
// launched from desktop shortcut, must create a fake filter // launched from desktop shortcut, must create a fake filter
String title = extras.getString(TOKEN_FILTER_TITLE); String title = extras.getString(TOKEN_FILTER_TITLE);
String sql = extras.getString(TOKEN_FILTER_SQL); String sql = extras.getString(TOKEN_FILTER_SQL);
ContentValues values = null; ContentValues values = null;
if(extras.containsKey(TOKEN_FILTER_VALUES)) if(extras.containsKey(TOKEN_FILTER_VALUES))
values = AndroidUtilities.contentValuesFromString(extras.getString(TOKEN_FILTER_VALUES)); values = AndroidUtilities.contentValuesFromString(extras.getString(TOKEN_FILTER_VALUES));
else { else {
values = new ContentValues(); values = new ContentValues();
for(String key : extras.keySet()) { for(String key : extras.keySet()) {
if(!key.startsWith(TOKEN_FILTER_VALUES_ITEM)) if(!key.startsWith(TOKEN_FILTER_VALUES_ITEM))
continue; continue;
Object value = extras.get(key); Object value = extras.get(key);
key = key.substring(TOKEN_FILTER_VALUES_ITEM.length()); key = key.substring(TOKEN_FILTER_VALUES_ITEM.length());
// assume one of the big 4... // assume one of the big 4...
if(value instanceof String) if(value instanceof String)
values.put(key, (String) value); values.put(key, (String) value);
else if(value instanceof Integer) else if(value instanceof Integer)
values.put(key, (Integer) value); values.put(key, (Integer) value);
else if(value instanceof Double) else if(value instanceof Double)
values.put(key, (Double) value); values.put(key, (Double) value);
else if(value instanceof Long) else if(value instanceof Long)
values.put(key, (Long) value); values.put(key, (Long) value);
else else
throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$ throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
} }
} }
Filter filter = new Filter("", title, new QueryTemplate(), values); //$NON-NLS-1$ Filter filter = new Filter("", title, new QueryTemplate(), values); //$NON-NLS-1$
filter.sqlQuery = sql; filter.sqlQuery = sql;
Intent taskListIntent = new Intent(this, TaskListActivity.class); Intent taskListIntent = new Intent(this, TaskListActivity.class);
taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter); taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
startActivity(taskListIntent); startActivity(taskListIntent);
} }
finish(); finish();
} }
public static Intent createIntent(Filter filter) { public static Intent createIntent(Filter filter) {
Intent shortcutIntent = new Intent(ContextManager.getContext(), Intent shortcutIntent = new Intent(ContextManager.getContext(),
ShortcutActivity.class); ShortcutActivity.class);
shortcutIntent.setAction(Intent.ACTION_VIEW); shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE, filter.title); shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE, filter.title);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_SQL, filter.sqlQuery); shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_SQL, filter.sqlQuery);
if(filter.valuesForNewTasks != null) { if(filter.valuesForNewTasks != null) {
for(Entry<String, Object> item : filter.valuesForNewTasks.valueSet()) { for(Entry<String, Object> item : filter.valuesForNewTasks.valueSet()) {
String key = TOKEN_FILTER_VALUES_ITEM + item.getKey(); String key = TOKEN_FILTER_VALUES_ITEM + item.getKey();
Object value = item.getValue(); Object value = item.getValue();
// assume one of the big 4... // assume one of the big 4...
if(value instanceof String) if(value instanceof String)
shortcutIntent.putExtra(key, (String) value); shortcutIntent.putExtra(key, (String) value);
else if(value instanceof Integer) else if(value instanceof Integer)
shortcutIntent.putExtra(key, (Integer) value); shortcutIntent.putExtra(key, (Integer) value);
else if(value instanceof Double) else if(value instanceof Double)
shortcutIntent.putExtra(key, (Double) value); shortcutIntent.putExtra(key, (Double) value);
else if(value instanceof Long) else if(value instanceof Long)
shortcutIntent.putExtra(key, (Long) value); shortcutIntent.putExtra(key, (Long) value);
else else
throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$ throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
} }
} }
return shortcutIntent; return shortcutIntent;
} }
} }

@ -13,7 +13,9 @@ import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.Html; import android.text.Html;
import android.text.Html.ImageGetter;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -52,6 +54,7 @@ import com.todoroo.astrid.repeats.RepeatDetailExposer;
import com.todoroo.astrid.rmilk.MilkDetailExposer; import com.todoroo.astrid.rmilk.MilkDetailExposer;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagDetailExposer; import com.todoroo.astrid.tags.TagDetailExposer;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
/** /**
@ -376,6 +379,18 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
*/ */
public class DetailManager extends AddOnManager<String> { public class DetailManager extends AddOnManager<String> {
private final ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Resources r = activity.getResources();
int drawable = r.getIdentifier("drawable/" + source, null, Constants.PACKAGE); //$NON-NLS-1$
if(drawable == 0)
return null;
Drawable d = r.getDrawable(drawable);
d.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight());
return d;
}
};
private final boolean extended; private final boolean extended;
public DetailManager(boolean extended) { public DetailManager(boolean extended) {
this.extended = extended; this.extended = extended;
@ -441,7 +456,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
String string = detailText.toString(); String string = detailText.toString();
if(string.contains("<")) if(string.contains("<"))
view.setText(Html.fromHtml(string.trim().replace("\n", "<br>"))); view.setText(Html.fromHtml(string.trim().replace("\n", "<br>"), imageGetter, null));
else else
view.setText(string.trim()); view.setText(string.trim());
Linkify.addLinks(view, Linkify.ALL); Linkify.addLinks(view, Linkify.ALL);

@ -1,289 +1,289 @@
package com.todoroo.astrid.provider; package com.todoroo.astrid.provider;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.UriMatcher; import android.content.UriMatcher;
import android.database.Cursor; import android.database.Cursor;
import android.database.MatrixCursor; import android.database.MatrixCursor;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag; import com.todoroo.astrid.tags.TagService.Tag;
/** /**
* This is the legacy Astrid task provider. While it will continue to be * This is the legacy Astrid task provider. While it will continue to be
* supported, note that it does not expose all of the information in * supported, note that it does not expose all of the information in
* Astrid, nor does it support many editing operations. * Astrid, nor does it support many editing operations.
* *
* See the individual methods for a description of what is returned. * See the individual methods for a description of what is returned.
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class Astrid2TaskProvider extends ContentProvider { public class Astrid2TaskProvider extends ContentProvider {
static { static {
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
private static final String TAG = "MessageProvider"; private static final String TAG = "MessageProvider";
private static final boolean LOGD = false; private static final boolean LOGD = false;
public static final String AUTHORITY = "com.timsu.astrid.tasksprovider"; public static final String AUTHORITY = "com.timsu.astrid.tasksprovider";
public static final Uri CONTENT_URI = Uri.parse("content://com.timsu.astrid.tasksprovider"); public static final Uri CONTENT_URI = Uri.parse("content://com.timsu.astrid.tasksprovider");
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
private static final int MAX_NUMBER_OF_TASKS = 30; private static final int MAX_NUMBER_OF_TASKS = 30;
private final static String NAME = "name"; private final static String NAME = "name";
private final static String IMPORTANCE_COLOR = "importance_color"; private final static String IMPORTANCE_COLOR = "importance_color";
private final static String IDENTIFIER = "identifier"; private final static String IDENTIFIER = "identifier";
private final static String PREFERRED_DUE_DATE = "preferredDueDate"; private final static String PREFERRED_DUE_DATE = "preferredDueDate";
private final static String DEFINITE_DUE_DATE = "definiteDueDate"; private final static String DEFINITE_DUE_DATE = "definiteDueDate";
private final static String IMPORTANCE = "importance"; private final static String IMPORTANCE = "importance";
private final static String ID = "id"; private final static String ID = "id";
// fake property for updating that completes a task // fake property for updating that completes a task
private final static String COMPLETED = "completed"; private final static String COMPLETED = "completed";
private final static String TAGS_ID = "tags_id"; private final static String TAGS_ID = "tags_id";
static String[] TASK_FIELD_LIST = new String[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE, static String[] TASK_FIELD_LIST = new String[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE,
IMPORTANCE, IDENTIFIER, TAGS_ID }; IMPORTANCE, IDENTIFIER, TAGS_ID };
static String[] TAGS_FIELD_LIST = new String[] { ID, NAME }; static String[] TAGS_FIELD_LIST = new String[] { ID, NAME };
private static final int URI_TASKS = 0; private static final int URI_TASKS = 0;
private static final int URI_TAGS = 1; private static final int URI_TAGS = 1;
private static final String TAG_SEPARATOR = "|"; private static final String TAG_SEPARATOR = "|";
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
private static Context ctx = null; private static Context ctx = null;
static { static {
URI_MATCHER.addURI(AUTHORITY, "tasks", URI_TASKS); URI_MATCHER.addURI(AUTHORITY, "tasks", URI_TASKS);
URI_MATCHER.addURI(AUTHORITY, "tags", URI_TAGS); URI_MATCHER.addURI(AUTHORITY, "tags", URI_TAGS);
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
public Astrid2TaskProvider() { public Astrid2TaskProvider() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
} }
@Override @Override
public int delete(Uri uri, String selection, String[] selectionArgs) { public int delete(Uri uri, String selection, String[] selectionArgs) {
if (LOGD) if (LOGD)
Log.d(TAG, "delete"); Log.d(TAG, "delete");
return 0; return 0;
} }
@Override @Override
public String getType(Uri uri) { public String getType(Uri uri) {
return null; return null;
} }
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(Uri uri, ContentValues values) {
return null; return null;
} }
@Override @Override
public boolean onCreate() { public boolean onCreate() {
ctx = getContext(); ctx = getContext();
return false; return false;
} }
/** /**
* Note: tag id is no longer a real column, so we pass in a UID * Note: tag id is no longer a real column, so we pass in a UID
* generated from the tag string. * generated from the tag string.
* *
* @return two-column cursor: tag id (string) and tag name * @return two-column cursor: tag id (string) and tag name
*/ */
public Cursor getTags() { public Cursor getTags() {
Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE, Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
Criterion.all); Criterion.all);
MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST); MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST);
for (int i = 0; i < tags.length; i++) { for (int i = 0; i < tags.length; i++) {
Object[] values = new Object[2]; Object[] values = new Object[2];
values[0] = tagNameToLong(tags[i].tag); values[0] = tagNameToLong(tags[i].tag);
values[1] = tags[i].tag; values[1] = tags[i].tag;
ret.addRow(values); ret.addRow(values);
} }
return ret; return ret;
} }
private long tagNameToLong(String tag) { private long tagNameToLong(String tag) {
MessageDigest m; MessageDigest m;
try { try {
m = MessageDigest.getInstance("MD5"); m = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
return -1; return -1;
} }
m.update(tag.getBytes(), 0, tag.length()); m.update(tag.getBytes(), 0, tag.length());
return new BigInteger(1, m.digest()).longValue(); return new BigInteger(1, m.digest()).longValue();
} }
/** /**
* Cursor with the following columns * Cursor with the following columns
* <ol> * <ol>
* <li>task title, string * <li>task title, string
* <li>task importance color, int android RGB color * <li>task importance color, int android RGB color
* <li>task due date (was: preferred due date), long millis since epoch * <li>task due date (was: preferred due date), long millis since epoch
* <li>task due date (was: absolute due date), long millis since epoch * <li>task due date (was: absolute due date), long millis since epoch
* <li>task importance, integer from 0 to 3 (0 => most important) * <li>task importance, integer from 0 to 3 (0 => most important)
* <li>task id, long * <li>task id, long
* <li>task tags, string tags separated by | * <li>task tags, string tags separated by |
* </ol> * </ol>
* *
* @return cursor as described above * @return cursor as described above
*/ */
public Cursor getTasks() { public Cursor getTasks() {
MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST); MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST);
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE, TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE,
Task.IMPORTANCE, Task.DUE_DATE).where(Criterion.and(TaskCriteria.isActive(), Task.IMPORTANCE, Task.DUE_DATE).where(Criterion.and(TaskCriteria.isActive(),
TaskCriteria.isVisible())). TaskCriteria.isVisible())).
orderBy(TaskService.defaultTaskOrder()).limit(MAX_NUMBER_OF_TASKS)); orderBy(TaskService.defaultTaskOrder()).limit(MAX_NUMBER_OF_TASKS));
try { try {
int[] importanceColors = Task.getImportanceColors(ctx.getResources()); int[] importanceColors = Task.getImportanceColors(ctx.getResources());
Task task = new Task(); Task task = new Task();
for (int i = 0; i < cursor.getCount(); i++) { for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); task.readFromCursor(cursor);
StringBuilder taskTags = new StringBuilder(); StringBuilder taskTags = new StringBuilder();
TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId()); TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId());
try { try {
for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext()) for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext())
taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR); taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR);
} finally { } finally {
tagCursor.close(); tagCursor.close();
} }
Object[] values = new Object[7]; Object[] values = new Object[7];
values[0] = task.getValue(Task.TITLE); values[0] = task.getValue(Task.TITLE);
values[1] = importanceColors[task.getValue(Task.IMPORTANCE)]; values[1] = importanceColors[task.getValue(Task.IMPORTANCE)];
values[2] = task.getValue(Task.DUE_DATE); values[2] = task.getValue(Task.DUE_DATE);
values[3] = task.getValue(Task.DUE_DATE); values[3] = task.getValue(Task.DUE_DATE);
values[4] = task.getValue(Task.IMPORTANCE); values[4] = task.getValue(Task.IMPORTANCE);
values[5] = task.getId(); values[5] = task.getId();
values[6] = taskTags.toString(); values[6] = taskTags.toString();
ret.addRow(values); ret.addRow(values);
} }
} finally { } finally {
cursor.close(); cursor.close();
} }
return ret; return ret;
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (LOGD) if (LOGD)
Log.d(TAG, "query"); Log.d(TAG, "query");
Cursor cursor; Cursor cursor;
switch (URI_MATCHER.match(uri)) { switch (URI_MATCHER.match(uri)) {
case URI_TASKS: case URI_TASKS:
cursor = getTasks(); cursor = getTasks();
break; break;
case URI_TAGS: case URI_TAGS:
cursor = getTags(); cursor = getTags();
break; break;
default: default:
throw new IllegalStateException("Unrecognized URI:" + uri); throw new IllegalStateException("Unrecognized URI:" + uri);
} }
return cursor; return cursor;
} }
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (LOGD) if (LOGD)
Log.d(TAG, "update"); Log.d(TAG, "update");
switch (URI_MATCHER.match(uri)) { switch (URI_MATCHER.match(uri)) {
case URI_TASKS: case URI_TASKS:
Task task = new Task(); Task task = new Task();
// map values // map values
if(values.containsKey(NAME)) if(values.containsKey(NAME))
task.setValue(Task.TITLE, values.getAsString(NAME)); task.setValue(Task.TITLE, values.getAsString(NAME));
if(values.containsKey(PREFERRED_DUE_DATE)) if(values.containsKey(PREFERRED_DUE_DATE))
task.setValue(Task.DUE_DATE, values.getAsLong(PREFERRED_DUE_DATE)); task.setValue(Task.DUE_DATE, values.getAsLong(PREFERRED_DUE_DATE));
if(values.containsKey(DEFINITE_DUE_DATE)) if(values.containsKey(DEFINITE_DUE_DATE))
task.setValue(Task.DUE_DATE, values.getAsLong(DEFINITE_DUE_DATE)); task.setValue(Task.DUE_DATE, values.getAsLong(DEFINITE_DUE_DATE));
if(values.containsKey(IMPORTANCE)) if(values.containsKey(IMPORTANCE))
task.setValue(Task.IMPORTANCE, values.getAsInteger(IMPORTANCE)); task.setValue(Task.IMPORTANCE, values.getAsInteger(IMPORTANCE));
if(values.containsKey(COMPLETED)) if(values.containsKey(COMPLETED))
task.setValue(Task.COMPLETION_DATE, task.setValue(Task.COMPLETION_DATE,
values.getAsBoolean(COMPLETED) ? DateUtilities.now() : 0); values.getAsBoolean(COMPLETED) ? DateUtilities.now() : 0);
// map selection criteria // map selection criteria
String criteria = selection.replace(NAME, Task.TITLE.name). String criteria = selection.replace(NAME, Task.TITLE.name).
replace(PREFERRED_DUE_DATE, Task.DUE_DATE.name). replace(PREFERRED_DUE_DATE, Task.DUE_DATE.name).
replace(DEFINITE_DUE_DATE, Task.DUE_DATE.name). replace(DEFINITE_DUE_DATE, Task.DUE_DATE.name).
replace(IDENTIFIER, Task.ID.name). replace(IDENTIFIER, Task.ID.name).
replace(ID, Task.ID.name). replace(ID, Task.ID.name).
replace(IMPORTANCE, Task.IMPORTANCE.name); replace(IMPORTANCE, Task.IMPORTANCE.name);
return taskService.updateBySelection(criteria, selectionArgs, task); return taskService.updateBySelection(criteria, selectionArgs, task);
case URI_TAGS: case URI_TAGS:
throw new UnsupportedOperationException("tags updating: not yet"); throw new UnsupportedOperationException("tags updating: not yet");
default: default:
throw new IllegalStateException("Unrecognized URI:" + uri); throw new IllegalStateException("Unrecognized URI:" + uri);
} }
} }
public static void notifyDatabaseModification() { public static void notifyDatabaseModification() {
if (LOGD) if (LOGD)
Log.d(TAG, "notifyDatabaseModification"); Log.d(TAG, "notifyDatabaseModification");
ctx.getContentResolver().notifyChange(CONTENT_URI, null); ctx.getContentResolver().notifyChange(CONTENT_URI, null);
} }
} }

@ -206,7 +206,7 @@ public class AddOnService {
list[2] = new AddOn(true, true, "Remember the Milk", null, list[2] = new AddOn(true, true, "Remember the Milk", null,
"Synchronize with Remember The Milk service.", "Synchronize with Remember The Milk service.",
Constants.PACKAGE, "http://www.rmilk.com", Constants.PACKAGE, "http://www.rmilk.com",
((BitmapDrawable)r.getDrawable(R.drawable.ic_menu_rmilk)).getBitmap()); ((BitmapDrawable)r.getDrawable(R.drawable.ic_menu_refresh)).getBitmap());
list[3] = new AddOn(true, true, "Producteev", null, list[3] = new AddOn(true, true, "Producteev", null,
"Synchronize with Producteev service. Also changes Astrid's importance levels to stars.", "Synchronize with Producteev service. Also changes Astrid's importance levels to stars.",

Loading…
Cancel
Save