1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

HPlus: Refactoring. Calendar -> GregorianCalendar

This commit is contained in:
João Paulo Barraca 2017-01-04 23:41:35 +00:00
parent 91b346b23d
commit 510427e30b
6 changed files with 34 additions and 34 deletions

View File

@ -4,7 +4,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
* @author João Paulo Barraca <jpbarraca@gmail.com> * @author João Paulo Barraca <jpbarraca@gmail.com>
*/ */
import java.util.Calendar; import java.util.GregorianCalendar;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
@ -33,7 +34,7 @@ public class HPlusDataRecordDay extends HPlusDataRecord {
//?? data[6]; //?? data[6];
secondsInactive = data[7] & 0xFF; // ? 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); timestamp = now * 3600 * 24 + (slot / 6 * 3600 + slot % 6 * 10);
} }

View File

@ -5,7 +5,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
*/ */
import java.util.Calendar; import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
@ -26,7 +26,7 @@ class HPlusDataRecordRealtime extends HPlusDataRecord {
throw new IllegalArgumentException("Invalid data packet"); 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 distance = 10 * ((data[4] & 0xFF) * 256 + (data[3] & 0xFF)); // meters
int x = (data[6] & 0xFF) * 256 + data[5] & 0xFF; int x = (data[6] & 0xFF) * 256 + data[5] & 0xFF;

View File

@ -7,6 +7,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
@ -47,7 +48,7 @@ public class HPlusDataRecordSleep extends HPlusDataRecord {
int hour = data[17] & 0xFF; int hour = data[17] & 0xFF;
int minute = data[18] & 0xFF; int minute = data[18] & 0xFF;
Calendar sleepStart = Calendar.getInstance(); Calendar sleepStart = GregorianCalendar.getInstance();
sleepStart.set(Calendar.YEAR, year); sleepStart.set(Calendar.YEAR, year);
sleepStart.set(Calendar.MONTH, month - 1); sleepStart.set(Calendar.MONTH, month - 1);
sleepStart.set(Calendar.DAY_OF_MONTH, day); sleepStart.set(Calendar.DAY_OF_MONTH, day);
@ -61,9 +62,6 @@ public class HPlusDataRecordSleep extends HPlusDataRecord {
lightSleepMinutes = enterSleepMinutes + spindleMinutes + remSleepMinutes; lightSleepMinutes = enterSleepMinutes + spindleMinutes + remSleepMinutes;
timestamp = bedTimeStart; timestamp = bedTimeStart;
Calendar sleepEnd = Calendar.getInstance();
sleepEnd.setTimeInMillis(bedTimeEnd * 1000L);
} }
public List<RecordInterval> getIntervals() { public List<RecordInterval> getIntervals() {

View File

@ -6,6 +6,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
@ -45,7 +46,7 @@ class HPlusDataRecordSteps extends HPlusDataRecord{
maxHeartRate = data[15] & 0xFF; maxHeartRate = data[15] & 0xFF;
minHeartRate = data[16] & 0xFF; minHeartRate = data[16] & 0xFF;
Calendar date = Calendar.getInstance(); Calendar date = GregorianCalendar.getInstance();
date.set(Calendar.YEAR, year); date.set(Calendar.YEAR, year);
date.set(Calendar.MONTH, month - 1); date.set(Calendar.MONTH, month - 1);
date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.DAY_OF_MONTH, day);

View File

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -46,17 +47,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
private int mLastSlotReceived = 0; private int mLastSlotReceived = 0;
private int mLastSlotRequested = 0; private int mLastSlotRequested = 0;
private Calendar mLastSleepDayReceived = Calendar.getInstance(); private Calendar mLastSleepDayReceived = GregorianCalendar.getInstance();
private Calendar mHelloTime = GregorianCalendar.getInstance();
private Calendar mHelloTime = Calendar.getInstance(); private Calendar mGetDaySlotsTime = GregorianCalendar.getInstance();
private Calendar mGetSleepTime = GregorianCalendar.getInstance();
private Calendar mGetDaySlotsTime = Calendar.getInstance();
private Calendar mGetSleepTime = Calendar.getInstance();
private final Object waitObject = new Object();
private HPlusDataRecordRealtime prevRealTimeRecord = null; private HPlusDataRecordRealtime prevRealTimeRecord = null;
private final Object waitObject = new Object();
public HPlusHandlerThread(GBDevice gbDevice, Context context, HPlusSupport hplusSupport) { public HPlusHandlerThread(GBDevice gbDevice, Context context, HPlusSupport hplusSupport) {
super(gbDevice, context); super(gbDevice, context);
@ -92,7 +91,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
break; break;
} }
Calendar now = Calendar.getInstance(); Calendar now = GregorianCalendar.getInstance();
if (now.compareTo(mHelloTime) > 0) { if (now.compareTo(mHelloTime) > 0) {
sendHello(); sendHello();
@ -106,7 +105,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
requestNextSleepData(); requestNextSleepData();
} }
now = Calendar.getInstance(); now = GregorianCalendar.getInstance();
waitTime = Math.min(Math.min(mGetDaySlotsTime.getTimeInMillis(), mGetSleepTime.getTimeInMillis()), mHelloTime.getTimeInMillis()) - now.getTimeInMillis(); waitTime = Math.min(Math.min(mGetDaySlotsTime.getTimeInMillis(), mGetSleepTime.getTimeInMillis()), mHelloTime.getTimeInMillis()) - now.getTimeInMillis();
} }
@ -151,7 +150,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
} }
public void scheduleHello(){ public void scheduleHello(){
mHelloTime = Calendar.getInstance(); mHelloTime = GregorianCalendar.getInstance();
mHelloTime.add(Calendar.SECOND, HELLO_INTERVAL); mHelloTime.add(Calendar.SECOND, HELLO_INTERVAL);
} }
@ -211,8 +210,8 @@ class HPlusHandlerThread extends GBDeviceIoThread {
byte nextMinute = 0; byte nextMinute = 0;
if (nextHour == (byte) Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) { if (nextHour == (byte) GregorianCalendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
nextMinute = (byte) Calendar.getInstance().get(Calendar.MINUTE); nextMinute = (byte) GregorianCalendar.getInstance().get(Calendar.MINUTE);
} }
byte minute = (byte) ((mLastSlotReceived % 6) * 10); byte minute = (byte) ((mLastSlotReceived % 6) * 10);
@ -223,15 +222,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
LOG.debug("Reached End of the Day"); LOG.debug("Reached End of the Day");
mLastSlotRequested = 0; mLastSlotRequested = 0;
mLastSlotReceived = 0; mLastSlotReceived = 0;
mGetDaySlotsTime = Calendar.getInstance(); mGetDaySlotsTime = GregorianCalendar.getInstance();
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD); mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD);
return; 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"); LOG.debug("Day data is up to date");
mGetDaySlotsTime = Calendar.getInstance(); mGetDaySlotsTime = GregorianCalendar.getInstance();
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD); mGetDaySlotsTime.add(Calendar.SECOND, SYNC_PERIOD);
return; return;
} }
@ -243,7 +242,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
builder.write(mHPlusSupport.ctrlCharacteristic, msg); builder.write(mHPlusSupport.ctrlCharacteristic, msg);
builder.queue(mHPlusSupport.getQueue()); builder.queue(mHPlusSupport.getQueue());
mGetDaySlotsTime = Calendar.getInstance(); mGetDaySlotsTime = GregorianCalendar.getInstance();
mGetDaySlotsTime.add(Calendar.SECOND, SYNC_RETRY_PERIOD); mGetDaySlotsTime.add(Calendar.SECOND, SYNC_RETRY_PERIOD);
} }
@ -298,15 +297,15 @@ class HPlusHandlerThread extends GBDeviceIoThread {
LOG.debug(ex.getMessage()); LOG.debug(ex.getMessage());
} }
mGetSleepTime = Calendar.getInstance(); mGetSleepTime = GregorianCalendar.getInstance();
mGetSleepTime.add(Calendar.SECOND, SLEEP_SYNC_PERIOD); mGetSleepTime.add(GregorianCalendar.SECOND, SLEEP_SYNC_PERIOD);
return true; return true;
} }
private void requestNextSleepData() { private void requestNextSleepData() {
mGetSleepTime = Calendar.getInstance(); mGetSleepTime = GregorianCalendar.getInstance();
mGetSleepTime.add(Calendar.SECOND, SLEEP_RETRY_PERIOD); mGetSleepTime.add(GregorianCalendar.SECOND, SLEEP_RETRY_PERIOD);
TransactionBuilder builder = new TransactionBuilder("requestSleepStats"); TransactionBuilder builder = new TransactionBuilder("requestSleepStats");
builder.write(mHPlusSupport.ctrlCharacteristic, new byte[]{HPlusConstants.CMD_GET_SLEEP}); builder.write(mHPlusSupport.ctrlCharacteristic, new byte[]{HPlusConstants.CMD_GET_SLEEP});

View File

@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants; import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
@ -207,7 +208,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
} }
private HPlusSupport setCurrentDate(TransactionBuilder transaction) { private HPlusSupport setCurrentDate(TransactionBuilder transaction) {
Calendar c = Calendar.getInstance(); Calendar c = GregorianGregorianCalendar.getInstance();
int year = c.get(Calendar.YEAR) - 1900; int year = c.get(Calendar.YEAR) - 1900;
int month = c.get(Calendar.MONTH); int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH); int day = c.get(Calendar.DAY_OF_MONTH);
@ -224,7 +225,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
} }
private HPlusSupport setCurrentTime(TransactionBuilder transaction) { private HPlusSupport setCurrentTime(TransactionBuilder transaction) {
Calendar c = Calendar.getInstance(); Calendar c = GregorianCalendar.getInstance();
transaction.write(ctrlCharacteristic, new byte[]{ transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_TIME, HPlusConstants.CMD_SET_TIME,
@ -238,7 +239,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setDayOfWeek(TransactionBuilder transaction) { private HPlusSupport setDayOfWeek(TransactionBuilder transaction) {
Calendar c = Calendar.getInstance(); Calendar c = GregorianCalendar.getInstance();
transaction.write(ctrlCharacteristic, new byte[]{ transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_WEEK, HPlusConstants.CMD_SET_WEEK,
@ -252,7 +253,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
int startTime = HPlusCoordinator.getSITStartTime(getDevice().getAddress()); int startTime = HPlusCoordinator.getSITStartTime(getDevice().getAddress());
int endTime = HPlusCoordinator.getSITEndTime(getDevice().getAddress()); int endTime = HPlusCoordinator.getSITEndTime(getDevice().getAddress());
Calendar now = Calendar.getInstance(); Calendar now = GregorianCalendar.getInstance();
transaction.write(ctrlCharacteristic, new byte[]{ transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_SIT_INTERVAL, HPlusConstants.CMD_SET_SIT_INTERVAL,