diff --git a/XixunPlayer/.idea/vcs.xml b/XixunPlayer/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/XixunPlayer/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java index f519025..12dd487 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleEnviron.java @@ -36,7 +36,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback { Bitmap title; ArrayList items = new ArrayList<>(); MainActivity act; - int spaceWidth; + int spaceWidth, digitHeight; int interval, cur, end, step; boolean isScroll, isFirst = true; @@ -70,6 +70,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback { if(json.bool("bPM25")) items.add(new Item("pm2.5", imgMap.remove("labelpm25"), imgMap.get("unit_pm10"))); if(json.bool("bPM10")) items.add(new Item("pm10", imgMap.remove("labelpm10"), imgMap.get("unit_pm10"))); } + digitHeight = imgMap.get("0").getHeight(); var scrollSpeed = json.dbl("scrollSpeed"); if(scrollSpeed==0) { var scrollDur = json.dbl("iScrollSpeed"); @@ -128,11 +129,13 @@ public class EleEnviron extends View implements Choreographer.FrameCallback { canvas.drawBitmap(title, x, Math.round((getHeight() - title.getHeight()) / 2), null); x += title.getWidth() + spaceWidth<<1; } + var y = (int) Math.round((getHeight() - digitHeight) / 2); for(var item : items) { - var y = (int) Math.round((getHeight() - item.lable.getHeight()) / 2); - canvas.drawBitmap(item.lable, x, y, null); - x += item.lable.getWidth(); - for(var num : item.nums) { + if(item.lable!=null) { + canvas.drawBitmap(item.lable, x, y, null); + x += item.lable.getWidth(); + } + for(var num : item.nums) if(num!=null) { canvas.drawBitmap(num, x, y, null); x += num.getWidth(); } @@ -150,10 +153,13 @@ public class EleEnviron extends View implements Choreographer.FrameCallback { int i = 0; if(title!=null) canvas.drawBitmap(title, 0, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null); for(var item : items) { - var y = (int) Math.round(itemH * i++ + (itemH - item.lable.getHeight()) / 2); - canvas.drawBitmap(item.lable, 0, y, null); - var x = item.lable.getWidth(); - for(var num : item.nums) { + var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2); + var x = 0; + if(item.lable!=null) { + canvas.drawBitmap(item.lable, 0, y, null); + x += item.lable.getWidth(); + } + for(var num : item.nums) if(num!=null) { canvas.drawBitmap(num, x, y, null); x += num.getWidth(); } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleScroll.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleScroll.java index 2694390..4919478 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleScroll.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleScroll.java @@ -58,8 +58,9 @@ public class EleScroll extends View implements Choreographer.FrameCallback { canvas.drawBitmap(img, 0, cur-img.getHeight(), null); } else canvas.drawBitmap(img, 0, 0, null); if(freshCnt==0 && effect!=0 && interval!=0) choreographer.postFrameCallback(this); - } catch (RuntimeException e) { - ((Page) getParent()).remove(this); + } catch (Throwable e) { + setVisibility(GONE); + img = null; e.printStackTrace(); } } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java index a2797c0..38d0017 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java @@ -2,9 +2,10 @@ package com.xixun.xixunplayer; import android.content.Context; import android.media.MediaPlayer; +import android.view.Choreographer; import android.widget.VideoView; -public class EleVideo extends VideoView { +public class EleVideo extends VideoView implements Choreographer.FrameCallback { float vol = 1; @@ -12,9 +13,10 @@ public class EleVideo extends VideoView { super(context); setVideoPath(path); setOnPreparedListener((MediaPlayer player)->{ + player.setLooping(true); if(! isShown()) { - player.pause(); player.seekTo(0); + player.pause(); } if(vol!=1) player.setVolume(vol, vol); setOnPreparedListener(null); @@ -24,6 +26,7 @@ public class EleVideo extends VideoView { return true; }); start(); + choreographer.postFrameCallback(this); } @Override @@ -37,11 +40,24 @@ public class EleVideo extends VideoView { if(isVisible) { if(! isPlaying()) start(); } else { - pause(); seekTo(0); + pause(); + choreographer.postFrameCallback(this); } } + Choreographer choreographer = Choreographer.getInstance(); + @Override + public void doFrame(long frameTimeNanos) { + if(isShown()) return; + if(isPlaying()) { + seekTo(0); + pause(); + System.out.println("pause in doFrame()"); + } + choreographer.postFrameCallback(this); + } + static String getErrorName(int code) { if(code==MediaPlayer.MEDIA_ERROR_UNKNOWN) return "UNKNOWN"; if(code==MediaPlayer.MEDIA_ERROR_SERVER_DIED) return "SERVER_DIED"; 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 681f1a5..e921584 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java @@ -20,6 +20,7 @@ import android.os.StatFs; import android.view.Choreographer; import androidx.activity.ComponentActivity; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -37,8 +38,6 @@ import java.net.ServerSocket; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; @@ -75,9 +74,9 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra } } @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if(requestCode==999 && grantResults!=null && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED && backView==null) init(); + if(requestCode==999 && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED && backView==null) init(); } public void init() { @@ -100,9 +99,11 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra System.out.println("Bind cardsystem aidl service success"); var service = CardService.Stub.asInterface(iBinder); try { + Util.isScreenOn = service.isScreenOpen(); backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight()); state = 5; - initProg(); + if(Util.isScreenOn) initProg(); + else state = 8; if(progView==null) setContentView(backView); } catch (RemoteException e) { Util.makeText(MainActivity.this, e.getMessage()).show(); @@ -118,7 +119,8 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra @Override public void onReceive(Context context, Intent intent) { System.out.println("Receive PAUSE_PLAYER"); - if(intent.getBooleanExtra("pause", false)) { + Util.isScreenOn = ! intent.getBooleanExtra("pause", false); + if(! Util.isScreenOn) { state = 8; if(progView!=null) { progView.setVisibility(GONE); @@ -334,12 +336,10 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra var milli = System.currentTimeMillis(); var lastPage = page(curAva); if(milli >= syncMilli) { - lastPage.setVisibility(GONE); - if(lastPage.hasVideo && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1); + lastPage.hide(); syncProg(milli-syncMilli>=1000 ? milli : syncMilli); } else if(milli >= lastPage.endMilli) { - lastPage.setVisibility(GONE); - if(lastPage.hasVideo && curTimes==lastPage.repeatTimes && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1); + lastPage.hide(); if(curTimes < lastPage.repeatTimes) curTimes++; else { curTimes = 1; @@ -353,23 +353,18 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra page(curAva).setMillis(lastPage.endMilli); } else { for(var layer : lastPage.layers) { - for(var ele : layer.eles) if(ele.isShort) { - if(ele.view.getVisibility()!=VISIBLE) { - if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE); - } else { - if(milli >= ele.endMilli) ele.view.setVisibility(GONE); - } + for(var ele : layer.eles) { + if(ele.view.getVisibility()==VISIBLE) { + if(milli >= ele.endMilli) ele.hide(); + } else if(milli < ele.endMilli && milli >= ele.startMilli) ele.show(); } if(milli >= layer.endMilli) { layer.endMilli += layer.dur; for(var ele : layer.eles) { ele.endMilli += layer.dur; ele.startMilli += layer.dur; - if(ele.view.getVisibility()!=VISIBLE) { - if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE); - } else { - if(milli >= ele.endMilli) ele.view.setVisibility(GONE); - } + if(ele.startTime > 0) ele.hide(); + else ele.show(); } } } @@ -400,7 +395,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra avas.clear(); var dur = 0; Page page; - for(int i=0; i eles = new ArrayList<>(); long endMilli = Long.MAX_VALUE; int dur; - boolean repeat; + boolean isLoop; } public static class Sche { @@ -42,36 +55,19 @@ public class Page extends AbsoluteLayout { ArrayList sches; long endMilli = Long.MAX_VALUE; int dur, repeatTimes; - boolean hasVideo = false; - public Page(Context context) { - super(context); + void hide() { + for(var layer : layers) for(var ele : layer.eles) ele.hide(); } public void setMillis(long milli) { endMilli = milli + dur; for(var layer : layers) { - if(layer.repeat) layer.endMilli = milli + layer.dur; - for(var ele : layer.eles) if(ele.isShort) { - if(ele.startTime > 0) { - ele.startMilli = milli + ele.startTime; - ele.view.setVisibility(GONE); - } else ele.view.setVisibility(VISIBLE); + if(layer.isLoop) layer.endMilli = milli + layer.dur; + for(var ele : layer.eles) { ele.endMilli = milli + ele.endTime; - } - } - if(getLeft() != 0) setLeft(0); - setVisibility(VISIBLE); - } - public void remove(View view) { - view.setVisibility(GONE); - removeView(view); - for(int ll=0; ll 1) layer.eles.remove(ee); - else layers.remove(ll); - return; + ele.startMilli = milli + ele.startTime; + if(ele.startTime == 0) ele.show(); } } } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/ProgView.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/ProgView.java index 6d421c9..199a335 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/ProgView.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/ProgView.java @@ -5,9 +5,11 @@ import android.net.Uri; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.AbsoluteLayout; +import android.widget.FrameLayout; import android.widget.ImageView; import java.io.File; +import java.util.ArrayList; import gnph.util.JSList; import gnph.util.JSMap; @@ -15,20 +17,22 @@ import pl.droidsonroids.gif.GifImageView; public class ProgView extends AbsoluteLayout { + ArrayList pages = new ArrayList<>(); + public ProgView(JSMap task, int width, int height, Context context) { super(context); - JSList pages = task.jslist("items"); - for(var pageMap : pages) { + JSList jpages = task.jslist("items"); + for(var pageMap : jpages) { var _program = pageMap.jsmap("_program"); JSList layers = _program.jslist("layers"); if(layers.isEmpty()) continue; var splitWidths = _program.jslist("splitWidths"); - var page = new Page(context); + var page = new Page(); page.repeatTimes = pageMap.intg("repeatTimes"); page.parse(pageMap.jslist("schedules")); for(int ll=layers.size()-1; ll>=0; ll--) { var layer = new Page.Layer(); - layer.repeat = layers.get(ll).bool("repeat"); + layer.isLoop = layers.get(ll).bool("repeat"); JSList sources = layers.get(ll).jslist("sources"); var border = layers.get(ll).jsmap("border"); EleBorder bdEle = null; @@ -99,9 +103,11 @@ public class ProgView extends AbsoluteLayout { } else if(ele.type.equals("DigitalClockNew")) ele.view = new EleDigiClock(Util.programDir+"/", source, context); else if(ele.type.equals("AnalogClock")) ele.view = new EleAnaClock(w, h, Util.programDir+"/"+ele.id, source, context); else if(ele.type.equals("Video")) { - page.hasVideo = true; + ele.isVideo = true; var videoView = new EleVideo(Util.programDir + "/" + ele.id, context); - ele.view = videoView; + var frame = new FrameLayout(context); + frame.addView(videoView); + ele.view = frame; var vol = source.intg("vol", 100); if (vol < 100) videoView.vol = vol / 100.0f; } else if(ele.type.equals("Audio")) { @@ -124,7 +130,10 @@ public class ProgView extends AbsoluteLayout { else if(ele.type.equals("EnvironmentalMonitoring")) ele.view = new EleEnviron(Util.programDir+"/", source, context); else continue; if(ele.view==null) continue; - if(w>0) page.addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); + if(w > 0) { + ele.view.setVisibility(GONE); + addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); + } layer.eles.add(ele); ele = new Page.EleBase(); } @@ -137,7 +146,8 @@ public class ProgView extends AbsoluteLayout { ele.startTime = bdStart; ele.endTime = bdEnd; ele.view = bdEle; - page.addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); + ele.view.setVisibility(GONE); + addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); layer.eles.add(ele); } if(! layer.eles.isEmpty()) page.layers.add(layer); @@ -156,12 +166,11 @@ public class ProgView extends AbsoluteLayout { continue for_layer; } } else if(ele.endTime > page.dur) ele.endTime = page.dur; - ele.isShort = ele.startTime > 0 || ele.endTime < page.dur; } if(layer.dur > page.dur) layer.dur = page.dur; + if(layer.dur == page.dur) layer.isLoop = false; } - page.setVisibility(GONE); - addView(page, new AbsoluteLayout.LayoutParams(width, height, 0, 0)); + pages.add(page); } } } \ No newline at end of file diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java index b462e87..f9deb26 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java @@ -13,6 +13,8 @@ import gnph.util.IOs; public class Util { + public static boolean isScreenOn; + public static final HashMap stateDescs = new HashMap<>(); static { stateDescs.put(1, new String[]{"Initialize", "初始化"}); diff --git a/xixuncard b/xixuncard new file mode 100644 index 0000000..a7b3d65 Binary files /dev/null and b/xixuncard differ