-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
188 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
android/src/main/java/br/com/dopaminamob/gpsstate/Ticker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package br.com.dopaminamob.gpsstate; | ||
|
||
public class Ticker { | ||
private int maxTicks = 10; | ||
private int interval = 1; | ||
private int ticksCount = 0; | ||
private boolean running = false; | ||
private TickerCallBack callBack; | ||
|
||
public void startTick(TickerCallBack cb){ | ||
running = true; | ||
callBack = cb; | ||
tick(); | ||
} | ||
|
||
public void stopTick(){ | ||
running = false; | ||
ticksCount = 0; | ||
} | ||
|
||
private void tick(){ | ||
if(!reachedMaxTicks() && hasCallback() && isRunning()){ | ||
new java.util.Timer().schedule( | ||
new java.util.TimerTask() { | ||
@Override | ||
public void run() { | ||
callBack.tick(); | ||
ticksCount ++; | ||
|
||
tick(); | ||
} | ||
}, | ||
getInterval() | ||
); | ||
}else{ | ||
stopTick(); | ||
} | ||
} | ||
|
||
|
||
public int getMaxTicks() { | ||
return maxTicks; | ||
} | ||
|
||
public void setMaxTicks(int maxTicks) { | ||
this.maxTicks = maxTicks; | ||
} | ||
|
||
public int getInterval() { | ||
return interval; | ||
} | ||
|
||
public void setInterval(int interval) { | ||
this.interval = interval; | ||
} | ||
|
||
public boolean isRunning(){ | ||
return running; | ||
} | ||
|
||
public boolean hasCallback(){ | ||
return callBack!=null; | ||
} | ||
|
||
public boolean reachedMaxTicks(){ | ||
return ticksCount >= getMaxTicks(); | ||
} | ||
} | ||
|
||
interface TickerCallBack { | ||
void tick(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters