This commit is contained in:
Gangphon 2024-08-22 17:37:46 +08:00
parent ef42b0eb98
commit a7a23e0b77
9 changed files with 322 additions and 160 deletions

View File

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

View File

@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:largeHeap="true"
android:allowBackup="true" android:allowBackup="true"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:launchMode="singleTop" android:launchMode="singleTop"

View File

@ -34,6 +34,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import gnph.util.Chsets; import gnph.util.Chsets;
@ -44,6 +45,7 @@ import gnph.util.JSMap;
public class MainActivity extends Activity implements Choreographer.FrameCallback, Runnable { public class MainActivity extends Activity implements Choreographer.FrameCallback, Runnable {
public static MainActivity ins; public static MainActivity ins;
ArrayList<BroadcastReceiver> reces = new ArrayList<>();
public Intent environIntent = new Intent(); public Intent environIntent = new Intent();
HashSet<IntentReceiver> environs = new HashSet<>(); HashSet<IntentReceiver> environs = new HashSet<>();
BackView backView; BackView backView;
@ -56,10 +58,13 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
var msg = "==== MainActivity onCreate ==== UI Thread: "+Thread.currentThread().getId();
Util.println(msg);
ins = this; ins = this;
startService(new Intent(this, RestartService.class)); Util.println("==>> MainActivity onCreate >>>> this "+hashCode()+" UI Thread: "+Thread.currentThread().getId());
try{
if(RestartService.ins==null) startService(new Intent(this, RestartService.class));
} catch(Throwable e) {
Util.printStackTrace(e);
}
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
@ -76,6 +81,58 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
@Override
protected void onDestroy() {
super.onDestroy();
Util.println("==<< MainActivity onDestroy <<<< this "+hashCode());
state = 8;
if(insView!=null) {
insView.release();
insView = null;
}
if(progView!=null) {
progView.release();
progView = null;
}
ins = null;
for(var rece : reces) {
try {
unregisterReceiver(rece);
} catch (Throwable ignored){
}
}
System.gc();
}
@Override
protected void onStart() {
super.onStart();
Util.println(" ==>> MainActivity onStart >> "+hashCode());
}
@Override
protected void onStop() {
super.onStop();
Util.println(" ==<< MainActivity onStop << "+hashCode());
}
@Override
protected void onRestart() {
super.onRestart();
Util.println(" ==>> MainActivity onRestart >> "+hashCode());
}
@Override
protected void onResume() {
super.onResume();
Util.println(" ==>> MainActivity onResume >> "+hashCode());
}
@Override
protected void onPause() {
super.onPause();
Util.println(" ==<< MainActivity onPause << "+hashCode());
}
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@ -152,7 +209,9 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
intent.setPackage("com.xixun.xy.conn"); intent.setPackage("com.xixun.xy.conn");
bindService(intent, connConn, Context.BIND_AUTO_CREATE); bindService(intent, connConn, Context.BIND_AUTO_CREATE);
registerReceiver(new BroadcastReceiver(){ reces.clear();
BroadcastReceiver rece;
registerReceiver(rece = new BroadcastReceiver(){
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Util.println("Receive PAUSE_PLAYER"); Util.println("Receive PAUSE_PLAYER");
@ -169,11 +228,13 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
progView = null; progView = null;
} }
setContentView(backView); setContentView(backView);
} else if(progView==null && insView==null) initProg(); } else if(progView==null && insView==null) MainActivity.ins.runOnUiThread(() -> initProg());
System.gc();
} }
}, new IntentFilter("com.xixun.action.PAUSE_PLAYER")); }, new IntentFilter("com.xixun.action.PAUSE_PLAYER"));
reces.add(rece);
registerReceiver(new BroadcastReceiver(){ registerReceiver(rece = new BroadcastReceiver(){
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Util.println("Receive CHANGE_COMPANYID"); Util.println("Receive CHANGE_COMPANYID");
@ -193,8 +254,9 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
}, new IntentFilter("com.xixun.joey.CHANGE_COMPANYID")); }, new IntentFilter("com.xixun.joey.CHANGE_COMPANYID"));
reces.add(rece);
registerReceiver(new BroadcastReceiver(){ registerReceiver(rece = new BroadcastReceiver(){
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
MainActivity.this.environIntent = intent; MainActivity.this.environIntent = intent;
@ -204,34 +266,36 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
}, new IntentFilter("xixun.intent.action.TEMPERATURE_HUMIDITY")); }, new IntentFilter("xixun.intent.action.TEMPERATURE_HUMIDITY"));
reces.add(rece);
registerReceiver(new BroadcastReceiver(){ registerReceiver(rece = new BroadcastReceiver(){
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try { try {
var code = intent.getIntExtra("code", 0); var code = intent.getIntExtra("code", 0);
Util.println(" remote_control "+code); Util.println(" remote_control "+code);
if(progView == null || ! progView.isShown() || code > progView.pages.size()) return; if(progView == null || ! progView.isShown() || code > progView.pages.size()) return;
if(! progView.avas.isEmpty()) { var page = progView.pages.get(code-1);
progView.curAva().hide(); var ms = System.currentTimeMillis();
if(progView.avas.size()==1 && progView.avas.get(0)==code-1) for(var call : progView.calls) call.doFrame(System.currentTimeMillis()); if(! avas.isEmpty()) {
avas.get(curAva).hide();
if(avas.size()==1 && avas.get(0)==page) for(var call : progView.calls) call.doFrame(ms);
} }
var millis = (System.currentTimeMillis()+999)/1000*1000; ms = (ms+999)/1000*1000;
if(code > 0) { if(code > 0) {
progView.avas.clear(); avas.clear();
progView.avas.add(code-1); avas.add(page);
progView.curAva = 0; curAva = 0;
progView.curTimes = 1; curTimes = 1;
progView.waitTo = 0; //点播 waitTo = 0; //点播
var page = progView.curAva(); page.setMillis(ms);
page.setMillis(millis);
if(state != 6) { if(state != 6) {
setContentView(progView); setContentView(progView);
state = 6; state = 6;
} }
} else { } else {
progView.waitTo = Long.MAX_VALUE; waitTo = Long.MAX_VALUE;
syncProg(millis); syncProg(ms);
} }
} catch (Throwable e) { } catch (Throwable e) {
Util.makeText(MainActivity.this, Util.toStr(e)).show(); Util.makeText(MainActivity.this, Util.toStr(e)).show();
@ -239,10 +303,11 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
}, new IntentFilter("com.xixun.yzd.REMOTE_CONTROL")); }, new IntentFilter("com.xixun.yzd.REMOTE_CONTROL"));
reces.add(rece);
var intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); var intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
intentFilter.addDataScheme("file"); intentFilter.addDataScheme("file");
registerReceiver(new BroadcastReceiver(){ registerReceiver(rece = new BroadcastReceiver(){
long lastMs; long lastMs;
final char[] pass = {'8','8','8'}; final char[] pass = {'8','8','8'};
@Override @Override
@ -296,6 +361,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
}).start(); }).start();
} }
}, intentFilter); }, intentFilter);
reces.add(rece);
new Thread(this).start(); new Thread(this).start();
} }
@ -310,6 +376,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
progView = null; progView = null;
} }
setContentView(backView); setContentView(backView);
System.gc();
} }
public boolean delProgFile() { public boolean delProgFile() {
stopProg(); stopProg();
@ -407,6 +474,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
fOut.getFD().sync(); fOut.getFD().sync();
fOut.close(); fOut.close();
state = 5; state = 5;
System.gc();
Util.println("Init Sync"); Util.println("Init Sync");
syncProg((System.currentTimeMillis()+999)/1000*1000); syncProg((System.currentTimeMillis()+999)/1000*1000);
if(canAdd) { if(canAdd) {
@ -421,6 +489,11 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
ArrayList<Prog.Page> avas = new ArrayList<>();
int curAva, curTimes = 1;
long waitTo = Long.MAX_VALUE;
boolean isInsert;
Choreographer choreographer = Choreographer.getInstance(); Choreographer choreographer = Choreographer.getInstance();
boolean canAdd = true; boolean canAdd = true;
@ -430,72 +503,64 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
canAdd = true; canAdd = true;
return; return;
} }
choreographer.postFrameCallback(this);
canAdd = false;
var milli = System.currentTimeMillis(); var milli = System.currentTimeMillis();
if(insView!=null && ! insView.avas.isEmpty()) { if(avas.isEmpty()) {
var lastPage = insView.curAva(); if(milli >= waitTo) {
if(milli >= lastPage.endMilli) { waitTo = Long.MAX_VALUE;
lastPage.hide();
if(--lastPage.repeatTimes<=0 && ++insView.curAva >= insView.avas.size()) {
var isDiff = milli-lastPage.endMilli>=1000;
Util.println("isDiff: "+isDiff+" endMs: "+lastPage.endMilli+" millis:"+milli);
syncProg(isDiff ? milli : lastPage.endMilli);
choreographer.postFrameCallback(this);
canAdd = false;
if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
return;
}
insView.curAva().setMillis(lastPage.endMilli);
Util.println("curAva: "+insView.curAva+" endMs: "+insView.curAva().endMilli);
} else lastPage.showHideSrcs(milli);
choreographer.postFrameCallback(this);
canAdd = false;
for(var call : insView.calls) call.doFrame(milli);
return;
}
if(progView.avas.isEmpty()) {
if(milli >= progView.waitTo) {
progView.waitTo = Long.MAX_VALUE;
Util.println("wait sync"); Util.println("wait sync");
syncProg(milli); syncProg(milli);
if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
} }
} else { return;
var lastPage = progView.curAva(); }
if(milli >= lastPage.endMilli) { var lastPage = avas.get(curAva);
lastPage.hide(); if(milli < lastPage.endMilli) lastPage.showHideSrcs(milli);
if(progView.waitTo > 0) { //waitTo==0 为点播不换页 else {
if(progView.curTimes < lastPage.repeatTimes) progView.curTimes++; lastPage.hide();
if(isInsert) {
if(--lastPage.repeatTimes<=0 && ++curAva >= avas.size()) {
var isDiff = milli-lastPage.endMilli>=1000;
syncProg(isDiff ? milli : lastPage.endMilli);
if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
return;
}
} else {
if(waitTo > 0) { //waitTo==0 为点播不换页
if(curTimes < lastPage.repeatTimes) curTimes++;
else { else {
progView.curTimes = 1; curTimes = 1;
if(++progView.curAva >= progView.avas.size()) { if(++curAva >= avas.size()) {
var isDiff = milli-lastPage.endMilli>=1000; var isDiff = milli-lastPage.endMilli>=1000;
if(Util.buf.length()>1000000) Util.buf.replace(0, 100000, "");
Util.println("isDiff: "+isDiff+" endMs: "+lastPage.endMilli+" millis:"+milli);
syncProg(isDiff ? milli : lastPage.endMilli); syncProg(isDiff ? milli : lastPage.endMilli);
if(! progView.isShown() || progView.avas.isEmpty()) Util.println("after. No Avas"); if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
else Util.println("after. curAva: "+progView.curAva+" endMs: "+progView.curAva().endMilli); if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
choreographer.postFrameCallback(this);
canAdd = false;
for(var call : progView.calls) call.doFrame(milli);
return; return;
} }
} }
} }
progView.curAva().setMillis(lastPage.endMilli); }
Util.println("curAva: "+progView.curAva+" endMs: "+progView.curAva().endMilli); avas.get(curAva).setMillis(lastPage.endMilli);
} else lastPage.showHideSrcs(milli); Util.println("curAva: "+curAva+" endMs: "+avas.get(curAva).endMilli);
} }
choreographer.postFrameCallback(this); if(isInsert) for(var call : insView.calls) call.doFrame(milli);
canAdd = false; else for(var call : progView.calls) call.doFrame(milli);
for(var call : progView.calls) call.doFrame(milli);
} }
void syncProg(long milli) { void syncProg(long milli) {
Util.println("\nSyncProg");
avas.clear();
curAva = 0;
curTimes = 1;
isInsert = false;
if(insView!=null) { if(insView!=null) {
insView.avas.clear();
for(int i=0; i<insView.pages.size(); i++) if(insView.pages.get(i).repeatTimes <= 0) { for(int i=0; i<insView.pages.size(); i++) if(insView.pages.get(i).repeatTimes <= 0) {
for(var layer : insView.pages.get(i).layers) for(var src : layer.srcs) { for(var layer : insView.pages.get(i).layers) for(var src : layer.srcs) {
insView.removeView(src.view); insView.removeView(src.view);
insView.calls.remove(src); if(src.view instanceof Choreographer.FrameCallback) insView.calls.remove((Choreographer.FrameCallback) src.view);
} }
insView.pages.remove(i--); insView.pages.remove(i--);
} }
@ -511,63 +576,57 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} catch(Exception e) { } catch(Exception e) {
Util.printStackTrace(e); Util.printStackTrace(e);
} }
System.gc();
} else { } else {
var dur = 0; var dur = 0;
for(int i=0; i<insView.pages.size(); i++) if(insView.pages.get(i).isScheOn(milli+dur)) { for(var page : insView.pages) if(page.isScheOn(milli+dur)) {
insView.avas.add(i); avas.add(page);
dur += insView.pages.get(i).tDur; dur += page.tDur;
} }
if(dur==0) for(int i=0; i<insView.pages.size(); i++) if(insView.pages.get(i).sches==null) { if(avas.isEmpty()) for(var page : insView.pages) if(page.sches==null) avas.add(page);
insView.avas.add(i); if(! avas.isEmpty()) {
dur += insView.pages.get(i).tDur; isInsert = true;
} avas.get(curAva).setMillis(milli);
if(dur!=0) {
insView.curAva = 0;
insView.curAva().setMillis(milli);
if(! insView.isShown()) setContentView(insView); if(! insView.isShown()) setContentView(insView);
state = 6; state = 6;
Util.println("avas "+avas.size()+" Insert");
return; return;
} }
} }
} }
if(progView!=null) { if(progView!=null) {
progView.curTimes = 1;
progView.avas.clear();
var dur = 0; var dur = 0;
for(int i=0; i<progView.pages.size(); i++) if(progView.pages.get(i).isScheOn(milli+dur)) { for(var page : progView.pages) if(page.isScheOn(milli+dur)) {
progView.avas.add(i); avas.add(page);
dur += progView.pages.get(i).tDur; dur += page.tDur;
} }
if(dur==0) { if(dur==0) for(var page : progView.pages) if(page.sches==null) {
for(int i=0; i<progView.pages.size(); i++) if(progView.pages.get(i).sches==null) { avas.add(page);
progView.avas.add(i); dur += page.tDur;
dur += progView.pages.get(i).tDur; }
} if(dur!=0) {
if(dur==0) { var start = milli / dur * dur;
progView.waitTo = milli + 1000; if(start < milli) {
if(state!=2) { do {
setContentView(backView); start += avas.get(curAva++).tDur;
state = 2; } while(curAva < avas.size() && start<=milli);
} start -= avas.get(--curAva).tDur;
return; syncMs = milli;
Util.println("Sync. dur: "+dur+" milli: "+milli+" start: "+start+" diff: "+(milli - start));
} }
avas.get(curAva).setMillis(start);
if(! progView.isShown()) setContentView(progView);
state = 6;
Util.println("Avas "+avas.size());
return;
} }
var start = milli / dur * dur;
progView.curAva = 0;
if(start < milli) {
do {
start += progView.curAva().tDur;
progView.curAva++;
} while(progView.curAva < progView.avas.size() && start<=milli);
progView.curAva--;
start -= progView.curAva().tDur;
syncMs = milli;
Util.println("Sync. dur: "+dur+" milli: "+milli+" start: "+start+" diff: "+(milli - start));
}
progView.curAva().setMillis(start);
if(! progView.isShown()) setContentView(progView);
state = 6;
} }
waitTo = milli + 1000;
if(state!=2) {
setContentView(backView);
state = 2;
}
Util.println("No Avas, back");
} }
public void run() { public void run() {
@ -577,15 +636,16 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
try { try {
Util.println("\nAccepting ..."); Util.println("\nAccepting ...");
var socket = serverSocket.accept(); var socket = serverSocket.accept();
new SocketThread(this, socket).start(); new SocketThread(MainActivity.ins, socket).start();
Util.println("\nAccepted"); Util.println("\nAccepted");
} catch (Throwable e) { } catch (Throwable e) {
MainActivity.ins.runOnUiThread(() -> Util.makeText(MainActivity.this, Util.toStr(e)).show()); if(MainActivity.ins!=null) MainActivity.ins.runOnUiThread(() -> Util.makeText(MainActivity.ins, Util.toStr(e)).show());
Util.printStackTrace(e); Util.printStackTrace(e);
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
MainActivity.ins.runOnUiThread(() -> Util.makeText(MainActivity.this, Util.toStr(e)).show()); var msg = e.getMessage();
if(msg==null || ! msg.contains("EADDRINUSE")) MainActivity.ins.runOnUiThread(() -> Util.makeText(MainActivity.ins, Util.toStr(e)).show());
Util.printStackTrace(e); Util.printStackTrace(e);
} }
} }

