Skip to content

Commit

Permalink
Merge pull request #8 from Calebe94/3_new_planning
Browse files Browse the repository at this point in the history
Added app screen
  • Loading branch information
Calebe94 authored Sep 26, 2021
2 parents 5e112d7 + 3c208b9 commit d0ee33d
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 141 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added comments to config file;
* Added `timely_app_t *current_app` pointer to store the opened app;
* Added methods to change context;
* Added style to watchface fonts;
* Added functions to manage the applications;

### Fixed

* Fixed typo in weather app;

### Changed

* Changed weather stock application by adding name and description labels;
* Renamed `timely_main` to `timely_watchface`;
* Renamed `timely_setup` to `timely_launcher`;

### Removed

* Removed unused event handler function;

## [0.1.0]

### Added
Expand Down
67 changes: 32 additions & 35 deletions apps/timely_weather_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
/**********************
* STATIC VARIABLES
**********************/
static lv_obj_t *weather_name_label;
static lv_obj_t *weather_description_label;
static lv_obj_t *weather_icon;
static lv_obj_t *weather_label;
static lv_style_t style_hour;

static lv_style_t style_name;
static lv_style_t style_description;

/**********************
* IMAGE DECLARATIONS
Expand All @@ -36,61 +38,56 @@ LV_IMG_DECLARE(cloudy_sun_48x48);
/**********************
* STATIC PROTOTYPES
**********************/
static void timely_weather_app_style_init()
{
lv_style_init(&style_hour);
lv_style_set_text_font(&style_hour, &lv_font_montserrat_48);
}

static void timely_format_time(int value, char *string)
static void timely_weather_style_init()
{
if(value < 9)
{
sprintf(string, "0%d", value);
}
else
{
sprintf(string, "%d", value);
}
}

static void weather_event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);

if(code == LV_EVENT_VALUE_CHANGED)
{
LV_LOG_USER("Toggled");
lv_style_init(&style_name);
lv_style_set_text_font(&style_name, &lv_font_montserrat_28);
lv_style_set_text_color(&style_name, lv_color_white());

}
lv_style_init(&style_description);
lv_style_set_text_font(&style_description, &lv_font_montserrat_14);
lv_style_set_text_color(&style_description, lv_color_white());
}
/**********************
* GLOBAL FUNCTIONS
**********************/

