diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/IntentReceiver.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/IntentReceiver.java new file mode 100644 index 0000000..d8401df --- /dev/null +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/IntentReceiver.java @@ -0,0 +1,7 @@ +package com.xixun.xixunplayer; + +import android.content.Intent; + +public interface IntentReceiver { + void onReceive(Intent intent); +} diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java index 7147212..ef480a0 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java @@ -19,6 +19,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.StatFs; import android.view.Choreographer; +import android.view.View; import android.webkit.WebView; import androidx.activity.ComponentActivity; @@ -59,7 +60,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra public static MainActivity ins; public Intent environIntent = new Intent(); - HashSet environs = new HashSet<>(); + HashSet environs = new HashSet<>(); BackView backView; Prog progView; long launchMilli = System.currentTimeMillis(); @@ -210,7 +211,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra MainActivity.this.environIntent = intent; for(var environ : environs) { environ.onReceive(intent); - environ.invalidate(); + ((View)environ).invalidate(); } } }, new IntentFilter("xixun.intent.action.TEMPERATURE_HUMIDITY")); @@ -585,7 +586,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra Util.printStackTrace(e); } finally { O.close(in, out); - Util.println("conn end"); + Util.println("conn end\n\n"); } } } catch (Throwable e) { diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java index 241de7f..d42f0c9 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java @@ -39,11 +39,11 @@ public class Prog extends AbsLayout { partObj = _program; } catch (Throwable ignored){} } + var width = partObj.intg("width"); + var height = partObj.intg("height"); AbsLayout box = this; if(partLengths!=null && partLengths.size() > 1) { box = new AbsLayout(context); - var width = partObj.intg("width"); - var height = partObj.intg("height"); addView(box, new AbsLayout.LayoutParams(0, 0, width, height)); var mask = new View(context); mask.setBackgroundColor(0xff000000); @@ -68,7 +68,7 @@ public class Prog extends AbsLayout { JSList layers = _program.jslist("layers"); if(layers==null || layers.isEmpty()) continue; var page = new Page(); - page.repeatTimes = pageMap.intg("repeatTimes"); + page.repeatTimes = pageMap.intg("repeatTimes", 1); page.parse(pageMap.jslist("schedules")); HashMap videoMap = new HashMap<>(); for(int ll=layers.size()-1; ll>=0; ll--) { @@ -90,7 +90,7 @@ public class Prog extends AbsLayout { if(timeSpan==0) continue; var geo = new AbsLayout.LayoutParams(source.intg("left")+bdWidth, source.intg("top")+bdWidth, source.intg("width")-bdWidth-bdWidth, source.intg("height")-bdWidth-bdWidth); boolean notAudio = ! src.type.equals("Audio"); - if((geo.width<=0 || geo.height<=0) && notAudio) continue; + if((geo.width<=0 || geo.height<=0 || (geo.y>=height && height>0) || (geo.x>=width && width>0)) && notAudio) continue; src.startTime = source.intg("playTime")*1000; if(bdStart > src.startTime) bdStart = src.startTime; src.endTime = src.startTime + timeSpan; @@ -228,7 +228,8 @@ public class Prog extends AbsLayout { } else if(src.type.equals("Timer")) src.view = new SrcTimer(context, source); else if(src.type.equals("Countdown")) src.view = new SrcCountdown(context, source); - else if(src.type.startsWith("Environ")) src.view = new EleEnviron(context, source); + else if(src.type.startsWith("Environ")) src.view = new SrcEnviron(context, source); + else if(src.type.startsWith("MultiLineText")) src.view = new SrcSensor(context, source); else continue; if(src.view==null) continue; src.view.setVisibility(GONE); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java similarity index 98% rename from XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java rename to XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java index 4331ce5..06e03e6 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java @@ -17,7 +17,7 @@ import gnph.util.JSList; import gnph.util.JSMap; import gnph.util.NumFmts; -public class EleEnviron extends View implements Choreographer.FrameCallback { +public class SrcEnviron extends View implements Choreographer.FrameCallback, IntentReceiver { class Item { String key; Bitmap label; @@ -39,7 +39,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback { int interval, cur, end, step; boolean isScroll, isFirst = true; - public EleEnviron(Context context, JSMap json) { + public SrcEnviron(Context context, JSMap json) { super(context); act = (MainActivity) context; alignType = json.intg("alignType"); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java new file mode 100644 index 0000000..578d3cd --- /dev/null +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java @@ -0,0 +1,90 @@ +package com.xixun.xixunplayer; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.view.Choreographer; +import android.view.View; +import android.webkit.WebView; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; + +import gnph.util.JSList; +import gnph.util.JSMap; +import gnph.util.NumFmts; + +public class SrcSensor extends WebView implements IntentReceiver { + + static String directs[] = {"NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"}; + MainActivity act; + String html, lineHeight, prefix; + int interval, cur, end, step; + boolean isFirst = true; + + public SrcSensor(Context context, JSMap json) { + super(context); + act = (MainActivity) context; + setBackgroundColor(Color.TRANSPARENT); + setVerticalScrollBarEnabled(false); + setHorizontalScrollBarEnabled(false); + setInitialScale(100); + html = json.stnn("html"); + lineHeight = json.str("lineHeight"); + prefix = ""; + } + + public static Method method; + static { + try { + method = Intent.class.getMethod("getExtra", String.class, Object.class); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void onReceive(Intent intent) { + try { +// for(var item : items) { +// item.nums.clear(); +// if(item.unit==null) { +// var num = intent.getIntExtra(item.key, -1); +// if(num>=0 && num<=15) item.nums.add(imgMap.get(directs[num])); +// else { +// var img = imgMap.get("-"); +// item.nums.add(img); +// item.nums.add(img); +// } +// } else { +// var num = ((Number) method.invoke(intent, item.key, -999)).doubleValue(); +// var str = num==-999 || (num==-1 && ! item.key.endsWith("rature")) ? "--" : NumFmts.zz().format(num); +// for(int cc=0; cc", "text/html", "UTF-8", null); + } catch (Exception e) { + Util.printStackTrace(e); + } + } + + @Override + public void onVisibilityAggregated(boolean isVisible) { + super.onVisibilityAggregated(isVisible); + if(isVisible) { + if(isFirst) { + isFirst = false; + onReceive(act.environIntent); + act.environs.add(this); + } + } else { + act.environs.remove(this); + isFirst = true; + } + } +}