From b6b6c0d8f6f6947c5d77c366183cabe5c54b476f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Fri, 27 Sep 2024 22:48:37 +0100 Subject: [PATCH] alarm sounds, backlight, preset titles --- .../gadgetbridge/daogen/GBDaoGenerator.java | 4 +- .../gadgetbridge/activities/AlarmDetails.java | 34 ++++++++++++++ .../schema/GadgetbridgeUpdate_79.java | 44 +++++++++++++++++++ .../devices/AbstractDeviceCoordinator.java | 20 +++++++++ .../devices/DeviceCoordinator.java | 5 +++ .../GarminForerunner245Coordinator.java | 32 ++++++++++++++ .../gadgetbridge/model/Alarm.java | 14 +++++- .../devices/huawei/HuaweiSupportProvider.java | 2 +- .../huawei/requests/GetEventAlarmList.java | 8 +++- .../huawei/requests/GetSmartAlarmList.java | 8 +++- .../gadgetbridge/util/AlarmUtils.java | 6 +-- .../res/layout/activity_alarm_details.xml | 20 +++++++++ 12 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_79.java diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index db389239d..6c5574de2 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -46,7 +46,7 @@ public class GBDaoGenerator { public static void main(String[] args) throws Exception { - final Schema schema = new Schema(78, MAIN_PACKAGE + ".entities"); + final Schema schema = new Schema(79, MAIN_PACKAGE + ".entities"); Entity userAttributes = addUserAttributes(schema); Entity user = addUserInfo(schema, userAttributes); @@ -1015,6 +1015,8 @@ public class GBDaoGenerator { alarm.addBooleanProperty("unused").notNull(); alarm.addStringProperty("title"); alarm.addStringProperty("description"); + alarm.addIntProperty("soundCode").notNull(); + alarm.addBooleanProperty("backlight").notNull(); alarm.addToOne(user, userId); alarm.addToOne(device, deviceId); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java index 276c1200f..35239c985 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java @@ -28,6 +28,8 @@ import android.widget.EditText; import android.widget.TimePicker; import java.text.NumberFormat; +import java.util.Collections; +import java.util.List; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; @@ -259,6 +261,38 @@ public class AlarmDetails extends AbstractGBActivity { return false; } + private boolean supportsAlarmSounds() { + if (device != null) { + DeviceCoordinator coordinator = device.getDeviceCoordinator(); + return coordinator.supportsAlarmSounds(device); + } + return false; + } + + private boolean supportsAlarmBacklight() { + if (device != null) { + DeviceCoordinator coordinator = device.getDeviceCoordinator(); + return coordinator.supportsAlarmBacklight(device); + } + return false; + } + + private boolean supportsAlarmTitlePresets() { + if (device != null) { + DeviceCoordinator coordinator = device.getDeviceCoordinator(); + return coordinator.supportsAlarmTitlePresets(device); + } + return false; + } + + private List getAlarmTitlePresets() { + if (device != null) { + DeviceCoordinator coordinator = device.getDeviceCoordinator(); + return coordinator.getAlarmTitlePresets(device); + } + return Collections.emptyList(); + } + @Override public boolean onOptionsItemSelected(final MenuItem item) { final int itemId = item.getItemId(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_79.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_79.java new file mode 100644 index 000000000..37abd5096 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_79.java @@ -0,0 +1,44 @@ +/* Copyright (C) 2024 José Rebelo + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.database.schema; + +import android.database.sqlite.SQLiteDatabase; + +import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; +import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript; +import nodomain.freeyourgadget.gadgetbridge.entities.AlarmDao; + +public class GadgetbridgeUpdate_79 implements DBUpdateScript { + @Override + public void upgradeSchema(SQLiteDatabase db) { + if (!DBHelper.existsColumn(AlarmDao.TABLENAME, AlarmDao.Properties.SoundCode.columnName, db)) { + String ADD_COLUMN_SOUND_CODE = "ALTER TABLE " + AlarmDao.TABLENAME + " ADD COLUMN " + + AlarmDao.Properties.SoundCode.columnName + " INTEGER NOT NULL DEFAULT 0;"; + db.execSQL(ADD_COLUMN_SOUND_CODE); + } + + if (!DBHelper.existsColumn(AlarmDao.TABLENAME, AlarmDao.Properties.Backlight.columnName, db)) { + String ADD_COLUMN_SOUND_CODE = "ALTER TABLE " + AlarmDao.TABLENAME + " ADD COLUMN " + + AlarmDao.Properties.Backlight.columnName + " BOOLEAN NOT NULL DEFAULT TRUE;"; + db.execSQL(ADD_COLUMN_SOUND_CODE); + } + } + + @Override + public void downgradeSchema(SQLiteDatabase db) { + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java index 935877260..f2ad5b222 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java @@ -567,6 +567,26 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { return false; } + @Override + public boolean supportsAlarmSounds(GBDevice device) { + return false; + } + + @Override + public boolean supportsAlarmBacklight(GBDevice device) { + return false; + } + + @Override + public boolean supportsAlarmTitlePresets(GBDevice device) { + return false; + } + + @Override + public List getAlarmTitlePresets(GBDevice device) { + return Collections.emptyList(); + } + @Override public boolean supportsMusicInfo() { return false; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java index b58ab0903..25484938a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java @@ -451,6 +451,11 @@ public interface DeviceCoordinator { */ boolean supportsAlarmDescription(GBDevice device); + boolean supportsAlarmSounds(GBDevice device); + boolean supportsAlarmBacklight(GBDevice device); + boolean supportsAlarmTitlePresets(GBDevice device); + List getAlarmTitlePresets(GBDevice device); + /** * Returns true if the given device supports heart rate measurements. * @return diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/watches/forerunner/GarminForerunner245Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/watches/forerunner/GarminForerunner245Coordinator.java index 5da1f7390..5c37f6991 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/watches/forerunner/GarminForerunner245Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/watches/forerunner/GarminForerunner245Coordinator.java @@ -1,9 +1,12 @@ package nodomain.freeyourgadget.gadgetbridge.devices.garmin.watches.forerunner; +import java.util.Arrays; +import java.util.List; import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.garmin.GarminCoordinator; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; public class GarminForerunner245Coordinator extends GarminCoordinator { @Override @@ -15,4 +18,33 @@ public class GarminForerunner245Coordinator extends GarminCoordinator { public int getDeviceNameResource() { return R.string.devicetype_garmin_forerunner_245; } + + @Override + public int getAlarmSlotCount(final GBDevice device) { + return 10; + } + + @Override + public boolean supportsAlarmSounds(final GBDevice device) { + return true; + } + + @Override + public boolean supportsAlarmBacklight(final GBDevice device) { + return true; + } + + @Override + public boolean supportsAlarmTitlePresets(final GBDevice device) { + return true; + } + + @Override + public List getAlarmTitlePresets(final GBDevice device) { + return Arrays.asList( + "label 1", + "label 2", + "label 3" + ); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java index 59c3a599d..a441436f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java @@ -36,6 +36,14 @@ public interface Alarm extends Serializable { byte ALARM_DAILY = Alarm.ALARM_MON | Alarm.ALARM_TUE | Alarm.ALARM_WED | Alarm.ALARM_THU | Alarm.ALARM_FRI | Alarm.ALARM_SAT | Alarm.ALARM_SUN; + enum ALARM_SOUND { + UNSET, + OFF, + TONE, + VIBRATION, + TONE_AND_VIBRATION, + } + int getPosition(); boolean getEnabled(); @@ -61,4 +69,8 @@ public interface Alarm extends Serializable { String getTitle(); String getDescription(); -} \ No newline at end of file + + int getSoundCode(); + + boolean getBacklight(); +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index aeddf4602..307c75edd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -808,7 +808,7 @@ public class HuaweiSupportProvider { title = context.getString(R.string.alarm_smart_wakeup); description = context.getString(R.string.huawei_alarm_smart_description); } - return new Alarm(device.getId(), user.getId(), position, false, smartWakeup, null, false, 0, 6, 30, true, title, description); + return new Alarm(device.getId(), user.getId(), position, false, smartWakeup, null, false, 0, 6, 30, true, title, description, 0, true); } private void getAlarms() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetEventAlarmList.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetEventAlarmList.java index a7fa49b5a..940b65e75 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetEventAlarmList.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetEventAlarmList.java @@ -78,7 +78,9 @@ public class GetEventAlarmList extends Request { eventAlarm.startMinute, false, eventAlarm.name, - "" + "", + 0, + true )); usedBitmap |= 1 << eventAlarm.index; } @@ -99,7 +101,9 @@ public class GetEventAlarmList extends Request { 0, true, "", - "" + "", + 0, + true )); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSmartAlarmList.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSmartAlarmList.java index 007c35865..b663abcae 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSmartAlarmList.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSmartAlarmList.java @@ -69,7 +69,9 @@ public class GetSmartAlarmList extends Request { smartAlarm.startMinute, false, "Smart alarm", - "" + "", + 0, + true ) }); } else { @@ -88,7 +90,9 @@ public class GetSmartAlarmList extends Request { 0, true, "Smart alarm", - "" + "", + 0, + true ) }); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java index 5cccdcfd5..3598aea9b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java @@ -52,7 +52,7 @@ public class AlarmUtils { */ public static nodomain.freeyourgadget.gadgetbridge.model.Alarm createSingleShot(int index, boolean smartWakeup, boolean snooze, Calendar calendar) { // TODO: add interval setting? - return new Alarm(-1, -1, index, true, smartWakeup, null, snooze, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, GBApplication.getContext().getString(R.string.quick_alarm), GBApplication.getContext().getString(R.string.quick_alarm_description)); + return new Alarm(-1, -1, index, true, smartWakeup, null, snooze, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, GBApplication.getContext().getString(R.string.quick_alarm), GBApplication.getContext().getString(R.string.quick_alarm_description), 0, true); } /** @@ -78,7 +78,7 @@ public class AlarmUtils { public static Alarm createDefaultAlarm(DaoSession daoSession, GBDevice gbDevice, int position) { Device device = DBHelper.getDevice(gbDevice, daoSession); User user = DBHelper.getUser(daoSession); - return new Alarm(device.getId(), user.getId(), position, false, false, null, false, 0, 6, 30, false, null, null); + return new Alarm(device.getId(), user.getId(), position, false, false, null, false, 0, 6, 30, false, null, null, 0, true); } /** @@ -157,7 +157,7 @@ public class AlarmUtils { int hour = Integer.parseInt(tokens[4]); int minute = Integer.parseInt(tokens[5]); - return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, null, false, repetition, hour, minute, false, null, null); + return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, null, false, repetition, hour, minute, false, null, null, 0, true); } private static Comparator createComparator() { diff --git a/app/src/main/res/layout/activity_alarm_details.xml b/app/src/main/res/layout/activity_alarm_details.xml index 8f9b1a8ad..aa81f2a7a 100644 --- a/app/src/main/res/layout/activity_alarm_details.xml +++ b/app/src/main/res/layout/activity_alarm_details.xml @@ -23,6 +23,11 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingBottom="@dimen/activity_vertical_margin"> + + + + + +