From 9e1309090cbba1a6e80a248f39278ff201291f6c Mon Sep 17 00:00:00 2001 From: Gangphon Date: Sat, 27 Jan 2024 21:46:22 +0800 Subject: [PATCH] player --- XixunPlayer/app/build.gradle | 2 +- .../main/java/com/xixun/xixunplayer/Prog.java | 2 +- .../{EleAnaClock.java => SrcAnaClock.java} | 56 ++++++------ .../java/com/xixun/xixunplayer/SrcSensor.java | 88 +++++++++++-------- 4 files changed, 86 insertions(+), 62 deletions(-) rename XixunPlayer/app/src/main/java/com/xixun/xixunplayer/{EleAnaClock.java => SrcAnaClock.java} (75%) diff --git a/XixunPlayer/app/build.gradle b/XixunPlayer/app/build.gradle index 5717e5f..ab53e6d 100644 --- a/XixunPlayer/app/build.gradle +++ b/XixunPlayer/app/build.gradle @@ -11,7 +11,7 @@ android { minSdk 24 targetSdk 34 versionCode 1 - versionName "1.0.18-digi" + versionName "1.0.20-sensor" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java index d42f0c9..7740973 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java @@ -198,7 +198,7 @@ public class Prog extends AbsLayout { } } 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("AnalogClock")) src.view = new SrcAnaClock(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; diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleAnaClock.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcAnaClock.java similarity index 75% rename from XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleAnaClock.java rename to XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcAnaClock.java index bb977fb..06ae88f 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleAnaClock.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcAnaClock.java @@ -1,8 +1,5 @@ package com.xixun.xixunplayer; -import static android.graphics.Paint.Join.ROUND; -import static android.graphics.Paint.Style.FILL_AND_STROKE; - import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; @@ -11,7 +8,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; -import android.graphics.Rect; import android.graphics.RectF; import android.view.Choreographer; import android.view.View; @@ -24,18 +20,17 @@ import java.util.TimeZone; import gnph.util.JSMap; @SuppressLint("ViewConstructor") -public class EleAnaClock extends View implements Choreographer.FrameCallback { +public class SrcAnaClock extends View implements Choreographer.FrameCallback { TimeZone timeZone; Bitmap img; - Rect imgRect; int pinHourColor, pinMinColor, pinSecColor; Path hPath, mPath, sPath; float hAngle, mAngle, sAngle; - Paint paint = new Paint(); + Paint paintPin = new Paint(), paint = new Paint(); boolean showSecHand; - public EleAnaClock(float w, float h, String path, JSMap source, Context context) { + public SrcAnaClock(float w, float h, String path, JSMap source, Context context) { super(context); var timeZoneStr = source.str("timeZone"); //if(timeZoneStr!=null) timeZone = ZoneId.of(timeZoneStr); @@ -46,10 +41,14 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback { var lineWidth = sideLen / 128; if(lineWidth < 1) lineWidth = 1; + paintPin.setAntiAlias(true); + paintPin.setStyle(Paint.Style.FILL_AND_STROKE); + paintPin.setStrokeWidth(lineWidth); + paintPin.setStrokeJoin(Paint.Join.ROUND); paint.setAntiAlias(true); - paint.setStyle(FILL_AND_STROKE); - paint.setStrokeWidth(lineWidth); - paint.setStrokeJoin(ROUND); + paint.setStyle(Paint.Style.FILL); + var fontSize = sideLen / 11; + paint.setTextSize(fontSize); img = BitmapFactory.decodeFile(path); if(img==null) { @@ -63,15 +62,17 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback { paint.setColor(bgColor); canvas.drawOval(-halfSide, -halfSide, halfSide, halfSide, paint); } - var minMarkSize = 2.5f; - var hourMarkSize = 5f; + var minMarkSize = sideLen/48; + var hourMarkSize = sideLen/32; var scaleHourColor = Color.parseColor(source.stnn("scaleHourColor")); var scaleMinColor = Color.parseColor(source.stnn("scaleMinColor")); - var r = (sideLen - Math.max(minMarkSize, hourMarkSize)) / 2; + var showScaleNum = source.bool("showScaleNum"); + var rScale = (sideLen - Math.max(minMarkSize, hourMarkSize)) / 2; + var rNum = halfSide * 0.83; 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); + var x = (float) (Math.sin(k) * rScale); + var y = (float) (-Math.cos(k) * rScale); if(i % 5 > 0) { var rr = minMarkSize / 2f; paint.setColor(scaleMinColor); @@ -80,11 +81,16 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback { 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); + if(showScaleNum) { + var hour = i/5; + if(hour==0) hour = 12; + x = (float) (Math.sin(k) * rNum); + y = (float) (-Math.cos(k) * rNum); + canvas.drawText(String.valueOf(hour), x - fontSize*(hour<10 ? 0.28f : 0.6f), y + fontSize*0.355f, paint); + } } } } - 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")); @@ -131,20 +137,20 @@ public class EleAnaClock extends View implements Choreographer.FrameCallback { choreographer.postFrameCallback(this); lastSec = 1; } - if(img != null) canvas.drawBitmap(img, imgRect, new RectF(0,0, getWidth(), getHeight()), paint); + if(img != null) canvas.drawBitmap(img, null, new RectF(0,0, getWidth(), getHeight()), null); canvas.translate(getWidth()/2f, getHeight()/2f); - paint.setColor(pinHourColor); + paintPin.setColor(pinHourColor); canvas.rotate(hAngle); - canvas.drawPath(hPath, paint); + canvas.drawPath(hPath, paintPin); - paint.setColor(pinMinColor); + paintPin.setColor(pinMinColor); canvas.rotate(mAngle-hAngle); - canvas.drawPath(mPath, paint); + canvas.drawPath(mPath, paintPin); if(showSecHand) { - paint.setColor(pinSecColor); + paintPin.setColor(pinSecColor); canvas.rotate(sAngle-mAngle); - canvas.drawPath(sPath, paint); + canvas.drawPath(sPath, paintPin); } } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java index 578d3cd..5e36cf4 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcSensor.java @@ -2,19 +2,11 @@ package com.xixun.xixunplayer; import android.content.Context; import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; import android.graphics.Color; -import android.view.Choreographer; -import android.view.View; import android.webkit.WebView; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; +import java.text.DecimalFormat; -import gnph.util.JSList; import gnph.util.JSMap; import gnph.util.NumFmts; @@ -23,7 +15,6 @@ public class SrcSensor extends WebView implements IntentReceiver { static String directs[] = {"NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"}; MainActivity act; String html, lineHeight, prefix; - int interval, cur, end, step; boolean isFirst = true; public SrcSensor(Context context, JSMap json) { @@ -33,40 +24,67 @@ public class SrcSensor extends WebView implements IntentReceiver { setVerticalScrollBarEnabled(false); setHorizontalScrollBarEnabled(false); setInitialScale(100); - html = json.stnn("html"); + html = json.stnn("html").replace("%Co2", "%CO2"); lineHeight = json.str("lineHeight"); prefix = ""; } - public static Method method; - static { - try { - method = Intent.class.getMethod("getExtra", String.class, Object.class); - } catch (Exception e) { - e.printStackTrace(); - } - } + static DecimalFormat fmt0 = NumFmts.newDecFmt("0"); public void onReceive(Intent intent) { try { -// for(var item : items) { -// item.nums.clear(); -// if(item.unit==null) { -// var num = intent.getIntExtra(item.key, -1); -// if(num>=0 && num<=15) item.nums.add(imgMap.get(directs[num])); -// else { -// var img = imgMap.get("-"); -// item.nums.add(img); -// item.nums.add(img); -// } -// } else { -// var num = ((Number) method.invoke(intent, item.key, -999)).doubleValue(); -// var str = num==-999 || (num==-1 && ! item.key.endsWith("rature")) ? "--" : NumFmts.zz().format(num); -// for(int cc=0; cc=directs.length ? "--" : directs[windDir]) + .replace("%pm2", (pm2 == -1 ? "--" : String.valueOf(pm2)) + "μg/m³") + .replace("%pm10", (pm10 == -1 ? "--" : String.valueOf(pm10)) + "μg/m³") + + .replace("%SO2", (SO2 == -1 ? "--" : String.valueOf(SO2)) +"ppb") + .replace("%NO2", (NO2 == -1 ? "--" : String.valueOf(NO2)) +"ppb") + .replace("%CO2", (CO2 == -1 ? "--" : String.valueOf(CO2)) +"ppm") + .replace("%CO", (CO == -1 ? "--" : String.valueOf(CO)) +"ppb") + .replace("%O3", (O3 == -1 ? "--" : String.valueOf(O3)) +"ppb") + .replace("%dp", (dp == -1 ? "--" : String.valueOf(dp)) +'℃') + .replace("%pressure", (pressure == -1 ? "--" : String.valueOf(pressure))+"hPa") + .replace("%rainfall", (rainfall == -1 ? "--" : String.valueOf(rainfall))+"mm") + .replace("%radiation", (radiation == -1 ? "--" : String.valueOf(radiation))+"W/m²") + .replace("%bm", (beam == -1 ? "--" : String.valueOf(beam))+"lux"); + loadDataWithBaseURL(null, prefix+htm+"", "text/html", "UTF-8", null); } catch (Exception e) { Util.printStackTrace(e);