• Home
Name Date Size #Lines LOC

..--

entry/06-May-2025-1,1621,031

hvigor/06-May-2025-2322

screenshots/device/06-May-2025-

.gitignoreD06-May-2025124 99

README.mdD06-May-20251 KiB3316

README_zh.mdD06-May-20252.9 KiB7550

build-profile.json5D06-May-20251 KiB4241

hvigorfile.jsD06-May-2025174 21

hvigorwD06-May-20252.1 KiB6228

hvigorw.batD06-May-20252 KiB7256

oh-package.json5D06-May-2025818 2625

ohosTest.mdD06-May-2025676 129

README.md

1# Vibrator
2
3### Introduction
4
5This sample simulates the countdown scenario to show the use of the vibrator APIs. Below shows the sample app.
6
7![](./screenshots/device/vibratorTime.jpeg)
8
9### Functions
10
11You can trigger a vibrator to vibrate by duration or vibration effect.
12
13### Required Permissions
14
15ohos.permission.VIBRATE
16
17### Usage
18
191. Touch the countdown text. A time picker is displayed. Select any time and touch **OK**. The selected time is displayed as the countdown text.
20
212. Touch **start**. The countdown starts, and the round progress bar and countdown text start changing. When the countdown ends, the device vibrates, the progress bar returns to the initial state, and a vibration dialog box is displayed.
22
233. Touch **reset**. The countdown ends, and the round progress bar and countdown text are restored to the initial state.
24
25### Constraints
26
271. This sample can only be run on standard-system devices.
28
292. This sample requires a device with a vibrator.
30
313. This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100) to compile and run.
32
33

README_zh.md

1# 振动
2
3### 介绍
4
5本示例模拟倒计时场景,通过[@ohos.vibrator](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md) 等接口来实现振动。
6
7### 效果预览
8
9|设置倒计时间|振动倒计时|
10|--------------------------------|--------------------------------|
11|![](./screenshots/device/setTime.jpeg)|![](./screenshots/device/vibratorTime.jpeg)
12
13使用说明
14
151.点击倒计时文本,弹出时间选择框,选择任意时间,点击**确认**,倒计时文本显示选择的时间。
16
172.点击**start**,开始倒计时,圆形进度条和文本开始变化;倒计时结束,开始振动,进度条恢复初始状态并且弹出振动提示框,按照描述进行选择。
18
193.点击**reset**,可以结束倒计时并使文本和进度条恢复初始状态。
20
21### 工程目录
22```
23entry/src/main/ets/
24|---MainAbility
25|   |---common
26|   |   |---TextDialog.ts                   // 弹窗组件
27|   |   |---TextTimeComponent.ts            // 内容模块
28|   |   |---TimerPicker.ts                  // TimerPicker模块
29|   |   |---TitleBar.ts                     // 标题组件
30|   |---mode
31|   |   |---Logger.ts                       // 日志工具
32|   |   |---TimerData.ts                    // 时间数据
33|   |---page
34|   |   |---Index.ets                       // 首页
35
36```
37### 具体实现
38
39* 本示例实现振动的方法主要封装在TextTimerComponent中,源码参考: [TextTimerComponent](entry/src/main/ets/MainAbility/common/TextTimerComponent.ets) 。
40    * 设置倒计时间:Timepicker文件中通过TextPicker组件来设置倒计的时间,并将设定的时间数据双向绑定到TextTimerComponent组件当中。
41    * 启动倒计时:点击start按钮通过setInterval执行倒计时,每隔一段时间Process组件的进度值会被此代码this.progressValue += TOTAL / this.duration进行处理同步刷新。
42    * 触发振动:当时间为0的时候,则执行vibrator.vibrate()方法去触发振动效果。
43    * 初始化时间:点击reset按钮会将Process组件的value以及时间进行初始化,并清除定时器。
44
45### 相关权限
46
47[ohos.permission.VIBRATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionvibrate)
48
49### 依赖
50
51不涉及。
52
53### 约束与限制
54
551.本示例仅支持标准系统上运行。
56
572.本示例需要使用有振动器的设备测试。
58
593.本示例已适配API version 9版本SDK,版本号:3.2.11.9。
60
614.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400 构建 2023年4月7日)及以上版本才可编译运行。
62
63### 下载
64
65如需单独下载本工程,执行如下命令:
66```
67git init
68git config core.sparsecheckout true
69echo code/BasicFeature/DeviceManagement/Vibrator/ > .git/info/sparse-checkout
70git remote add origin https://gitee.com/openharmony/applications_app_samples.git
71git pull origin master
72
73```
74
75