use of com.edotasx.amazfit.db.model.BatteryRead in project AmazMod by edotassi.
the class BatteryChartCard method updateChart.
private void updateChart() {
final List<Entry> yValues = new ArrayList<Entry>();
final List<Integer> colors = new ArrayList<>();
final int days = PreferenceManager.getInt(getContext(), Constants.PREFERENCE_BATTERY_CHART_RANGE, 5);
Calendar calendar = Calendar.getInstance();
long highX = calendar.getTimeInMillis();
calendar.add(Calendar.DATE, -1 * days);
long lowX = calendar.getTimeInMillis();
List<BatteryRead> batteryReadList = SQLite.select().from(BatteryRead.class).where(BatteryRead_Table.date.greaterThan(lowX)).queryList();
BatteryRead prevRead = null;
for (int i = 0; i < batteryReadList.size(); i++) {
BatteryRead read = batteryReadList.get(i);
if ((read.getLevel() > 0) && ((prevRead == null) || (read.getLevel() != prevRead.getLevel()))) {
Entry entry = new Entry(read.getDate(), read.getLevel());
yValues.add(entry);
colors.add(Color.parseColor(read.isCharging() ? "#00E676" : "#3F51B5"));
}
prevRead = read;
}
if (yValues.size() == 0) {
return;
}
LineDataSet lineDataSet = new LineDataSet(yValues, "Battery");
lineDataSet.setLineWidth(1.5f);
lineDataSet.setDrawCircleHole(false);
lineDataSet.setDrawCircles(false);
lineDataSet.setDrawValues(false);
Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fade_blue_battery);
lineDataSet.setDrawFilled(true);
lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
lineDataSet.setFillDrawable(drawable);
lineDataSet.setColors(colors);
lineDataSet.setMode(LineDataSet.Mode.LINEAR);
lineDataSet.setCubicIntensity(0.05f);
Description description = new Description();
description.setText("");
chart.setDescription(description);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setLabelRotationAngle(-45);
xAxis.setTextSize(8);
xAxis.setAxisMinimum(lowX);
xAxis.setAxisMaximum(highX);
final Calendar now = Calendar.getInstance();
final SimpleDateFormat simpleDateFormatHours = new SimpleDateFormat("HH");
final SimpleDateFormat simpleDateFormatHoursMinutes = new SimpleDateFormat("HH:mm");
final SimpleDateFormat simpleDateFormatDateMonth = new SimpleDateFormat("dd/MM");
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((long) value);
Date date = calendar.getTime();
if ((days > 1) || (now.get(Calendar.DATE) != calendar.get(Calendar.DATE))) {
int minutes = calendar.get(Calendar.MINUTE);
if (minutes > 30) {
calendar.add(Calendar.HOUR, 1);
}
return simpleDateFormatHours.format(date) + "\n" + simpleDateFormatDateMonth.format(date);
} else {
return simpleDateFormatHoursMinutes.format(calendar.getTime()) + "\n" + simpleDateFormatDateMonth.format(calendar.getTime());
}
}
});
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setDrawAxisLine(true);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(true);
leftAxis.setAxisMinimum(0);
leftAxis.setAxisMaximum(100);
chart.getAxisRight().setEnabled(false);
chart.getLegend().setEnabled(false);
chart.setTouchEnabled(false);
chart.setXAxisRenderer(new CustomXAxisRenderer(chart.getViewPortHandler(), chart.getXAxis(), chart.getTransformer(YAxis.AxisDependency.LEFT)));
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
chart.invalidate();
}
use of com.edotasx.amazfit.db.model.BatteryRead in project AmazMod by edotassi.
the class NotificationManager method updateBatteryLevel.
private void updateBatteryLevel() {
if (PreferenceManager.getBoolean(context, Constants.PREFERENCE_DISABLE_BATTERY_CHART, false)) {
return;
}
int intervalWithNotifications = 1000 * 60 * PreferenceManager.getInt(context, Constants.PREFERENCE_BATTERY_SYNC_WITH_NOTIFICATIONS, 5);
if ((lastNotificationTime == -1) || (System.currentTimeMillis() - lastNotificationTime) > intervalWithNotifications) {
Log.d("BatteryAlarm", "notification trigger");
if (transporter == null) {
transporter = Transporter.get(context, "com.huami.watch.companion");
dataListener = new Transporter.DataListener() {
@Override
public void onDataReceived(TransportDataItem transportDataItem) {
String action = transportDataItem.getAction();
Log.d("BatteryAlarm", "action: " + action);
if ("com.huami.watch.companion.transport.SyncBattery".equals(action)) {
BatteryInfo batteryInfo = BatteryInfoHelper.getBatteryInfo(transportDataItem.getData());
Log.d("BatteryAlarm", "batteryLvl: " + batteryInfo.getBatteryLevel());
FlowManager.init(context);
BatteryRead batteryRead = new BatteryRead();
batteryRead.setDate(System.currentTimeMillis());
batteryRead.setLevel(batteryInfo.getBatteryLevel());
batteryRead.setCharging(batteryInfo.isBatteryCharging());
FlowManager.getModelAdapter(BatteryRead.class).insert(batteryRead);
transporter.removeDataListener(dataListener);
}
}
};
transporter.addDataListener(dataListener);
transporter.connectTransportService();
}
SyncUtil.syncRequestBattery(transporter, true);
}
}
use of com.edotasx.amazfit.db.model.BatteryRead in project AmazMod by edotassi.
the class BatteryStatsReceiver method onReceive.
@Override
public void onReceive(final Context context, Intent intent) {
Log.d("BatteryAlarm", "onReceive");
if (transporter == null) {
transporter = Transporter.get(context, "com.huami.watch.companion");
dataListener = new Transporter.DataListener() {
@Override
public void onDataReceived(TransportDataItem transportDataItem) {
String action = transportDataItem.getAction();
Log.d("BatteryAlarm", "action: " + action);
if ("com.huami.watch.companion.transport.SyncBattery".equals(action)) {
BatteryInfo batteryInfo = BatteryInfoHelper.getBatteryInfo(transportDataItem.getData());
Log.d("BatteryAlarm", "batteryLvl: " + batteryInfo.getBatteryLevel());
FlowManager.init(context);
BatteryRead batteryRead = new BatteryRead();
batteryRead.setDate(System.currentTimeMillis());
batteryRead.setLevel(batteryInfo.getBatteryLevel());
batteryRead.setCharging(batteryInfo.isBatteryCharging());
FlowManager.getModelAdapter(BatteryRead.class).insert(batteryRead);
transporter.removeDataListener(dataListener);
}
}
};
transporter.addDataListener(dataListener);
}
SyncUtil.syncRequestBattery(transporter, true);
}
use of com.edotasx.amazfit.db.model.BatteryRead in project AmazMod by edotassi.
the class BatteryCard method updateBatteryViews.
@DexWrap
public void updateBatteryViews(BatteryInfo batteryInfo) {
updateBatteryViews(batteryInfo);
BatteryRead batteryRead = new BatteryRead();
batteryRead.setDate(System.currentTimeMillis());
batteryRead.setLevel(batteryInfo.getBatteryLevel());
batteryRead.setCharging(batteryInfo.isBatteryCharging());
FlowManager.getModelAdapter(BatteryRead.class).insert(batteryRead);
Log.d("BatteryChart", "level: " + batteryInfo.getBatteryLevel());
RxBus.get().post(new BatteryHistoryUpdatedEvent());
}
Aggregations