void timely_weather_init(void *context)
{
timely_weather_style_init();
lv_obj_t * context_obj = ((timely_app_t *) context)->context;

LV_LOG_USER("Clicked");
LV_LOG_USER( ((timely_app_t *) context)->name );
lv_obj_t *parent = lv_obj_get_parent(context_obj);
lv_obj_t * timely_tv = lv_obj_get_parent(context_obj);
lv_obj_t * weather_app_tile = lv_tileview_add_tile(timely_tv, 3, 1, LV_DIR_HOR);
lv_obj_add_event_cb(timely_tv, weather_event_handler, LV_EVENT_VALUE_CHANGED, NULL);

/**********************
* WEATHER ICON
* WEATHER APP NAME
*********************/
weather_name_label = lv_label_create(context_obj);
lv_label_set_long_mode(weather_name_label, LV_LABEL_LONG_WRAP); /*Circular scroll*/
lv_label_set_text(weather_name_label, ((timely_app_t *) context)->name);
lv_obj_add_style(weather_name_label, &style_name, 0);
lv_obj_align(weather_name_label, LV_ALIGN_CENTER, 0, -80);

/**********************
* WEATHER APP Description
*********************/
weather_description_label = lv_label_create(context_obj);
lv_label_set_long_mode(weather_description_label, LV_LABEL_LONG_WRAP); /*Circular scroll*/
lv_label_set_text(weather_description_label, ((timely_app_t *) context)->description);
lv_obj_add_style(weather_description_label, &style_description, 0);
lv_obj_align(weather_description_label, LV_ALIGN_CENTER, 0, 0);

weather_icon = lv_img_create(weather_app_tile);
/**********************
* WEATHER ICON
*********************/
weather_icon = lv_img_create(context_obj);
lv_img_set_src(weather_icon, &cloudy_sun_48x48);
lv_obj_align(weather_icon, LV_ALIGN_CENTER, 0, 60);

/**********************
* WEATHER LABEL
*********************/
weather_label = lv_label_create(weather_app_tile);
weather_label = lv_label_create(context_obj);
lv_label_set_long_mode(weather_label, LV_LABEL_LONG_WRAP); /*Circular scroll*/
//lv_obj_set_width(missed_notification_label, 90);
lv_label_set_text(weather_label, "16°C");
Expand Down
139 changes: 65 additions & 74 deletions src/timely_setup.c → src/timely_apps.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* @file timely.c
* @file timely_apps.c
*
*/

/*********************
* INCLUDES
*********************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "timely_setup.h"
#include "timely_main.h"
#include "timely_apps.h"
#include "timely_watchface.h"
#include "../timely_config.h"

/*********************
Expand All @@ -21,19 +22,29 @@
* EXTERNAL VARIABLES
**********************/

/**********************
* STATIC VARIABLES
**********************/
static lv_style_t font_style;
static lv_style_t style_btn;

#if USE_APPLICATIONS == 1
static lv_obj_t *timely_apps_tile;
static lv_obj_t *timely_app_tile;
static timely_app_t *current_app;
#endif

/**********************
* STATIC PROTOTYPES
**********************/

static void auto_del(lv_obj_t * obj, uint32_t delay)
static void timely_apps_style_init()
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, obj);
lv_anim_set_time(&a, 0);
lv_anim_set_delay(&a, delay);
lv_anim_set_ready_cb(&a, lv_obj_del_anim_ready_cb);
lv_anim_start(&a);
lv_style_init(&font_style);
lv_style_init(&style_btn);

lv_style_set_text_font(&font_style, &lv_font_montserrat_28);
lv_style_set_bg_color(&style_btn, lv_color_hex(0x2f3237));
}

static void event_handler(lv_event_t * e)
Expand All @@ -44,29 +55,60 @@ static void event_handler(lv_event_t * e)
{
LV_LOG_USER("Clicked");
timely_app_t *app = (timely_app_t*)lv_event_get_user_data(e);

app->on_init((void*)app);
lv_obj_set_tile_id(lv_obj_get_parent(app->context), 3, 1, LV_ANIM_ON);
app->context = timely_app_tile;
current_app = app;
//lv_obj_add_event_cb(timely_tv, weather_event_handler, LV_EVENT_VALUE_CHANGED, NULL);
if(app->on_init != NULL)
{
app->on_init((void*)app);
lv_obj_clear_flag(timely_app_tile, LV_OBJ_FLAG_HIDDEN);
//lv_obj_set_tile(timely_tv, weather_app_tile, LV_ANIM_ON);
lv_obj_set_tile_id(lv_obj_get_parent(timely_apps_tile), 3, 1, LV_ANIM_ON);
}
}
else if(code == LV_EVENT_VALUE_CHANGED)
{
LV_LOG_USER("Toggled");
}
}

static void init_apps(void *argv)
static void timely_app_event_handler(lv_event_t *event)
{
static lv_style_t font_style;
static lv_style_t style_btn;
lv_event_code_t code = lv_event_get_code(event);

lv_style_init(&font_style);
lv_style_init(&style_btn);
if (code == LV_EVENT_DEFOCUSED)
{
if (current_app != NULL && current_app->on_close != NULL)
{
current_app->on_close((void*)current_app);
current_app = NULL;
}
LV_LOG_USER("Saiu da tela do aplicativo");

lv_style_set_text_font(&font_style, &lv_font_montserrat_28);
lv_style_set_bg_color(&style_btn, lv_color_hex(0x2f3237));
lv_obj_clean(timely_app_tile);
lv_obj_add_flag(timely_app_tile, LV_OBJ_FLAG_HIDDEN);
}
}

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/

