Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The channels sample will use a dialog and toast

Before, this sample used 2 dialogs.  The ability to control the
position of the dialogs has been deprecated so the two dialogs
overlap.  This is undesirable so we have changed one of them into
a toast.
  • Loading branch information...
commit a32a777281e4494157c865d55f4b450c24c0962d 1 parent 7a2fa18
Anthony Hu authored
Showing with 59 additions and 61 deletions.
  1. +31 −36 Channels/dialogutil.c
  2. +18 −15 Channels/dialogutil.h
  3. +10 −10 Channels/main.c
View
67 Channels/dialogutil.c
@@ -25,8 +25,8 @@
static screen_context_t screen_ctx = 0;
static screen_window_t screen_win = 0;
-static dialog_instance_t top_dialog = 0;
-static dialog_instance_t bottom_dialog = 0;
+static dialog_instance_t geolocation_dialog = 0;
+static dialog_instance_t accelerometer_dialog = 0;
/**
@@ -129,67 +129,62 @@ void cleanup_screen() {
void
-create_bottom_dialog()
+create_geolocation_dialog()
{
- if (bottom_dialog == NULL) {
- dialog_create_alert(&bottom_dialog);
- dialog_set_alert_message_text(bottom_dialog, "\n");
- dialog_set_background_alpha(bottom_dialog, 0.0);
- dialog_set_size(bottom_dialog, DIALOG_SIZE_SMALL);
- dialog_set_position(bottom_dialog, DIALOG_POSITION_BOTTOM_CENTER);
- dialog_set_group_id(bottom_dialog, get_window_group_id());
- dialog_set_cancel_required(bottom_dialog, true);
- dialog_show(bottom_dialog);
+ if (accelerometer_dialog == NULL) {
+ dialog_create_alert(&geolocation_dialog);
+ dialog_set_alert_message_text(geolocation_dialog, "\n");
+ dialog_set_group_id(geolocation_dialog, get_window_group_id());
+ dialog_set_cancel_required(geolocation_dialog, true);
+ dialog_show(geolocation_dialog);
}
}
void
-create_top_dialog()
+create_accelerometer_dialog()
{
- if (top_dialog == NULL) {
- dialog_create_alert(&top_dialog);
- dialog_set_alert_message_text(top_dialog, "\n");
- dialog_set_background_alpha(top_dialog, 0.0);
- dialog_set_size(top_dialog, DIALOG_SIZE_SMALL);
- dialog_set_position(top_dialog, DIALOG_POSITION_TOP_CENTER);
- dialog_set_group_id(top_dialog, get_window_group_id());
- dialog_set_cancel_required(top_dialog, true);
- dialog_show(top_dialog);
+ if (accelerometer_dialog == NULL) {
+ dialog_create_toast(&accelerometer_dialog);
+ dialog_set_toast_message_text(accelerometer_dialog, "\n");
+ dialog_set_toast_position(accelerometer_dialog, DIALOG_POSITION_BOTTOM_CENTER);
+ dialog_set_group_id(accelerometer_dialog, get_window_group_id());
+ dialog_add_button(accelerometer_dialog, "OK", true, NULL, true);
+ dialog_show(accelerometer_dialog);
}
}
void
-destroy_top_dialog() {
- if (top_dialog) {
- dialog_destroy(top_dialog);
+destroy_geolocation_dialog() {
+ if (geolocation_dialog) {
+ dialog_destroy(geolocation_dialog);
}
- top_dialog = 0;
+ geolocation_dialog = 0;
}
void
-destroy_bottom_dialog() {
+destroy_accelerometer_dialog() {
- if (bottom_dialog) {
- dialog_destroy(bottom_dialog);
+ if (accelerometer_dialog) {
+ dialog_destroy(accelerometer_dialog);
}
- bottom_dialog = 0;
+ accelerometer_dialog = 0;
}
void
-show_top_dialog_message(const char * msg) {
- dialog_set_alert_message_text(top_dialog, msg);
- dialog_update(top_dialog);
+show_geolocation_dialog_message(const char * msg) {
+ dialog_set_alert_message_text(geolocation_dialog, msg);
+ dialog_update(geolocation_dialog);
fprintf(stderr, "%s\n", msg);
}
void
-show_bottom_dialog_message(const char * msg) {
- dialog_set_alert_message_text(bottom_dialog, msg);
- dialog_update(bottom_dialog);
+show_accelerometer_dialog_message(const char * msg) {
+ dialog_set_alert_message_text(accelerometer_dialog, msg);
+ dialog_update(accelerometer_dialog);
fprintf(stderr, "%s\n", msg);
}
View
33 Channels/dialogutil.h
@@ -27,7 +27,7 @@
int setup_screen();
/**
- * Clean up all the resources that were allocated by setup_screen().
+ * Clean up all the resources that were allocated by @c setup_screen().
*/
void cleanup_screen();
@@ -35,41 +35,44 @@ void cleanup_screen();
* Show an alert dialog to display general data along the bottom
* of the screen.
*/
-void create_bottom_dialog();
+void create_accelerometer_dialog();
/**
* Show an alert dialog to display general data along the top
* of the screen.
*/
-void create_top_dialog();
+void create_geolocation_dialog();
/**
- * Destroy the top dialog that was created by create_top_dialog.
+ * Destroy the top dialog that was created by @c create_geolocation_dialog().
*/
-void destroy_top_dialog();
+void destroy_geolocation_dialog();
/**
- * Destroy the bottom dialog that was created by create_bottom_dialog.
+ * Destroy the bottom dialog that was created by
+ * @c create_accelerometer_dialog().
*/
-void destroy_bottom_dialog();
+void destroy_accelerometer_dialog();
/**
- * Displays a message to the top dialog created by create_dialogs() and
- * outputs that message to stderr. This means it will get added
- * to the log file in the sandbox and output to the console.
+ * Displays a message to the top dialog created by
+ * @c create_geolocation_dialogs() and outputs that message to stderr. This
+ * means it will get added to the log file in the sandbox and output to the
+ * console.
*
* @param msg the message to be displayed.
*/
-void show_top_dialog_message(const char *msg);
+void show_geolocation_dialog_message(const char *msg);
/**
- * Displays a message to the bottom dialog created by create_dialogs() and
- * outputs that message to stderr. This means it will get added
- * to the log file in the sandbox and output to the console.
+ * Displays a message to the bottom dialog created by
+ * @c create_accelerometer_dialogs() and outputs that message to stderr.
+ * This means it will get added to the log file in the sandbox and output to
+ * the console.
*
* @param msg the message to be displayed.
*/
-void show_bottom_dialog_message(const char *msg);
+void show_accelerometer_dialog_message(const char *msg);
#endif /* DIALOGUTIL_H_ */
View
20 Channels/main.c
@@ -85,7 +85,7 @@ display_accelerometer_reading(float x, float y, float z)
* Display the accelerometer values
*/
snprintf(accel_msg, MSG_SIZE, "\n\nx: %f, y: %f, z: %f\n", x, y, z);
- show_bottom_dialog_message(accel_msg);
+ show_accelerometer_dialog_message(accel_msg);
}
/**
@@ -136,7 +136,7 @@ handle_geolocation_response(bps_event_t *event)
count,
latitude, longitude, accuracy);
- show_top_dialog_message(msg);
+ show_geolocation_dialog_message(msg);
count++;
}
@@ -168,8 +168,8 @@ accel_main (void *p) {
/*
* Create and display a dialog that will show the data.
*/
- create_bottom_dialog();
- show_bottom_dialog_message("\n\nThis is the Accelerometer Dialog");
+ create_accelerometer_dialog();
+ show_accelerometer_dialog_message("\n\nThis is the Accelerometer Dialog");
if (BPS_SUCCESS != sensor_request_events(SENSOR_TYPE_ACCELEROMETER)) {
fprintf(stderr, "Error requesting sensor's accelerometer events: %s", strerror(errno));
@@ -200,7 +200,7 @@ accel_main (void *p) {
}
sensor_stop_events(0);
- destroy_bottom_dialog();
+ destroy_accelerometer_dialog();
bps_shutdown();
@@ -273,8 +273,8 @@ main(int argc, char *argv[])
/*
* Create and display the dialogs that will show the data.
*/
- create_top_dialog();
- show_top_dialog_message("Geolocation getting first fix");
+ create_geolocation_dialog();
+ show_geolocation_dialog_message("Geolocation getting first fix");
/*
* Before initializing the accelerometer service we must ensure the device
@@ -286,12 +286,12 @@ main(int argc, char *argv[])
* clean up and exit
*/
snprintf(msg, MSG_SIZE, "Accelerometer not supported by device!");
- show_top_dialog_message(msg);
+ show_geolocation_dialog_message(msg);
/*
* Destroy the dialog, if it exists and cleanup screen resources.
*/
- destroy_top_dialog();
+ destroy_geolocation_dialog();
cleanup_screen();
bps_shutdown();
return EXIT_FAILURE;
@@ -353,7 +353,7 @@ main(int argc, char *argv[])
/*
* Destroy the dialog, if it exists.
*/
- destroy_top_dialog();
+ destroy_geolocation_dialog();
bps_shutdown();
cleanup_screen();
Please sign in to comment.
Something went wrong with that request. Please try again.