import com.google.zxing.ReaderException;
import com.google.zxing.Result;
-import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
* @param height The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
- Date startDate = new Date();
+ long start = System.currentTimeMillis();
boolean success;
Result rawResult = null;
YUVMonochromeBitmapSource source = new YUVMonochromeBitmapSource(data, width, height,
} catch (ReaderException e) {
success = false;
}
- Date endDate = new Date();
+ long end = System.currentTimeMillis();
if (success) {
Message message = Message.obtain(mActivity.mHandler, R.id.decode_succeeded, rawResult);
- message.arg1 = (int) (endDate.getTime() - startDate.getTime());
+ message.arg1 = (int) (end - start);
Bundle bundle = new Bundle();
bundle.putParcelable(BARCODE_BITMAP, source.renderToBitmap());
message.setData(bundle);
message.sendToTarget();
} else {
Message message = Message.obtain(mActivity.mHandler, R.id.decode_failed);
- message.arg1 = (int) (endDate.getTime() - startDate.getTime());
+ message.arg1 = (int) (end - start);
message.sendToTarget();
}
}
public final class AddressBookResultHandler extends ResultHandler {
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
+
private final boolean[] mFields;
private int mButtonCount;
String birthday = result.getBirthday();
if (birthday != null && birthday.length() > 0) {
- DateFormat format = new SimpleDateFormat("yyyyMMdd");
- Date date = format.parse(birthday, new ParsePosition(0));
+ Date date;
+ synchronized (DATE_FORMAT) {
+ date = DATE_FORMAT.parse(birthday, new ParsePosition(0));
+ }
ParsedResult.maybeAppend(DateFormat.getDateInstance().format(date.getTime()), contents);
}
ParsedResult.maybeAppend(result.getNote(), contents);
public final class CalendarResultHandler extends ResultHandler {
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
+ private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
+
private static final int[] mButtons = {
R.string.button_add_calendar
};
private void appendTime(String when, StringBuffer result) {
if (when.length() == 8) {
// Show only year/month/day
- DateFormat format = new SimpleDateFormat("yyyyMMdd");
- Date date = format.parse(when, new ParsePosition(0));
+ Date date;
+ synchronized (DATE_FORMAT) {
+ date = DATE_FORMAT.parse(when, new ParsePosition(0));
+ }
ParsedResult.maybeAppend(DateFormat.getDateInstance().format(date.getTime()), result);
} else {
// The when string can be local time, or UTC if it ends with a Z
- DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
- Date date = format.parse(when.substring(0, 15), new ParsePosition(0));
+ Date date;
+ synchronized (DATE_TIME_FORMAT) {
+ date = DATE_TIME_FORMAT.parse(when.substring(0, 15), new ParsePosition(0));
+ }
long milliseconds = date.getTime();
if (when.length() == 16 && when.charAt(15) == 'Z') {
Calendar calendar = new GregorianCalendar();
public abstract class ResultHandler {
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
+ private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
+
public static final int MAX_BUTTON_COUNT = 4;
protected final ParsedResult mResult;
private long calculateMilliseconds(String when) {
if (when.length() == 8) {
// Only contains year/month/day
- DateFormat format = new SimpleDateFormat("yyyyMMdd");
- Date date = format.parse(when, new ParsePosition(0));
+ Date date;
+ synchronized (DATE_FORMAT) {
+ date = DATE_FORMAT.parse(when, new ParsePosition(0));
+ }
return date.getTime();
} else {
// The when string can be local time, or UTC if it ends with a Z
- DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
- Date date = format.parse(when.substring(0, 15), new ParsePosition(0));
+ Date date;
+ synchronized (DATE_TIME_FORMAT) {
+ date = DATE_TIME_FORMAT.parse(when.substring(0, 15), new ParsePosition(0));
+ }
long milliseconds = date.getTime();
if (when.length() == 16 && when.charAt(15) == 'Z') {
Calendar calendar = new GregorianCalendar();