Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"WeatherUVIndex",
"SettingAltClockName",
"SettingAltClockOffset",
"SettingAutoReplaceIndex",
"SettingDisableAutobattery",
"SettingBluetoothVibe",
"SettingDisconnectIcon",
Expand All @@ -48,6 +49,7 @@
"SettingColorSidebar",
"SettingColorTime",
"SettingDecimalSep",
"SettingDisableAutoQuietTime",
"SettingHealthUseDistance",
"SettingHealthUseRestfulSleep",
"SettingHourlyVibe",
Expand Down Expand Up @@ -199,6 +201,11 @@
"name": "HEALTH_HEART",
"type": "raw"
},
{
"file": "data/QUIET_TIME.pdc",
"name": "QUIET_TIME",
"type": "raw"
},
{
"file": "images/digit_leco_9.png",
"name": "CLOCK_DIGIT_LECO_9",
Expand Down
Binary file added resources/data/QUIET_TIME.pdc
Binary file not shown.
10 changes: 10 additions & 0 deletions src/c/messaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) {
Tuple *healthUseRestfulSleep_tuple = dict_find(iterator, MESSAGE_KEY_SettingHealthUseRestfulSleep);

Tuple *autobattery_tuple = dict_find(iterator, MESSAGE_KEY_SettingDisableAutobattery);
Tuple *autoQuietTime_tuple = dict_find(iterator, MESSAGE_KEY_SettingDisableAutoQuietTime);

Tuple *activateDisconnectIcon_tuple = dict_find(iterator, MESSAGE_KEY_SettingDisconnectIcon);

Tuple *autoReplaceIndex_tuple = dict_find(iterator, MESSAGE_KEY_SettingAutoReplaceIndex);

if(timeColor_tuple != NULL) {
settings.timeColor = GColorFromHEX(timeColor_tuple->value->int32);
Expand Down Expand Up @@ -147,6 +149,10 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) {
settings.disableAutobattery = (bool)autobattery_tuple->value->int8;
}

if(autoQuietTime_tuple != NULL) {
settings.disableAutoQuietTime = (bool)autoQuietTime_tuple->value->int8;
}

if(clockFont_tuple != NULL) {
settings.clockFontId = clockFont_tuple->value->int8;
}
Expand Down Expand Up @@ -199,6 +205,10 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) {
settings.activateDisconnectIcon = (bool)activateDisconnectIcon_tuple->value->int8;
}

if(autoReplaceIndex_tuple != NULL) {
settings.autoReplaceIndex = autoReplaceIndex_tuple->value->int8;
}

// save the new settings to persistent storage
Settings_saveToStorage();

