player
This commit is contained in:
parent
ce66727d0f
commit
9e1309090c
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 = "<body style=\"color:#fff;margin:0;padding:0;";
|
||||
if(lineHeight!=null) prefix += "line-height:"+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<str.length(); cc++) item.nums.add(imgMap.get(str.substring(cc, cc+1)));
|
||||
// }
|
||||
// }
|
||||
var htm = html;
|
||||
var temp = intent.getFloatExtra("temperature", -99f);
|
||||
var noTemp = temp==-99f;
|
||||
var t2 = noTemp ? "--" : NumFmts.fix2().format(temp);
|
||||
var t1 = noTemp ? "--" : NumFmts.fix1().format(temp);
|
||||
var tn = noTemp ? "--" : String.valueOf(temp);
|
||||
var t0 = noTemp ? "--" : fmt0.format(temp);
|
||||
var f2 = noTemp ? "--" : NumFmts.fix2().format(temp * 1.8 + 32);
|
||||
var f1 = noTemp ? "--" : NumFmts.fix1().format(temp * 1.8 + 32);
|
||||
var fn = noTemp ? "--" : String.valueOf(temp * 1.8 + 32);
|
||||
var f0 = noTemp ? "--" : fmt0.format(temp * 1.8 + 32);
|
||||
|
||||
var humi = intent.getFloatExtra("humidity", -1);
|
||||
var h = humi == -1 ? "--" : String.valueOf(humi);
|
||||
var noise = intent.getFloatExtra("noise", -1);
|
||||
var windSpeed = intent.getFloatExtra("windSpeed", -1);
|
||||
int pm2 = intent.getIntExtra("pm2.5", -1);
|
||||
int pm10 = intent.getIntExtra("pm10", -1);
|
||||
int windDir = intent.getIntExtra("windDirection", -1);
|
||||
int SO2 = intent.getIntExtra("SO2", -1);
|
||||
int NO2 = intent.getIntExtra("NO2", -1);
|
||||
int CO2 = intent.getIntExtra("CO2", -1);
|
||||
int CO = intent.getIntExtra("CO", -1);
|
||||
int O3 = intent.getIntExtra("O3", -1);
|
||||
var pressure = intent.getFloatExtra("pressure", -1);
|
||||
var rainfall = intent.getFloatExtra("rainfall", -1);
|
||||
int radiation = intent.getIntExtra("radiation", -1);
|
||||
int beam = intent.getIntExtra("beam", -1);
|
||||
//int brightness = intent.getIntExtra("brightness", -1);
|
||||
var dp = intent.getFloatExtra("dpTemperature", -99f);
|
||||
|
||||
htm = htm.replace("%T2", t2 + '℃').replace("%T1", t1 + '℃').replace("%T", tn + '℃').replace("%c2", t2).replace("%c1", t1).replace("%c", t0)
|
||||
.replace("%t2", f2 + '℉').replace("%t1", f1 + '℉').replace("%t", fn + '℉').replace("%f2", f2).replace("%f1", f1).replace("%f", f0)
|
||||
.replace("%RH", h+'%').replace("%h", h)
|
||||
.replace("%ns", (noise == -1 ? "--" : String.valueOf(noise)) + "dB")
|
||||
.replace("%ws", (windSpeed == -1 ? "--" : String.valueOf(windSpeed)) + "m/s")
|
||||
.replace("%wd", windDir<0||windDir>=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+"</body>", "text/html", "UTF-8", null);
|
||||
} catch (Exception e) {
|
||||
Util.printStackTrace(e);
|
||||
|
|
Loading…
Reference in New Issue
Block a user