void timely_apps_init(lv_obj_t *context)
{
timely_apps_style_init();
timely_apps_tile = context;
lv_obj_t * timely_tv = lv_obj_get_parent(timely_apps_tile);
timely_app_tile = lv_tileview_add_tile(timely_tv, 3, 1, LV_DIR_HOR);
lv_obj_add_event_cb(timely_app_tile, timely_app_event_handler, LV_EVENT_DEFOCUSED, NULL);
lv_obj_add_flag(timely_app_tile, LV_OBJ_FLAG_HIDDEN);
#if USE_APPLICATIONS == 1
#endif
lv_obj_t * label, *icon;
lv_obj_t *context = (lv_obj_t*)argv;

int app_align = -80;
for(int index = 0; index < LENGTH(apps); index++)
Expand All @@ -84,7 +126,7 @@ static void init_apps(void *argv)
lv_img_set_src(icon, apps[index].icon);
//lv_img_set_src(icon, &activity_48x48);
}
apps[index].context = argv;
apps[index].context = timely_app_tile;

// App title label
label = lv_label_create(btn1);
Expand All @@ -99,54 +141,3 @@ static void init_apps(void *argv)
app_align += 80;
}
}

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/

void timely_launcher_init(void)
{
lv_obj_t * obj;

lv_style_t text_style;
lv_style_init(&text_style);
lv_style_set_text_font(&text_style, &lv_font_montserrat_48); /*Set a larger font*/

static lv_style_t style_tileview;
lv_style_init(&style_tileview);
lv_style_set_bg_color(&style_tileview, lv_color_black());

lv_obj_t * timely_tv = lv_tileview_create(lv_scr_act());
lv_obj_set_size(timely_tv, 240, 240);
lv_obj_set_scrollbar_mode(timely_tv, LV_SCROLLBAR_MODE_OFF);
lv_obj_add_style(timely_tv, &style_tileview, 0);

obj = lv_tileview_add_tile(timely_tv, 1, 0, LV_DIR_VER);
obj = lv_label_create(obj);
lv_label_set_text(obj, "Settings: 1;0");
//lv_obj_add_style(obj, &text_style, 0);

obj = lv_tileview_add_tile(timely_tv, 1, 1, LV_DIR_ALL);
timely_main_init(obj);
//obj = lv_label_create(obj);
//lv_label_set_text(obj, "Main Tile: 1;1");

obj = lv_tileview_add_tile(timely_tv, 1, 2, LV_DIR_VER);
obj = lv_label_create(obj);
lv_label_set_text(obj, "Notifications: 1;2");

obj = lv_tileview_add_tile(timely_tv, 2, 1, LV_DIR_HOR);
//obj = lv_label_create(obj);
//lv_label_set_text(obj, "Apps: 2;1");
init_apps((lv_obj_t*) obj);

obj = lv_tileview_add_tile(timely_tv, 0, 1, LV_DIR_HOR);
obj = lv_label_create(obj);
lv_label_set_text(obj, "Favorites: 1;2");

lv_obj_set_tile_id(timely_tv, 1, 1, LV_ANIM_OFF);
}
8 changes: 4 additions & 4 deletions src/timely_setup.h → src/timely_apps.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @file timely.h
* @file timely_apps.h
*
*/

#ifndef _TIMELY_H_
#define _TIMELY_H_
#ifndef _TIMELY_APPS_H_
#define _TIMELY_APPS_H_

#ifdef __cplusplus
extern "C" {
Expand All @@ -27,7 +27,7 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/

void timely_launcher_init(void);
void timely_apps_init(lv_obj_t *);

/**********************
* MACROS
Expand Down
Loading

0 comments on commit d0ee33d

Please sign in to comment.