Home | History | Annotate | Download | only in util
      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 }
     50