Search in sources :

Example 1 with TransportDataItem

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);
    }
}
Also used : BatteryRead(com.edotasx.amazfit.db.model.BatteryRead) BatteryInfo(com.huami.watch.companion.battery.bean.BatteryInfo) TransportDataItem(com.huami.watch.transport.TransportDataItem) Transporter(com.huami.watch.transport.Transporter)

Example 2 with TransportDataItem

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);
}
Also used : BatteryRead(com.edotasx.amazfit.db.model.BatteryRead) BatteryInfo(com.huami.watch.companion.battery.bean.BatteryInfo) TransportDataItem(com.huami.watch.transport.TransportDataItem) Transporter(com.huami.watch.transport.Transporter)

Aggregations

BatteryRead (com.edotasx.amazfit.db.model.BatteryRead)2 BatteryInfo (com.huami.watch.companion.battery.bean.BatteryInfo)2 TransportDataItem (com.huami.watch.transport.TransportDataItem)2 Transporter (com.huami.watch.transport.Transporter)2