use of nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents in project Gadgetbridge by Freeyourgadget.
the class MiBand2Support method sendCalendarEvents.
/**
* Fetch the events from the android device calendars and set the alarms on the miband.
* @param builder
*/
private MiBand2Support sendCalendarEvents(TransactionBuilder builder) {
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION);
Prefs prefs = GBApplication.getPrefs();
int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
if (availableSlots > 0) {
CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
int iteration = 0;
for (CalendarEvents.CalendarEvent mEvt : mEvents) {
if (iteration >= availableSlots || iteration > 2) {
break;
}
int slotToUse = 2 - iteration;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mEvt.getBegin());
Alarm alarm = GBAlarm.createSingleShot(slotToUse, false, calendar);
queueAlarm(alarm, builder, characteristic);
iteration++;
}
builder.queue(getQueue());
}
return this;
}
use of nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents in project Gadgetbridge by Freeyourgadget.
the class HuamiSupport method sendCalendarEvents.
/**
* Fetch the events from the android device calendars and set the alarms on the miband.
* @param builder
*/
private HuamiSupport sendCalendarEvents(TransactionBuilder builder) {
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int availableSlots = prefs.getInt(PREF_RESERVER_ALARMS_CALENDAR, 0);
if (availableSlots > 0) {
CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
int iteration = 0;
for (CalendarEvents.CalendarEvent mEvt : mEvents) {
if (mEvt.isAllDay()) {
continue;
}
if (iteration >= availableSlots || iteration > 2) {
break;
}
int slotToUse = 2 - iteration;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mEvt.getBegin());
Alarm alarm = AlarmUtils.createSingleShot(slotToUse, false, true, calendar);
queueAlarm(alarm, builder);
iteration++;
}
}
return this;
}
use of nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents in project Gadgetbridge by Freeyourgadget.
the class MiBandSupport method sendCalendarEvents.
/**
* Fetch the events from the android device calendars and set the alarms on the miband.
*/
private void sendCalendarEvents() {
try {
TransactionBuilder builder = performInitialized("Send upcoming events");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int availableSlots = prefs.getInt(DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR, 0);
if (availableSlots > 3) {
availableSlots = 3;
}
if (availableSlots > 0) {
CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
int iteration = 0;
for (CalendarEvents.CalendarEvent mEvt : mEvents) {
if (iteration >= availableSlots) {
break;
}
int slotToUse = 2 - iteration;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mEvt.getBegin());
Alarm alarm = AlarmUtils.createSingleShot(slotToUse, false, false, calendar);
queueAlarm(alarm, builder, characteristic);
iteration++;
}
builder.queue(getQueue());
}
} catch (IOException ex) {
LOG.error("Unable to send Events to MI device", ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents in project Gadgetbridge by Freeyourgadget.
the class HuamiSupport method sendCalendarEventsAsReminder.
private HuamiSupport sendCalendarEventsAsReminder(TransactionBuilder builder) {
boolean syncCalendar = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(PREF_SYNC_CALENDAR, false);
if (!syncCalendar) {
return this;
}
final Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int availableSlots = prefs.getInt(PREF_RESERVER_REMINDERS_CALENDAR, 9);
CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> calendarEvents = upcomingEvents.getCalendarEventList(getContext());
Calendar calendar = Calendar.getInstance();
int iteration = 0;
for (CalendarEvents.CalendarEvent calendarEvent : calendarEvents) {
if (calendarEvent.isAllDay()) {
continue;
}
if (iteration >= availableSlots) {
break;
}
calendar.setTimeInMillis(calendarEvent.getBegin());
byte[] title;
if (calendarEvent.getTitle() != null) {
title = calendarEvent.getTitle().getBytes();
} else {
title = new byte[] {};
}
int length = 1 + 1 + 4 + 6 + 6 + 1 + title.length + 1;
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
// always 0x0b?
buf.put((byte) 0x0b);
// id
buf.put((byte) iteration);
// flags 0x01 = enable, 0x04 = end date present, 0x08 = has text
buf.putInt(0x08 | 0x04 | 0x01);
calendar.setTimeInMillis(calendarEvent.getBegin());
buf.put(BLETypeConversions.shortCalendarToRawBytes(calendar));
calendar.setTimeInMillis(calendarEvent.getEnd());
buf.put(BLETypeConversions.shortCalendarToRawBytes(calendar));
// 0 Terminated
buf.put((byte) 0);
buf.put(title);
// 0 Terminated
buf.put((byte) 0);
writeToChunked(builder, 2, buf.array());
iteration++;
}
// Continue by deleting the events
for (; iteration < availableSlots; iteration++) {
int length = 1 + 1 + 4 + 6 + 6 + 1 + 0 + 1;
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
// always 0x0b?
buf.put((byte) 0x0b);
// id
buf.put((byte) iteration);
// flags 0x01 = enable, 0x04 = end date present, 0x08 = has text
buf.putInt(0x08);
// default value is 0
buf.put(new byte[6 + 6 + 1 + 1]);
writeToChunked(builder, 2, buf.array());
}
return this;
}
use of nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents in project Gadgetbridge by Freeyourgadget.
the class ZeTimeDeviceSupport method sendUpcomingCalendarEvents.
private void sendUpcomingCalendarEvents(TransactionBuilder builder) {
boolean syncCalendar = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(PREF_SYNC_CALENDAR, false);
if (!syncCalendar) {
return;
}
CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> calendarEvents = upcomingEvents.getCalendarEventList(getContext());
int eventCount = 0;
for (CalendarEvents.CalendarEvent calendarEvent : calendarEvents) {
if (calendarEvent.isAllDay()) {
continue;
}
String body = calendarEvent.getTitle();
if (body == null) {
body = "";
}
String description = calendarEvent.getDescription();
if (description != null) {
body += " : " + description;
}
byte opcode = 2;
if (eventCount == 0)
opcode = 1;
byte[] message = encodeCalendarEvent(body, calendarEvent.getBeginSeconds(), opcode);
sendMsgToWatch(builder, message);
// Urgh, seems it is a general problem when sending data too fast
builder.add(new WaitAction(300));
if (eventCount++ == 16) {
// limit this to 16 for now
break;
}
}
}
Aggregations