This commit is contained in:
Gangphon 2024-07-04 17:45:56 +08:00
parent 4ed3aacec7
commit 0d95ad356f
4 changed files with 71 additions and 18 deletions

View File

@ -212,7 +212,10 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
var code = intent.getIntExtra("code", 0);
Util.println(" remote_control "+code);
if(progView == null || ! progView.isShown() || code > progView.pages.size()) return;
if(! progView.avas.isEmpty()) progView.curAva().hide();
if(! progView.avas.isEmpty()) {
progView.curAva().hide();
if(progView.avas.size()==1 && progView.avas.get(0)==code-1) for(var call : progView.calls) call.doFrame(System.currentTimeMillis());
}
var millis = (System.currentTimeMillis()+999)/1000*1000;
if(code > 0) {
progView.avas.clear();
@ -255,16 +258,13 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
var zip = new ZipFile(path+"/program.zip");
if(zip.isEncrypted()) zip.setPassword(pass);
long size = 0;
ByteArrayOutputStream progJson = null;
ByteArrayOutputStream jsonOut = null;
var headers = zip.getFileHeaders();
for(var header : headers) {
size += header.getUncompressedSize();
if("program".equals(header.getFileName())) {
progJson = new ByteArrayOutputStream();
IOs.writeClose(progJson, zip.getInputStream(header));
}
if("program".equals(header.getFileName())) IOs.writeClose(jsonOut = new ByteArrayOutputStream(), zip.getInputStream(header));
}
if(progJson==null) {
if(jsonOut==null) {
Util.println("No program File");
runOnUiThread(() -> Util.makeText(MainActivity.this, "No program File").show());
return;
@ -283,7 +283,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
fOut.getFD().sync();
fOut.close();
}
var json = progJson.toByteArray();
var json = jsonOut.toByteArray();
runOnUiThread(() -> {
Util.println("Import Succeed");
Util.makeText(MainActivity.this, "Import Succeed 导入成功\nDon't shut down within 1 minute, otherwise the program may be lost\n不要在 1 分钟内关机,否则节目可能丢失").show();

View File

@ -34,7 +34,11 @@ public class Server extends Service {
@Override
public String getProgramName() throws RemoteException {
try {
var name = MainActivity.ins!=null && MainActivity.ins.progView!=null && ! MainActivity.ins.progView.avas.isEmpty() ? MainActivity.ins.progView.curAva().name : null;
String name = null;
if(MainActivity.ins!=null) {
if(MainActivity.ins.insView!=null && ! MainActivity.ins.insView.avas.isEmpty()) name = MainActivity.ins.insView.curAva().name;
else if(MainActivity.ins.progView!=null && ! MainActivity.ins.progView.avas.isEmpty()) name = MainActivity.ins.progView.curAva().name;
}
Util.println("Server getProgramName. <-"+name);
return name;
} catch (Exception e) {
@ -312,7 +316,9 @@ public class Server extends Service {
@Override
public int countOfPrograms(int type) throws RemoteException {
return 0;
var cnt = MainActivity.ins!=null && MainActivity.ins.progView!=null ? MainActivity.ins.progView.pages.size() : 0;
Util.println("Server countOfPrograms. <-"+cnt);
return cnt;
}
@Override

View File

@ -11,6 +11,8 @@ import android.webkit.WebView;
import androidx.annotation.OptIn;
import androidx.media3.common.util.UnstableApi;
import net.lingala.zip4j.ZipFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -111,6 +113,45 @@ public class SocketThread extends Thread {
progJson = null;
main.runOnUiThread(() -> main.initProg(json));
}
} else if("playZipTask".equals(_type)) {
var zip = new ZipFile(Util.programDir+"/"+obj.stnn("proName"));
if(zip.isEncrypted()) zip.setPassword(new char[]{'8','8','8'});
long size = 0;
ByteArrayOutputStream jsonOut = null;
try {
var headers = zip.getFileHeaders();
for(var header : headers) {
size += header.getUncompressedSize();
if("program".equals(header.getFileName())) IOs.writeClose(jsonOut = new ByteArrayOutputStream(), zip.getInputStream(header));
}
if(jsonOut==null) {
Util.println("No 'program' File");
new JSMap("success", false, "msg", "No 'program' File").write(out);
main.runOnUiThread(() -> Util.makeText(main, "No program File").show());
} else if(size==0) {
Util.println("Zip Size is 0");
new JSMap("success", false, "msg", "Zip Size is 0").write(out);
main.runOnUiThread(() -> Util.makeText(main, "zip size is 0").show());
} else {
Util.deleteFiles(size, null);
for(var header : headers) if(! "program".equals(header.getFileName())) {
Util.println(" name: " + header.getFileName());
var fOut = new FileOutputStream(Util.programDir + "/" + header.getFileName());
IOs.writeCloseIn(fOut, zip.getInputStream(header));
fOut.flush();
fOut.getFD().sync();
fOut.close();
}
var json = jsonOut.toByteArray();
main.runOnUiThread(()->main.initProg(json));
Util.println(" Succeed");
new JSMap("success", true).write(out);
}
} catch (Exception e) {
Util.printStackTrace(e);
new JSMap("success", false).write(out);
main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show());
}
} else if("DelPrograms".equals(_type)) {
var latch = new CountDownLatch(1);
var ok = new AtomicBoolean(false);
@ -217,12 +258,13 @@ public class SocketThread extends Thread {
out.write(Util.buf.toString().getBytes());
} else if("ListProgFiles".equals(_type)) {
var files = new File(Util.programDir).listFiles();
if(files == null) return;
Arrays.sort(files, (f1, f2) -> (int) (f2.lastModified() - f1.lastModified()));
var writer = new OutputStreamWriter(out);
for(var file : files) writer.append(fmt.format(new Date(file.lastModified()))).append(' ').append(file.getName()).append(' ').append(String.valueOf(file.length())).append('\n');
writer.append('\n');
writer.flush();
if(files!=null) {
Arrays.sort(files, (f1, f2) -> (int) (f2.lastModified() - f1.lastModified()));
var writer = new OutputStreamWriter(out);
for(var file : files) writer.append(fmt.format(new Date(file.lastModified()))).append(' ').append(file.getName()).append(' ').append(String.valueOf(file.length())).append('\n');
writer.append('\n');
writer.flush();
}
} else if("GetFile".equals(_type)) {
var name = obj.str("name");
if(name==null) new JSMap("msg", "name is null").write(out);

View File

@ -126,8 +126,13 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
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 {
if(num>=0 && num<=15) {
if(directs[num].length() < 3) item.nums.add(imgMap.get(directs[num]));
else {
item.nums.add(imgMap.get(directs[num].substring(0, 1)));
item.nums.add(imgMap.get(directs[num].substring(1)));
}
} else {
var img = imgMap.get("-");
item.nums.add(img);
item.nums.add(img);