--- /dev/null
+/*\r
+ * Copyright 2008 ZXing authors\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.google.zxing.client.rim.util;\r
+\r
+/**\r
+ * Used to determine if something happend within a specified amount of time.\r
+ * For example, if a QR code was decoded in a resonable amount of time.\r
+ * If not, perhaps the user should lower their camera resolution.\r
+ *\r
+ * This code was contributed by LifeMarks.\r
+ *\r
+ * @author Matt York (matt@lifemarks.mobi)\r
+ */\r
+public final class ReasonableTimer {\r
+\r
+ // 2000 too low for qr decoding\r
+ private static final long DEF_RESONABLE_TIME = 2500; // in ms\r
+\r
+ private long reasonableTime;\r
+ private final long startTime;\r
+ private long finishTime;\r
+\r
+ public ReasonableTimer() {\r
+ startTime = System.currentTimeMillis();\r
+ reasonableTime = DEF_RESONABLE_TIME;\r
+ }\r
+\r
+ public ReasonableTimer(long reasonableTime) {\r
+ startTime = System.currentTimeMillis();\r
+ this.reasonableTime = reasonableTime;\r
+ }\r
+\r
+ /**\r
+ * Stops the timing.\r
+ */\r
+ public void finished() {\r
+ finishTime = System.currentTimeMillis();\r
+ }\r
+\r
+ /**\r
+ * Returns true if the timer finished in a reasonable amount of time.\r
+ */\r
+ public boolean wasResonableTime() {\r
+ return finishTime - startTime <= reasonableTime;\r
+ }\r
+\r
+ /**\r
+ * Sets the reasonable time to the given time\r
+ */\r
+ public void setResonableTime(long reasonableTime) {\r
+ this.reasonableTime = reasonableTime;\r
+ }\r
+\r
+ /**\r
+ * Returns the reasonable time.\r
+ */\r
+ public long getResonableTime() {\r
+ return reasonableTime;\r
+ }\r
+\r
+}\r