| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 22-Oct-2025 | - | 35 | 32 | ||
| entry/ | 22-Oct-2025 | - | 1,200 | 1,051 | ||
| hvigor/ | 22-Oct-2025 | - | 38 | 36 | ||
| screenshots/device/ | 22-Oct-2025 | - | ||||
| .gitignore | D | 22-Oct-2025 | 133 | 12 | 12 | |
| README.md | D | 22-Oct-2025 | 1 KiB | 33 | 16 | |
| README_zh.md | D | 22-Oct-2025 | 2.9 KiB | 73 | 49 | |
| build-profile.json5 | D | 22-Oct-2025 | 1.3 KiB | 57 | 56 | |
| code-linter.json5 | D | 22-Oct-2025 | 1.4 KiB | 47 | 46 | |
| hvigorfile.ts | D | 22-Oct-2025 | 848 | 22 | 5 | |
| oh-package.json5 | D | 22-Oct-2025 | 814 | 26 | 24 | |
| ohosTest.md | D | 22-Oct-2025 | 676 | 12 | 9 |
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 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||| 12 13使用说明 14 151.点击倒计时文本,弹出时间选择框,选择任意时间,点击**确认**,倒计时文本显示选择的时间。 16 172.点击**start**,开始倒计时,圆形进度条和文本开始变化;倒计时结束,开始振动,进度条恢复初始状态并且弹出振动提示框,按照描述进行选择。 18 193.点击**reset**,可以结束倒计时并使文本和进度条恢复初始状态。 20 21### 工程目录 22``` 23entry/src/main/ets/ 24|---common 25| |---TextDialog.ts // 弹窗组件 26| |---TextTimeComponent.ts // 内容模块 27| |---TimerPicker.ts // TimerPicker模块 28| |---TitleBar.ts // 标题组件 29|---mode 30| |---Logger.ts // 日志工具 31| |---TimerData.ts // 时间数据 32|---page 33| |---Index.ets // 首页 34``` 35 36### 具体实现 37 38* 本示例实现振动的方法主要封装在TextTimerComponent中,源码参考: [TextTimerComponent](entry/src/main/ets/MainAbility/common/TextTimerComponent.ets) 。 39 * 设置倒计时间:Timepicker文件中通过TextPicker组件来设置倒计的时间,并将设定的时间数据双向绑定到TextTimerComponent组件当中。 40 * 启动倒计时:点击start按钮通过setInterval执行倒计时,每隔一段时间Process组件的进度值会被此代码this.progressValue += TOTAL / this.duration进行处理同步刷新。 41 * 触发振动:当时间为0的时候,则执行vibrator.vibrate()方法去触发振动效果。 42 * 初始化时间:点击reset按钮会将Process组件的value以及时间进行初始化,并清除定时器。 43 44### 相关权限 45 46[ohos.permission.VIBRATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionvibrate) 47 48### 依赖 49 50不涉及。 51 52### 约束与限制 53 541.本示例仅支持标准系统上运行。 55 562.本示例需要使用有振动器的设备测试。 57 583.本示例已适配API version 14版本SDK,版本号:5.0.2.123。 59 604.本示例需要使用DevEco Studio 5.0.2 Release (Build Version: 5.0.7.210 构建 2025年2月11日)及以上版本才可编译运行。 61 62### 下载 63 64如需单独下载本工程,执行如下命令: 65``` 66git init 67git config core.sparsecheckout true 68echo code/BasicFeature/DeviceManagement/Vibrator/ > .git/info/sparse-checkout 69git remote add origin https://gitee.com/openharmony/applications_app_samples.git 70git pull origin master 71``` 72 73