player
This commit is contained in:
parent
67c9e8abd6
commit
9b951e17eb
|
@ -8,7 +8,7 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.xixun.xixunplayer"
|
applicationId "com.xixun.xixunplayer"
|
||||||
minSdk 26
|
minSdk 24
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
@ -40,7 +40,23 @@ dependencies {
|
||||||
// implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
|
// implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
|
||||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
|
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
|
||||||
implementation files('libs/gnph.jar')
|
implementation files('libs/gnph.jar')
|
||||||
|
implementation files('libs/zip4j-2.10.0.jar')
|
||||||
implementation files('libs/xixun_card_settings_1.2.4.jar')
|
implementation files('libs/xixun_card_settings_1.2.4.jar')
|
||||||
implementation files('libs/ijkplayer-java-0.8.8.aar')
|
implementation files('libs/ijkplayer-java-0.8.8.aar')
|
||||||
|
implementation files('libs/ijkplayer-armv7a-0.8.8.aar')
|
||||||
implementation files('libs/ijkplayer-arm64-0.8.8.aar')
|
implementation files('libs/ijkplayer-arm64-0.8.8.aar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getAppName() {
|
||||||
|
def stringsFile = android.sourceSets.main.res.sourceFiles.find { it.name.equals 'strings.xml' }
|
||||||
|
String s = new XmlParser().parse(stringsFile).string.find { it.@name.equals 'app_name' }.text();
|
||||||
|
return s.replaceAll("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改 Apk 名
|
||||||
|
android.applicationVariants.all { variant ->
|
||||||
|
variant.outputs.all {
|
||||||
|
def fileName = "${getAppName()}-${versionName}.apk"
|
||||||
|
outputFileName = fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -11,20 +11,20 @@ import android.view.View;
|
||||||
public class BackView extends View {
|
public class BackView extends View {
|
||||||
|
|
||||||
public Bitmap img, cosImg;
|
public Bitmap img, cosImg;
|
||||||
public int width, height;
|
Rect rect = new Rect();
|
||||||
|
|
||||||
public BackView(Context context, int width, int height) {
|
public BackView(Context context, int width, int height) {
|
||||||
super(context);
|
super(context);
|
||||||
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back);
|
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back);
|
||||||
cosImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/XixunPlayer/background");
|
cosImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/XixunPlayer/background");
|
||||||
this.width = width;
|
rect.right = width;
|
||||||
this.height = height;
|
rect.bottom = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
if(cosImg!=null) canvas.drawBitmap(cosImg, new Rect(0, 0, cosImg.getWidth(), cosImg.getHeight()), new Rect(0, 0, width, height), null);
|
if(cosImg!=null) canvas.drawBitmap(cosImg, null, rect, null);
|
||||||
else if(img!=null) for(int y=0; y<height; y+=img.getHeight()) for(int x=0; x<width; x+=img.getWidth()) canvas.drawBitmap(img, x, y, null);
|
else if(img!=null) for(int y=0; y<rect.bottom; y+=img.getHeight()) for(int x=0; x<rect.right; x+=img.getWidth()) canvas.drawBitmap(img, x, y, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import android.content.Intent;
|
||||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
System.out.println("BootCompletedReceiver onReceive ---- "+intent.getAction());
|
Util.println("BootCompletedReceiver onReceive ---- "+intent.getAction());
|
||||||
if(MainActivity.ins!=null) return;
|
if(MainActivity.ins!=null) return;
|
||||||
intent = new Intent(context, MainActivity.class);
|
intent = new Intent(context, MainActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.xixun.xixunplayer;
|
|
||||||
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
|
|
||||||
public interface DrawOther {
|
|
||||||
void drawOther(Canvas canvas);
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package com.xixun.xixunplayer;
|
||||||
import static android.graphics.Paint.Join.ROUND;
|
import static android.graphics.Paint.Join.ROUND;
|
||||||
import static android.graphics.Paint.Style.FILL_AND_STROKE;
|
import static android.graphics.Paint.Style.FILL_AND_STROKE;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -15,39 +16,34 @@ import android.graphics.RectF;
|
||||||
import android.view.Choreographer;
|
import android.view.Choreographer;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import androidx.annotation.NonNull;
|
||||||
import java.time.ZoneId;
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
|
|
||||||
|
@SuppressLint("ViewConstructor")
|
||||||
public class EleAnaClock extends View implements Choreographer.FrameCallback {
|
public class EleAnaClock extends View implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
ZoneId timeZone;
|
TimeZone timeZone;
|
||||||
Bitmap img;
|
Bitmap img;
|
||||||
|
Rect imgRect;
|
||||||
int pinHourColor, pinMinColor, pinSecColor;
|
int pinHourColor, pinMinColor, pinSecColor;
|
||||||
Path hPath, mPath, sPath;
|
Path hPath, mPath, sPath;
|
||||||
float hAngle, mAngle, sAngle;
|
float hAngle, mAngle, sAngle;
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
boolean showSecHand;
|
boolean showSecHand;
|
||||||
|
|
||||||
public EleAnaClock(float w, float h, String path, JSMap layer, Context context) {
|
public EleAnaClock(float w, float h, String path, JSMap source, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
var aTimeZone = layer.str("timeZone");
|
var timeZoneStr = source.str("timeZone");
|
||||||
if(aTimeZone!=null) timeZone = ZoneId.of(aTimeZone);
|
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
|
||||||
img = BitmapFactory.decodeFile(path);
|
if(timeZoneStr!=null) TimeZone.getTimeZone(timeZoneStr);
|
||||||
pinHourColor = Color.parseColor(layer.stnn("pinHourColor"));
|
|
||||||
pinMinColor = Color.parseColor(layer.stnn("pinMinColor"));
|
var sideLen = Math.min(w, h);
|
||||||
pinSecColor = Color.parseColor(layer.stnn("pinSecColor"));
|
var halfSide = sideLen / 2;
|
||||||
var hhLen = layer.intg("pinHourLen");
|
var lineWidth = sideLen / 128;
|
||||||
var mhLen = layer.intg("pinMinLen");
|
|
||||||
var shLen = layer.intg("pinSecLen");
|
|
||||||
var hhWidth = layer.intg("pinHourWidth");
|
|
||||||
var mhWidth = layer.intg("pinMinWidth");
|
|
||||||
var shWidth = layer.intg("pinSecWidth");
|
|
||||||
showSecHand = layer.bool("showSecond");
|
|
||||||
var sideLen = w;
|
|
||||||
if(h < sideLen) sideLen = h;
|
|
||||||
var lineWidth = sideLen/128;
|
|
||||||
if(lineWidth < 1) lineWidth = 1;
|
if(lineWidth < 1) lineWidth = 1;
|
||||||
|
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
@ -55,6 +51,51 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback {
|
||||||
paint.setStrokeWidth(lineWidth);
|
paint.setStrokeWidth(lineWidth);
|
||||||
paint.setStrokeJoin(ROUND);
|
paint.setStrokeJoin(ROUND);
|
||||||
|
|
||||||
|
img = BitmapFactory.decodeFile(path);
|
||||||
|
if(img==null) {
|
||||||
|
img = Bitmap.createBitmap((int)w, (int)h, Bitmap.Config.ARGB_8888);
|
||||||
|
var canvas = new Canvas(img);
|
||||||
|
canvas.translate(w / 2, h / 2);
|
||||||
|
if(source.bool("showBg")) {
|
||||||
|
var bgColor = Color.parseColor(source.stnn("bgColor"));
|
||||||
|
var opacity = source.dbl("opacity", -1);
|
||||||
|
if(opacity!=-1) bgColor = bgColor & 0x00ffffff | ((int)opacity*255)<<24;
|
||||||
|
paint.setColor(bgColor);
|
||||||
|
canvas.drawOval(-halfSide, -halfSide, halfSide, halfSide, paint);
|
||||||
|
}
|
||||||
|
var minMarkSize = 2.5f;
|
||||||
|
var hourMarkSize = 5f;
|
||||||
|
var scaleHourColor = Color.parseColor(source.stnn("scaleHourColor"));
|
||||||
|
var scaleMinColor = Color.parseColor(source.stnn("scaleMinColor"));
|
||||||
|
var r = (sideLen - Math.max(minMarkSize, hourMarkSize)) / 2;
|
||||||
|
for(int i=0; i<60; i++) {
|
||||||
|
var k = i * Math.PI / 30;
|
||||||
|
var x = (float) (Math.sin(k) * r);
|
||||||
|
var y = (float) (-Math.cos(k) * r);
|
||||||
|
if(i % 5 > 0) {
|
||||||
|
var rr = minMarkSize / 2f;
|
||||||
|
paint.setColor(scaleMinColor);
|
||||||
|
canvas.drawOval(x-rr, y-rr, x+rr, y+rr, paint);
|
||||||
|
} else {
|
||||||
|
var rr = hourMarkSize / 2f;
|
||||||
|
paint.setColor(scaleHourColor);
|
||||||
|
canvas.drawOval(x-rr, y-rr, x+rr, y+rr, paint);
|
||||||
|
//if(m_attr.hourMark==2) drawMarkNumber(painter, {x, y}, m_attr.hourMarkColor, m_attr.hourMarkSize, i/5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imgRect = new Rect(0, 0, img.getWidth(), img.getHeight());
|
||||||
|
pinHourColor = Color.parseColor(source.stnn("pinHourColor"));
|
||||||
|
pinMinColor = Color.parseColor(source.stnn("pinMinColor"));
|
||||||
|
pinSecColor = Color.parseColor(source.stnn("pinSecColor"));
|
||||||
|
var hhLen = (float) source.dbl("pinHourLen", 50);
|
||||||
|
var mhLen = (float) source.dbl("pinMinLen", 75);
|
||||||
|
var shLen = (float) source.dbl("pinSecLen", 100);
|
||||||
|
var hhWidth = (float) source.dbl("pinHourWidth", 15);
|
||||||
|
var mhWidth = (float) source.dbl("pinMinWidth", 10);
|
||||||
|
var shWidth = (float) source.dbl("pinSecWidth", 5);
|
||||||
|
showSecHand = source.bool("showSecond");
|
||||||
|
|
||||||
var rx = hhWidth*sideLen/400;
|
var rx = hhWidth*sideLen/400;
|
||||||
hPath = new Path();
|
hPath = new Path();
|
||||||
hPath.moveTo(rx, 0);
|
hPath.moveTo(rx, 0);
|
||||||
|
@ -76,20 +117,22 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback {
|
||||||
sPath.close();
|
sPath.close();
|
||||||
}
|
}
|
||||||
void cal() {
|
void cal() {
|
||||||
var time = timeZone==null ? LocalTime.now() : LocalTime.now(timeZone);
|
//var time = timeZone==null ? LocalTime.now() : LocalTime.now(timeZone);
|
||||||
sAngle = time.getSecond() * 6;
|
var calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
|
||||||
mAngle = time.getMinute() * 6 + sAngle/60;
|
sAngle = calendar.get(Calendar.SECOND) * 6;
|
||||||
hAngle = time.getHour() * 30 + mAngle/12;
|
mAngle = calendar.get(Calendar.MINUTE) * 6 + sAngle/60;
|
||||||
|
hAngle = calendar.get(Calendar.HOUR_OF_DAY) * 30 + mAngle/12;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(@NonNull Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
if(lastSec==0) {
|
if(lastSec==0) {
|
||||||
cal();
|
cal();
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
lastSec = 1;
|
||||||
}
|
}
|
||||||
if(img != null) canvas.drawBitmap(img, new Rect(0,0,img.getWidth(), img.getHeight()), new RectF(0,0, getWidth(), getHeight()), paint);
|
if(img != null) canvas.drawBitmap(img, imgRect, new RectF(0,0, getWidth(), getHeight()), paint);
|
||||||
canvas.translate(getWidth()/2, getHeight()/2);
|
canvas.translate(getWidth()/2f, getHeight()/2f);
|
||||||
|
|
||||||
paint.setColor(pinHourColor);
|
paint.setColor(pinHourColor);
|
||||||
canvas.rotate(hAngle);
|
canvas.rotate(hAngle);
|
||||||
|
@ -106,7 +149,7 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
long lastSec = 0;
|
long lastSec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
|
|
|
@ -63,7 +63,10 @@ public class EleBorder extends View implements Choreographer.FrameCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(freshCnt==0 && eff!=0) choreographer.postFrameCallback(this);
|
if(freshCnt==0 && eff!=0) {
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
freshCnt = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.xixun.xixunplayer;
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -9,47 +10,58 @@ import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import androidx.annotation.NonNull;
|
||||||
import java.time.ZoneId;
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import gnph.android.LinearBox;
|
import gnph.android.LinearBox;
|
||||||
import gnph.util.Dates;
|
import gnph.util.Dates;
|
||||||
import gnph.util.JSList;
|
import gnph.util.JSList;
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
import gnph.util.Sys;
|
|
||||||
|
|
||||||
|
@SuppressLint("ViewConstructor")
|
||||||
public class EleDigiClock extends LinearBox implements Choreographer.FrameCallback {
|
public class EleDigiClock extends LinearBox implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
static final String weeks[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
|
static final String weeks[] = {"SUN", "MON","TUE","WED","THU","FRI","SAT"};
|
||||||
HashMap<String, Bitmap> imgs = new HashMap<>();
|
HashMap<String, Bitmap> imgs = new HashMap<>();
|
||||||
ImageView yearComps[] = {new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] yearComps = {new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext())};
|
||||||
ImageView monthComps[] = {new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] monthComps = {new ImageView(getContext()), new ImageView(getContext())};
|
||||||
ImageView dayComps[] = {new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] dayComps = {new ImageView(getContext()), new ImageView(getContext())};
|
||||||
ImageView weekComp = new ImageView(getContext()), ampmComp = new ImageView(getContext());
|
ImageView weekComp = new ImageView(getContext()), ampmComp = new ImageView(getContext());
|
||||||
ImageView hourComps[] = {new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] hourComps = {new ImageView(getContext()), new ImageView(getContext())};
|
||||||
ImageView minComps[] = {new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] minComps = {new ImageView(getContext()), new ImageView(getContext())};
|
||||||
ImageView secComps[] = {new ImageView(getContext()), new ImageView(getContext())};
|
ImageView[] secComps = {new ImageView(getContext()), new ImageView(getContext())};
|
||||||
|
|
||||||
ZoneId timeZone;
|
TimeZone timeZone;
|
||||||
String timeptn;
|
SimpleDateFormat timeptn, dataFmt = new SimpleDateFormat("yyyyMMdd");
|
||||||
boolean multiline, weekly, isSingleMonth;
|
boolean multiline, weekly, isSingleMonth;
|
||||||
|
|
||||||
public EleDigiClock(String prefix, JSMap json, Context context) {
|
public EleDigiClock(Context context, JSMap json) {
|
||||||
super(context);
|
super(context);
|
||||||
setGravity(Gravity.CENTER);
|
setGravity(Gravity.CENTER);
|
||||||
var aZone = json.str("timeZone");
|
var timeZoneStr = json.str("timeZone");
|
||||||
if(aZone!=null) timeZone = ZoneId.of(aZone);
|
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
|
||||||
|
if(timeZoneStr!=null) TimeZone.getTimeZone(timeZoneStr);
|
||||||
var spaceWidth = json.dbl("spaceWidth");
|
var spaceWidth = json.dbl("spaceWidth");
|
||||||
JSList<JSMap> pics = json.jslist("arrayPics");
|
JSList<JSMap> pics = json.jslist("arrayPics");
|
||||||
for(var pic : pics) imgs.put(pic.stnn("name"), BitmapFactory.decodeFile(prefix+pic.stnn("id")));
|
if(pics!=null && ! pics.isEmpty() && pics.get(0).containsKey("startX")) {
|
||||||
|
var big = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id"));
|
||||||
|
for(var pic : pics) {
|
||||||
|
var startX = pic.intg("startX");
|
||||||
|
var startY = pic.intg("startY");
|
||||||
|
imgs.put(pic.str("name"), Bitmap.createBitmap(big, startX, startY, pic.intg("endX")-startX, pic.intg("endY")-startY));
|
||||||
|
}
|
||||||
|
} else for(var pic : pics) imgs.put(pic.str("name"), BitmapFactory.decodeFile(Util.programDir+"/"+pic.stnn("id")));
|
||||||
int dateStyle = json.intg("dateStyle");
|
int dateStyle = json.intg("dateStyle");
|
||||||
isSingleMonth = dateStyle==1||dateStyle==2||dateStyle==4||dateStyle==6||dateStyle==8||dateStyle==10||dateStyle==12;
|
isSingleMonth = dateStyle==1||dateStyle==2||dateStyle==4||dateStyle==6||dateStyle==8||dateStyle==10||dateStyle==12;
|
||||||
var timeSep = imgs.get("maohao");
|
var timeSep = imgs.get("maohao");
|
||||||
weekly = json.bool("weekly");
|
weekly = json.bool("weekly");
|
||||||
var hour12 = json.bool("hour12");
|
var hour12 = json.bool("hour12");
|
||||||
var AmPm = hour12 ? json.bool("AmPm") : false;
|
var AmPm = hour12 && json.bool("AmPm");
|
||||||
timeptn = hour12 ? "hhmmssa" : "HHmmss";
|
timeptn = new SimpleDateFormat(hour12 ? "hhmmssa" : "HHmmss");
|
||||||
var hour = json.bool("hour");
|
var hour = json.bool("hour");
|
||||||
var min = json.bool("min");
|
var min = json.bool("min");
|
||||||
var sec = json.bool("sec");
|
var sec = json.bool("sec");
|
||||||
|
@ -228,20 +240,19 @@ public class EleDigiClock extends LinearBox implements Choreographer.FrameCallba
|
||||||
}
|
}
|
||||||
|
|
||||||
void cal() {
|
void cal() {
|
||||||
var dt = timeZone==null ? LocalDateTime.now() : LocalDateTime.now(timeZone);
|
//var dt = timeZone==null ? LocalDateTime.now() : LocalDateTime.now(timeZone);
|
||||||
var time = dt.toLocalTime();
|
var calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
|
||||||
var hms = Dates.fmt(time, timeptn);
|
var hms = timeptn.format(calendar.getTime());
|
||||||
ampmComp.setImageBitmap(imgs.get(time.getHour()<12?"AM":"PM"));
|
ampmComp.setImageBitmap(imgs.get(calendar.get(Calendar.HOUR_OF_DAY) < 12?"AM":"PM"));
|
||||||
hourComps[0].setImageBitmap(imgs.get(hms.substring(0,1)));
|
hourComps[0].setImageBitmap(imgs.get(hms.substring(0,1)));
|
||||||
hourComps[1].setImageBitmap(imgs.get(hms.substring(1,2)));
|
hourComps[1].setImageBitmap(imgs.get(hms.substring(1,2)));
|
||||||
minComps[0].setImageBitmap(imgs.get(hms.substring(2,3)));
|
minComps[0].setImageBitmap(imgs.get(hms.substring(2,3)));
|
||||||
minComps[1].setImageBitmap(imgs.get(hms.substring(3,4)));
|
minComps[1].setImageBitmap(imgs.get(hms.substring(3,4)));
|
||||||
secComps[0].setImageBitmap(imgs.get(hms.substring(4,5)));
|
secComps[0].setImageBitmap(imgs.get(hms.substring(4,5)));
|
||||||
secComps[1].setImageBitmap(imgs.get(hms.substring(5,6)));
|
secComps[1].setImageBitmap(imgs.get(hms.substring(5,6)));
|
||||||
if(yearComps[0].getDrawable()==null || (time.getHour()==0 && time.getSecond()==0)) {
|
if(yearComps[0].getDrawable()==null || (calendar.get(Calendar.HOUR_OF_DAY)==0 && calendar.get(Calendar.SECOND)==0)) {
|
||||||
var date = dt.toLocalDate();
|
if(weekly) weekComp.setImageBitmap(imgs.get(weeks[calendar.get(Calendar.DAY_OF_WEEK) - 1]));
|
||||||
if(weekly) weekComp.setImageBitmap(imgs.get(weeks[date.getDayOfWeek().ordinal()]));
|
var ymd = dataFmt.format(calendar.getTime());
|
||||||
var ymd = Dates.fmt(date, "yyyyMMdd");
|
|
||||||
yearComps[0].setImageBitmap(imgs.get(ymd.substring(0,1)));
|
yearComps[0].setImageBitmap(imgs.get(ymd.substring(0,1)));
|
||||||
yearComps[1].setImageBitmap(imgs.get(ymd.substring(1,2)));
|
yearComps[1].setImageBitmap(imgs.get(ymd.substring(1,2)));
|
||||||
yearComps[2].setImageBitmap(imgs.get(ymd.substring(2,3)));
|
yearComps[2].setImageBitmap(imgs.get(ymd.substring(2,3)));
|
||||||
|
@ -254,18 +265,19 @@ public class EleDigiClock extends LinearBox implements Choreographer.FrameCallba
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onVisibilityChanged(View changedView, int visibility) {
|
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
|
||||||
super.onVisibilityChanged(changedView, visibility);
|
super.onVisibilityChanged(changedView, visibility);
|
||||||
if(visibility==View.VISIBLE) {
|
if(visibility==View.VISIBLE) {
|
||||||
if(lastSec==0) {
|
if(lastSec==0) {
|
||||||
cal();
|
cal();
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
lastSec = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
long lastSec = 0;
|
long lastSec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
|
@ -277,7 +289,6 @@ public class EleDigiClock extends LinearBox implements Choreographer.FrameCallba
|
||||||
if(sec != lastSec) {
|
if(sec != lastSec) {
|
||||||
lastSec = sec;
|
lastSec = sec;
|
||||||
cal();
|
cal();
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,30 +36,39 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
|
||||||
Bitmap title;
|
Bitmap title;
|
||||||
ArrayList<Item> items = new ArrayList<>();
|
ArrayList<Item> items = new ArrayList<>();
|
||||||
MainActivity act;
|
MainActivity act;
|
||||||
int spaceWidth, digitHeight;
|
int alignType, spaceWidth, digitHeight;
|
||||||
int interval, cur, end, step;
|
int interval, cur, end, step;
|
||||||
boolean isScroll, isFirst = true;
|
boolean isScroll, isFirst = true;
|
||||||
|
|
||||||
public EleEnviron(String prefix, JSMap json, Context context) {
|
public EleEnviron(Context context, JSMap json) {
|
||||||
super(context);
|
super(context);
|
||||||
act = (MainActivity) context;
|
act = (MainActivity) context;
|
||||||
|
alignType = json.intg("alignType");
|
||||||
spaceWidth = json.intg("spaceWidth");
|
spaceWidth = json.intg("spaceWidth");
|
||||||
isScroll = json.bool("bSingleScroll");
|
isScroll = json.bool("bSingleScroll");
|
||||||
try {
|
try {
|
||||||
setBackgroundColor(Color.parseColor(json.stnn("backColor")));
|
setBackgroundColor(Color.parseColor(json.stnn("backColor")));
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
var values = json.jsmap("values");
|
var values = json.jsmap("values");
|
||||||
JSList<JSMap> arrayPics = json.jslist("arrayPics");
|
|
||||||
if(values!=null) {
|
if(values!=null) {
|
||||||
|
title = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("title"));
|
||||||
var entrys = values.entrySet();
|
var entrys = values.entrySet();
|
||||||
for(var entry : entrys) imgMap.put(entry.getKey(), BitmapFactory.decodeFile(prefix+entry.getValue()));
|
for(var entry : entrys) imgMap.put(entry.getKey(), BitmapFactory.decodeFile(Util.programDir+"/"+entry.getValue()));
|
||||||
JSList<JSMap> jitems = json.jslist("items");
|
JSList<JSMap> jitems = json.jslist("items");
|
||||||
for(var jitem : jitems) {
|
for(var jitem : jitems) {
|
||||||
var unit = jitem.str("unit");
|
var unit = jitem.str("unit");
|
||||||
items.add(new Item(jitem.str("name"), BitmapFactory.decodeFile(prefix+jitem.stnn("label")), unit==null ? null : BitmapFactory.decodeFile(prefix+unit)));
|
items.add(new Item(jitem.str("name"), BitmapFactory.decodeFile(Util.programDir+"/"+jitem.stnn("label")), unit==null ? null : BitmapFactory.decodeFile(Util.programDir+"/"+unit)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(var img : arrayPics) imgMap.put(img.str("name"), BitmapFactory.decodeFile(prefix+img.stnn("id")));
|
JSList<JSMap> pics = json.jslist("arrayPics");
|
||||||
|
if(pics!=null && ! pics.isEmpty() && pics.get(0).containsKey("startX")) {
|
||||||
|
var big = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id"));
|
||||||
|
for(var pic : pics) {
|
||||||
|
var startX = pic.intg("startX");
|
||||||
|
var startY = pic.intg("startY");
|
||||||
|
imgMap.put(pic.str("name"), Bitmap.createBitmap(big, startX, startY, pic.intg("endX")-startX, pic.intg("endY")-startY));
|
||||||
|
}
|
||||||
|
} else for(var img : pics) imgMap.put(img.str("name"), BitmapFactory.decodeFile(Util.programDir+"/"+img.stnn("id")));
|
||||||
imgMap.put("-", imgMap.remove("minus_sign"));
|
imgMap.put("-", imgMap.remove("minus_sign"));
|
||||||
title = imgMap.get("labeltitle");
|
title = imgMap.get("labeltitle");
|
||||||
if(json.bool("bTemperature")) items.add(new Item("temperature", imgMap.remove("labeltemperature"), imgMap.remove("unit_celsius")));
|
if(json.bool("bTemperature")) items.add(new Item("temperature", imgMap.remove("labeltemperature"), imgMap.remove("unit_celsius")));
|
||||||
|
@ -71,6 +80,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
|
||||||
if(json.bool("bPM10")) items.add(new Item("pm10", imgMap.remove("labelpm10"), 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();
|
digitHeight = imgMap.get("0").getHeight();
|
||||||
|
if(spaceWidth==0) spaceWidth = imgMap.get("0").getWidth();
|
||||||
var scrollSpeed = json.dbl("scrollSpeed");
|
var scrollSpeed = json.dbl("scrollSpeed");
|
||||||
if(scrollSpeed==0) {
|
if(scrollSpeed==0) {
|
||||||
var scrollDur = json.dbl("iScrollSpeed");
|
var scrollDur = json.dbl("iScrollSpeed");
|
||||||
|
@ -109,7 +119,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,16 +157,30 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
|
||||||
}
|
}
|
||||||
if(ccc==0) end = -(x-cur-step);
|
if(ccc==0) end = -(x-cur-step);
|
||||||
}
|
}
|
||||||
if(freshCnt==0 && interval!=0) choreographer.postFrameCallback(this);
|
if(freshCnt==0 && interval!=0) {
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
freshCnt = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var itemH = (double) getHeight() / (title!=null ? items.size()+1 : items.size());
|
var itemH = (double) getHeight() / (title!=null ? items.size()+1 : items.size());
|
||||||
int i = 0;
|
int i = 0, x = 0;
|
||||||
if(title!=null) canvas.drawBitmap(title, 0, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null);
|
if(title!=null) {
|
||||||
|
if(alignType==1) x = (getWidth() - title.getWidth()) / 2;
|
||||||
|
else if(alignType==2) x = getWidth() - title.getWidth();
|
||||||
|
canvas.drawBitmap(title, x, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null);
|
||||||
|
}
|
||||||
for(var item : items) {
|
for(var item : items) {
|
||||||
var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2);
|
var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2);
|
||||||
var x = 0;
|
x = 0;
|
||||||
|
if(alignType!=0) {
|
||||||
|
if(item.lable!=null) x += item.lable.getWidth();
|
||||||
|
for(var num : item.nums) if(num!=null) x += num.getWidth();
|
||||||
|
if(item.unit!=null) x += item.unit.getWidth();
|
||||||
|
x = getWidth() - x;
|
||||||
|
if(alignType==1) x /= 2;
|
||||||
|
}
|
||||||
if(item.lable!=null) {
|
if(item.lable!=null) {
|
||||||
canvas.drawBitmap(item.lable, 0, y, null);
|
canvas.drawBitmap(item.lable, x, y, null);
|
||||||
x += item.lable.getWidth();
|
x += item.lable.getWidth();
|
||||||
}
|
}
|
||||||
for(var num : item.nums) if(num!=null) {
|
for(var num : item.nums) if(num!=null) {
|
||||||
|
|
|
@ -1,128 +0,0 @@
|
||||||
package com.xixun.xixunplayer;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.view.Choreographer;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import gnph.util.JSList;
|
|
||||||
import gnph.util.JSMap;
|
|
||||||
|
|
||||||
public class EleFlip extends View implements DrawOther, Choreographer.FrameCallback {
|
|
||||||
|
|
||||||
static final char effTypes[] = {'l', 't', 'r', 'b'};
|
|
||||||
ArrayList<EleOtherPart> others;
|
|
||||||
Random rand = new Random();
|
|
||||||
ArrayList<Bitmap> imgs = new ArrayList<>();
|
|
||||||
int picDur, EffDur, AniInterval, step, imgc, imgx, imgy;
|
|
||||||
char effType;
|
|
||||||
boolean needRand = false;
|
|
||||||
|
|
||||||
public EleFlip(String dirPre, JSList<JSMap> maps, Context context) {
|
|
||||||
super(context);
|
|
||||||
var map = maps.get(0);
|
|
||||||
picDur = map.intg("picDuration")*60;
|
|
||||||
if(picDur==0) return;
|
|
||||||
EffDur = map.intg("effectSpeed")*60;
|
|
||||||
for(var amap : maps) imgs.add(BitmapFactory.decodeFile(dirPre+amap.stnn("id")));
|
|
||||||
var effStr = map.str("effect");
|
|
||||||
if(effStr == null || effStr.equals("no")) EffDur = 0;
|
|
||||||
else if(effStr.endsWith("left")) effType = 'l';
|
|
||||||
else if(effStr.endsWith("top")) effType = 't';
|
|
||||||
else if(effStr.endsWith("right")) effType = 'r';
|
|
||||||
else if(effStr.endsWith("bottom")) effType = 'b';
|
|
||||||
else if(effStr.equals("random")) needRand = true;
|
|
||||||
else EffDur = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startMove() {
|
|
||||||
if(EffDur==0) return;
|
|
||||||
if(needRand) effType = effTypes[rand.nextInt(4)];
|
|
||||||
double effDurD = EffDur;
|
|
||||||
if(effType=='l') {
|
|
||||||
imgx = getWidth();
|
|
||||||
imgy = 0;
|
|
||||||
effDurD /= getWidth();
|
|
||||||
} else if(effType=='r') {
|
|
||||||
imgx = -getWidth();
|
|
||||||
imgy = 0;
|
|
||||||
effDurD /= getWidth();
|
|
||||||
} else if(effType=='t') {
|
|
||||||
imgx = 0;
|
|
||||||
imgy = getHeight();
|
|
||||||
effDurD /= getHeight();
|
|
||||||
} else if(effType=='b') {
|
|
||||||
imgx = 0;
|
|
||||||
imgy = -getHeight();
|
|
||||||
effDurD /= getHeight();
|
|
||||||
} else return;
|
|
||||||
AniInterval = (int) Math.round(effDurD);
|
|
||||||
if(AniInterval < 1) AniInterval = 1;
|
|
||||||
step = (int) Math.round(AniInterval / effDurD);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
if(freshCnt==0 && (EffDur!=0 || imgs.size()>1)) {
|
|
||||||
startMove();
|
|
||||||
choreographer.postFrameCallback(this);
|
|
||||||
}
|
|
||||||
drawOther(canvas);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void drawOther(Canvas canvas) {
|
|
||||||
canvas.drawBitmap(imgs.get(imgc), imgx, imgy, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
|
||||||
int freshCnt, curDur;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFrame(long frameTimeNanos) {
|
|
||||||
if(! isShown()) {
|
|
||||||
freshCnt = curDur = imgc = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(curDur < picDur) {
|
|
||||||
curDur++;
|
|
||||||
if(AniInterval > 0) {
|
|
||||||
if(freshCnt < AniInterval) freshCnt++;
|
|
||||||
else {
|
|
||||||
freshCnt = 1;
|
|
||||||
if(effType=='l') {
|
|
||||||
imgx -= step;
|
|
||||||
if(imgx < 0) imgx = 0;
|
|
||||||
} else if(effType=='t') {
|
|
||||||
imgy -= step;
|
|
||||||
if(imgy < 0) imgy = 0;
|
|
||||||
} else if(effType=='r') {
|
|
||||||
imgx += step;
|
|
||||||
if(imgx > 0) imgx = 0;
|
|
||||||
} else if(effType=='b') {
|
|
||||||
imgy += step;
|
|
||||||
if(imgy > 0) imgy = 0;
|
|
||||||
}
|
|
||||||
if(imgx==0 && imgy==0) AniInterval = 0;
|
|
||||||
invalidate();
|
|
||||||
if(others!=null) for(var other : others) other.invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
curDur = 0;
|
|
||||||
freshCnt = 1;
|
|
||||||
if(imgc >= imgs.size()-1) imgc = 0;
|
|
||||||
else imgc++;
|
|
||||||
startMove();
|
|
||||||
invalidate();
|
|
||||||
if(others!=null) for(var other : others) other.invalidate();
|
|
||||||
}
|
|
||||||
choreographer.postFrameCallback(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.xixun.xixunplayer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
public class EleOtherPart extends View {
|
|
||||||
|
|
||||||
DrawOther master;
|
|
||||||
|
|
||||||
public EleOtherPart(Context context, DrawOther master) {
|
|
||||||
super(context);
|
|
||||||
this.master = master;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
try {
|
|
||||||
master.drawOther(canvas);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
setVisibility(GONE);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +1,42 @@
|
||||||
package com.xixun.xixunplayer;
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.view.Choreographer;
|
import android.view.Choreographer;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
|
|
||||||
public class EleScroll extends View implements DrawOther, Choreographer.FrameCallback {
|
@SuppressLint("ViewConstructor")
|
||||||
|
public class EleScroll extends View implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
ArrayList<EleOtherPart> others;
|
ArrayList<Bitmap> imgs = new ArrayList<>();
|
||||||
int w, h;
|
Rect rect = new Rect();
|
||||||
Bitmap img;
|
int imgsWidth;
|
||||||
int interval, cur, end, step;
|
int interval, cur, end, step;
|
||||||
char effect;
|
char effect;
|
||||||
|
|
||||||
public EleScroll(Context context, String dirPre, JSMap json, int w, int h) {
|
public EleScroll(Context context, JSMap json) {
|
||||||
super(context);
|
super(context);
|
||||||
this.w = w;
|
var img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id"));
|
||||||
this.h = h;
|
imgsWidth = img.getWidth();
|
||||||
img = BitmapFactory.decodeFile(dirPre + json.stnn("id"));
|
if(imgsWidth <= 8192) imgs.add(img);
|
||||||
|
else {
|
||||||
|
var rem = img.getWidth();
|
||||||
|
do {
|
||||||
|
imgs.add(Bitmap.createBitmap(img, img.getWidth()-rem, 0, Math.min(8192, rem), img.getHeight()));
|
||||||
|
rem -= 8192;
|
||||||
|
} while (rem>0);
|
||||||
|
}
|
||||||
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");
|
||||||
|
@ -38,47 +51,67 @@ public class EleScroll extends View implements DrawOther, Choreographer.FrameCal
|
||||||
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 = -(img.getWidth()-step);
|
if(effect=='l') end = -(imgsWidth-step);
|
||||||
else if(effect=='r') end = img.getWidth()-step;
|
else if(effect=='r') end = imgsWidth-step;
|
||||||
else if(effect=='t') end = -(img.getHeight()-step);
|
else if(effect=='t') end = -(imgs.get(0).getHeight()-step);
|
||||||
else if(effect=='b') end = img.getHeight()-step;
|
else if(effect=='b') end = imgs.get(0).getHeight()-step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(@NonNull Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
if(img==null) return;
|
if(imgs.isEmpty()) return;
|
||||||
try {
|
try {
|
||||||
drawOther(canvas);
|
drawOther(canvas);
|
||||||
if(freshCnt==0 && effect!=0 && interval!=0) choreographer.postFrameCallback(this);
|
if(freshCnt==0 && effect!=0 && interval!=0) {
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
freshCnt = 1;
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
setVisibility(GONE);
|
setVisibility(GONE);
|
||||||
img = null;
|
imgs.clear();
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void drawOther(Canvas canvas) {
|
public void drawOther(Canvas canvas) {
|
||||||
if(img==null) return;
|
if(! canvas.getClipBounds(rect)) {
|
||||||
|
rect.left = rect.top = 0;
|
||||||
|
rect.right = getWidth();
|
||||||
|
rect.bottom = getHeight();
|
||||||
|
}
|
||||||
if(effect=='l') {
|
if(effect=='l') {
|
||||||
var x = cur;
|
int ii = 0, x = cur;
|
||||||
do {
|
do {
|
||||||
canvas.drawBitmap(img, x, 0, null);
|
if(x > rect.left-imgs.get(ii).getWidth() && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null);
|
||||||
x += img.getWidth();
|
x += imgs.get(ii).getWidth();
|
||||||
} while(x < w);
|
if(++ii >= imgs.size()) ii = 0;
|
||||||
|
} while(x < rect.right);
|
||||||
} else if(effect=='r') {
|
} else if(effect=='r') {
|
||||||
var x = cur + w - img.getWidth();
|
int ii = imgs.size()-1, x = cur + getWidth();
|
||||||
|
boolean con1;
|
||||||
do {
|
do {
|
||||||
canvas.drawBitmap(img, x, 0, null);
|
x -= imgs.get(ii).getWidth();
|
||||||
x -= img.getWidth();
|
con1 = x > rect.left-imgs.get(ii).getWidth();
|
||||||
} while(x > -img.getWidth());
|
if(con1 && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null);
|
||||||
|
if(--ii < 0) ii = imgs.size()-1;
|
||||||
|
} while(con1);
|
||||||
} else if(effect=='t') {
|
} else if(effect=='t') {
|
||||||
canvas.drawBitmap(img, 0, cur, null);
|
int ii = 0, y = cur;
|
||||||
canvas.drawBitmap(img, 0, cur+img.getHeight(), null);
|
do {
|
||||||
|
if(y > rect.top-imgs.get(ii).getHeight() && y < rect.bottom) canvas.drawBitmap(imgs.get(ii), 0, y, null);
|
||||||
|
y += imgs.get(ii).getHeight();
|
||||||
|
if(++ii >= imgs.size()) ii = 0;
|
||||||
|
} while(y < rect.bottom);
|
||||||
} else if(effect=='b') {
|
} else if(effect=='b') {
|
||||||
canvas.drawBitmap(img, 0, cur, null);
|
int ii = imgs.size()-1, y = cur + getHeight();
|
||||||
canvas.drawBitmap(img, 0, cur-img.getHeight(), null);
|
boolean con1;
|
||||||
} else canvas.drawBitmap(img, 0, 0, null);
|
do {
|
||||||
|
y -= imgs.get(ii).getHeight();
|
||||||
|
con1 = y > rect.top-imgs.get(ii).getHeight();
|
||||||
|
if(con1 && y < rect.bottom) canvas.drawBitmap(imgs.get(ii), 0, y, null);
|
||||||
|
if(--ii < 0) ii = imgs.size()-1;
|
||||||
|
} while(con1);
|
||||||
|
} else canvas.drawBitmap(imgs.get(0), 0, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
|
@ -101,7 +134,6 @@ public class EleScroll extends View implements DrawOther, Choreographer.FrameCal
|
||||||
else cur += step;
|
else cur += step;
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
if(others!=null) for(var other : others) other.invalidate();
|
|
||||||
}
|
}
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
package com.xixun.xixunplayer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.view.Choreographer;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import gnph.util.JSMap;
|
|
||||||
|
|
||||||
public class EleScrollAny extends View implements DrawOther, Choreographer.FrameCallback {
|
|
||||||
|
|
||||||
ArrayList<EleOtherPart> others;
|
|
||||||
Bitmap img;
|
|
||||||
float cur, end, step;
|
|
||||||
char effect;
|
|
||||||
|
|
||||||
public EleScrollAny(String dirPre, JSMap json, Context context) {
|
|
||||||
super(context);
|
|
||||||
img = BitmapFactory.decodeFile(dirPre + json.stnn("id"));
|
|
||||||
var effStr = json.str("effect");
|
|
||||||
if(effStr==null || effStr.equals("no")) return;
|
|
||||||
var scrollSpeed = json.dbl("scrollSpeed");
|
|
||||||
if(scrollSpeed==0) {
|
|
||||||
var scrollDur = json.dbl("effectSpeed");
|
|
||||||
if(scrollDur==0) return;
|
|
||||||
scrollSpeed = 1000 / scrollDur;
|
|
||||||
}
|
|
||||||
step = (float) (scrollSpeed / 60);
|
|
||||||
int idx = effStr.lastIndexOf(' ');
|
|
||||||
if(idx > -1) {
|
|
||||||
effect = effStr.charAt(idx+1);
|
|
||||||
if(effect=='l') end = -(img.getWidth()-step);
|
|
||||||
else if(effect=='r') end = img.getWidth()-step;
|
|
||||||
else if(effect=='t') end = -(img.getHeight()-step);
|
|
||||||
else if(effect=='b') end = img.getHeight()-step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
if(img==null) return;
|
|
||||||
try {
|
|
||||||
drawOther(canvas);
|
|
||||||
if(freshCnt==0 && effect!=0 && step!=0) choreographer.postFrameCallback(this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
setVisibility(GONE);
|
|
||||||
img = null;
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void drawOther(Canvas canvas) {
|
|
||||||
if(img==null) return;
|
|
||||||
if(effect=='l') {
|
|
||||||
canvas.drawBitmap(img, cur, 0, null);
|
|
||||||
canvas.drawBitmap(img, cur+img.getWidth(), 0, null);
|
|
||||||
} else if(effect=='r') {
|
|
||||||
var x = cur-img.getWidth()+getWidth();
|
|
||||||
canvas.drawBitmap(img, x, 0, null);
|
|
||||||
canvas.drawBitmap(img, x-img.getWidth(), 0, null);
|
|
||||||
} else if(effect=='t') {
|
|
||||||
canvas.drawBitmap(img, 0, cur, null);
|
|
||||||
canvas.drawBitmap(img, 0, cur+img.getHeight(), null);
|
|
||||||
} else if(effect=='b') {
|
|
||||||
canvas.drawBitmap(img, 0, cur, null);
|
|
||||||
canvas.drawBitmap(img, 0, cur-img.getHeight(), null);
|
|
||||||
} else canvas.drawBitmap(img, 0, 0, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
|
||||||
int freshCnt;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFrame(long frameTimeNanos) {
|
|
||||||
if(! isShown()) {
|
|
||||||
cur = freshCnt = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
freshCnt = 1;
|
|
||||||
if(effect=='t' || effect=='l') {
|
|
||||||
if(cur <= end) cur -= end;
|
|
||||||
else cur -= step;
|
|
||||||
} else if(effect=='b' || effect=='r') {
|
|
||||||
if(cur >= end) cur -= end;
|
|
||||||
else cur += step;
|
|
||||||
}
|
|
||||||
invalidate();
|
|
||||||
if(others!=null) for(var other : others) other.invalidate();
|
|
||||||
choreographer.postFrameCallback(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
package com.xixun.xixunplayer;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.view.Choreographer;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import gnph.util.Dates;
|
|
||||||
import gnph.util.JSMap;
|
|
||||||
import gnph.util.NumFmts;
|
|
||||||
|
|
||||||
public class EleTimer2 extends View implements Choreographer.FrameCallback {
|
|
||||||
|
|
||||||
Paint paint = new Paint();
|
|
||||||
long targetTime;
|
|
||||||
String title, text;
|
|
||||||
int x, y;
|
|
||||||
boolean isDown;
|
|
||||||
boolean isMultiline;
|
|
||||||
boolean hasDay;
|
|
||||||
boolean hasHour;
|
|
||||||
boolean hasMin;
|
|
||||||
boolean hasSec;
|
|
||||||
|
|
||||||
public EleTimer2(JSMap json, Context context) {
|
|
||||||
super(context);
|
|
||||||
isDown = json.bool("isDown");
|
|
||||||
targetTime = Dates.milli(json.stnn("targetTime")) / 1000;
|
|
||||||
hasDay = json.bool("hasDay");
|
|
||||||
hasHour = json.bool("hasHour");
|
|
||||||
hasMin = json.bool("hasMin");
|
|
||||||
hasSec = json.bool("hasSec");
|
|
||||||
title = json.stnn("text");
|
|
||||||
isMultiline = json.bool("isMultiline");
|
|
||||||
int style = 0;
|
|
||||||
if(json.bool("fontBold")) style |= 1;
|
|
||||||
if(json.bool("fontItalic")) style |= 2;
|
|
||||||
@SuppressLint("WrongConstant") var font = Typeface.create(json.stnn("font"), style);
|
|
||||||
paint.setTypeface(font);
|
|
||||||
paint.setTextSize(json.intg("fontSize"));
|
|
||||||
paint.setUnderlineText(json.bool("fontUnderline"));
|
|
||||||
paint.setColor(Color.parseColor(json.stnn("textColor")));
|
|
||||||
paint.setTextAlign(Paint.Align.CENTER);
|
|
||||||
try {
|
|
||||||
setBackgroundColor(Color.parseColor(json.stnn("backColor")));
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
|
||||||
x = getWidth() / 2;
|
|
||||||
var fontMetrics = paint.getFontMetrics();
|
|
||||||
y = (int) (getHeight() - fontMetrics.top - fontMetrics.bottom) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cal() {
|
|
||||||
var cur = System.currentTimeMillis() / 1000;
|
|
||||||
var secs = isDown ? targetTime - cur : cur - targetTime;
|
|
||||||
if(secs < 0) secs = 0;
|
|
||||||
var buf = new StringBuilder(title);
|
|
||||||
if(buf.length() != 0) buf.append(isMultiline ? '\n' : ' ');
|
|
||||||
if(hasDay) {
|
|
||||||
buf.append(secs/86400).append(" ").append("day").append(" ");
|
|
||||||
secs %= 86400;
|
|
||||||
}
|
|
||||||
if(hasHour) {
|
|
||||||
buf.append(NumFmts.zz().format(secs/3600)).append("hour").append(" ");
|
|
||||||
secs %= 3600;
|
|
||||||
}
|
|
||||||
if(hasMin) {
|
|
||||||
buf.append(NumFmts.zz().format(secs/60)).append("min").append(" ");
|
|
||||||
secs %= 60;
|
|
||||||
}
|
|
||||||
if(hasSec) buf.append(NumFmts.zz().format(secs)).append("sec").append(" ");
|
|
||||||
text = buf.toString().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
if(lastSec==0) {
|
|
||||||
cal();
|
|
||||||
choreographer.postFrameCallback(this);
|
|
||||||
}
|
|
||||||
canvas.drawText(text, x, y, paint);
|
|
||||||
}
|
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
|
||||||
long lastSec = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFrame(long frameTimeNanos) {
|
|
||||||
if(! isShown()) {
|
|
||||||
lastSec = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var sec = frameTimeNanos / 1000000000;
|
|
||||||
if(sec != lastSec) {
|
|
||||||
lastSec = sec;
|
|
||||||
cal();
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
choreographer.postFrameCallback(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
|
import androidx.annotation.OptIn;
|
||||||
|
import androidx.media3.common.MediaItem;
|
||||||
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
import androidx.media3.exoplayer.ExoPlayer;
|
||||||
|
import androidx.media3.exoplayer.SeekParameters;
|
||||||
|
|
||||||
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
|
public class EleVVV extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
|
String path;
|
||||||
|
float vol;
|
||||||
|
IjkMediaPlayer ijkPlayer;
|
||||||
|
ExoPlayer exoPlayer;
|
||||||
|
|
||||||
|
public EleVVV(Context context, String path, float vol) {
|
||||||
|
super(context);
|
||||||
|
this.path = path;
|
||||||
|
this.vol = vol;
|
||||||
|
initIjk();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(markerClass = UnstableApi.class)
|
||||||
|
void initExo() {
|
||||||
|
exoPlayer = new ExoPlayer.Builder(getContext()).build();
|
||||||
|
exoPlayer.setMediaItem(MediaItem.fromUri(path));
|
||||||
|
exoPlayer.setRepeatMode(ExoPlayer.REPEAT_MODE_ONE);
|
||||||
|
exoPlayer.setSeekParameters(SeekParameters.CLOSEST_SYNC);
|
||||||
|
exoPlayer.setVolume(vol);
|
||||||
|
exoPlayer.setVideoSurfaceView(this);
|
||||||
|
exoPlayer.prepare();
|
||||||
|
}
|
||||||
|
void initIjk() {
|
||||||
|
ijkPlayer = new IjkMediaPlayer();
|
||||||
|
//ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
|
||||||
|
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);
|
||||||
|
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1);
|
||||||
|
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
|
||||||
|
try {
|
||||||
|
getHolder().addCallback(this);
|
||||||
|
ijkPlayer.setDataSource(path);
|
||||||
|
ijkPlayer.setLooping(true);
|
||||||
|
ijkPlayer.setVolume(vol, vol);
|
||||||
|
ijkPlayer.setOnPreparedListener((IMediaPlayer var1)->{
|
||||||
|
if(ijkPlayer.getBitRate() > 12000000) {
|
||||||
|
getHolder().removeCallback(this);
|
||||||
|
release();
|
||||||
|
initExo();
|
||||||
|
}
|
||||||
|
if(isShown()) start();
|
||||||
|
});
|
||||||
|
ijkPlayer.prepareAsync();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Util.makeText(getContext(), Util.toStr(e)).show();
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
ijkPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
if(ijkPlayer!=null) ijkPlayer.setDisplay(holder);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||||
|
System.out.println("surfaceChanged");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
System.out.println("surfaceDestroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
if(ijkPlayer!=null) {
|
||||||
|
ijkPlayer.seekTo(0);
|
||||||
|
ijkPlayer.start();
|
||||||
|
} else if(exoPlayer!=null) {
|
||||||
|
if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare();
|
||||||
|
exoPlayer.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void pause() {
|
||||||
|
if(ijkPlayer!=null) {
|
||||||
|
ijkPlayer.pause();
|
||||||
|
ijkPlayer.seekTo(0);
|
||||||
|
}
|
||||||
|
if(exoPlayer!=null && exoPlayer.isPlaying()) {
|
||||||
|
exoPlayer.pause();
|
||||||
|
exoPlayer.seekToDefaultPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void release() {
|
||||||
|
if(ijkPlayer!=null) {
|
||||||
|
ijkPlayer.release();
|
||||||
|
ijkPlayer = null;
|
||||||
|
}
|
||||||
|
if(exoPlayer!=null) {
|
||||||
|
exoPlayer.release();
|
||||||
|
exoPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String getState() {
|
||||||
|
if(exoPlayer!=null) {
|
||||||
|
var state = exoPlayer.getPlaybackState();
|
||||||
|
if(state==ExoPlayer.STATE_IDLE) return "STATE_IDLE";
|
||||||
|
if(state==ExoPlayer.STATE_BUFFERING) return "STATE_BUFFERING";
|
||||||
|
if(state==ExoPlayer.STATE_READY) return "STATE_READY";
|
||||||
|
if(state==ExoPlayer.STATE_ENDED) return "STATE_ENDED";
|
||||||
|
}
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVisibilityAggregated(boolean isVisible) {
|
||||||
|
super.onVisibilityAggregated(isVisible);
|
||||||
|
if(isVisible) start();
|
||||||
|
else pause();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package com.xixun.xixunplayer;
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.SurfaceHolder;
|
import android.graphics.Bitmap;
|
||||||
import android.view.SurfaceView;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import android.view.Surface;
|
||||||
|
import android.view.TextureView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.OptIn;
|
import androidx.annotation.OptIn;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
@ -13,12 +16,13 @@ import androidx.media3.exoplayer.SeekParameters;
|
||||||
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
public class EleVideo extends SurfaceView implements SurfaceHolder.Callback {
|
public class EleVideo extends TextureView implements TextureView.SurfaceTextureListener {
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
float vol;
|
float vol;
|
||||||
IjkMediaPlayer ijkPlayer;
|
IjkMediaPlayer ijkPlayer;
|
||||||
ExoPlayer exoPlayer;
|
ExoPlayer exoPlayer;
|
||||||
|
long bitRate;
|
||||||
|
|
||||||
public EleVideo(Context context, String path, float vol) {
|
public EleVideo(Context context, String path, float vol) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -34,7 +38,7 @@ public class EleVideo extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
exoPlayer.setRepeatMode(ExoPlayer.REPEAT_MODE_ONE);
|
exoPlayer.setRepeatMode(ExoPlayer.REPEAT_MODE_ONE);
|
||||||
exoPlayer.setSeekParameters(SeekParameters.CLOSEST_SYNC);
|
exoPlayer.setSeekParameters(SeekParameters.CLOSEST_SYNC);
|
||||||
exoPlayer.setVolume(vol);
|
exoPlayer.setVolume(vol);
|
||||||
exoPlayer.setVideoSurfaceView(this);
|
exoPlayer.setVideoTextureView(this);
|
||||||
exoPlayer.prepare();
|
exoPlayer.prepare();
|
||||||
}
|
}
|
||||||
void initIjk() {
|
void initIjk() {
|
||||||
|
@ -44,13 +48,14 @@ public class EleVideo extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
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);
|
||||||
try {
|
try {
|
||||||
getHolder().addCallback(this);
|
setSurfaceTextureListener(this);
|
||||||
ijkPlayer.setDataSource(path);
|
ijkPlayer.setDataSource(path);
|
||||||
ijkPlayer.setLooping(true);
|
ijkPlayer.setLooping(true);
|
||||||
ijkPlayer.setVolume(vol, vol);
|
ijkPlayer.setVolume(vol, vol);
|
||||||
ijkPlayer.setOnPreparedListener((IMediaPlayer var1)->{
|
ijkPlayer.setOnPreparedListener((IMediaPlayer var1)->{
|
||||||
if(ijkPlayer.getBitRate() > 12000000) {
|
bitRate = ijkPlayer.getBitRate();
|
||||||
getHolder().removeCallback(this);
|
if(bitRate > 12000000) {
|
||||||
|
setSurfaceTextureListener(null);
|
||||||
release();
|
release();
|
||||||
initExo();
|
initExo();
|
||||||
}
|
}
|
||||||
|
@ -58,27 +63,31 @@ public class EleVideo extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
});
|
});
|
||||||
ijkPlayer.prepareAsync();
|
ijkPlayer.prepareAsync();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Util.makeText(getContext(), e.getMessage()).show();
|
Util.makeText(getContext(), Util.toStr(e)).show();
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
ijkPlayer = null;
|
ijkPlayer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
|
||||||
if(ijkPlayer!=null) ijkPlayer.setDisplay(holder);
|
if(ijkPlayer!=null) ijkPlayer.setSurface(new Surface(surface));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
|
||||||
System.out.println("surfaceChanged");
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
|
||||||
System.out.println("surfaceDestroyed");
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
if(ijkPlayer!=null) ijkPlayer.start();
|
if(ijkPlayer!=null) {
|
||||||
else if(exoPlayer!=null) {
|
ijkPlayer.seekTo(0);
|
||||||
|
ijkPlayer.start();
|
||||||
|
} else if(exoPlayer!=null) {
|
||||||
if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare();
|
if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare();
|
||||||
exoPlayer.play();
|
exoPlayer.play();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class EleVideo2 extends VideoView implements Choreographer.FrameCallback
|
||||||
setOnErrorListener((MediaPlayer mp, int what, int extra)->{
|
setOnErrorListener((MediaPlayer mp, int what, int extra)->{
|
||||||
var err = "Media Error: "+getErrorName(what)+". "+getErrorName(extra);
|
var err = "Media Error: "+getErrorName(what)+". "+getErrorName(extra);
|
||||||
Util.makeText(getContext(), err).show();
|
Util.makeText(getContext(), err).show();
|
||||||
MainActivity.ins.buf.append(err+'\n');
|
Util.println(err);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
start();
|
start();
|
||||||
|
@ -39,25 +39,29 @@ public class EleVideo2 extends VideoView implements Choreographer.FrameCallback
|
||||||
public void onVisibilityAggregated(boolean isVisible) {
|
public void onVisibilityAggregated(boolean isVisible) {
|
||||||
super.onVisibilityAggregated(isVisible);
|
super.onVisibilityAggregated(isVisible);
|
||||||
if(isVisible) {
|
if(isVisible) {
|
||||||
MainActivity.ins.buf.append("Video Show\n");
|
Util.println("Video Show");
|
||||||
if(! isPlaying()) {
|
if(! isPlaying()) {
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
start();
|
start();
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
if(! isPlaying()) MainActivity.ins.buf.append("Video isn't Playing on Show\n");
|
if(! isPlaying()) Util.println("Video isn't Playing on Show");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MainActivity.ins.buf.append("Video Hide\n");
|
Util.println("Video Hide");
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
pause();
|
pause();
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
showCnt = 3;
|
showCnt = 3;
|
||||||
choreographer.postFrameCallback(this);
|
if(canAdd) {
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
int showCnt;
|
int showCnt;
|
||||||
|
boolean canAdd = true;
|
||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
if(isShown()) {
|
if(isShown()) {
|
||||||
|
@ -66,7 +70,7 @@ public class EleVideo2 extends VideoView implements Choreographer.FrameCallback
|
||||||
start();
|
start();
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
if(! isPlaying()) {
|
if(! isPlaying()) {
|
||||||
MainActivity.ins.buf.append("Video isn't Playing on doFrame ").append(showCnt).append('\n');
|
Util.println("Video isn't Playing on doFrame "+showCnt);
|
||||||
if(showCnt==0) {
|
if(showCnt==0) {
|
||||||
suspend();
|
suspend();
|
||||||
resume();
|
resume();
|
||||||
|
@ -74,14 +78,18 @@ public class EleVideo2 extends VideoView implements Choreographer.FrameCallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(showCnt>0) showCnt--;
|
if(showCnt>0) showCnt--;
|
||||||
else return;
|
else {
|
||||||
|
canAdd = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else if(isPlaying()) {
|
} else if(isPlaying()) {
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
pause();
|
pause();
|
||||||
seekTo(0);
|
seekTo(0);
|
||||||
System.out.println("pause in doFrame()");
|
Util.println("pause in doFrame()");
|
||||||
}
|
}
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getErrorName(int code) {
|
static String getErrorName(int code) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.xixun.xixunplayer;
|
||||||
|
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
@ -30,27 +31,29 @@ import androidx.media3.common.util.UnstableApi;
|
||||||
|
|
||||||
import com.xixun.joey.aidlset.CardService;
|
import com.xixun.joey.aidlset.CardService;
|
||||||
|
|
||||||
|
import net.lingala.zip4j.ZipFile;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import gnph.util.Dates;
|
|
||||||
import gnph.util.IOs;
|
import gnph.util.IOs;
|
||||||
import gnph.util.JSList;
|
import gnph.util.JSList;
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
import gnph.util.NumFmts;
|
import gnph.util.NumFmts;
|
||||||
import gnph.util.O;
|
import gnph.util.O;
|
||||||
import tv.danmaku.ijk.media.player.IjkMediaMeta;
|
|
||||||
|
|
||||||
public class MainActivity extends ComponentActivity implements Choreographer.FrameCallback, Runnable {
|
public class MainActivity extends ComponentActivity implements Choreographer.FrameCallback, Runnable {
|
||||||
|
|
||||||
|
@ -67,15 +70,14 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
@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;
|
||||||
startService(new Intent(this, RestartService.class));
|
startService(new Intent(this, RestartService.class));
|
||||||
|
|
||||||
var msg = "---- MainActivity onCreate ---- UI Thread: "+Thread.currentThread().getId();
|
|
||||||
System.out.println(msg);
|
|
||||||
buf.append(msg).append('\n');
|
|
||||||
ins = this;
|
|
||||||
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) init();
|
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) init();
|
||||||
else {
|
else {
|
||||||
System.out.println("---- No permission, Try again ...");
|
Util.println("---- No permission, Try again ...");
|
||||||
ActivityCompat.requestPermissions(this, new String[]{
|
ActivityCompat.requestPermissions(this, new String[]{
|
||||||
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
android.Manifest.permission.READ_EXTERNAL_STORAGE,
|
android.Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
@ -85,42 +87,45 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
}, 999);
|
}, 999);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
if(requestCode==999 && 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||||
public void init() {
|
public void init() {
|
||||||
Util.programDir = Environment.getExternalStorageDirectory() + "/XixunPlayer/program";
|
var dir = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ? Environment.getExternalStorageDirectory().getAbsolutePath() + "/XixunPlayer" : getExternalFilesDir(null).getAbsolutePath();
|
||||||
Util.backImgFile = Environment.getExternalStorageDirectory() + "/XixunPlayer/background";
|
var msg = "---- dir "+dir;
|
||||||
|
Util.println(msg);
|
||||||
|
Util.programDir = dir + "/program";
|
||||||
|
Util.backImgFile = dir + "/background";
|
||||||
|
|
||||||
var program = new File(Util.programDir);
|
var program = new File(Util.programDir);
|
||||||
if(program.isFile()) program.delete();
|
if(program.isFile()) program.delete();
|
||||||
var msg = "mkdir: "+program.mkdirs();
|
msg = "---- mkdir: "+program.mkdirs();
|
||||||
System.out.println(msg);
|
Util.println(msg);
|
||||||
buf.append(msg).append('\n');
|
|
||||||
|
|
||||||
var conn = new ServiceConnection() {
|
var conn = new ServiceConnection() {
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
System.out.println("Disconnected cardsystem aidl service");
|
Util.println("Disconnected cardsystem aidl service");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceConnected(ComponentName name, IBinder iBinder) {
|
public void onServiceConnected(ComponentName name, IBinder iBinder) {
|
||||||
System.out.println("Bind cardsystem aidl service success");
|
Util.println("Bind cardsystem aidl service success");
|
||||||
buf.append("Bind cardsystem aidl service success\n");
|
|
||||||
var service = CardService.Stub.asInterface(iBinder);
|
var service = CardService.Stub.asInterface(iBinder);
|
||||||
try {
|
try {
|
||||||
Util.isScreenOn = service.isScreenOpen();
|
Util.isScreenOn = service.isScreenOpen();
|
||||||
buf.append("isScreenOn:").append(Util.isScreenOn).append("\n");
|
Util.println("isScreenOn: "+Util.isScreenOn);
|
||||||
backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight());
|
backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight());
|
||||||
state = 5;
|
state = 5;
|
||||||
if(Util.isScreenOn) initProg();
|
if(Util.isScreenOn) initProg();
|
||||||
else state = 8;
|
else state = 8;
|
||||||
if(progView==null) setContentView(backView);
|
if(progView==null) setContentView(backView);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Util.makeText(MainActivity.this, e.toString()).show();
|
Util.makeText(MainActivity.this, Util.toStr(e)).show();
|
||||||
throw new RuntimeException(e);
|
Util.printStackTrace(e);
|
||||||
} finally {
|
} finally {
|
||||||
unbindService(this);
|
unbindService(this);
|
||||||
}
|
}
|
||||||
|
@ -130,13 +135,58 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
intent.setPackage("com.xixun.joey.cardsystem");
|
intent.setPackage("com.xixun.joey.cardsystem");
|
||||||
bindService(intent, conn, Context.BIND_AUTO_CREATE);
|
bindService(intent, conn, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
|
var intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
|
||||||
|
intentFilter.addDataScheme("file");
|
||||||
|
registerReceiver(new BroadcastReceiver(){
|
||||||
|
long lastMs;
|
||||||
|
char [] pass = {'8','8','8'};
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
var path = intent.getData().getPath();
|
||||||
|
Util.println("\nMEDIA_MOUNTED path: "+path);
|
||||||
|
var ms = System.currentTimeMillis();
|
||||||
|
if(ms-lastMs<1000) return;
|
||||||
|
lastMs = ms;
|
||||||
|
Util.makeText(MainActivity.this, "MEDIA_MOUNTED path: "+path).show();
|
||||||
|
new Thread(()->{
|
||||||
|
try {
|
||||||
|
var zip = new ZipFile(path+"/program.zip");
|
||||||
|
if(zip.isEncrypted()) zip.setPassword(pass);
|
||||||
|
var json = JSMap.fromClose(zip.getInputStream(zip.getFileHeader("program")));
|
||||||
|
var isIns = json.bool("isIns");
|
||||||
|
long size = 0;
|
||||||
|
var headers = zip.getFileHeaders();
|
||||||
|
for(var header : headers) size += header.getUncompressedSize();
|
||||||
|
if(size==0) {
|
||||||
|
Util.println("zip size is 0");
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Util.makeText(MainActivity.this, "zip size is 0").show();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Util.deleteFiles(size, null);
|
||||||
|
for(var header : headers) zip.extractFile(header, Util.programDir);
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Util.println("Import Succeed");
|
||||||
|
Util.makeText(MainActivity.this, "Import Succeed").show();
|
||||||
|
initProg();
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Util.makeText(MainActivity.this, Util.toStr(e)).show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}, intentFilter);
|
||||||
|
|
||||||
registerReceiver(new BroadcastReceiver(){
|
registerReceiver(new BroadcastReceiver(){
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
System.out.println("Receive PAUSE_PLAYER");
|
Util.println("Receive PAUSE_PLAYER");
|
||||||
buf.append("Receive PAUSE_PLAYER\n");
|
|
||||||
Util.isScreenOn = ! intent.getBooleanExtra("pause", false);
|
Util.isScreenOn = ! intent.getBooleanExtra("pause", false);
|
||||||
buf.append("isScreenOn:").append(Util.isScreenOn).append("\n");
|
Util.println(" isScreenOn: "+Util.isScreenOn);
|
||||||
if(! Util.isScreenOn) {
|
if(! Util.isScreenOn) {
|
||||||
state = 8;
|
state = 8;
|
||||||
if(progView!=null) {
|
if(progView!=null) {
|
||||||
|
@ -146,7 +196,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
}
|
}
|
||||||
} else if(progView==null) initProg();
|
} else if(progView==null) initProg();
|
||||||
}
|
}
|
||||||
}, new IntentFilter("com.xixun.action.PAUSE_PLAYER"), RECEIVER_EXPORTED);
|
}, new IntentFilter("com.xixun.action.PAUSE_PLAYER"));
|
||||||
|
|
||||||
// registerReceiver(new BroadcastReceiver(){
|
// registerReceiver(new BroadcastReceiver(){
|
||||||
// @Override
|
// @Override
|
||||||
|
@ -163,14 +213,14 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
environ.invalidate();
|
environ.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new IntentFilter("xixun.intent.action.TEMPERATURE_HUMIDITY"), RECEIVER_EXPORTED);
|
}, new IntentFilter("xixun.intent.action.TEMPERATURE_HUMIDITY"));
|
||||||
|
|
||||||
registerReceiver(new BroadcastReceiver(){
|
registerReceiver(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);
|
||||||
buf.append("remote_control ").append(code).append("\n");
|
Util.println(" remote_control "+code);
|
||||||
if(progView == null || code > progView.pages.size()) return;
|
if(progView == null || code > progView.pages.size()) return;
|
||||||
if(! progView.avas.isEmpty()) page(curAva).hide();
|
if(! progView.avas.isEmpty()) page(curAva).hide();
|
||||||
var millis = (System.currentTimeMillis()+999)/1000*1000;
|
var millis = (System.currentTimeMillis()+999)/1000*1000;
|
||||||
|
@ -181,7 +231,6 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
curTimes = 1;
|
curTimes = 1;
|
||||||
waitTo = 0;
|
waitTo = 0;
|
||||||
var page = page(0);
|
var page = page(0);
|
||||||
dur = page.tDur;
|
|
||||||
page.setMillis(millis);
|
page.setMillis(millis);
|
||||||
if(state != 6) {
|
if(state != 6) {
|
||||||
setContentView(progView);
|
setContentView(progView);
|
||||||
|
@ -192,11 +241,11 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
syncProg(millis);
|
syncProg(millis);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Util.makeText(MainActivity.this, e.toString()).show();
|
Util.makeText(MainActivity.this, Util.toStr(e)).show();
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new IntentFilter("com.xixun.yzd.REMOTE_CONTROL"), RECEIVER_EXPORTED);
|
}, new IntentFilter("com.xixun.yzd.REMOTE_CONTROL"));
|
||||||
|
|
||||||
new Thread(this).start();
|
new Thread(this).start();
|
||||||
}
|
}
|
||||||
|
@ -238,99 +287,95 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
if(progView!=null) progView.release();
|
if(progView!=null) progView.release();
|
||||||
progView = view;
|
progView = view;
|
||||||
setContentView(progView);
|
setContentView(progView);
|
||||||
buf.append("init sync\n");
|
state = 5;
|
||||||
|
Util.println("Init Sync");
|
||||||
syncProg((System.currentTimeMillis()+999)/1000*1000);
|
syncProg((System.currentTimeMillis()+999)/1000*1000);
|
||||||
choreographer.postFrameCallback(this);
|
if(canAdd) {
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
state = 3;
|
state = 3;
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
state = 7;
|
state = 7;
|
||||||
Util.makeText(this, e.toString()).show();
|
Util.makeText(this, Util.toStr(e)).show();
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
int curAva, curTimes = 1, dur;
|
int curAva, curTimes = 1;
|
||||||
long waitTo = Long.MAX_VALUE;
|
long waitTo = Long.MAX_VALUE;
|
||||||
StringBuffer buf = new StringBuffer();
|
boolean canAdd = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
if(progView == null) return;
|
if(progView == null) {
|
||||||
|
canAdd = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
var milli = System.currentTimeMillis();
|
var milli = System.currentTimeMillis();
|
||||||
if(progView.avas.isEmpty()) {
|
if(progView.avas.isEmpty()) {
|
||||||
if(milli >= waitTo) {
|
if(milli >= waitTo) {
|
||||||
waitTo = Long.MAX_VALUE;
|
waitTo = Long.MAX_VALUE;
|
||||||
buf.append("wait sync\n");
|
Util.println("wait sync");
|
||||||
syncProg(milli);
|
syncProg(milli);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var lastPage = page(curAva);
|
var lastPage = page(curAva);
|
||||||
if(milli >= lastPage.endMilli) {
|
if(milli >= lastPage.endMilli) {
|
||||||
lastPage.hide();
|
lastPage.hide();
|
||||||
if(waitTo>0) {
|
if(waitTo>0) { //waitTo==0 为点播,不换页
|
||||||
if(curTimes < lastPage.repeatTimes) curTimes++;
|
if(curTimes < lastPage.repeatTimes) curTimes++;
|
||||||
else {
|
else {
|
||||||
curTimes = 1;
|
curTimes = 1;
|
||||||
curAva++;
|
curAva++;
|
||||||
if(curAva >= progView.avas.size()) {
|
if(curAva >= progView.avas.size()) {
|
||||||
var isDiff = milli-lastPage.endMilli>=1000;
|
var isDiff = milli-lastPage.endMilli>=1000;
|
||||||
if(buf.length()>1000000) buf.replace(0, 100000, "");
|
if(Util.buf.length()>1000000) Util.buf.replace(0, 100000, "");
|
||||||
buf.append("isDiff:").append(isDiff).append(" endMs:").append(lastPage.endMilli).append(" millis:").append(milli).append("\n");
|
Util.println("isDiff: "+isDiff+" endMs: "+lastPage.endMilli+" millis:"+milli);
|
||||||
syncProg(isDiff ? milli : lastPage.endMilli);
|
syncProg(isDiff ? milli : lastPage.endMilli);
|
||||||
buf.append("after. curAva:").append(curAva).append(" endMs:").append(lastPage.endMilli).append("\n");
|
Util.println("after. curAva: "+curAva+" endMs: "+lastPage.endMilli);
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page(curAva).setMillis(lastPage.endMilli);
|
page(curAva).setMillis(lastPage.endMilli);
|
||||||
buf.append("curAva:").append(curAva).append(" endMs:").append(lastPage.endMilli).append("\n");
|
Util.println("curAva: "+curAva+" endMs: "+lastPage.endMilli);
|
||||||
} else {
|
} else {
|
||||||
for(var layer : lastPage.layers) {
|
for(var layer : lastPage.layers) {
|
||||||
for(var ele : layer.eles) {
|
for(var src : layer.srcs) {
|
||||||
if(ele.view.getVisibility()==VISIBLE) {
|
if(src.view.getVisibility()==VISIBLE) {
|
||||||
if(milli >= ele.endMilli) ele.hide();
|
if(milli >= src.endMilli) src.hide();
|
||||||
// else if(ele.needLoop) {
|
else src.doEff();
|
||||||
// try {
|
} else if(milli < src.endMilli && milli >= src.startMilli) src.show();
|
||||||
// var vv = (EleVideo) ele.view;
|
|
||||||
// var vdur = vv.getDuration();
|
|
||||||
// if(vdur>=1000) {
|
|
||||||
// ele.needLoop = false;
|
|
||||||
// if(ele.endTime-ele.startTime-vdur>=1000) vv.exoPlayer.setRepeatMode(ExoPlayer.REPEAT_MODE_ONE);
|
|
||||||
// }
|
|
||||||
// } catch (Throwable e) {
|
|
||||||
// Util.makeText(this, e.toString()).show();
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} else if(milli < ele.endMilli && milli >= ele.startMilli) ele.show();
|
|
||||||
}
|
}
|
||||||
if(milli >= layer.endMilli) {
|
if(milli >= layer.endMilli) {
|
||||||
layer.endMilli += layer.dur;
|
layer.endMilli += layer.dur;
|
||||||
for(var ele : layer.eles) {
|
for(var src : layer.srcs) {
|
||||||
ele.endMilli += layer.dur;
|
src.endMilli += layer.dur;
|
||||||
ele.startMilli += layer.dur;
|
src.startMilli += layer.dur;
|
||||||
if(ele.startTime > 0) ele.hide();
|
if(src.startTime > 0) src.hide();
|
||||||
else ele.show();
|
else src.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncProg(long milli) {
|
void syncProg(long milli) {
|
||||||
curTimes = 1;
|
curTimes = 1;
|
||||||
progView.avas.clear();
|
progView.avas.clear();
|
||||||
dur = 0;
|
var dur = 0;
|
||||||
Prog.Page page;
|
for(int i=0; i<progView.pages.size(); i++) if(progView.pages.get(i).isSchedule(milli+dur)) {
|
||||||
for(int i=0; i<progView.pages.size(); i++) if((page = progView.pages.get(i)).isSchedule(milli+dur)) {
|
|
||||||
progView.avas.add(i);
|
progView.avas.add(i);
|
||||||
dur += page.tDur;
|
dur += progView.pages.get(i).tDur;
|
||||||
}
|
}
|
||||||
if(dur==0) {
|
if(dur==0) {
|
||||||
waitTo = milli + 1000;
|
waitTo = milli + 1000;
|
||||||
|
@ -347,7 +392,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
} while(curAva < progView.avas.size() && start<=milli);
|
} while(curAva < progView.avas.size() && start<=milli);
|
||||||
start -= page(--curAva).tDur;
|
start -= page(--curAva).tDur;
|
||||||
syncMs = milli;
|
syncMs = milli;
|
||||||
buf.append("Sync. milli:").append(milli).append(" start:").append(start).append(" diff:").append(milli - start).append("\n");
|
Util.println("Sync. milli: "+milli+" start: "+start+" diff: "+(milli - start));
|
||||||
}
|
}
|
||||||
page(curAva).setMillis(start);
|
page(curAva).setMillis(start);
|
||||||
if(state != 6) {
|
if(state != 6) {
|
||||||
|
@ -368,19 +413,19 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
System.out.println("Accept ...");
|
Util.println("Accepting ...");
|
||||||
final var socket = serverSocket.accept();
|
final var socket = serverSocket.accept();
|
||||||
System.out.println("Receiving ...");
|
Util.println("Accepted");
|
||||||
in = socket.getInputStream();
|
in = socket.getInputStream();
|
||||||
out = socket.getOutputStream();
|
out = socket.getOutputStream();
|
||||||
JSList<String> hases = null;
|
HashSet<String> hases = null;
|
||||||
while(true) {
|
while(true) {
|
||||||
var obj = JSMap.from(in);
|
var obj = JSMap.from(in);
|
||||||
var _type = obj.stnn("_type");
|
var _type = obj.stnn("_type");
|
||||||
System.out.println("_type: "+_type);
|
Util.println("_type: "+_type);
|
||||||
if("consult".equals(_type)) {
|
if("consult".equals(_type)) {
|
||||||
JSList<String> ids = obj.jslist("idList");
|
JSList<String> ids = obj.jslist("idList");
|
||||||
hases = new JSList<>();
|
hases = new HashSet<>();
|
||||||
if(ids!=null) for(int i=0; i<ids.size(); i++) {
|
if(ids!=null) for(int i=0; i<ids.size(); i++) {
|
||||||
if(new File(Util.programDir + "/" + ids.get(i)).exists()) ids.remove(i--);
|
if(new File(Util.programDir + "/" + ids.get(i)).exists()) ids.remove(i--);
|
||||||
else hases.add(ids.get(i));
|
else hases.add(ids.get(i));
|
||||||
|
@ -391,7 +436,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
} else if("fileStart".equals(_type)) {
|
} else if("fileStart".equals(_type)) {
|
||||||
var size = obj.intg("size");
|
var size = obj.intg("size");
|
||||||
var name = obj.stnn("id");
|
var name = obj.stnn("id");
|
||||||
System.out.println(" size: " + size + " name: " + name);
|
Util.println(" size: " + size + " name: " + name);
|
||||||
var fout = new FileOutputStream(Util.programDir + "/" + name);
|
var fout = new FileOutputStream(Util.programDir + "/" + name);
|
||||||
IOs.write(fout, in, size);
|
IOs.write(fout, in, size);
|
||||||
fout.flush();
|
fout.flush();
|
||||||
|
@ -439,14 +484,16 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
).write(out);
|
).write(out);
|
||||||
} else if("GetInfo".equals(_type)) {
|
} else if("GetInfo".equals(_type)) {
|
||||||
var writer = new OutputStreamWriter(out);
|
var writer = new OutputStreamWriter(out);
|
||||||
var fmt = "yy-MM-dd HH:mm:ss.SSS";
|
var Fmt = new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS");
|
||||||
writer.append("ProgSend: ").append(Dates.fmt(new File(Util.programDir + "/program").lastModified(), fmt)).append(" ProgDur: ").append(String.valueOf(dur));
|
var dur = 0;
|
||||||
|
if(progView!=null) for(var page : progView.pages) dur += page.tDur;
|
||||||
|
writer.append("ProgSend: ").append(Fmt.format(new File(Util.programDir + "/program").lastModified())).append(" ProgDur: ").append(String.valueOf(dur));
|
||||||
if(progView!=null) writer.append(" Pages: ").append(String.valueOf(progView.avas.size())).append(" / ").append(String.valueOf(progView.pages.size()));
|
if(progView!=null) writer.append(" Pages: ").append(String.valueOf(progView.avas.size())).append(" / ").append(String.valueOf(progView.pages.size()));
|
||||||
writer.append("\n");
|
writer.append("\n");
|
||||||
writer.append(" Launch: ").append(Dates.fmt(launchMilli, fmt)).append("\n");
|
writer.append(" Launch: ").append(Fmt.format(launchMilli)).append("\n");
|
||||||
writer.append(" Sync: ").append(Dates.fmt(syncMs, fmt)).append("\n");
|
writer.append(" Sync: ").append(Fmt.format(syncMs)).append("\n");
|
||||||
writer.append("Page End: ").append(progView==null || progView.avas.isEmpty() ? "0" : Dates.fmt(page(curAva).endMilli, fmt)).append(" CurPage: ").append(String.valueOf(curAva)).append(" / ").append(progView==null || progView.avas.isEmpty() ? "0" : String.valueOf(progView.avas.get(curAva))).append("\n");
|
writer.append("Page End: ").append(progView==null || progView.avas.isEmpty() ? "0" : Fmt.format(page(curAva).endMilli)).append(" CurPage: ").append(String.valueOf(curAva)).append(" / ").append(progView==null || progView.avas.isEmpty() ? "0" : String.valueOf(progView.avas.get(curAva))).append("\n");
|
||||||
writer.append(" Current: ").append(Dates.fmt(System.currentTimeMillis(), fmt)).append("\n");
|
writer.append(" Current: ").append(Fmt.format(System.currentTimeMillis())).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) getSystemService(ACTIVITY_SERVICE);
|
var actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||||
|
@ -455,35 +502,41 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
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");
|
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");
|
||||||
|
IOs.writeCloseIn(writer, new FileReader("/proc/stat"));
|
||||||
|
writer.append("\n");
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
if(! progView.avas.isEmpty()) {
|
if(progView!=null && ! progView.avas.isEmpty()) {
|
||||||
var page = page(curAva);
|
var page = page(curAva);
|
||||||
for(var layer : page.layers) for(var ele : layer.eles) if(ele.view.getVisibility()==VISIBLE) {
|
for(var layer : page.layers) for(var src : layer.srcs) if(src.view.getVisibility()==VISIBLE) {
|
||||||
try {
|
try {
|
||||||
if(ele.view instanceof EleVideo) {
|
if(src.view instanceof EleVideo) {
|
||||||
var view = (EleVideo) ele.view;
|
var view = (EleVideo) src.view;
|
||||||
if(view.ijkPlayer!=null) {
|
if(view.ijkPlayer!=null) {
|
||||||
writer.append("VideoPlaying: ").append(String.valueOf(view.ijkPlayer.isPlaying())).append(" ").append(String.valueOf(view.ijkPlayer.getCurrentPosition())).append("/").append(String.valueOf(view.ijkPlayer.getDuration())).append("\n");
|
writer.append("VideoPlaying: ").append(String.valueOf(view.ijkPlayer.isPlaying())).append("\tCur/Dur: ").append(String.valueOf(view.ijkPlayer.getCurrentPosition())).append("/").append(String.valueOf(view.ijkPlayer.getDuration())).append("\n");
|
||||||
writer.append(" BitRate: ").append(String.valueOf(view.ijkPlayer.getBitRate()/1000)).append("\n");
|
|
||||||
writer.append("VideoDecoder: ").append(String.valueOf(view.ijkPlayer.getVideoDecoder())).append("\n");
|
|
||||||
var mediaInfo = view.ijkPlayer.getMediaInfo();
|
var mediaInfo = view.ijkPlayer.getMediaInfo();
|
||||||
writer.append("Format: ").append(mediaInfo.mMeta.mFormat).append("\n");
|
var vStream = mediaInfo.mMeta.mVideoStream;
|
||||||
writer.append("VideoDecoder: ").append(mediaInfo.mVideoDecoder).append(" ").append(mediaInfo.mVideoDecoderImpl).append("\n");
|
writer.append(" BitRate: ").append(String.valueOf(view.ijkPlayer.getBitRate()/1000)).append("k\tFPS: ").append(String.valueOf(vStream.mFpsNum/(float)vStream.mFpsDen)).append(" (").append(String.valueOf(vStream.mFpsNum)).append("/").append(String.valueOf(vStream.mFpsDen)).append(")\n");
|
||||||
|
var tracks = view.ijkPlayer.getTrackInfo();
|
||||||
|
for(var track : tracks) writer.append(" ").append(track.getInfoInline()).append("\n");
|
||||||
|
writer.append(" Format: ").append(mediaInfo.mMeta.mFormat).append("\n");
|
||||||
|
writer.append("VideoDecoder: ").append(mediaInfo.mVideoDecoder).append(" ").append(mediaInfo.mVideoDecoderImpl).append(" (").append(String.valueOf(view.ijkPlayer.getVideoDecoder())).append(")\n");
|
||||||
writer.append("AudioDecoder: ").append(mediaInfo.mAudioDecoder).append(" ").append(mediaInfo.mAudioDecoderImpl).append("\n");
|
writer.append("AudioDecoder: ").append(mediaInfo.mAudioDecoder).append(" ").append(mediaInfo.mAudioDecoderImpl).append("\n");
|
||||||
//writer.append("PROFILE: ").append(mediaInfo.mMeta.getString(IjkMediaMeta.IJKM_KEY_CODEC_PROFILE)).append("\n");
|
//writer.append("PROFILE: ").append(mediaInfo.mMeta.getString(IjkMediaMeta.IJKM_KEY_CODEC_PROFILE)).append("\n");
|
||||||
} else if(view.exoPlayer!=null) {
|
} else if(view.exoPlayer!=null) {
|
||||||
writer.append("isVideoPlaying: ").append(String.valueOf(view.exoPlayer.isPlaying())).append(" ").append(String.valueOf(view.exoPlayer.getCurrentPosition())).append("/").append(String.valueOf(view.exoPlayer.getDuration())).append("\n");
|
writer.append("VideoPlaying: ").append(String.valueOf(view.exoPlayer.isPlaying())).append(" ").append(String.valueOf(view.exoPlayer.getCurrentPosition())).append("/").append(String.valueOf(view.exoPlayer.getDuration())).append("\n");
|
||||||
writer.append("getPlaybackState: ").append(view.getState()).append("\n");
|
writer.append(" BitRate: ").append(String.valueOf(view.bitRate/1000)).append("k\n");
|
||||||
writer.append("getPlayerError: ").append(String.valueOf(view.exoPlayer.getPlayerError())).append("\n");
|
writer.append("PlaybackStat: ").append(view.getState()).append("\n");
|
||||||
writer.append("getVideoFormat: ").append(String.valueOf(view.exoPlayer.getVideoFormat())).append("\n");
|
writer.append(" PlayerError: ").append(String.valueOf(view.exoPlayer.getPlayerError())).append("\n");
|
||||||
|
writer.append(" VideoFormat: ").append(String.valueOf(view.exoPlayer.getVideoFormat())).append("\n");
|
||||||
var cnt = view.exoPlayer.getRendererCount();
|
var cnt = view.exoPlayer.getRendererCount();
|
||||||
for(int rr=0; rr<cnt; rr++) writer.append(" Renderer: ").append(String.valueOf(view.exoPlayer.getRendererType(rr))).append(" ").append(String.valueOf(view.exoPlayer.getRenderer(rr))).append("\n");
|
for(int rr=0; rr<cnt; rr++) writer.append(" Renderer: ").append(String.valueOf(view.exoPlayer.getRendererType(rr))).append(" ").append(String.valueOf(view.exoPlayer.getRenderer(rr))).append("\n");
|
||||||
writer.append("getPlaybackParameters: ").append(String.valueOf(view.exoPlayer.getPlaybackParameters())).append("\n");
|
writer.append("getPlaybackParameters: ").append(String.valueOf(view.exoPlayer.getPlaybackParameters())).append("\n");
|
||||||
}
|
}
|
||||||
writer.append("\n");
|
writer.append("\n");
|
||||||
} else if(ele.view instanceof WebView) {
|
} else if(src.view instanceof WebView) {
|
||||||
var view = (WebView) ele.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("OrUrl: ").append(view.getOriginalUrl()).append("\n");
|
||||||
|
@ -500,7 +553,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
} catch (InterruptedException ignored) {}
|
} catch (InterruptedException ignored) {}
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} else if("GetLog".equals(_type)) {
|
} else if("GetLog".equals(_type)) {
|
||||||
out.write(buf.toString().getBytes());
|
out.write(Util.buf.toString().getBytes());
|
||||||
} else if("ListProgFiles".equals(_type)) {
|
} else if("ListProgFiles".equals(_type)) {
|
||||||
var files = new File(Util.programDir).listFiles();
|
var files = new File(Util.programDir).listFiles();
|
||||||
if(files == null) return;
|
if(files == null) return;
|
||||||
|
@ -517,23 +570,29 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
|
||||||
if(name!=null) IOs.writeCloseIn(out, new FileInputStream(Util.programDir+"/"+name));
|
if(name!=null) IOs.writeCloseIn(out, new FileInputStream(Util.programDir+"/"+name));
|
||||||
else new JSMap("code", 1, "msg", "name is null").write(out);
|
else new JSMap("code", 1, "msg", "name is null").write(out);
|
||||||
}
|
}
|
||||||
|
out.flush();
|
||||||
|
Util.println("cmd end");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
var emsg = e.getMessage();
|
var emsg = e.getMessage();
|
||||||
if(emsg!=null && ("Socket closed".equals(emsg) || emsg.endsWith("end-of-input"))) continue;
|
if(emsg!=null && ("Socket closed".equals(emsg) || emsg.endsWith("end-of-input"))) {
|
||||||
|
Util.println(emsg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
MainActivity.ins.runOnUiThread(() -> {
|
MainActivity.ins.runOnUiThread(() -> {
|
||||||
Util.makeText(MainActivity.this, e.getMessage()).show();
|
Util.makeText(MainActivity.this, Util.toStr(e)).show();
|
||||||
});
|
});
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
} finally {
|
} finally {
|
||||||
O.close(in, out);
|
O.close(in, out);
|
||||||
|
Util.println("conn end");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
MainActivity.ins.runOnUiThread(() -> {
|
MainActivity.ins.runOnUiThread(() -> {
|
||||||
Util.makeText(MainActivity.this, e.toString()).show();
|
Util.makeText(MainActivity.this, Util.toStr(e)).show();
|
||||||
});
|
});
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,10 +9,10 @@ import android.webkit.WebViewClient;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.time.LocalDate;
|
import java.text.ParseException;
|
||||||
import java.time.LocalTime;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import gnph.util.Dates;
|
import gnph.util.Dates;
|
||||||
import gnph.util.JSList;
|
import gnph.util.JSList;
|
||||||
|
@ -24,19 +24,53 @@ public class Prog extends AbsLayout {
|
||||||
|
|
||||||
ArrayList<Page> pages = new ArrayList<>();
|
ArrayList<Page> pages = new ArrayList<>();
|
||||||
ArrayList<Integer> avas = new ArrayList<>();
|
ArrayList<Integer> avas = new ArrayList<>();
|
||||||
HashSet<Source> toBeHided = new HashSet<>();
|
|
||||||
|
|
||||||
public Prog(JSMap task, Context context) {
|
public Prog(JSMap task, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
JSList<JSMap> jpages = task.jslist("items");
|
JSList<JSMap> jpages = task.jslist("items");
|
||||||
|
JSList<Long> partLengths = task.jslist("partLengths");
|
||||||
|
var isVertical = task.bool("isVertical");
|
||||||
|
var partObj = task;
|
||||||
|
if(partLengths==null) {
|
||||||
|
try {
|
||||||
|
var _program = jpages.get(0).jsmap("_program");
|
||||||
|
partLengths = _program.jslist("splitWidths");
|
||||||
|
isVertical = _program.bool("isVer");
|
||||||
|
partObj = _program;
|
||||||
|
} catch (Throwable ignored){}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
var len0 = partLengths.get(0).intValue();
|
||||||
|
addView(mask, isVertical ? new AbsLayout.LayoutParams(0, len0, width, height - len0) : new AbsLayout.LayoutParams(len0, 0, width - len0, height));
|
||||||
|
int x = 0, y = 0;
|
||||||
|
for(int i=1; i<partLengths.size(); i++) {
|
||||||
|
var part = new SrcCopy(context, box);
|
||||||
|
if(isVertical) {
|
||||||
|
y -= partLengths.get(i-1);
|
||||||
|
x += width;
|
||||||
|
addView(part, new AbsLayout.LayoutParams(x, y, width, partLengths.get(i).intValue() - y));
|
||||||
|
} else {
|
||||||
|
x -= partLengths.get(i-1);
|
||||||
|
y += height;
|
||||||
|
addView(part, new AbsLayout.LayoutParams(x, y, partLengths.get(i).intValue() - x, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for(var pageMap : jpages) {
|
for(var pageMap : jpages) {
|
||||||
var _program = pageMap.jsmap("_program");
|
var _program = pageMap.jsmap("_program");
|
||||||
JSList<JSMap> layers = _program.jslist("layers");
|
JSList<JSMap> layers = _program.jslist("layers");
|
||||||
if(layers.isEmpty()) continue;
|
if(layers==null || layers.isEmpty()) continue;
|
||||||
JSList<Long> splitWidths = _program.jslist("splitWidths");
|
|
||||||
var page = new Page();
|
var page = new Page();
|
||||||
page.repeatTimes = pageMap.intg("repeatTimes");
|
page.repeatTimes = pageMap.intg("repeatTimes");
|
||||||
page.parse(pageMap.jslist("schedules"));
|
page.parse(pageMap.jslist("schedules"));
|
||||||
|
HashMap<String, EleVideo> videoMap = new HashMap<>();
|
||||||
for(int ll=layers.size()-1; ll>=0; ll--) {
|
for(int ll=layers.size()-1; ll>=0; ll--) {
|
||||||
var layer = new Layer();
|
var layer = new Layer();
|
||||||
layer.isLoop = layers.get(ll).bool("repeat");
|
layer.isLoop = layers.get(ll).bool("repeat");
|
||||||
|
@ -48,73 +82,139 @@ public class Prog extends AbsLayout {
|
||||||
bdEle = new EleBorder(Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"), context);
|
bdEle = new EleBorder(Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"), context);
|
||||||
bdWidth = bdEle.img.getHeight();
|
bdWidth = bdEle.img.getHeight();
|
||||||
}
|
}
|
||||||
var ele = new Source();
|
var src = new Source();
|
||||||
int x, y, w, h;
|
|
||||||
String id;
|
|
||||||
for(var source : sources) {
|
for(var source : sources) {
|
||||||
ele.type = source.stnn("_type");
|
src.type = source.stnn("_type");
|
||||||
if(ele.type.isEmpty()) continue;
|
if(src.type.isEmpty()) continue;
|
||||||
var timeSpan = source.intg("timeSpan")*1000;
|
var timeSpan = source.intg("timeSpan")*1000;
|
||||||
if(timeSpan==0) continue;
|
if(timeSpan==0) continue;
|
||||||
x = source.intg("left")+bdWidth;
|
var geo = new AbsLayout.LayoutParams(source.intg("left")+bdWidth, source.intg("top")+bdWidth, source.intg("width")-bdWidth-bdWidth, source.intg("height")-bdWidth-bdWidth);
|
||||||
y = source.intg("top")+bdWidth;
|
boolean notAudio = ! src.type.equals("Audio");
|
||||||
w = source.intg("width")-bdWidth-bdWidth;
|
if((geo.width<=0 || geo.height<=0) && notAudio) continue;
|
||||||
h = source.intg("height")-bdWidth-bdWidth;
|
src.startTime = source.intg("playTime")*1000;
|
||||||
boolean notAudio = ! ele.type.equals("Audio");
|
if(bdStart > src.startTime) bdStart = src.startTime;
|
||||||
if((w<=0 || h<=0) && notAudio) continue;
|
src.endTime = src.startTime + timeSpan;
|
||||||
ele.startTime = source.intg("playTime")*1000;
|
if(bdEnd < src.endTime) bdEnd = src.endTime;
|
||||||
if(bdStart > ele.startTime) bdStart = ele.startTime;
|
if(layer.dur < src.endTime) layer.dur = src.endTime;
|
||||||
ele.endTime = ele.startTime + timeSpan;
|
if(notAudio) {
|
||||||
if(bdEnd < ele.endTime) bdEnd = ele.endTime;
|
if(page.sDur < src.endTime) page.sDur = src.endTime;
|
||||||
if(layer.dur < ele.endTime) layer.dur = ele.endTime;
|
} else if(page.audioDur < src.endTime) page.audioDur = src.endTime;
|
||||||
if(page.sDur < ele.endTime && notAudio) page.sDur = ele.endTime;
|
|
||||||
id = source.stnn("id");
|
src.entryDur = source.intg("entryEffectTimeSpan")*60;
|
||||||
ele.view = null;
|
if(src.entryDur > 0) {
|
||||||
if(ele.type.equals("Image")) {
|
var effect = source.str("entryEffect");
|
||||||
var isGif = source.stnn("fileExt").equalsIgnoreCase("gif");
|
if(effect == null || effect.equalsIgnoreCase("None")) src.entryDur = 0;
|
||||||
ImageView imgView = isGif ? new GifImageView(context) : new ImageView(context);
|
else if(effect.equalsIgnoreCase("Random")) src.isEntryRand = true;
|
||||||
imgView.setImageURI(ele.uri = Uri.fromFile(new File(Util.programDir + "/" + id)));
|
else {
|
||||||
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
|
effect = effect.replace("MOVING", "MOVE");
|
||||||
if(! isGif) ele.uri = null;
|
effect = effect.replace("LEFT_TOP", "TL");
|
||||||
ele.view = imgView;
|
effect = effect.replace("RIGHT_TOP", "TR");
|
||||||
} else if(ele.type.equals("MultiPng")) {
|
effect = effect.replace("RIGHT_BOTTOM", "BR");
|
||||||
JSList<JSMap> imgs = source.jslist("arrayPics");
|
effect = effect.replace("LEFT_BOTTOM", "BL");
|
||||||
if(imgs.isEmpty()) continue;
|
effect = effect.replace("ALPHA", "FADE");
|
||||||
if(imgs.size()==1 && imgs.get(0).intg("picDuration")==0) ele.view = new EleScroll(context, Util.programDir+"/", imgs.get(0), w, h);
|
effect = effect.replace("_IN", "");
|
||||||
else ele.view = new EleFlip(Util.programDir+"/", imgs, context);
|
effect = effect.replace("_OUT", "");
|
||||||
} else if(ele.type.equals("SplitText")) {
|
try {
|
||||||
JSList<JSMap> imgs = source.jslist("arrayPics");
|
src.entryEff = Effect.valueOf(effect);
|
||||||
if(imgs.isEmpty()) continue;
|
} catch (Throwable e) {
|
||||||
ele.view = new AbsLayout(context);
|
if(effect.equalsIgnoreCase("ROTATE_RIGHT")) src.entryEff = Effect.ROTATE;
|
||||||
var partHeight = _program.intg("height");
|
else if(effect.equalsIgnoreCase("ROTATE_LEFT")) src.entryEff = Effect.ROTATE_R;
|
||||||
if(imgs.size()==1 && imgs.get(0).intg("picDuration")==0) {
|
else src.entryDur = 0;
|
||||||
var view = new EleScroll(context, Util.programDir+"/", imgs.get(0), w, h);
|
|
||||||
((AbsLayout) ele.view).addView(view, new AbsLayout.LayoutParams(x, y, splitWidths.get(0).intValue(), h));
|
|
||||||
view.others = new ArrayList<>();
|
|
||||||
for(int i=1; i<splitWidths.size(); i++) {
|
|
||||||
x -= splitWidths.get(i-1);
|
|
||||||
y += partHeight;
|
|
||||||
var split = new EleOtherPart(context, view);
|
|
||||||
((AbsLayout) ele.view).addView(split, new AbsLayout.LayoutParams(x, y, splitWidths.get(i).intValue() - x, h));
|
|
||||||
view.others.add(split);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var view = new EleFlip(Util.programDir+"/", imgs, context);
|
|
||||||
((AbsLayout) ele.view).addView(view, new AbsLayout.LayoutParams(x, y, splitWidths.get(0).intValue(), h));
|
|
||||||
view.others = new ArrayList<>();
|
|
||||||
for(int i=1; i<splitWidths.size(); i++) {
|
|
||||||
x -= splitWidths.get(i-1);
|
|
||||||
y += partHeight;
|
|
||||||
var split = new EleOtherPart(context, view);
|
|
||||||
((AbsLayout) ele.view).addView(split, new AbsLayout.LayoutParams(x, y, splitWidths.get(i).intValue() - x, h));
|
|
||||||
view.others.add(split);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w = 0;
|
}
|
||||||
} else if(ele.type.equals("DigitalClockNew")) ele.view = new EleDigiClock(Util.programDir+"/", source, context);
|
src.exitDur = source.intg("exitEffectTimeSpan")*60;
|
||||||
else if(ele.type.equals("AnalogClock")) ele.view = new EleAnaClock(w, h, Util.programDir + "/" + id, source, context);
|
if(src.exitDur > 0) {
|
||||||
else if(ele.type.equals("Video") || ele.type.equals("Audio")) ele.view = new EleVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f);
|
var effect = source.str("exitEffect");
|
||||||
else if(ele.type.equals("WebURL")) {
|
if(effect == null || effect.equalsIgnoreCase("None")) src.exitDur = 0;
|
||||||
|
else if(effect.equalsIgnoreCase("Random")) src.isExitRand = true;
|
||||||
|
else {
|
||||||
|
effect = effect.replace("MOVING", "MOVE");
|
||||||
|
effect = effect.replace("LEFT_TOP", "TL");
|
||||||
|
effect = effect.replace("RIGHT_TOP", "TR");
|
||||||
|
effect = effect.replace("RIGHT_BOTTOM", "BR");
|
||||||
|
effect = effect.replace("LEFT_BOTTOM", "BL");
|
||||||
|
effect = effect.replace("ALPHA", "FADE");
|
||||||
|
effect = effect.replace("_IN", "");
|
||||||
|
effect = effect.replace("_OUT", "");
|
||||||
|
try {
|
||||||
|
src.exitEff = Effect.valueOf(effect);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if(effect.equalsIgnoreCase("ROTATE_RIGHT")) src.exitEff = Effect.ROTATE;
|
||||||
|
else if(effect.equalsIgnoreCase("ROTATE_LEFT")) src.exitEff = Effect.ROTATE_R;
|
||||||
|
else src.exitDur = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(src.exitDur!=0) src.exitStart = timeSpan*60/1000 - src.exitDur;
|
||||||
|
|
||||||
|
var id = source.stnn("id");
|
||||||
|
src.view = null;
|
||||||
|
if(src.type.equals("Image")) {
|
||||||
|
var isGif = source.stnn("fileExt").toLowerCase().endsWith("gif");
|
||||||
|
if(isGif) {
|
||||||
|
var imgView = new GifImageView(context);
|
||||||
|
imgView.setImageURI(src.uri = Uri.fromFile(new File(Util.programDir + "/" + id)));
|
||||||
|
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
|
src.view = imgView;
|
||||||
|
} else {
|
||||||
|
var imgView = new ImageView(context);
|
||||||
|
imgView.setImageURI(Uri.fromFile(new File(Util.programDir + "/" + id)));
|
||||||
|
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
|
src.view = imgView;
|
||||||
|
}
|
||||||
|
} else if(src.type.equals("MultiPng") || src.type.equals("SplitText")) {
|
||||||
|
JSList<JSMap> imgs = source.jslist("arrayPics");
|
||||||
|
if(imgs.isEmpty()) continue;
|
||||||
|
if(imgs.size()==1 && imgs.get(0).intg("picDuration")==0) src.view = new EleScroll(context, imgs.get(0));
|
||||||
|
else {
|
||||||
|
var start = src.startTime;
|
||||||
|
var ele0 = src;
|
||||||
|
for(var map : imgs) {
|
||||||
|
var picDur = map.intg("picDuration")*1000;
|
||||||
|
if(picDur==0) continue;
|
||||||
|
src.type = "Image";
|
||||||
|
src.startTime = start;
|
||||||
|
src.endTime = start = src.startTime + picDur;
|
||||||
|
if(src!=ele0) {
|
||||||
|
src.entryEff = ele0.entryEff;
|
||||||
|
src.exitEff = ele0.exitEff;
|
||||||
|
src.entryDur = ele0.entryDur;
|
||||||
|
src.exitDur = ele0.exitDur;
|
||||||
|
src.exitStart = ele0.exitStart;
|
||||||
|
src.isEntryRand = ele0.isEntryRand;
|
||||||
|
src.isExitRand = ele0.isExitRand;
|
||||||
|
}
|
||||||
|
var imgView = new ImageView(context);
|
||||||
|
imgView.setImageURI(Uri.fromFile(new File(Util.programDir + "/" + map.stnn("id"))));
|
||||||
|
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
|
src.view = imgView;
|
||||||
|
src.view.setVisibility(GONE);
|
||||||
|
src.view.setLayoutParams(geo);
|
||||||
|
box.addView(src.view);
|
||||||
|
layer.srcs.add(src);
|
||||||
|
src = new Source();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(src.type.startsWith("DigitalClock")) src.view = new EleDigiClock(context, source);
|
||||||
|
else if(src.type.equals("AnalogClock")) src.view = new EleAnaClock(geo.width, geo.height, Util.programDir + "/" + id, source, context);
|
||||||
|
else if(src.type.equals("Audio")) src.view = new EleVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f);
|
||||||
|
else if(src.type.equals("Video")) {
|
||||||
|
var key = id + src.startTime + src.endTime;
|
||||||
|
var videoView = videoMap.get(key);
|
||||||
|
if(videoView!=null) {
|
||||||
|
var geoOld = (AbsLayout.LayoutParams) videoView.getLayoutParams();
|
||||||
|
if(geo.width*geo.height > geoOld.width*geoOld.height) {
|
||||||
|
videoView.setLayoutParams(geo);
|
||||||
|
geo = geoOld;
|
||||||
|
}
|
||||||
|
src.view = new SrcCopy(context, videoView);
|
||||||
|
((SrcCopy) src.view).scaleX = 0;
|
||||||
|
} else {
|
||||||
|
src.view = new EleVideo(context, Util.programDir+"/"+id, source.intg("vol", 100) / 100.0f);
|
||||||
|
videoMap.put(key, (EleVideo) src.view);
|
||||||
|
}
|
||||||
|
} else if(src.type.equals("WebURL")) {
|
||||||
var webView = new WebView(context);
|
var webView = new WebView(context);
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,46 +223,46 @@ public class Prog extends AbsLayout {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
webView.loadUrl(source.stnn("url"));
|
webView.loadUrl(source.stnn("url"));
|
||||||
ele.view = webView;
|
src.view = webView;
|
||||||
}
|
}
|
||||||
else if(ele.type.equals("Timer")) ele.view = new EleTimer(Util.programDir+"/", source, context);
|
else if(src.type.equals("Timer")) src.view = new SrcTimer(context, source);
|
||||||
else if(ele.type.equals("EnvironmentalMonitoring")) ele.view = new EleEnviron(Util.programDir+"/", source, context);
|
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 continue;
|
else continue;
|
||||||
if(ele.view==null) continue;
|
if(src.view==null) continue;
|
||||||
if(w > 0) ele.view.setLayoutParams(new AbsLayout.LayoutParams(x, y, w, h));
|
src.view.setVisibility(GONE);
|
||||||
ele.view.setVisibility(GONE);
|
src.view.setLayoutParams(geo);
|
||||||
addView(ele.view);
|
box.addView(src.view);
|
||||||
layer.eles.add(ele);
|
layer.srcs.add(src);
|
||||||
ele = new Source();
|
src = new Source();
|
||||||
}
|
}
|
||||||
if(bdEle!=null && ! sources.isEmpty()) {
|
if(bdEle!=null && ! sources.isEmpty()) {
|
||||||
JSList<Long> geometry = border.jslist("geometry");
|
JSList<Long> geometry = border.jslist("geometry");
|
||||||
x = geometry.get(0).intValue();
|
src.startTime = bdStart;
|
||||||
y = geometry.get(1).intValue();
|
src.endTime = bdEnd;
|
||||||
w = geometry.get(2).intValue();
|
src.view = bdEle;
|
||||||
h = geometry.get(3).intValue();
|
src.view.setVisibility(GONE);
|
||||||
ele.startTime = bdStart;
|
box.addView(src.view, new AbsLayout.LayoutParams(geometry.get(0).intValue(), geometry.get(1).intValue(), geometry.get(2).intValue(), geometry.get(3).intValue()));
|
||||||
ele.endTime = bdEnd;
|
layer.srcs.add(src);
|
||||||
ele.view = bdEle;
|
|
||||||
ele.view.setVisibility(GONE);
|
|
||||||
addView(ele.view, new AbsLayout.LayoutParams(x, y, w, h));
|
|
||||||
layer.eles.add(ele);
|
|
||||||
}
|
}
|
||||||
if(! layer.eles.isEmpty()) page.layers.add(layer);
|
if(! layer.srcs.isEmpty()) page.layers.add(layer);
|
||||||
|
}
|
||||||
|
if(page.sDur==0) {
|
||||||
|
if(page.audioDur > 0) page.sDur = page.audioDur;
|
||||||
|
else continue;
|
||||||
}
|
}
|
||||||
if(page.sDur==0) continue;
|
|
||||||
page.tDur = page.sDur * page.repeatTimes;
|
page.tDur = page.sDur * page.repeatTimes;
|
||||||
for_layer: for(int ll=0; ll<page.layers.size(); ll++) {
|
for_layer: for(int ll=0; ll<page.layers.size(); ll++) {
|
||||||
var layer = page.layers.get(ll);
|
var layer = page.layers.get(ll);
|
||||||
for(int ee=0; ee<layer.eles.size(); ee++) {
|
for(int ss=0; ss<layer.srcs.size(); ss++) {
|
||||||
var ele = layer.eles.get(ee);
|
var src = layer.srcs.get(ss);
|
||||||
if(ele.startTime >= page.sDur) {
|
if(src.startTime >= page.sDur) {
|
||||||
if(layer.eles.size() > 1) layer.eles.remove(ee--);
|
if(layer.srcs.size() > 1) layer.srcs.remove(ss--);
|
||||||
else {
|
else {
|
||||||
page.layers.remove(ll--);
|
page.layers.remove(ll--);
|
||||||
continue for_layer;
|
continue for_layer;
|
||||||
}
|
}
|
||||||
} else if(ele.endTime > page.sDur) ele.endTime = page.sDur;
|
} else if(src.endTime > page.sDur) src.endTime = page.sDur;
|
||||||
}
|
}
|
||||||
if(layer.dur > page.sDur) layer.dur = page.sDur;
|
if(layer.dur > page.sDur) layer.dur = page.sDur;
|
||||||
if(layer.dur == page.sDur) layer.isLoop = false;
|
if(layer.dur == page.sDur) layer.isLoop = false;
|
||||||
|
@ -177,61 +277,208 @@ public class Prog extends AbsLayout {
|
||||||
View view;
|
View view;
|
||||||
for(int cc=0; cc<getChildCount(); cc++) if((view = getChildAt(cc)) instanceof EleVideo) ((EleVideo) view).release();
|
for(int cc=0; cc<getChildCount(); cc++) if((view = getChildAt(cc)) instanceof EleVideo) ((EleVideo) view).release();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Source {
|
public static class Source {
|
||||||
View view;
|
View view;
|
||||||
long startMilli;
|
long startMilli, endMilli = Long.MAX_VALUE;
|
||||||
long endMilli = Long.MAX_VALUE;
|
int startTime, entryDur, exitStart = Integer.MAX_VALUE, exitDur, endTime, ff;
|
||||||
int startTime;
|
Effect entryEff, exitEff;
|
||||||
int endTime;
|
|
||||||
String type;
|
String type;
|
||||||
Uri uri;
|
Uri uri;
|
||||||
|
boolean isEntryRand, isExitRand;
|
||||||
|
|
||||||
void show() {
|
void show() {
|
||||||
if(view.getVisibility()==VISIBLE) return;
|
if(view.getVisibility()==VISIBLE) return;
|
||||||
view.setVisibility(VISIBLE);
|
view.setVisibility(VISIBLE);
|
||||||
|
ff = 0;
|
||||||
|
if(isEntryRand) entryEff = Effect.values()[Util.rand.nextInt(Effect.values().length)];
|
||||||
|
if(isExitRand) exitEff = Effect.values()[Util.rand.nextInt(Effect.values().length)];
|
||||||
|
resetEff();
|
||||||
|
doEff();
|
||||||
}
|
}
|
||||||
void hide() {
|
void hide() {
|
||||||
if(view.getVisibility()!=VISIBLE) return;
|
if(view.getVisibility()!=VISIBLE) return;
|
||||||
view.setVisibility(GONE);
|
view.setVisibility(GONE);
|
||||||
if(uri!=null) ((GifImageView) view).setImageURI(uri);
|
if(uri!=null) ((GifImageView) view).setImageURI(uri);
|
||||||
}
|
}
|
||||||
|
void doEff() {
|
||||||
|
var w = view.getLayoutParams().width;
|
||||||
|
var h = view.getLayoutParams().height;
|
||||||
|
if(ff < entryDur) {
|
||||||
|
if(entryEff == Effect.EXPAND_HOR) view.setScaleX(ff / (float) entryDur);
|
||||||
|
else if(entryEff == Effect.EXPAND_VER) view.setScaleY(ff / (float) entryDur);
|
||||||
|
else if(entryEff == Effect.EXPAND_LEFT) {
|
||||||
|
view.setScaleX(ff / (float) entryDur);
|
||||||
|
view.setTranslationX((1 - view.getScaleX()) * w / 2);
|
||||||
|
} else if(entryEff == Effect.EXPAND_TOP) {
|
||||||
|
view.setScaleY(ff / (float) entryDur);
|
||||||
|
view.setTranslationY((1 - view.getScaleY()) * h / 2);
|
||||||
|
} else if(entryEff == Effect.EXPAND_RIGHT) {
|
||||||
|
view.setScaleX(ff / (float) entryDur);
|
||||||
|
view.setTranslationX((view.getScaleX() - 1) * w / 2);
|
||||||
|
} else if(entryEff == Effect.EXPAND_BOTTOM) {
|
||||||
|
view.setScaleY(ff / (float) entryDur);
|
||||||
|
view.setTranslationY((view.getScaleY() - 1) * h / 2);
|
||||||
|
}
|
||||||
|
else if(entryEff == Effect.MOVE_LEFT) view.setTranslationX(w - ff*w/(float) entryDur);
|
||||||
|
else if(entryEff == Effect.MOVE_TOP) view.setTranslationY(h - ff*h/(float) entryDur);
|
||||||
|
else if(entryEff == Effect.MOVE_RIGHT) view.setTranslationX(ff*w/(float) entryDur - w);
|
||||||
|
else if(entryEff == Effect.MOVE_BOTTOM) view.setTranslationY(ff*h/(float) entryDur - h);
|
||||||
|
else if(entryEff == Effect.FADE) view.setAlpha(ff / (float) entryDur);
|
||||||
|
else if(entryEff == Effect.ZOOM) {
|
||||||
|
view.setScaleX(ff / (float) entryDur);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
} else if(entryEff == Effect.ZOOM_TL) {
|
||||||
|
var rate = ff / (float) entryDur;
|
||||||
|
view.setTranslationX((rate - 1) * w / 2);
|
||||||
|
view.setTranslationY((rate - 1) * h / 2);
|
||||||
|
view.setScaleX(rate);
|
||||||
|
view.setScaleY(rate);
|
||||||
|
} else if(entryEff == Effect.ZOOM_BR) {
|
||||||
|
var rate = ff / (float) entryDur;
|
||||||
|
view.setTranslationX((1 - rate) * w / 2);
|
||||||
|
view.setTranslationY((1 - rate) * h / 2);
|
||||||
|
view.setScaleX(rate);
|
||||||
|
view.setScaleY(rate);
|
||||||
|
} else if(entryEff == Effect.ZOOM_TR) {
|
||||||
|
var rate = ff / (float) entryDur;
|
||||||
|
view.setTranslationX((1 - rate) * w / 2);
|
||||||
|
view.setTranslationY((rate - 1) * h / 2);
|
||||||
|
view.setScaleX(rate);
|
||||||
|
view.setScaleY(rate);
|
||||||
|
} else if(entryEff == Effect.ZOOM_BL) {
|
||||||
|
var rate = ff / (float) entryDur;
|
||||||
|
view.setTranslationX((rate - 1) * w / 2);
|
||||||
|
view.setTranslationY((1 - rate) * h / 2);
|
||||||
|
view.setScaleX(rate);
|
||||||
|
view.setScaleY(rate);
|
||||||
|
} else if(entryEff == Effect.ROTATE) {
|
||||||
|
view.setScaleX(ff / (float) entryDur);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
view.setRotation(view.getScaleX() * 360);
|
||||||
|
} else if(entryEff == Effect.ROTATE_R) {
|
||||||
|
view.setScaleX(ff / (float) entryDur);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
view.setRotation(- view.getScaleX() * 360);
|
||||||
|
}
|
||||||
|
} else if(ff>=exitStart) {
|
||||||
|
var fff = ff - exitStart;
|
||||||
|
if(fff > exitDur) fff = exitDur;
|
||||||
|
if(exitEff == Effect.EXPAND_HOR) view.setScaleX(1 - fff / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.EXPAND_VER) view.setScaleY(1 - fff / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.EXPAND_LEFT) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setTranslationX(rate * w / 2);
|
||||||
|
} else if(exitEff == Effect.EXPAND_TOP) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
view.setTranslationY(rate * h / 2);
|
||||||
|
} else if(exitEff == Effect.EXPAND_RIGHT) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setTranslationX(- rate * w / 2);
|
||||||
|
} else if(exitEff == Effect.EXPAND_BOTTOM) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
view.setTranslationY(- rate * h / 2);
|
||||||
|
}
|
||||||
|
else if(exitEff == Effect.MOVE_LEFT) view.setTranslationX(- fff*w / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.MOVE_RIGHT) view.setTranslationX(fff*w / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.MOVE_TOP) view.setTranslationY(- fff*h / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.MOVE_BOTTOM) view.setTranslationY(fff*h / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.FADE) view.setAlpha(1 - fff / (float) exitDur);
|
||||||
|
else if(exitEff == Effect.ZOOM) {
|
||||||
|
view.setScaleX(1 - fff / (float) exitDur);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
} else if(exitEff == Effect.ZOOM_TL) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setTranslationX(- rate * w / 2);
|
||||||
|
view.setTranslationY(- rate * h / 2);
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
} else if(exitEff == Effect.ZOOM_BR) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setTranslationX(rate * w / 2);
|
||||||
|
view.setTranslationY(rate * h / 2);
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
} else if(exitEff == Effect.ZOOM_TR) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setTranslationX(rate * w / 2);
|
||||||
|
view.setTranslationY(- rate * h / 2);
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
} else if(exitEff == Effect.ZOOM_BL) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setTranslationX(- rate * w / 2);
|
||||||
|
view.setTranslationY(rate * h / 2);
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(1 - rate);
|
||||||
|
} else if(exitEff == Effect.ROTATE) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
view.setRotation(rate * 360);
|
||||||
|
} else if(exitEff == Effect.ROTATE_R) {
|
||||||
|
var rate = fff / (float) exitDur;
|
||||||
|
view.setScaleX(1 - rate);
|
||||||
|
view.setScaleY(view.getScaleX());
|
||||||
|
view.setRotation(- rate * 360);
|
||||||
|
}
|
||||||
|
} else resetEff();
|
||||||
|
ff++;
|
||||||
|
}
|
||||||
|
void resetEff() {
|
||||||
|
view.setTranslationX(0);
|
||||||
|
view.setTranslationY(0);
|
||||||
|
view.setAlpha(1);
|
||||||
|
view.setScaleX(1);
|
||||||
|
view.setScaleY(1);
|
||||||
|
view.setRotation(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static class Layer {
|
public static class Layer {
|
||||||
ArrayList<Source> eles = new ArrayList<>();
|
ArrayList<Source> srcs = new ArrayList<>();
|
||||||
long endMilli = Long.MAX_VALUE;
|
long endMilli = Long.MAX_VALUE;
|
||||||
int dur;
|
int dur;
|
||||||
boolean isLoop;
|
boolean isLoop;
|
||||||
}
|
}
|
||||||
|
public enum Effect {
|
||||||
|
EXPAND_HOR, EXPAND_VER, EXPAND_LEFT, EXPAND_TOP, EXPAND_RIGHT, EXPAND_BOTTOM,
|
||||||
|
ZOOM, ZOOM_TL, ZOOM_TR, ZOOM_BR, ZOOM_BL,
|
||||||
|
ROTATE, ROTATE_R,
|
||||||
|
FADE,
|
||||||
|
MOVE_LEFT, MOVE_TOP, MOVE_RIGHT, MOVE_BOTTOM,
|
||||||
|
}
|
||||||
public static class Sche {
|
public static class Sche {
|
||||||
long startDate = -1, endDate = -1;
|
long startDate = -1, endDate = -1;
|
||||||
int startTime = -1, endTime = -1;
|
int startTime = -1, endTime = -1;
|
||||||
JSList<Integer> weeks;
|
JSList<Long> weeks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Page {
|
public static class Page {
|
||||||
ArrayList<Layer> layers = new ArrayList<>();
|
ArrayList<Layer> layers = new ArrayList<>();
|
||||||
ArrayList<Sche> sches;
|
ArrayList<Sche> sches;
|
||||||
long endMilli = Long.MAX_VALUE;
|
long endMilli = Long.MAX_VALUE;
|
||||||
int sDur, tDur, repeatTimes;
|
int sDur, tDur, repeatTimes, audioDur;
|
||||||
|
|
||||||
void hide() {
|
void hide() {
|
||||||
for(var layer : layers) for(var ele : layer.eles) ele.hide();
|
for(var layer : layers) for(var src : layer.srcs) src.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMillis(long milli) {
|
public void setMillis(long milli) {
|
||||||
endMilli = milli + sDur;
|
endMilli = milli + sDur;
|
||||||
for(var layer : layers) {
|
for(var layer : layers) {
|
||||||
if(layer.isLoop) layer.endMilli = milli + layer.dur;
|
if(layer.isLoop) layer.endMilli = milli + layer.dur;
|
||||||
for(var ele : layer.eles) {
|
for(var src : layer.srcs) {
|
||||||
ele.endMilli = milli + ele.endTime;
|
src.endMilli = milli + src.endTime;
|
||||||
ele.startMilli = milli + ele.startTime;
|
src.startMilli = milli + src.startTime;
|
||||||
if(ele.startTime == 0) ele.show();
|
if(src.startTime == 0) src.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,12 +486,12 @@ public class Prog extends AbsLayout {
|
||||||
if(sches==null) return true;
|
if(sches==null) return true;
|
||||||
var local = milli + Dates.zoneOff;
|
var local = milli + Dates.zoneOff;
|
||||||
var time = local % 86400000L;
|
var time = local % 86400000L;
|
||||||
var week = -1;
|
long week = -1;
|
||||||
for(var sche : sches) {
|
for(var sche : sches) {
|
||||||
if(notInRange(sche.startDate, local, sche.endDate)) continue;
|
if(notInRange(sche.startDate, local, sche.endDate)) continue;
|
||||||
if(notInRange(sche.startTime, time, sche.endTime)) continue;
|
if(notInRange(sche.startTime, time, sche.endTime)) continue;
|
||||||
if(sche.weeks==null) return true;
|
if(sche.weeks==null) return true;
|
||||||
if(week==-1) week = LocalDate.ofEpochDay(local / 86400000L).getDayOfWeek().getValue();
|
if(week==-1) week = (local / 86400000L + 3) % 7 + 1;
|
||||||
if(sche.weeks.contains(week)) return true;
|
if(sche.weeks.contains(week)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -253,21 +500,48 @@ public class Prog extends AbsLayout {
|
||||||
if(end==-1) return false;
|
if(end==-1) return false;
|
||||||
return start <= end ? !(val >= start && val < end) : val >= end && val < start;
|
return start <= end ? !(val >= start && val < end) : val >= end && val < start;
|
||||||
}
|
}
|
||||||
|
SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
SimpleDateFormat timeFmt = new SimpleDateFormat("HH:mm:ss");
|
||||||
public void parse(JSList<JSMap> schedules) {
|
public void parse(JSList<JSMap> schedules) {
|
||||||
if(schedules!=null) for(var schedule : schedules) {
|
if(schedules!=null) for(var schedule : schedules) {
|
||||||
var sche = new Sche();
|
var sche = new Sche();
|
||||||
var startTime = schedule.str("startTime");
|
var startTime = schedule.str("startTime");
|
||||||
if(startTime!=null) sche.startTime = LocalTime.parse(startTime).toSecondOfDay()*1000;
|
if(startTime!=null) {
|
||||||
|
if(startTime.length()==5) startTime += ":00";
|
||||||
|
try {
|
||||||
|
sche.startTime = (int)timeFmt.parse(startTime).getTime()+Dates.zoneOff;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
var endTime = schedule.str("endTime");
|
var endTime = schedule.str("endTime");
|
||||||
if(endTime!=null) sche.endTime = LocalTime.parse(endTime).toSecondOfDay()*1000;
|
if(endTime!=null) {
|
||||||
|
if(endTime.length()==5) endTime += ":00";
|
||||||
|
try {
|
||||||
|
sche.endTime = (int)timeFmt.parse(endTime).getTime()+Dates.zoneOff;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(sche.startTime==sche.endTime) sche.startTime = sche.endTime = -1;
|
if(sche.startTime==sche.endTime) sche.startTime = sche.endTime = -1;
|
||||||
var startDate = schedule.str("startDate");
|
var startDate = schedule.str("startDate");
|
||||||
if(startDate!=null) sche.startDate = LocalDate.parse(startDate).toEpochDay() * 86400000L;
|
if(startDate!=null) {
|
||||||
|
try {
|
||||||
|
sche.startDate = dateFmt.parse(startDate).getTime() + Dates.zoneOff;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
var endDate = schedule.str("endDate");
|
var endDate = schedule.str("endDate");
|
||||||
if(endDate!=null) sche.endDate = (LocalDate.parse(endDate).toEpochDay() + 1) * 86400000L;
|
if(endDate!=null) {
|
||||||
|
try {
|
||||||
|
sche.endDate = dateFmt.parse(endDate).getTime() + Dates.zoneOff + 86400000L;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(sche.startDate==sche.endDate) sche.startDate = sche.endDate = -1;
|
if(sche.startDate==sche.endDate) sche.startDate = sche.endDate = -1;
|
||||||
JSList<Integer> weekFilter = schedule.jslist("weekFilter");
|
JSList<Long> weekFilter = schedule.jslist("weekFilter");
|
||||||
if(weekFilter!=null && ! weekFilter.isEmpty() && weekFilter.size() < 7) sche.weeks = weekFilter;
|
if(weekFilter!=null && ! weekFilter.isEmpty() && weekFilter.size() < 7) sche.weeks = weekFilter;
|
||||||
if(sches==null) sches = new ArrayList<>();
|
if(sches==null) sches = new ArrayList<>();
|
||||||
sches.add(sche);
|
sches.add(sche);
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class RestartService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
System.out.println("---- RestartService onCreate");
|
Util.println("---- RestartService onCreate");
|
||||||
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);
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
|
@ -13,10 +12,14 @@ import com.xixun.util.PlayerInfo;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import gnph.util.IOs;
|
import gnph.util.IOs;
|
||||||
|
import gnph.util.JSList;
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
import gnph.util.URLConn;
|
import gnph.util.URLConn;
|
||||||
|
|
||||||
|
@ -30,6 +33,7 @@ public class Server extends Service {
|
||||||
PlayerInfo.Stub binder = new PlayerInfo.Stub() {
|
PlayerInfo.Stub binder = new PlayerInfo.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public String getProgramName() throws RemoteException {
|
public String getProgramName() throws RemoteException {
|
||||||
|
Util.println("Server getProgramName ...");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +84,7 @@ public class Server extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurProgramId() throws RemoteException {
|
public String getCurProgramId() throws RemoteException {
|
||||||
|
Util.println("Server getCurProgramId ...");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,19 +96,126 @@ public class Server extends Service {
|
||||||
@SuppressLint("ResourceType")
|
@SuppressLint("ResourceType")
|
||||||
@Override
|
@Override
|
||||||
public String executeJosnCommand(String jsonstr) throws RemoteException {
|
public String executeJosnCommand(String jsonstr) throws RemoteException {
|
||||||
System.out.println("Server executeJsonCommand ..."+jsonstr);//{"_type":"DeleteTask","id":"652522a0e81d1e000009201a","sendTo":"yzd-player"}
|
Util.println("Server executeJsonCommand ..."+jsonstr);//{"_type":"DeleteTask","id":"652522a0e81d1e000009201a","sendTo":"yzd-player"}
|
||||||
String id = null;
|
String commandId = null;
|
||||||
try {
|
try {
|
||||||
var json = JSMap.from(jsonstr.getBytes(StandardCharsets.UTF_8));
|
var jsonBytes = jsonstr.getBytes(StandardCharsets.UTF_8);
|
||||||
|
var json = JSMap.from(jsonBytes);
|
||||||
var _type = json.stnn("_type");
|
var _type = json.stnn("_type");
|
||||||
id = json.stnn("id");
|
commandId = json.stnn("id");
|
||||||
if(_type.equals("PlayXixunTask")) {
|
boolean is2 = false;
|
||||||
MainActivity.ins.runOnUiThread(() -> MainActivity.ins.delProgFile());
|
if(_type.equals("PlayXixunTask") || (is2 = _type.equals("PlayProgramTask"))) {
|
||||||
|
var preDownloadURL = json.str("preDownloadURL");
|
||||||
|
if(preDownloadURL==null && is2) preDownloadURL = "https://m2mled.net/file/download?id=";
|
||||||
|
var task = json.jsmap("task");
|
||||||
|
JSList<JSMap> jpages = task.jslist("items");
|
||||||
|
int proSize = 0;
|
||||||
|
var needDowns = new ArrayList<NeedDowns>();
|
||||||
|
var hases = new HashSet<String>();
|
||||||
|
for(var pageMap : jpages) {
|
||||||
|
var _program = pageMap.jsmap("_program");
|
||||||
|
if(_program==null) continue;
|
||||||
|
proSize += _program.intg("totalSize");
|
||||||
|
var needDown = new NeedDowns();
|
||||||
|
needDown.prog = pageMap.stnn("_id");
|
||||||
|
needDowns.add(needDown);
|
||||||
|
JSList<JSMap> layers = _program.jslist("layers");
|
||||||
|
if(layers==null || layers.isEmpty()) continue;
|
||||||
|
for(int ll=layers.size()-1; ll>=0; ll--) {
|
||||||
|
var layer = new Prog.Layer();
|
||||||
|
JSList<JSMap> sources = layers.get(ll).jslist("sources");
|
||||||
|
// var border = layers.get(ll).jsmap("border");
|
||||||
|
// if(border!=null) {
|
||||||
|
// }
|
||||||
|
for(var source : sources) {
|
||||||
|
var type = source.stnn("_type");
|
||||||
|
if(type.equals("Video") || type.equals("Audio") || type.equals("Image") || type.startsWith("DigitalClock") || type.equals("Timer") || type.startsWith("Environ")) {
|
||||||
|
var filename = source.str("id");
|
||||||
|
if(filename==null) continue;
|
||||||
|
var url = source.stnn("url");
|
||||||
|
if(! url.startsWith("http")) {
|
||||||
|
if(preDownloadURL==null) continue;
|
||||||
|
url = preDownloadURL + filename;
|
||||||
|
}
|
||||||
|
var file = new File(Util.programDir+"/"+filename);
|
||||||
|
if(file.exists() && file.length() > 0) {
|
||||||
|
proSize -= file.length();
|
||||||
|
hases.add(filename);
|
||||||
|
} else needDown.srcs.add(new Src(filename, url));
|
||||||
|
} else if(type.equals("MultiPng") || type.equals("SplitText")) {
|
||||||
|
JSList<JSMap> imgs = source.jslist("arrayPics");
|
||||||
|
if(imgs.isEmpty()) continue;
|
||||||
|
for(var img : imgs) {
|
||||||
|
var filename = img.str("id");
|
||||||
|
if(filename==null) continue;
|
||||||
|
var url = img.stnn("url");
|
||||||
|
if(! url.startsWith("http")) {
|
||||||
|
if(preDownloadURL==null) continue;
|
||||||
|
url = preDownloadURL + filename;
|
||||||
|
}
|
||||||
|
var file = new File(Util.programDir+"/"+filename);
|
||||||
|
if(file.exists() && file.length() > 0) {
|
||||||
|
proSize -= file.length();
|
||||||
|
hases.add(filename);
|
||||||
|
} else needDown.srcs.add(new Src(filename, url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int finalProSize = proSize;
|
||||||
|
String finalCommandId = commandId;
|
||||||
|
var notificationURL = json.str("notificationURL");
|
||||||
|
new Thread(()->{
|
||||||
|
Util.deleteFiles(finalProSize, hases);
|
||||||
|
for(var needDown : needDowns) {
|
||||||
|
int cnt = 0;
|
||||||
|
for(var src : needDown.srcs) {
|
||||||
|
try {
|
||||||
|
var in = new URLConn(src.url).in();
|
||||||
|
var fout = new FileOutputStream(Util.programDir+"/"+src.filename);
|
||||||
|
IOs.writeCloseIn(fout, in);
|
||||||
|
fout.flush();
|
||||||
|
fout.getFD().sync();
|
||||||
|
fout.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
cnt++;
|
||||||
|
if(notificationURL!=null && cnt!=needDown.srcs.size()) {
|
||||||
|
try {
|
||||||
|
new URLConn(notificationURL).timeout(5000).writeJson(new JSMap(
|
||||||
|
"commandId", finalCommandId,
|
||||||
|
"taskItemId", needDown.prog,
|
||||||
|
"progress", cnt*100/needDown.srcs.size()).toStr()).read();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(notificationURL!=null) {
|
||||||
|
try {
|
||||||
|
new URLConn(notificationURL).timeout(5000).writeJson(new JSMap(
|
||||||
|
"commandId", finalCommandId,
|
||||||
|
"taskItemId", needDown.prog,
|
||||||
|
"progress", 100).toStr()).read();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
IOs.writeClose(new FileOutputStream(Util.programDir+"/program"), jsonBytes);
|
||||||
|
MainActivity.ins.runOnUiThread(MainActivity.ins::initProg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
return new JSMap(
|
return new JSMap(
|
||||||
"_type", "DataCallback",
|
"_type", "Success",
|
||||||
"result", "received command",
|
"result", "received command",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id
|
"commandId", commandId
|
||||||
).toString();
|
).toString();
|
||||||
} else if(_type.equals("DeleteTask")) {
|
} else if(_type.equals("DeleteTask")) {
|
||||||
MainActivity.ins.runOnUiThread(() -> MainActivity.ins.delProgFile());
|
MainActivity.ins.runOnUiThread(() -> MainActivity.ins.delProgFile());
|
||||||
|
@ -111,14 +223,14 @@ public class Server extends Service {
|
||||||
"_type", "DataCallback",
|
"_type", "DataCallback",
|
||||||
"result", "received command",
|
"result", "received command",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id
|
"commandId", commandId
|
||||||
).toString();
|
).toString();
|
||||||
} else if(_type.equals("PlayerStateCommand")) {
|
} else if(_type.equals("PlayerStateCommand")) {
|
||||||
var descs = Util.getState(MainActivity.ins.state);
|
var descs = Util.getState(MainActivity.ins.state);
|
||||||
return new JSMap(
|
return new JSMap(
|
||||||
"_type", "Success",
|
"_type", "Success",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id,
|
"commandId", commandId,
|
||||||
"code", MainActivity.ins.state,
|
"code", MainActivity.ins.state,
|
||||||
"des_en", descs[0],
|
"des_en", descs[0],
|
||||||
"des", descs[1]
|
"des", descs[1]
|
||||||
|
@ -134,7 +246,7 @@ public class Server extends Service {
|
||||||
return new JSMap(
|
return new JSMap(
|
||||||
"_type", "Success",
|
"_type", "Success",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id
|
"commandId", commandId
|
||||||
).toString();
|
).toString();
|
||||||
} else if(_type.equals("GetPlayerBackground")) {
|
} else if(_type.equals("GetPlayerBackground")) {
|
||||||
var backImg = new File(Util.backImgFile);
|
var backImg = new File(Util.backImgFile);
|
||||||
|
@ -142,7 +254,7 @@ public class Server extends Service {
|
||||||
return new JSMap(
|
return new JSMap(
|
||||||
"_type", "DataCallback",
|
"_type", "DataCallback",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id,
|
"commandId", commandId,
|
||||||
"img", img
|
"img", img
|
||||||
).toString();
|
).toString();
|
||||||
}
|
}
|
||||||
|
@ -150,15 +262,15 @@ public class Server extends Service {
|
||||||
"_type", "Error",
|
"_type", "Error",
|
||||||
"errorMessage", "Unknow Type",
|
"errorMessage", "Unknow Type",
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id
|
"commandId", commandId
|
||||||
).toString();
|
).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Util.printStackTrace(e);
|
||||||
return new JSMap(
|
return new JSMap(
|
||||||
"_type", "Error",
|
"_type", "Error",
|
||||||
"errorMessage", e.toString(),
|
"errorMessage", e.toString(),
|
||||||
"cardId", Util.getCardId(),
|
"cardId", Util.getCardId(),
|
||||||
"commandId", id
|
"commandId", commandId
|
||||||
).toString();
|
).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,4 +321,18 @@ public class Server extends Service {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static class Src {
|
||||||
|
String filename;
|
||||||
|
String url;
|
||||||
|
|
||||||
|
public Src(String filename, String url) {
|
||||||
|
this.filename = filename;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static class NeedDowns {
|
||||||
|
String prog;
|
||||||
|
ArrayList<Src> srcs = new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.view.Choreographer;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
public class SrcCopy extends View {
|
||||||
|
|
||||||
|
View view;
|
||||||
|
float scaleX = 1, scaleY = 1;
|
||||||
|
|
||||||
|
public SrcCopy(Context context, View view) {
|
||||||
|
super(context);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(@NonNull Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
if(view==null) return;
|
||||||
|
if(scaleX==0) {
|
||||||
|
if(view.getWidth()!=0&&getWidth()!=0) {
|
||||||
|
scaleX = getWidth() / (float) view.getWidth();
|
||||||
|
scaleY = getHeight() / (float) view.getHeight();
|
||||||
|
} else {
|
||||||
|
invalidate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(scaleX!=1 || scaleY!=1) canvas.scale(scaleX, scaleY);
|
||||||
|
view.draw(canvas);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.view.Choreographer;
|
||||||
|
import android.view.View;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import gnph.util.Dates;
|
||||||
|
import gnph.util.JSMap;
|
||||||
|
import gnph.util.NumFmts;
|
||||||
|
|
||||||
|
public class SrcCountdown extends WebView implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
|
long targetTime;
|
||||||
|
String html;
|
||||||
|
boolean hasDay, hasHour, hasMin, hasSec;
|
||||||
|
|
||||||
|
public SrcCountdown(Context context, JSMap json) {
|
||||||
|
super(context);
|
||||||
|
try {
|
||||||
|
html = json.stnn("html");
|
||||||
|
targetTime = Dates.milli(json.stnn("time")) / 1000;
|
||||||
|
hasDay = html.contains("%d");
|
||||||
|
hasHour = html.contains("%h");
|
||||||
|
hasMin = html.contains("%m");
|
||||||
|
hasSec = html.contains("%s");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.printStackTrace(e);
|
||||||
|
Util.makeText(context, Util.toStr(e)).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cal() {
|
||||||
|
var cur = System.currentTimeMillis() / 1000;
|
||||||
|
var secs = targetTime - cur;
|
||||||
|
if(secs < 0) secs = 0;
|
||||||
|
var htm = html;
|
||||||
|
if(hasDay) {
|
||||||
|
var str = Long.toString(secs/86400);
|
||||||
|
secs %= 86400;
|
||||||
|
htm = htm.replace("%d", str);
|
||||||
|
}
|
||||||
|
if(hasHour) {
|
||||||
|
var str = NumFmts.zz().format(secs/3600);
|
||||||
|
secs %= 3600;
|
||||||
|
htm = htm.replace("%h", str);
|
||||||
|
}
|
||||||
|
if(hasMin) {
|
||||||
|
var str = NumFmts.zz().format(secs/60);
|
||||||
|
secs %= 60;
|
||||||
|
htm = htm.replace("%m", str);
|
||||||
|
}
|
||||||
|
if(hasSec) {
|
||||||
|
var str = NumFmts.zz().format(secs);
|
||||||
|
htm = htm.replace("%s", str);
|
||||||
|
}
|
||||||
|
loadData(htm, "text/html", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
|
||||||
|
super.onVisibilityChanged(changedView, visibility);
|
||||||
|
if(visibility==View.VISIBLE) {
|
||||||
|
if(lastSec==0) {
|
||||||
|
cal();
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
lastSec = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
|
long lastSec;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFrame(long frameTimeNanos) {
|
||||||
|
if(! isShown()) {
|
||||||
|
lastSec = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var sec = System.currentTimeMillis() / 1000;
|
||||||
|
if(sec != lastSec) {
|
||||||
|
lastSec = sec;
|
||||||
|
cal();
|
||||||
|
}
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.view.Choreographer;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import gnph.util.JSList;
|
||||||
|
import gnph.util.JSMap;
|
||||||
|
|
||||||
|
public class SrcImage extends View implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
|
static final char effTypes[] = {'l', 't', 'r', 'b'};
|
||||||
|
Bitmap img;
|
||||||
|
Rect RECT = new Rect();
|
||||||
|
RectF rect;
|
||||||
|
Paint paint = new Paint();
|
||||||
|
int entryDur, exitStart;
|
||||||
|
char entryType, exitType;
|
||||||
|
boolean isEntryRand, isExitRand;
|
||||||
|
|
||||||
|
public SrcImage(Context context, JSMap map, int w, int h) {
|
||||||
|
super(context);
|
||||||
|
RECT.right = w;
|
||||||
|
RECT.bottom = h;
|
||||||
|
img = BitmapFactory.decodeFile(Util.programDir+"/"+map.stnn("id"));
|
||||||
|
if(img==null) return;
|
||||||
|
rect = new RectF(0, 0, w, h);
|
||||||
|
// entryDur = map.intg("entryEffectTimeSpan")*60;
|
||||||
|
// if(entryDur > 0) {
|
||||||
|
// var effStr = map.str("entryEffect");
|
||||||
|
// if(effStr == null || effStr.equalsIgnoreCase("None")) entryDur = 0;
|
||||||
|
// else if(effStr.equalsIgnoreCase("moving_left")) entryType = 'l';
|
||||||
|
// else if(effStr.equalsIgnoreCase("moving_top")) entryType = 't';
|
||||||
|
// else if(effStr.equalsIgnoreCase("moving_right")) entryType = 'r';
|
||||||
|
// else if(effStr.equalsIgnoreCase("moving_bottom")) entryType = 'b';
|
||||||
|
// else if(effStr.equalsIgnoreCase("alpha_in")) entryType = 'a';
|
||||||
|
// else if(effStr.equalsIgnoreCase("zoom_in")) entryType = 'z';
|
||||||
|
// else if(effStr.equalsIgnoreCase("Random")) isEntryRand = true;
|
||||||
|
// else entryDur = 0;
|
||||||
|
// }
|
||||||
|
// var exitDur = map.intg("exitEffectTimeSpan")*60;
|
||||||
|
// if(exitDur > 0) {
|
||||||
|
// var effStrExit = map.str("exitEffect");
|
||||||
|
// if(effStrExit == null || effStrExit.equalsIgnoreCase("None")) exitDur = 0;
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("moving_left")) exitType = 'l';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("moving_top")) exitType = 't';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("moving_right")) exitType = 'r';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("moving_bottom")) exitType = 'b';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("alpha_out")) exitType = 'a';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("zoom_out")) exitType = 'z';
|
||||||
|
// else if(effStrExit.equalsIgnoreCase("Random")) isExitRand = true;
|
||||||
|
// else exitDur = 0;
|
||||||
|
// }
|
||||||
|
// exitStart = exitDur==0 ? Integer.MAX_VALUE : map.intg("timeSpan")*60 - exitDur;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
drawOther(canvas, this);
|
||||||
|
}
|
||||||
|
public void drawOther(Canvas canvas, View view) {
|
||||||
|
// var fff = ff==0 ? 0 : ff-1;
|
||||||
|
// if(fff < entryDur) {
|
||||||
|
// if(entryType=='l') {
|
||||||
|
// rect.left = RECT.right - fff*RECT.right/(float) entryDur;
|
||||||
|
// rect.right = rect.left + RECT.right;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(entryType=='r') {
|
||||||
|
// rect.left = -RECT.right + fff*RECT.right/(float) entryDur;
|
||||||
|
// rect.right = rect.left + RECT.right;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(entryType=='t') {
|
||||||
|
// rect.top = RECT.bottom - fff*RECT.bottom/(float) entryDur;
|
||||||
|
// rect.bottom = rect.top + RECT.bottom;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(entryType=='b') {
|
||||||
|
// rect.top = -RECT.bottom + fff*RECT.bottom/(float) entryDur;
|
||||||
|
// rect.bottom = rect.top + RECT.bottom;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(entryType=='a') {
|
||||||
|
// paint.setAlpha(fff*255/entryDur);
|
||||||
|
// canvas.drawBitmap(img, null, rect, paint);
|
||||||
|
// } else if(entryType=='z') {
|
||||||
|
// var haw = RECT.right/2f;
|
||||||
|
// var hah = RECT.bottom/2f;
|
||||||
|
// var ww = fff*haw/(float) entryDur;
|
||||||
|
// var hh = fff*hah/(float) entryDur;
|
||||||
|
// rect.left = haw - ww;
|
||||||
|
// rect.right = haw + ww;
|
||||||
|
// rect.top = hah - hh;
|
||||||
|
// rect.bottom = hah + hh;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// }
|
||||||
|
// } else if(fff>=exitStart) {
|
||||||
|
// fff -= exitStart;
|
||||||
|
// if(exitType=='l') {
|
||||||
|
// rect.left = - fff*RECT.right/(float) entryDur;
|
||||||
|
// rect.right = rect.left + RECT.right;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(exitType=='r') {
|
||||||
|
// rect.left = fff*RECT.right/(float) entryDur;
|
||||||
|
// rect.right = rect.left + RECT.right;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(exitType=='t') {
|
||||||
|
// rect.top = - fff*RECT.bottom/(float) entryDur;
|
||||||
|
// rect.bottom = rect.top + RECT.bottom;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(exitType=='b') {
|
||||||
|
// rect.top = fff*RECT.bottom/(float) entryDur;
|
||||||
|
// rect.bottom = rect.top + RECT.bottom;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// } else if(exitType=='a') {
|
||||||
|
// paint.setAlpha(255 - fff*255/entryDur);
|
||||||
|
// canvas.drawBitmap(img, null, rect, paint);
|
||||||
|
// } else if(exitType=='z') {
|
||||||
|
// var haw = RECT.right/2f;
|
||||||
|
// var hah = RECT.bottom/2f;
|
||||||
|
// var ww = haw - fff*haw/(float) entryDur;
|
||||||
|
// var hh = hah - fff*hah/(float) entryDur;
|
||||||
|
// rect.left = haw - ww;
|
||||||
|
// rect.right = haw + ww;
|
||||||
|
// rect.top = hah - hh;
|
||||||
|
// rect.bottom = hah + hh;
|
||||||
|
// canvas.drawBitmap(img, null, rect, null);
|
||||||
|
// }
|
||||||
|
// } else
|
||||||
|
canvas.drawBitmap(img, null, RECT, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
|
int ff;
|
||||||
|
boolean canAdd = true;
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void onVisibilityAggregated(boolean isVisible) {
|
||||||
|
// super.onVisibilityAggregated(isVisible);
|
||||||
|
// ff = 0;
|
||||||
|
// if(isVisible) {
|
||||||
|
// if(canAdd && (entryDur > 0 || exitStart < Integer.MAX_VALUE)) {
|
||||||
|
// choreographer.postFrameCallback(this);
|
||||||
|
// canAdd = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
@Override
|
||||||
|
public void doFrame(long frameTimeNanos) {
|
||||||
|
if(! isShown()) {
|
||||||
|
canAdd = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(ff <= entryDur || ff>=exitStart) {
|
||||||
|
if(ff==0) {
|
||||||
|
if(isEntryRand) entryType = effTypes[Util.rand.nextInt(4)];
|
||||||
|
if(isExitRand) exitType = effTypes[Util.rand.nextInt(4)];
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
ff++;
|
||||||
|
choreographer.postFrameCallback(this);
|
||||||
|
canAdd = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,26 +1,22 @@
|
||||||
package com.xixun.xixunplayer;
|
package com.xixun.xixunplayer;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.view.Choreographer;
|
import android.view.Choreographer;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import gnph.util.Dates;
|
import gnph.util.Dates;
|
||||||
import gnph.util.JSList;
|
|
||||||
import gnph.util.JSMap;
|
import gnph.util.JSMap;
|
||||||
import gnph.util.NumFmts;
|
import gnph.util.NumFmts;
|
||||||
|
|
||||||
public class EleTimer extends View implements Choreographer.FrameCallback {
|
public class SrcTimer extends View implements Choreographer.FrameCallback {
|
||||||
|
|
||||||
HashMap<String, Bitmap> imgMap = new HashMap<>();
|
HashMap<String, Bitmap> imgMap = new HashMap<>();
|
||||||
ArrayList<Bitmap> imgs = new ArrayList<>();
|
ArrayList<Bitmap> imgs = new ArrayList<>();
|
||||||
|
@ -30,15 +26,12 @@ public class EleTimer extends View implements Choreographer.FrameCallback {
|
||||||
long targetTime;
|
long targetTime;
|
||||||
boolean isDown;
|
boolean isDown;
|
||||||
boolean isMultiline;
|
boolean isMultiline;
|
||||||
boolean hasDay;
|
boolean hasDay, hasHour, hasMin, hasSec;
|
||||||
boolean hasHour;
|
|
||||||
boolean hasMin;
|
|
||||||
boolean hasSec;
|
|
||||||
|
|
||||||
public EleTimer(String prefix, JSMap json, Context context) {
|
public SrcTimer(Context context, JSMap json) {
|
||||||
super(context);
|
super(context);
|
||||||
var imgEntrys = json.jsmap("imgs").entrySet();
|
var imgEntrys = json.jsmap("imgs").entrySet();
|
||||||
for(var imgEntry : imgEntrys) imgMap.put(imgEntry.getKey(), BitmapFactory.decodeFile(prefix+imgEntry.getValue()));
|
for(var imgEntry : imgEntrys) imgMap.put(imgEntry.getKey(), BitmapFactory.decodeFile(Util.programDir+"/"+imgEntry.getValue()));
|
||||||
text = imgMap.get("text");
|
text = imgMap.get("text");
|
||||||
day = imgMap.get("day");
|
day = imgMap.get("day");
|
||||||
hour = imgMap.get("hour");
|
hour = imgMap.get("hour");
|
||||||
|
@ -132,6 +125,7 @@ public class EleTimer extends View implements Choreographer.FrameCallback {
|
||||||
if(lastSec==0) {
|
if(lastSec==0) {
|
||||||
cal();
|
cal();
|
||||||
choreographer.postFrameCallback(this);
|
choreographer.postFrameCallback(this);
|
||||||
|
lastSec = 1;
|
||||||
}
|
}
|
||||||
int x = (getWidth()-len) / 2, y;
|
int x = (getWidth()-len) / 2, y;
|
||||||
if(text!=null && isMultiline) {
|
if(text!=null && isMultiline) {
|
||||||
|
@ -148,7 +142,7 @@ public class EleTimer extends View implements Choreographer.FrameCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
Choreographer choreographer = Choreographer.getInstance();
|
Choreographer choreographer = Choreographer.getInstance();
|
||||||
long lastSec = 0;
|
long lastSec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
|
@ -156,7 +150,7 @@ public class EleTimer extends View implements Choreographer.FrameCallback {
|
||||||
lastSec = 0;
|
lastSec = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var sec = frameTimeNanos / 1000000000;
|
var sec = System.currentTimeMillis() / 1000;
|
||||||
if(sec != lastSec) {
|
if(sec != lastSec) {
|
||||||
lastSec = sec;
|
lastSec = sec;
|
||||||
cal();
|
cal();
|
|
@ -6,12 +6,15 @@ import android.os.StatFs;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.CharArrayWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import gnph.util.IOs;
|
import gnph.util.IOs;
|
||||||
|
@ -34,6 +37,33 @@ public class Util {
|
||||||
}
|
}
|
||||||
public static final String[] stateDescsUnknow = {"Unknown", "未知"};
|
public static final String[] stateDescsUnknow = {"Unknown", "未知"};
|
||||||
|
|
||||||
|
public static StringBuffer buf = new StringBuffer();
|
||||||
|
public static Random rand = new Random();
|
||||||
|
|
||||||
|
public static void println(String msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
buf.append(msg).append("\n");
|
||||||
|
}
|
||||||
|
public static void printStackTrace(Throwable e) {
|
||||||
|
println(toStackTrace(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toStr(Throwable e) {
|
||||||
|
var traces = e.getStackTrace();
|
||||||
|
var msg = e.toString();
|
||||||
|
for(var trace : traces) if(trace.getClassName().startsWith("com.xixun.xixunplayer.")) {
|
||||||
|
msg += "\n at "+trace.getFileName()+'.'+trace.getMethodName()+':'+trace.getLineNumber();
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
public static String toStackTrace(Throwable e) {
|
||||||
|
var out = new CharArrayWriter();
|
||||||
|
var writer = new PrintWriter(out);
|
||||||
|
e.printStackTrace(writer);
|
||||||
|
writer.flush();
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static Toast makeText(Context context, CharSequence text) {
|
public static Toast makeText(Context context, CharSequence text) {
|
||||||
var toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
|
var toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
|
||||||
toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
|
toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
|
||||||
|
@ -56,12 +86,12 @@ public class Util {
|
||||||
if(cardId.length() > 13) cardId = cardId.substring(0, 13);
|
if(cardId.length() > 13) cardId = cardId.substring(0, 13);
|
||||||
return cardId;
|
return cardId;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
printStackTrace(e);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteFiles(int proSize, List<String> keeps) {
|
public static void deleteFiles(long proSize, Set<String> keeps) {
|
||||||
var statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
var statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||||
var remain = statFs.getAvailableBytes() - proSize - 1048576;
|
var remain = statFs.getAvailableBytes() - proSize - 1048576;
|
||||||
if(remain >= 0) return;
|
if(remain >= 0) return;
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background" />
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
</adaptive-icon>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background" />
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
</adaptive-icon>
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user