View File

@ -6,16 +6,27 @@ import android.os.IBinder;
public class RestartService extends Service { public class RestartService extends Service {
static RestartService ins;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Util.println("---- RestartService onCreate"); ins = this;
Util.println("==>> RestartService onCreate >>>> "+hashCode());
if(MainActivity.ins!=null) return; if(MainActivity.ins!=null) return;
var intent = new Intent(this, MainActivity.class); var intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
} }
@Override
public void onDestroy() {
super.onDestroy();
Util.println("==<< RestartService onDestroy <<<< this "+hashCode());
ins = null;
System.gc();
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented"); throw new UnsupportedOperationException("Not yet implemented");

View File

@ -35,10 +35,8 @@ public class Server extends Service {
public String getProgramName() throws RemoteException { public String getProgramName() throws RemoteException {
try { try {
String name = null; String name = null;
if(MainActivity.ins!=null) { var ins = MainActivity.ins;
if(MainActivity.ins.insView!=null && ! MainActivity.ins.insView.avas.isEmpty()) name = MainActivity.ins.insView.curAva().name; if(ins!=null && ! ins.avas.isEmpty()) name = ins.avas.get(ins.curAva).name;
else if(MainActivity.ins.progView!=null && ! MainActivity.ins.progView.avas.isEmpty()) name = MainActivity.ins.progView.curAva().name;
}
Util.println("Server getProgramName. <-"+name); Util.println("Server getProgramName. <-"+name);
return name; return name;
} catch (Exception e) { } catch (Exception e) {

View File

@ -100,7 +100,7 @@ public class SocketThread extends Thread {
fout.flush(); fout.flush();
fout.getFD().sync(); fout.getFD().sync();
fout.close(); fout.close();
main.runOnUiThread(() -> { if(main!=null) main.runOnUiThread(() -> {
main.backView.cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled); main.backView.cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled);
main.backView.invalidate(); main.backView.invalidate();
}); });
@ -110,7 +110,14 @@ public class SocketThread extends Thread {
if(progJson!=null) { if(progJson!=null) {
var json = progJson.toByteArray(); var json = progJson.toByteArray();
progJson = null; progJson = null;
main.runOnUiThread(() -> main.initProg(json)); if(main!=null) main.runOnUiThread(() -> main.initProg(json));
else {
var fOut = new FileOutputStream(Util.programDir + "/program");
fOut.write(json);
fOut.flush();
fOut.getFD().sync();
fOut.close();
}
} }
} else if("playZipTask".equals(_type)) { } else if("playZipTask".equals(_type)) {
var zip = new ZipFile(Util.programDir+"/"+obj.stnn("proName")); var zip = new ZipFile(Util.programDir+"/"+obj.stnn("proName"));
@ -126,11 +133,11 @@ public class SocketThread extends Thread {
if(jsonOut==null) { if(jsonOut==null) {
Util.println("No 'program' File"); Util.println("No 'program' File");
new JSMap("success", false, "msg", "No 'program' File").write(out); new JSMap("success", false, "msg", "No 'program' File").write(out);
main.runOnUiThread(() -> Util.makeText(main, "No program File").show()); if(main!=null) main.runOnUiThread(() -> Util.makeText(main, "No program File").show());
} else if(size==0) { } else if(size==0) {
Util.println("Zip Size is 0"); Util.println("Zip Size is 0");
new JSMap("success", false, "msg", "Zip Size is 0").write(out); new JSMap("success", false, "msg", "Zip Size is 0").write(out);
main.runOnUiThread(() -> Util.makeText(main, "zip size is 0").show()); if(main!=null) main.runOnUiThread(() -> Util.makeText(main, "zip size is 0").show());
} else { } else {
Util.deleteFiles(size, null); Util.deleteFiles(size, null);
for(var header : headers) if(! "program".equals(header.getFileName())) { for(var header : headers) if(! "program".equals(header.getFileName())) {
@ -142,19 +149,19 @@ public class SocketThread extends Thread {
fOut.close(); fOut.close();
} }
var json = jsonOut.toByteArray(); var json = jsonOut.toByteArray();
main.runOnUiThread(()->main.initProg(json)); if(main!=null) main.runOnUiThread(()->main.initProg(json));
Util.println(" Succeed"); Util.println(" Succeed");
new JSMap("success", true).write(out); new JSMap("success", true).write(out);
} }
} catch (Exception e) { } catch (Exception e) {
Util.printStackTrace(e); Util.printStackTrace(e);
new JSMap("success", false).write(out); new JSMap("success", false).write(out);
main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show()); if(main!=null) main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show());
} }
} else if("DelPrograms".equals(_type)) { } else if("DelPrograms".equals(_type)) {
var latch = new CountDownLatch(1); var latch = new CountDownLatch(1);
var ok = new AtomicBoolean(false); var ok = new AtomicBoolean(false);
main.runOnUiThread(() -> { if(main!=null) main.runOnUiThread(() -> {
ok.set(main.delProgFile()); ok.set(main.delProgFile());
latch.countDown(); latch.countDown();
}); });
@ -169,9 +176,10 @@ public class SocketThread extends Thread {
}); });
new JSMap("success", new File(Util.backImgFile).delete()).write(out); new JSMap("success", new File(Util.backImgFile).delete()).write(out);
} else if("getPlayerState".equals(_type)) { } else if("getPlayerState".equals(_type)) {
var descs = Util.getState(main.state); var state = main==null ? 8 : main.state;
var descs = Util.getState(state);
new JSMap( new JSMap(
"code", main.state, "code", state,
"des_en", descs[0], "des_en", descs[0],
"des", descs[1] "des", descs[1]
).write(out); ).write(out);
@ -179,22 +187,28 @@ public class SocketThread extends Thread {
var writer = new OutputStreamWriter(out); var writer = new OutputStreamWriter(out);
var fmt = new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"); var fmt = new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS");
var dur = 0; var dur = 0;
if(main.progView!=null) for(var page : main.progView.pages) dur += page.tDur; if(main==null) writer.append("\nAPP is Closed\n");
writer.append("ProgSend: ").append(fmt.format(new File(Util.programDir + "/program").lastModified())).append(" ProgDur: ").append(String.valueOf(dur)).append("ms"); else {
if(main.progView!=null) writer.append(" Size Avas: ").append(String.valueOf(main.progView.avas.size())).append(" Pages: ").append(String.valueOf(main.progView.pages.size())); if(main.progView!=null) for(var page : main.progView.pages) dur += page.tDur;
writer.append("\n"); writer.append("ProgSend: ").append(fmt.format(new File(Util.programDir + "/program").lastModified())).append(" ProgDur: ").append(String.valueOf(dur)).append("ms");
writer.append(" Launch: ").append(fmt.format(main.launchMilli)).append("\n"); writer.append(" Size Avas: ").append(String.valueOf(main.avas.size())).append(" Pages: ").append(main.progView==null ? "null" : String.valueOf(main.progView.pages.size()));
writer.append(" Sync: ").append(fmt.format(main.syncMs)).append("\n"); writer.append("\n");
if(main.progView==null) writer.append(" ProgView is Null\n"); writer.append(" Launch: ").append(fmt.format(main.launchMilli)).append("\n");
else if(main.progView.avas.isEmpty()) writer.append(" No Avas\n"); writer.append(" Sync: ").append(fmt.format(main.syncMs)).append("\n");
else writer.append("Page End: ").append(fmt.format(main.progView.curAva().endMilli)).append(" CurPage: ").append(String.valueOf(main.progView.curAva)).append(" / ").append(String.valueOf(main.progView.avas.get(main.progView.curAva))).append("\n"); if(main.insView==null) writer.append(" InseView is Null\n");
if(main.progView==null) writer.append(" ProgView is Null\n");
if(main.avas.isEmpty()) writer.append(" No Avas\n");
else writer.append("Page End: ").append(fmt.format(main.avas.get(main.curAva).endMilli)).append(" CurPage: ").append(String.valueOf(main.curAva)).append(" ").append(String.valueOf(main.avas.get(main.curAva).name)).append("\n");
}
writer.append(" Current: ").append(fmt.format(System.currentTimeMillis())).append(" ").append(String.valueOf(TimeZone.getDefault().getRawOffset()/3600000f)).append(" ").append(TimeZone.getDefault().getDisplayName()).append("\n"); writer.append(" Current: ").append(fmt.format(System.currentTimeMillis())).append(" ").append(String.valueOf(TimeZone.getDefault().getRawOffset()/3600000f)).append(" ").append(TimeZone.getDefault().getDisplayName()).append("\n");
var statFs = new StatFs(Environment.getExternalStorageDirectory().getPath()); var statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
writer.append(" Disk: ").append(String.valueOf(statFs.getTotalBytes()/1000000)).append(" ").append(String.valueOf(statFs.getAvailableBytes()/1000000)).append(" ").append(String.valueOf(statFs.getFreeBytes()/1000000)).append(" (total avail free)\n"); writer.append(" Disk: ").append(String.valueOf(statFs.getTotalBytes()/1000000)).append(" ").append(String.valueOf(statFs.getAvailableBytes()/1000000)).append(" ").append(String.valueOf(statFs.getFreeBytes()/1000000)).append(" (total avail free)\n");
var actManager = (ActivityManager) main.getSystemService(main.ACTIVITY_SERVICE); if(main!=null) {
var memoryInfo = new ActivityManager.MemoryInfo(); var actManager = (ActivityManager) main.getSystemService(MainActivity.ACTIVITY_SERVICE);
actManager.getMemoryInfo(memoryInfo); var memoryInfo = new ActivityManager.MemoryInfo();
writer.append(" Memory: ").append(String.valueOf(memoryInfo.totalMem/1000000)).append(" ").append(String.valueOf(memoryInfo.availMem/1000000)).append(" ").append(String.valueOf(memoryInfo.threshold/1000000)).append(" ").append(String.valueOf(memoryInfo.lowMemory)).append(" (total avail threshold low)\n"); actManager.getMemoryInfo(memoryInfo);
writer.append(" Memory: ").append(String.valueOf(memoryInfo.totalMem/1000000)).append(" ").append(String.valueOf(memoryInfo.availMem/1000000)).append(" ").append(String.valueOf(memoryInfo.threshold/1000000)).append(" ").append(String.valueOf(memoryInfo.lowMemory)).append(" (total avail threshold low)\n");
}
var runtime = Runtime.getRuntime(); var runtime = Runtime.getRuntime();
writer.append("Runtime: ").append(String.valueOf(runtime.maxMemory()/1000000)).append(" ").append(String.valueOf(runtime.totalMemory()/1000000)).append(" ").append(NumFmts.cfix2().format(runtime.freeMemory()*0.000001)).append(" (max total free)\n"); writer.append("Runtime: ").append(String.valueOf(runtime.maxMemory()/1000000)).append(" ").append(String.valueOf(runtime.totalMemory()/1000000)).append(" ").append(NumFmts.cfix2().format(runtime.freeMemory()*0.000001)).append(" (max total free)\n");
// writer.append("/proc/stat\n"); // writer.append("/proc/stat\n");
@ -204,9 +218,9 @@ public class SocketThread extends Thread {
writer.append("\n"); writer.append("\n");
var latch = new CountDownLatch(1); var latch = new CountDownLatch(1);
main.runOnUiThread(() -> { if(main!=null) main.runOnUiThread(() -> {
if(main.progView!=null && ! main.progView.avas.isEmpty()) { if(! main.avas.isEmpty()) {
var page = main.progView.curAva(); var page = main.avas.get(main.curAva);
for(var layer : page.layers) for(var src : layer.srcs) if(src.view.getVisibility()==VISIBLE) { for(var layer : page.layers) for(var src : layer.srcs) if(src.view.getVisibility()==VISIBLE) {
try { try {
if(src.view instanceof SrcVideo) { if(src.view instanceof SrcVideo) {
@ -240,7 +254,7 @@ public class SocketThread extends Thread {
var view = (WebView) src.view; var view = (WebView) src.view;
writer.append("Title: ").append(view.getTitle()).append("\n"); writer.append("Title: ").append(view.getTitle()).append("\n");
writer.append(" Url: ").append(view.getUrl()).append("\n"); writer.append(" Url: ").append(view.getUrl()).append("\n");
writer.append("OrUrl: ").append(view.getOriginalUrl()).append("\n"); writer.append("OriginUrl: ").append(view.getOriginalUrl()).append("\n");
writer.append("Progress: ").append(String.valueOf(view.getProgress())).append("\n"); writer.append("Progress: ").append(String.valueOf(view.getProgress())).append("\n");
} }
} catch (Exception ignored) { } catch (Exception ignored) {
@ -275,13 +289,24 @@ public class SocketThread extends Thread {
} }
} }
} else if("GetJsonWithFileInfo".equals(_type)) { } else if("GetJsonWithFileInfo".equals(_type)) {
var inse = new File(Util.programDir+"/insert");
var files = new File(Util.programDir).listFiles();
if(inse.isFile()) {
var json = IOs.readStrClose(new FileInputStream(inse));
if(files!=null) for(var file : files) if(! "program".equals(file.getName())) json = json.replace("\""+file.getName()+"\"", "\""+file.getName()+"\"/*"+file.length()+" "+fmt.format(new Date(file.lastModified()))+"*/");
var writer = new OutputStreamWriter(out);
writer.append("insert:\n");
writer.append(json);
if(! json.endsWith("\n")) writer.append("\n");
writer.flush();
}
var prog = new File(Util.programDir+"/program"); var prog = new File(Util.programDir+"/program");
if(! prog.isFile()) new JSMap("msg", "'program' file not exist").write(out); if(! prog.isFile()) new JSMap("msg", "'program' file not exist").write(out);
else { else {
var json = IOs.readStrClose(new FileInputStream(prog)); var json = IOs.readStrClose(new FileInputStream(prog));
var files = new File(Util.programDir).listFiles();
if(files!=null) for(var file : files) if(! "program".equals(file.getName())) json = json.replace("\""+file.getName()+"\"", "\""+file.getName()+"\"/*"+file.length()+" "+fmt.format(new Date(file.lastModified()))+"*/"); if(files!=null) for(var file : files) if(! "program".equals(file.getName())) json = json.replace("\""+file.getName()+"\"", "\""+file.getName()+"\"/*"+file.length()+" "+fmt.format(new Date(file.lastModified()))+"*/");
var writer = new OutputStreamWriter(out); var writer = new OutputStreamWriter(out);
writer.append("\nprogram:\n");
writer.append(json); writer.append(json);
writer.flush(); writer.flush();
} }
@ -295,7 +320,7 @@ public class SocketThread extends Thread {
Util.println(emsg); Util.println(emsg);
return; return;
} }
main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show()); if(main!=null) main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show());
Util.printStackTrace(e); Util.printStackTrace(e);
} finally { } finally {
Util.socketThreads.remove(this); Util.socketThreads.remove(this);

View File

@ -25,15 +25,19 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
public SrcScroll(Prog prog, JSMap json, Bitmap img) { public SrcScroll(Prog prog, JSMap json, Bitmap img) {
super(prog.getContext()); super(prog.getContext());
if(img==null) img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id")); if(img==null) img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id"));
var imgsWidth = img.getWidth(); if(img.getWidth() > 8192) {
if(imgsWidth <= 8192) imgs.add(img);
else {
var rem = img.getWidth(); var rem = img.getWidth();
do { do {
imgs.add(Bitmap.createBitmap(img, img.getWidth()-rem, 0, Math.min(8192, rem), img.getHeight())); imgs.add(Bitmap.createBitmap(img, img.getWidth()-rem, 0, Math.min(8192, rem), img.getHeight()));
rem -= 8192; rem -= 8192;
} while (rem>0); } while (rem>0);
} } else if(img.getHeight() > 8192) {
var rem = img.getHeight();
do {
imgs.add(Bitmap.createBitmap(img, 0, img.getHeight()-rem, img.getWidth(), Math.min(8192, rem)));
rem -= 8192;
} while (rem>0);
} else imgs.add(img);
var effStr = json.str("effect"); var effStr = json.str("effect");
if(effStr==null || effStr.equals("no")) return; if(effStr==null || effStr.equals("no")) return;
var scrollSpeed = json.dbl("scrollSpeed"); var scrollSpeed = json.dbl("scrollSpeed");
@ -48,10 +52,10 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
int idx = effStr.lastIndexOf(' '); int idx = effStr.lastIndexOf(' ');
if(idx > -1) { if(idx > -1) {
effect = effStr.charAt(idx+1); effect = effStr.charAt(idx+1);
if(effect=='l') end = -(imgsWidth-step); if(effect=='l') end = -(img.getWidth()-step);
else if(effect=='r') end = imgsWidth-step; else if(effect=='r') end = img.getWidth()-step;
else if(effect=='t') end = -(imgs.get(0).getHeight()-step); else if(effect=='t') end = -(img.getHeight()-step);
else if(effect=='b') end = imgs.get(0).getHeight()-step; else if(effect=='b') end = img.getHeight()-step;
else effect = 0; else effect = 0;
} }
if(effect!=0) prog.calls.add(this); if(effect!=0) prog.calls.add(this);

View File

@ -21,17 +21,19 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
String path; String path;
float vol; float vol;
int dur;
IjkMediaPlayer ijkPlayer; IjkMediaPlayer ijkPlayer;
ExoPlayer exoPlayer; ExoPlayer exoPlayer;
long bitRate; long bitRate;
boolean isLive; boolean isLive;
public SrcVideo(Context context, String path, float vol, boolean isLive) { public SrcVideo(Context context, String path, float vol, int dur, boolean useHW, boolean isLive) {
super(context); super(context);
this.path = path; this.path = path;
this.vol = vol; this.vol = vol;
this.dur = dur;
this.isLive = isLive; this.isLive = isLive;
initIjk(); initIjk(useHW);
} }
@OptIn(markerClass = UnstableApi.class) @OptIn(markerClass = UnstableApi.class)
@ -44,9 +46,12 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
exoPlayer.setVideoTextureView(this); exoPlayer.setVideoTextureView(this);
exoPlayer.prepare(); exoPlayer.prepare();
} }
void initIjk() { void initIjk(boolean useHW) {
ijkPlayer = new IjkMediaPlayer(); ijkPlayer = new IjkMediaPlayer();
//ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1); if(useHW) {
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", 1);
}
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
@ -62,6 +67,9 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
setSurfaceTextureListener(null); setSurfaceTextureListener(null);
release(); release();
initExo(); initExo();
} else {
var diff = dur - ijkPlayer.getDuration();
if(diff>0 && diff<=1000) ijkPlayer.setLooping(false);
} }
if(isShown()) start(); if(isShown()) start();
}); });

View File

@ -0,0 +1,55 @@
package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.Choreographer;
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 {
String url;
int refresh;
@SuppressLint("SetJavaScriptEnabled")
public SrcWeb(Prog prog, JSMap json) {
super(prog.getContext());
var settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setLoadsImagesAutomatically(true);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
setBackgroundColor(Color.TRANSPARENT);
setInitialScale(json.intg("zoom", 100));
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("+json.str("offX", "0")+", "+json.str("offY", "0")+")");
}
});
loadUrl(url = json.str("url"));
refresh = json.intg("refreshSec")*1000;
if(refresh>0 && url!=null) prog.calls.add(this);
nextMs = System.currentTimeMillis() + refresh;
}
long nextMs;
@Override
public void doFrame(long ms) {
if(! isShown()) return;
if(ms>=nextMs) {
nextMs = ms + refresh;
loadUrl(url);
}
}
}