This commit is contained in:
Gangphon 2024-01-25 20:43:39 +08:00
parent 9b951e17eb
commit d093537ddd
7 changed files with 156 additions and 43 deletions

View File

@ -11,7 +11,7 @@ android {
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
versionName "1.0.18-digi"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -39,7 +39,7 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback {
super(context);
var timeZoneStr = source.str("timeZone");
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
if(timeZoneStr!=null) TimeZone.getTimeZone(timeZoneStr);
if(timeZoneStr!=null) timeZone = TimeZone.getTimeZone(timeZoneStr);
var sideLen = Math.min(w, h);
var halfSide = sideLen / 2;

View File

@ -16,18 +16,17 @@ import java.util.HashMap;
import gnph.util.JSList;
import gnph.util.JSMap;
import gnph.util.NumFmts;
import gnph.util.Sys;
public class EleEnviron extends View implements Choreographer.FrameCallback {
class Item {
String key;
Bitmap lable;
Bitmap label;
ArrayList<Bitmap> nums = new ArrayList<>();
Bitmap unit;
public Item(String key, Bitmap lable, Bitmap unit) {
public Item(String key, Bitmap label, Bitmap unit) {
this.key = key;
this.lable = lable;
this.label = label;
this.unit = unit;
}
}
@ -141,9 +140,9 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
}
var y = (int) Math.round((getHeight() - digitHeight) / 2);
for(var item : items) {
if(item.lable!=null) {
canvas.drawBitmap(item.lable, x, y, null);
x += item.lable.getWidth();
if(item.label !=null) {
canvas.drawBitmap(item.label, x, y, null);
x += item.label.getWidth();
}
for(var num : item.nums) if(num!=null) {
canvas.drawBitmap(num, x, y, null);
@ -173,15 +172,15 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2);
x = 0;
if(alignType!=0) {
if(item.lable!=null) x += item.lable.getWidth();
if(item.label !=null) x += item.label.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) {
canvas.drawBitmap(item.lable, x, y, null);
x += item.lable.getWidth();
if(item.label !=null) {
canvas.drawBitmap(item.label, x, y, null);
x += item.label.getWidth();
}
for(var num : item.nums) if(num!=null) {
canvas.drawBitmap(num, x, y, null);

View File

@ -196,7 +196,8 @@ public class Prog extends AbsLayout {
src = new Source();
}
}
} else if(src.type.startsWith("DigitalClock")) src.view = new EleDigiClock(context, 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 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")) {

View File

@ -1,39 +1,46 @@
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 java.text.SimpleDateFormat;
import gnph.util.Dates;
import gnph.util.JSMap;
import gnph.util.NumFmts;
public class SrcCountdown extends WebView implements Choreographer.FrameCallback {
long targetTime;
String html;
String html, lineHeight, prefix;
boolean hasDay, hasHour, hasMin, hasSec;
public SrcCountdown(Context context, JSMap json) {
super(context);
setBackgroundColor(Color.TRANSPARENT);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
setInitialScale(100);
html = json.stnn("html");
lineHeight = json.str("lineHeight");
prefix = "<body style=\"color:#fff;margin:0;padding:0;";
if(lineHeight!=null) prefix += "line-height:"+lineHeight+";";
prefix += "\">";
hasDay = html.contains("%d");
hasHour = html.contains("%h");
hasMin = html.contains("%m");
hasSec = html.contains("%s");
var time = json.stnn("time");
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");
try {
targetTime = new SimpleDateFormat("y-M-d H:m:s").parse(time).getTime() / 1000;
} catch (Exception e) {
targetTime = new SimpleDateFormat("y-M-d H:m").parse(time).getTime() / 1000;
}
} catch (Exception e) {
Util.printStackTrace(e);
Util.makeText(context, Util.toStr(e)).show();
@ -46,25 +53,19 @@ public class SrcCountdown extends WebView implements Choreographer.FrameCallback
if(secs < 0) secs = 0;
var htm = html;
if(hasDay) {
var str = Long.toString(secs/86400);
htm = htm.replace("%d", Long.toString(secs/86400));
secs %= 86400;
htm = htm.replace("%d", str);
}
if(hasHour) {
var str = NumFmts.zz().format(secs/3600);
htm = htm.replace("%h", NumFmts.zz().format(secs/3600));
secs %= 3600;
htm = htm.replace("%h", str);
}
if(hasMin) {
var str = NumFmts.zz().format(secs/60);
htm = htm.replace("%m", 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);
if(hasSec) htm = htm.replace("%s", NumFmts.zz().format(secs));
loadDataWithBaseURL(null, prefix+htm+"</body>", "text/html", "UTF-8", null);
}
@Override

View File

@ -18,12 +18,11 @@ import java.util.HashMap;
import java.util.TimeZone;
import gnph.android.LinearBox;
import gnph.util.Dates;
import gnph.util.JSList;
import gnph.util.JSMap;
@SuppressLint("ViewConstructor")
public class EleDigiClock extends LinearBox implements Choreographer.FrameCallback {
public class SrcDigiClock extends LinearBox implements Choreographer.FrameCallback {
static final String weeks[] = {"SUN", "MON","TUE","WED","THU","FRI","SAT"};
HashMap<String, Bitmap> imgs = new HashMap<>();
@ -39,12 +38,12 @@ public class EleDigiClock extends LinearBox implements Choreographer.FrameCallba
SimpleDateFormat timeptn, dataFmt = new SimpleDateFormat("yyyyMMdd");
boolean multiline, weekly, isSingleMonth;
public EleDigiClock(Context context, JSMap json) {
public SrcDigiClock(Context context, JSMap json) {
super(context);
setGravity(Gravity.CENTER);
var timeZoneStr = json.str("timeZone");
//if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr);
if(timeZoneStr!=null) TimeZone.getTimeZone(timeZoneStr);
if(timeZoneStr!=null) timeZone = TimeZone.getTimeZone(timeZoneStr);
var spaceWidth = json.dbl("spaceWidth");
JSList<JSMap> pics = json.jslist("arrayPics");
if(pics!=null && ! pics.isEmpty() && pics.get(0).containsKey("startX")) {

View File

@ -0,0 +1,113 @@
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;
import gnph.util.Txts;
@SuppressLint("ViewConstructor")
public class SrcDigitalClock extends WebView implements Choreographer.FrameCallback {
String html, lineHeight, prefix;
Calendar calendar;
Locale locale;
boolean hasYear, hasMonthStr, hasMonth, hasDay, hasWeek, hasAP, hasHour, hasHour12, hasMin, hasSec;
public SrcDigitalClock(Context context, JSMap json) {
super(context);
setBackgroundColor(Color.TRANSPARENT);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
setInitialScale(100);
html = json.stnn("html");
lineHeight = json.str("lineHeight");
var timezone = json.dbl("timezone", 9999);
calendar = timezone==9999 ? Calendar.getInstance() : Calendar.getInstance(new SimpleTimeZone((int) (timezone*3600000), ""));
prefix = "<body style=\"color:#fff;margin:0;padding:0;";
if(lineHeight!=null) prefix += "line-height:"+lineHeight+";";
prefix += "\">";
hasYear = html.contains("%y");
var hhh = html.replace("%Mw", "");
hasMonthStr = html.length()!=hhh.length();
hasMonth = hhh.contains("%M");
hasDay = html.contains("%d");
hasWeek = html.contains("%w");
hasAP = html.contains("%am");
hasHour = html.contains("%H");
hasHour12 = html.contains("%h");
hasMin = html.contains("%m");
hasSec = html.contains("%s");
try {
var lan = Txts.split(json.stnn("language"), "-", 1);
if(lan.isEmpty()) locale = Locale.getDefault();
else if(lan.size()==1) locale = lan.get(0).equals("cn") ? new Locale("zh", "CN") : new Locale(lan.get(0));
else locale = new Locale(lan.get(0), lan.get(1));
} catch (Exception e) {
Util.printStackTrace(e);
Util.makeText(context, Util.toStr(e)).show();
}
}
void cal() {
calendar.setTimeInMillis(System.currentTimeMillis());
var htm = html;
if(hasYear) htm = htm.replace("%y", Long.toString(calendar.get(Calendar.YEAR)));
try {
if(hasMonthStr) htm = htm.replace("%Mw", calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale));
if(hasWeek) htm = htm.replace("%w", calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale));
if(hasAP) htm = htm.replace("%am", calendar.getDisplayName(Calendar.AM_PM, Calendar.SHORT, locale));
} catch (Exception ignored) {}
if(hasMonth) htm = htm.replace("%M", NumFmts.zz().format(calendar.get(Calendar.MONTH)+1));
if(hasDay) htm = htm.replace("%d", NumFmts.zz().format(calendar.get(Calendar.DAY_OF_MONTH)));
if(hasHour) htm = htm.replace("%H", NumFmts.zz().format(calendar.get(Calendar.HOUR_OF_DAY)));
if(hasHour12) htm = htm.replace("%h", NumFmts.zz().format(caseThen(calendar.get(Calendar.HOUR), 0, 12)));
if(hasMin) htm = htm.replace("%m", NumFmts.zz().format(calendar.get(Calendar.MINUTE)));
if(hasSec) htm = htm.replace("%s", NumFmts.zz().format(calendar.get(Calendar.SECOND)));
loadDataWithBaseURL(null, prefix+htm+"</body>", "text/html", "UTF-8", null);
}
int caseThen(int val, int cas, int then) {
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;
if(sec != lastSec) {
lastSec = sec;
cal();
}
choreographer.postFrameCallback(this);
}
}