mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-29 12:05:53 +01:00
HPlus: Refactoring. Calendar -> GregorianCalendar
This commit is contained in:
parent
91b346b23d
commit
510427e30b
@ -4,7 +4,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
* @author João Paulo Barraca <jpbarraca@gmail.com>
|
||||
*/
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
|
||||
@ -33,7 +34,7 @@ public class HPlusDataRecordDay extends HPlusDataRecord {
|
||||
//?? data[6];
|
||||
secondsInactive = data[7] & 0xFF; // ?
|
||||
|
||||
int now = (int) (Calendar.getInstance().getTimeInMillis() / (3600 * 24 * 1000L));
|
||||
int now = (int) (GregorianCalendar.getInstance().getTimeInMillis() / (3600 * 24 * 1000L));
|
||||
timestamp = now * 3600 * 24 + (slot / 6 * 3600 + slot % 6 * 10);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
*/
|
||||
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
@ -26,7 +26,7 @@ class HPlusDataRecordRealtime extends HPlusDataRecord {
|
||||
throw new IllegalArgumentException("Invalid data packet");
|
||||
}
|
||||
|
||||
timestamp = (int) (Calendar.getInstance().getTimeInMillis() / 1000);
|
||||
timestamp = (int) (GregorianCalendar.getInstance().getTimeInMillis() / 1000);
|
||||
distance = 10 * ((data[4] & 0xFF) * 256 + (data[3] & 0xFF)); // meters
|
||||
|
||||
int x = (data[6] & 0xFF) * 256 + data[5] & 0xFF;
|
||||
|
@ -7,6 +7,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
@ -47,7 +48,7 @@ public class HPlusDataRecordSleep extends HPlusDataRecord {
|
||||
int hour = data[17] & 0xFF;
|
||||
int minute = data[18] & 0xFF;
|
||||
|
||||
Calendar sleepStart = Calendar.getInstance();
|
||||
Calendar sleepStart = GregorianCalendar.getInstance();
|
||||
sleepStart.set(Calendar.YEAR, year);
|
||||
sleepStart.set(Calendar.MONTH, month - 1);
|
||||
sleepStart.set(Calendar.DAY_OF_MONTH, day);
|
||||
@ -61,9 +62,6 @@ public class HPlusDataRecordSleep extends HPlusDataRecord {
|
||||
lightSleepMinutes = enterSleepMinutes + spindleMinutes + remSleepMinutes;
|
||||
|
||||
timestamp = bedTimeStart;
|
||||
|
||||
Calendar sleepEnd = Calendar.getInstance();
|
||||
sleepEnd.setTimeInMillis(bedTimeEnd * 1000L);
|
||||
}
|
||||
|
||||
public List<RecordInterval> getIntervals() {
|
||||
|
@ -6,6 +6,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@ -45,7 +46,7 @@ class HPlusDataRecordSteps extends HPlusDataRecord{
|
||||
maxHeartRate = data[15] & 0xFF;
|
||||
minHeartRate = data[16] & 0xFF;
|
||||
|
||||
Calendar date = Calendar.getInstance();
|
||||
Calendar date = GregorianCalendar.getInstance();
|
||||
date.set(Calendar.YEAR, year);
|
||||
date.set(Calendar.MONTH, month - 1);
|
||||
date.set(Calendar.DAY_OF_MONTH, day);
|
||||
|
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -46,17 +47,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
private int mLastSlotReceived = 0;
|
||||
private int mLastSlotRequested = 0;
|
||||
|
||||
private Calendar mLastSleepDayReceived = Calendar.getInstance();
|
||||
|
||||
private Calendar mHelloTime = Calendar.getInstance();
|
||||
|
||||
private Calendar mGetDaySlotsTime = Calendar.getInstance();
|
||||
private Calendar mGetSleepTime = Calendar.getInstance();
|
||||
|
||||
private final Object waitObject = new Object();
|
||||
private Calendar mLastSleepDayReceived = GregorianCalendar.getInstance();
|
||||
private Calendar mHelloTime = GregorianCalendar.getInstance();
|
||||
private Calendar mGetDaySlotsTime = GregorianCalendar.getInstance();
|
||||
private Calendar mGetSleepTime = GregorianCalendar.getInstance();
|
||||
|
||||
private HPlusDataRecordRealtime prevRealTimeRecord = null;
|
||||
|
||||
private final Object waitObject = new Object();
|
||||
|
||||
public HPlusHandlerThread(GBDevice gbDevice, Context context, HPlusSupport hplusSupport) {
|
||||
super(gbDevice, context);
|
||||
|
||||
@ -92,7 +91,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
break;
|
||||
}
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
|
||||
if (now.compareTo(mHelloTime) > 0) {
|
||||
sendHello();
|
||||
@ -106,7 +105,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
requestNextSleepData();
|
||||
}
|
||||
|
||||
now = Calendar.getInstance();
|
||||
now = GregorianCalendar.getInstance();
|
||||
waitTime = Math.min(Math.min(mGetDaySlotsTime.getTimeInMillis(), mGetSleepTime.getTimeInMillis()), mHelloTime.getTimeInMillis()) - now.getTimeInMillis();
|
||||
}
|
||||
|
||||
@ -151,7 +150,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
}
|
||||
|
||||
public void scheduleHello(){
|
||||
mHelloTime = Calendar.getInstance();
|
||||
mHelloTime = GregorianCalendar.getInstance();
|
||||
mHelloTime.add(Calendar.SECOND, HELLO_INTERVAL);
|
||||
}
|
||||
|
||||
@ -211,8 +210,8 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
|
||||
byte nextMinute = 0;
|
||||
|
||||
if (nextHour == (byte) Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
nextMinute = (byte) Calendar.getInstance().get(Calendar.MINUTE);
|
||||
if (nextHour == (byte) GregorianCalendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
nextMinute = (byte) GregorianCalendar.getInstance().get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
byte minute = (byte) ((mLastSlotReceived % 6) * 10);
|
||||
@ -223,15 +222,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
LOG.debug("Reached End of the Day");
|
||||
mLastSlotRequested = 0;
|
||||
mLastSlotReceived = 0;
|
||||
mGetDaySlotsTime = Calendar.getInstance();
|
||||
mGetDaySlotsTime = GregorianCalendar.getInstance();
|
||||
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextHour > Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
if (nextHour > GregorianCalendar.getInstance().get(GregorianCalendar.HOUR_OF_DAY)) {
|
||||
LOG.debug("Day data is up to date");
|
||||
mGetDaySlotsTime = Calendar.getInstance();
|
||||
mGetDaySlotsTime = GregorianCalendar.getInstance();
|
||||
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD);
|
||||
return;
|
||||
}
|
||||
@ -243,7 +242,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
builder.write(mHPlusSupport.ctrlCharacteristic, msg);
|
||||
builder.queue(mHPlusSupport.getQueue());
|
||||
|
||||
mGetDaySlotsTime = Calendar.getInstance();
|
||||
mGetDaySlotsTime = GregorianCalendar.getInstance();
|
||||
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_RETRY_PERIOD);
|
||||
}
|
||||
|
||||
@ -298,15 +297,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
LOG.debug(ex.getMessage());
|
||||
}
|
||||
|
||||
mGetSleepTime = Calendar.getInstance();
|
||||
mGetSleepTime.add(Calendar.SECOND, SLEEP_SYNC_PERIOD);
|
||||
mGetSleepTime = GregorianCalendar.getInstance();
|
||||
mGetSleepTime.add(GregorianCalendar.SECOND, SLEEP_SYNC_PERIOD);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void requestNextSleepData() {
|
||||
mGetSleepTime = Calendar.getInstance();
|
||||
mGetSleepTime.add(Calendar.SECOND, SLEEP_RETRY_PERIOD);
|
||||
mGetSleepTime = GregorianCalendar.getInstance();
|
||||
mGetSleepTime.add(GregorianCalendar.SECOND, SLEEP_RETRY_PERIOD);
|
||||
|
||||
TransactionBuilder builder = new TransactionBuilder("requestSleepStats");
|
||||
builder.write(mHPlusSupport.ctrlCharacteristic, new byte[]{HPlusConstants.CMD_GET_SLEEP});
|
||||
|
@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
||||
@ -207,7 +208,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private HPlusSupport setCurrentDate(TransactionBuilder transaction) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Calendar c = GregorianGregorianCalendar.getInstance();
|
||||
int year = c.get(Calendar.YEAR) - 1900;
|
||||
int month = c.get(Calendar.MONTH);
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
@ -224,7 +225,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private HPlusSupport setCurrentTime(TransactionBuilder transaction) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Calendar c = GregorianCalendar.getInstance();
|
||||
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_TIME,
|
||||
@ -238,7 +239,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
|
||||
private HPlusSupport setDayOfWeek(TransactionBuilder transaction) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Calendar c = GregorianCalendar.getInstance();
|
||||
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_WEEK,
|
||||
@ -252,7 +253,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
int startTime = HPlusCoordinator.getSITStartTime(getDevice().getAddress());
|
||||
int endTime = HPlusCoordinator.getSITEndTime(getDevice().getAddress());
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_SIT_INTERVAL,
|
||||
|
Loading…
Reference in New Issue
Block a user