Skip to content

Most visited

Recently visited

navigation
Timer / src / com.example.android.wearable.timer / util /

TimerObj.java

1
/*
2
 * Copyright (C) 2014 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
package com.example.android.wearable.timer.util;
18
 
19
import android.os.SystemClock;
20
 
21
/** This class represents a timer. */
22
public class TimerObj {
23
 
24
    // Start time in milliseconds.
25
    public long startTime;
26
 
27
    // Length of the timer in milliseconds.
28
    public long originalLength;
29
 
30
    /**
31
     * Construct a timer with a specific start time and length.
32
     *
33
     * @param startTime the start time of the timer.
34
     * @param timerLength the length of the timer.
35
     */
36
    public TimerObj(long startTime, long timerLength) {
37
        this.startTime = startTime;
38
        this.originalLength = timerLength;
39
    }
40
 
41
    /**
42
     * Calculate the time left of this timer.
43
     * @return the time left for this timer.
44
     */
45
    public long timeLeft() {
46
        long millis = SystemClock.elapsedRealtime();
47
        return originalLength - (millis - startTime);
48
    }
49
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)