mirror of
https://github.com/google/pebble
synced 2026-10-18 01:04:12 +02:00
Import of the watch repository from Pebble
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble_hrm_reminder_popup.h"
|
||||
|
||||
#include "drivers/rtc.h"
|
||||
#include "services/common/i18n/i18n.h"
|
||||
#include "services/normal/notifications/notifications.h"
|
||||
#include "services/normal/timeline/timeline.h"
|
||||
#include "services/normal/timeline/timeline_resources.h"
|
||||
|
||||
#include <util/size.h>
|
||||
|
||||
void ble_hrm_push_reminder_popup(void) {
|
||||
AttributeList attr_list = {};
|
||||
|
||||
const char *body = i18n_get("Your heart rate has been shared with an app on your phone for "
|
||||
"several hours. This could affect your battery. Stop sharing now?",
|
||||
&attr_list);
|
||||
attribute_list_add_cstring(&attr_list, AttributeIdBody, body);
|
||||
attribute_list_add_uint32(&attr_list, AttributeIdIconTiny,
|
||||
TIMELINE_RESOURCE_BLE_HRM_SHARING);
|
||||
attribute_list_add_uint8(&attr_list, AttributeIdBgColor, GColorOrangeARGB8);
|
||||
|
||||
AttributeList dismiss_action_attr_list = {};
|
||||
attribute_list_add_cstring(&dismiss_action_attr_list, AttributeIdTitle,
|
||||
i18n_get("Dismiss", &attr_list));
|
||||
|
||||
AttributeList stop_action_attr_list = {};
|
||||
attribute_list_add_cstring(&stop_action_attr_list, AttributeIdTitle,
|
||||
i18n_get("Stop Sharing Heart Rate", &attr_list));
|
||||
|
||||
TimelineItemActionGroup action_group = {
|
||||
.num_actions = 2,
|
||||
.actions = (TimelineItemAction[]) {
|
||||
{
|
||||
.id = 0,
|
||||
.type = TimelineItemActionTypeDismiss,
|
||||
.attr_list = dismiss_action_attr_list,
|
||||
},
|
||||
{
|
||||
.id = 1,
|
||||
.type = TimelineItemActionTypeBLEHRMStopSharing,
|
||||
.attr_list = stop_action_attr_list,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
TimelineItem *item = timeline_item_create_with_attributes(rtc_get_time(), 0,
|
||||
TimelineItemTypeNotification,
|
||||
LayoutIdNotification, &attr_list,
|
||||
&action_group);
|
||||
i18n_free_all(&attr_list);
|
||||
attribute_list_destroy_list(&attr_list);
|
||||
attribute_list_destroy_list(&dismiss_action_attr_list);
|
||||
attribute_list_destroy_list(&stop_action_attr_list);
|
||||
|
||||
notifications_add_notification(item);
|
||||
|
||||
timeline_item_destroy(item);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void ble_hrm_push_reminder_popup(void);
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "services/normal/bluetooth/ble_hrm.h"
|
||||
|
||||
#include "applib/graphics/gcolor_definitions.h"
|
||||
#include "applib/ui/dialogs/actionable_dialog.h"
|
||||
#include "applib/ui/dialogs/dialog.h"
|
||||
#include "applib/ui/dialogs/simple_dialog.h"
|
||||
#include "kernel/ui/modals/modal_manager.h"
|
||||
#include "applib/ui/vibes.h"
|
||||
#include "resource/resource_ids.auto.h"
|
||||
#include "services/common/i18n/i18n.h"
|
||||
|
||||
#include <util/size.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BLE_HRM_CONFIRMATION_TIMEOUT_MS (2000)
|
||||
|
||||
static void prv_respond(bool is_granted, ActionableDialog *actionable_dialog) {
|
||||
BLEHRMSharingRequest *sharing_request = actionable_dialog->dialog.callback_context;
|
||||
ble_hrm_handle_sharing_request_response(is_granted, sharing_request);
|
||||
|
||||
actionable_dialog_pop(actionable_dialog);
|
||||
|
||||
if (is_granted) {
|
||||
SimpleDialog *simple_dialog = simple_dialog_create("Sharing");
|
||||
Dialog *dialog = simple_dialog_get_dialog(simple_dialog);
|
||||
|
||||
const char *msg = i18n_get("Sharing Heart Rate", dialog);
|
||||
dialog_set_text(dialog, msg);
|
||||
dialog_set_icon(dialog, RESOURCE_ID_BLE_HRM_SHARED);
|
||||
dialog_set_timeout(dialog, BLE_HRM_CONFIRMATION_TIMEOUT_MS);
|
||||
simple_dialog_set_icon_animated(simple_dialog, false);
|
||||
i18n_free(msg, dialog);
|
||||
simple_dialog_push(simple_dialog, modal_manager_get_window_stack(ModalPriorityGeneric));
|
||||
}
|
||||
}
|
||||
|
||||
static void prv_confirm_cb(ClickRecognizerRef recognizer, void *context) {
|
||||
prv_respond(true /* is_granted */, (ActionableDialog *)context);
|
||||
}
|
||||
|
||||
static void prv_back_cb(ClickRecognizerRef recognizer, void *context) {
|
||||
prv_respond(false /* is_granted */, (ActionableDialog *)context);
|
||||
}
|
||||
|
||||
static void prv_shutdown_click_provider(void *context) {
|
||||
window_single_click_subscribe(BUTTON_ID_UP, prv_confirm_cb);
|
||||
window_single_click_subscribe(BUTTON_ID_BACK, prv_back_cb);
|
||||
window_single_click_subscribe(BUTTON_ID_DOWN, prv_back_cb);
|
||||
}
|
||||
|
||||
void ble_hrm_push_sharing_request_window(BLEHRMSharingRequest *sharing_request) {
|
||||
ActionableDialog *a_dialog = actionable_dialog_create("HRM Sharing");
|
||||
Dialog *dialog = actionable_dialog_get_dialog(a_dialog);
|
||||
dialog->callback_context = sharing_request;
|
||||
|
||||
actionable_dialog_set_action_bar_type(a_dialog, DialogActionBarConfirmDecline, NULL);
|
||||
actionable_dialog_set_click_config_provider(a_dialog, prv_shutdown_click_provider);
|
||||
|
||||
dialog_set_text_color(dialog, GColorWhite);
|
||||
dialog_set_background_color(dialog, GColorCobaltBlue);
|
||||
|
||||
dialog_set_icon(dialog, RESOURCE_ID_BLE_HRM_SHARE_REQUEST_LARGE);
|
||||
|
||||
dialog_set_text(dialog, i18n_get("Share heart rate?", a_dialog));
|
||||
i18n_free_all(a_dialog);
|
||||
|
||||
actionable_dialog_push(a_dialog, modal_manager_get_window_stack(ModalPriorityGeneric));
|
||||
|
||||
const uint32_t const heart_beat_durations[] = { 100, 100, 150, 600, 100, 100, 150 };
|
||||
VibePattern heart_beat_pattern = {
|
||||
.durations = heart_beat_durations,
|
||||
.num_segments = ARRAY_LENGTH(heart_beat_durations),
|
||||
};
|
||||
vibes_enqueue_custom_pattern(heart_beat_pattern);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if CAPABILITY_HAS_BUILTIN_HRM
|
||||
|
||||
typedef struct BLEHRMSharingRequest BLEHRMSharingRequest;
|
||||
|
||||
//! @note Must be called from KernelMain
|
||||
void ble_hrm_push_sharing_request_window(BLEHRMSharingRequest *sharing_request);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble_hrm_stop_sharing_popup.h"
|
||||
|
||||
#include "applib/ui/dialogs/simple_dialog.h"
|
||||
#include "resource/resource_ids.auto.h"
|
||||
#include "services/common/i18n/i18n.h"
|
||||
#include "util/time/time.h"
|
||||
|
||||
#define BLE_HRM_CONFIRMATION_TIMEOUT_MS (2 * MS_PER_SECOND)
|
||||
|
||||
SimpleDialog *ble_hrm_stop_sharing_popup_create(void) {
|
||||
SimpleDialog *simple_dialog = simple_dialog_create("Stopped Sharing");
|
||||
Dialog *dialog = simple_dialog_get_dialog(simple_dialog);
|
||||
|
||||
const char *msg = i18n_get("Heart Rate Not Shared", dialog);
|
||||
dialog_set_text(dialog, msg);
|
||||
dialog_set_icon(dialog, RESOURCE_ID_BLE_HRM_NOT_SHARED);
|
||||
dialog_set_timeout(dialog, BLE_HRM_CONFIRMATION_TIMEOUT_MS);
|
||||
simple_dialog_set_icon_animated(simple_dialog, false);
|
||||
i18n_free(msg, dialog);
|
||||
return simple_dialog;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct SimpleDialog SimpleDialog;
|
||||
|
||||
SimpleDialog *ble_hrm_stop_sharing_popup_create(void);
|
||||
Reference in New Issue
Block a user