From cb1ec5dccb72be35e01f7067c49717a5fa5e233b Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 24 May 2016 13:11:57 +0200 Subject: [PATCH] Make calendar event type byte instead of int Now the UUID will be constructed like this: High 64bit 0x4742474200 | type Low 64bit id --- .../freeyourgadget/gadgetbridge/devices/EventHandler.java | 2 +- .../freeyourgadget/gadgetbridge/impl/GBDeviceService.java | 2 +- .../gadgetbridge/model/CalendarEventSpec.java | 8 ++++---- .../gadgetbridge/service/DeviceCommunicationService.java | 4 ++-- .../gadgetbridge/service/ServiceDeviceSupport.java | 2 +- .../service/devices/miband/MiBandSupport.java | 2 +- .../service/devices/pebble/PebbleProtocol.java | 8 +++++--- .../service/devices/pebble/PebbleSupport.java | 2 +- .../service/serial/AbstractSerialDeviceSupport.java | 2 +- .../gadgetbridge/service/serial/GBDeviceProtocol.java | 2 +- .../gadgetbridge/service/TestDeviceSupport.java | 2 +- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java index d4f44101f..602ca5c85 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java @@ -55,5 +55,5 @@ public interface EventHandler { void onAddCalendarEvent(CalendarEventSpec calendarEventSpec); - void onDeleteCalendarEvent(int type, long id); + void onDeleteCalendarEvent(byte type, long id); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java index 6c51e6b29..2e598eacf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -238,7 +238,7 @@ public class GBDeviceService implements DeviceService { } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { Intent intent = createIntent().setAction(ACTION_DELETE_CALENDAREVENT) .putExtra(EXTRA_CALENDAREVENT_TYPE, type) .putExtra(EXTRA_CALENDAREVENT_ID, id); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEventSpec.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEventSpec.java index 7f52b2a2d..438123e49 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEventSpec.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEventSpec.java @@ -1,11 +1,11 @@ package nodomain.freeyourgadget.gadgetbridge.model; public class CalendarEventSpec { - public static final int TYPE_UNKNOWN = 0; - public static final int TYPE_SUNRISE = 1; - public static final int TYPE_SUNSET = 2; + public static final byte TYPE_UNKNOWN = 0; + public static final byte TYPE_SUNRISE = 1; + public static final byte TYPE_SUNSET = 2; - public int type; + public byte type; public long id; public int timestamp; public int durationInSeconds; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index ed7edc018..fdafa5265 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -282,7 +282,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere case ACTION_ADD_CALENDAREVENT: { CalendarEventSpec calendarEventSpec = new CalendarEventSpec(); calendarEventSpec.id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1); - calendarEventSpec.type = intent.getIntExtra(EXTRA_CALENDAREVENT_TYPE, -1); + calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1); calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1); calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1); calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE); @@ -292,7 +292,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere } case ACTION_DELETE_CALENDAREVENT: { long id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1); - int type = intent.getIntExtra(EXTRA_CALENDAREVENT_TYPE, -1); + byte type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1); mDeviceSupport.onDeleteCalendarEvent(type, id); break; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 6753f27e1..019722b54 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -279,7 +279,7 @@ public class ServiceDeviceSupport implements DeviceSupport { } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { if (checkBusy("delete calendar event")) { return; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index ea2d4d7cf..444e59ee9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -389,7 +389,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { // not supported } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index a3e4b02cd..9901f85ec 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -241,6 +241,8 @@ public class PebbleProtocol extends GBDeviceProtocol { static final byte LENGTH_UUID = 16; + static final long GB_UUID_MASK = 0x4742474200L; + // base is -5 private static final String[] hwRevisions = { // Emulator @@ -479,12 +481,12 @@ public class PebbleProtocol extends GBDeviceProtocol { iconId = PebbleIconID.TIMELINE_CALENDAR; } - return encodeTimelinePin(new UUID(calendarEventSpec.type, id), calendarEventSpec.timestamp, (short) calendarEventSpec.durationInSeconds, iconId, calendarEventSpec.title, calendarEventSpec.description); + return encodeTimelinePin(new UUID(GB_UUID_MASK | calendarEventSpec.type, id), calendarEventSpec.timestamp, (short) calendarEventSpec.durationInSeconds, iconId, calendarEventSpec.title, calendarEventSpec.description); } @Override - public byte[] encodeDeleteCalendarEvent(int type, long id) { - return encodeBlobdb(new UUID(type, id), BLOBDB_DELETE, BLOBDB_PIN, null); + public byte[] encodeDeleteCalendarEvent(byte type, long id) { + return encodeBlobdb(new UUID(GB_UUID_MASK | type, id), BLOBDB_DELETE, BLOBDB_PIN, null); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java index 9414f0653..b0bc3b47d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java @@ -129,7 +129,7 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { if (reconnect()) { super.onDeleteCalendarEvent(type, id); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java index 18be585d9..78e15667d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java @@ -196,7 +196,7 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { byte[] bytes = gbDeviceProtocol.encodeDeleteCalendarEvent(type, id); sendToDevice(bytes); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java index 79337b5d2..a226c0947 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java @@ -70,7 +70,7 @@ public abstract class GBDeviceProtocol { return null; } - public byte[] encodeDeleteCalendarEvent(int type, long id) { + public byte[] encodeDeleteCalendarEvent(byte type, long id) { return null; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java index 45eea6ebf..8070cb1eb 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java @@ -137,7 +137,7 @@ public class TestDeviceSupport extends AbstractDeviceSupport { } @Override - public void onDeleteCalendarEvent(int type, long id) { + public void onDeleteCalendarEvent(byte type, long id) { }