Update SrcCountdown.java

This commit is contained in:
Gangphon 2024-07-10 21:46:34 +08:00
parent 0d95ad356f
commit 9741d689d0

View File

@ -14,20 +14,32 @@ import gnph.util.NumFmts;
public class SrcCountdown extends WebView implements Choreographer.FrameCallback {
long targetTime;
String html, lineHeight, prefix;
boolean hasDay, hasHour, hasMin, hasSec;
String html, lineHeight, prefix, suffix;
boolean isUp, hasDay, hasHour, hasMin, hasSec;
public SrcCountdown(Prog prog, JSMap json) {
super(prog.getContext());
setBackgroundColor(Color.TRANSPARENT);
try {
var backColor = json.str("backColor");
setBackgroundColor(backColor==null ? Color.TRANSPARENT : Color.parseColor(backColor));
} catch (Exception ignored) {
setBackgroundColor(Color.TRANSPARENT);
}
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
setInitialScale(100);
isUp = json.bool("isUp");
html = json.stnn("html");
lineHeight = json.str("lineHeight");
prefix = "<body style=\"color:#fff;margin:0;padding:0;";
if(lineHeight!=null) prefix += "line-height:"+lineHeight+";";
prefix += "\">";
suffix = "</body>";
try {
var aaa = html.substring(0, 16).trim();
if(aaa.startsWith("<html") || aaa.startsWith("<body") || aaa.startsWith("<!DOCTYPE")) prefix = suffix = "";
} catch (Exception ignored) {
}
hasDay = html.contains("%d");
hasHour = html.contains("%h");
hasMin = html.contains("%m");
@ -47,7 +59,7 @@ public class SrcCountdown extends WebView implements Choreographer.FrameCallback
}
void cal() {
var secs = targetTime - lastSec;
var secs = isUp ? lastSec - targetTime : targetTime - lastSec;
if(secs < 0) secs = 0;
var htm = html;
if(hasDay) {
@ -63,7 +75,7 @@ public class SrcCountdown extends WebView implements Choreographer.FrameCallback
secs %= 60;
}
if(hasSec) htm = htm.replace("%s", NumFmts.zz().format(secs));
loadDataWithBaseURL(null, prefix+htm+"</body>", "text/html", "UTF-8", null);
loadDataWithBaseURL(null, prefix+htm+suffix, "text/html", "UTF-8", null);
}
long lastSec;