正在查看: xDrip+ v04633772025.07.16 应用的 LibreTrendGraph.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 LibreTrendGraph.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utils;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.eveningoutpost.dexdrip.BaseAppCompatActivity;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.LibreBlock;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.HPointValue;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.LineChartView;
public class LibreTrendGraph extends BaseAppCompatActivity {
private LineChartView chart;
private LineChartData data;
private final boolean doMgdl = Pref.getString("units", "mgdl").equals("mgdl");
private final int MINUTES_TO_DISPLAY = 45;
public void closeNow(View view) {
try {
finish();
} catch (Exception e) {
UserError.Log.d("LibreTrendGraph", "Error finishing " + e.toString());
}
}
private static ArrayList<Float> getLatestBgForXMinutes(int i) {
UserError.Log.i("LibreTrendGraph", "getLatestBgForXMinutes number of minutes = " + i);
List<LibreTrendPoint> data = LibreTrendUtil.getInstance().getData(JoH.tsl() - ((long) ((i * 60) * 1000)), JoH.tsl(), true);
if (data == null || data.size() == 0) {
UserError.Log.e("LibreTrendGraph", "Error getting data from getLatestBgForXMinutes");
return null;
}
LibreTrendLatest libreTrendLatest = LibreTrendUtil.getInstance().getLibreTrendLatest();
if (libreTrendLatest == null) {
UserError.Log.e("LibreTrendGraph", "LibreTrendPoints exists but libreTrendLatest is NULL.");
return null;
}
ArrayList<Float> arrayList = new ArrayList<>();
double factor = libreTrendLatest.getFactor();
if (factor == BgReading.BESTOFFSET) {
UserError.Log.e("LibreTrendGraph", "getLatestBgForXMinutes: factor is 0 returning.");
return null;
}
int i2 = 0;
for (int i3 = libreTrendLatest.id; i3 >= 0 && i2 < i; i3--) {
i2++;
arrayList.add(new Float(data.get(i3).rawSensorValue * factor));
}
return arrayList;
}
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(2131492922);
JoH.fixActionBar(this);
}
@Override
protected void onResume() {
super.onResume();
setTitle(String.format(getResources().getString(2131755750), 45));
setupCharts();
}
public static List<PointValue> getTrendDataPoints(boolean z, long j, long j2) {
float f = (float) (z ? 1.0d : 0.0554994394556615d);
ArrayList<Float> latestBgForXMinutes = getLatestBgForXMinutes((int) ((j2 - j) / 60000));
if (latestBgForXMinutes == null) {
UserError.Log.e("LibreTrendGraph", "Error getting data from getLatestBgForXMinutes. Returning");
return null;
}
LibreTrendLatest libreTrendLatest = LibreTrendUtil.getInstance().getLibreTrendLatest();
if (libreTrendLatest == null || libreTrendLatest.getFactor() == BgReading.BESTOFFSET) {
UserError.Log.e("LibreTrendGraph", "libreBlock exists but libreTrendLatest.getFactor is zero ");
return null;
}
ArrayList arrayList = new ArrayList(latestBgForXMinutes.size());
Iterator<Float> it = latestBgForXMinutes.iterator();
long j3 = 0;
while (it.hasNext()) {
Float next = it.next();
if (next.floatValue() > 0.0f) {
long j4 = libreTrendLatest.timestamp - j3;
if (j4 <= j2 && j4 >= j) {
arrayList.add(new HPointValue(j4 / 30000.0d, next.floatValue() * f));
}
}
j3 += 60000;
}
return arrayList;
}
public void setupCharts() {
TextView textView = (TextView) findViewById(2131297064);
this.chart = findViewById(2131296707);
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
float f = (float) (this.doMgdl ? 1.0d : 0.0554994394556615d);
LibreBlock latestForTrend = LibreBlock.getLatestForTrend();
if (latestForTrend == null) {
textView.setText("No libre data to display");
setupEmptyCharts();
return;
}
String format = DateFormat.getDateTimeInstance(3, 3).format(new Date(latestForTrend.timestamp));
ArrayList<Float> latestBgForXMinutes = getLatestBgForXMinutes(45);
if (latestBgForXMinutes == null) {
textView.setText("Error displaying data for " + format);
setupEmptyCharts();
return;
}
textView.setText("Scan from " + format);
Iterator<Float> it = latestBgForXMinutes.iterator();
float f2 = 1000.0f;
int i = 0;
float f3 = 0.0f;
while (it.hasNext()) {
float floatValue = it.next().floatValue();
if (floatValue > 0.0f) {
if (f2 > floatValue) {
f2 = floatValue;
}
if (f3 < floatValue) {
f3 = floatValue;
}
arrayList2.add(new PointValue(-i, floatValue * f));
}
i++;
}
Line line = new Line(arrayList2);
int i2 = ChartUtils.COLOR_RED;
line.setColor(i2);
line.setHasLines(false);
line.setHasPoints(true);
line.setPointRadius(3);
arrayList.add(line);
if (f3 - f2 < 20.0f) {
float f4 = (f3 + f2) / 2.0f;
ArrayList arrayList3 = new ArrayList();
Line line2 = new Line(arrayList3);
arrayList3.add(new PointValue(0.0f, (f4 - 10.0f) * f));
arrayList3.add(new PointValue(0.0f, (f4 + 10.0f) * f));
line2.setColor(i2);
line2.setHasLines(false);
line2.setHasPoints(false);
arrayList.add(line2);
}
Axis axis = new Axis();
Axis hasLines = new Axis().setHasLines(true);
axis.setTextSize(16);
hasLines.setTextSize(16);
axis.setName("Time from last scan");
StringBuilder sb = new StringBuilder();
sb.append("Glucose ");
sb.append(this.doMgdl ? "mg/dl" : "mmol/l");
hasLines.setName(sb.toString());
LineChartData lineChartData = new LineChartData(arrayList);
this.data = lineChartData;
lineChartData.setAxisXBottom(axis);
this.data.setAxisYLeft(hasLines);
this.chart.setLineChartData(this.data);
}
void setupEmptyCharts() {
this.chart = findViewById(2131296707);
LineChartData lineChartData = new LineChartData(new ArrayList());
this.data = lineChartData;
this.chart.setLineChartData(lineChartData);
}
}