Minor performance improvements to DateUtilities, TaskAction

pull/14/head
Sam Bosley 13 years ago
parent 8a9554a30a
commit b614a5af3c

@ -243,20 +243,14 @@ public class DateUtilities {
return DateUtilities.getRelativeDay(context, date, true); return DateUtilities.getRelativeDay(context, date, true);
} }
private static final Calendar calendar = Calendar.getInstance();
public static long getStartOfDay(long time) { public static long getStartOfDay(long time) {
Date date = new Date(time); calendar.setTimeInMillis(time);
date.setHours(0); calendar.set(Calendar.HOUR, 0);
date.setMinutes(0); calendar.set(Calendar.MINUTE, 0);
date.setSeconds(0); calendar.set(Calendar.SECOND, 0);
return date.getTime(); calendar.set(Calendar.MILLISECOND, 0);
} return calendar.getTimeInMillis();
public static long getEndOfDay(long time) {
Date date = new Date(time);
date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
return date.getTime();
} }
private static long clearTime(Date date) { private static long clearTime(Date date) {

@ -6,9 +6,7 @@
package com.todoroo.astrid.api; package com.todoroo.astrid.api;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable;
import android.os.Parcel;
import android.os.Parcelable;
/** /**
* Represents an intent that can be called on a task * Represents an intent that can be called on a task
@ -16,7 +14,7 @@ import android.os.Parcelable;
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public class TaskAction implements Parcelable { public class TaskAction {
/** /**
* Label * Label
@ -31,7 +29,7 @@ public class TaskAction implements Parcelable {
/** /**
* Quick action icon * Quick action icon
*/ */
public Bitmap icon = null; public BitmapDrawable icon = null;
/** /**
* Quick action drawable resource * Quick action drawable resource
@ -46,7 +44,7 @@ public class TaskAction implements Parcelable {
* @param intent * @param intent
* intent to invoke. {@link #EXTRAS_TASK_ID} will be passed * intent to invoke. {@link #EXTRAS_TASK_ID} will be passed
*/ */
public TaskAction(String text, PendingIntent intent, Bitmap icon) { public TaskAction(String text, PendingIntent intent, BitmapDrawable icon) {
super(); super();
this.text = text; this.text = text;
this.intent = intent; this.intent = intent;
@ -61,38 +59,38 @@ public class TaskAction implements Parcelable {
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
//
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public void writeToParcel(Parcel dest, int flags) { // public void writeToParcel(Parcel dest, int flags) {
dest.writeString(text); // dest.writeString(text);
dest.writeParcelable(intent, 0); // dest.writeParcelable(intent, 0);
dest.writeParcelable(icon, 0); // dest.writeParcelable(icon, 0);
dest.writeInt(drawable); // dest.writeInt(drawable);
} // }
//
/** // /**
* Parcelable creator // * Parcelable creator
*/ // */
public static final Parcelable.Creator<TaskAction> CREATOR = new Parcelable.Creator<TaskAction>() { // public static final Parcelable.Creator<TaskAction> CREATOR = new Parcelable.Creator<TaskAction>() {
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public TaskAction createFromParcel(Parcel source) { // public TaskAction createFromParcel(Parcel source) {
TaskAction action = new TaskAction(source.readString(), // TaskAction action = new TaskAction(source.readString(),
(PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()), // (PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()),
(Bitmap)source.readParcelable(Bitmap.class.getClassLoader())); // (Bitmap)source.readParcelable(Bitmap.class.getClassLoader()));
action.drawable = source.readInt(); // action.drawable = source.readInt();
return action; // return action;
} // }
//
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public TaskAction[] newArray(int size) { // public TaskAction[] newArray(int size) {
return new TaskAction[size]; // return new TaskAction[size];
}; // };
}; // };
} }

@ -14,7 +14,6 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
@ -68,13 +67,13 @@ public class LinkActionExposer {
Resources r = context.getResources(); Resources r = context.getResources();
if (hasAttachments) { if (hasAttachments) {
Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_attachments)).getBitmap(); BitmapDrawable icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_attachments));
FilesAction filesAction = new FilesAction("", null, icon); //$NON-NLS-1$ FilesAction filesAction = new FilesAction("", null, icon); //$NON-NLS-1$
result.add(filesAction); result.add(filesAction);
} }
if (!TextUtils.isEmpty(notes) && !Preferences.getBoolean(R.string.p_showNotes, false)) { if (!TextUtils.isEmpty(notes) && !Preferences.getBoolean(R.string.p_showNotes, false)) {
Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_notes)).getBitmap(); BitmapDrawable icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_notes));
NotesAction notesAction = new NotesAction("", null, icon); //$NON-NLS-1$ NotesAction notesAction = new NotesAction("", null, icon); //$NON-NLS-1$
result.add(notesAction); result.add(notesAction);
} }
@ -113,13 +112,13 @@ public class LinkActionExposer {
} else { } else {
icon = r.getDrawable(R.drawable.action_web); icon = r.getDrawable(R.drawable.action_web);
} }
Bitmap bitmap = ((BitmapDrawable)icon).getBitmap(); // Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
if(text.length() > 15) if(text.length() > 15)
text = text.substring(0, 12) + "..."; //$NON-NLS-1$ text = text.substring(0, 12) + "..."; //$NON-NLS-1$
TaskAction action = new TaskAction(text, TaskAction action = new TaskAction(text,
PendingIntent.getActivity(context, (int)id, actionIntent, 0), bitmap); PendingIntent.getActivity(context, (int)id, actionIntent, 0), (BitmapDrawable)icon);
return action; return action;
} }

