This commit is contained in:
Gangphon 2024-02-02 21:51:16 +08:00
parent d7409bc19f
commit 6f0d507e50
13 changed files with 96 additions and 188 deletions

View File

@ -389,6 +389,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
Util.println("after. curAva: "+progView.curAva+" endMs: "+page(progView.curAva).endMilli);
choreographer.postFrameCallback(this);
canAdd = false;
for(var call : progView.calls) call.doFrame(milli);
return;
}
}
@ -417,6 +418,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
}
choreographer.postFrameCallback(this);
canAdd = false;
for(var call : progView.calls) call.doFrame(milli);
}
void syncProg(long milli) {

View File

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.speech.tts.TextToSpeech;
import android.view.Choreographer;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@ -25,6 +26,7 @@ public class Prog extends AbsLayout {
ArrayList<Page> pages = new ArrayList<>();
ArrayList<Integer> avas = new ArrayList<>();
ArrayList<Choreographer.FrameCallback> calls = new ArrayList<>();
int curAva, curTimes = 1;
long waitTo = Long.MAX_VALUE;
@ -82,7 +84,7 @@ public class Prog extends AbsLayout {
SrcBorder bdEle = null;
int bdWidth = 0, bdStart = 0xffff, bdEnd = 0;
if(border!=null) {
bdEle = new SrcBorder(Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"), context);
bdEle = new SrcBorder(this, Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"));
bdWidth = bdEle.img.getHeight();
}
var src = new Source();
@ -174,7 +176,7 @@ public class Prog extends AbsLayout {
var speechRate = (float) source.dbl("voiceRate");
if(mode!=null ? mode.endsWith("roll") : (imgs.size()==1 && imgs.get(0).intg("picDuration")==0)) {
var img = imgs.get(0);
src.view = new SrcScroll(context, img);
src.view = new SrcScroll(this, img);
if(hasTTS) {
src.text = img.str("text");
if(src.text!=null) {
@ -222,9 +224,9 @@ public class Prog extends AbsLayout {
src = new Source();
}
}
} else if(src.type.equals("DigitalClock")) src.view = new SrcDigitalClock(context, source);
else if(src.type.startsWith("DigitalClock")) src.view = new SrcDigiClock(context, source);
else if(src.type.equals("AnalogClock")) src.view = new SrcAnaClock(geo.width, geo.height, Util.programDir + "/" + id, source, context);
} else if(src.type.equals("DigitalClock")) src.view = new SrcDigitalClock(this, source);
else if(src.type.startsWith("DigitalClock")) src.view = new SrcDigiClock(this, source);
else if(src.type.equals("AnalogClock")) src.view = new SrcAnaClock(this, geo.width, geo.height, Util.programDir + "/" + id, source);
else if(src.type.equals("Audio")) src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, false);
else if(src.type.endsWith("Video")) {
var isLive = src.type.startsWith("Live");
@ -255,10 +257,11 @@ public class Prog extends AbsLayout {
webView.loadUrl(source.stnn("url"));
src.view = webView;
}
else if(src.type.equals("Timer")) src.view = new SrcTimer(context, source);
else if(src.type.equals("Countdown")) src.view = new SrcCountdown(context, source);
else if(src.type.startsWith("Environ")) src.view = new SrcEnviron(context, source);
else if(src.type.equals("Timer")) src.view = new SrcTimer(this, source);
else if(src.type.equals("Countdown")) src.view = new SrcCountdown(this, source);
else if(src.type.startsWith("Environ")) src.view = new SrcEnviron(this, source);
else if(src.type.startsWith("Weather")) src.view = new SrcWeather(context, source);
else if(src.type.startsWith("VistorSource")) src.view = new SrcVisitor(this, source);
else if(src.type.startsWith("MultiLineText")) src.view = new SrcSensor(context, source);
else continue;
if(src.view==null) continue;

View File

@ -1,7 +1,6 @@
package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -22,7 +21,7 @@ import gnph.util.JSMap;
@SuppressLint("ViewConstructor")
public class SrcAnaClock extends View implements Choreographer.FrameCallback {
TimeZone timeZone;
Calendar calendar;
Bitmap img;
int pinHourColor, pinMinColor, pinSecColor;
Path hPath, mPath, sPath;
@ -30,11 +29,13 @@ public class SrcAnaClock extends View implements Choreographer.FrameCallback {
Paint paintPin = new Paint(), paint = new Paint();
boolean showSecHand;
public SrcAnaClock(float w, float h, String path, JSMap source, Context context) {
super(context);
public SrcAnaClock(Prog prog, float w, float h, String path, JSMap source) {
super(prog.getContext());
var timeZoneStr = source.str("timeZone");
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
TimeZone timeZone = null;
if(timeZoneStr!=null) timeZone = TimeZone.getTimeZone(timeZoneStr);
calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
var sideLen = Math.min(w, h);
var halfSide = sideLen / 2;
@ -121,10 +122,12 @@ public class SrcAnaClock extends View implements Choreographer.FrameCallback {
sPath.lineTo(0, shLen*sideLen/-200);
sPath.lineTo(-rx, 0);
sPath.close();
prog.calls.add(this);
}
void cal() {
//var time = timeZone==null ? LocalTime.now() : LocalTime.now(timeZone);
var calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
calendar.setTimeInMillis(lastSec);
sAngle = calendar.get(Calendar.SECOND) * 6;
mAngle = calendar.get(Calendar.MINUTE) * 6 + sAngle/60;
hAngle = calendar.get(Calendar.HOUR_OF_DAY) * 30 + mAngle/12;
@ -132,11 +135,6 @@ public class SrcAnaClock extends View implements Choreographer.FrameCallback {
@Override
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
if(lastSec==0) {
cal();
choreographer.postFrameCallback(this);
lastSec = 1;
}
if(img != null) canvas.drawBitmap(img, null, new RectF(0,0, getWidth(), getHeight()), null);
canvas.translate(getWidth()/2f, getHeight()/2f);
@ -154,21 +152,16 @@ public class SrcAnaClock extends View implements Choreographer.FrameCallback {
}
}
Choreographer choreographer = Choreographer.getInstance();
long lastSec;
@Override
public void doFrame(long frameTimeNanos) {
if(! isShown()) {
lastSec = 0;
return;
}
var sec = System.currentTimeMillis() / 1000;
public void doFrame(long ms) {
if(! isShown()) return;
var sec = ms / 1000;
if(sec != lastSec) {
lastSec = sec;
cal();
invalidate();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,14 +1,14 @@
package com.xixun.xixunplayer;
import android.content.Context;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.Choreographer;
import android.view.View;
@SuppressLint("ViewConstructor")
public class SrcBorder extends View implements Choreographer.FrameCallback {
Bitmap img;
int[] lens = new int[4];
@ -17,13 +17,14 @@ public class SrcBorder extends View implements Choreographer.FrameCallback {
byte eff;
int interval;
public SrcBorder(String path, String eff, int speed, Context context) {
super(context);
public SrcBorder(Prog prog, String path, String effStr, int speed) {
super(prog.getContext());
img = BitmapFactory.decodeFile(path);
if(eff.startsWith("ro")) this.eff = 'r';
else if(eff.startsWith("bl")) this.eff = 'b';
if(this.eff=='r') interval = speed==1 ? 4 : (speed==2 ? 2 : 1);
if(effStr.startsWith("ro")) eff = 'r';
else if(effStr.startsWith("bl")) eff = 'b';
if(eff=='r') interval = speed==1 ? 4 : (speed==2 ? 2 : 1);
else interval = speed==1 ? 30 : (speed==2 ? 15 : 4);
if(eff!=0) prog.calls.add(this);
}
@Override
@ -63,17 +64,12 @@ public class SrcBorder extends View implements Choreographer.FrameCallback {
}
}
}
if(freshCnt==0 && eff!=0) {
choreographer.postFrameCallback(this);
freshCnt = 1;
}
}
Choreographer choreographer = Choreographer.getInstance();
int freshCnt;
@Override
public void doFrame(long frameTimeNanos) {
public void doFrame(long ms) {
if(! isShown()) {
freshCnt = offs[0] = 0;
return;
@ -87,6 +83,5 @@ public class SrcBorder extends View implements Choreographer.FrameCallback {
} else offs[0] = offs[0]==0 ? 1 : 0;
invalidate();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,26 +1,24 @@
package com.xixun.xixunplayer;
import android.content.Context;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.Choreographer;
import android.view.View;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import java.text.SimpleDateFormat;
import gnph.util.JSMap;
import gnph.util.NumFmts;
@SuppressLint("ViewConstructor")
public class SrcCountdown extends WebView implements Choreographer.FrameCallback {
long targetTime;
String html, lineHeight, prefix;
boolean hasDay, hasHour, hasMin, hasSec;
public SrcCountdown(Context context, JSMap json) {
super(context);
public SrcCountdown(Prog prog, JSMap json) {
super(prog.getContext());
setBackgroundColor(Color.TRANSPARENT);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
@ -43,13 +41,13 @@ public class SrcCountdown extends WebView implements Choreographer.FrameCallback
}
} catch (Exception e) {
Util.printStackTrace(e);
Util.makeText(context, Util.toStr(e)).show();
Util.makeText(prog.getContext(), Util.toStr(e)).show();
}
prog.calls.add(this);
}
void cal() {
var cur = System.currentTimeMillis() / 1000;
var secs = targetTime - cur;
var secs = targetTime - lastSec;
if(secs < 0) secs = 0;
var htm = html;
if(hasDay) {
@ -68,32 +66,15 @@ public class SrcCountdown extends WebView implements Choreographer.FrameCallback
loadDataWithBaseURL(null, prefix+htm+"</body>", "text/html", "UTF-8", 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;
public void doFrame(long ms) {
if(! isShown()) return;
var sec = ms / 1000;
if(sec != lastSec) {
lastSec = sec;
cal();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,17 +1,13 @@
package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Choreographer;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
@ -24,7 +20,7 @@ import gnph.util.JSMap;
@SuppressLint("ViewConstructor")
public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallback {
static final String weeks[] = {"SUN", "MON","TUE","WED","THU","FRI","SAT"};
static final String[] weeks = {"SUN", "MON","TUE","WED","THU","FRI","SAT"};
HashMap<String, Bitmap> imgs = new HashMap<>();
ImageView[] yearComps = {new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext()), new ImageView(getContext())};
ImageView[] monthComps = {new ImageView(getContext()), new ImageView(getContext())};
@ -34,16 +30,17 @@ public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallba
ImageView[] minComps = {new ImageView(getContext()), new ImageView(getContext())};
ImageView[] secComps = {new ImageView(getContext()), new ImageView(getContext())};
TimeZone timeZone;
Calendar calendar;
SimpleDateFormat timeptn, dataFmt = new SimpleDateFormat("yyyyMMdd");
boolean multiline, weekly, isSingleMonth;
public SrcDigiClock(Context context, JSMap json) {
super(context);
public SrcDigiClock(Prog prog, JSMap json) {
super(prog.getContext());
setGravity(Gravity.CENTER);
var timeZoneStr = json.str("timeZone");
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
if(timeZoneStr!=null) timeZone = TimeZone.getTimeZone(timeZoneStr);
var timeZone = timeZoneStr==null ? null : TimeZone.getTimeZone(timeZoneStr);
calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
var spaceWidth = json.dbl("spaceWidth");
JSList<JSMap> pics = json.jslist("arrayPics");
if(pics!=null && ! pics.isEmpty() && pics.get(0).containsKey("startX")) {
@ -127,6 +124,7 @@ public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallba
}
}
addStretch();
prog.calls.add(this);
}
ImageView newImgView(Bitmap img) {
@ -240,7 +238,7 @@ public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallba
void cal() {
//var dt = timeZone==null ? LocalDateTime.now() : LocalDateTime.now(timeZone);
var calendar = timeZone==null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
calendar.setTimeInMillis(lastSec);
var hms = timeptn.format(calendar.getTime());
ampmComp.setImageBitmap(imgs.get(calendar.get(Calendar.HOUR_OF_DAY) < 12?"AM":"PM"));
hourComps[0].setImageBitmap(imgs.get(hms.substring(0,1)));
@ -263,32 +261,15 @@ public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallba
}
}
@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;
public void doFrame(long ms) {
if(! isShown()) return;
var sec = ms / 1000;
if(sec != lastSec) {
lastSec = sec;
cal();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,18 +1,13 @@
package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.Choreographer;
import android.view.View;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import java.util.Calendar;
import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import gnph.util.JSMap;
import gnph.util.NumFmts;
@ -26,8 +21,8 @@ public class SrcDigitalClock extends WebView implements Choreographer.FrameCallb
Locale locale;
boolean hasYear, hasMonthStr, hasMonth, hasDay, hasWeek, hasAP, hasHour, hasHour12, hasMin, hasSec;
public SrcDigitalClock(Context context, JSMap json) {
super(context);
public SrcDigitalClock(Prog prog, JSMap json) {
super(prog.getContext());
setBackgroundColor(Color.TRANSPARENT);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
@ -57,12 +52,13 @@ public class SrcDigitalClock extends WebView implements Choreographer.FrameCallb
else locale = new Locale(lan.get(0), lan.get(1));
} catch (Exception e) {
Util.printStackTrace(e);
Util.makeText(context, Util.toStr(e)).show();
Util.makeText(prog.getContext(), Util.toStr(e)).show();
}
prog.calls.add(this);
}
void cal() {
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.setTimeInMillis(lastSec);
var htm = html;
if(hasYear) htm = htm.replace("%y", Long.toString(calendar.get(Calendar.YEAR)));
try {
@ -82,32 +78,15 @@ public class SrcDigitalClock extends WebView implements Choreographer.FrameCallb
return val==cas ? then : val;
}
@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;
public void doFrame(long ms) {
if(! isShown()) return;
var sec = ms / 1000;
if(sec != lastSec) {
lastSec = sec;
cal();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,6 +1,6 @@
package com.xixun.xixunplayer;
import android.content.Context;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -17,8 +17,9 @@ import gnph.util.JSList;
import gnph.util.JSMap;
import gnph.util.NumFmts;
@SuppressLint("ViewConstructor")
public class SrcEnviron extends View implements Choreographer.FrameCallback, IntentReceiver {
class Item {
static class Item {
String key;
Bitmap label;
ArrayList<Bitmap> nums = new ArrayList<>();
@ -30,7 +31,7 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
this.unit = unit;
}
}
static String directs[] = {"NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"};
static String[] directs = {"NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"};
HashMap<String, Bitmap> imgMap = new HashMap<>();
Bitmap title;
ArrayList<Item> items = new ArrayList<>();
@ -39,9 +40,9 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
int interval, cur, end, step;
boolean isScroll, isFirst = true;
public SrcEnviron(Context context, JSMap json) {
super(context);
act = (MainActivity) context;
public SrcEnviron(Prog prog, JSMap json) {
super(prog.getContext());
act = (MainActivity) prog.getContext();
alignType = json.intg("alignType");
spaceWidth = json.intg("spaceWidth");
isScroll = json.bool("bSingleScroll");
@ -56,7 +57,7 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
JSList<JSMap> jitems = json.jslist("items");
for(var jitem : jitems) {
var unit = jitem.str("unit");
items.add(new Item(jitem.str("name"), BitmapFactory.decodeFile(Util.programDir+"/"+jitem.stnn("label")), unit==null ? null : BitmapFactory.decodeFile(Util.programDir+"/"+unit)));
items.add(new Item(jitem.str("name"), BitmapFactory.decodeFile(Util.programDir + "/" + jitem.stnn("label")), unit == null ? null : BitmapFactory.decodeFile(Util.programDir + "/" + unit)));
}
} else {
JSList<JSMap> pics = json.jslist("arrayPics");
@ -89,6 +90,7 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
interval = step = 1;
if(scrollSpeed > 60) step = (int) Math.round(scrollSpeed/60);
else if(scrollSpeed < 60) interval = (int) Math.round(60/scrollSpeed);
if(isScroll) prog.calls.add(this);
}
public static Method method;
@ -156,10 +158,6 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
}
if(ccc==0) end = -(x-cur-step);
}
if(freshCnt==0 && interval!=0) {
choreographer.postFrameCallback(this);
freshCnt = 1;
}
} else {
var itemH = (double) getHeight() / (title!=null ? items.size()+1 : items.size());
int i = 0, x = 0;
@ -200,11 +198,10 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
}
}
Choreographer choreographer = Choreographer.getInstance();
int freshCnt;
@Override
public void doFrame(long frameTimeNanos) {
public void doFrame(long ms) {
if(! isShown()) {
freshCnt = cur = 0;
return;
@ -216,6 +213,5 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int
else cur -= step;
invalidate();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,7 +1,6 @@
package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -12,7 +11,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
import gnph.util.JSMap;
@ -25,8 +23,8 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
int interval, cur, end, step;
char effect;
public SrcScroll(Context context, JSMap json) {
super(context);
public SrcScroll(Prog prog, JSMap json) {
super(prog.getContext());
var img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id"));
imgsWidth = img.getWidth();
if(imgsWidth <= 8192) imgs.add(img);
@ -55,7 +53,9 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
else if(effect=='r') end = imgsWidth-step;
else if(effect=='t') end = -(imgs.get(0).getHeight()-step);
else if(effect=='b') end = imgs.get(0).getHeight()-step;
else effect = 0;
}
if(effect!=0) prog.calls.add(this);
}
@Override
protected void onDraw(@NonNull Canvas canvas) {
@ -63,10 +63,6 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
if(imgs.isEmpty()) return;
try {
drawOther(canvas);
if(freshCnt==0 && effect!=0 && interval!=0) {
choreographer.postFrameCallback(this);
freshCnt = 1;
}
} catch (Throwable e) {
setVisibility(GONE);
imgs.clear();
@ -114,11 +110,10 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
} else canvas.drawBitmap(imgs.get(0), 0, 0, null);
}
Choreographer choreographer = Choreographer.getInstance();
int freshCnt;
@Override
public void doFrame(long frameTimeNanos) {
public void doFrame(long ms) {
if(! isShown()) {
freshCnt = cur = 0;
return;
@ -135,6 +130,5 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
}
invalidate();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,6 +1,6 @@
package com.xixun.xixunplayer;
import android.content.Context;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -16,6 +16,7 @@ import gnph.util.Dates;
import gnph.util.JSMap;
import gnph.util.NumFmts;
@SuppressLint("ViewConstructor")
public class SrcTimer extends View implements Choreographer.FrameCallback {
HashMap<String, Bitmap> imgMap = new HashMap<>();
@ -28,8 +29,8 @@ public class SrcTimer extends View implements Choreographer.FrameCallback {
boolean isMultiline;
boolean hasDay, hasHour, hasMin, hasSec;
public SrcTimer(Context context, JSMap json) {
super(context);
public SrcTimer(Prog prog, JSMap json) {
super(prog.getContext());
var imgEntrys = json.jsmap("imgs").entrySet();
for(var imgEntry : imgEntrys) imgMap.put(imgEntry.getKey(), BitmapFactory.decodeFile(Util.programDir+"/"+imgEntry.getValue()));
text = imgMap.get("text");
@ -49,11 +50,11 @@ public class SrcTimer extends View implements Choreographer.FrameCallback {
try {
setBackgroundColor(Color.parseColor(json.stnn("backColor")));
} catch (Exception ignored) {}
prog.calls.add(this);
}
void cal() {
var cur = System.currentTimeMillis() / 1000;
var secs = isDown ? targetTime - cur : cur - targetTime;
var secs = isDown ? targetTime - lastSec : lastSec - targetTime;
if(secs < 0) secs = 0;
len = 0;
imgs.clear();
@ -122,11 +123,6 @@ public class SrcTimer extends View implements Choreographer.FrameCallback {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(lastSec==0) {
cal();
choreographer.postFrameCallback(this);
lastSec = 1;
}
int x = (getWidth()-len) / 2, y;
if(text!=null && isMultiline) {
y = getHeight() / 2;
@ -141,21 +137,16 @@ public class SrcTimer extends View implements Choreographer.FrameCallback {
}
}
Choreographer choreographer = Choreographer.getInstance();
long lastSec;
@Override
public void doFrame(long frameTimeNanos) {
if(! isShown()) {
lastSec = 0;
return;
}
var sec = System.currentTimeMillis() / 1000;
public void doFrame(long ms) {
if(! isShown()) return;
var sec = ms / 1000;
if(sec != lastSec) {
lastSec = sec;
cal();
invalidate();
}
choreographer.postFrameCallback(this);
}
}

View File

@ -1,7 +1,6 @@
package com.xixun.xixunplayer;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.view.Surface;
import android.view.TextureView;

View File

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.Choreographer;
import android.webkit.WebView;
import java.text.DecimalFormat;
@ -18,12 +19,12 @@ import gnph.util.Txts;
import gnph.util.URLConn;
@SuppressLint("ViewConstructor")
public class SrcVisitor extends WebView {
public class SrcVisitor extends WebView implements Choreographer.FrameCallback {
String html, lineHeight, prefix, url;
public SrcVisitor(Context context, JSMap json) {
super(context);
public SrcVisitor(Prog prog, JSMap json) {
super(prog.getContext());
setBackgroundColor(Color.TRANSPARENT);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
@ -34,6 +35,7 @@ public class SrcVisitor extends WebView {
prefix = "<body style=\"color:#fff;margin:0;padding:0;";
if(lineHeight!=null) prefix += "line-height:"+lineHeight+";";
prefix += "\">";
if(url!=null) prog.calls.add(this);
}
public void refresh() {
@ -82,14 +84,11 @@ public class SrcVisitor extends WebView {
long nextMs;
@Override
public void onVisibilityAggregated(boolean isVisible) {
super.onVisibilityAggregated(isVisible);
if(isVisible) {
var ms = System.currentTimeMillis();
if(ms>=nextMs) {
nextMs += 15000;
refresh();
}
public void doFrame(long ms) {
if(! isShown()) return;
if(ms>=nextMs) {
nextMs += 15000;
refresh();
}
}
}

View File

@ -2,18 +2,13 @@ package com.xixun.xixunplayer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.webkit.WebView;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.regex.Pattern;
import gnph.util.IOs;
import gnph.util.JSList;
import gnph.util.JSMap;
import gnph.util.NumFmts;
import gnph.util.Txts;
import gnph.util.URLConn;