Minor performance improvements to DateUtilities, TaskAction

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

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

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

@ -14,7 +14,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@ -68,13 +67,13 @@ public class LinkActionExposer {
Resources r = context.getResources();
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$
result.add(filesAction);
}
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$
result.add(notesAction);
}
@ -113,13 +112,13 @@ public class LinkActionExposer {
} else {
icon = r.getDrawable(R.drawable.action_web);
}
Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
// Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
if(text.length() > 15)
text = text.substring(0, 12) + "..."; //$NON-NLS-1$
TaskAction action = new TaskAction(text,
PendingIntent.getActivity(context, (int)id, actionIntent, 0), bitmap);
PendingIntent.getActivity(context, (int)id, actionIntent, 0), (BitmapDrawable)icon);
return action;
}

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

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

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

Loading…
Cancel
Save