@ -6,40 +6,38 @@
package com.todoroo.astrid.files; package com.todoroo.astrid.files;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable;
import android.os.Parcel;
import android.os.Parcelable;
import com.todoroo.astrid.api.TaskAction; import com.todoroo.astrid.api.TaskAction;
public class FilesAction extends TaskAction { public class FilesAction extends TaskAction {
public FilesAction(String text, PendingIntent intent, Bitmap icon) { public FilesAction(String text, PendingIntent intent, BitmapDrawable icon) {
super(text, intent, icon); super(text, intent, icon);
} }
//
/** // /**
* Parcelable creator // * Parcelable creator
*/ // */
@SuppressWarnings("hiding") // @SuppressWarnings("hiding")
public static final Parcelable.Creator<FilesAction> CREATOR = new Parcelable.Creator<FilesAction>() { // public static final Parcelable.Creator<FilesAction> CREATOR = new Parcelable.Creator<FilesAction>() {
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public FilesAction createFromParcel(Parcel source) { // public FilesAction createFromParcel(Parcel source) {
FilesAction action = new FilesAction(source.readString(), // FilesAction action = new FilesAction(source.readString(),
(PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()), // (PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()),
(Bitmap)source.readParcelable(Bitmap.class.getClassLoader())); // (Bitmap)source.readParcelable(Bitmap.class.getClassLoader()));
action.drawable = source.readInt(); // action.drawable = source.readInt();
return action; // return action;
} // }
//
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public FilesAction[] newArray(int size) { // public FilesAction[] newArray(int size) {
return new FilesAction[size]; // return new FilesAction[size];
}; // };
}; // };
} }

@ -6,40 +6,38 @@
package com.todoroo.astrid.notes; package com.todoroo.astrid.notes;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable;
import android.os.Parcel;
import android.os.Parcelable;
import com.todoroo.astrid.api.TaskAction; import com.todoroo.astrid.api.TaskAction;
public class NotesAction extends TaskAction { public class NotesAction extends TaskAction {
public NotesAction(String text, PendingIntent intent, Bitmap icon) { public NotesAction(String text, PendingIntent intent, BitmapDrawable icon) {
super(text, intent, icon); super(text, intent, icon);
} }
//
/** // /**
* Parcelable creator // * Parcelable creator
*/ // */
@SuppressWarnings("hiding") // @SuppressWarnings("hiding")
public static final Parcelable.Creator<NotesAction> CREATOR = new Parcelable.Creator<NotesAction>() { // public static final Parcelable.Creator<NotesAction> CREATOR = new Parcelable.Creator<NotesAction>() {
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public NotesAction createFromParcel(Parcel source) { // public NotesAction createFromParcel(Parcel source) {
NotesAction action = new NotesAction(source.readString(), // NotesAction action = new NotesAction(source.readString(),
(PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()), // (PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()),
(Bitmap)source.readParcelable(Bitmap.class.getClassLoader())); // (Bitmap)source.readParcelable(Bitmap.class.getClassLoader()));
action.drawable = source.readInt(); // action.drawable = source.readInt();
return action; // return action;
} // }
//
/** // /**
* {@inheritDoc} // * {@inheritDoc}
*/ // */
public NotesAction[] newArray(int size) { // public NotesAction[] newArray(int size) {
return new NotesAction[size]; // return new NotesAction[size];
}; // };
}; // };
} }

@ -489,7 +489,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
taskAction.setVisibility(View.VISIBLE); taskAction.setVisibility(View.VISIBLE);
TaskAction action = taskActionLoader.get(task.getId()); TaskAction action = taskActionLoader.get(task.getId());
if (action != null) { if (action != null) {
taskAction.setImageBitmap(action.icon); taskAction.setImageDrawable(action.icon);
taskAction.setTag(action); taskAction.setTag(action);
} }
} else { } else {

Loading…
Cancel
Save