• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import android.os.CountDownTimer;
4 import org.robolectric.annotation.Implementation;
5 import org.robolectric.annotation.Implements;
6 import org.robolectric.annotation.RealObject;
7 import org.robolectric.shadow.api.Shadow;
8 import org.robolectric.util.ReflectionHelpers.ClassParameter;
9 
10 @Implements(CountDownTimer.class)
11 public class ShadowCountDownTimer {
12   private boolean started;
13   private long countDownInterval;
14   private long millisInFuture;
15 
16   @RealObject CountDownTimer countDownTimer;
17 
18   @Implementation
__constructor__(long millisInFuture, long countDownInterval)19   protected void __constructor__(long millisInFuture, long countDownInterval) {
20     this.countDownInterval = countDownInterval;
21     this.millisInFuture = millisInFuture;
22     this.started = false;
23     Shadow.invokeConstructor(
24         CountDownTimer.class,
25         countDownTimer,
26         ClassParameter.from(long.class, millisInFuture),
27         ClassParameter.from(long.class, countDownInterval));
28   }
29 
30   @Implementation
start()31   protected synchronized CountDownTimer start() {
32     started = true;
33     return countDownTimer;
34   }
35 
36   @Implementation
cancel()37   protected void cancel() {
38     started = false;
39   }
40 
invokeTick(long millisUntilFinished)41   public void invokeTick(long millisUntilFinished) {
42     countDownTimer.onTick(millisUntilFinished);
43   }
44 
invokeFinish()45   public void invokeFinish() {
46     countDownTimer.onFinish();
47   }
48 
hasStarted()49   public boolean hasStarted() {
50     return started;
51   }
52 
getCountDownInterval()53   public long getCountDownInterval() {
54     return countDownInterval;
55   }
56 
getMillisInFuture()57   public long getMillisInFuture() {
58     return millisInFuture;
59   }
60 }
61