| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 2,698 | 2,495 | ||
| hvigor/ | 06-May-2025 | - | 22 | 21 | ||
| lib/ | 06-May-2025 | - | ||||
| screenshots/devices/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 143 | 12 | 11 | |
| README.md | D | 06-May-2025 | 1.5 KiB | 35 | 18 | |
| README_zh.md | D | 06-May-2025 | 6.4 KiB | 123 | 95 | |
| build-profile.json5 | D | 06-May-2025 | 1.1 KiB | 43 | 42 | |
| hvigorfile.ts | D | 06-May-2025 | 158 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 814 | 26 | 25 | |
| ohosTest.md | D | 06-May-2025 | 1.5 KiB | 18 | 16 |
README.md
1# Flip Clock 2 3### Introduction 4 5 This sample uses the Feature Ability (FA) model and related APIs to implement a simple flip clock app. Below shows the sample app. 6 7  8 9### Concepts 10 11**reminderAgent**: a class that provides APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background when your application is frozen or exits. 12 13### Required Permissions 14 15ohos.permission.PUBLISH_AGENT_REMINDER (permission for the reminder agent) 16 17ohos.permission.RUNNING_LOCK (permission for the running lock) 18 19ohos.permission.NOTIFICATION_CONTROLLER (permission for send notification) 20 21### Usage 22 231. There are four tab bars (**Clock**, **Alarm**, **Countdown**, and **Settings**) at the bottom of the home page of the sample app. The **Clock** tab page displays a flip clock. 24 252. On the **Alarm** tab page, you can touch **+** to create an alarm record. When the alarm time arrives, a notification will be displayed. 26 273. The **Countdown** tab page provides the countdown function. 28 294. The **Settings** tab page provides the following functions: full screen, screen brightness adjustment, and screen-on. 30 31### Constraints 32 331. This sample can only be run on standard-system devices. 34 352. This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100, built on November 3, 2022) to compile and run.
README_zh.md
1# 翻页时钟 2 3### 介绍 4 5本示例集中展示了时钟、闹钟、倒计时、设置屏幕亮度相关的场景, 61、使用[@ohos.reminderAgentManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-backgroundtasks-kit/js-apis-reminderAgentManager.md )完成闹钟的相关功能, 72、使用animateTo完成翻页时钟动画,使用[@ohos.runningLock](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-runninglock.md )完成屏幕常亮功能, 83、设置屏幕亮度,使用[@ohos.brightness](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-brightness-sys.md )系统能力调节屏幕亮度, 94、后台消息提醒,使用[@ohos.notificationManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notificationManager.md )系统能力做后台代理提醒。 105、需要系统存储信息,使用用户首选项接口[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md )。 11 12 13### 效果预览 14 15|首页|闹钟|倒计时|设置| 16|----------------|----------------------|----------------------|----------------------| 17| | | || 18 19使用说明 20 211.主页面有四个底部标签栏,时钟页面展示了数字翻页时钟功能。 22 232.闹钟功能点击**+**号可以创建一个闹钟,等闹钟时间到了会进行提醒。 24 253.倒计时功能。 26 274.设置相关功能需安装[Brightness](./lib/Brightness-1.0.0.hap)应用,设置里边实现的功能有全屏、调节屏幕亮度和不熄屏。 28 29### 工程目录 30``` 31entry/src/main/ets/ 32|---common 33| |---AlarmClock.ets // 闹钟组件 34| |---CountDown.ets // 倒计时组件 35| |---CustomDataPicker.ets // 点击添加闹钟弹出来的时间选择器组件 36| |---DataSource.ets // 闹钟组件 37| |---FlipClock.ets // 翻转时钟组件 38| |---LockSwitch.ets // 屏幕常亮组件 39| |---Setting.ets // 设置组件 40|---mock 41| |---TabData.ets // 放TabContent()资源:tabs()组件切换时,每个子tab用到的资源 42|---model 43| |---StorageModel.ets // 存储组件 44|---pages 45| |---Index.ets // 首页 46``` 47 48 49#### 相关概念 50 51后台代理提醒:后台代理提醒主要提供后台提醒发布接口,开发者在应用开发时,可以调用这些接口去创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。 52 53### 具体实现 54* 在entry/pages/index.ets中通过tabArray.TabType.num的值来加载每个TabContent()的资源,num:[0,1,2,3]分别加载翻页时钟,闹钟,倒计时,设置组件。[源码参考]( entry/src/main/ets/pages/Index.ets) 。 55* 页面编写步骤: 56 1、定义以下四个页面组件 FlipClock()//翻转时钟 AlarmClock()// 闹钟CountDown()// 倒计时Setting()//设置 57 2、使用tabs()标签,将四个组件封装。 58* 组件逻辑实现 59 1、时钟: 通过aboutToAppear()中new date()获取当前时间,通过获取date的时、分、秒,10位数通过math.floor()取整,个位数通过对10取余,从而实现对时间格式化,使用box标签,对获取到的数据进行渲染。 60 2、闹钟: 61 * a) 使用自定义对话控制器CustomDialogController,定义时间选择器,使用data.preferences存储设置的闹钟,并使用reminderAgentManager将其添加到系统中。 62 import data_preferences from '@ohos.data.preferences' 63 import reminderAgentManager from '@ohos.reminderAgentManager' 64 * b) 页面从data.preferences获取添加的闹钟数据,通过Scroll()标签渲染,在标签row内,设置delete按钮,如果删除就调用以下函数取消系统时钟 65 import reminderAgentManager from '@ohos.reminderAgentManager' 66 reminderAgentManager.cancelReminder 67 3、倒计时 68 * a) 使用aboutToAppear()初始化界面布局,通过this.listener.on('change', portraitFunc)添加监听, 69 * b) 点击开始按钮触发以下函数开始计时,并修改按钮的样式为暂停,并将running=true,触发canvas样式 70 countInSec = pickerH * 3600 + pickerM * 60 + pickerS //总计时计算 71 this.timer = setInterval(this.timerCountDown.bind(this), 1000) //时间计算 72 * c) 点击暂停按钮,时间暂停,并将按钮样式修改为开始 73 clearInterval(this.timer) 74 this.isRunning = true 75 this.isPausing = true 76 this.startImg = $r('app.media.start') 77 * d) 点击reset计时重置,将所有数据初始化 78 clearInterval(this.timer) 79 this.isRunning = false 80 this.isPausing = false 81 this.progressVal = 0 82 this.rotates = 0 83 passSec = 0 84 this.hoursTime = 0 85 this.minuteTime = 0 86 this.secondTime = 0 87 pickerH = 0 88 pickerM = 0 89 pickerS = 0 90 this.startImg = $r('app.media.start') 91 this.resetImg = $r('app.media.resetccc') 92 93### 相关权限 94 95[ohos.permission.PUBLISH_AGENT_REMINDER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionpublish_agent_reminder) 96 97[ohos.permission.RUNNING_LOCK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionrunning_lock) 98 99[ohos.permission.NOTIFICATION_CONTROLLER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionnotification_controller) 100 101### 依赖 102 103不涉及。 104 105### 约束与限制 106 1071.本示例仅支持在标准系统上运行。 108 1092.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 4.1.3.700, built on March 19, 2024)版本才可编译运行。 110 1113.本示例已适配API version 12版本SDK,版本号:5.0.0.70; 112 113### 下载 114 115如需单独下载本工程,执行如下命令: 116 117```` 118git init 119git config core.sparsecheckout true 120echo code/Solutions/Tools/FlipClock/ > .git/info/sparse-checkout 121git remote add origin https://gitee.com/openharmony/applications_app_samples.git 122git pull origin master 123````