Search in sources :

Example 21 with Alarm

use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.

the class ZeTimeDeviceSupport method onSetAlarms.

@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
    byte[] alarmMessage = null;
    try {
        TransactionBuilder builder = performInitialized("setAlarms");
        Prefs prefs = GBApplication.getPrefs();
        for (Alarm alarm : alarms) {
            if (remindersOnWatch[alarm.getPosition()][0] == 0) {
                alarmMessage = new byte[] { ZeTimeConstants.CMD_PREAMBLE, ZeTimeConstants.CMD_REMINDERS, ZeTimeConstants.CMD_SEND, (byte) 0xb, (byte) 0x0, // (byte) alarm.getPosition(), // index
                (byte) 0x0, ZeTimeConstants.REMINDER_ALARM, // year low byte
                (byte) 0x0, // year high byte
                (byte) 0x0, // month
                (byte) 0x0, // day
                (byte) 0x0, (byte) AlarmUtils.toCalendar(alarm).get(Calendar.HOUR_OF_DAY), (byte) AlarmUtils.toCalendar(alarm).get(Calendar.MINUTE), (byte) alarm.getRepetition(), (byte) (alarm.getEnabled() ? 1 : 0), // reminder signaling
                (byte) prefs.getInt(ZeTimeConstants.PREF_ALARM_SIGNALING, 11), ZeTimeConstants.CMD_END };
                System.arraycopy(alarmMessage, 6, remindersOnWatch[alarm.getPosition()], 0, 10);
            } else {
                alarmMessage = new byte[] { ZeTimeConstants.CMD_PREAMBLE, ZeTimeConstants.CMD_REMINDERS, ZeTimeConstants.CMD_SEND, (byte) 0x15, (byte) 0x0, // edit alarm
                (byte) 0x1, remindersOnWatch[alarm.getPosition()][0], remindersOnWatch[alarm.getPosition()][1], remindersOnWatch[alarm.getPosition()][2], remindersOnWatch[alarm.getPosition()][3], remindersOnWatch[alarm.getPosition()][4], remindersOnWatch[alarm.getPosition()][5], remindersOnWatch[alarm.getPosition()][6], remindersOnWatch[alarm.getPosition()][7], remindersOnWatch[alarm.getPosition()][8], remindersOnWatch[alarm.getPosition()][9], ZeTimeConstants.REMINDER_ALARM, // year low byte
                (byte) 0x0, // year high byte
                (byte) 0x0, // month
                (byte) 0x0, // day
                (byte) 0x0, (byte) AlarmUtils.toCalendar(alarm).get(Calendar.HOUR_OF_DAY), (byte) AlarmUtils.toCalendar(alarm).get(Calendar.MINUTE), (byte) alarm.getRepetition(), (byte) (alarm.getEnabled() ? 1 : 0), // reminder signaling
                (byte) prefs.getInt(ZeTimeConstants.PREF_ALARM_SIGNALING, 11), ZeTimeConstants.CMD_END };
                System.arraycopy(alarmMessage, 16, remindersOnWatch[alarm.getPosition()], 0, 10);
            }
            sendMsgToWatch(builder, alarmMessage);
        }
        builder.queue(getQueue());
    } catch (IOException e) {
        GB.toast(getContext(), "Error set alarms: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException) GBPrefs(nodomain.freeyourgadget.gadgetbridge.util.GBPrefs) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 22 with Alarm

use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.

the class DeviceCommunicationService method handleAction.

private void handleAction(Intent intent, String action, Prefs prefs) {
    Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(mGBDevice.getAddress()));
    boolean transliterate = devicePrefs.getBoolean(PREF_TRANSLITERATION_ENABLED, false);
    if (transliterate) {
        for (String extra : GBDeviceService.transliterationExtras) {
            if (intent.hasExtra(extra)) {
                intent.putExtra(extra, LanguageUtils.transliterate(intent.getStringExtra(extra)));
            }
        }
    }
    switch(action) {
        case ACTION_REQUEST_DEVICEINFO:
            mGBDevice.sendDeviceUpdateIntent(this);
            break;
        case ACTION_NOTIFICATION:
            {
                int desiredId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
                NotificationSpec notificationSpec = new NotificationSpec(desiredId);
                notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER);
                notificationSpec.sender = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_SENDER));
                notificationSpec.subject = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT));
                notificationSpec.title = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_TITLE));
                notificationSpec.body = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_BODY));
                notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME);
                notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE);
                notificationSpec.attachedActions = (ArrayList<NotificationSpec.Action>) intent.getSerializableExtra(EXTRA_NOTIFICATION_ACTIONS);
                notificationSpec.pebbleColor = (byte) intent.getSerializableExtra(EXTRA_NOTIFICATION_PEBBLE_COLOR);
                notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);
                notificationSpec.sourceAppId = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCEAPPID);
                notificationSpec.iconId = intent.getIntExtra(EXTRA_NOTIFICATION_ICONID, 0);
                notificationSpec.dndSuppressed = intent.getIntExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, 0);
                if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) {
                    GBApplication.getIDSenderLookup().add(notificationSpec.getId(), notificationSpec.phoneNumber);
                }
                // TODO: check if at least one of the attached actions is a reply action instead?
                if ((notificationSpec.attachedActions != null && notificationSpec.attachedActions.size() > 0) || (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) {
                    // NOTE: maybe not where it belongs
                    // I would rather like to save that as an array in SharedPreferences
                    // this would work but I dont know how to do the same in the Settings Activity's xml
                    ArrayList<String> replies = new ArrayList<>();
                    for (int i = 1; i <= 16; i++) {
                        String reply = devicePrefs.getString("canned_reply_" + i, null);
                        if (reply != null && !reply.equals("")) {
                            replies.add(reply);
                        }
                    }
                    notificationSpec.cannedReplies = replies.toArray(new String[0]);
                }
                mDeviceSupport.onNotification(notificationSpec);
                break;
            }
        case ACTION_DELETE_NOTIFICATION:
            {
                mDeviceSupport.onDeleteNotification(intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1));
                break;
            }
        case ACTION_ADD_CALENDAREVENT:
            {
                CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
                calendarEventSpec.id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -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 = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE));
                calendarEventSpec.description = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION));
                calendarEventSpec.location = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_LOCATION));
                mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
                break;
            }
        case ACTION_DELETE_CALENDAREVENT:
            {
                long id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1);
                byte type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1);
                mDeviceSupport.onDeleteCalendarEvent(type, id);
                break;
            }
        case ACTION_RESET:
            {
                int flags = intent.getIntExtra(EXTRA_RESET_FLAGS, 0);
                mDeviceSupport.onReset(flags);
                break;
            }
        case ACTION_HEARTRATE_TEST:
            {
                mDeviceSupport.onHeartRateTest();
                break;
            }
        case ACTION_FETCH_RECORDED_DATA:
            {
                int dataTypes = intent.getIntExtra(EXTRA_RECORDED_DATA_TYPES, 0);
                mDeviceSupport.onFetchRecordedData(dataTypes);
                break;
            }
        case ACTION_DISCONNECT:
            {
                mDeviceSupport.dispose();
                if (mGBDevice != null) {
                    mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
                    mGBDevice.sendDeviceUpdateIntent(this);
                }
                setReceiversEnableState(false, false, null);
                mGBDevice = null;
                mDeviceSupport = null;
                mCoordinator = null;
                break;
            }
        case ACTION_FIND_DEVICE:
            {
                boolean start = intent.getBooleanExtra(EXTRA_FIND_START, false);
                mDeviceSupport.onFindDevice(start);
                break;
            }
        case ACTION_SET_CONSTANT_VIBRATION:
            {
                int intensity = intent.getIntExtra(EXTRA_VIBRATION_INTENSITY, 0);
                mDeviceSupport.onSetConstantVibration(intensity);
                break;
            }
        case ACTION_CALLSTATE:
            CallSpec callSpec = new CallSpec();
            callSpec.command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
            callSpec.number = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
            callSpec.name = sanitizeNotifText(intent.getStringExtra(EXTRA_CALL_DISPLAYNAME));
            mDeviceSupport.onSetCallState(callSpec);
            break;
        case ACTION_SETCANNEDMESSAGES:
            int type = intent.getIntExtra(EXTRA_CANNEDMESSAGES_TYPE, -1);
            String[] cannedMessages = intent.getStringArrayExtra(EXTRA_CANNEDMESSAGES);
            CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
            cannedMessagesSpec.type = type;
            cannedMessagesSpec.cannedMessages = cannedMessages;
            mDeviceSupport.onSetCannedMessages(cannedMessagesSpec);
            break;
        case ACTION_SETTIME:
            mDeviceSupport.onSetTime();
            break;
        case ACTION_SETMUSICINFO:
            MusicSpec musicSpec = new MusicSpec();
            musicSpec.artist = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_ARTIST));
            musicSpec.album = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_ALBUM));
            musicSpec.track = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_TRACK));
            musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
            musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
            musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
            mDeviceSupport.onSetMusicInfo(musicSpec);
            break;
        case ACTION_SETMUSICSTATE:
            MusicStateSpec stateSpec = new MusicStateSpec();
            stateSpec.shuffle = intent.getByteExtra(EXTRA_MUSIC_SHUFFLE, (byte) 0);
            stateSpec.repeat = intent.getByteExtra(EXTRA_MUSIC_REPEAT, (byte) 0);
            stateSpec.position = intent.getIntExtra(EXTRA_MUSIC_POSITION, 0);
            stateSpec.playRate = intent.getIntExtra(EXTRA_MUSIC_RATE, 0);
            stateSpec.state = intent.getByteExtra(EXTRA_MUSIC_STATE, (byte) 0);
            mDeviceSupport.onSetMusicState(stateSpec);
            break;
        case ACTION_REQUEST_APPINFO:
            mDeviceSupport.onAppInfoReq();
            break;
        case ACTION_REQUEST_SCREENSHOT:
            mDeviceSupport.onScreenshotReq();
            break;
        case ACTION_STARTAPP:
            {
                UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
                boolean start = intent.getBooleanExtra(EXTRA_APP_START, true);
                mDeviceSupport.onAppStart(uuid, start);
                break;
            }
        case ACTION_DELETEAPP:
            {
                UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
                mDeviceSupport.onAppDelete(uuid);
                break;
            }
        case ACTION_APP_CONFIGURE:
            {
                UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
                String config = intent.getStringExtra(EXTRA_APP_CONFIG);
                Integer id = null;
                if (intent.hasExtra(EXTRA_APP_CONFIG_ID)) {
                    id = intent.getIntExtra(EXTRA_APP_CONFIG_ID, 0);
                }
                mDeviceSupport.onAppConfiguration(uuid, config, id);
                break;
            }
        case ACTION_APP_REORDER:
            {
                UUID[] uuids = (UUID[]) intent.getSerializableExtra(EXTRA_APP_UUID);
                mDeviceSupport.onAppReorder(uuids);
                break;
            }
        case ACTION_INSTALL:
            Uri uri = intent.getParcelableExtra(EXTRA_URI);
            if (uri != null) {
                LOG.info("will try to install app/fw");
                mDeviceSupport.onInstallApp(uri);
            }
            break;
        case ACTION_SET_ALARMS:
            ArrayList<? extends Alarm> alarms = (ArrayList<? extends Alarm>) intent.getSerializableExtra(EXTRA_ALARMS);
            mDeviceSupport.onSetAlarms(alarms);
            break;
        case ACTION_SET_REMINDERS:
            ArrayList<? extends Reminder> reminders = (ArrayList<? extends Reminder>) intent.getSerializableExtra(EXTRA_REMINDERS);
            mDeviceSupport.onSetReminders(reminders);
            break;
        case ACTION_ENABLE_REALTIME_STEPS:
            {
                boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
                mDeviceSupport.onEnableRealtimeSteps(enable);
                break;
            }
        case ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT:
            {
                boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
                mDeviceSupport.onEnableHeartRateSleepSupport(enable);
                break;
            }
        case ACTION_SET_HEARTRATE_MEASUREMENT_INTERVAL:
            {
                int seconds = intent.getIntExtra(EXTRA_INTERVAL_SECONDS, 0);
                mDeviceSupport.onSetHeartRateMeasurementInterval(seconds);
                break;
            }
        case ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT:
            {
                boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
                mDeviceSupport.onEnableRealtimeHeartRateMeasurement(enable);
                break;
            }
        case ACTION_SEND_CONFIGURATION:
            {
                String config = intent.getStringExtra(EXTRA_CONFIG);
                mDeviceSupport.onSendConfiguration(config);
                break;
            }
        case ACTION_READ_CONFIGURATION:
            {
                String config = intent.getStringExtra(EXTRA_CONFIG);
                mDeviceSupport.onReadConfiguration(config);
                break;
            }
        case ACTION_TEST_NEW_FUNCTION:
            {
                mDeviceSupport.onTestNewFunction();
                break;
            }
        case ACTION_SEND_WEATHER:
            {
                WeatherSpec weatherSpec = intent.getParcelableExtra(EXTRA_WEATHER);
                if (weatherSpec != null) {
                    mDeviceSupport.onSendWeather(weatherSpec);
                }
                break;
            }
        case ACTION_SET_LED_COLOR:
            int color = intent.getIntExtra(EXTRA_LED_COLOR, 0);
            if (color != 0) {
                mDeviceSupport.onSetLedColor(color);
            }
            break;
        case ACTION_POWER_OFF:
            mDeviceSupport.onPowerOff();
            break;
        case ACTION_SET_FM_FREQUENCY:
            float frequency = intent.getFloatExtra(EXTRA_FM_FREQUENCY, -1);
            if (frequency != -1) {
                mDeviceSupport.onSetFmFrequency(frequency);
            }
            break;
    }
}
Also used : Reminder(nodomain.freeyourgadget.gadgetbridge.model.Reminder) ArrayList(java.util.ArrayList) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) GBPrefs(nodomain.freeyourgadget.gadgetbridge.util.GBPrefs) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) MusicStateSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec) MusicSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicSpec) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) NotificationType(nodomain.freeyourgadget.gadgetbridge.model.NotificationType) Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) WeatherSpec(nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec) CannedMessagesSpec(nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec) EXTRA_APP_UUID(nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_UUID) UUID(java.util.UUID) CalendarEventSpec(nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec)

Example 23 with Alarm

use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.

the class WatchXPlusDeviceSupport 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);
    }
}
Also used : Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 24 with Alarm

use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.

the class SonySWR12DeviceSupport method onSetAlarms.

@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
    try {
        BluetoothGattCharacteristic alarmCharacteristic = getCharacteristic(SonySWR12Constants.UUID_CHARACTERISTIC_ALARM);
        TransactionBuilder builder = performInitialized("alarm");
        int prefInterval = Integer.valueOf(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_SONYSWR12_SMART_INTERVAL, "0"));
        ArrayList<BandAlarm> bandAlarmList = new ArrayList<>();
        for (Alarm alarm : alarms) {
            BandAlarm bandAlarm = BandAlarm.fromAppAlarm(alarm, bandAlarmList.size(), alarm.getSmartWakeup() ? prefInterval : 0);
            if (bandAlarm != null)
                bandAlarmList.add(bandAlarm);
        }
        builder.write(alarmCharacteristic, new BandAlarms(bandAlarmList).toByteArray());
        builder.queue(getQueue());
    } catch (Exception e) {
        GB.toast(getContext(), "Error setting alarms: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : BandAlarm(nodomain.freeyourgadget.gadgetbridge.service.devices.sonyswr12.entities.alarm.BandAlarm) BandAlarm(nodomain.freeyourgadget.gadgetbridge.service.devices.sonyswr12.entities.alarm.BandAlarm) Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) ArrayList(java.util.ArrayList) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic) IOException(java.io.IOException) BandAlarms(nodomain.freeyourgadget.gadgetbridge.service.devices.sonyswr12.entities.alarm.BandAlarms)

Example 25 with Alarm

use of nodomain.freeyourgadget.gadgetbridge.model.Alarm in project Gadgetbridge by Freeyourgadget.

the class TLW64Support 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();
            Calendar calendar = AlarmUtils.toCalendar(alarm);
            int maxAlarms = 3;
            if (alarm.getPosition() >= maxAlarms) {
                if (alarm.getEnabled()) {
                    GB.toast(getContext(), "Only 3 alarms are supported.", Toast.LENGTH_LONG, GB.WARN);
                }
                return;
            }
            byte repetition = 0x00;
            switch(alarm.getRepetition()) {
                // TODO: case Alarm.ALARM_ONCE is not supported! Need to notify user somehow...
                case Alarm.ALARM_MON:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_MONDAY;
                case Alarm.ALARM_TUE:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_TUESDAY;
                case Alarm.ALARM_WED:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_WEDNESDAY;
                case Alarm.ALARM_THU:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_THURSDAY;
                case Alarm.ALARM_FRI:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_FRIDAY;
                case Alarm.ALARM_SAT:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_SATURDAY;
                case Alarm.ALARM_SUN:
                    repetition |= TLW64Constants.ARG_SET_ALARM_REMINDER_REPEAT_SUNDAY;
                    break;
                default:
                    LOG.warn("invalid alarm repetition " + alarm.getRepetition());
                    break;
            }
            byte[] alarmMessage = new byte[] { TLW64Constants.CMD_ALARM, (byte) repetition, (byte) calendar.get(Calendar.HOUR_OF_DAY), (byte) calendar.get(Calendar.MINUTE), // vibration duration
            (byte) (alarm.getEnabled() ? 2 : 0), // vibration count
            (byte) (alarm.getEnabled() ? 10 : 0), // unknown
            (byte) (alarm.getEnabled() ? 2 : 0), (byte) 0x00, (byte) (alarm.getPosition() + 1) };
            builder.write(ctrlCharacteristic, alarmMessage);
        }
        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);
    }
}
Also used : Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Aggregations

Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)25 TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)16 IOException (java.io.IOException)15 GregorianCalendar (java.util.GregorianCalendar)10 Calendar (java.util.Calendar)9 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)5 ArrayList (java.util.ArrayList)5 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)3 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)3 CalendarEvents (nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents)3 GBPrefs (nodomain.freeyourgadget.gadgetbridge.util.GBPrefs)3 Context (android.content.Context)2 UUID (java.util.UUID)2 GBAlarm (nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1