mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-02-04 04:54:10 +01:00
Pebble: send sunrise/sunset to watch for today and tomorrow, also delete previous timeline pins
This commit is contained in:
parent
017f650b3f
commit
4bd578ebea
@ -231,33 +231,50 @@ public class DebugActivity extends GBActivity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
GBApplication.deviceService().onSetTime();
|
GBApplication.deviceService().onSetTime();
|
||||||
|
|
||||||
//FIXME: dont do it here, make another button
|
//FIXME: dont do it here, and make another button
|
||||||
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, 1);
|
||||||
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, 3);
|
||||||
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, 2);
|
||||||
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, 4);
|
||||||
|
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
float latitude = prefs.getFloat("location_latitude", 0);
|
float latitude = prefs.getFloat("location_latitude", 0);
|
||||||
float longitude = prefs.getFloat("location_longitude", 0);
|
float longitude = prefs.getFloat("location_longitude", 0);
|
||||||
final GregorianCalendar dateTime = new GregorianCalendar();
|
final GregorianCalendar dateTimeToday = new GregorianCalendar();
|
||||||
GregorianCalendar[] sunriseTransitSet = SPA.calculateSunriseTransitSet(dateTime, latitude, longitude, DeltaT.estimate(dateTime));
|
final GregorianCalendar dateTimeTomorrow = new GregorianCalendar();
|
||||||
|
dateTimeTomorrow.add(GregorianCalendar.DAY_OF_MONTH, 1);
|
||||||
|
|
||||||
if (sunriseTransitSet[0] != null) {
|
GregorianCalendar[] sunriseTransitSetToday = SPA.calculateSunriseTransitSet(dateTimeToday, latitude, longitude, DeltaT.estimate(dateTimeToday));
|
||||||
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
GregorianCalendar[] sunriseTransitSetTomorrow = SPA.calculateSunriseTransitSet(dateTimeTomorrow, latitude, longitude, DeltaT.estimate(dateTimeToday));
|
||||||
calendarEventSpec.id = -1;
|
|
||||||
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNRISE;
|
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
||||||
calendarEventSpec.timestamp = (int) (sunriseTransitSet[0].getTimeInMillis() / 1000);
|
calendarEventSpec.durationInSeconds = 0;
|
||||||
calendarEventSpec.durationInSeconds = 0;
|
calendarEventSpec.description = null;
|
||||||
calendarEventSpec.title = "Sunrise";
|
|
||||||
calendarEventSpec.description = null;
|
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNRISE;
|
||||||
|
calendarEventSpec.title = "Sunrise";
|
||||||
|
if (sunriseTransitSetToday[0] != null) {
|
||||||
|
calendarEventSpec.id = 1;
|
||||||
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetToday[0].getTimeInMillis() / 1000);
|
||||||
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
||||||
}
|
}
|
||||||
if (sunriseTransitSet[2] != null) {
|
if (sunriseTransitSetTomorrow[0] != null) {
|
||||||
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
calendarEventSpec.id = 2;
|
||||||
calendarEventSpec.id = -1;
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[0].getTimeInMillis() / 1000);
|
||||||
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNSET;
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
||||||
calendarEventSpec.timestamp = (int) (sunriseTransitSet[2].getTimeInMillis() / 1000);
|
}
|
||||||
calendarEventSpec.durationInSeconds = 0;
|
|
||||||
calendarEventSpec.title = "Sunset";
|
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNSET;
|
||||||
calendarEventSpec.description = null;
|
calendarEventSpec.title = "Sunset";
|
||||||
|
if (sunriseTransitSetToday[2] != null) {
|
||||||
|
calendarEventSpec.id = 1;
|
||||||
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetToday[2].getTimeInMillis() / 1000);
|
||||||
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
||||||
|
}
|
||||||
|
if (sunriseTransitSetTomorrow[2] != null) {
|
||||||
|
calendarEventSpec.id = 2;
|
||||||
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[2].getTimeInMillis() / 1000);
|
||||||
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,6 @@ public interface EventHandler {
|
|||||||
void onEnableHeartRateSleepSupport(boolean enable);
|
void onEnableHeartRateSleepSupport(boolean enable);
|
||||||
|
|
||||||
void onAddCalendarEvent(CalendarEventSpec calendarEventSpec);
|
void onAddCalendarEvent(CalendarEventSpec calendarEventSpec);
|
||||||
|
|
||||||
|
void onDeleteCalendarEvent(int type, long id);
|
||||||
}
|
}
|
||||||
|
@ -236,4 +236,12 @@ public class GBDeviceService implements DeviceService {
|
|||||||
.putExtra(EXTRA_CALENDAREVENT_DESCRIPTION, calendarEventSpec.description);
|
.putExtra(EXTRA_CALENDAREVENT_DESCRIPTION, calendarEventSpec.description);
|
||||||
invokeService(intent);
|
invokeService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
Intent intent = createIntent().setAction(ACTION_DELETE_CALENDAREVENT)
|
||||||
|
.putExtra(EXTRA_CALENDAREVENT_TYPE, type)
|
||||||
|
.putExtra(EXTRA_CALENDAREVENT_ID, id);
|
||||||
|
invokeService(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT = PREFIX + ".action.enable_heartrate_sleep_support";
|
String ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT = PREFIX + ".action.enable_heartrate_sleep_support";
|
||||||
String ACTION_HEARTRATE_MEASUREMENT = PREFIX + ".action.hr_measurement";
|
String ACTION_HEARTRATE_MEASUREMENT = PREFIX + ".action.hr_measurement";
|
||||||
String ACTION_ADD_CALENDAREVENT = PREFIX + ".action.add_calendarevent";
|
String ACTION_ADD_CALENDAREVENT = PREFIX + ".action.add_calendarevent";
|
||||||
|
String ACTION_DELETE_CALENDAREVENT = PREFIX + ".action.delete_calendarevent";
|
||||||
String EXTRA_DEVICE_ADDRESS = "device_address";
|
String EXTRA_DEVICE_ADDRESS = "device_address";
|
||||||
String EXTRA_NOTIFICATION_BODY = "notification_body";
|
String EXTRA_NOTIFICATION_BODY = "notification_body";
|
||||||
String EXTRA_NOTIFICATION_FLAGS = "notification_flags";
|
String EXTRA_NOTIFICATION_FLAGS = "notification_flags";
|
||||||
|
@ -47,6 +47,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_AP
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETE_CALENDAREVENT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DISCONNECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DISCONNECT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT;
|
||||||
@ -284,6 +285,12 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
|
mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTION_DELETE_CALENDAREVENT: {
|
||||||
|
long id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1);
|
||||||
|
int type = intent.getIntExtra(EXTRA_CALENDAREVENT_TYPE, -1);
|
||||||
|
mDeviceSupport.onDeleteCalendarEvent(type, id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ACTION_REBOOT: {
|
case ACTION_REBOOT: {
|
||||||
mDeviceSupport.onReboot();
|
mDeviceSupport.onReboot();
|
||||||
break;
|
break;
|
||||||
|
@ -277,4 +277,12 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
delegate.onAddCalendarEvent(calendarEventSpec);
|
delegate.onAddCalendarEvent(calendarEventSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
if (checkBusy("delete calendar event")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delegate.onDeleteCalendarEvent(type, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,6 +388,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
// not supported
|
// not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
// not supported
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part of device initialization process. Do not call manually.
|
* Part of device initialization process. Do not call manually.
|
||||||
*
|
*
|
||||||
|
@ -452,7 +452,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
if (isFw3x) {
|
if (isFw3x) {
|
||||||
// 3.x notification
|
// 3.x notification
|
||||||
//return encodeTimelinePin(id, (int) ((ts + 600) & 0xffffffffL), (short) 90, PebbleIconID.TIMELINE_CALENDAR, title); // really, this is just for testing
|
|
||||||
return encodeBlobdbNotification(id, (int) (ts & 0xffffffffL), title, subtitle, notificationSpec.body, notificationSpec.sourceName, hasHandle, notificationSpec.type, notificationSpec.cannedReplies);
|
return encodeBlobdbNotification(id, (int) (ts & 0xffffffffL), title, subtitle, notificationSpec.body, notificationSpec.sourceName, hasHandle, notificationSpec.type, notificationSpec.cannedReplies);
|
||||||
} else if (mForceProtocol || notificationSpec.type != NotificationType.EMAIL) {
|
} else if (mForceProtocol || notificationSpec.type != NotificationType.EMAIL) {
|
||||||
// 2.x notification
|
// 2.x notification
|
||||||
@ -480,7 +479,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
iconId = PebbleIconID.TIMELINE_CALENDAR;
|
iconId = PebbleIconID.TIMELINE_CALENDAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return encodeTimelinePin(id, calendarEventSpec.timestamp, (short)calendarEventSpec.durationInSeconds, iconId, calendarEventSpec.title, calendarEventSpec.description);
|
return encodeTimelinePin(new UUID(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -761,11 +765,10 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] encodeTimelinePin(long id, int timestamp, short duration, int icon_id, String title, String subtitle) {
|
private byte[] encodeTimelinePin(UUID uuid, int timestamp, short duration, int icon_id, String title, String subtitle) {
|
||||||
final short TIMELINE_PIN_LENGTH = 46;
|
final short TIMELINE_PIN_LENGTH = 46;
|
||||||
|
|
||||||
icon_id |= 0x80000000;
|
icon_id |= 0x80000000;
|
||||||
UUID uuid = new UUID(mRandom.nextLong(), id);
|
|
||||||
byte attributes_count = 2;
|
byte attributes_count = 2;
|
||||||
byte actions_count = 0;
|
byte actions_count = 0;
|
||||||
|
|
||||||
|
@ -126,4 +126,11 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
|
|||||||
super.onAddCalendarEvent(calendarEventSpec);
|
super.onAddCalendarEvent(calendarEventSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
if (reconnect()) {
|
||||||
|
super.onDeleteCalendarEvent(type, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,9 +188,16 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
|||||||
byte[] bytes = gbDeviceProtocol.encodeEnableRealtimeHeartRateMeasurement(enable);
|
byte[] bytes = gbDeviceProtocol.encodeEnableRealtimeHeartRateMeasurement(enable);
|
||||||
sendToDevice(bytes);
|
sendToDevice(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
|
public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
|
||||||
byte[] bytes = gbDeviceProtocol.encodeAddCalendarEvent(calendarEventSpec);
|
byte[] bytes = gbDeviceProtocol.encodeAddCalendarEvent(calendarEventSpec);
|
||||||
sendToDevice(bytes);
|
sendToDevice(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
byte[] bytes = gbDeviceProtocol.encodeDeleteCalendarEvent(type, id);
|
||||||
|
sendToDevice(bytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,10 @@ public abstract class GBDeviceProtocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] encodeDeleteCalendarEvent(int type, long id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
|
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,11 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleteCalendarEvent(int type, long id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
|
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user