-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/Hannah/master' into FontColor
# Conflicts: # app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
- Loading branch information
Showing
9 changed files
with
298 additions
and
4 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
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/morristaedt/mirror/modules/CountdownModule.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,62 @@ | ||
package com.morristaedt.mirror.modules; | ||
|
||
import android.app.Activity; | ||
|
||
import java.util.Date; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public class CountdownModule { | ||
|
||
public interface CountdownListener { | ||
void onCountdownUpdate(String timeLeft); | ||
} | ||
|
||
private static Timer timer; | ||
|
||
public static void getTimeRemaining(final Date countdownEnd, final CountdownListener listener){ | ||
if (timer != null) { | ||
timer.cancel(); | ||
} | ||
timer = new Timer(); | ||
|
||
timer.scheduleAtFixedRate(new TimerTask() { | ||
@Override | ||
public void run() { | ||
long timeLeft = countdownEnd.getTime() - System.currentTimeMillis(); | ||
listener.onCountdownUpdate(formatTime(timeLeft)); | ||
} | ||
}, 0, 1000); | ||
} | ||
|
||
private static String formatTime(long time) { | ||
String formattedTime = "Time is up!"; | ||
|
||
time /= 1000; //convert to secs | ||
if (time <= 0){ | ||
return formattedTime; | ||
} | ||
formattedTime = time%60 + "s"; | ||
|
||
time /= 60; //convert to mins | ||
if (time == 0){ | ||
return formattedTime; | ||
} | ||
formattedTime = time%60 + "m " + formattedTime; | ||
|
||
time /= 60; //convert to hours | ||
if (time == 0) { | ||
return formattedTime; | ||
} | ||
formattedTime = time%60 + "h " + formattedTime; | ||
|
||
time /= 24; //convert to days | ||
if (time == 0) { | ||
return formattedTime; | ||
} | ||
formattedTime = time + "d " + formattedTime; | ||
|
||
return formattedTime; | ||
} | ||
|
||
} |
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
Oops, something went wrong.