use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.
the class FitProDeviceSupport method onSetAlarms.
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
LOG.debug("FitPro set alarms");
if (alarms.toArray().length == 1 && alarms.get(0).getRepetition() == 0) {
Alarm oneshot = alarms.get(0);
DBHandler db = null;
try {
db = GBApplication.acquireDB();
DaoSession daoSession = db.getDaoSession();
Device device = DBHelper.getDevice(gbDevice, daoSession);
User user = DBHelper.getUser(daoSession);
nodomain.freeyourgadget.gadgetbridge.entities.Alarm tmpAlarm = new nodomain.freeyourgadget.gadgetbridge.entities.Alarm(device.getId(), user.getId(), 7, true, false, false, 0, oneshot.getHour(), oneshot.getMinute(), // kind of indicate the specialty of this alarm
true, "", "");
daoSession.insertOrReplace(tmpAlarm);
GBApplication.releaseDB();
} catch (GBException e) {
LOG.error("error storing one shot quick alarm");
}
}
try {
TransactionBuilder builder = performInitialized("Set alarm");
boolean anyAlarmEnabled = false;
byte[] all_alarms = new byte[] {};
for (Alarm alarm : alarms) {
Calendar calendar = AlarmUtils.toCalendar(alarm);
anyAlarmEnabled |= alarm.getEnabled();
LOG.debug("alarms: " + alarm.getPosition());
int maxAlarms = 8;
if (alarm.getPosition() >= maxAlarms) {
// we should never encounter this, but just in case
if (alarm.getEnabled()) {
GB.toast(getContext(), "Only 8 alarms are supported.", Toast.LENGTH_LONG, GB.WARN);
}
return;
}
if (alarm.getEnabled()) {
long datetime = (long) alarm.getRepetition() | ((long) (calendar.get(Calendar.YEAR) - 2000) << 34 | (long) (calendar.get(Calendar.MONTH) + 1) << 30 | (long) (calendar.get(Calendar.DAY_OF_MONTH)) << 25 | (long) (calendar.get(Calendar.HOUR_OF_DAY)) << 20 | (long) (calendar.get(Calendar.MINUTE)) << 14 | 1L << 11);
byte[] single_alarm = new byte[] { (byte) (datetime >> 32), (byte) (datetime >> 24), (byte) (datetime >> 16), (byte) (datetime >> 8), (byte) (datetime) };
all_alarms = ArrayUtils.addAll(all_alarms, single_alarm);
}
}
builder.write(writeCharacteristic, craftData(CMD_GROUP_GENERAL, CMD_ALARM, all_alarms));
builder.queue(getQueue());
if (anyAlarmEnabled) {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
} else {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}
} catch (IOException ex) {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG, GB.ERROR, ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.
the class BangleJSDeviceSupport method onSetAlarms.
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try {
JSONObject o = new JSONObject();
o.put("t", "alarm");
JSONArray jsonalarms = new JSONArray();
o.put("d", jsonalarms);
for (Alarm alarm : alarms) {
if (!alarm.getEnabled())
continue;
JSONObject jsonalarm = new JSONObject();
jsonalarms.put(jsonalarm);
Calendar calendar = AlarmUtils.toCalendar(alarm);
// TODO: getRepetition to ensure it only happens on correct day?
jsonalarm.put("h", alarm.getHour());
jsonalarm.put("m", alarm.getMinute());
}
uartTxJSON("onSetAlarms", o);
} catch (JSONException e) {
LOG.info("JSONException: " + e.getLocalizedMessage());
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.
the class HPlusSupport method onSetAlarms.
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try {
TransactionBuilder builder = performInitialized("alarm");
for (Alarm alarm : alarms) {
if (!alarm.getEnabled())
continue;
if (// Not available
alarm.getSmartWakeup())
continue;
Calendar t = AlarmUtils.toCalendar(alarm);
setAlarm(builder, t);
builder.queue(getQueue());
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
// Only first alarm
return;
}
setAlarm(builder, null);
builder.queue(getQueue());
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
} catch (Exception e) {
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.
the class HuamiSupport method onSetAlarms.
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try {
TransactionBuilder builder = performInitialized("Set alarm");
boolean anyAlarmEnabled = false;
for (Alarm alarm : alarms) {
anyAlarmEnabled |= alarm.getEnabled();
queueAlarm(alarm, builder);
}
builder.queue(getQueue());
if (anyAlarmEnabled) {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
} else {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}
} catch (IOException ex) {
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG, GB.ERROR, ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.
the class Watch9DeviceSupport method onSetAlarms.
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try {
TransactionBuilder builder = performInitialized("setAlarms");
for (Alarm alarm : alarms) {
setAlarm(alarm, alarm.getPosition() + 1, builder);
}
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn("Unable to set alarms", e);
}
}
Aggregations