Add 'examples/hello/' from commit 'e88e5a6ff3b0f55671cb64c0a506e552360010e9'

git-subtree-dir: examples/hello
git-subtree-mainline: f44e3bc6d0
git-subtree-split: e88e5a6ff3
This commit is contained in:
MeowOS committed 2026-09-01 21:08:44 +08:00
commit 4f66da66ad
13 files changed
+1296

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
/* logic/logic.h — 业务层接口(纯 C,不依赖 meow_ui.h / meow_view)。
*
* 分层契约(SDK_VIEW_FRAMEWORK_DESIGN.md §B.1):
* ① UI→业务 = 纯函数命令 + getter(logic_* / notify_* 返回业务态,业务不回调 UI);
* ② 业务→UI = 可选 push 监听器(logic_listener_fn + logic_set_listener);
* ③ view 的 ctx = 视图控制器(biz-UI 绑定点)。
* 本头只声明数据类型与函数原型,不含任何 meow_ui.h / meow_ui_view.h 依赖——
* logic/state.c 因此保持纯 C;logic/notify.c 仅因要用 SDK 通知 API 而 include meow_ui.h。
*/
#ifndef HELLO_LOGIC_H
#define HELLO_LOGIC_H
/* 监听器事件类型(业务态变化 → 通知 UI) */
#define LOGIC_EV_TAPS 1 /* taps 计数变化 */
#define LOGIC_EV_SECS 2 /* secs 秒计数变化 */
#define LOGIC_EV_PROG 3 /* demo 进度值变化(批③ 语义值上收) */
typedef void (*logic_listener_fn)(int ev, void *ctx); /* ctx = 监听器注册时给的视图控制器 */
/* ---- 计数业务态(logic/state.c)---- */
int logic_taps_get(void); /* 返回累计 taps */
void logic_taps_bump(void); /* taps++,并触发监听器(若已注册) */
int logic_secs_get(void); /* 返回过去秒数 */
void logic_secs_add(int n); /* secs += n,并触发监听器(若已注册) */
int logic_prog_get(void); /* 返回 demo 进度值 0..100(批③ 语义值上收) */
void logic_prog_set(int p); /* 设置进度值(clamp 0..100),并触发监听器(若已注册) */
void logic_set_listener(logic_listener_fn cb, void *ctx); /* 注册业务→UI 推送监听器(可 NULL 注销) */
/* ---- 通知业务(logic/notify.c)---- */
void notif_send(int which); /* 按索引发一条通知(数据/超时/优先级在业务层定) */
void notif_cancel(void); /* 取消最近一条发送的通知 */
#endif /* HELLO_LOGIC_H */
+56
View File
@@ -0,0 +1,56 @@
/* logic/notify.c — 通知业务(notif_send/notif_cancel)。
*
* 纯业务:只依赖 SDK 通知数据类型/API(meow_notify_*)+ meow_log,不碰任何 UI 控件/view。
* UI 只经 notif_send()/notif_cancel() 调用(契约 ①);本层不回调 UI,最近一条 id 由本层持有。
* 注:boundary 折中——通知是 SDK 服务(§9.1),故本文件 include meow_ui.h 仅用其通知类型/函数。
*/
#include "logic.h"
#include "meow_ui.h"
#include <string.h>
#include <stdint.h>
static uint32_t g_last_notif = 0; /* 最近一次 send 返回的 id,供 cancel */
void notif_send(int which)
{
meow_notify n;
memset(&n, 0, sizeof n);
n.progress = -1;
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_NEVER;
n.urgency = MEOW_NOTIFY_URG_NORMAL;
const char *label = "?";
switch (which) {
case 0: label = "INFO"; n.cat = MEOW_NOTIFY_CAT_GENERAL;
n.title = "测试-普通通知"; n.body = "普通 INFO 通知,timeout=5000ms"; n.timeout_ms = 5000; break;
case 1: label = "MEDIA"; n.cat = MEOW_NOTIFY_CAT_MEDIA; n.urgency = MEOW_NOTIFY_URG_LOW;
n.title = "测试-媒体通知"; n.body = "媒体单例,正在播放,timeout=-1 常驻";
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_ONGOING; break;
case 2: label = "HIGH"; n.cat = MEOW_NOTIFY_CAT_GENERAL; n.urgency = MEOW_NOTIFY_URG_HIGH;
n.title = "测试-紧急度HIGH"; n.body = "高紧急度:顶部横幅+提示音"; n.timeout_ms = 3000; break;
case 3: label = "PROG"; n.cat = MEOW_NOTIFY_CAT_PROGRESS;
n.title = "测试-进度通知"; n.body = "下载进度 40%"; n.timeout_ms = 8000; n.progress = 40; break;
case 4: label = "ONGO"; n.cat = MEOW_NOTIFY_CAT_GENERAL;
n.title = "测试-常驻通知"; n.body = "常驻不自动过期(timeout=-1),需手动取消";
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_ONGOING; break;
case 5: label = "TGT"; n.cat = MEOW_NOTIFY_CAT_MESSAGE;
n.title = "测试-跳转Activity"; n.body = "点击跳转 target_activity=main";
n.timeout_ms = 6000; n.target_activity = "main"; n.icon = NULL; break;
default: return;
}
uint32_t id = meow_notify_send(&n);
g_last_notif = id;
meow_log(MEOW_LOG_INFO,
"notify btn=%s id=%u cat=%s urg=%s tmo=%d prog=%d target=%s title=%s",
label, (unsigned)id, meow_notify_category_str(n.cat),
meow_notify_urgency_str(n.urgency), n.timeout_ms, n.progress,
n.target_activity ? n.target_activity : "-", n.title ? n.title : "-");
}
void notif_cancel(void)
{
int r = meow_notify_cancel(g_last_notif);
meow_log(MEOW_LOG_INFO, "notify cancel id=%u result=%d", (unsigned)g_last_notif, r);
g_last_notif = 0;
}
+51
View File
@@ -0,0 +1,51 @@
/* logic/state.c — 计数业务态(taps/secs)+ 可选推送监听器(biz→UI)。
*
* 纯 C(无 meow_ui.h 依赖):状态 + getter/setter + 监听器。UI 经 logic_taps_bump()/
* logic_secs_add() 改状态;业务改后触发监听器(若已注册)通知 UI 刷新——契约 ①②(§B.1)。
*/
#include "logic.h"
#include <stddef.h>
static int g_taps = 0;
static int g_secs = 0;
static int g_prog = 0; /* demo 进度语义值 0..100(批③ 自 ui/demo/demo.c 上收) */
static logic_listener_fn g_listener = NULL;
static void *g_listener_ctx = NULL;
int logic_taps_get(void)
{
return g_taps;
}
void logic_taps_bump(void)
{
g_taps++;
if (g_listener) g_listener(LOGIC_EV_TAPS, g_listener_ctx);
}
int logic_secs_get(void)
{
return g_secs;
}
void logic_secs_add(int n)
{
g_secs += n;
if (g_listener) g_listener(LOGIC_EV_SECS, g_listener_ctx);
}
int logic_prog_get(void)
{
return g_prog;
}
void logic_prog_set(int p)
{
if (p < 0) p = 0;
if (p > 100) p = 100;
g_prog = p;
if (g_listener) g_listener(LOGIC_EV_PROG, g_listener_ctx);
}
void logic_set_listener(logic_listener_fn cb, void *ctx)
{
g_listener = cb;
g_listener_ctx = ctx;
}