This commit is contained in:
Gangphon 2024-08-22 18:14:03 +08:00
parent a7a23e0b77
commit 9691b7b907
4 changed files with 44 additions and 39 deletions

View File

@ -3,6 +3,7 @@ package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.net.Uri;
@ -12,7 +13,6 @@ import android.view.Choreographer;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import java.io.File;
@ -32,10 +32,7 @@ import pl.droidsonroids.gif.GifImageView;
public class Prog extends AbsLayout {
ArrayList<Page> pages = new ArrayList<>();
ArrayList<Integer> avas = new ArrayList<>();
ArrayList<Choreographer.FrameCallback> calls = new ArrayList<>();
int curAva, curTimes = 1;
long waitTo = Long.MAX_VALUE;
boolean isInsert;
@SuppressLint("SetJavaScriptEnabled")
@ -108,8 +105,8 @@ public class Prog extends AbsLayout {
for(var source : sources) {
src.type = source.stnn("_type");
if(src.type.isEmpty()) continue;
var timeSpan = source.intg("timeSpan")*1000;
if(timeSpan==0) {
var dur = source.intg("timeSpan")*1000;
if(dur==0) {
Util.println("\nError: timeSpan is 0. _type: "+src.type);
continue;
}
@ -127,7 +124,7 @@ public class Prog extends AbsLayout {
}
src.startTime = isSimple ? (layer.srcs.isEmpty() ? 0 : layer.srcs.get(layer.srcs.size()-1).endTime) : source.intg("playTime")*1000;
if(bdStart > src.startTime) bdStart = src.startTime;
src.endTime = src.startTime + timeSpan;
src.endTime = src.startTime + dur;
if(bdEnd < src.endTime) bdEnd = src.endTime;
if(layer.dur < src.endTime) layer.dur = src.endTime;
if(notAudio) {
@ -180,7 +177,7 @@ public class Prog extends AbsLayout {
}
}
}
if(src.exitDur!=0) src.exitStart = timeSpan*60/1000 - src.exitDur;
if(src.exitDur!=0) src.exitStart = dur*60/1000 - src.exitDur;
var id = source.str("id");
var fileExt = source.stnn("fileExt");
@ -196,7 +193,20 @@ public class Prog extends AbsLayout {
src.view = imgView;
} else {
var imgView = new ImageView(context);
imgView.setImageURI(Uri.fromFile(new File(Util.programDir + "/" + id)));
var file = Util.programDir+"/"+id;
new Thread(()->{
var ttt = System.currentTimeMillis();
var img = BitmapFactory.decodeFile(file);
// if(img.getByteCount()>1500*1500*4) {
// var matrix = new Matrix();
// matrix.setScale(0.5f, 0.5f);
// img = Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), matrix, true);
// }
ttt = System.currentTimeMillis() - ttt;
Util.println(" img "+img.getWidth()+"x"+img.getHeight()+" "+ttt);
Bitmap finalImg = img;
MainActivity.ins.runOnUiThread(() -> imgView.setImageBitmap(finalImg));
}).start();
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
src.view = imgView;
}
@ -217,12 +227,12 @@ public class Prog extends AbsLayout {
src.view = new SrcCopy(context, exist);
((SrcCopy) src.view).scaleX = 0;
} else {
src.view = new SrcVideo(context, isLive ? url : Util.programDir+"/"+id, source.intg("vol", 100) / 100.0f, isLive);
src.view = new SrcVideo(context, isLive ? url : Util.programDir+"/"+id, source.intg("vol", 100) / 100.0f, dur, source.bool("useHW"), isLive);
videoMap.put(key, src.view);
}
} else if(src.type.equals("Audio")) {
if(id==null) continue;
src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, false);
src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, dur, false, false);
} else if(src.type.startsWith("MultiPng") || src.type.equals("SplitText")) {
JSList<JSMap> imgs = source.jslist("arrayPics");
if(imgs.isEmpty()) continue;
@ -245,7 +255,7 @@ public class Prog extends AbsLayout {
var ele0 = src;
for(var map : imgs) {
var picDur = map.intg("picDuration")*1000;
if(picDur==0) picDur = timeSpan / imgs.size();
if(picDur==0) picDur = dur / imgs.size();
src.type = "Image";
if(src!=ele0) {
src.startTime = layer.srcs.get(layer.srcs.size()-1).endTime;
@ -281,26 +291,7 @@ 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")) {
var webView = new WebView(context);
webView.getSettings().setJavaScriptEnabled(true);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.setInitialScale(source.intg("zoom", 100));
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.scrollTo("+source.str("offX", "0")+", "+source.str("offY", "0")+")");
}
});
webView.loadUrl(source.stnn("url"));
src.view = webView;
}
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("Countdown")) src.view = new SrcCountdown(this, source);
else if(src.type.startsWith("Environ")) src.view = new SrcEnviron(this, source);
@ -409,9 +400,6 @@ public class Prog extends AbsLayout {
}
}
Page curAva() {
return pages.get(avas.get(curAva));
}
void release() {
try {
setVisibility(GONE);
@ -702,7 +690,7 @@ public class Prog extends AbsLayout {
if(startTime.length()<=5) startTime += ":00";
try {
sche.startTime = (int)timeFmt.parse(startTime).getTime();
Util.println("startTime "+timeFmt.format(sche.startTime));
Util.println("startTime "+timeFmt.format(sche.startTime)+" "+sche.startTime);
} catch (ParseException e) {
Util.printStackTrace(e);
}
@ -712,7 +700,7 @@ public class Prog extends AbsLayout {
if(endTime.length()<=5) endTime += ":00";
try {
sche.endTime = (int)timeFmt.parse(endTime).getTime();
Util.println("endTime "+timeFmt.format(sche.endTime));
Util.println("endTime "+timeFmt.format(sche.endTime)+" "+sche.endTime);
} catch (ParseException e) {
Util.printStackTrace(e);
}

View File

@ -169,6 +169,17 @@ public class SocketThread extends Thread {
latch.await();
} catch (InterruptedException ignored) {}
new JSMap("success", ok.get()).write(out);
} else if("getProgramName".equals(_type)) {
try {
String name = null;
var ins = MainActivity.ins;
if(ins!=null && ! ins.avas.isEmpty()) name = ins.avas.get(ins.curAva).name;
new JSMap("success", true, "name", name).write(out);
Util.println(" name "+name);
} catch (Exception e) {
Util.printStackTrace(e);
new JSMap("success", false, "msg", Util.toStr(e)).write(out);
}
} else if("DelBackImg".equals(_type)) {
MainActivity.ins.runOnUiThread(() -> {
MainActivity.ins.backView.cosImg = null;

View File

@ -32,8 +32,9 @@ public class SrcSensor extends WebView implements IntentReceiver, Choreographer.
setInitialScale(100);
getSettings().setJavaScriptEnabled(true);
var html = json.stnn("html").replace("%Co2", "%CO2").replace("<p>", "").trim();
var html = json.stnn("html").replace("%Co2", "%CO2").trim();
htmls = Txts.split(html, "</p>", 1);
for(int i=0; i<htmls.size(); i++) htmls.set(i, htmls.get(i)+"</p>");
pageDur = json.intg("speed")*1000;
if(pageDur==0) pageDur = json.intg("timeSpan")*1000 / htmls.size();
url = json.str("sUrl");

View File

@ -2,12 +2,13 @@ package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.net.http.SslError;
import android.view.Choreographer;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import gnph.util.JSMap;
import gnph.util.URLConn;
@SuppressLint("ViewConstructor")
public class SrcWeb extends WebView implements Choreographer.FrameCallback {
@ -32,6 +33,10 @@ public class SrcWeb extends WebView implements Choreographer.FrameCallback {
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); //忽略SSL证书错误加载网页
}
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.scrollTo("+json.str("offX", "0")+", "+json.str("offY", "0")+")");
}