aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/DurationTimer.java
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2018-01-17 11:15:16 -0800
committerNick Chalko <nchalko@google.com>2018-01-17 11:20:37 -0800
commit38fef3bf253578f518d1bc727da4afb263194398 (patch)
tree09a06234eda7c54216bca773b6d8407eafe0722d /src/com/android/tv/util/DurationTimer.java
parentc9889d13513e26649a7708cf2d0562cb592d441a (diff)
downloadTV-38fef3bf253578f518d1bc727da4afb263194398.tar.gz
Fix broken build
This reverts c9889d1 Update aosp build to use a snapshot of exoplyer. by nchalko · 5 hours ago master 8952aa7 Clean format by nchalko · 20 hours ago ba3fb16 Merge "Use a snapshot of exoplayer" by TreeHugger Robot · 18 hours ago ff75e39 Project import generated by Copybara. by Live Channels Team · 22 hours ago 9737fc2 Use a snapshot of exoplayer by Nick Chalko · 20 hours ago 4a5144a Project import generated by Copybara. by Live Channels Team · 6 days ago Bug: 72092981 Bug: 69474774 Change-Id: Ie756857c10bf052c60b6442c3d61252f65b49143
Diffstat (limited to 'src/com/android/tv/util/DurationTimer.java')
-rw-r--r--src/com/android/tv/util/DurationTimer.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/com/android/tv/util/DurationTimer.java b/src/com/android/tv/util/DurationTimer.java
new file mode 100644
index 00000000..6aabf37b
--- /dev/null
+++ b/src/com/android/tv/util/DurationTimer.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.util;
+
+import android.os.SystemClock;
+import android.util.Log;
+import com.android.tv.common.BuildConfig;
+
+/** Times a duration. */
+public final class DurationTimer {
+ private static final String TAG = "DurationTimer";
+ public static final long TIME_NOT_SET = -1;
+
+ private long mStartTimeMs = TIME_NOT_SET;
+ private String mTag = TAG;
+ private boolean mLogEngOnly;
+
+ public DurationTimer() {}
+
+ public DurationTimer(String tag, boolean logEngOnly) {
+ mTag = tag;
+ mLogEngOnly = logEngOnly;
+ }
+
+ /** Returns true if the timer is running. */
+ public boolean isRunning() {
+ return mStartTimeMs != TIME_NOT_SET;
+ }
+
+ /** Start the timer. */
+ public void start() {
+ mStartTimeMs = SystemClock.elapsedRealtime();
+ }
+
+ /** Returns true if timer is started. */
+ public boolean isStarted() {
+ return mStartTimeMs != TIME_NOT_SET;
+ }
+
+ /**
+ * Returns the current duration in milliseconds or {@link #TIME_NOT_SET} if the timer is not
+ * running.
+ */
+ public long getDuration() {
+ return isRunning() ? SystemClock.elapsedRealtime() - mStartTimeMs : TIME_NOT_SET;
+ }
+
+ /**
+ * Stops the timer and resets its value to {@link #TIME_NOT_SET}.
+ *
+ * @return the current duration in milliseconds or {@link #TIME_NOT_SET} if the timer is not
+ * running.
+ */
+ public long reset() {
+ long duration = getDuration();
+ mStartTimeMs = TIME_NOT_SET;
+ return duration;
+ }
+
+ /** Adds information and duration time to the log. */
+ public void log(String message) {
+ if (isRunning() && (!mLogEngOnly || BuildConfig.ENG)) {
+ Log.i(mTag, message + " : " + getDuration() + "ms");
+ }
+ }
+}