Expand Down
6 changes: 6 additions & 0 deletions src/c/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ void Settings_loadFromStorage() {
settings.decimalSeparator = '.';
settings.showBatteryPct = true;

#ifdef PBL_ROUND
settings.autoReplaceIndex = 0;
#else
settings.autoReplaceIndex = 1;
#endif

// to correct settings migration bug (settings key v6), we must do another migration (nooooooooooo)
if (persist_exists(SETTINGS_PERSIST_KEY)) {
int version = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/c/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ typedef struct {
bool healthUseDistance;
bool healthUseRestfulSleep;
char decimalSeparator;

// quiet time widget settings
bool disableAutoQuietTime; // TODO only works with certain versions?

// auto replace index preference
uint8_t autoReplaceIndex;
} Settings;

// Dynamic settings (calculated at runtime based on currently-selected widgets)
Expand Down
62 changes: 40 additions & 22 deletions src/c/sidebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,39 @@ bool isAutoBatteryShown() {
return false;
}

bool isAutoQuietTimeShown() {
return !settings.disableAutoQuietTime && quiet_time_is_active();
}

#ifdef PBL_ROUND

// returns the best candidate widget for replacement by the auto battery
// or the disconnection icon
int getReplacableWidget() {
// returns the best candidate widget for replacement by auto widgets
int getReplacableWidget(bool isDisconnect) {
// if any widgets are empty, it's an obvious choice
if(settings.widgets[0] == EMPTY) {
return 0;
} else if(settings.widgets[2] == EMPTY) {
return 2;
}

if(settings.widgets[0] == WEATHER_CURRENT || settings.widgets[0] == WEATHER_FORECAST_TODAY) {
return 0;
} else if(settings.widgets[2] == WEATHER_CURRENT || settings.widgets[2] == WEATHER_FORECAST_TODAY) {
return 2;
// are there any bluetooth-enabled widgets? if so, they're the second-best
// candidates for disconnection
if(isDisconnect) {
if(settings.widgets[0] == WEATHER_CURRENT || settings.widgets[0] == WEATHER_FORECAST_TODAY) {
return 0;
} else if(settings.widgets[2] == WEATHER_CURRENT || settings.widgets[2] == WEATHER_FORECAST_TODAY) {
return 2;
}
}

// if we don't have any of those things, just replace the left widget
return 0;
// if we don't have any of those things, replace the preferred widget
return settings.autoReplaceIndex; // TODO does PBL_ROUND only have two slots? Can't let them set 1 as auto replace index?
}

#else

// returns the best candidate widget for replacement by the auto battery
// or the disconnection icon
int getReplacableWidget() {
// returns the best candidate widget for replacement by auto widgets
int getReplacableWidget(bool isDisconnect) {
// if any widgets are empty, it's an obvious choice
for(int i = 0; i < 3; i++) {
if(settings.widgets[i] == EMPTY) {
Expand All @@ -148,15 +154,17 @@ int getReplacableWidget() {
}

// are there any bluetooth-enabled widgets? if so, they're the second-best
// candidates
for(int i = 0; i < 3; i++) {
if(settings.widgets[i] == WEATHER_CURRENT || settings.widgets[i] == WEATHER_FORECAST_TODAY) {
return i;
// candidates for disconnection
if(isDisconnect) {
for(int i = 0; i < 3; i++) {
if(settings.widgets[i] == WEATHER_CURRENT || settings.widgets[i] == WEATHER_FORECAST_TODAY) {
return i;
}
}
}

// if we don't have any of those things, just replace the middle widget
return 1;
// if we don't have any of those things, replace the preferred widget
return settings.autoReplaceIndex;
}

#endif
Expand All @@ -169,14 +177,17 @@ void updateRoundSidebarRight(Layer *l, GContext* ctx) {

bool showDisconnectIcon = !bluetooth_connection_service_peek();
bool showAutoBattery = isAutoBatteryShown();
bool showAutoQuietTime = isAutoQuietTimeShown();

SidebarWidgetType displayWidget = settings.widgets[2];

if((showAutoBattery || showDisconnectIcon) && getReplacableWidget() == 2) {
if((showAutoBattery || showDisconnectIcon || showAutoQuietTime) && getReplacableWidget(showDisconnectIcon) == 2) {
if(showAutoBattery) {
displayWidget = BATTERY_METER;
} else if(showDisconnectIcon) {
displayWidget = BLUETOOTH_DISCONNECT;
} else if(showAutoQuietTime) {
displayWidget = QUIET_TIME;
}
}

Expand All @@ -189,13 +200,17 @@ void updateRoundSidebarLeft(Layer *l, GContext* ctx) {

bool showDisconnectIcon = !bluetooth_connection_service_peek();
bool showAutoBattery = isAutoBatteryShown();
bool showAutoQuietTime = isAutoQuietTimeShown();

SidebarWidgetType displayWidget = settings.widgets[0];

if((showAutoBattery || showDisconnectIcon) && getReplacableWidget() == 0) {
if((showAutoBattery || showDisconnectIcon || showAutoQuietTime) && getReplacableWidget(showDisconnectIcon) == 0) {
if(showAutoBattery) {
displayWidget = BATTERY_METER;
} else if(showDisconnectIcon) {
displayWidget = BLUETOOTH_DISCONNECT;
} else if(showAutoQuietTime) {
displayWidget = QUIET_TIME;
}
}

Expand Down Expand Up @@ -239,6 +254,7 @@ void updateRectSidebar(Layer *l, GContext* ctx) {

bool showDisconnectIcon = false;
bool showAutoBattery = isAutoBatteryShown();
bool showAutoQuietTime = isAutoQuietTimeShown();

// if the pebble is disconnected and activated, show the disconnect icon
if(settings.activateDisconnectIcon) {
Expand All @@ -253,13 +269,15 @@ void updateRectSidebar(Layer *l, GContext* ctx) {

// do we need to replace a widget?
// if so, determine which widget should be replaced
if(showAutoBattery || showDisconnectIcon) {
int widget_to_replace = getReplacableWidget();
if(showAutoBattery || showDisconnectIcon || showAutoQuietTime) {
int widget_to_replace = getReplacableWidget(showDisconnectIcon);

if(showAutoBattery) {
displayWidgets[widget_to_replace] = getSidebarWidgetByType(BATTERY_METER);
} else if(showDisconnectIcon) {
displayWidgets[widget_to_replace] = getSidebarWidgetByType(BLUETOOTH_DISCONNECT);
} else if(showAutoQuietTime) {
displayWidgets[widget_to_replace] = getSidebarWidgetByType(QUIET_TIME);
}
}

Expand Down
37 changes: 26 additions & 11 deletions src/c/sidebar_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GDrawCommandImage* dateImage;
GDrawCommandImage* disconnectImage;
GDrawCommandImage* batteryImage;
GDrawCommandImage* batteryChargeImage;
GDrawCommandImage* quietTimeImage;

// fonts
GFont smSidebarFont;
Expand Down Expand Up @@ -76,6 +77,10 @@ SidebarWidget uvIndexWidget;
int UVIndex_getHeight();
void UVIndex_draw(GContext* ctx, int yPosition);

SidebarWidget quietTimeWidget;
int QuietTime_getHeight();
void QuietTime_draw(GContext* ctx, int yPosition);

#ifdef PBL_HEALTH
GDrawCommandImage* sleepImage;
GDrawCommandImage* stepsImage;
Expand Down Expand Up @@ -105,6 +110,7 @@ void SidebarWidgets_init() {
disconnectImage = gdraw_command_image_create_with_resource(RESOURCE_ID_DISCONNECTED);
batteryImage = gdraw_command_image_create_with_resource(RESOURCE_ID_BATTERY_BG);
batteryChargeImage = gdraw_command_image_create_with_resource(RESOURCE_ID_BATTERY_CHARGE);
quietTimeImage = gdraw_command_image_create_with_resource(RESOURCE_ID_QUIET_TIME);

#ifdef PBL_HEALTH
sleepImage = gdraw_command_image_create_with_resource(RESOURCE_ID_HEALTH_SLEEP);
Expand Down Expand Up @@ -156,13 +162,17 @@ void SidebarWidgets_init() {

beatsWidget.getHeight = Beats_getHeight;
beatsWidget.draw = Beats_draw;

quietTimeWidget.getHeight = QuietTime_getHeight;
quietTimeWidget.draw = QuietTime_draw;
}

void SidebarWidgets_deinit() {
gdraw_command_image_destroy(dateImage);
gdraw_command_image_destroy(disconnectImage);
gdraw_command_image_destroy(batteryImage);
gdraw_command_image_destroy(batteryChargeImage);
gdraw_command_image_destroy(quietTimeImage);

#ifdef PBL_HEALTH
gdraw_command_image_destroy(stepsImage);
Expand Down Expand Up @@ -249,25 +259,18 @@ SidebarWidget getSidebarWidgetByType(SidebarWidgetType type) {
switch(type) {
case BATTERY_METER:
return batteryMeterWidget;
break;
case BLUETOOTH_DISCONNECT:
return btDisconnectWidget;
break;
case DATE:
return dateWidget;
break;
case ALT_TIME_ZONE:
return altTimeWidget;
break;
case SECONDS:
return secondsWidget;
break;
case WEATHER_CURRENT:
return currentWeatherWidget;
break;
case WEATHER_FORECAST_TODAY:
return weatherForecastWidget;
break;
case WEEK_NUMBER:
return weekNumberWidget;
case WEATHER_UV_INDEX:
Expand All @@ -282,9 +285,10 @@ SidebarWidget getSidebarWidgetByType(SidebarWidgetType type) {
#endif
case BEATS:
return beatsWidget;
case QUIET_TIME:
return quietTimeWidget;
default:
return emptyWidget;
break;
}
}

Expand Down Expand Up @@ -521,8 +525,6 @@ int BTDisconnect_getHeight() {
void BTDisconnect_draw(GContext* ctx, int yPosition) {
if(disconnectImage) {
gdraw_command_image_recolor(disconnectImage, dynamicSettings.iconFillColor, dynamicSettings.iconStrokeColor);


gdraw_command_image_draw(ctx, disconnectImage, GPoint(3 + SidebarWidgets_xOffset, yPosition));
}
}
Expand Down Expand Up @@ -888,7 +890,7 @@ void SleepTimer_draw(GContext* ctx, int yPosition) {

}


/***** Heart Rate Widget *****/

int HeartRate_getHeight() {
if(settings.useLargeFonts) {
Expand Down Expand Up @@ -951,3 +953,16 @@ void Beats_draw(GContext* ctx, int yPosition) {
GTextAlignmentCenter,
NULL);
}

/***** Quiet Time Widget *****/

int QuietTime_getHeight() {
return 26;
}

void QuietTime_draw(GContext* ctx, int yPosition) {
if(quietTimeImage) {
gdraw_command_image_recolor(quietTimeImage, dynamicSettings.iconFillColor, dynamicSettings.iconStrokeColor);
gdraw_command_image_draw(ctx, quietTimeImage, GPoint(2 + SidebarWidgets_xOffset, yPosition));
}
}
3 changes: 2 additions & 1 deletion src/c/sidebar_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ typedef enum {
STEP_COUNTER = 10,
BEATS = 11,
HEARTRATE = 12,
WEATHER_UV_INDEX = 13
WEATHER_UV_INDEX = 13,
QUIET_TIME = 14
} SidebarWidgetType;

typedef struct {
Expand Down
11 changes: 11 additions & 0 deletions src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ Pebble.addEventListener('webviewclosed', function(e) {
}
}

// TODO can't handle PBL_ROUND here to have different default
if(configData.auto_replace_index_setting) {
if(configData.auto_replace_index_setting == '0') {
dict.SettingAutoReplaceIndex = 0;
} else if (configData.auto_replace_index_setting == '2') {
dict.SettingAutoReplaceIndex = 2;
} else {
dict.SettingAutoReplaceIndex = 1;
}
}

// notification settings
if(configData.hourly_vibe_setting) {
if(configData.hourly_vibe_setting == 'yes') {
Expand Down