Created
April 13, 2014 08:03
-
-
Save sarfata/10574031 to your computer and use it in GitHub Desktop.
Pebble: How to override the back button when you are using a menu layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Add those lines somewhere in your file */ | |
// Define what you want to do when the back button is pressed | |
void back_button_handler(ClickRecognizerRef recognizer, void *context) { | |
APP_LOG(APP_LOG_LEVEL_DEBUG, "back clicked"); | |
} | |
// We need to save a reference to the ClickConfigProvider originally set by the menu layer | |
ClickConfigProvider previous_ccp; | |
// This is the new ClickConfigProvider we will set, it just calls the old one and then subscribe | |
// for back button events. | |
void new_ccp(void *context) { | |
APP_LOG(APP_LOG_LEVEL_DEBUG, "calling the new ccp"); | |
previous_ccp(context); | |
window_single_click_subscribe(BUTTON_ID_BACK, back_button_handler); | |
APP_LOG(APP_LOG_LEVEL_DEBUG, "done in the new ccp"); | |
} | |
// Call this from your init function to do the hack | |
void force_back_button(Window *window, MenuLayer *menu_layer) { | |
previous_ccp = window_get_click_config_provider(window); | |
window_set_click_config_provider_with_context(window, new_ccp, menu_layer); | |
} | |
/* ... */ | |
void init() { | |
/* ... */ | |
menu_layer_set_click_config_onto_window(menu_layer, window); | |
force_back_button(window, menu_layer); | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment