use of com.huami.watch.transport.TransportDataItem 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.huami.watch.transport.TransportDataItem 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);
}
Aggregations