This commit is contained in:
Gangphon 2025-08-20 23:03:20 +08:00
parent 1329d0b66d
commit 1d536269fe
5 changed files with 61 additions and 19 deletions

View File

@ -11,7 +11,7 @@ android {
minSdk 21
targetSdk 34
versionCode 1
versionName "2.1.46-3568"
versionName "2.1.48"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -357,8 +357,10 @@ public class Prog extends AbsLayout {
} else if(src.type.equals("DigitalClock")) src.view = new SrcDigitalClock(this, source);
else if(src.type.startsWith("DigitalClock")) src.view = new SrcDigiClock(this, source);
else if(src.type.equals("AnalogClock")) src.view = new SrcAnaClock(this, geo.width, geo.height, Util.programDir + "/" + id, source);
else if(src.type.equals("WebURL")) src.view = new SrcWeb(this, source);
else if(src.type.equals("Timer")) src.view = new SrcTimer(this, source);
else if(src.type.equals("WebURL")) {
var url = source.str("url");
if(url!=null) src.view = new SrcWeb(this, url, source);
} else if(src.type.equals("Timer")) src.view = new SrcTimer(this, source);
else if(src.type.equals("Countdown")) src.view = new SrcCountdown(this, source);
else if(src.type.startsWith("Environ")) src.view = new SrcEnviron(this, source);
else if(src.type.startsWith("Weather")) src.view = new SrcWeather(context, source);

View File

@ -124,7 +124,7 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
try {
for(var item : items) {
item.nums.clear();
if(item.unit==null) {
if(item.key.startsWith("windDir")) {
var num = intent.getIntExtra(item.key, -1);
if(num>=0 && num<=15) {
if(directs[num].length() < 3) item.nums.add(imgMap.get(directs[num]));

View File

@ -14,6 +14,7 @@ import gnph.util.URLConn;
public class SrcVisitor extends WebView implements Choreographer.FrameCallback {
String html, lineHeight, prefix, url;
int interval;
public SrcVisitor(Prog prog, JSMap json) {
super(prog.getContext());
@ -24,6 +25,7 @@ public class SrcVisitor extends WebView implements Choreographer.FrameCallback {
html = json.stnn("html").replace("%{yesterday.", "%{arr.-1.");
lineHeight = json.str("lineHeight");
url = json.str("url");
interval = json.intg("interval", 15)*1000;
if(url!=null) {
var token = json.str("token");
if(token!=null) url += "?dataKey="+token;
@ -88,7 +90,7 @@ public class SrcVisitor extends WebView implements Choreographer.FrameCallback {
public void doFrame(long ms) {
if(! isShown()) return;
if(ms>=nextMs) {
nextMs = ms + 15000;
nextMs = ms + interval;
refresh();
}
}

View File

@ -3,11 +3,17 @@ package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.net.http.SslError;
import android.os.Build;
import android.view.Choreographer;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.ArrayList;
import gnph.util.JSMap;
@SuppressLint("ViewConstructor")
@ -15,10 +21,12 @@ public class SrcWeb extends WebView implements Choreographer.FrameCallback {
String url;
int refresh;
ArrayList<Choreographer.FrameCallback> calls;
@SuppressLint("SetJavaScriptEnabled")
public SrcWeb(Prog prog, JSMap json) {
public SrcWeb(Prog prog, String url, JSMap json) {
super(prog.getContext());
this.url = url;
var settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
@ -41,27 +49,45 @@ public class SrcWeb extends WebView implements Choreographer.FrameCallback {
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.scrollTo("+json.str("offX", "0")+", "+json.str("offY", "0")+")");
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(request.isForMainFrame() && error.getErrorCode()==-2 && request.getUrl().toString().equals(url)) needReload = true;
Util.println(" WebView ReceivedError "+error.getErrorCode()+" "+error.getDescription()+"; isForMainFrame "+request.isForMainFrame()+" URL "+request.getUrl());
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
Util.println(" WebView ReceivedHttpError "+errorResponse.getStatusCode()+"; isForMainFrame "+request.isForMainFrame()+" URL "+request.getUrl());
}
});
loadUrl(url = json.str("url"));
loadUrl(url);
refresh = json.intg("refreshSec")*1000;
if(Util.custom==Util.Custom.Yishi) {
prog.calls.add(this);
} else {
if(refresh>0 && url!=null) prog.calls.add(this);
}
if(refresh==0 || Util.custom!=Util.Custom.Yishi) this.calls = prog.calls;
prog.calls.add(this);
nextMs = System.currentTimeMillis() + refresh;
}
long nextMs;
int w, h;
int cnt, w, h;
boolean needReload;
@Override
public void doFrame(long ms) {
if(! isShown()) return;
if(Util.custom==Util.Custom.Yishi) {
if(refresh>0 && url!=null && ms>=nextMs) {
nextMs = ms + refresh;
loadUrl(url);
if(refresh > 0) {
if(ms>=nextMs) {
nextMs = ms + refresh;
loadUrl(url);
}
} else if(++cnt>=600) {
cnt = 0;
if(needReload) {
needReload = false;
loadUrl(url);
Util.println(" WebView Refreshed");
}
}
if(Util.screenWidth!=w || Util.screenHeight!=h) {
w = Util.screenWidth;
@ -70,9 +96,21 @@ public class SrcWeb extends WebView implements Choreographer.FrameCallback {
setLayoutParams(new AbsLayout.LayoutParams(0, 0, w, h));
}
} else {
if(ms>=nextMs) {
nextMs = ms + refresh;
loadUrl(url);
if(refresh > 0) {
if(ms>=nextMs) {
nextMs = ms + refresh;
loadUrl(url);
}
} else if(++cnt>=600) {
cnt = 0;
if(needReload) {
needReload = false;
loadUrl(url);
Util.println(" WebView Refreshed");
} else if(calls!=null) {
calls.remove(this);
calls = null;
}
}
}
}