add stm32mp157 development board
Signed-off-by: Laowang-BearPi <wangcheng@holdiot.com>
@@ -65,7 +65,7 @@
|
||||
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.iml|*.json|*.txt|*.png|*.gif|*.docx|*.jpg" desc="desc files"/>
|
||||
<filteritem type="filename" name="*.hap|*.iml|*.json|*.txt|*.png|*.gif|*.docx|*.jpg" desc="desc files"/>
|
||||
<filteritem type="filepath" name="target/.*" desc="Compile output files"/>
|
||||
<filteritem type="filepath" name="out/.*" desc="Compile output files"/>
|
||||
<filteritem type="filepath" name="log/.*" desc="log files"/>
|
||||
@@ -83,12 +83,18 @@
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/bearpi_hm_nano_build.sh" desc="sh file do not declare license"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/config/sdk.mk" desc="config file do not declare license"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/config/usr_config.mk" desc="config file do not declare license"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/tools/download_img/kernel/.keep" desc=""/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/tools/download_img/flashlayout/bearpi-hm_micro.tsv" desc=""/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/liteos_a/config.gni" desc=""/>
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
|
||||
<filteritem type="filename" name="fstab" desc="This type configuration file can not declare copyright"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/bearpi_hm_nano_build.sh" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/config/sdk.mk" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_nano/config/usr_config.mk" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/tools/download_img/kernel/.keep" desc=""/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/tools/download_img/flashlayout/bearpi-hm_micro.tsv" desc=""/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/liteos_a/config.gni" desc=""/>
|
||||
</filefilter>
|
||||
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
|
||||
</filefilter>
|
||||
@@ -97,6 +103,8 @@
|
||||
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
|
||||
<filteritem type="filename" name="*.stm32" desc="desc files"/>
|
||||
<filteritem type="filepath" name="bearpi_hm_micro/tools/hap_tools/bm" desc="desc files"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# device_board_bearpi
|
||||
|
||||
### 介绍
|
||||
|
||||
本仓用于放置BearPi开发板板相关内容,详情请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发板介绍](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发板介绍.md)
|
||||
|
||||
|
||||
### 开发环境搭建
|
||||
|
||||
开发环境搭建教程请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发环境搭建](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发搭建环境.md)
|
||||
|
||||
|
||||
### 编译调试
|
||||
|
||||
请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发板编译调试](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发板编译调试.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# device_board_bearpi
|
||||
- [简介](#section469617221261)
|
||||
- [开发环境搭建](#section469617221262)
|
||||
- [编译调试](#section469617221263)
|
||||
- [目录](#section161941989596)
|
||||
- [相关仓](#section641143415335)
|
||||
## 简介<a name="section469617221261"></a>
|
||||
|
||||
本仓用于放置小熊派BearPi开发板相关内容,目前,小熊派已有两款开发板适配OpenHarmony,分别是基于海思Hi3861的轻量系统BearPi-HM Nano开发板和基于意法半导体STM32MP157的小型系统BearPi-HM Micro开发板,详情请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发板介绍](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发板介绍.md)
|
||||
|
||||
|
||||
[小型系统BearPi-HM Micro开发板介绍](bearpi_hm_micro/docs/device-dev/BearPi-HM_Micro开发板介绍.md)
|
||||
|
||||
## 开发环境搭建<a name="section469617221262"></a>
|
||||
|
||||
开发环境搭建教程请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发环境搭建](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发搭建环境.md)
|
||||
|
||||
[小型系统BearPi-HM Micro开发环境搭建](bearpi_hm_micro/docs/device-dev/BearPi-HM_Micro开发环境搭建.md)
|
||||
|
||||
## 编译调试<a name="section469617221263"></a>
|
||||
|
||||
请参见各开发板readme。
|
||||
|
||||
[轻量系统BearPi-HM Nano开发板编译调试](bearpi_hm_nano/docs/quick-start/BearPi-HM_Nano开发板编译调试.md)
|
||||
|
||||
[小型系统BearPi-HM Micro开发板编译调试](bearpi_hm_micro/docs/device-dev/BearPi-HM_Micro开发板编译调试.md)
|
||||
## 目录<a name="section161941989596"></a>
|
||||
```
|
||||
/device/board/bearpi
|
||||
├── bearpi_hm_micro # 小熊派小型系统STM32MP157开发板
|
||||
└── app # 应用案例
|
||||
└── docs # 文档
|
||||
└── hal # 外设HDI适配
|
||||
└── liteos_a # liteos_a 内核适配
|
||||
└── tools # tf-a、uboot镜像
|
||||
├── bearpi_hm_nano # 小熊派轻量系统Hi3861开发板
|
||||
└── app # 应用案例
|
||||
└── config # 驱动差异化使能配置
|
||||
└── docs # 文档
|
||||
└── iot_hardware_hals # 外设适配
|
||||
└── liteos_m # liteos_m 内核适配
|
||||
└── third_party # 三方库
|
||||
```
|
||||
## 相关仓<a name="section641143415335"></a>
|
||||
|
||||
**[device_board_bearpi](https://gitee.com/openharmony/device_board_bearpi)**
|
||||
|
||||
[device_soc_st](https://gitee.com/openharmony/device_soc_st)
|
||||
|
||||
[vendor_bearpi](https://gitee.com/openharmony/vendor_bearpi)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2021 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("bearpi_hm_micro") {
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
---
|
||||
# 小熊派-鸿蒙·叔(BearPi-HM Micro)
|
||||
|
||||
## 一、BearPi-HM Micro 开发板介绍
|
||||
|
||||
BearPi-HM Micro开发板是一块高度集成并可运行OpenHarmony系统的开发板,板载高性能的工业级处理器STM32MP157芯片,搭配4.3寸LCD电容式触摸屏,并板载wifi电路及标准的E53接口,标准的E53接口可扩展智能加湿器、智能台灯、智能安防、智能烟感等案例。可折叠式屏幕设计大大提高用户开发体验,便于携带和存放,更好地满足不同用户的需求,拓展无限可能。
|
||||
|
||||
## 二、设备开发手把手教程系列
|
||||
|
||||
1、视频系列(B站) 对应PPT地址
|
||||
* [P1. 初识BearPi-HM Micro开发板](https://www.bilibili.com/video/BV12Y411H7ry?p=1)
|
||||
* [P2. 开发环境搭建(复杂)——编译环境搭建](https://www.bilibili.com/video/BV12Y411H7ry?p=3)
|
||||
* [P3. 开发环境搭建(复杂)——源码获取及编译](https://www.bilibili.com/video/BV12Y411H7ry?p=4)
|
||||
* [P4. BearPi-HM Micro开发板源码烧录](https://www.bilibili.com/video/BV12Y411H7ry?p=5)
|
||||
* [P5. OpenHarmony 快速入门:HelloWorld](https://www.bilibili.com/video/BV12Y411H7ry?p=6)
|
||||
* [P6. OpenHarmony 快速入门:点亮LED](https://www.bilibili.com/video/BV12Y411H7ry?p=7)
|
||||
* [P7. OpenHarmony 快速入门:安装HAP](https://www.bilibili.com/video/BV12Y411H7ry?p=8)
|
||||
* [P8. OpenHarmony 快速入门:JS点亮LED](https://www.bilibili.com/video/BV12Y411H7ry?p=9)
|
||||
|
||||
2、文档系列(Gitee)
|
||||
- [1. 初识BearPi-HM Micro开发板](docs/device-dev/BearPi-HM_Micro开发板介绍.md)
|
||||
- [2. 开发环境搭建](docs/device-dev/BearPi-HM_Micro开发环境搭建.md)
|
||||
- [3. 源码获取、编译烧录](docs/device-dev/BearPi-HM_Micro开发板编译调试.md)
|
||||
- [4. 编写一个hello_world程序](docs/device-dev/编写一个hello_world程序.md)
|
||||
- [5. 如何运行一个可执行程序](docs/device-dev/如何运行一个可执行程序.md)
|
||||
- [6. 编写一个点亮LED灯程序](docs/device-dev/编写一个点亮LED灯程序.md)
|
||||
- [7. 通过JS应用控制LED灯](docs/device-dev/通过JS应用控制LED灯.md)
|
||||
- [8. 如何在开发板上安装HAP应用](docs/device-dev/如何在开发板上安装HAP应用.md)
|
||||
|
||||
|
||||
## 三、开发板图片预览[(淘宝链接)](https://item.taobao.com/item.htm?id=662078665554)
|
||||
|
||||
[](https://item.taobao.com/item.htm?id=633296694816)
|
||||
|
||||
|
||||
## 四、联系我们
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Notes:
|
||||
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com.
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
|
||||
<filteritem type="filepath" name=".*" desc="Resource and figure binary."/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "@ohos/bearpi_hm_micro_sample",
|
||||
"version": "3.1",
|
||||
"description": "bearpi_hm_micro samples.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "",
|
||||
"private": false,
|
||||
"scripts": {},
|
||||
"envs": [],
|
||||
"dirs": [
|
||||
"device/board/bearpi/bearpi_hm_micro/app/launcher",
|
||||
"device/board/bearpi/bearpi_hm_micro/app/setting",
|
||||
"device/board/bearpi/bearpi_hm_micro/app/screensaver",
|
||||
"device/board/bearpi/bearpi_hm_micro/app/communication"
|
||||
],
|
||||
"component": {
|
||||
"name": "bearpi_hm_micro_sample",
|
||||
"subsystem": "bearpi_hm_micro_sample",
|
||||
"syscap": [
|
||||
""
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"liteos_a"
|
||||
],
|
||||
"rom": "22KB",
|
||||
"ram": "~10KB",
|
||||
"output": [
|
||||
"launcher.so",
|
||||
"setting.so",
|
||||
"screensaver.so"
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"aafwk_lite",
|
||||
"appexecfwk_lite",
|
||||
"surface",
|
||||
"ui",
|
||||
"graphic_utils",
|
||||
"kv_store",
|
||||
"syspara_lite",
|
||||
"permission",
|
||||
"ipc_lite",
|
||||
"samgr_lite",
|
||||
"utils_base"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function",
|
||||
"wpa_supplicant",
|
||||
"cjson",
|
||||
"giflib",
|
||||
"libjpeg",
|
||||
"libpng"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//device/board/bearpi/bearpi_hm_micro/app/launcher:launcher_hap",
|
||||
"//device/board/bearpi/bearpi_hm_micro/app/setting:setting_hap",
|
||||
"//device/board/bearpi/bearpi_hm_micro/app/screensaver:screensaver_hap",
|
||||
"//device/board/bearpi/bearpi_hm_micro/app/communication:sample"
|
||||
],
|
||||
"inner_kits": [],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
lite_component("sample") {
|
||||
features = [
|
||||
"hostapd:hostapd_sample",
|
||||
"wpa_cli:wpa_cli_sample",
|
||||
"wpa_supplicant:wpa_sample",
|
||||
]
|
||||
}
|
||||
|
||||
generate_notice_file("communication_sample") {
|
||||
module_name = "communication_sample"
|
||||
module_source_dir_list = [
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9/hostapd",
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9/wpa_supplicant",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,11 @@
|
||||
## Introduction
|
||||
This directory is the sample code of the communication subsystem. For now, it contains the usage example of wpa_supplicant.
|
||||
## Directions
|
||||
|
||||
```
|
||||
.
|
||||
├── hostapd
|
||||
├── wpa_cli
|
||||
└── wpa_supplicant
|
||||
|
||||
```
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
sample_sources = [ "src/hostapd_sample.c" ]
|
||||
|
||||
config_file = [ "config/hostapd.conf" ]
|
||||
|
||||
executable("hostapd_sample_exe") {
|
||||
output_name = "hostapd"
|
||||
sources = sample_sources
|
||||
}
|
||||
|
||||
copy("config") {
|
||||
sources = config_file
|
||||
outputs = [ "$root_out_dir/etc/hostapd.conf" ]
|
||||
}
|
||||
|
||||
group("hostapd_sample") {
|
||||
deps = [
|
||||
":config",
|
||||
":hostapd_sample_exe",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
interface=wlan0
|
||||
driver=hdf wifi
|
||||
ctrl_interface=udp
|
||||
ssid=testap
|
||||
hw_mode=g
|
||||
channel=1
|
||||
ignore_broadcast_ssid=0
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
pthread_t g_apThread;
|
||||
|
||||
char* g_apArg[20] = {0};
|
||||
int g_apArgc = 0;
|
||||
|
||||
static void* ThreadMain()
|
||||
{
|
||||
printf("[HostapdSample]init hostapd.\n");
|
||||
|
||||
void *handleLibWpa = dlopen("/usr/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (handleLibWpa == NULL) {
|
||||
printf("[HostapdSample]dlopen libwpa failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
int (*func)(int, char **) = NULL;
|
||||
func = dlsym(handleLibWpa, "ap_main");
|
||||
if (func == NULL) {
|
||||
dlclose(handleLibWpa);
|
||||
printf("[HostapdSample]dlsym ap_main failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
int ret = func(g_apArgc, g_apArg);
|
||||
|
||||
printf("[HostapdSample]run ap_main failed, ret:%d.\n", ret);
|
||||
for (int i = 0; i < g_apArgc; i++) {
|
||||
printf("[HostapdSample]arg %d:%s.\n", i, g_apArg[i]);
|
||||
}
|
||||
|
||||
if (dlclose(handleLibWpa) != 0) {
|
||||
printf("[HostapdSample]dlclose libwpa failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
g_apArgc = argc;
|
||||
for (int i = 0; i < g_apArgc; i++) {
|
||||
g_apArg[i] = argv[i];
|
||||
}
|
||||
|
||||
int ret = pthread_create(&g_apThread, NULL, ThreadMain, NULL);
|
||||
if (ret != 0) {
|
||||
printf("[HostapdSample]create thread failed error:%s.\n", strerror(ret));
|
||||
return 1;
|
||||
}
|
||||
pthread_join(g_apThread, NULL);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
sample_sources = [ "src/wpa_cli_sample.c" ]
|
||||
|
||||
sample_include_dirs = [
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9/src/",
|
||||
"//third_party/bounds_checking_function:libsec_shared/include/",
|
||||
]
|
||||
|
||||
executable("wpa_cli_exe") {
|
||||
output_name = "wpa_cli"
|
||||
sources = sample_sources
|
||||
include_dirs = sample_include_dirs
|
||||
out_dir = rebase_path(root_build_dir)
|
||||
deps = [
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9:wpa_supplicant",
|
||||
]
|
||||
ldflags = [
|
||||
"-L${out_dir}",
|
||||
"-lwpa_client",
|
||||
]
|
||||
}
|
||||
|
||||
group("wpa_cli_sample") {
|
||||
deps = [ ":wpa_cli_exe" ]
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "utils/includes.h"
|
||||
#include "pthread.h"
|
||||
#include "common/wpa_ctrl.h"
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define WPA_IFACE_NAME "wlan0"
|
||||
#define WIFI_AUTH_FAILED_REASON_STR "WRONG_KEY"
|
||||
#define WIFI_AUTH_FAILED_REASON_CODE "reason=2"
|
||||
#define WPA_CTRL_REQUEST_OK "OK"
|
||||
#define WPA_CTRL_REQUEST_FAIL "FAIL"
|
||||
|
||||
#define SAMPLE_INFO(format, args...) \
|
||||
do { \
|
||||
fprintf(stderr, "\033[1;32m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
|
||||
#define SAMPLE_ERROR(format, args...) \
|
||||
do { \
|
||||
fprintf(stderr, "\033[1;31m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static struct wpa_ctrl *g_monitorConn;
|
||||
static struct wpa_ctrl *g_ctrlConn;
|
||||
static pthread_t g_wpaThreadId;
|
||||
static int g_scanAvailable = 0;
|
||||
|
||||
static void DumpString(const char *buf, int len, const char *tag)
|
||||
{
|
||||
SAMPLE_INFO("%s dump start.", tag);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf("%c", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
SAMPLE_INFO("%s dump end.", tag);
|
||||
}
|
||||
|
||||
static int StrMatch(const char *a, const char *b)
|
||||
{
|
||||
return strncmp(a, b, strlen(b)) == 0;
|
||||
}
|
||||
|
||||
static void WifiEventHandler(char *rawEvent, int len)
|
||||
{
|
||||
char *pos = rawEvent;
|
||||
if (*pos == '<') {
|
||||
pos = strchr(pos, '>');
|
||||
if (pos) {
|
||||
pos++;
|
||||
} else {
|
||||
pos = rawEvent;
|
||||
}
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_CONNECTED)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_CONNECTED");
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_SCAN_RESULTS)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_SCAN_DONE");
|
||||
g_scanAvailable = 1;
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_TEMP_DISABLED) && strstr(pos, WIFI_AUTH_FAILED_REASON_STR)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_WRONG_KEY");
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_DISCONNECTED) && !strstr(pos, WIFI_AUTH_FAILED_REASON_CODE)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_DISCONNECTED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void CliRecvPending(void)
|
||||
{
|
||||
while (wpa_ctrl_pending(g_monitorConn)) {
|
||||
char buf[4096];
|
||||
size_t len = sizeof(buf) - 1;
|
||||
if (wpa_ctrl_recv(g_monitorConn, buf, &len) == 0) {
|
||||
buf[len] = '\0';
|
||||
SAMPLE_INFO("event received %s", buf);
|
||||
WifiEventHandler(buf, len);
|
||||
} else {
|
||||
SAMPLE_INFO("could not read pending message.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void* MonitorTask(void *args)
|
||||
{
|
||||
(void)args;
|
||||
int fd, ret;
|
||||
fd_set rfd;
|
||||
while (1) {
|
||||
fd = wpa_ctrl_get_fd(g_monitorConn);
|
||||
FD_ZERO(&rfd);
|
||||
FD_SET(fd, &rfd);
|
||||
ret = select(fd + 1, &rfd, NULL, NULL, NULL);
|
||||
if (ret <= 0) {
|
||||
SAMPLE_INFO("select failed ret = %d\n", ret);
|
||||
break;
|
||||
}
|
||||
CliRecvPending();
|
||||
sleep(1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int SendCtrlCommand(const char *cmd, char *reply, size_t *replyLen)
|
||||
{
|
||||
size_t len = *replyLen - 1;
|
||||
wpa_ctrl_request(g_ctrlConn, cmd, strlen(cmd), reply, &len, 0);
|
||||
DumpString(reply, len, "SendCtrlCommand raw return");
|
||||
if (len != 0 && !StrMatch(reply, WPA_CTRL_REQUEST_FAIL)) {
|
||||
*replyLen = len;
|
||||
return 0;
|
||||
}
|
||||
SAMPLE_ERROR("send ctrl request [%s] failed.", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void TestNetworkConfig(void)
|
||||
{
|
||||
char networkId[20] = {0};
|
||||
size_t networkIdLen = sizeof(networkId);
|
||||
int ret = SendCtrlCommand("DISCONNECT", networkId, &networkIdLen);
|
||||
ret += SendCtrlCommand("ADD_NETWORK", networkId, &networkIdLen);
|
||||
if (ret != 0) {
|
||||
SAMPLE_ERROR("add network failed.");
|
||||
return;
|
||||
}
|
||||
SAMPLE_INFO("add network success, network id [%.*s]", networkIdLen, networkId);
|
||||
char reply[100] = {0};
|
||||
size_t replyLen = sizeof(reply);
|
||||
char cmd[200] = {0};
|
||||
sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s ssid \"example\"", networkIdLen, networkId);
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s psk \"012345678\"", networkIdLen, networkId);
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
sprintf_s(cmd, sizeof(cmd), "ENABLE_NETWORK %.*s", networkIdLen, networkId);
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
ret += SendCtrlCommand("RECONNECT", reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
if (ret == 0) {
|
||||
SAMPLE_INFO("network config success.");
|
||||
return;
|
||||
}
|
||||
sprintf_s(cmd, sizeof(cmd), "REMOVE_NETWORK %.*s", networkIdLen, networkId);
|
||||
SendCtrlCommand(cmd, reply, &replyLen);
|
||||
SAMPLE_ERROR("network config failed remove network [%.*s].", networkIdLen, networkId);
|
||||
}
|
||||
|
||||
static void TestCliConnection(void)
|
||||
{
|
||||
char reply[100] = {0};
|
||||
size_t replyLen = sizeof(reply);
|
||||
int ret = SendCtrlCommand("PING", reply, &replyLen);
|
||||
if (ret == 0 && StrMatch(reply, "PONG")) {
|
||||
SAMPLE_INFO("connect to wpa success.");
|
||||
return;
|
||||
}
|
||||
SAMPLE_INFO("connect to wpa failed, err = %s.", reply);
|
||||
}
|
||||
|
||||
static void TestScan()
|
||||
{
|
||||
char reply[100] = {0};
|
||||
size_t replyLen = sizeof(reply);
|
||||
g_scanAvailable = 0;
|
||||
SendCtrlCommand("SCAN", reply, &replyLen);
|
||||
while (1) {
|
||||
sleep(1);
|
||||
if (g_scanAvailable == 1) {
|
||||
SAMPLE_INFO("scan result received.");
|
||||
break;
|
||||
}
|
||||
SAMPLE_INFO("waiting scan result.");
|
||||
}
|
||||
char scanResult[4096] = {0};
|
||||
size_t scanLen = sizeof(scanResult);
|
||||
int ret = SendCtrlCommand("SCAN_RESULTS", scanResult, &scanLen);
|
||||
if (ret != 0) {
|
||||
SAMPLE_ERROR("request scan results failed.");
|
||||
return;
|
||||
}
|
||||
DumpString(scanResult, scanLen, "scan results");
|
||||
}
|
||||
|
||||
static void StartTest()
|
||||
{
|
||||
TestCliConnection(); // test if wpa control interface connected successfully
|
||||
TestScan(); // test scan and get scan results
|
||||
TestNetworkConfig(); // test config network and connect
|
||||
}
|
||||
|
||||
int InitControlInterface()
|
||||
{
|
||||
g_ctrlConn = wpa_ctrl_open(WPA_IFACE_NAME); // create control interface for send cmd
|
||||
g_monitorConn = wpa_ctrl_open(WPA_IFACE_NAME); // create control interface for event monitor
|
||||
if (!g_ctrlConn || !g_monitorConn) {
|
||||
SAMPLE_ERROR("open wpa control interface failed.");
|
||||
return -1;
|
||||
}
|
||||
if (wpa_ctrl_attach(g_monitorConn) == 0) { // start monitor
|
||||
pthread_create(&g_wpaThreadId, NULL, MonitorTask, NULL); // create thread for read event
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (InitControlInterface() != 0) {
|
||||
SAMPLE_ERROR("control interface init failed, exit client.");
|
||||
return -1;
|
||||
}
|
||||
SAMPLE_INFO("control interface init success.");
|
||||
StartTest();
|
||||
pthread_join(g_wpaThreadId, NULL);
|
||||
SAMPLE_INFO("test finished, exit client.");
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
sample_sources = [ "src/wpa_sample.c" ]
|
||||
|
||||
config_file = [ "config/wpa_supplicant.conf" ]
|
||||
|
||||
executable("wpa_sample_exe") {
|
||||
output_name = "wpa_supplicant"
|
||||
sources = sample_sources
|
||||
}
|
||||
|
||||
copy("config") {
|
||||
sources = config_file
|
||||
outputs = [ "$root_out_dir/etc/wpa_supplicant.conf" ]
|
||||
}
|
||||
|
||||
group("wpa_sample") {
|
||||
deps = [
|
||||
":config",
|
||||
":wpa_sample_exe",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
country=GB
|
||||
ctrl_interface=udp
|
||||
network={
|
||||
ssid="bearpi"
|
||||
psk="0987654321"
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
pthread_t g_wpaThread;
|
||||
|
||||
char* g_wpaArg[20] = {0};
|
||||
int g_wpaArgc = 0;
|
||||
|
||||
static void* ThreadMain()
|
||||
{
|
||||
printf("[WpaSample]init wpa_supplicant.\n");
|
||||
|
||||
void *handleLibWpa = dlopen("/usr/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (handleLibWpa == NULL) {
|
||||
printf("[WpaSample]dlopen libwpa failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
int (*func)(int, char **) = NULL;
|
||||
func = dlsym(handleLibWpa, "wpa_main");
|
||||
if (func == NULL) {
|
||||
dlclose(handleLibWpa);
|
||||
printf("[WpaSample]dlsym wpa_main failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
int ret = func(g_wpaArgc, g_wpaArg);
|
||||
|
||||
printf("[WpaSample]run wpa_main failed, ret:%d.\n", ret);
|
||||
for (int i = 0; i < g_wpaArgc; i++) {
|
||||
printf("[WpaSample]arg %d:%s.\n", i, g_wpaArg[i]);
|
||||
}
|
||||
|
||||
if (dlclose(handleLibWpa) != 0) {
|
||||
printf("[WpaSample]dlclose libwpa failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
g_wpaArgc = argc;
|
||||
for (int i = 0; i < g_wpaArgc; i++) {
|
||||
g_wpaArg[i] = argv[i];
|
||||
}
|
||||
|
||||
int ret = pthread_create(&g_wpaThread, NULL, ThreadMain, NULL);
|
||||
if (ret != 0) {
|
||||
printf("[WpaSample]create thread failed error:%s.\n", strerror(ret));
|
||||
return 1;
|
||||
}
|
||||
pthread_join(g_wpaThread, NULL);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/hap_pack.gni")
|
||||
|
||||
shared_library("launcher") {
|
||||
sources = [
|
||||
"launcher/src/main/cpp/app_info.cpp",
|
||||
"launcher/src/main/cpp/app_manage.cpp",
|
||||
"launcher/src/main/cpp/long_press_view.cpp",
|
||||
"launcher/src/main/cpp/main_ability.cpp",
|
||||
"launcher/src/main/cpp/main_ability_slice.cpp",
|
||||
"launcher/src/main/cpp/swipe_view.cpp",
|
||||
"launcher/src/main/cpp/time_weather_view.cpp",
|
||||
"launcher/src/main/cpp/view_group_page.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//foundation/graphic/surface",
|
||||
"//foundation/graphic/ui:lite_ui",
|
||||
"//foundation/graphic/utils:lite_graphic_utils",
|
||||
"//utils/native/lite/kv_store:kv_store",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"launcher/src/main/cpp",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"//base/startup/syspara_lite/interfaces/kits",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ENABLE_WINDOW=1",
|
||||
"ABILITY_WINDOW_SUPPORT",
|
||||
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
|
||||
]
|
||||
}
|
||||
|
||||
hap_pack("launcher_hap") {
|
||||
deps = [ ":launcher" ]
|
||||
mode = "hap"
|
||||
json_path = "launcher/src/main/config.json"
|
||||
ability_so_path = "$root_out_dir/liblauncher.so"
|
||||
force = "true"
|
||||
cert_profile = "cert/com.huawei.launcher_HarmonyAppProvision_release.p7b"
|
||||
resources_path = "launcher/src/main/resources"
|
||||
hap_name = "launcher"
|
||||
privatekey = "HOS Application Provision Release"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.huawei.launcher",
|
||||
"vendor": "huawei",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 3,
|
||||
"target": 4
|
||||
}
|
||||
},
|
||||
"deviceConfig": {
|
||||
"default": {
|
||||
"keepAlive": true
|
||||
},
|
||||
"smartCamera": {
|
||||
"keepAlive": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"package": "com.huawei.launcher",
|
||||
"name": ".MyHarmonyAbilityPackage",
|
||||
"deviceType": [
|
||||
"phone", "tv","tablet","car","smartWatch","sportsWatch","smartVision"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "launcher",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [{
|
||||
"name": "MainAbility",
|
||||
"icon": "assets/launcher/resources/base/media/background.png",
|
||||
"label": "launcher",
|
||||
"launchType": "standard",
|
||||
"type": "page",
|
||||
"visible":true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_info.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
AppInfo::AppInfo()
|
||||
{
|
||||
ReSet();
|
||||
}
|
||||
void AppInfo::Release()
|
||||
{
|
||||
if (button_) {
|
||||
delete button_;
|
||||
button_ = nullptr;
|
||||
}
|
||||
if (lable_) {
|
||||
delete lable_;
|
||||
lable_ = nullptr;
|
||||
}
|
||||
if (appClickListener_) {
|
||||
delete appClickListener_;
|
||||
appClickListener_ = nullptr;
|
||||
}
|
||||
if (appLpListener_) {
|
||||
delete appLpListener_;
|
||||
appLpListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
AppInfo::~AppInfo()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
void AppInfo::ReSet()
|
||||
{
|
||||
button_ = nullptr;
|
||||
lable_ = nullptr;
|
||||
appClickListener_ = nullptr;
|
||||
appLpListener_ = nullptr;
|
||||
}
|
||||
|
||||
void AppInfo::SetButton(UILabelButton* button)
|
||||
{
|
||||
button->SetPosition(buttonXY_.x, buttonXY_.y, buttonHV_.x, buttonHV_.y);
|
||||
button->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
button->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED);
|
||||
button->SetStyleForState(STYLE_BACKGROUND_OPA, TOTAL_OPACITY, UIButton::PRESSED);
|
||||
button->SetStyleForState(STYLE_BORDER_OPA, TOTAL_OPACITY, UIButton::PRESSED);
|
||||
button->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS);
|
||||
button->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
button->SetStyle(STYLE_BORDER_OPA, TOTAL_OPACITY);
|
||||
button->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
button->SetImageSrc(appIconDir_, appIconDir_);
|
||||
button_ = button;
|
||||
}
|
||||
|
||||
void AppInfo::SetLable(UILabel* lable)
|
||||
{
|
||||
lable->SetPosition(lableXY_.x, lableXY_.y, lableHV_.x, lableHV_.y);
|
||||
char* p = strrchr(appName_, static_cast<int>('.'));
|
||||
if (p != nullptr) {
|
||||
lable->SetText(p + 1);
|
||||
} else {
|
||||
lable->SetText(appName_);
|
||||
}
|
||||
lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
|
||||
lable->SetFont(FOND_PATH, APP_FOND_ID);
|
||||
lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
|
||||
lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
lable_ = lable;
|
||||
}
|
||||
|
||||
void AppInfo::SetListener(AppInfo* app)
|
||||
{
|
||||
AppClickListener* clickListener = new AppClickListener(app->funcclick_, this);
|
||||
button_->SetOnClickListener(clickListener);
|
||||
appClickListener_ = static_cast<UIView::OnClickListener*>(clickListener);
|
||||
AppLongPressListener* lPListener = new AppLongPressListener(app->funclPress_, this);
|
||||
button_->SetOnLongPressListener(lPListener);
|
||||
appLpListener_ = static_cast<UIView::OnLongPressListener*>(lPListener);
|
||||
button_->SetDraggable(true);
|
||||
}
|
||||
|
||||
void AppInfo::SetLocation(int16_t r, int16_t c)
|
||||
{
|
||||
row_col_.x = r;
|
||||
row_col_.y = c;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APP_INFO_H
|
||||
#define OHOS_APP_INFO_H
|
||||
|
||||
#include <components/ui_label_button.h>
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_view_group.h>
|
||||
|
||||
#include "native_base.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
class AppInfo;
|
||||
using funcLongPress = bool (*)(AppInfo *app);
|
||||
using funcClick = bool (*)(AppInfo *app);
|
||||
using UninstallApp = bool (*)(AppInfo *app);
|
||||
using AddApp = bool (*)(AppInfo *app);
|
||||
|
||||
struct MyPoint {
|
||||
int16_t x; // the x coordinate of the point
|
||||
int16_t y; // the y coordinate of the point
|
||||
};
|
||||
|
||||
class AppInfo {
|
||||
public:
|
||||
AppInfo();
|
||||
virtual ~AppInfo();
|
||||
void Release();
|
||||
void ReSet();
|
||||
void SetButton(UILabelButton *button);
|
||||
void SetLable(UILabel *lable);
|
||||
void SetListener(AppInfo *app);
|
||||
void SetLocation(int16_t r, int16_t c);
|
||||
|
||||
UILabelButton* button_ { nullptr };
|
||||
UILabel* lable_ { nullptr };
|
||||
|
||||
UIView::OnLongPressListener* appLpListener_ { nullptr };
|
||||
UIView::OnClickListener* appClickListener_ { nullptr };
|
||||
|
||||
funcClick funcclick_ { nullptr };
|
||||
funcLongPress funclPress_ { nullptr };
|
||||
MyPoint lableXY_ { 0 };
|
||||
MyPoint lableHV_ { 0 };
|
||||
MyPoint buttonXY_ { 0 };
|
||||
MyPoint buttonHV_ { 0 };
|
||||
MyPoint row_col_ { 0 };
|
||||
char appName_[TMP_BUF_SIZE] = { 0 };
|
||||
char abilityName_[TMP_BUF_SIZE] = { 0 };
|
||||
char appIconDir_[TMP_BUF_SIZE] = { 0 };
|
||||
};
|
||||
|
||||
class AppClickListener : public UIView::OnClickListener {
|
||||
public:
|
||||
AppClickListener(funcClick func, AppInfo* app) : funcClick_(func), appInfo_(app) {}
|
||||
virtual ~AppClickListener() {}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
funcClick_(appInfo_);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
funcClick funcClick_ { nullptr };
|
||||
AppInfo *appInfo_ { nullptr };
|
||||
};
|
||||
|
||||
class AppLongPressListener : public UIView::OnLongPressListener {
|
||||
public:
|
||||
AppLongPressListener(funcClick func, AppInfo* app) : appInfo_(app), funcLongPress_(func) {}
|
||||
virtual ~AppLongPressListener() {}
|
||||
bool OnLongPress(UIView& view, const LongPressEvent& event) override
|
||||
{
|
||||
funcLongPress_(appInfo_);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
AppInfo* appInfo_ { nullptr };
|
||||
funcLongPress funcLongPress_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <securec.h>
|
||||
|
||||
#include "app_manage.h"
|
||||
|
||||
namespace OHOS {
|
||||
ViewGroupPage* AppManage::viewPage_[MAX_VIEWGROUP] = { nullptr };
|
||||
funcClick AppManage::installFuncClick_ = { nullptr };
|
||||
funcLongPress AppManage::installFunclPress_ = { nullptr };
|
||||
int AppManage::size_ = 0;
|
||||
|
||||
AppManage::~AppManage()
|
||||
{
|
||||
UnregisterCallback();
|
||||
}
|
||||
|
||||
bool AppManage::GetAbilityInfosByBundleName(const char* bundleName, AppInfo* pApp)
|
||||
{
|
||||
if (bundleName == nullptr || pApp == nullptr) {
|
||||
return false;
|
||||
}
|
||||
uint8_t ret = -1;
|
||||
BundleInfo* pBundleInfos = nullptr;
|
||||
int count = 0;
|
||||
ret = GetBundleInfos(1, &pBundleInfos, &count);
|
||||
if (ret == 0) {
|
||||
BundleInfo* pBundleInfo = pBundleInfos;
|
||||
for (int i = 0; i < count; i++, pBundleInfo++) {
|
||||
if (memcmp(bundleName, pBundleInfo->bundleName, strlen(pBundleInfo->bundleName)) == 0) {
|
||||
memcpy_s(
|
||||
pApp->appName_, sizeof(pApp->appName_), pBundleInfo->bundleName, strlen(pBundleInfo->bundleName));
|
||||
pApp->appName_[strlen(pBundleInfo->bundleName)] = 0;
|
||||
if (pBundleInfo->abilityInfos[0].name) {
|
||||
memcpy_s(pApp->abilityName_, sizeof(pApp->abilityName_), pBundleInfo->abilityInfos[0].name,
|
||||
strlen(pBundleInfo->abilityInfos[0].name));
|
||||
pApp->abilityName_[strlen(pBundleInfo->abilityInfos[0].name)] = 0;
|
||||
}
|
||||
if (pBundleInfo->bigIconPath) {
|
||||
memcpy_s(pApp->appIconDir_, sizeof(pApp->appIconDir_), pBundleInfo->bigIconPath,
|
||||
strlen(pBundleInfo->bigIconPath));
|
||||
pApp->appIconDir_[strlen(pBundleInfo->bigIconPath)] = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AppManage::GetAppInstallInfo(const char* bundleName)
|
||||
{
|
||||
if (bundleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
AppInfo* pApp = new AppInfo();
|
||||
pApp->funcclick_ = installFuncClick_;
|
||||
pApp->funclPress_ = installFunclPress_;
|
||||
if (GetAbilityInfosByBundleName(bundleName, pApp) == true) {
|
||||
int i = 0;
|
||||
for (; i < size_; i++) {
|
||||
if (viewPage_[i]->FindApp(pApp)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == size_) {
|
||||
for (i = 0; i < size_; i++) {
|
||||
if (viewPage_[i]->AddApp(pApp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete pApp;
|
||||
pApp = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppManage::MyBundleStateCallback(
|
||||
const uint8_t installType, const uint8_t resultCode, const void* resultMessage, const char* bundleName, void* data)
|
||||
{
|
||||
if (installType == 0) { // install update
|
||||
if (resultCode == 0 && bundleName != nullptr) {
|
||||
char tmpName[TMP_BUF_SIZE] = {0};
|
||||
if (memcpy_s(tmpName, sizeof(tmpName), bundleName, strlen(bundleName)) == LAUNCHER_SUCCESS) {
|
||||
tmpName[strlen(bundleName)] = 0;
|
||||
GetAppInstallInfo(tmpName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppManage::MyBundleOwnCallback(const uint8_t resultCode, const void* resultMessage)
|
||||
{
|
||||
// todo uninstall callback
|
||||
}
|
||||
|
||||
bool AppManage::LauncherApp(BundleInfo** info, int& count)
|
||||
{
|
||||
callBackParam_.bundleName = nullptr;
|
||||
callBackParam_.data = nullptr;
|
||||
callBackParam_.callBack = MyBundleStateCallback;
|
||||
RegisterCallback(&callBackParam_);
|
||||
|
||||
BundleInfo* pBundleInfos = nullptr;
|
||||
uint8_t ret = GetBundleInfos(1, &pBundleInfos, &count);
|
||||
if (ret == 0) {
|
||||
*info = pBundleInfos;
|
||||
return true;
|
||||
} else {
|
||||
*info = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AppManage::InstallApp(AppInfo* app)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppManage::UnInstallApp(AppInfo* app)
|
||||
{
|
||||
return Uninstall(app->appName_, nullptr, MyBundleOwnCallback);
|
||||
}
|
||||
|
||||
bool AppManage::StartApp(AppInfo* app)
|
||||
{
|
||||
Want want1 = { nullptr };
|
||||
ElementName element = { nullptr };
|
||||
SetElementBundleName(&element, app->appName_);
|
||||
SetElementAbilityName(&element, app->abilityName_);
|
||||
SetWantElement(&want1, element);
|
||||
SetWantData(&want1, "WantData", strlen("WantData") + 1);
|
||||
StartAbility(&want1);
|
||||
ClearElement(&element);
|
||||
ClearWant(&want1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppManage::SetViewGroup(funcClick click, funcLongPress press, ViewGroupPage* viewPage[MAX_VIEWGROUP], int size)
|
||||
{
|
||||
if (click == nullptr || press == nullptr || viewPage == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
viewPage_[i] = viewPage[i];
|
||||
}
|
||||
size_ = size;
|
||||
installFuncClick_ = click;
|
||||
installFunclPress_ = press;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APP_MANAGE_H
|
||||
#define OHOS_APP_MANAGE_H
|
||||
|
||||
#include <ability_info.h>
|
||||
#include <ability_slice.h>
|
||||
#include <bundle_manager.h>
|
||||
#include <element_name.h>
|
||||
#include <module_info.h>
|
||||
#include <want.h>
|
||||
|
||||
#include "app_info.h"
|
||||
#include "ui_config.h"
|
||||
#include "view_group_page.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AppManage {
|
||||
public:
|
||||
AppManage() = default;
|
||||
~AppManage();
|
||||
// start all app ,get all app info
|
||||
|
||||
bool LauncherApp(BundleInfo** info, int& count);
|
||||
bool InstallApp(AppInfo* app);
|
||||
bool UnInstallApp(AppInfo* app);
|
||||
bool StartApp(AppInfo* app);
|
||||
static void SetViewGroup(funcClick click, funcLongPress press, ViewGroupPage* arrPage[MAX_VIEWGROUP], int size);
|
||||
|
||||
private:
|
||||
static void MyBundleStateCallback(const uint8_t installType, const uint8_t resultCode, const void* resultMessage,
|
||||
const char* bundleName, void* data);
|
||||
static void MyBundleOwnCallback(const uint8_t resultCode, const void* resultMessage);
|
||||
static bool GetAbilityInfosByBundleName(const char* bundleName, AppInfo* pApp);
|
||||
static bool GetAppInstallInfo(const char* bundleName);
|
||||
|
||||
private:
|
||||
BundleStatusCallback callBackParam_ { nullptr };
|
||||
static ViewGroupPage* viewPage_[MAX_VIEWGROUP];
|
||||
static int size_;
|
||||
static funcClick installFuncClick_;
|
||||
static funcLongPress installFunclPress_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_EVENT_LISTENER_H
|
||||
#define OHOS_EVENT_LISTENER_H
|
||||
|
||||
#include <components/ui_view.h>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace OHOS {
|
||||
using OnEventFunc = std::function<bool(UIView& view, const Event& event)>;
|
||||
|
||||
class EventListener : public UIView::OnClickListener, public UIView::OnLongPressListener {
|
||||
public:
|
||||
EventListener() = delete;
|
||||
~EventListener() override = default;
|
||||
|
||||
EventListener(OnEventFunc onClick, OnEventFunc onLongPress)
|
||||
{
|
||||
onClick_ = std::move(onClick);
|
||||
onLongPress_ = std::move(onLongPress);
|
||||
}
|
||||
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
if (!onClick_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onClick_(*currentView, event);
|
||||
}
|
||||
|
||||
bool OnLongPress(UIView& view, const LongPressEvent& event) override
|
||||
{
|
||||
if (!onLongPress_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onLongPress_(*currentView, event);
|
||||
}
|
||||
|
||||
private:
|
||||
OnEventFunc onClick_ { nullptr };
|
||||
OnEventFunc onLongPress_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "long_press_view.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
LongPressView::LongPressView(UninstallApp uninstall)
|
||||
{
|
||||
bStatus_ = false;
|
||||
uninstall_ = uninstall;
|
||||
viewGroup_ = new UIViewGroup();
|
||||
viewGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Black()));
|
||||
viewGroup_->SetStyle(STYLE_BORDER_RADIUS, GROUP_VIEW_RADIUS);
|
||||
viewGroup_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
|
||||
|
||||
buttUninstall_ = new UILabelButton();
|
||||
buttUninstall_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Gray()));
|
||||
buttUninstall_->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS);
|
||||
buttUninstall_->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
buttUninstall_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED);
|
||||
buttUninstall_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED);
|
||||
buttUninstall_->SetText("卸载");
|
||||
buttUninstall_->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
buttUninstall_->SetOnClickListener(this);
|
||||
|
||||
buttCancel_ = new UILabelButton();
|
||||
buttCancel_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Gray()));
|
||||
buttCancel_->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS);
|
||||
buttCancel_->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
buttCancel_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED);
|
||||
buttCancel_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED);
|
||||
buttCancel_->SetText("取消");
|
||||
buttCancel_->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
buttCancel_->SetOnClickListener(this);
|
||||
|
||||
viewGroup_->Add(buttUninstall_);
|
||||
viewGroup_->Add(buttCancel_);
|
||||
viewGroup_->SetVisible(false);
|
||||
}
|
||||
|
||||
LongPressView::~LongPressView()
|
||||
{
|
||||
DeleteChildren(viewGroup_);
|
||||
}
|
||||
|
||||
void LongPressView::RemoveLview()
|
||||
{
|
||||
if (bStatus_ == false) {
|
||||
return;
|
||||
}
|
||||
viewParent_->Remove(viewGroup_);
|
||||
viewGroup_->SetVisible(false);
|
||||
viewParent_->Invalidate();
|
||||
bStatus_ = false;
|
||||
}
|
||||
|
||||
void LongPressView::Show(UIViewGroup* viewParent, AppInfo* pApp)
|
||||
{
|
||||
const int16_t HEIGHT_DISCOUNT = 3;
|
||||
const int16_t WIDTH_DISCOUNT = 2;
|
||||
bStatus_ = true;
|
||||
viewParent_ = viewParent;
|
||||
app_ = pApp;
|
||||
viewGroup_->SetPosition(pApp->buttonXY_.x / WIDTH_DISCOUNT + pApp->button_->GetWidth(),
|
||||
pApp->buttonXY_.y / WIDTH_DISCOUNT + pApp->button_->GetHeight(), pApp->button_->GetWidth(),
|
||||
(pApp->button_->GetHeight() * WIDTH_DISCOUNT) / HEIGHT_DISCOUNT + pApp->button_->GetHeight() / WIDTH_DISCOUNT);
|
||||
buttUninstall_->SetPosition(0, 0,
|
||||
pApp->button_->GetWidth(), pApp->button_->GetHeight() / WIDTH_DISCOUNT);
|
||||
buttCancel_->SetPosition(0, (pApp->button_->GetHeight() * WIDTH_DISCOUNT) / HEIGHT_DISCOUNT,
|
||||
pApp->button_->GetWidth(), pApp->button_->GetHeight() / WIDTH_DISCOUNT);
|
||||
viewGroup_->SetVisible(true);
|
||||
viewParent_->Add(viewGroup_);
|
||||
viewParent_->Invalidate();
|
||||
}
|
||||
|
||||
bool LongPressView::OnClick(UIView& view, const ClickEvent& event)
|
||||
{
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
UILabelButton* lbutt = nullptr;
|
||||
lbutt = static_cast<UILabelButton*>(currentView);
|
||||
RemoveLview();
|
||||
if (currentView == buttUninstall_) {
|
||||
uninstall_(app_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LISTENTER_H
|
||||
#define OHOS_LISTENTER_H
|
||||
|
||||
#include "app_info.h"
|
||||
#include "view_group_page.h"
|
||||
#include "app_manage.h"
|
||||
|
||||
namespace OHOS {
|
||||
class LongPressView : public UIView::OnClickListener, public NativeBase {
|
||||
public:
|
||||
explicit LongPressView(UninstallApp uninstall);
|
||||
virtual ~LongPressView();
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override;
|
||||
void RemoveLview();
|
||||
void Show(UIViewGroup* viewParent, AppInfo* pApp);
|
||||
void SetStatus(bool status)
|
||||
{
|
||||
bStatus_ = status;
|
||||
}
|
||||
|
||||
bool GetStatus() const
|
||||
{
|
||||
return bStatus_;
|
||||
}
|
||||
|
||||
private:
|
||||
UIViewGroup* viewParent_ { nullptr };
|
||||
UIViewGroup* viewGroup_ { nullptr };
|
||||
UILabelButton* buttUninstall_ { nullptr };
|
||||
UILabelButton* buttCancel_ { nullptr };
|
||||
UninstallApp uninstall_ { nullptr };
|
||||
AppInfo* app_ { nullptr };
|
||||
bool bStatus_ { false };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "main_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AA(MainAbility)
|
||||
|
||||
void MainAbility::OnStart(const Want& want)
|
||||
{
|
||||
SetMainRoute("MainAbilitySlice");
|
||||
Ability::OnStart(want);
|
||||
}
|
||||
|
||||
void MainAbility::OnInactive()
|
||||
{
|
||||
Ability::OnInactive();
|
||||
}
|
||||
|
||||
void MainAbility::OnActive(const Want& want)
|
||||
{
|
||||
Ability::OnActive(want);
|
||||
}
|
||||
|
||||
void MainAbility::OnBackground()
|
||||
{
|
||||
Ability::OnBackground();
|
||||
}
|
||||
|
||||
void MainAbility::OnStop()
|
||||
{
|
||||
Ability::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_MAIN_ABILITY_H
|
||||
#define OHOS_MAIN_ABILITY_H
|
||||
|
||||
#include <ability_loader.h>
|
||||
|
||||
namespace OHOS {
|
||||
class MainAbility : public Ability {
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <common/screen.h>
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_label_button.h>
|
||||
|
||||
#include "main_ability_slice.h"
|
||||
#include "ability_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(MainAbilitySlice)
|
||||
|
||||
MainAbilitySlice::~MainAbilitySlice()
|
||||
{
|
||||
ReleaseView();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::ReleaseView()
|
||||
{
|
||||
if (swipeView_) {
|
||||
delete swipeView_;
|
||||
swipeView_ = nullptr;
|
||||
}
|
||||
if (uiImageView_) {
|
||||
delete uiImageView_;
|
||||
uiImageView_ = nullptr;
|
||||
}
|
||||
if (lableHead_) {
|
||||
delete lableHead_;
|
||||
lableHead_ = nullptr;
|
||||
}
|
||||
if (lableTail_) {
|
||||
delete lableTail_;
|
||||
lableTail_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetHead()
|
||||
{
|
||||
char tmp[TMP_BUF_SIZE] = { 0 };
|
||||
time_t t = time(nullptr);
|
||||
struct tm* st = nullptr;
|
||||
st = localtime(&t);
|
||||
sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
|
||||
UILabel* label = new UILabel();
|
||||
rootview_->Add(label);
|
||||
label->SetPosition(0, 0, Screen::GetInstance().GetWidth(), LABLE_TITLE_HEIGHT);
|
||||
label->SetText(tmp);
|
||||
label->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP);
|
||||
label->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
|
||||
lableHead_ = label;
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetTail()
|
||||
{
|
||||
UILabel* label = new UILabel();
|
||||
rootview_->Add(label);
|
||||
label->SetPosition(0, Screen::GetInstance().GetHeight() - LABLE_TAIL_HEIGHT,
|
||||
Screen::GetInstance().GetWidth(), LABLE_TAIL_HEIGHT);
|
||||
char buf[TMP_BUF_SIZE] = { 0 };
|
||||
sprintf_s(buf, sizeof(buf), ".%d.", 1);
|
||||
label->SetText(buf);
|
||||
label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
||||
label->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
|
||||
lableTail_ = label;
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetImageView()
|
||||
{
|
||||
uiImageView_ = new UIImageView();
|
||||
// modify image view height
|
||||
|
||||
uiImageView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
||||
uiImageView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White()));
|
||||
uiImageView_->SetSrc(TABLE_BACKGROUND);
|
||||
uiImageView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
|
||||
rootview_->Add(uiImageView_);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetSwipe()
|
||||
{
|
||||
swipeView_ = new SwipeView(lableHead_, lableTail_);
|
||||
swipeView_->OnSetUpView();
|
||||
rootview_->Add(swipeView_->GetSwipeView());
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnStart(want);
|
||||
rootview_ = RootView::GetWindowRootView();
|
||||
rootview_->SetPosition(0, 0);
|
||||
rootview_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
||||
rootview_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
|
||||
rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30)));
|
||||
SetImageView();
|
||||
SetHead();
|
||||
SetTail();
|
||||
SetSwipe();
|
||||
SetUIContent(rootview_);
|
||||
rootview_->Invalidate();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_MAIN_ABILITY_SLICE_H
|
||||
#define OHOS_MAIN_ABILITY_SLICE_H
|
||||
|
||||
#include <ability_info.h>
|
||||
#include <ability_loader.h>
|
||||
#include <bundle_info.h>
|
||||
#include <components/root_view.h>
|
||||
#include <components/ui_image_view.h>
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_label_button.h>
|
||||
#include <components/ui_swipe_view.h>
|
||||
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "swipe_view.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
class MainAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
MainAbilitySlice() = default;
|
||||
~MainAbilitySlice() override;
|
||||
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
void SetHead();
|
||||
void SetTail();
|
||||
void SetSwipe();
|
||||
void ReleaseView();
|
||||
void SetImageView();
|
||||
|
||||
private:
|
||||
SwipeView* swipeView_ { nullptr };
|
||||
UIImageView* uiImageView_ { nullptr };
|
||||
UILabel* lableHead_ { nullptr };
|
||||
UILabel* lableTail_ { nullptr };
|
||||
RootView *rootview_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_NATIVE_BASE_H
|
||||
#define OHOS_NATIVE_BASE_H
|
||||
|
||||
#include <components/ui_view_group.h>
|
||||
|
||||
namespace OHOS {
|
||||
class NativeBase : public HeapBase {
|
||||
public:
|
||||
NativeBase() {}
|
||||
virtual ~NativeBase() {}
|
||||
void DeleteChildren(UIView *view)
|
||||
{
|
||||
if (view == nullptr) {
|
||||
return;
|
||||
}
|
||||
while (view) {
|
||||
UIView *tempView = view;
|
||||
view = view->GetNextSibling();
|
||||
if (tempView->IsViewGroup()) {
|
||||
DeleteChildren(static_cast<UIViewGroup *>(tempView)->GetChildrenHead());
|
||||
}
|
||||
if (tempView->GetParent()) {
|
||||
static_cast<UIViewGroup *>(tempView->GetParent())->Remove(tempView);
|
||||
}
|
||||
delete tempView;
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <common/screen.h>
|
||||
|
||||
#include "swipe_view.h"
|
||||
|
||||
namespace OHOS {
|
||||
AppEvent* AppEvent::appEvent_ = { nullptr };
|
||||
SwipeView* AppEvent::nativeView_ = { nullptr };
|
||||
static constexpr int32_t PERIOD_TIME = 60 * 1000; // 60 seconds
|
||||
|
||||
SwipeView::SwipeView(UILabel* titlellable, UILabel* taillable)
|
||||
{
|
||||
lableTitle_ = titlellable;
|
||||
lableTail_ = taillable;
|
||||
groupCount_ = 0;
|
||||
for (int i = 0; i < MAX_VIEWGROUP; i++) {
|
||||
arrPage_[i] = nullptr;
|
||||
}
|
||||
arrViewListener_ = nullptr;
|
||||
swipeListener_ = nullptr;
|
||||
appManage_ = new AppManage();
|
||||
lpView_ = new LongPressView(AppEvent::UninstallApp);
|
||||
Task::Init();
|
||||
Task::SetPeriod(PERIOD_TIME);
|
||||
}
|
||||
|
||||
SwipeView::~SwipeView()
|
||||
{
|
||||
OnStop();
|
||||
}
|
||||
|
||||
void SwipeView::SetUpSwipe()
|
||||
{
|
||||
swipe_ = new UISwipeView();
|
||||
swipe_->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
|
||||
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
|
||||
swipe_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
swipe_->SetLoopState(true);
|
||||
swipe_->SetAnimatorTime(20); // set swipe view animator time 20s
|
||||
}
|
||||
|
||||
UIViewGroup* SwipeView::AddViewGroup()
|
||||
{
|
||||
if (groupCount_ >= MAX_VIEWGROUP) {
|
||||
return nullptr;
|
||||
}
|
||||
UIViewGroup* viewGroup = new UIViewGroup();
|
||||
viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
|
||||
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
|
||||
viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
groupCount_++;
|
||||
ViewGroupPage* page = new ViewGroupPage(viewGroup);
|
||||
arrPage_[groupCount_ - 1] = page;
|
||||
swipe_->Add(viewGroup);
|
||||
return viewGroup;
|
||||
}
|
||||
|
||||
UIViewGroup* SwipeView::AddFirstViewGroup()
|
||||
{
|
||||
UIViewGroup* firstView = new UIViewGroup();
|
||||
firstView->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
|
||||
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
|
||||
firstView->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
|
||||
UIViewGroup* viewTimeWeather = new UIViewGroup();
|
||||
// 2: set first view to 2 piece
|
||||
viewTimeWeather->SetPosition(0, 0, firstView->GetWidth() / 2, firstView->GetHeight());
|
||||
viewTimeWeather->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
timeWeatherView_ = new TimeWeatherView(viewTimeWeather);
|
||||
timeWeatherView_->SetUpView();
|
||||
firstView->Add(viewTimeWeather);
|
||||
|
||||
UIViewGroup* viewGroup = new UIViewGroup();
|
||||
// 2 : get left && right view width and height
|
||||
viewGroup->SetPosition(firstView->GetWidth() / 2, 0, firstView->GetWidth() / 2, firstView->GetHeight());
|
||||
viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
firstView->Add(viewGroup);
|
||||
groupCount_++;
|
||||
ViewGroupPage *page = new ViewGroupPage(viewGroup);
|
||||
arrPage_[groupCount_ - 1] = page;
|
||||
|
||||
swipe_->Add(firstView);
|
||||
firstView->Invalidate();
|
||||
Task::TaskExecute();
|
||||
return firstView;
|
||||
}
|
||||
|
||||
void SwipeView::OnSetUpView()
|
||||
{
|
||||
SetUpSwipe();
|
||||
swipeListener_ = new SwipeListener(lpView_, swipe_, lableTail_);
|
||||
swipe_->SetOnSwipeListener(swipeListener_);
|
||||
arrViewListener_ = new ViewPageListener(lpView_);
|
||||
swipe_->SetOnClickListener(arrViewListener_);
|
||||
|
||||
AddFirstViewGroup();
|
||||
AddViewGroup();
|
||||
AddViewGroup();
|
||||
// Reserved. Touch and hold to add a page.
|
||||
arrPage_[0]->SetMatrix(APP_ROW_COUNT, APP_COL_COUNT);
|
||||
arrPage_[0]->SetScale(0.6); // 0.6 blank/icon width
|
||||
for (int16_t i = 1; i < groupCount_; i++) {
|
||||
arrPage_[i]->SetMatrix(APP_ROW_COUNT, 2 * APP_COL_COUNT); // 2 scale of first view's col count
|
||||
arrPage_[i]->SetScale(0.69); // 0.69 blank/icon width
|
||||
}
|
||||
AppEvent::GetInstance(this);
|
||||
AppManage::SetViewGroup(AppEvent::ClickEvent, AppEvent::LongPressEvent, arrPage_, groupCount_);
|
||||
BundleInfo* pBundleInfos = nullptr;
|
||||
int count = 0;
|
||||
if (appManage_->LauncherApp(&pBundleInfos, count)) {
|
||||
for (int j = 0; j < count; j++) {
|
||||
for (int i = 0; i < groupCount_; i++) {
|
||||
if (memcmp(LAUNCHER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) {
|
||||
break;
|
||||
}
|
||||
if (memcmp(SCREENSAVER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
AppInfo* app = new AppInfo();
|
||||
app->funcclick_ = AppEvent::ClickEvent;
|
||||
app->funclPress_ = AppEvent::LongPressEvent;
|
||||
if (pBundleInfos[j].bundleName) {
|
||||
memcpy_s(app->appName_, sizeof(app->appName_), pBundleInfos[j].bundleName,
|
||||
strlen(pBundleInfos[j].bundleName));
|
||||
app->appName_[strlen(pBundleInfos[j].bundleName)] = 0;
|
||||
}
|
||||
if (pBundleInfos[j].abilityInfos[0].name) {
|
||||
memcpy_s(app->abilityName_, sizeof(app->abilityName_), pBundleInfos[j].abilityInfos[0].name,
|
||||
strlen(pBundleInfos[j].abilityInfos[0].name));
|
||||
app->abilityName_[strlen(pBundleInfos[j].abilityInfos[0].name)] = 0;
|
||||
}
|
||||
if (pBundleInfos[j].bigIconPath) {
|
||||
memcpy_s(app->appIconDir_, sizeof(app->appIconDir_), pBundleInfos[j].bigIconPath,
|
||||
strlen(pBundleInfos[j].bigIconPath));
|
||||
app->appIconDir_[strlen(pBundleInfos[j].bigIconPath)] = 0;
|
||||
}
|
||||
if (arrPage_[i]->AddApp(app)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
swipe_->SetCurrentPage(0);
|
||||
}
|
||||
|
||||
void SwipeView::StartApp(AppInfo* app)
|
||||
{
|
||||
if (lpView_->GetStatus() == true) {
|
||||
lpView_->RemoveLview();
|
||||
return;
|
||||
}
|
||||
appManage_->StartApp(app);
|
||||
}
|
||||
|
||||
void SwipeView::ShowLongPressView(AppInfo* app)
|
||||
{
|
||||
lpView_->Show(static_cast<UIViewGroup*>(app->button_->GetParent()), app);
|
||||
}
|
||||
|
||||
void SwipeView::UninstallApp(AppInfo* app)
|
||||
{
|
||||
if (appManage_->UnInstallApp(app)) {
|
||||
for (int16_t i = 0; i < groupCount_; i++) {
|
||||
if (arrPage_[i]) {
|
||||
if (arrPage_[i]->RemoveApp(app->appName_)) {
|
||||
swipe_->Invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SwipeView::InstallApp(AppInfo* app)
|
||||
{
|
||||
appManage_->InstallApp(app);
|
||||
AppInfo* pApp = new AppInfo();
|
||||
if (pApp == nullptr) {
|
||||
return;
|
||||
}
|
||||
app->funcclick_ = AppEvent::ClickEvent;
|
||||
app->funclPress_ = AppEvent::LongPressEvent;
|
||||
int16_t i;
|
||||
for (i = 0; i < groupCount_; i++) {
|
||||
if (arrPage_[i]->AddApp(pApp)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == groupCount_) {
|
||||
delete pApp;
|
||||
pApp = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SwipeView::OnStop()
|
||||
{
|
||||
if (lpView_) {
|
||||
delete lpView_;
|
||||
lpView_ = nullptr;
|
||||
}
|
||||
if (appManage_) {
|
||||
delete appManage_;
|
||||
appManage_ = nullptr;
|
||||
}
|
||||
if (arrViewListener_) {
|
||||
delete arrViewListener_;
|
||||
arrViewListener_ = nullptr;
|
||||
}
|
||||
if (swipeListener_) {
|
||||
delete swipeListener_;
|
||||
swipeListener_ = nullptr;
|
||||
}
|
||||
if (timeWeatherView_) {
|
||||
delete timeWeatherView_;
|
||||
timeWeatherView_ = nullptr;
|
||||
}
|
||||
for (int i = 0; i < MAX_VIEWGROUP; i++) {
|
||||
if (arrPage_[i]) {
|
||||
delete arrPage_[i];
|
||||
arrPage_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
DeleteChildren(swipe_);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SWIPE_VIEW_H
|
||||
#define OHOS_SWIPE_VIEW_H
|
||||
|
||||
#include <cstdio>
|
||||
#include <securec.h>
|
||||
#include <components/ui_label_button.h>
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_view_group.h>
|
||||
#include <components/ui_swipe_view.h>
|
||||
#include <components/root_view.h>
|
||||
#include <common/task.h>
|
||||
|
||||
#include "ui_config.h"
|
||||
#include "app_info.h"
|
||||
#include "view_group_page.h"
|
||||
#include "native_base.h"
|
||||
#include "long_press_view.h"
|
||||
#include "app_manage.h"
|
||||
#include "time_weather_view.h"
|
||||
|
||||
namespace OHOS {
|
||||
class ViewPageListener : public UIView::OnClickListener {
|
||||
public:
|
||||
explicit ViewPageListener(LongPressView* view) : view_(view) {}
|
||||
virtual ~ViewPageListener() {}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
view_->RemoveLview();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
LongPressView *view_ { nullptr };
|
||||
};
|
||||
|
||||
class SwipeListener : public UISwipeView::OnSwipeListener {
|
||||
public:
|
||||
SwipeListener(LongPressView* view, UISwipeView* swipe, UILabel* lable)
|
||||
: view_(view), swipe_(swipe), lable_(lable) {};
|
||||
~SwipeListener() {};
|
||||
virtual void OnSwipe(UISwipeView& view) override
|
||||
{
|
||||
char buf[TMP_BUF_SIZE] = { 0 };
|
||||
sprintf_s(buf, sizeof(buf), ".%d.", swipe_->GetCurrentPage() + 1);
|
||||
lable_->SetText(buf);
|
||||
view_->RemoveLview();
|
||||
}
|
||||
|
||||
private:
|
||||
LongPressView* view_ { nullptr };
|
||||
UISwipeView* swipe_ { nullptr };
|
||||
UILabel* lable_ { nullptr };
|
||||
};
|
||||
|
||||
class SwipeView : public Task, public NativeBase {
|
||||
public:
|
||||
SwipeView() = delete;
|
||||
SwipeView(UILabel* titlellable, UILabel* taillable);
|
||||
virtual ~SwipeView();
|
||||
void OnSetUpView();
|
||||
void StartApp(AppInfo* app);
|
||||
void ShowLongPressView(AppInfo* app);
|
||||
void UninstallApp(AppInfo* app);
|
||||
void InstallApp(AppInfo* app);
|
||||
void Callback() override
|
||||
{
|
||||
char tmp[TMP_BUF_SIZE] = { 0 };
|
||||
time_t t = time(nullptr);
|
||||
struct tm* st = localtime(&t);
|
||||
if (st != nullptr) {
|
||||
int ret = sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
|
||||
if (ret != LAUNCHER_PARAMERROR) {
|
||||
lableTitle_->SetText(tmp);
|
||||
timeWeatherView_->SetUpTimeView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UISwipeView* GetSwipeView() const
|
||||
{
|
||||
return swipe_;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnStop();
|
||||
void SetUpSwipe();
|
||||
UIViewGroup* AddViewGroup();
|
||||
UIViewGroup* AddFirstViewGroup();
|
||||
ViewGroupPage* arrPage_[MAX_VIEWGROUP] { nullptr };
|
||||
UISwipeView* swipe_ { nullptr };
|
||||
UILabel* lableTitle_ { nullptr }; // view title time label
|
||||
UILabel* lableTail_ { nullptr };
|
||||
int groupCount_ { 0 };
|
||||
ViewPageListener* arrViewListener_ { nullptr };
|
||||
SwipeListener* swipeListener_ { nullptr };
|
||||
AppManage* appManage_ { nullptr };
|
||||
LongPressView* lpView_ { nullptr };
|
||||
TimeWeatherView* timeWeatherView_ {nullptr};
|
||||
};
|
||||
|
||||
class AppEvent {
|
||||
public:
|
||||
static AppEvent* GetInstance(SwipeView* nativeView)
|
||||
{
|
||||
if (appEvent_ == nullptr) {
|
||||
appEvent_ = new AppEvent();
|
||||
nativeView_ = nativeView;
|
||||
}
|
||||
return appEvent_;
|
||||
}
|
||||
// app click
|
||||
|
||||
static bool ClickEvent(AppInfo* app)
|
||||
{
|
||||
nativeView_->StartApp(app);
|
||||
return true;
|
||||
}
|
||||
// app long press show window
|
||||
|
||||
static bool LongPressEvent(AppInfo* app)
|
||||
{
|
||||
nativeView_->ShowLongPressView(app);
|
||||
return true;
|
||||
}
|
||||
// app uninstall click
|
||||
|
||||
static bool UninstallApp(AppInfo* app)
|
||||
{
|
||||
nativeView_->UninstallApp(app);
|
||||
return true;
|
||||
}
|
||||
// none install app used appmanage::InstallApp, this function is invailate
|
||||
|
||||
static bool InstallApp(AppInfo* app)
|
||||
{
|
||||
nativeView_->InstallApp(app);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
AppEvent() {}
|
||||
~AppEvent()
|
||||
{
|
||||
if (appEvent_) {
|
||||
delete appEvent_;
|
||||
appEvent_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static AppEvent* appEvent_;
|
||||
static SwipeView* nativeView_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include <securec.h>
|
||||
|
||||
#include "time_weather_view.h"
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr int16_t DISPLATE_PICESE = 2;
|
||||
static constexpr int16_t BLANK_H = 5;
|
||||
static constexpr int16_t BLANK_TW = 15;
|
||||
static constexpr int16_t BLANK_W = 100;
|
||||
static constexpr int16_t BIGLABEL_H = 100;
|
||||
static constexpr int16_t SMALLLABEL_H = 35;
|
||||
static constexpr int16_t IMAGE_H = 40;
|
||||
static constexpr int16_t IMAGE_W = 40;
|
||||
const char* g_weekDate[WEEK_DAY_MAX] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
|
||||
TimeWeatherView::TimeWeatherView(UIViewGroup* viewGroup)
|
||||
{
|
||||
viewGroup_ = viewGroup;
|
||||
}
|
||||
TimeWeatherView::~TimeWeatherView()
|
||||
{
|
||||
// todo other release
|
||||
}
|
||||
|
||||
void TimeWeatherView::SetStyle(Style sty)
|
||||
{
|
||||
viewGroup_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
viewGroup_->Invalidate();
|
||||
}
|
||||
|
||||
void TimeWeatherView::SetPosion(int16_t x, int16_t y, int16_t height, int16_t width)
|
||||
{
|
||||
viewGroup_->SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
void TimeWeatherView::SetUpView()
|
||||
{
|
||||
SetUpTimeView();
|
||||
SetUpWeatherView();
|
||||
viewGroup_->Invalidate();
|
||||
}
|
||||
|
||||
void TimeWeatherView::SetUpTimeView()
|
||||
{
|
||||
char hour_min[TMP_BUF_SIZE] = { 0 };
|
||||
char mont_day[TMP_BUF_SIZE] = { 0 };
|
||||
char week_day[TMP_BUF_SIZE] = { 0 };
|
||||
char date[TMP_BUF_SIZE] = { 0 };
|
||||
const int16_t january = 1;
|
||||
const int16_t commonYear = 1970;
|
||||
time_t t = time(nullptr);
|
||||
struct tm* st = localtime(&t);
|
||||
if (st == nullptr) {
|
||||
return;
|
||||
}
|
||||
int ret = sprintf_s(hour_min, sizeof(hour_min), "%02d : %02d", st->tm_hour, st->tm_min);
|
||||
if (ret == LAUNCHER_PARAMERROR) {
|
||||
return;
|
||||
}
|
||||
ret = sprintf_s(mont_day, sizeof(mont_day), "%02d月%02d日", st->tm_mon + january, st->tm_mday);
|
||||
if (ret == LAUNCHER_PARAMERROR) {
|
||||
return;
|
||||
}
|
||||
GetWeekdayByYearday(st->tm_year + commonYear, st->tm_mon + january, st->tm_mday, week_day, sizeof(week_day));
|
||||
ret = sprintf_s(date, sizeof(date), "%s %s", mont_day, week_day);
|
||||
if (ret == LAUNCHER_PARAMERROR) {
|
||||
return;
|
||||
}
|
||||
if (viewTime_ == nullptr) {
|
||||
viewTime_ = new UIViewGroup();
|
||||
viewTime_->SetPosition(BLANK_TW, BLANK_H, viewGroup_->GetWidth() - BLANK_W,
|
||||
viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H);
|
||||
viewTime_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
UILabel* lable = new UILabel();
|
||||
lable->SetPosition(BLANK_TW, BLANK_H, viewTime_->GetWidth(), BIGLABEL_H);
|
||||
lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_BOTTOM);
|
||||
lable->SetText(hour_min);
|
||||
lable->SetFont(FOND_PATH, BIGLAUNCHER_FOND_ID);
|
||||
lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
|
||||
lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
lable->SetViewId("labletime");
|
||||
|
||||
UILabel* lable2 = new UILabel();
|
||||
lable2->SetPosition(BLANK_TW, BLANK_H + BIGLABEL_H + BLANK_H, viewTime_->GetWidth(), SMALLLABEL_H);
|
||||
lable2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
|
||||
lable2->SetText(date);
|
||||
lable2->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
|
||||
lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
|
||||
lable2->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
lable2->SetViewId("labledate");
|
||||
|
||||
viewTime_->Add(lable);
|
||||
viewTime_->Add(lable2);
|
||||
viewGroup_->Add(viewTime_);
|
||||
} else {
|
||||
UILabel* label = nullptr;
|
||||
label = static_cast<UILabel*>(viewTime_->GetChildById("labletime"));
|
||||
if (label) {
|
||||
label->SetText(hour_min);
|
||||
}
|
||||
label = static_cast<UILabel*>(viewTime_->GetChildById("labledate"));
|
||||
if (label) {
|
||||
label->SetText(date);
|
||||
}
|
||||
viewTime_->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void TimeWeatherView::GetWeekdayByYearday(int iY, int iM, int iD, char* date, int size)
|
||||
{
|
||||
if (date == nullptr) {
|
||||
return;
|
||||
}
|
||||
const int16_t months = 12;
|
||||
const int16_t january = 1;
|
||||
const int16_t february = 2;
|
||||
const int16_t oneHundred = 100;
|
||||
const int16_t fourHundred = 400;
|
||||
int iWeekDay = -1;
|
||||
if (january == iM || february == iM) {
|
||||
iM += months;
|
||||
iY--;
|
||||
}
|
||||
// 1 : MONDAY_LAUNCHER, 2 : TUESDAY_LAUNCHER, 3 : WEDNESDAY_LAUNCHER, 4 : , 5 : ect
|
||||
iWeekDay = (iD + 1 + 2 * iM + 3 * (iM + 1) / 5 + iY + iY / 4 - iY / oneHundred + iY / fourHundred) % WEEKEND_LAUNCHER;
|
||||
for (int i = 0; i < WEEK_DAY_MAX; i++) {
|
||||
if (iWeekDay == i) {
|
||||
if (memcpy_s(date, size, g_weekDate[i], strlen(g_weekDate[i])) == LAUNCHER_SUCCESS) {
|
||||
date[strlen(g_weekDate[i])] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void TimeWeatherView::SetUpWeatherView()
|
||||
{
|
||||
const int16_t countTimes = 6;
|
||||
viewweather_ = new UIViewGroup();
|
||||
viewweather_->SetPosition(BLANK_W, viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H,
|
||||
viewGroup_->GetWidth() / DISPLATE_PICESE + BLANK_TW, DISPLATE_PICESE * (BLANK_H + SMALLLABEL_H) + BLANK_H);
|
||||
viewweather_->SetStyle(STYLE_BACKGROUND_OPA, HALF_OPACITY);
|
||||
viewweather_->SetStyle(STYLE_BORDER_RADIUS, GROUP_VIEW_RADIUS);
|
||||
viewweather_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Gray()));
|
||||
|
||||
UIImageView* uiImageView = new UIImageView();
|
||||
uiImageView->SetPosition(BLANK_TW, BLANK_H * countTimes, IMAGE_W, IMAGE_H);
|
||||
uiImageView->SetSrc(RES_WEATHER);
|
||||
uiImageView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
|
||||
|
||||
UILabel* lable = new UILabel();
|
||||
lable->SetPosition(BLANK_TW + IMAGE_W, BLANK_H,
|
||||
viewweather_->GetWidth() - IMAGE_W - BLANK_TW - BLANK_TW - BLANK_TW, SMALLLABEL_H);
|
||||
lable->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
|
||||
lable->SetText("室内温度 26℃");
|
||||
lable->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
|
||||
lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
|
||||
UILabel* lable2 = new UILabel();
|
||||
lable2->SetPosition(BLANK_TW + IMAGE_W, SMALLLABEL_H + BLANK_H + BLANK_H,
|
||||
viewweather_->GetWidth() - IMAGE_W - BLANK_TW - BLANK_TW - BLANK_TW, SMALLLABEL_H);
|
||||
lable2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
|
||||
lable2->SetText("空气污染指数 136");
|
||||
lable2->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
|
||||
lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
|
||||
lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
|
||||
lable2->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
|
||||
|
||||
viewweather_->Add(uiImageView);
|
||||
viewweather_->Add(lable);
|
||||
viewweather_->Add(lable2);
|
||||
viewGroup_->Add(viewweather_);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_TIME_WEATHER_H
|
||||
#define OHOS_TIME_WEATHER_H
|
||||
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_label_button.h>
|
||||
#include <components/ui_view_group.h>
|
||||
#include <components/ui_image_view.h>
|
||||
|
||||
#include "app_info.h"
|
||||
#include "native_base.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
enum DATE_LAUNCHER {
|
||||
SUNDAY_LAUNCHER = 0,
|
||||
MONDAY_LAUNCHER,
|
||||
TUESDAY_LAUNCHER,
|
||||
WEDNESDAY_LAUNCHER,
|
||||
THURSDAY_LAUNCHER,
|
||||
FRIDAY_LAUNCHER,
|
||||
SATURDAY_LAUNCHER,
|
||||
WEEKEND_LAUNCHER
|
||||
};
|
||||
|
||||
class TimeWeatherView : public NativeBase {
|
||||
public:
|
||||
TimeWeatherView() = delete;
|
||||
explicit TimeWeatherView(UIViewGroup* viewGroup);
|
||||
virtual ~TimeWeatherView();
|
||||
void SetStyle(Style sty);
|
||||
void SetPosion(int16_t width, int16_t height, int16_t x, int16_t y);
|
||||
void SetUpView();
|
||||
void SetUpTimeView();
|
||||
|
||||
protected:
|
||||
void SetUpWeatherView();
|
||||
void GetWeekdayByYearday(int iY, int iM, int iD, char* date, int size);
|
||||
|
||||
private:
|
||||
UIViewGroup* viewTime_ { nullptr };
|
||||
UIViewGroup* viewweather_ { nullptr };
|
||||
UIViewGroup* viewGroup_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_UI_CONFIG_H
|
||||
#define OHOS_UI_CONFIG_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <securec.h>
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr int16_t LABLE_TITLE_HEIGHT = 30; // tail lable height
|
||||
static constexpr int16_t LABLE_TAIL_HEIGHT = 30;
|
||||
static constexpr int16_t APP_WIDTH_COUNT = 7; // blank + app + blank + app + blank
|
||||
static constexpr int16_t APP_HEIGHT_COUNT = 4; // app + lable + app + lable
|
||||
static constexpr int16_t MAX_VIEWGROUP = 3; // swipe window count
|
||||
static constexpr int16_t APP_ROW_COUNT = 2; // a swipe view app count in row
|
||||
static constexpr int16_t APP_COL_COUNT = 3; // a swipe view app count in col
|
||||
static constexpr int16_t LAUNCHER_FOND_ID = 16; // other view fond id
|
||||
static constexpr int16_t APP_FOND_ID = 16; // app name fond id
|
||||
static constexpr int16_t BIGLAUNCHER_FOND_ID = 48; // time big fond id
|
||||
static constexpr int16_t TOTAL_OPACITY = 0; // transparent
|
||||
static constexpr int16_t HALF_OPACITY = 50; // diaphanous
|
||||
static constexpr int16_t UN_OPACITY = 255; // opaque
|
||||
static constexpr int16_t BUTTON_RADIUS = 20; // app icon radius
|
||||
static constexpr int16_t LABLE_RADIUS = 0; // lable icon radius
|
||||
static constexpr int16_t TITLE_LABLE_OPACITY = 255; // translucent
|
||||
static constexpr int16_t GROUP_VIEW_RADIUS = 20; // view radius
|
||||
|
||||
#ifndef TMP_BUF_SIZE
|
||||
#define TMP_BUF_SIZE 128
|
||||
#endif
|
||||
|
||||
#define LAUNCHER_BUNDLE_NAME "com.huawei.launcher"
|
||||
#define SCREENSAVER_BUNDLE_NAME "com.huawei.screensaver"
|
||||
#define TABLE_BACKGROUND \
|
||||
"/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/background.png"
|
||||
#define RES_WEATHER "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/weather.png"
|
||||
#define FOND_PATH "SourceHanSansSC-Regular.otf"
|
||||
|
||||
#ifndef LAUNCHER_SUCCESS
|
||||
#define LAUNCHER_SUCCESS 0
|
||||
#endif
|
||||
|
||||
#ifndef LAUNCHER_PARAMERROR
|
||||
#define LAUNCHER_PARAMERROR (-1)
|
||||
#endif
|
||||
|
||||
#ifndef WEEK_DAY_MAX
|
||||
#define WEEK_DAY_MAX 7
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "view_group_page.h"
|
||||
#include "ui_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
ViewGroupPage::ViewGroupPage(UIViewGroup* viewGroup)
|
||||
{
|
||||
viewGroup_ = viewGroup;
|
||||
}
|
||||
|
||||
ViewGroupPage::~ViewGroupPage()
|
||||
{
|
||||
ListNode<AppInfo*>* app = appInfo_.Begin();
|
||||
while (app != appInfo_.End()) {
|
||||
delete app->data_;
|
||||
app = app->next_;
|
||||
}
|
||||
appInfo_.Clear();
|
||||
if (row_col_) {
|
||||
delete[] row_col_;
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewGroupPage::IsFull(int16_t& row, int16_t& col)
|
||||
{
|
||||
for (int16_t i = 0; i < row_; i++) {
|
||||
for (int16_t j = 0; j < col_; j++) {
|
||||
if (row_col_[i][j] == false) {
|
||||
row = i;
|
||||
col = j;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewGroupPage::SetStyle(Style sty)
|
||||
{
|
||||
viewGroup_->SetStyle(sty);
|
||||
viewGroup_->Invalidate();
|
||||
}
|
||||
|
||||
void ViewGroupPage::SetPosion(int16_t width, int16_t height, int16_t x, int16_t y)
|
||||
{
|
||||
viewGroup_->SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
void ViewGroupPage::SetScale(double scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
}
|
||||
|
||||
void ViewGroupPage::SetMatrix(int16_t rows, int16_t cols)
|
||||
{
|
||||
row_col_ = new bool* [rows];
|
||||
for (int i = 0; i < rows; i++) {
|
||||
row_col_[i] = new bool[cols]();
|
||||
}
|
||||
row_ = rows;
|
||||
col_ = cols;
|
||||
}
|
||||
|
||||
void ViewGroupPage::CalculateAppPosition(AppInfo* pAppInfo, int16_t row, int16_t col)
|
||||
{
|
||||
int16_t w = viewGroup_->GetWidth();
|
||||
|
||||
const double scale = scale_;
|
||||
const int16_t blank1 = 10;
|
||||
const int16_t blank2 = 30;
|
||||
const int16_t labelH = 2;
|
||||
int16_t width = static_cast<int16_t>(static_cast<double>(w) / static_cast<double>(scale * col_ + col_ + scale));
|
||||
int16_t heightB = width;
|
||||
int16_t heightL = heightB / labelH;
|
||||
int16_t xB = scale * width + (scale + 1) * width * col;
|
||||
int16_t yB = blank1 + (blank2 + heightL + heightB) * row;
|
||||
int16_t xL = xB;
|
||||
int16_t yL = yB + heightB + blank1;
|
||||
|
||||
pAppInfo->buttonXY_.x = xB;
|
||||
pAppInfo->buttonXY_.y = yB;
|
||||
pAppInfo->buttonHV_.x = width;
|
||||
pAppInfo->buttonHV_.y = heightB;
|
||||
|
||||
pAppInfo->lableXY_.x = xL;
|
||||
pAppInfo->lableXY_.y = yL;
|
||||
pAppInfo->lableHV_.x = width;
|
||||
pAppInfo->lableHV_.y = heightL;
|
||||
}
|
||||
|
||||
void ViewGroupPage::SetUpApp(AppInfo *pAppInfo)
|
||||
{
|
||||
UILabelButton *button = new UILabelButton();
|
||||
UILabel *lable = new UILabel();
|
||||
lable->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Red()));
|
||||
lable->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
|
||||
pAppInfo->SetButton(button);
|
||||
pAppInfo->SetLable(lable);
|
||||
|
||||
pAppInfo->SetListener(pAppInfo);
|
||||
viewGroup_->Add(button);
|
||||
viewGroup_->Add(lable);
|
||||
viewGroup_->Invalidate();
|
||||
}
|
||||
|
||||
bool ViewGroupPage::AddApp(AppInfo* pAppInfo)
|
||||
{
|
||||
int16_t row = 0;
|
||||
int16_t col = 0;
|
||||
|
||||
if (FindApp(pAppInfo)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsFull(row, col)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pAppInfo->SetLocation(row, col);
|
||||
CalculateAppPosition(pAppInfo, row, col);
|
||||
|
||||
SetUpApp(pAppInfo);
|
||||
appInfo_.PushBack(pAppInfo);
|
||||
row_col_[row][col] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewGroupPage::FindApp(AppInfo* pApp)
|
||||
{
|
||||
ListNode<AppInfo*>* app = appInfo_.Begin();
|
||||
while (app != appInfo_.End()) {
|
||||
if (memcmp(app->data_->appName_, pApp->appName_, strlen(pApp->appName_)) == 0) {
|
||||
return true;
|
||||
}
|
||||
app = app->next_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ViewGroupPage::RemoveApp(const char* pAppName)
|
||||
{
|
||||
ListNode<AppInfo*>* app = appInfo_.Begin();
|
||||
while (app != appInfo_.End()) {
|
||||
if (memcmp(app->data_->appName_, pAppName, strlen(pAppName)) == 0) {
|
||||
row_col_[app->data_->row_col_.x][app->data_->row_col_.y] = false;
|
||||
viewGroup_->Remove(app->data_->button_);
|
||||
viewGroup_->Remove(app->data_->lable_);
|
||||
viewGroup_->Invalidate();
|
||||
appInfo_.Remove(app);
|
||||
return true;
|
||||
}
|
||||
app = app->next_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_VIEWGROUP_PAGE_H
|
||||
#define OHOS_VIEWGROUP_PAGE_H
|
||||
|
||||
#include <components/ui_label.h>
|
||||
#include <components/ui_label_button.h>
|
||||
#include <components/ui_view_group.h>
|
||||
#include "gfx_utils/list.h"
|
||||
|
||||
#include "ui_config.h"
|
||||
#include "app_info.h"
|
||||
#include "native_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
class ViewGroupPage {
|
||||
public:
|
||||
ViewGroupPage() = delete;
|
||||
explicit ViewGroupPage(UIViewGroup* viewGroup);
|
||||
virtual ~ViewGroupPage();
|
||||
void SetMatrix(int16_t rows, int16_t cols);
|
||||
bool AddApp(AppInfo* pAppInfo);
|
||||
bool RemoveApp(const char* appName);
|
||||
bool FindApp(AppInfo* pAppInfo);
|
||||
void SetScale(double scale);
|
||||
|
||||
protected:
|
||||
void SetPosion(int16_t width, int16_t height, int16_t x = 0, int16_t y = 0);
|
||||
void SetStyle(Style sty);
|
||||
bool IsFull(int16_t& row, int16_t& col);
|
||||
void SetUpApp(AppInfo* pAppInfo);
|
||||
void CalculateAppPosition(AppInfo* pAppInfo, int16_t row, int16_t col);
|
||||
|
||||
private:
|
||||
List<AppInfo*> appInfo_;
|
||||
UIViewGroup* viewGroup_ { nullptr };
|
||||
bool** row_col_ { nullptr };
|
||||
int16_t row_ { 0 };
|
||||
int16_t col_ { 0 };
|
||||
double scale_ { 0.0 };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/hap_pack.gni")
|
||||
|
||||
shared_library("screensaver") {
|
||||
sources = [
|
||||
"screensaver/src/main/cpp/screensaver_ability.cpp",
|
||||
"screensaver/src/main/cpp/screensaver_ability_slice.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//foundation/graphic/surface",
|
||||
"//foundation/graphic/ui:lite_ui",
|
||||
"//foundation/graphic/utils:lite_graphic_utils",
|
||||
"//utils/native/lite/kv_store:kv_store",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"screensaver/src/main/cpp",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"//base/startup/syspara_lite/interfaces/kits",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ENABLE_WINDOW=1",
|
||||
"ABILITY_WINDOW_SUPPORT",
|
||||
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
|
||||
]
|
||||
}
|
||||
|
||||
hap_pack("screensaver_hap") {
|
||||
deps = [ ":screensaver" ]
|
||||
mode = "hap"
|
||||
json_path = "screensaver/src/main/config.json"
|
||||
ability_so_path = "$root_out_dir/libscreensaver.so"
|
||||
force = "true"
|
||||
cert_profile = "cert/com.huawei.screensaver_HarmonyAppProvision_release.p7b"
|
||||
resources_path = "screensaver/src/main/resources"
|
||||
hap_name = "screensaver"
|
||||
privatekey = "HOS Application Provision Release"
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,34 @@
|
||||
# CAMERA\_SCREENSAVER\_APP<a name="EN-US_TOPIC_0000001130489941"></a>
|
||||
|
||||
- [Introduction](#section132119717356)
|
||||
- [Directory Structure](#section176641621345)
|
||||
- [Constraints](#section722512541395)
|
||||
- [Repositories Involved](#section16511040154318)
|
||||
|
||||
## Introduction<a name="section132119717356"></a>
|
||||
|
||||
This repository provides the screen saver capability. You can use it to:
|
||||
|
||||
- Play the preset images.
|
||||
|
||||
- Tap the screen to exit the screen saver.
|
||||
|
||||
**Figure 1** Position of this repository in the graphics subsystem<a name="fig4460722185514"></a>
|
||||
|
||||
|
||||

|
||||
|
||||
## Directory Structure<a name="section176641621345"></a>
|
||||
|
||||
```
|
||||
applications/sample/camera/screensaver
|
||||
├── cert Certificate
|
||||
├── screensaver/src/main
|
||||
├──resources Resources
|
||||
├──cpp Source code
|
||||
```
|
||||
|
||||
## Constraints<a name="section722512541395"></a>
|
||||
|
||||
C++ 11 or later
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# 图形子系统CAMERA\_SCREENSAVER\_APP组件<a name="ZH-CN_TOPIC_0000001130489941"></a>
|
||||
|
||||
- [简介](#section132119717356)
|
||||
- [目录](#section176641621345)
|
||||
- [约束](#section722512541395)
|
||||
- [相关仓](#section16511040154318)
|
||||
|
||||
## 简介<a name="section132119717356"></a>
|
||||
|
||||
CAMERA\_SCREENSAVER\_APP组件, 提供用户屏幕保护能力。它主要实现了以下功能:
|
||||
|
||||
1、支持播放预设图片能力。
|
||||
|
||||
2、支持点击屏幕退出能力。
|
||||
|
||||
**图 1** 组件架构图(红色框是屏保应用)<a name="fig4460722185514"></a>
|
||||
|
||||
|
||||

|
||||
|
||||
## 目录<a name="section176641621345"></a>
|
||||
|
||||
```
|
||||
applications/sample/camera/screensaver
|
||||
├── cert 签名目录
|
||||
├── screensaver/src/main
|
||||
├──resources 资源目录
|
||||
├──cpp 源码目录
|
||||
```
|
||||
|
||||
## 约束<a name="section722512541395"></a>
|
||||
|
||||
C++11版本或以上
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.huawei.screensaver",
|
||||
"vendor": "huawei",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 3,
|
||||
"target": 4
|
||||
}
|
||||
},
|
||||
"deviceConfig": {
|
||||
"default": {
|
||||
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"package": "com.huawei.screensaver",
|
||||
"name": ".MyHarmonyAbilityPackage",
|
||||
"deviceType": [
|
||||
"phone", "tv","tablet","car","smartWatch","sportsWatch","smartVision"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "screensaver",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"name": "ScreensaverAbility",
|
||||
"label": "screensaver",
|
||||
"launchType": "standard",
|
||||
"type": "page",
|
||||
"visible":true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_EVENT_LISTENER_H
|
||||
#define OHOS_EVENT_LISTENER_H
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "components/ui_view.h"
|
||||
#include "events/click_event.h"
|
||||
#include "events/event.h"
|
||||
#include "events/long_press_event.h"
|
||||
|
||||
namespace OHOS {
|
||||
using OnEventFunc = std::function<bool(UIView &view, const Event &event)>;
|
||||
|
||||
class EventListener : public UIView::OnClickListener, public UIView::OnLongPressListener {
|
||||
public:
|
||||
EventListener() = delete;
|
||||
~EventListener() override = default;
|
||||
|
||||
EventListener(OnEventFunc onClick, OnEventFunc onLongPress)
|
||||
{
|
||||
onClick_ = std::move(onClick);
|
||||
onLongPress_ = std::move(onLongPress);
|
||||
}
|
||||
|
||||
bool OnClick(UIView& view, const ClickEvent &event) override
|
||||
{
|
||||
if (!onClick_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onClick_(*currentView, event);
|
||||
}
|
||||
|
||||
bool OnLongPress(UIView& view, const LongPressEvent &event) override
|
||||
{
|
||||
if (!onLongPress_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onLongPress_(*currentView, event);
|
||||
}
|
||||
|
||||
private:
|
||||
OnEventFunc onClick_ {};
|
||||
OnEventFunc onLongPress_ {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "screensaver_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AA(ScreensaverAbility)
|
||||
|
||||
void ScreensaverAbility::OnStart(const Want& want)
|
||||
{
|
||||
SetMainRoute("ScreensaverAbilitySlice");
|
||||
Ability::OnStart(want);
|
||||
}
|
||||
|
||||
void ScreensaverAbility::OnInactive()
|
||||
{
|
||||
Ability::OnInactive();
|
||||
}
|
||||
|
||||
void ScreensaverAbility::OnActive(const Want& want)
|
||||
{
|
||||
Ability::OnActive(want);
|
||||
}
|
||||
|
||||
void ScreensaverAbility::OnBackground()
|
||||
{
|
||||
Ability::OnBackground();
|
||||
}
|
||||
|
||||
void ScreensaverAbility::OnStop()
|
||||
{
|
||||
Ability::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SCREENSAVER_ABILITY_H
|
||||
#define OHOS_SCREENSAVER_ABILITY_H
|
||||
|
||||
#include <ability_loader.h>
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class ScreensaverAbility : public Ability {
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "screensaver_ability_slice.h"
|
||||
#include "common/screen.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(ScreensaverAbilitySlice)
|
||||
namespace {
|
||||
int16_t screenWidth = static_cast<int16_t>(Screen::GetInstance().GetWidth());
|
||||
int16_t screenHeight = static_cast<int16_t>(Screen::GetInstance().GetHeight());
|
||||
}
|
||||
static ImageAnimatorInfo g_imageAnimatorInfo[IMAGE_TOTAL_NUM] = {
|
||||
{{IMG_DEFAULT_001_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
|
||||
{{IMG_DEFAULT_002_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
|
||||
{{IMG_DEFAULT_003_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
|
||||
{{IMG_DEFAULT_004_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
|
||||
{{IMG_DEFAULT_005_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
|
||||
};
|
||||
|
||||
ScreensaverAbilitySlice::~ScreensaverAbilitySlice()
|
||||
{
|
||||
if (imageAnimator_ != nullptr) {
|
||||
delete imageAnimator_;
|
||||
imageAnimator_ = nullptr;
|
||||
}
|
||||
|
||||
if (exitListener_ != nullptr) {
|
||||
delete exitListener_;
|
||||
exitListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::SetCyclePlayView()
|
||||
{
|
||||
imageAnimator_ = new UIImageAnimatorView();
|
||||
imageAnimator_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
||||
imageAnimator_->SetImageAnimatorSrc(g_imageAnimatorInfo, IMAGE_TOTAL_NUM, IMAGE_ANIMATOR_TIME_S);
|
||||
rootView_->Add(imageAnimator_);
|
||||
|
||||
auto onClick = [this] (UIView& view, const Event& event) -> bool {
|
||||
TerminateAbility();
|
||||
return true;
|
||||
};
|
||||
exitListener_ = new EventListener(onClick, nullptr);
|
||||
imageAnimator_->SetOnClickListener(exitListener_);
|
||||
imageAnimator_->SetTouchable(true);
|
||||
|
||||
imageAnimator_->Start();
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::OnStart(const Want &want)
|
||||
{
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
|
||||
|
||||
SetCyclePlayView();
|
||||
SetUIContent(rootView_);
|
||||
rootView_->Invalidate();
|
||||
AbilitySlice::OnStart(want);
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::OnInactive()
|
||||
{
|
||||
printf("ScreensaverAbilitySlice::OnInactive\n");
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::OnActive(const Want &want)
|
||||
{
|
||||
printf("ScreensaverAbilitySlice::OnActive\n");
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::OnBackground()
|
||||
{
|
||||
printf("ScreensaverAbilitySlice::OnBackground\n");
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void ScreensaverAbilitySlice::OnStop()
|
||||
{
|
||||
printf("ScreensaverAbilitySlice::OnStop\n");
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SCREENSAVER_ABILITY_SLICE_H
|
||||
#define OHOS_SCREENSAVER_ABILITY_SLICE_H
|
||||
|
||||
#include <ability_info.h>
|
||||
#include <ability_loader.h>
|
||||
#include <bundle_info.h>
|
||||
#include "components/root_view.h"
|
||||
#include "components/ui_image_animator.h"
|
||||
#include "event_listener.h"
|
||||
#include "ui_config.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class ScreensaverAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
ScreensaverAbilitySlice() : rootView_(nullptr), imageAnimator_(nullptr), exitListener_(nullptr) {}
|
||||
virtual ~ScreensaverAbilitySlice();
|
||||
|
||||
protected:
|
||||
void OnStart(const Want &want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want &want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void SetCyclePlayView();
|
||||
|
||||
RootView* rootView_;
|
||||
UIImageAnimatorView* imageAnimator_;
|
||||
EventListener* exitListener_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_UI_CONFIG_H
|
||||
#define OHOS_UI_CONFIG_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr uint16_t IMAGE_ANIMATOR_TIME_S = 2 * 1000; // Cyclic image playback interval
|
||||
static constexpr uint8_t IMAGE_TOTAL_NUM = 5; // Number of images
|
||||
|
||||
static const char* const IMG_DEFAULT_001_PATH =
|
||||
"/storage/app/run/com.huawei.screensaver/screensaver/assets/screensaver/resources/base/media/img_default_1.png";
|
||||
static const char* const IMG_DEFAULT_002_PATH =
|
||||
"/storage/app/run/com.huawei.screensaver/screensaver/assets/screensaver/resources/base/media/img_default_2.png";
|
||||
static const char* const IMG_DEFAULT_003_PATH =
|
||||
"/storage/app/run/com.huawei.screensaver/screensaver/assets/screensaver/resources/base/media/img_default_3.png";
|
||||
static const char* const IMG_DEFAULT_004_PATH =
|
||||
"/storage/app/run/com.huawei.screensaver/screensaver/assets/screensaver/resources/base/media/img_default_4.png";
|
||||
static const char* const IMG_DEFAULT_005_PATH =
|
||||
"/storage/app/run/com.huawei.screensaver/screensaver/assets/screensaver/resources/base/media/img_default_5.png";
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,78 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/hap_pack.gni")
|
||||
|
||||
shared_library("setting") {
|
||||
sources = [
|
||||
"setting/src/main/cpp/app_ability_slice.cpp",
|
||||
"setting/src/main/cpp/app_info_ability_slice.cpp",
|
||||
"setting/src/main/cpp/main_ability_slice.cpp",
|
||||
"setting/src/main/cpp/setting_about_ability_slice.cpp",
|
||||
"setting/src/main/cpp/setting_display_ability_slice.cpp",
|
||||
"setting/src/main/cpp/setting_main_ability.cpp",
|
||||
"setting/src/main/cpp/setting_utils.cpp",
|
||||
"setting/src/main/cpp/setting_wifi_ability_slice.cpp",
|
||||
"setting/src/main/cpp/setting_wifi_input_password_ability_slice.cpp",
|
||||
"setting/src/main/cpp/wpa_work.c",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//base/powermgr/powermgr_lite/frameworks:powermgr",
|
||||
"//base/startup/syspara_lite/frameworks/parameter:parameter",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//foundation/graphic/surface",
|
||||
"//foundation/graphic/ui:lite_ui",
|
||||
"//foundation/graphic/utils:lite_graphic_utils",
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9:wpa_supplicant",
|
||||
"//utils/native/lite/kv_store:kv_store",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"setting/src/main/cpp",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"//base/startup/syspara_lite/interfaces/kits",
|
||||
"//base/security/permission/interfaces/kits/permission_lite",
|
||||
"//third_party/wpa_supplicant/wpa_supplicant-2.9/src/common",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-lwpa",
|
||||
"-lwpa_client",
|
||||
"-lsysparam",
|
||||
"-lpms_client",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ENABLE_WINDOW=1",
|
||||
"ABILITY_WINDOW_SUPPORT",
|
||||
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
|
||||
]
|
||||
}
|
||||
|
||||
hap_pack("setting_hap") {
|
||||
deps = [ ":setting" ]
|
||||
mode = "hap"
|
||||
json_path = "setting/src/main/config.json"
|
||||
ability_so_path = "$root_out_dir/libsetting.so"
|
||||
force = "true"
|
||||
cert_profile = "cert/com.huawei.setting_HarmonyAppProvision_release.p7b"
|
||||
resources_path = "setting/src/main/resources"
|
||||
hap_name = "setting"
|
||||
privatekey = "HOS Application Provision Release"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.huawei.setting",
|
||||
"vendor": "huawei",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 3,
|
||||
"target": 4
|
||||
}
|
||||
},
|
||||
"deviceConfig": {
|
||||
"default": {
|
||||
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"package": "com.huawei.setting",
|
||||
"name": ".MyHarmonyAbilityPackage",
|
||||
"deviceType": [
|
||||
"phone", "tv","tablet","car","smartWatch","sportsWatch","smartVision"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "setting",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [{
|
||||
"name": "SettingMainAbility",
|
||||
"icon": "assets/setting/resources/base/media/setting.png",
|
||||
"label": "test testapp2 1",
|
||||
"launchType": "standard",
|
||||
"type": "page",
|
||||
"visible":true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_ability_slice.h"
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(AppAbilitySlice)
|
||||
|
||||
AppAbilitySlice::~AppAbilitySlice()
|
||||
{
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
if (buttonAppInfoListener_) {
|
||||
delete buttonAppInfoListener_;
|
||||
buttonAppInfoListener_ = nullptr;
|
||||
}
|
||||
if (pBundleInfos_) {
|
||||
ClearBundleInfo(pBundleInfos_);
|
||||
}
|
||||
}
|
||||
|
||||
void AppAbilitySlice::SetButtonListener(void)
|
||||
{
|
||||
auto onClick1 = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("MainAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingWifiAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick1, nullptr);
|
||||
}
|
||||
|
||||
void AppAbilitySlice::SetAppButtonListener(const char* appName)
|
||||
{
|
||||
auto onClick2 = [this, appName](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
bool ret = SetWantData(&want1, appName, strlen(appName) + 1);
|
||||
if (ret != true) {
|
||||
return false;
|
||||
}
|
||||
StartAbility(want1);
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("AppInfoAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingWifiAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
ClearWant(&want1);
|
||||
return true;
|
||||
};
|
||||
buttonAppInfoListener_ = new EventListener(onClick2, nullptr);
|
||||
}
|
||||
|
||||
void AppAbilitySlice::SetHead()
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText("应用");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void AppAbilitySlice::SetAnAppInfo(const int count, BundleInfo& pBundleInfo)
|
||||
{
|
||||
UIViewGroup* itemView = new UIViewGroup();
|
||||
char buff[64] = {0};
|
||||
int useX = 0;
|
||||
int useY = count * DE_ITEM_INTERVAL;
|
||||
itemView->SetPosition(useX, useY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
itemView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
itemView->SetTouchable(true);
|
||||
|
||||
int err = strcpy_s(buff, sizeof(buff), pBundleInfo.bundleName);
|
||||
if (err != EOK) {
|
||||
printf("[ERROR]strcpy_s pBundleInfo.bundleName failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < strlen(pBundleInfo.bundleName); i++) {
|
||||
buff[i] = pBundleInfo.bundleName[i];
|
||||
}
|
||||
SetAppButtonListener(pBundleInfo.bundleName);
|
||||
itemView->SetOnClickListener(buttonAppInfoListener_);
|
||||
scrollView_->Add(itemView);
|
||||
|
||||
UIImageView* imageIdView = new UIImageView();
|
||||
imageIdView->SetPosition(APP_IMAGE_X, APP_IMAGE_Y, APP_IMAGE_WIDTH, APP_IMAGE_HEIGHT);
|
||||
imageIdView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
imageIdView->SetSrc(DE_IMAGE_APP);
|
||||
itemView->Add(imageIdView);
|
||||
|
||||
int bundleNameOffset = 11;
|
||||
UILabel* name = new UILabel();
|
||||
name->SetPosition(APP_NAME_X, APP_NAME_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
name->SetText(pBundleInfo.bundleName + bundleNameOffset);
|
||||
name->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
name->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
itemView->Add(name);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(DE_FORWARD_IMG_X, DE_FORWARD_IMG_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_FORWORD);
|
||||
itemView->Add(imageView);
|
||||
}
|
||||
|
||||
|
||||
void AppAbilitySlice::SetScrollView()
|
||||
{
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(true);
|
||||
rootView_->Add(scrollView_);
|
||||
|
||||
uint8_t ret = -1;
|
||||
int num = 0;
|
||||
ret = GetBundleInfos(1, &pBundleInfos_, &num);
|
||||
if (ret == 0) {
|
||||
BundleInfo* pBundleInfo = pBundleInfos_;
|
||||
for (int count = 0; count < num; count++, pBundleInfo++) {
|
||||
printf("[LOG]pBundleInfo.bundleName->%s versionName->%s \n",
|
||||
pBundleInfo->bundleName, pBundleInfo->versionName);
|
||||
if (pBundleInfo->isSystemApp == false) {
|
||||
SetAnAppInfo(count, *pBundleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnStart(want);
|
||||
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetButtonListener();
|
||||
SetHead();
|
||||
SetScrollView();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void AppAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void AppAbilitySlice::OnActive(const Want &want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void AppAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void AppAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APP_ABILITY_SLICE_H
|
||||
#define OHOS_APP_ABILITY_SLICE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_manager.h"
|
||||
#include "ability_slice.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "components/ui_image_view.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "element_name.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "module_info.h"
|
||||
#include "setting_utils.h"
|
||||
#include "want.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AppAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
AppAbilitySlice()
|
||||
: headView_(nullptr), scrollView_(nullptr), rootView_(nullptr), pBundleInfos_(nullptr),
|
||||
buttonBackListener_(nullptr), buttonAppInfoListener_(nullptr) {}
|
||||
virtual ~AppAbilitySlice();
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void SetButtonListener();
|
||||
void SetAppButtonListener(const char* appName);
|
||||
void SetHead();
|
||||
void SetScrollView();
|
||||
void SetAnAppInfo(int count, BundleInfo& pBundleInfo);
|
||||
UIViewGroup* headView_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
BundleInfo* pBundleInfos_;
|
||||
EventListener* buttonBackListener_;
|
||||
EventListener* buttonAppInfoListener_;
|
||||
|
||||
constexpr static int APP_IMAGE_X = 12;
|
||||
constexpr static int APP_IMAGE_Y = 12;
|
||||
constexpr static int APP_IMAGE_WIDTH = 64;
|
||||
constexpr static int APP_IMAGE_HEIGHT = 64;
|
||||
constexpr static int APP_NAME_X = 94;
|
||||
constexpr static int APP_NAME_Y = 28;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_info_ability_slice.h"
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(AppInfoAbilitySlice)
|
||||
|
||||
AppInfoAbilitySlice::~AppInfoAbilitySlice()
|
||||
{
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
|
||||
if (!buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (permissions_) {
|
||||
free(permissions_);
|
||||
}
|
||||
ListNode<ToggBtnOnListener*>* node = listListener_.Begin();
|
||||
while (node != listListener_.End()) {
|
||||
delete node->data_;
|
||||
node = node->next_;
|
||||
}
|
||||
listListener_.Clear();
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::SetButtonListener(void)
|
||||
{
|
||||
auto onClick = [this](UIView& view, const Event& event) -> bool {
|
||||
Terminate();
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick, nullptr);
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::SetHead()
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
printf("[LOG] bundleName_-> %s +11->%s \n", bundleName_, bundleName_ + 11); // 11
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText(bundleName_ + 11); // use 11
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::SetAppPermissionInfo(int index, PermissionSaved& permissions)
|
||||
{
|
||||
UIViewGroup* itemView = new UIViewGroup();
|
||||
int useX = 0;
|
||||
int useY = index * DE_ITEM_INTERVAL;
|
||||
itemView->SetPosition(useX, useY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
itemView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
scrollView_->Add(itemView);
|
||||
|
||||
UILabel* nameLabel = new UILabel();
|
||||
nameLabel->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
nameLabel->SetText(permissions.name + 16); // 16 is get offset name
|
||||
nameLabel->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
nameLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
|
||||
nameLabel->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
itemView->Add(nameLabel);
|
||||
UIToggleButton* togglebutton = new UIToggleButton();
|
||||
togglebutton->SetPosition(DE_TOGGLE_BUTTON_X, DE_TOGGLE_BUTTON_Y);
|
||||
if (permissions.granted == 0) {
|
||||
togglebutton->SetState(false);
|
||||
} else {
|
||||
togglebutton->SetState(true);
|
||||
}
|
||||
ToggBtnOnListener* listener = new ToggBtnOnListener(togglebutton);
|
||||
listener->SetPermissionName(permissions.name, strlen(permissions.name));
|
||||
listener->SetBundleName(bundleName_, strlen(bundleName_));
|
||||
togglebutton->SetOnClickListener(listener);
|
||||
listListener_.PushBack(listener);
|
||||
itemView->Add(togglebutton);
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::PermissionInfoList()
|
||||
{
|
||||
int permNum = 0;
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(true);
|
||||
rootView_->Add(scrollView_);
|
||||
int ret = QueryPermission(bundleName_, &permissions_, &permNum);
|
||||
if (ret == 0) {
|
||||
printf("[LOG]PermissionInfoList bundleName_ -> %s ,permNum->%d\n", bundleName_, permNum);
|
||||
for (int i = 0; i < permNum; i++) {
|
||||
if (permissions_ != nullptr) {
|
||||
printf("[LOG]PermissionInfoList xxx -> name %s \n", permissions_->name);
|
||||
SetAppPermissionInfo(i, permissions_[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
int ret;
|
||||
printf("[LOG]receive the data -> %s\n", static_cast<char*>(want.data));
|
||||
AbilitySlice::OnStart(want);
|
||||
|
||||
ret = memcpy_s(bundleName_, sizeof(bundleName_), want.data, want.dataLength);
|
||||
if (ret != EOK) {
|
||||
return;
|
||||
}
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetButtonListener();
|
||||
SetHead();
|
||||
PermissionInfoList();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::OnActive(const Want &want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void AppInfoAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APP_INFO_ABILITY_SLICE_H
|
||||
#define OHOS_APP_INFO_ABILITY_SLICE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_manager.h"
|
||||
#include "ability_slice.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "components/ui_image_view.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "element_name.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "module_info.h"
|
||||
#include "setting_utils.h"
|
||||
#include "want.h"
|
||||
#include "pms_interface.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <securec.h>
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
class ToggBtnOnListener : public UIView::OnClickListener {
|
||||
public:
|
||||
|
||||
explicit ToggBtnOnListener(UIToggleButton* togglebutton)
|
||||
{
|
||||
status_ = false;
|
||||
togglebutton_ = togglebutton;
|
||||
}
|
||||
|
||||
virtual ~ToggBtnOnListener(){}
|
||||
|
||||
void SetPermissionName(const char* permissionsName, int nameLength)
|
||||
{
|
||||
int ret;
|
||||
ret = memcpy_s(name_, sizeof(name_), permissionsName, nameLength);
|
||||
if (ret != EOK) {
|
||||
printf("[ERR] memcpy_s func[SetToggleButton]\n");
|
||||
return;
|
||||
}
|
||||
name_[nameLength] = 0;
|
||||
}
|
||||
|
||||
void SetBundleName(const char* bundleName, int nameLength)
|
||||
{
|
||||
int ret;
|
||||
ret = memcpy_s(bundleName_, sizeof(bundleName_), bundleName, nameLength);
|
||||
if (ret != EOK) {
|
||||
printf("[ERR] memcpy_s func[SetBundleName]\n");
|
||||
return;
|
||||
}
|
||||
bundleName_[nameLength] = 0;
|
||||
}
|
||||
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
int ret;
|
||||
if (status_) {
|
||||
ret = RevokePermission(bundleName_, name_);
|
||||
if (ret == 0) {
|
||||
status_ = false;
|
||||
togglebutton_->SetState(false);
|
||||
}
|
||||
} else {
|
||||
ret = GrantPermission(bundleName_, name_);
|
||||
if (ret == 0) {
|
||||
status_ = true;
|
||||
togglebutton_->SetState(true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
char name_[128] = {0};
|
||||
char bundleName_[128] = {0};
|
||||
bool status_ = false;
|
||||
UIToggleButton* togglebutton_ = nullptr;
|
||||
};
|
||||
|
||||
class AppInfoAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
AppInfoAbilitySlice()
|
||||
: headView_(nullptr), scrollView_(nullptr), rootView_(nullptr), permissions_(nullptr),
|
||||
buttonBackListener_(nullptr) {}
|
||||
virtual ~AppInfoAbilitySlice();
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
private:
|
||||
void SetAppButtonListener(const char* appName);
|
||||
void SetButtonListener(void);
|
||||
void SetHead(void);
|
||||
UIViewGroup* headView_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
PermissionSaved* permissions_;
|
||||
EventListener* buttonBackListener_;
|
||||
List<ToggBtnOnListener*> listListener_;
|
||||
|
||||
void PermissionInfoList();
|
||||
void SetAppPermissionInfo(int index, PermissionSaved& permissions);
|
||||
char bundleName_[128];
|
||||
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_EVENT_LISTENER_H
|
||||
#define OHOS_EVENT_LISTENER_H
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "components/ui_view.h"
|
||||
|
||||
namespace OHOS {
|
||||
using OnEventFunc = std::function<bool(UIView &view, const Event &event)>;
|
||||
|
||||
class EventListener : public UIView::OnClickListener, public UIView::OnLongPressListener {
|
||||
public:
|
||||
EventListener() = delete;
|
||||
~EventListener() override = default;
|
||||
|
||||
EventListener(OnEventFunc onClick, OnEventFunc onLongPress)
|
||||
{
|
||||
onClick_ = std::move(onClick);
|
||||
onLongPress_ = std::move(onLongPress);
|
||||
}
|
||||
|
||||
bool OnClick(UIView& view, const ClickEvent &event) override
|
||||
{
|
||||
if (!onClick_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onClick_(*currentView, event);
|
||||
}
|
||||
|
||||
bool OnLongPress(UIView& view, const LongPressEvent &event) override
|
||||
{
|
||||
if (!onLongPress_) {
|
||||
return false;
|
||||
}
|
||||
UIView *currentView = &view;
|
||||
if (currentView == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return onLongPress_(*currentView, event);
|
||||
}
|
||||
|
||||
private:
|
||||
OnEventFunc onClick_ {};
|
||||
OnEventFunc onLongPress_ {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "main_ability_slice.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_slice.h"
|
||||
#include "ability_info.h"
|
||||
#include "ability_manager.h"
|
||||
#include "event_listener.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "module_info.h"
|
||||
#include "element_name.h"
|
||||
#include "wpa_work.h"
|
||||
#include "gfx_utils/style.h"
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(MainAbilitySlice)
|
||||
|
||||
MainAbilitySlice::~MainAbilitySlice()
|
||||
{
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonWifiListener_) {
|
||||
delete buttonWifiListener_;
|
||||
buttonWifiListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonDisplayListener_) {
|
||||
delete buttonDisplayListener_;
|
||||
buttonDisplayListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonAppListener_) {
|
||||
delete buttonAppListener_;
|
||||
buttonAppListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonAboutListener_) {
|
||||
delete buttonAboutListener_;
|
||||
buttonAboutListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetButtonListenerWifi(void)
|
||||
{
|
||||
auto onClick1 = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("SettingWifiAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingWifiAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonWifiListener_ = new EventListener(onClick1, nullptr);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetButtonListenerApp(void)
|
||||
{
|
||||
auto onClick2 = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("AppAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined AppInfoAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonAppListener_ = new EventListener(onClick2, nullptr);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetButtonListenerDisplay(void)
|
||||
{
|
||||
auto onClick3 = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("SettingDisplayAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingDisplayAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonDisplayListener_ = new EventListener(onClick3, nullptr);
|
||||
}
|
||||
|
||||
|
||||
void MainAbilitySlice::SetButtonListenerAbout(void)
|
||||
{
|
||||
auto onClick4 = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("SettingAboutAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingAboutAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonAboutListener_ = new EventListener(onClick4, nullptr);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetHead(void)
|
||||
{
|
||||
auto toLauncher = [this] (UIView &view, const Event &event) -> bool {
|
||||
TerminateAbility();
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(toLauncher, nullptr);
|
||||
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText("设置");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetWifiButtonView(void)
|
||||
{
|
||||
UIViewGroup* buttonView = new UIViewGroup();
|
||||
buttonView->SetPosition(WIFI_BUTTON_X, WIFI_BUTTON_Y, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
buttonView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
buttonView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
buttonView->SetTouchable(true);
|
||||
buttonView->SetOnClickListener(buttonWifiListener_);
|
||||
scrollView_->Add(buttonView);
|
||||
|
||||
UILabel* lablelFontWifi = new UILabel();
|
||||
lablelFontWifi->SetPosition(DE_TITLE_TEXT_X, WIFI_BUTTON_TEXT_WIFI_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFontWifi->SetText("WiFi");
|
||||
lablelFontWifi->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFontWifi->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFontWifi);
|
||||
|
||||
char buff[64] = {0};
|
||||
int myX = WIFI_BUTTON_TEXT_SSID_X;
|
||||
int myY = WIFI_BUTTON_TEXT_SSID_Y;
|
||||
int ret = GetCurrentConnInfo(buff, sizeof(buff));
|
||||
lablelFontSsid_ = new UILabel();
|
||||
lablelFontSsid_->SetPosition(myX, myY, DE_SUBTITLE_TEXT_WIDTH, DE_SUBTITLE_TEXT_HEIGHT);
|
||||
if (ret == 0) {
|
||||
lablelFontSsid_->SetText(buff);
|
||||
} else {
|
||||
lablelFontSsid_->SetText("未连接");
|
||||
}
|
||||
|
||||
lablelFontSsid_->SetFont(DE_FONT_OTF, DE_SUBTITLE_TEXT_SIZE);
|
||||
lablelFontSsid_->SetStyle(STYLE_TEXT_COLOR, DE_SUBTITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFontSsid_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(DE_FORWARD_IMG_X, DE_FORWARD_IMG_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_FORWORD);
|
||||
buttonView->Add(imageView);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetAppButtonView(void)
|
||||
{
|
||||
UIViewGroup* buttonView = new UIViewGroup();
|
||||
buttonView->SetPosition(APP_BUTTON_X, APP_BUTTON_Y, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
buttonView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
buttonView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
buttonView->SetTouchable(true);
|
||||
buttonView->SetOnClickListener(buttonAppListener_);
|
||||
scrollView_->Add(buttonView);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText("应用");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFont);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(DE_FORWARD_IMG_X, DE_FORWARD_IMG_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_FORWORD);
|
||||
buttonView->Add(imageView);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetDisplayButtonView(void)
|
||||
{
|
||||
UIViewGroup* buttonView = new UIViewGroup();
|
||||
buttonView->SetPosition(DISPALY_BUTTON_X, DISPALY_BUTTON_Y, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
buttonView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
buttonView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
buttonView->SetTouchable(true);
|
||||
buttonView->SetOnClickListener(buttonDisplayListener_);
|
||||
scrollView_->Add(buttonView);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText("显示");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFont);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(DE_FORWARD_IMG_X, DE_FORWARD_IMG_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_FORWORD);
|
||||
buttonView->Add(imageView);
|
||||
}
|
||||
|
||||
static void setAboutTest(UIViewGroup *buttonView, int positionX, int positionY, const char *setText)
|
||||
{
|
||||
UILabel* lablelFontSystem = new UILabel();
|
||||
lablelFontSystem->SetPosition(positionX, positionY, DE_SUBTITLE_TEXT_WIDTH, DE_SUBTITLE_TEXT_HEIGHT);
|
||||
lablelFontSystem->SetText(setText);
|
||||
lablelFontSystem->SetFont(DE_FONT_OTF, DE_SUBTITLE_TEXT_SIZE);
|
||||
lablelFontSystem->SetStyle(STYLE_TEXT_COLOR, DE_SUBTITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFontSystem);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetAboutButtonView(void)
|
||||
{
|
||||
UIViewGroup* buttonView = new UIViewGroup();
|
||||
buttonView->SetPosition(ABOUT_BUTTON_X, ABOUT_BUTTON_Y, DE_BUTTON_WIDTH, ABOUT_BUTTON_HEIGHT);
|
||||
buttonView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
buttonView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
buttonView->SetTouchable(true);
|
||||
buttonView->SetOnClickListener(buttonAboutListener_);
|
||||
scrollView_->Add(buttonView);
|
||||
|
||||
UILabel* lablelFontAbout = new UILabel();
|
||||
lablelFontAbout->SetPosition(DE_TITLE_TEXT_X, ABOUT_BUTTON_TEXT_ABOUT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFontAbout->SetText("关于");
|
||||
lablelFontAbout->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFontAbout->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
buttonView->Add(lablelFontAbout);
|
||||
|
||||
char buff[62];
|
||||
const char* gDV = GetDisplayVersion();
|
||||
int err = sprintf_s(buff, sizeof(buff), "系统版本: %s", gDV);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
gDV = nullptr;
|
||||
return;
|
||||
}
|
||||
setAboutTest(buttonView, ABOUT_BUTTON_TEXT_SYSTEM_X, ABOUT_BUTTON_TEXT_SYSTEM_Y, buff);
|
||||
|
||||
err = memset_s(buff, sizeof(buff), 0, sizeof(buff));
|
||||
if (err < EOK) {
|
||||
printf("[ERROR]memset_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
const char* gPT = GetDeviceType();
|
||||
err = sprintf_s(buff, sizeof(buff), "设备名称: %s", gPT);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
gPT = nullptr;
|
||||
return;
|
||||
}
|
||||
setAboutTest(buttonView, ABOUT_BUTTON_TEXT_DEVICE_X, ABOUT_BUTTON_TEXT_DEVICE_Y, buff);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(DE_FORWARD_IMG_X, ABOUT_BUTTON_IMAGE_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_FORWORD);
|
||||
buttonView->Add(imageView);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::SetScrollView()
|
||||
{
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(false);
|
||||
rootView_->Add(scrollView_);
|
||||
SetWifiButtonView();
|
||||
SetAppButtonView();
|
||||
SetDisplayButtonView();
|
||||
SetAboutButtonView();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnStart(want);
|
||||
SetButtonListenerWifi();
|
||||
SetButtonListenerApp();
|
||||
SetButtonListenerDisplay();
|
||||
SetButtonListenerAbout();
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
|
||||
SetHead();
|
||||
SetScrollView();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
char buff[64] = {0};
|
||||
int ret = GetCurrentConnInfo(buff, sizeof(buff));
|
||||
if (ret == 0) {
|
||||
printf("##### SetText -> %s \n", buff);
|
||||
lablelFontSsid_->SetText(buff);
|
||||
} else {
|
||||
lablelFontSsid_->SetText("未连接");
|
||||
}
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void MainAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_MAIN_ABILITY_SLICE_H
|
||||
#define OHOS_MAIN_ABILITY_SLICE_H
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_manager.h"
|
||||
#include "ability_slice.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "components/ui_image_view.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "element_name.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "module_info.h"
|
||||
#include "parameter.h"
|
||||
#include "pthread.h"
|
||||
#include "setting_utils.h"
|
||||
#include "want.h"
|
||||
#include "wpa_work.h"
|
||||
|
||||
namespace OHOS {
|
||||
class MainAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
MainAbilitySlice()
|
||||
: headView_(nullptr), scrollView_(nullptr), rootView_(nullptr), lablelFontSsid_(nullptr),
|
||||
buttonWifiListener_(nullptr), buttonAppListener_(nullptr), buttonDisplayListener_(nullptr),
|
||||
buttonAboutListener_(nullptr), buttonBackListener_(nullptr) {}
|
||||
virtual ~MainAbilitySlice();
|
||||
|
||||
protected:
|
||||
void OnStart(const Want &want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want &want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void SetButtonListenerWifi();
|
||||
void SetButtonListenerApp();
|
||||
void SetButtonListenerDisplay();
|
||||
void SetButtonListenerAbout();
|
||||
void SetAboutButtonView();
|
||||
void SetAppButtonView();
|
||||
void SetDisplayButtonView();
|
||||
void SetWifiButtonView();
|
||||
void SetScrollView();
|
||||
void SetHead();
|
||||
|
||||
UIViewGroup* headView_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
UILabel* lablelFontSsid_;
|
||||
EventListener* buttonWifiListener_;
|
||||
EventListener* buttonAppListener_;
|
||||
EventListener* buttonDisplayListener_;
|
||||
EventListener* buttonAboutListener_;
|
||||
EventListener* buttonBackListener_;
|
||||
|
||||
constexpr static int WIFI_BUTTON_X = 0;
|
||||
constexpr static int WIFI_BUTTON_Y = 0;
|
||||
constexpr static int WIFI_BUTTON_TEXT_WIFI_Y = 13;
|
||||
constexpr static int WIFI_BUTTON_TEXT_SSID_X = 18;
|
||||
constexpr static int WIFI_BUTTON_TEXT_SSID_Y = 45;
|
||||
|
||||
constexpr static int APP_BUTTON_X = 0;
|
||||
constexpr static int APP_BUTTON_Y = 95;
|
||||
|
||||
constexpr static int DISPALY_BUTTON_X = 0;
|
||||
constexpr static int DISPALY_BUTTON_Y = 190;
|
||||
|
||||
constexpr static int ABOUT_BUTTON_X = 0;
|
||||
constexpr static int ABOUT_BUTTON_Y = 190 + DE_BUTTON_HEIGHT + 6;
|
||||
constexpr static int ABOUT_BUTTON_HEIGHT = 113;
|
||||
constexpr static int ABOUT_BUTTON_TEXT_ABOUT_Y = 5;
|
||||
constexpr static int ABOUT_BUTTON_TEXT_SYSTEM_X = 18;
|
||||
constexpr static int ABOUT_BUTTON_TEXT_SYSTEM_Y = 39;
|
||||
constexpr static int ABOUT_BUTTON_TEXT_DEVICE_X = 18;
|
||||
constexpr static int ABOUT_BUTTON_TEXT_DEVICE_Y = 72;
|
||||
constexpr static int ABOUT_BUTTON_IMAGE_Y = 34;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OHOS_MAIN_ABILITY_SLICE_H
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "setting_about_ability_slice.h"
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(SettingAboutAbilitySlice)
|
||||
|
||||
SettingAboutAbilitySlice::~SettingAboutAbilitySlice()
|
||||
{
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
for (int count = 0; count < SCROLL_ITEM_NUM; count++) {
|
||||
if (!itemInfo_[count][1]) {
|
||||
itemInfo_[count][1] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::SetButtonListener()
|
||||
{
|
||||
auto onClick = [this](UIView& view, const Event& event) -> bool {
|
||||
Terminate();
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick, nullptr);
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::SetItemInfo()
|
||||
{
|
||||
itemInfo_[0][0] = (char*) "设备名称"; // 0
|
||||
itemInfo_[0][1] = GetDeviceType(); // 0
|
||||
itemInfo_[1][0] = (char*) "厂家信息"; // 1
|
||||
itemInfo_[1][1] = GetManufacture(); // 1
|
||||
itemInfo_[2][0] = (char*) "品牌信息"; // 2
|
||||
itemInfo_[2][1] = GetBrand(); // 2
|
||||
itemInfo_[3][0] = (char*) "硬件版本号"; // 3
|
||||
itemInfo_[3][1] = GetHardwareModel(); // 3
|
||||
itemInfo_[4][0] = (char*) "设备序列号"; // 4
|
||||
itemInfo_[4][1] = GetSerial(); // 4
|
||||
itemInfo_[5][0] = (char*) "操作系统名"; // 5
|
||||
itemInfo_[5][1] = GetOSFullName(); // 5
|
||||
itemInfo_[6][0] = (char*) "软件版本号"; // 6
|
||||
itemInfo_[6][1] = GetDisplayVersion(); // 6
|
||||
itemInfo_[7][0] = (char*) "BootLoader版本号"; // 7
|
||||
itemInfo_[7][1] = GetBootloaderVersion(); // 7
|
||||
itemInfo_[8][0] = (char*) "构建时间"; // 8
|
||||
itemInfo_[8][1] = GetBuildTime(); // 8
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::SetHead()
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText("关于");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::SetScrollItem(int count)
|
||||
{
|
||||
int myPositonY = count * DE_ITEM_INTERVAL;
|
||||
|
||||
UIViewGroup* itemView = new UIViewGroup();
|
||||
itemView->SetPosition(ITEM_X, myPositonY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
scrollView_->Add(itemView);
|
||||
|
||||
UILabel* lablelFontName = new UILabel();
|
||||
lablelFontName->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFontName->SetText(itemInfo_[count][0]);
|
||||
lablelFontName->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFontName->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
itemView->Add(lablelFontName);
|
||||
|
||||
UILabel* lablelFontInfo = new UILabel();
|
||||
lablelFontInfo->SetPosition(ITEM_INFO_X, ITEM_INFO_Y, DE_SUBTITLE_TEXT_WIDTH, DE_SUBTITLE_TEXT_HEIGHT);
|
||||
lablelFontInfo->SetText(itemInfo_[count][1]);
|
||||
lablelFontInfo->SetFont(DE_FONT_OTF, DE_SUBTITLE_TEXT_SIZE);
|
||||
lablelFontInfo->SetAlign(TEXT_ALIGNMENT_RIGHT);
|
||||
lablelFontInfo->SetStyle(STYLE_TEXT_COLOR, DE_SUBTITLE_TEXT_COLOR);
|
||||
itemView->Add(lablelFontInfo);
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::SetScroll()
|
||||
{
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(true);
|
||||
rootView_->Add(scrollView_);
|
||||
for (int count = 0; count < SCROLL_ITEM_NUM; count++) {
|
||||
SetScrollItem(count);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnStart(want);
|
||||
SetButtonListener();
|
||||
SetItemInfo();
|
||||
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetHead();
|
||||
SetScroll();
|
||||
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void SettingAboutAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SETTING_ABOUT_ABILITY_SLICE_H
|
||||
#define OHOS_SETTING_ABOUT_ABILITY_SLICE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_slice.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "components/ui_image_view.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "element_name.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "module_info.h"
|
||||
#include "parameter.h"
|
||||
#include "setting_utils.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class SettingAboutAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
SettingAboutAbilitySlice()
|
||||
: headView_(nullptr), scrollView_(nullptr), rootView_(nullptr), buttonBackListener_(nullptr) {}
|
||||
virtual ~SettingAboutAbilitySlice();
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
private:
|
||||
void SetItemInfo();
|
||||
void SetButtonListener();
|
||||
void SetScrollItem(int count);
|
||||
void SetScroll();
|
||||
void SetHead();
|
||||
|
||||
UIViewGroup* headView_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
EventListener *buttonBackListener_;
|
||||
constexpr static int SCROLL_ITEM_NUM = 9;
|
||||
const char *itemInfo_[SCROLL_ITEM_NUM][2];
|
||||
constexpr static int ITEM_X = 0;
|
||||
constexpr static int ITEM_INFO_X = 385;
|
||||
constexpr static int ITEM_INFO_Y = 36;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "setting_display_ability_slice.h"
|
||||
#include <iostream>
|
||||
#include <power_screen_saver.h>
|
||||
#include <securec.h>
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(SettingDisplayAbilitySlice)
|
||||
|
||||
#define COM_SET_ON 0
|
||||
#define COM_SET_OFF 1
|
||||
#define COM_GET_STATUS 2
|
||||
|
||||
SettingDisplayAbilitySlice::~SettingDisplayAbilitySlice()
|
||||
{
|
||||
if (toggleButtonView_) {
|
||||
DeleteChildren(toggleButtonView_);
|
||||
toggleButtonView_ = nullptr;
|
||||
}
|
||||
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
|
||||
if (changeListener_) {
|
||||
delete changeListener_;
|
||||
changeListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::SetButtonListener(void)
|
||||
{
|
||||
auto onClick = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("MainAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined MainAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick, nullptr);
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::SetHead(void)
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText("显示");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::SetToggleButton(void)
|
||||
{
|
||||
toggleButtonView_ = new UIViewGroup();
|
||||
toggleButtonView_->SetPosition(TOGGLE_X, TOGGLE_Y, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
toggleButtonView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
toggleButtonView_->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
toggleButtonView_->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
rootView_->Add(toggleButtonView_);
|
||||
|
||||
auto lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText("屏保");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
toggleButtonView_->Add(lablelFont);
|
||||
|
||||
SetScreenSaverState(TRUE);
|
||||
UIToggleButton* togglebutton = new UIToggleButton();
|
||||
togglebutton->SetState(true);
|
||||
changeListener_ = new DisBtnOnStateChangeListener(togglebutton);
|
||||
togglebutton->SetOnClickListener(changeListener_);
|
||||
togglebutton->SetPosition(DE_TOGGLE_BUTTON_X, DE_TOGGLE_BUTTON_Y);
|
||||
toggleButtonView_->Add(togglebutton);
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnStart(want);
|
||||
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetButtonListener();
|
||||
SetHead();
|
||||
SetToggleButton();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void SettingDisplayAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SETTING_DISPLAY_ABILITY_SLICE_H
|
||||
#define OHOS_SETTING_DISPLAY_ABILITY_SLICE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iproxy_client.h>
|
||||
#include <power_screen_saver.h>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "parameter.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "setting_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
class DisBtnOnStateChangeListener : public OHOS::UICheckBox::OnChangeListener, public OHOS::UIView::OnClickListener {
|
||||
public:
|
||||
~DisBtnOnStateChangeListener() {}
|
||||
explicit DisBtnOnStateChangeListener(UIToggleButton* togglebutton) : myTogglebutton(togglebutton) {}
|
||||
|
||||
bool OnChange(UICheckBox::UICheckBoxState state) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
bool status = myTogglebutton->GetState();
|
||||
SetScreenSaverState(status ? TRUE : FALSE);
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
UIToggleButton* myTogglebutton;
|
||||
};
|
||||
|
||||
class SettingDisplayAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
SettingDisplayAbilitySlice()
|
||||
: headView_(nullptr), toggleButtonView_(nullptr), rootView_(nullptr),
|
||||
buttonBackListener_(nullptr), changeListener_(nullptr) {}
|
||||
|
||||
virtual ~SettingDisplayAbilitySlice();
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void SetButtonListener();
|
||||
void SetHead();
|
||||
void SetToggleButton();
|
||||
|
||||
UIViewGroup* headView_;
|
||||
UIViewGroup* toggleButtonView_;
|
||||
RootView* rootView_;
|
||||
EventListener* buttonBackListener_;
|
||||
DisBtnOnStateChangeListener* changeListener_;
|
||||
constexpr static int TOGGLE_X = 36;
|
||||
constexpr static int TOGGLE_Y = 72;
|
||||
|
||||
constexpr static int USE_WIFI_FONT_X = 54;
|
||||
constexpr static int USE_WIFI_FONT_Y = 187;
|
||||
|
||||
constexpr static int ADD_WIFI_X = 0;
|
||||
constexpr static int SCROLL_WIFI_X = 36;
|
||||
constexpr static int SCROLL_WIFI_Y = 242;
|
||||
constexpr static int SCROLL_WIFI_WIDTH = 800;
|
||||
constexpr static int SCROLL_WIFI_HEIGHT = 238;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "setting_main_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AA(SettingMainAbility)
|
||||
|
||||
void SettingMainAbility::OnStart(const Want& want)
|
||||
{
|
||||
SetMainRoute("MainAbilitySlice");
|
||||
Ability::OnStart(want);
|
||||
}
|
||||
|
||||
void SettingMainAbility::OnInactive()
|
||||
{
|
||||
Ability::OnInactive();
|
||||
}
|
||||
|
||||
void SettingMainAbility::OnActive(const Want& want)
|
||||
{
|
||||
Ability::OnActive(want);
|
||||
}
|
||||
|
||||
void SettingMainAbility::OnBackground()
|
||||
{
|
||||
Ability::OnBackground();
|
||||
}
|
||||
|
||||
void SettingMainAbility::OnStop()
|
||||
{
|
||||
|
||||
Ability::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_MAIN_ABILITY_H
|
||||
#define OHOS_MAIN_ABILITY_H
|
||||
|
||||
#include "ability_loader.h"
|
||||
|
||||
namespace OHOS {
|
||||
class SettingMainAbility : public Ability {
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "setting_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
void DeleteChildren(UIView *view)
|
||||
{
|
||||
if (view == nullptr) {
|
||||
return;
|
||||
}
|
||||
while (view != nullptr) {
|
||||
UIView *tempView = view;
|
||||
view = view->GetNextSibling();
|
||||
if (tempView->IsViewGroup()) {
|
||||
DeleteChildren(static_cast<UIViewGroup *>(tempView)->GetChildrenHead());
|
||||
}
|
||||
if (tempView->GetParent()) {
|
||||
static_cast<UIViewGroup *>(tempView->GetParent())->Remove(tempView);
|
||||
}
|
||||
delete tempView;
|
||||
tempView = nullptr;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SETTING_UTILS_H
|
||||
#define OHOS_SETTING_UTILS_H
|
||||
|
||||
#include "components/ui_view_group.h"
|
||||
|
||||
namespace OHOS {
|
||||
#define DE_IMAGE_BACK "/storage/app/run/com.huawei.setting/setting/assets/setting/resources/base/media/back.png"
|
||||
#define DE_IMAGE_FORWORD \
|
||||
"/storage/app/run/com.huawei.setting/setting/assets/setting/resources/base/media/forward.png"
|
||||
#define DE_IMAGE_ENTER "/storage/app/run/com.huawei.setting/setting/assets/setting/resources/base/media/enter.png"
|
||||
#define DE_IMAGE_APP "/storage/app/run/com.huawei.setting/setting/assets/setting/resources/base/media/app.png"
|
||||
#define DE_FONT_OTF "SourceHanSansSC-Regular.otf"
|
||||
|
||||
#define DE_ROOT_X 0
|
||||
#define DE_ROOT_Y 0
|
||||
#define DE_ROOT_WIDTH 800
|
||||
#define DE_ROOT_HEIGHT 480
|
||||
#define DE_ROOT_BACKGROUND_COLOR Color::ColorTo32(Color::Black())
|
||||
|
||||
#define DE_SCROLL_X 36
|
||||
#define DE_SCROLL_Y 72
|
||||
#define DE_SCROLL_WIDTH 737
|
||||
#define DE_SCROLL_HEIGHT 408
|
||||
#define DE_SCROLL_COLOR Color::ColorTo32(Color::Black())
|
||||
|
||||
#define DE_HEAD_X 0
|
||||
#define DE_HEAD_Y 0
|
||||
#define DE_HEAD_WIDTH 249
|
||||
#define DE_HEAD_HEIGHT 72
|
||||
|
||||
#define DE_HEAD_IMAGE_X 39
|
||||
#define DE_HEAD_IMAGE_Y 16
|
||||
#define DE_HEAD_IMAGE_WIDTH 30
|
||||
#define DE_HEAD_IMAGE_HEIGHT 30
|
||||
|
||||
#define DE_HEAD_TEXT_X 100
|
||||
#define DE_HEAD_TEXT_Y 15
|
||||
#define DE_HEAD_TEXT_WIDTH 180
|
||||
#define DE_HEAD_TEXT_HEIGHT 60
|
||||
#define DE_HEAD_TEXT_SIZE 32
|
||||
#define DE_HEAD_TEXT_COLOR Color::ColorTo32(Color::White())
|
||||
|
||||
#define DE_BUTTON_WIDTH 737
|
||||
#define DE_BUTTON_HEIGHT 89
|
||||
#define DE_BUTTON_BACKGROUND_COLOR Color::ColorTo32(Color::GetColorFromRGB(0x33, 0x33, 0x33))
|
||||
#define DE_BUTTON_RADIUS 16
|
||||
|
||||
#define DE_TITLE_TEXT_X 18
|
||||
#define DE_TITLE_TEXT_Y 28
|
||||
#define DE_TITLE_TEXT_WIDTH 332
|
||||
#define DE_TITLE_TEXT_HEIGHT 50
|
||||
#define DE_TITLE_TEXT_SIZE 26
|
||||
#define DE_TITLE_TEXT_COLOR Color::ColorTo32(Color::White())
|
||||
|
||||
#define DE_SUBTITLE_TEXT_WIDTH 332
|
||||
#define DE_SUBTITLE_TEXT_HEIGHT 40
|
||||
#define DE_SUBTITLE_TEXT_COLOR Color::ColorTo32(Color::GetColorFromRGB(0x9F, 0x9F, 0x9F))
|
||||
#define DE_SUBTITLE_TEXT_SIZE 24
|
||||
|
||||
#define DE_FORWARD_IMG_X 709
|
||||
#define DE_FORWARD_IMG_Y 24
|
||||
#define DE_FORWARD_IMG_WIDTH 12
|
||||
#define DE_FORWARD_IMG_HEIGHT 12
|
||||
|
||||
#define DE_TOGGLE_BUTTON_X 677
|
||||
#define DE_TOGGLE_BUTTON_Y 14
|
||||
|
||||
#define DE_ITEM_INTERVAL 95
|
||||
#define DE_CONTENT_FONT_SIZE 28
|
||||
#define DE_OPACITY_ALL 255
|
||||
|
||||
void DeleteChildren(UIView *view);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "setting_wifi_ability_slice.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(SettingWifiAbilitySlice)
|
||||
static int g_wifiStatus = 0;
|
||||
|
||||
SettingWifiAbilitySlice::SettingWifiAbilitySlice()
|
||||
: headView_(nullptr), toggleButtonView_(nullptr), scrollView_(nullptr), rootView_(nullptr),
|
||||
changeListener_(nullptr), buttonBackListener_(nullptr), buttonInputListener_(nullptr), wpaCount_(0)
|
||||
{
|
||||
int taskPeriod = 5000;
|
||||
Task::Init();
|
||||
SetPeriod(taskPeriod);
|
||||
}
|
||||
|
||||
SettingWifiAbilitySlice::~SettingWifiAbilitySlice()
|
||||
{
|
||||
if (wpaCount_ == 1) {
|
||||
printf("%s:%d call ExitWpa, this %p\n", __FUNCTION__, __LINE__, this);
|
||||
ExitWpa();
|
||||
ExitWpaScan();
|
||||
wpaCount_ = 0;
|
||||
}
|
||||
|
||||
if (toggleButtonView_) {
|
||||
DeleteChildren(toggleButtonView_);
|
||||
toggleButtonView_ = nullptr;
|
||||
}
|
||||
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
}
|
||||
|
||||
if (changeListener_) {
|
||||
delete changeListener_;
|
||||
changeListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
|
||||
if (buttonInputListener_) {
|
||||
delete buttonInputListener_;
|
||||
buttonInputListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetButtonListener(void)
|
||||
{
|
||||
auto onClick = [this](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("MainAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingWifiAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick, nullptr);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetWifiButtonListener(char* ssid)
|
||||
{
|
||||
auto onClick2 = [this, ssid](UIView& view, const Event& event) -> bool {
|
||||
Want want1 = { nullptr };
|
||||
bool ret = SetWantData(&want1, ssid, strlen(ssid) + 1);
|
||||
if (ret != true) {
|
||||
return false;
|
||||
}
|
||||
StartAbility(want1);
|
||||
AbilitySlice* nextSlice =
|
||||
AbilityLoader::GetInstance().GetAbilitySliceByName("SettingWifiInputPasswordAbilitySlice");
|
||||
if (nextSlice == nullptr) {
|
||||
printf("[warning]undefined SettingWifiAbilitySlice\n");
|
||||
} else {
|
||||
Present(*nextSlice, want1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
buttonInputListener_ = new EventListener(onClick2, nullptr);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetHead(void)
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText("WiFi");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetToggleButton(void)
|
||||
{
|
||||
toggleButtonView_ = new UIViewGroup();
|
||||
toggleButtonView_->SetPosition(TOGGLE_X, TOGGLE_Y, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
toggleButtonView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
toggleButtonView_->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
toggleButtonView_->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
rootView_->Add(toggleButtonView_);
|
||||
|
||||
auto lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText("WiFi");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
toggleButtonView_->Add(lablelFont);
|
||||
|
||||
UIToggleButton* togglebutton = new UIToggleButton();
|
||||
changeListener_ = new TestBtnOnStateChangeListener(reinterpret_cast<UIView*>(scrollView_));
|
||||
togglebutton->SetOnClickListener(changeListener_);
|
||||
togglebutton->SetPosition(DE_TOGGLE_BUTTON_X, DE_TOGGLE_BUTTON_Y);
|
||||
togglebutton->SetState(true);
|
||||
scrollView_->SetVisible(true);
|
||||
|
||||
toggleButtonView_->Add(togglebutton);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetUseWifi(void)
|
||||
{
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(USE_WIFI_FONT_X, USE_WIFI_FONT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText("可用WiFi列表");
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_SUBTITLE_TEXT_COLOR);
|
||||
rootView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::AddWifi(void)
|
||||
{
|
||||
int ssidIndex, ssidCount;
|
||||
|
||||
ssidCount = GetIdNum();
|
||||
if (ssidCount == 0) {
|
||||
printf("[LOG]SettingWifiAbilitySlice::AddWifi ssidCount == 0 \n");
|
||||
return;
|
||||
}
|
||||
if (scrollView_ == nullptr) {
|
||||
printf("[LOG]SettingWifiAbilitySlice::AddWifi scrollView_ == nullptr \n");
|
||||
return;
|
||||
}
|
||||
if (g_wifiStatus == 1) {
|
||||
printf("[LOG]SettingWifiAbilitySlice::AddWifi wifiStatus == 1 \n");
|
||||
return;
|
||||
}
|
||||
for (ssidIndex = 0; ssidIndex < ssidCount; ssidIndex++) {
|
||||
UIViewGroup *useWifiView = new UIViewGroup();
|
||||
useWifiView->SetPosition(ADD_WIFI_X, DE_ITEM_INTERVAL * ssidIndex, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
|
||||
useWifiView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
useWifiView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
useWifiView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
useWifiView->SetTouchable(true);
|
||||
char* buff = GetSsid(ssidIndex); // GetSsid need return point
|
||||
SetWifiButtonListener(buff);
|
||||
useWifiView->SetOnClickListener(buttonInputListener_);
|
||||
scrollView_->Add(useWifiView);
|
||||
|
||||
auto lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
|
||||
lablelFont->SetText(buff);
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
useWifiView->Add(lablelFont);
|
||||
g_wifiStatus = 1;
|
||||
}
|
||||
|
||||
scrollView_->Invalidate();
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::SetScrollWifi(void)
|
||||
{
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetPosition(DE_SCROLL_X, SCROLL_WIFI_Y, DE_SCROLL_WIDTH, SCROLL_WIFI_HEIGHT);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(true);
|
||||
rootView_->Add(scrollView_);
|
||||
g_wifiStatus = 0;
|
||||
AddWifi();
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::Callback()
|
||||
{
|
||||
if (GetAndResetScanStat() == 1) {
|
||||
LockWifiData();
|
||||
AddWifi();
|
||||
UnLockWifiData();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
if (wpaCount_ == 0) {
|
||||
printf("%s:%d call WpaClientStart, this %p\n", __FUNCTION__, __LINE__, this);
|
||||
WpaClientStart();
|
||||
WpaScanReconnect(nullptr, nullptr, HIDDEN_CLOSE);
|
||||
wpaCount_ = 1;
|
||||
}
|
||||
AbilitySlice::OnStart(want);
|
||||
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetButtonListener();
|
||||
SetHead();
|
||||
SetUseWifi();
|
||||
SetScrollWifi();
|
||||
SetToggleButton();
|
||||
|
||||
TaskExecute();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void SettingWifiAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
if (wpaCount_ == 1) {
|
||||
printf("%s:%d call ExitWpa, this %p\n", __FUNCTION__, __LINE__, this);
|
||||
ExitWpa();
|
||||
ExitWpaScan();
|
||||
wpaCount_ = 0;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SETTING_WIFI_ABILITY_SLICE_H
|
||||
#define OHOS_SETTING_WIFI_ABILITY_SLICE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "common/task.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_toggle_button.h"
|
||||
#include "event_listener.h"
|
||||
#include "gfx_utils/list.h"
|
||||
#include "parameter.h"
|
||||
#include "pthread.h"
|
||||
#include "setting_utils.h"
|
||||
#include "wpa_work.h"
|
||||
|
||||
namespace OHOS {
|
||||
class TestBtnOnStateChangeListener : public OHOS::UICheckBox::OnChangeListener, public OHOS::UIView::OnClickListener {
|
||||
public:
|
||||
~TestBtnOnStateChangeListener() {}
|
||||
explicit TestBtnOnStateChangeListener(UIView* uiView) : myUiView(uiView) {}
|
||||
|
||||
bool OnChange(UICheckBox::UICheckBoxState state) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
bool ret = myUiView->IsVisible();
|
||||
if (ret == false) {
|
||||
myUiView->SetVisible(true);
|
||||
} else {
|
||||
myUiView->SetVisible(false);
|
||||
}
|
||||
myUiView->Invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
UIView* myUiView;
|
||||
};
|
||||
|
||||
class SettingWifiAbilitySlice : public AbilitySlice, Task {
|
||||
public:
|
||||
SettingWifiAbilitySlice();
|
||||
virtual ~SettingWifiAbilitySlice();
|
||||
void AddWifi(void);
|
||||
void Callback() override;
|
||||
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void MyThread();
|
||||
void SetWifiButtonListener(char* ssid);
|
||||
void SetButtonListener();
|
||||
void SetHead();
|
||||
void SetToggleButton();
|
||||
void SetUseWifi();
|
||||
void SetScrollWifi();
|
||||
|
||||
UIViewGroup* headView_;
|
||||
UIViewGroup* toggleButtonView_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
TestBtnOnStateChangeListener* changeListener_;
|
||||
EventListener* buttonBackListener_;
|
||||
EventListener* buttonInputListener_;
|
||||
int wpaCount_;
|
||||
|
||||
constexpr static int TOGGLE_X = 36;
|
||||
constexpr static int TOGGLE_Y = 72;
|
||||
|
||||
constexpr static int USE_WIFI_FONT_X = 54;
|
||||
constexpr static int USE_WIFI_FONT_Y = 187;
|
||||
|
||||
constexpr static int ADD_WIFI_X = 0;
|
||||
constexpr static int SCROLL_WIFI_X = 36;
|
||||
constexpr static int SCROLL_WIFI_Y = 242;
|
||||
constexpr static int SCROLL_WIFI_WIDTH = 800;
|
||||
constexpr static int SCROLL_WIFI_HEIGHT = 238;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <setting_wifi_input_password_ability_slice.h>
|
||||
#include "gfx_utils/style.h"
|
||||
|
||||
namespace OHOS {
|
||||
REGISTER_AS(SettingWifiInputPasswordAbilitySlice)
|
||||
|
||||
static UIView::OnClickListener* clickLeftListener_ = nullptr;
|
||||
|
||||
static const int g_maxPassword = 10; // Maximum length of a password.
|
||||
static char* g_inputSsid = nullptr;
|
||||
static char g_inputPassword[g_maxPassword + 1] = { 0 };
|
||||
static int g_inputCount = 0;
|
||||
static int g_cursorPositionX = 20; // Initial position of cursor X
|
||||
|
||||
SettingWifiInputPasswordAbilitySlice::~SettingWifiInputPasswordAbilitySlice()
|
||||
{
|
||||
if (scrollView_) {
|
||||
DeleteChildren(scrollView_);
|
||||
scrollView_ = nullptr;
|
||||
}
|
||||
if (inputView_) {
|
||||
DeleteChildren(inputView_);
|
||||
inputView_ = nullptr;
|
||||
}
|
||||
if (headView_) {
|
||||
DeleteChildren(headView_);
|
||||
headView_ = nullptr;
|
||||
};
|
||||
if (buttonBackListener_) {
|
||||
delete buttonBackListener_;
|
||||
buttonBackListener_ = nullptr;
|
||||
}
|
||||
if (clickLeftListener_) {
|
||||
delete clickLeftListener_;
|
||||
clickLeftListener_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
class TestBtnOnClickInputPasswordChangeListener : public OHOS::UIView::OnClickListener {
|
||||
public:
|
||||
~TestBtnOnClickInputPasswordChangeListener() {}
|
||||
TestBtnOnClickInputPasswordChangeListener(UILabel* uiLabel, UILabel* uiCursor, const int ii,
|
||||
const int cursorOffset) : myUiLabel(uiLabel), myUiCursor(uiCursor), mIi(ii), myCursorOffset(cursorOffset) {}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
if (g_inputCount >= g_maxPassword) {
|
||||
return true;
|
||||
}
|
||||
g_inputPassword[g_inputCount] = '0' + mIi;
|
||||
myUiLabel->SetText(g_inputPassword);
|
||||
g_inputCount++;
|
||||
g_inputPassword[g_inputCount] = '\0';
|
||||
g_cursorPositionX += myCursorOffset;
|
||||
myUiCursor->SetX(g_cursorPositionX);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
UILabel* myUiLabel;
|
||||
UILabel* myUiCursor;
|
||||
int mIi;
|
||||
int myCursorOffset;
|
||||
};
|
||||
|
||||
class TestBtnOnClickEnterChangeListener : public OHOS::UIView::OnClickListener {
|
||||
public:
|
||||
explicit TestBtnOnClickEnterChangeListener(SettingWifiInputPasswordAbilitySlice* slice) : mySlice(slice) {}
|
||||
~TestBtnOnClickEnterChangeListener() {}
|
||||
bool OnClick(UIView& view, const ClickEvent& event) override
|
||||
{
|
||||
WpaScanReconnect(g_inputSsid, g_inputPassword, HIDDEN_OPEN);
|
||||
g_inputSsid = nullptr;
|
||||
int err = memset_s(g_inputPassword, sizeof(g_inputPassword), 0, sizeof(g_inputPassword));
|
||||
if (err != EOK) {
|
||||
printf("[ERROR]memset_s failed, err = %d\n", err);
|
||||
return false;
|
||||
}
|
||||
mySlice->Terminate();
|
||||
return true;
|
||||
}
|
||||
SettingWifiInputPasswordAbilitySlice* mySlice;
|
||||
};
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::SetButtonListener(void)
|
||||
{
|
||||
auto onClick = [this](UIView& view, const Event& event) -> bool {
|
||||
Terminate();
|
||||
return true;
|
||||
};
|
||||
buttonBackListener_ = new EventListener(onClick, nullptr);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::SetHead(void)
|
||||
{
|
||||
headView_ = new UIViewGroup();
|
||||
rootView_->Add(headView_);
|
||||
headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
|
||||
headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||||
headView_->SetTouchable(true);
|
||||
headView_->SetOnClickListener(buttonBackListener_);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
headView_->Add(imageView);
|
||||
imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_BACK);
|
||||
|
||||
UILabel* lablelFont = new UILabel();
|
||||
lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
|
||||
lablelFont->SetText(g_inputSsid);
|
||||
lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
|
||||
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
|
||||
headView_->Add(lablelFont);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::SetInput(void)
|
||||
{
|
||||
inputView_ = new UIViewGroup();
|
||||
inputView_->SetPosition(INPUT_X, INPUT_Y, INPUT_WIDTH, INPUT_HEIGHT);
|
||||
|
||||
inputView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
inputView_->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
inputView_->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
rootView_->Add(inputView_);
|
||||
|
||||
lablelInputText_ = new UILabel();
|
||||
lablelInputText_->SetPosition(INPUT_TEXT_X, INPUT_TEXT_Y, INPUT_TEXT_WIDTH, INPUT_TEXT_HEIGHT);
|
||||
lablelInputText_->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
lablelInputText_->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
lablelInputText_->SetText("输入密码");
|
||||
lablelInputText_->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
inputView_->Add(lablelInputText_);
|
||||
|
||||
lablelCursorText_ = new UILabel();
|
||||
lablelCursorText_->SetPosition(g_cursorPositionX, INPUT_CURSOR_Y, INPUT_CURSOR_WIDTH, INPUT_CURSOR_HEIGHT);
|
||||
lablelCursorText_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x0D, 0x9F, 0xF8)));
|
||||
lablelCursorText_->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
inputView_->Add(lablelCursorText_);
|
||||
|
||||
UIViewGroup* enterView = new UIViewGroup();
|
||||
enterView->SetPosition(INPUT_ENTER_X, INPUT_ENTER_Y, INPUT_ENTER_WIDTH, INPUT_ENTER_HEIGHT);
|
||||
enterView->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x0D, 0x9F, 0xF8)));
|
||||
enterView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
|
||||
enterView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
|
||||
inputView_->Add(enterView);
|
||||
|
||||
UIImageView* imageView = new UIImageView();
|
||||
imageView->SetPosition(INPUT_IMAGE_X, INPUT_IMAGE_Y, INPUT_IMAGE_WIDTH, INPUT_IMAGE_HEIGHT);
|
||||
imageView->SetSrc(DE_IMAGE_ENTER);
|
||||
enterView->Add(imageView);
|
||||
imageView->SetTouchable(true);
|
||||
clickLeftListener_ = new TestBtnOnClickEnterChangeListener(this);
|
||||
imageView->SetOnClickListener(clickLeftListener_);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::AddInputKeyBoardZero(void)
|
||||
{
|
||||
char buf[8] = {0};
|
||||
int myUseX = BUTTON_INTERVAL_X;
|
||||
int myUseY = 198;
|
||||
int inputNum = 0;
|
||||
UILabelButton* inputButton = new UILabelButton();
|
||||
|
||||
inputButton->SetPosition(myUseX, myUseY);
|
||||
sprintf_s(buf, sizeof(buf), "%d", inputNum);
|
||||
inputButton->SetWidth(BUTTON_WIDTH);
|
||||
inputButton->SetHeight(BUTTON_HEIGHT);
|
||||
inputButton->SetText(buf);
|
||||
inputButton->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
inputButton->SetStyle(STYLE_BORDER_RADIUS, RECT_RADIUS);
|
||||
inputButton->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
inputButton->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
|
||||
|
||||
clickLeftListener_ = new TestBtnOnClickInputPasswordChangeListener((UILabel*)lablelInputText_, (UILabel*)lablelCursorText_, inputNum, CURSOR_POSITION_OFFSET);
|
||||
inputButton->SetOnClickListener(clickLeftListener_);
|
||||
scrollView_->Add(inputButton);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::SetScrollView(void)
|
||||
{
|
||||
char buf[8] = {0};
|
||||
int inputNum;
|
||||
scrollView_ = new UIScrollView();
|
||||
scrollView_->SetPosition(SCROLL_WIFI_INPUT_X, SCROLL_WIFI_INPUT_Y, SCROLL_WIFI_INPUT_WIDTH,
|
||||
SCROLL_WIFI_INPUT_WIDTH);
|
||||
scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
|
||||
scrollView_->SetXScrollBarVisible(false);
|
||||
scrollView_->SetYScrollBarVisible(false);
|
||||
rootView_->Add(scrollView_);
|
||||
for (int countFirst = 0; countFirst < BUTTON_NUM; countFirst++) {
|
||||
for (int countSecond = 0; countSecond < BUTTON_NUM; countSecond++) {
|
||||
int myUseX = countSecond * BUTTON_INTERVAL_X;
|
||||
int myUseY = countFirst * BUTTON_INTERVAL_Y;
|
||||
inputNum = ((countFirst * BUTTON_NUM) + countSecond + 1);
|
||||
UILabelButton* inputButton = new UILabelButton();
|
||||
inputButton->SetPosition(myUseX, myUseY, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
int err = sprintf_s(buf, sizeof(buf), "%d", inputNum);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
inputButton->SetText(buf); // SetText is system functions
|
||||
inputButton->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
|
||||
inputButton->SetStyle(STYLE_BORDER_RADIUS, RECT_RADIUS);
|
||||
inputButton->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
|
||||
inputButton->SetFont(DE_FONT_OTF, DE_CONTENT_FONT_SIZE);
|
||||
UIView::OnClickListener* clickLeftListener = nullptr;
|
||||
clickLeftListener = new TestBtnOnClickInputPasswordChangeListener((UILabel*)lablelInputText_,
|
||||
(UILabel*)lablelCursorText_, inputNum, CURSOR_POSITION_OFFSET);
|
||||
inputButton->SetOnClickListener(clickLeftListener);
|
||||
scrollView_->Add(inputButton);
|
||||
}
|
||||
}
|
||||
AddInputKeyBoardZero();
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::OnStart(const Want& want)
|
||||
{
|
||||
printf("[LOG]receive the data -> %s\n", reinterpret_cast<char*>(want.data));
|
||||
AbilitySlice::OnStart(want);
|
||||
|
||||
g_inputSsid = reinterpret_cast<char*>(want.data);
|
||||
rootView_ = RootView::GetWindowRootView();
|
||||
|
||||
int err = memset_s(g_inputPassword, sizeof(g_inputPassword), 0, g_maxPassword);
|
||||
if (err != EOK) {
|
||||
printf("[ERROR]memcpy_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
g_inputCount = 0;
|
||||
g_cursorPositionX = 20; // 20
|
||||
rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
|
||||
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
|
||||
SetButtonListener();
|
||||
SetHead();
|
||||
SetInput();
|
||||
SetScrollView();
|
||||
SetUIContent(rootView_);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::OnInactive()
|
||||
{
|
||||
AbilitySlice::OnInactive();
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::OnActive(const Want& want)
|
||||
{
|
||||
int err;
|
||||
lablelInputText_->SetText("输入密码");
|
||||
g_cursorPositionX = 20; // 20
|
||||
lablelCursorText_->SetX(g_cursorPositionX);
|
||||
g_inputCount = 0;
|
||||
err = memset_s(g_inputPassword, sizeof(g_inputPassword), 0, sizeof(g_inputPassword));
|
||||
if (err != EOK) {
|
||||
return;
|
||||
}
|
||||
AbilitySlice::OnActive(want);
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::OnBackground()
|
||||
{
|
||||
AbilitySlice::OnBackground();
|
||||
}
|
||||
|
||||
void SettingWifiInputPasswordAbilitySlice::OnStop()
|
||||
{
|
||||
AbilitySlice::OnStop();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SETTING_WIFI_INPUT_PASSWORD_ABILITY_SLICE_H
|
||||
#define OHOS_SETTING_WIFI_INPUT_PASSWORD_ABILITY_SLICE_H
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "common/task.h"
|
||||
#include "components/ui_checkbox.h"
|
||||
#include "components/ui_image_view.h"
|
||||
#include "components/ui_label.h"
|
||||
#include "components/ui_label_button.h"
|
||||
#include "components/ui_list.h"
|
||||
#include "components/ui_scroll_view.h"
|
||||
#include "components/ui_view_group.h"
|
||||
#include "event_listener.h"
|
||||
#include "parameter.h"
|
||||
#include "setting_utils.h"
|
||||
#include "setting_wifi_input_password_ability_slice.h"
|
||||
#include "wpa_work.h"
|
||||
|
||||
namespace OHOS {
|
||||
class SettingWifiInputPasswordAbilitySlice : public AbilitySlice {
|
||||
public:
|
||||
SettingWifiInputPasswordAbilitySlice() : headView_(nullptr), inputView_(nullptr), lablelCursorText_(nullptr),
|
||||
scrollView_(nullptr), rootView_(nullptr), lablelInputText_(nullptr),
|
||||
buttonBackListener_(nullptr) {}
|
||||
virtual ~SettingWifiInputPasswordAbilitySlice();
|
||||
|
||||
protected:
|
||||
void OnStart(const Want& want) override;
|
||||
void OnInactive() override;
|
||||
void OnActive(const Want& want) override;
|
||||
void OnBackground() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
void SetHead();
|
||||
void SetInput();
|
||||
void AddInputKeyBoardZero();
|
||||
void SetScrollView();
|
||||
void SetButtonListener();
|
||||
UIViewGroup* headView_;
|
||||
UIViewGroup* inputView_;
|
||||
UILabel* lablelCursorText_;
|
||||
UIScrollView* scrollView_;
|
||||
RootView* rootView_;
|
||||
UILabel* lablelInputText_;
|
||||
EventListener* buttonBackListener_;
|
||||
|
||||
constexpr static int CURSOR_POSITION_OFFSET = 16;
|
||||
constexpr static int RECT_RADIUS = 6;
|
||||
constexpr static int INPUT_X = 36;
|
||||
constexpr static int INPUT_Y = 108;
|
||||
constexpr static int INPUT_WIDTH = 737;
|
||||
constexpr static int INPUT_HEIGHT = 54;
|
||||
constexpr static int INPUT_RADIUS = 32;
|
||||
constexpr static int INPUT_CURSOR_X = 20;
|
||||
constexpr static int INPUT_CURSOR_Y = 10;
|
||||
constexpr static int INPUT_CURSOR_WIDTH = 2;
|
||||
constexpr static int INPUT_CURSOR_HEIGHT = 36;
|
||||
constexpr static int INPUT_TEXT_X = 24;
|
||||
constexpr static int INPUT_TEXT_Y = 11;
|
||||
constexpr static int INPUT_TEXT_WIDTH = 398;
|
||||
constexpr static int INPUT_TEXT_HEIGHT = 38;
|
||||
constexpr static int INPUT_FONT_SIZE = 28;
|
||||
constexpr static int INPUT_ENTER_X = 650;
|
||||
constexpr static int INPUT_ENTER_Y = 6;
|
||||
constexpr static int INPUT_ENTER_WIDTH = 70;
|
||||
constexpr static int INPUT_ENTER_HEIGHT = 42;
|
||||
constexpr static int INPUT_ENTER_RADIUS = 32;
|
||||
|
||||
constexpr static int INPUT_IMAGE_X = 10;
|
||||
constexpr static int INPUT_IMAGE_Y = 2;
|
||||
constexpr static int INPUT_IMAGE_WIDTH = 38;
|
||||
constexpr static int INPUT_IMAGE_HEIGHT = 38;
|
||||
|
||||
constexpr static int BUTTON_NUM = 3;
|
||||
|
||||
constexpr static int BUTTON_INTERVAL_X = 140;
|
||||
constexpr static int BUTTON_INTERVAL_Y = 66;
|
||||
constexpr static int BUTTON_WIDTH = 132;
|
||||
constexpr static int BUTTON_HEIGHT = 54;
|
||||
|
||||
constexpr static int SCROLL_WIFI_INPUT_X = 228;
|
||||
constexpr static int SCROLL_WIFI_INPUT_Y = 198;
|
||||
constexpr static int SCROLL_WIFI_INPUT_WIDTH = 439;
|
||||
constexpr static int SCROLL_WIFI_INPUT_HEIGHT = 252;
|
||||
};
|
||||
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "wpa_work.h"
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#define WPA_IFACE_NAME "wlan0"
|
||||
#define WIFI_AUTH_FAILED_REASON_STR "WRONG_KEY"
|
||||
#define WIFI_AUTH_FAILED_REASON_CODE "reason=2"
|
||||
#define WPA_CTRL_REQUEST_OK "OK"
|
||||
#define WPA_CTRL_REQUEST_FAIL "FAIL"
|
||||
|
||||
#define SAMPLE_INFO(format, args...) \
|
||||
do { \
|
||||
fprintf(stderr, "\033[1;32m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
|
||||
#define SAMPLE_ERROR(format, args...) \
|
||||
do { \
|
||||
fprintf(stderr, "\033[1;31m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static struct wpa_ctrl *g_monitorConn = NULL;
|
||||
static pthread_t g_threadId = 0;
|
||||
pthread_mutex_t g_mutex;
|
||||
pthread_mutex_t g_monitorConnMutex;
|
||||
static char g_mySsidD[40][40] = {0};
|
||||
static int g_ssidCount = 0;
|
||||
|
||||
static char g_useSsidD[40][40] = {0};
|
||||
static int g_useSsidCount = 0;
|
||||
|
||||
static pthread_t g_wpaThreadId = 0;
|
||||
static pthread_t g_scanThreadId = 0;
|
||||
static int g_scanAvailable = 0;
|
||||
static int g_Connect = 0;
|
||||
|
||||
static void DumpString(const char *buf, int len, const char *tag)
|
||||
{
|
||||
SAMPLE_INFO("%s dump start.", tag);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf("%c", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("\n");
|
||||
SAMPLE_INFO("%s dump end.", tag);
|
||||
}
|
||||
|
||||
static int StrMatch(const char *a, const char *b)
|
||||
{
|
||||
return strncmp(a, b, strlen(b)) == 0;
|
||||
}
|
||||
|
||||
static int SendCtrlCommand(const char *cmd, char *reply, size_t *replyLen)
|
||||
{
|
||||
static struct wpa_ctrl *ctrlConn = NULL;
|
||||
int i = 0;
|
||||
int reTime = 5;
|
||||
while (i++ < reTime) { // check wpa init success
|
||||
ctrlConn = wpa_ctrl_open(WPA_IFACE_NAME);
|
||||
if (ctrlConn != NULL) {
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
if (ctrlConn == NULL) {
|
||||
printf("%s:%d [ERROR] control connect handle is null\n", __FUNCTION__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
size_t len = *replyLen - 1;
|
||||
wpa_ctrl_request(ctrlConn, cmd, strlen(cmd), reply, &len, 0);
|
||||
DumpString(reply, len, "SendCtrlCommand raw return");
|
||||
if (ctrlConn != NULL) {
|
||||
wpa_ctrl_close(ctrlConn);
|
||||
ctrlConn = NULL;
|
||||
}
|
||||
|
||||
if (len != 0 && !StrMatch(reply, WPA_CTRL_REQUEST_FAIL)) {
|
||||
*replyLen = len;
|
||||
return 0;
|
||||
}
|
||||
SAMPLE_ERROR("send ctrl request [%s] failed.", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void ProcessScanResult(const char *buf, int len)
|
||||
{
|
||||
int myUse1 = 1;
|
||||
int myUse2 = 2;
|
||||
int myUse5 = 5;
|
||||
|
||||
int err = memset_s(g_mySsidD, sizeof(g_mySsidD), 0, sizeof(g_mySsidD));
|
||||
g_ssidCount = 0;
|
||||
if (err != EOK) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (buf[i] == 'E' && buf[i + myUse1] == 'S' && buf[i + myUse2] == 'S') {
|
||||
int j;
|
||||
printf("[ERROR]get the ESS i->%d\n", i);
|
||||
i = i + myUse5;
|
||||
for (j = 0; i < len && buf[i] != '\n'; i++) {
|
||||
g_mySsidD[g_ssidCount][j] = buf[i];
|
||||
j++;
|
||||
}
|
||||
|
||||
g_ssidCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResetSSIDBuff(void)
|
||||
{
|
||||
g_useSsidCount = 0;
|
||||
}
|
||||
|
||||
int GetIdNum(void)
|
||||
{
|
||||
return g_useSsidCount;
|
||||
}
|
||||
|
||||
int GetCurrentConnInfo(char *ssid, int len)
|
||||
{
|
||||
int offset = 5;
|
||||
char connInfo[2048] = {0};
|
||||
size_t infoLen = sizeof(connInfo);
|
||||
if (g_Connect == 0) {
|
||||
printf("[LOG]GetCurrentConnInfo g_Connect -> 0 \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = SendCtrlCommand("STATUS", connInfo, &infoLen);
|
||||
if (ret == -1) {
|
||||
printf("[ERROR]GetCurrentConnInfo Command(STATUS) Error \n");
|
||||
return -1;
|
||||
}
|
||||
DumpString(connInfo, infoLen, "connInfo");
|
||||
printf("[LOG]end the DumpStrint\n");
|
||||
char *pos = strstr(connInfo, "ssid=");
|
||||
if (pos == NULL) {
|
||||
printf("[ERROR]strstr(ssid) is null");
|
||||
return -1;
|
||||
}
|
||||
if (offset >= strlen(pos)) {
|
||||
return -1;
|
||||
}
|
||||
pos += offset;
|
||||
pos = strstr(pos, "ssid=");
|
||||
if (pos == NULL) {
|
||||
printf("[ERROR]second strstr(ssid) is null");
|
||||
return -1;
|
||||
}
|
||||
char *end = strchr(pos, '\n');
|
||||
if (end == NULL) {
|
||||
printf("[ERROR]second strstr(end) is null");
|
||||
return -1;
|
||||
}
|
||||
int ssidLen = end - pos - offset;
|
||||
if (len < ssidLen) {
|
||||
return -1;
|
||||
}
|
||||
int i = 0;
|
||||
int myOffset = 5;
|
||||
for (pos += myOffset; pos < end; pos++, i++) {
|
||||
ssid[i] = *pos;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ExitWpaScan(void)
|
||||
{
|
||||
int ret;
|
||||
if (g_scanThreadId != 0) {
|
||||
ret = pthread_cancel(g_scanThreadId);
|
||||
printf("[INFO]pthread_cancel(g_scanThreadId) ret -> %d \n", ret);
|
||||
g_scanThreadId = 0;
|
||||
}
|
||||
if (g_wpaThreadId != 0) {
|
||||
ret = pthread_cancel(g_wpaThreadId);
|
||||
printf("[INFO]pthread_cancel(g_wpaThreadId) ret -> %d \n", ret);
|
||||
g_wpaThreadId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ExitWpa(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_lock(&g_monitorConnMutex);
|
||||
if (g_monitorConn != NULL) {
|
||||
wpa_ctrl_close(g_monitorConn);
|
||||
printf("[INFO]wpa_ctrl_close(g_monitorConn).\n");
|
||||
g_monitorConn = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_monitorConnMutex);
|
||||
char result[100] = {0};
|
||||
size_t len = sizeof(result);
|
||||
printf("[INFO]ExitWpa TERMINATE begin.\n");
|
||||
SendCtrlCommand("TERMINATE", result, &len);
|
||||
printf("[INFO]ExitWpa TERMINATE end.\n");
|
||||
sleep(1);
|
||||
DeinitWifiService();
|
||||
if (g_threadId != 0) {
|
||||
ret = pthread_cancel(g_threadId);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]pthread_cancel(g_threadId) ret -> %d \n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]pthread_mutex_destroy ret -> %d \n", ret);
|
||||
}
|
||||
ret = pthread_mutex_destroy(&g_monitorConnMutex);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]pthread_mutex_destroy ret -> %d \n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
int GetAndResetScanStat(void)
|
||||
{
|
||||
int ret = g_scanAvailable;
|
||||
g_scanAvailable = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *GetSsid(const int ssidNum)
|
||||
{
|
||||
return g_useSsidD[ssidNum];
|
||||
}
|
||||
|
||||
void LockWifiData()
|
||||
{
|
||||
pthread_mutex_lock(&g_mutex);
|
||||
}
|
||||
|
||||
void UnLockWifiData()
|
||||
{
|
||||
pthread_mutex_unlock(&g_mutex);
|
||||
}
|
||||
|
||||
static void CheckSsid(void)
|
||||
{
|
||||
int i, ret, err;
|
||||
int checkSsid = 0x5C;
|
||||
|
||||
err = memset_s(g_useSsidD, sizeof(g_useSsidD), 0, sizeof(g_useSsidD));
|
||||
if (err != EOK) {
|
||||
printf("[ERROR]memset_s g_useSsidD failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
g_useSsidCount = 0;
|
||||
for (i = 0; i < g_ssidCount; i++) {
|
||||
int j = i + 1;
|
||||
for (; j < g_ssidCount; j++) {
|
||||
ret = strcmp(g_mySsidD[i], g_useSsidD[j]);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((g_mySsidD[i][0] == checkSsid) || (g_mySsidD[i][0] == 0)) {
|
||||
continue;
|
||||
}
|
||||
if (j == g_ssidCount) {
|
||||
err = strcpy_s(g_useSsidD[g_useSsidCount], sizeof(g_useSsidD[g_useSsidCount]), g_mySsidD[i]);
|
||||
if (err != EOK) {
|
||||
continue;
|
||||
}
|
||||
g_useSsidCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WifiEventHandler(char *rawEvent, int len)
|
||||
{
|
||||
char *pos = rawEvent;
|
||||
if (*pos == '<') {
|
||||
pos = strchr(pos, '>');
|
||||
if (pos) {
|
||||
pos++;
|
||||
} else {
|
||||
pos = rawEvent;
|
||||
}
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_CONNECTED)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_CONNECTED");
|
||||
g_Connect = 1;
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_SCAN_RESULTS)) {
|
||||
pthread_mutex_lock(&g_mutex);
|
||||
SAMPLE_INFO("WIFI_EVENT_SCAN_DONE");
|
||||
char scanResult[4096] = {0};
|
||||
size_t scanLen = sizeof(scanResult);
|
||||
SendCtrlCommand("SCAN_RESULTS", scanResult, &scanLen);
|
||||
|
||||
ProcessScanResult(scanResult, scanLen);
|
||||
CheckSsid();
|
||||
g_scanAvailable = 1;
|
||||
pthread_mutex_unlock(&g_mutex);
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_TEMP_DISABLED) && strstr(pos, WIFI_AUTH_FAILED_REASON_STR)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_WRONG_KEY");
|
||||
return;
|
||||
}
|
||||
if (StrMatch(pos, WPA_EVENT_DISCONNECTED) && !strstr(pos, WIFI_AUTH_FAILED_REASON_CODE)) {
|
||||
SAMPLE_INFO("WIFI_EVENT_DISCONNECTED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void CliRecvPending(void)
|
||||
{
|
||||
int pendingResult = -1;
|
||||
pthread_mutex_lock(&g_monitorConnMutex);
|
||||
if (g_monitorConn!= NULL) {
|
||||
pendingResult = wpa_ctrl_pending(g_monitorConn);
|
||||
}
|
||||
while (pendingResult > 0) {
|
||||
char buf[4096];
|
||||
size_t len = sizeof(buf) - 1;
|
||||
if (g_monitorConn != NULL) {
|
||||
if (wpa_ctrl_recv(g_monitorConn, buf, &len) == 0) {
|
||||
buf[len] = '\0';
|
||||
SAMPLE_INFO("event received %s", buf);
|
||||
WifiEventHandler(buf, len);
|
||||
} else {
|
||||
SAMPLE_INFO("could not read pending message.");
|
||||
break;
|
||||
}
|
||||
pendingResult = wpa_ctrl_pending(g_monitorConn);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_monitorConnMutex);
|
||||
}
|
||||
|
||||
static void* MonitorTask(void *args)
|
||||
{
|
||||
(void)args;
|
||||
int fd, ret;
|
||||
fd_set rfd;
|
||||
while (1) {
|
||||
fd = -1;
|
||||
pthread_mutex_lock(&g_monitorConnMutex);
|
||||
if (g_monitorConn != NULL) {
|
||||
fd = wpa_ctrl_get_fd(g_monitorConn);
|
||||
} else {
|
||||
pthread_mutex_unlock(&g_monitorConnMutex);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&g_monitorConnMutex);
|
||||
FD_ZERO(&rfd);
|
||||
FD_SET(fd, &rfd);
|
||||
ret = select(fd + 1, &rfd, NULL, NULL, NULL);
|
||||
if (ret <= 0) {
|
||||
SAMPLE_INFO("select failed ret = %d\n", ret);
|
||||
break;
|
||||
}
|
||||
CliRecvPending();
|
||||
sleep(1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void TestNetworkConfig(const char *gSsid, const char *gPassWord)
|
||||
{
|
||||
char networkId[20] = {0};
|
||||
size_t networkIdLen = sizeof(networkId);
|
||||
int ret = SendCtrlCommand("DISCONNECT", networkId, &networkIdLen);
|
||||
ret += SendCtrlCommand("ADD_NETWORK", networkId, &networkIdLen);
|
||||
if (ret != 0) {
|
||||
SAMPLE_ERROR("add network failed.");
|
||||
return;
|
||||
}
|
||||
SAMPLE_INFO("add network success, network id [%.*s]", networkIdLen, networkId);
|
||||
char reply[100] = {0};
|
||||
size_t replyLen = sizeof(reply);
|
||||
char cmd[200] = {0};
|
||||
int err = sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s ssid \"%s\"", networkIdLen, networkId, gSsid);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
err = sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s psk \"%s\"", networkIdLen, networkId, gPassWord);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
err = sprintf_s(cmd, sizeof(cmd), "ENABLE_NETWORK %.*s", networkIdLen, networkId);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
ret += SendCtrlCommand(cmd, reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
ret += SendCtrlCommand("RECONNECT", reply, &replyLen);
|
||||
replyLen = sizeof(reply);
|
||||
if (ret == 0) {
|
||||
SAMPLE_INFO("network config success.");
|
||||
return;
|
||||
}
|
||||
err = sprintf_s(cmd, sizeof(cmd), "REMOVE_NETWORK %.*s", networkIdLen, networkId);
|
||||
if (err < 0) {
|
||||
printf("[ERROR]sprintf_s failed, err = %d\n", err);
|
||||
return;
|
||||
}
|
||||
SendCtrlCommand(cmd, reply, &replyLen);
|
||||
SAMPLE_ERROR("network config failed remove network [%.*s].", networkIdLen, networkId);
|
||||
}
|
||||
|
||||
int InitControlInterface()
|
||||
{
|
||||
int i = 0;
|
||||
int ret;
|
||||
int reTime = 5;
|
||||
while (i++ < reTime) { // create control interface for event monitor
|
||||
g_monitorConn = wpa_ctrl_open(WPA_IFACE_NAME);
|
||||
if (g_monitorConn != NULL) {
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
if (!g_monitorConn) {
|
||||
SAMPLE_ERROR("open wpa control interface failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = -1;
|
||||
pthread_mutex_lock(&g_monitorConnMutex);
|
||||
if (g_monitorConn!= NULL) {
|
||||
ret = wpa_ctrl_attach(g_monitorConn);
|
||||
}
|
||||
pthread_mutex_unlock(&g_monitorConnMutex);
|
||||
printf("[INFO]wpa_ctrl_attach return %d.\n", ret);
|
||||
if (ret == 0) { // start monitor
|
||||
ret = pthread_create(&g_wpaThreadId, NULL, MonitorTask, NULL); // create thread for read event
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]thread error %s\n", strerror(ret));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* WpaScanThread(void *args)
|
||||
{
|
||||
int mySleep = 2;
|
||||
int ret = 0;
|
||||
sleep(mySleep);
|
||||
if (g_monitorConn == NULL) {
|
||||
ret = InitControlInterface();
|
||||
printf("%s:%d [INFO] InitControlInterface return %d.\n", __FUNCTION__, __LINE__, ret);
|
||||
if (ret == -1) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
char reply[100] = {0};
|
||||
size_t replyLen = sizeof(reply);
|
||||
g_scanAvailable = 0;
|
||||
SendCtrlCommand("SCAN", reply, &replyLen);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WpaScanReconnect(const char *gSsid, const char *gPassWord, const int hiddenSwitch)
|
||||
{
|
||||
if (HIDDEN_OPEN == hiddenSwitch) {
|
||||
TestNetworkConfig(gSsid, gPassWord);
|
||||
} else {
|
||||
int ret = pthread_create(&g_scanThreadId, NULL, WpaScanThread, NULL); // create thread for read event
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]thread error %s\n", strerror(ret));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *ThreadMain()
|
||||
{
|
||||
prctl(PR_SET_NAME, "WPA_THREAD");
|
||||
int i = 0;
|
||||
int myfor = 5;
|
||||
char *arg[20] = {0};
|
||||
arg[i] = (char *)"wpa_supplicant";
|
||||
arg[++i] = (char *)"-i";
|
||||
arg[++i] = (char *)"wlan0";
|
||||
arg[++i] = (char *)"-c";
|
||||
arg[++i] = (char *)"/storage/app/run/com.huawei.setting/setting/assets/setting/resources/base/element/wpa_supplicant.conf";
|
||||
|
||||
for (i = 0; i < myfor; i++) {
|
||||
printf("[LOG]arg[%d]->%s \n", i, arg[i]);
|
||||
}
|
||||
wpa_main(myfor, arg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WpaClientStart(void)
|
||||
{
|
||||
static int runStatus = 0;
|
||||
if (runStatus == 0) {
|
||||
int ret = pthread_create(&g_threadId, NULL, ThreadMain, NULL);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]thread error %s\n", strerror(ret));
|
||||
return;
|
||||
}
|
||||
ret = pthread_mutex_init(&g_mutex, NULL);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]pthread_mutex_init error %s\n", strerror(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
ret = pthread_mutex_init(&g_monitorConnMutex, &attr);
|
||||
if (ret != 0) {
|
||||
printf("[ERROR]pthread_mutex_init error %s\n", strerror(ret));
|
||||
return;
|
||||
}
|
||||
runStatus = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_WPA_WORK_H
|
||||
#define OHOS_WPA_WORK_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "parameter.h"
|
||||
#include "pthread.h"
|
||||
#include "securec.h"
|
||||
#include "wpa_ctrl.h"
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#define HIDDEN_CLOSE 0
|
||||
#define HIDDEN_OPEN 1
|
||||
void ExitWpaScan(void);
|
||||
void ExitWpa(void);
|
||||
int wpa_main(int argc, char *argv[]);
|
||||
int GetCurrentConnInfo(char *ssid, int len);
|
||||
void DeinitWifiService();
|
||||
void ResetSSIDBuff(void);
|
||||
int GetIdNum(void);
|
||||
int GetAndResetScanStat(void);
|
||||
char *GetSsid(const int ssidNum);
|
||||
void WpaScanReconnect(const char *gSsid, const char *gPassWord, const int hiddenSwitch);
|
||||
void WpaClientStart(void);
|
||||
void LockWifiData(void);
|
||||
void UnLockWifiData(void);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
country=GB
|
||||
ctrl_interface=udp
|
||||
network={
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 359 B |
|
After Width: | Height: | Size: 353 B |
|
After Width: | Height: | Size: 330 B |
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,44 @@
|
||||
|
||||
---
|
||||
# 小熊派-鸿蒙·叔(BearPi-HM Micro)
|
||||
|
||||
## 一、BearPi-HM Micro 开发板介绍
|
||||
|
||||
BearPi-HM Micro开发板是一块高度集成并可运行OpenHarmony系统的开发板,板载高性能的工业级处理器STM32MP157芯片,搭配4.3寸LCD电容式触摸屏,并板载wifi电路及标准的E53接口,标准的E53接口可扩展智能加湿器、智能台灯、智能安防、智能烟感等案例。可折叠式屏幕设计大大提高用户开发体验,便于携带和存放,更好地满足不同用户的需求,拓展无限可能。
|
||||
|
||||
|
||||
|
||||
## 二、设备开发手把手教程系列
|
||||
|
||||
1、视频系列(B站) 对应PPT地址
|
||||
* [P1. 初识BearPi-HM Micro开发板](https://www.bilibili.com/video/BV12Y411H7ry?p=1)
|
||||
* [P2. 开发环境搭建(复杂)——编译环境搭建](https://www.bilibili.com/video/BV12Y411H7ry?p=3)
|
||||
* [P3. 开发环境搭建(复杂)——源码获取及编译](https://www.bilibili.com/video/BV12Y411H7ry?p=4)
|
||||
* [P4. BearPi-HM Micro开发板源码烧录](https://www.bilibili.com/video/BV12Y411H7ry?p=5)
|
||||
* [P5. OpenHarmony 快速入门:HelloWorld](https://www.bilibili.com/video/BV12Y411H7ry?p=6)
|
||||
* [P6. OpenHarmony 快速入门:点亮LED](https://www.bilibili.com/video/BV12Y411H7ry?p=7)
|
||||
* [P7. OpenHarmony 快速入门:安装HAP](https://www.bilibili.com/video/BV12Y411H7ry?p=8)
|
||||
* [P8. OpenHarmony 快速入门:JS点亮LED](https://www.bilibili.com/video/BV12Y411H7ry?p=9)
|
||||
|
||||
2、文档系列(Gitee)
|
||||
- [1. 初识BearPi-HM Micro开发板](device-dev/BearPi-HM_Micro开发板介绍.md)
|
||||
- [2. 开发环境搭建](device-dev/BearPi-HM_Micro开发环境搭建.md)
|
||||
- [3. 源码获取、编译烧录](device-dev/BearPi-HM_Micro开发板编译调试.md)
|
||||
- [4. 编写一个hello_world程序](device-dev/编写一个hello_world程序.md)
|
||||
- [5. 如何运行一个可执行程序](device-dev/如何运行一个可执行程序.md)
|
||||
- [6. 编写一个点亮LED灯程序](device-dev/编写一个点亮LED灯程序.md)
|
||||
- [7. 通过JS应用控制LED灯](device-dev/通过JS应用控制LED灯.md)
|
||||
- [8. 如何在开发板上安装HAP应用](device-dev/如何在开发板上安装HAP应用.md)
|
||||
|
||||
|
||||
## 三、开发板图片预览[(淘宝链接)](https://item.taobao.com/item.htm?id=662078665554)
|
||||
|
||||
[](https://item.taobao.com/item.htm?id=633296694816)
|
||||
|
||||
|
||||
## 四、联系我们
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# BearPi-HM Micro开发板介绍
|
||||
|
||||
本文档介绍BearPi-HM Micro开发板外观、功能、资源及参数规格,通过学习,开发者会对BearPi-HM Micro开发板有初步认识,并可上手业务开发。
|
||||
|
||||
## 开发板简介
|
||||
|
||||
BearPi-HM Micro开发板是一块高度集成并可运行OpenHarmony系统的开发板,板载高性能的工业级处理器STM32MP157芯片,搭配4.3寸LCD电容式触摸屏,并板载wifi电路及标准的E53接口,标准的E53接口可扩展智能加湿器、智能台灯、智能安防、智能烟感等案例。可折叠式屏幕设计大大提高用户开发体验,便于携带和存放,更好地满足不同用户的需求,拓展无限可能。
|
||||
|
||||
### 购买地址 [点击购买](https://item.taobao.com/item.htm?id=662078665554)
|
||||
|
||||
### 视频教程地址 [点击观看](https://space.bilibili.com/470797387?spm_id_from=333.788.b_765f7570696e666f.2)
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## 开发板硬件资源
|
||||
|
||||
**表 1** BearPi-HM Micro开发板硬件规格清单
|
||||
|
||||
|
||||
| No | 功能 | 参数 |
|
||||
| ---- | ---- | ------------------------------------------------------------ |
|
||||
| 1 | Power | 5V TypeC供电|
|
||||
| 2 | eMMC | 1x4GB|
|
||||
| 3 | DDR | 1x4Gb|
|
||||
| 4 | LCD | 4.3寸电容式触摸屏|
|
||||
| 5 |WIFI | Hi3881 支持WIFI 2.4G|
|
||||
| 6 | KEY| Reset key x1, User Key x1 |
|
||||
| 7 | TypeC | 集供电、烧录程序、调试一体|
|
||||
| 8 | LED | LED x1|
|
||||
| 9 | USB HOST | 一路 USB2.0 HOST|
|
||||
| 10 |AUDIO |4段式耳机 x1,MIC咪头 x1,扬声器 x1|
|
||||
| 11 |Expansion | 支持 标准E53接口 x1, S24接口 x1|
|
||||
|
||||
## 开发板软件资源
|
||||
|
||||
* 搭载OpenHarmony 3.0 操作系统
|
||||
* 轻量级ACE UI框架,支持JS应用开发部署
|
||||
* 支持分布式软总线,用户应用程序可分可合、可跨设备流转(TODO)
|
||||
|
||||
|
||||
**表 2** BearPi-HM Micro开发板平台驱动支持清单
|
||||
|
||||
| No | 类别 | 是否支持 |
|
||||
| ---- | ---- | ------------- |
|
||||
| 1 | GPIO | 支持|
|
||||
| 2 | I2C | 支持|
|
||||
| 3 |RTC | TODO|
|
||||
| 4 | SDIO | 支持|
|
||||
| 5 | SPI | 支持|
|
||||
| 6 | UART | 支持|
|
||||
| 7 | WATCHDOG | 支持|
|
||||
| 9 |MMC | 支持|
|
||||
| 10 |PWM | 支持|
|
||||
| 11 |ADC | 支持|
|
||||
| 12 |I2S | TODO|
|
||||
|
||||
**表 3** BearPi-HM Micro开发板外设驱动支持清单
|
||||
|
||||
| No | 类别 | 是否支持 |
|
||||
| ---- | ---- | ------ |
|
||||
| 1 | LCD | 支持|
|
||||
| 2 | TOUCH | 支持|
|
||||
| 3 | AUDIO | TODO|
|
||||
| 4 | NETWORK | 支持|
|
||||
| 5 | SENSOR | TODO|
|
||||
| 6 | USB | TODO|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# BearPi-HM_Micro开发板编译调试
|
||||
|
||||
## 获取源码
|
||||
```
|
||||
repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify
|
||||
repo sync -c
|
||||
repo forall -c 'git lfs pull'
|
||||
./build/prebuilts_download.sh
|
||||
```
|
||||
## 源码编译
|
||||
|
||||
1. 在源码目录下输入以下指令。
|
||||
```
|
||||
hb set
|
||||
|
||||
bearpi
|
||||
>bearpi_hm_micro
|
||||
|
||||
选择bearpi_hm_micro
|
||||
|
||||
hb build --tee -f
|
||||
```
|
||||
|
||||
2. 查看编译出的固件位置
|
||||
|
||||
当编译完后,在Windows中可以直接查看到最终编译的固件,具体路径在:
|
||||
`\out\bearpi-hm_micro\bearpi-hm_micro`
|
||||
其中有以下文件是后面烧录系统需要使用的。
|
||||
|
||||
* OHOS_Image.stm32:系统镜像文件
|
||||
* rootfs_vfat.img:根文件系统
|
||||
* userfs_vfat.img:用户文件系统
|
||||
|
||||
|
||||

|
||||
|
||||
3. 在MobaXterm中执行以下三条指令将以上三个文件复制到`device/board/bearpi/bearpi_hm_micro/tools/download_img/kernel/`下,以便后续烧录系统使用
|
||||
|
||||
```
|
||||
cp out/bearpi_hm_micro/bearpi_hm_micro/OHOS_Image.stm32 device/board/bearpi/bearpi_hm_micro/tools/download_img/kernel/
|
||||
cp out/bearpi_hm_micro/bearpi_hm_micro/rootfs_vfat.img device/board/bearpi/bearpi_hm_micro/tools/download_img/kernel/
|
||||
cp out/bearpi_hm_micro/bearpi_hm_micro/userfs_vfat.img device/board/bearpi/bearpi_hm_micro/tools/download_img/kernel/
|
||||
```
|
||||
|
||||
## 烧录镜像并启动开发板
|
||||
### 一、安装软件
|
||||
|
||||
- 下载并安装JRE
|
||||
- 下载地址(百度云):https://pan.baidu.com/s/1yuMn4YulfP6j50mQA8faoA 提取码:1234
|
||||
|
||||
- 下载并安装STM32CubeProgrammer(需要2.4.0+版本)
|
||||
- 下载地址(百度云):https://pan.baidu.com/s/1XfFFFs7UdE9TPdN0FdA6ag 提取码:1234
|
||||
|
||||
### 二、连接开发板
|
||||
|
||||
1. 通过TypeC数据线,把电脑与BearPi-HM Micro连接。
|
||||
|
||||
2. 安装CH340驱动。
|
||||
|
||||
下载地址:http://www.wch.cn/downloads/CH341SER_EXE.html
|
||||
|
||||
3. 关闭虚拟机捕获USB功能。(有很多开发者都是因为虚拟机捕获了USB设备,导致本机Windows电脑看不到串口)
|
||||
|
||||

|
||||
|
||||
如果上面操作不行,直接关闭VMware Workstation,选择挂起,然后再重新插拔USB。
|
||||
|
||||
4. 查看开发板的串口
|
||||
|
||||

|
||||
|
||||
### 三、烧录镜像
|
||||
|
||||
1. 将开发板的拨码开关上拨到“000”烧录模式,并按一下开发板的RESET按键
|
||||
|
||||

|
||||
|
||||
2. 在Windows打开STM32CubeProgrammer工具,选择“USB”烧录方式,再点击刷新按钮,然后点击"Connect"。
|
||||
|
||||

|
||||
|
||||
3. 点击STM32CubeProgrammer工具的“+”按钮,然后选择烧录配置的tvs文件。
|
||||
|
||||

|
||||
|
||||
4. 点击Browse按钮,然后选择工程源码下的烧录镜像路径
|
||||
|
||||

|
||||
|
||||
5. 点击Download按钮启动镜像烧录,并等待烧录完毕。
|
||||
|
||||

|
||||
|
||||
### 四、启动开发板进入终端
|
||||
|
||||
1. 打开MobaXterm,
|
||||
|
||||
1. 点击:`Session`、`Serial`按钮
|
||||
|
||||
2. 设置Seral port为 第一-4 查看到的COM号
|
||||
|
||||
3. 设置Speed为 `115200`
|
||||
|
||||
4. 点击`OK`
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
3. 将开发板的拨码开关拨至“010”emmc启动模式,并按一下开发板的“RESET”按钮复位开发板。
|
||||
|
||||

|
||||
|
||||
4. MobaXterm上打印出运行日志,等待启动日志运行结束,按键盘“回车”按键进入开发板shell终端,输入例如"ls"命令,可与开发板交互。
|
||||
|
||||

|
||||
|
||||
5. 开发板屏幕出现桌面及预安装的"setting"应用,点击"setting"应用可查看系统信息。
|
||||
|
||||

|
||||
@@ -0,0 +1,342 @@
|
||||
# BearPi-HM_Micro开发环境搭建<a name="ZH-CN_TOPIC_0000001054781998"></a>
|
||||
|
||||
## 环境要求<a name="section466851916410"></a>
|
||||
|
||||
### 硬件要求<a name="section07318322310"></a>
|
||||
|
||||
- Linux服务器
|
||||
- Windows工作台(主机电脑)
|
||||
- BearPi-HM_Micro开发板
|
||||
- USB Type-C线(Windows工作台通过USB与BearPi-HM_Micr开发板连接)
|
||||
|
||||
|
||||
### 软件系统要求<a name="section182305581332"></a>
|
||||
|
||||
**表 1** BearPi-HM_Micro开发板开发平台要求
|
||||
|
||||
<a name="tc50585b2b3fe43f7835154789b0e25af"></a>
|
||||
<table><thead align="left"><tr id="ra9df6acc53154b819d5f86d885d994de"><th class="cellrowborder" valign="top" width="12.41%" id="mcps1.2.5.1.1"><p id="a999bb40532eb4f74a7383e1e776bb94a"><a name="a999bb40532eb4f74a7383e1e776bb94a"></a><a name="a999bb40532eb4f74a7383e1e776bb94a"></a>硬件</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="12.389999999999999%" id="mcps1.2.5.1.2"><p id="ae63cf791fbe348d3b907d20fc4927df8"><a name="ae63cf791fbe348d3b907d20fc4927df8"></a><a name="ae63cf791fbe348d3b907d20fc4927df8"></a>软件</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="46.21%" id="mcps1.2.5.1.3"><p id="a54c4c80c43c84cb187342865a1d2b51e"><a name="a54c4c80c43c84cb187342865a1d2b51e"></a><a name="a54c4c80c43c84cb187342865a1d2b51e"></a>描述</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="28.99%" id="mcps1.2.5.1.4"><p id="a11e8d096fb204378a63d8805cd6d1f88"><a name="a11e8d096fb204378a63d8805cd6d1f88"></a><a name="a11e8d096fb204378a63d8805cd6d1f88"></a>备注</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row117591159175819"><td class="cellrowborder" valign="top" width="12.41%" headers="mcps1.2.5.1.1 "><p id="a0c1290183f2548898dbfc516a4db2c4b"><a name="a0c1290183f2548898dbfc516a4db2c4b"></a><a name="a0c1290183f2548898dbfc516a4db2c4b"></a>Linux编译服务器</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="12.389999999999999%" headers="mcps1.2.5.1.2 "><p id="a687efa8001f140488dc1da9a2ee8f6d1"><a name="a687efa8001f140488dc1da9a2ee8f6d1"></a><a name="a687efa8001f140488dc1da9a2ee8f6d1"></a>操作系统</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="46.21%" headers="mcps1.2.5.1.3 "><p id="ace724e00c9094eccb8c600d6ad426ed8"><a name="ace724e00c9094eccb8c600d6ad426ed8"></a><a name="ace724e00c9094eccb8c600d6ad426ed8"></a>Ubuntu16.04及以上64位系统版本,Shell使用bash</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="2" valign="top" width="28.99%" headers="mcps1.2.5.1.4 "><p id="a4d0e2c8444484554ab58949ce322be32"><a name="a4d0e2c8444484554ab58949ce322be32"></a><a name="a4d0e2c8444484554ab58949ce322be32"></a>开发人员可以在Windows工作台中进行程序开发,或者远程登录到Linux服务器进行程序开发。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r85c4bf56ff3244e48db9d2f5b622b340"><td class="cellrowborder" valign="top" headers="mcps1.2.5.1.1 "><p id="a8e99fd0262cb4489b70cf86c2144c294"><a name="a8e99fd0262cb4489b70cf86c2144c294"></a><a name="a8e99fd0262cb4489b70cf86c2144c294"></a>Windows工作台</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.5.1.2 "><p id="a44d6164ce2e9421f9ade362f600c2815"><a name="a44d6164ce2e9421f9ade362f600c2815"></a><a name="a44d6164ce2e9421f9ade362f600c2815"></a>操作系统</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.5.1.3 "><p id="a1c17349e334a44ada5c5f150457fe17d"><a name="a1c17349e334a44ada5c5f150457fe17d"></a><a name="a1c17349e334a44ada5c5f150457fe17d"></a>Windows XP/Windows7/Windows10</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Linux构建工具要求<a name="section20374218687"></a>
|
||||
|
||||
Linux服务器通用环境配置需要的工具及其获取途径如下表所示。
|
||||
|
||||
**表 2** Linux服务器开发工具及获取途径
|
||||
|
||||
<a name="table6299192712513"></a>
|
||||
<table><thead align="left"><tr id="row122993276512"><th class="cellrowborder" valign="top" width="25.562556255625562%" id="mcps1.2.4.1.1"><p id="p1829914271858"><a name="p1829914271858"></a><a name="p1829914271858"></a>开发工具</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="20.7020702070207%" id="mcps1.2.4.1.2"><p id="p429918274517"><a name="p429918274517"></a><a name="p429918274517"></a>用途</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="53.73537353735374%" id="mcps1.2.4.1.3"><p id="p12997271757"><a name="p12997271757"></a><a name="p12997271757"></a>获取途径</p>
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
<tr id="row430016273514"><td class="cellrowborder" valign="top" width="25.562556255625562%" headers="mcps1.2.4.1.1 "><p id="p330015271158"><a name="p330015271158"></a><a name="p330015271158"></a>Python3.7+</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="20.7020702070207%" headers="mcps1.2.4.1.2 "><p id="p43003270510"><a name="p43003270510"></a><a name="p43003270510"></a>编译构建工具</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="53.73537353735374%" headers="mcps1.2.4.1.3 "><p id="p18254155164617"><a name="p18254155164617"></a><a name="p18254155164617"></a><a href="https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz" target="_blank" rel="noopener noreferrer">https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz</a></p>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr id="row42668197206"><td class="cellrowborder" valign="top" width="25.562556255625562%" headers="mcps1.2.4.1.1 "><p id="p426711912014"><a name="p426711912014"></a><a name="p426711912014"></a>bash</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="20.7020702070207%" headers="mcps1.2.4.1.2 "><p id="p14267131962014"><a name="p14267131962014"></a><a name="p14267131962014"></a>命令处理器</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="53.73537353735374%" headers="mcps1.2.4.1.3 "><p id="p14267101962014"><a name="p14267101962014"></a><a name="p14267101962014"></a>通过互联网获取</p>
|
||||
</td>
|
||||
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Windows开发工具要求<a name="section11161833102716"></a>
|
||||
|
||||
**表 3** Windows工作台开发工具及获取途径
|
||||
|
||||
<a name="table1313323311274"></a>
|
||||
<table><thead align="left"><tr id="row3133133312711"><th class="cellrowborder" valign="top" width="16.371637163716375%" id="mcps1.2.4.1.1"><p id="p16132203372716"><a name="p16132203372716"></a><a name="p16132203372716"></a>开发工具</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="50.29502950295029%" id="mcps1.2.4.1.2"><p id="p1413219339278"><a name="p1413219339278"></a><a name="p1413219339278"></a>用途</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p17133183312711"><a name="p17133183312711"></a><a name="p17133183312711"></a>获取途径</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row138432533451"><td class="cellrowborder" valign="top" width="16.371637163716375%" headers="mcps1.2.4.1.1 "><p id="p163612016916"><a name="p163612016916"></a><a name="p163612016916"></a>Visual Studio Code</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50.29502950295029%" headers="mcps1.2.4.1.2 "><p id="p1563690791"><a name="p1563690791"></a><a name="p1563690791"></a>代码编辑工具。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p146361701097"><a name="p146361701097"></a><a name="p146361701097"></a><a href="https://code.visualstudio.com/" target="_blank" rel="noopener noreferrer">https://code.visualstudio.com/</a></p>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr id="row18342145821513"><td class="cellrowborder" valign="top" width="16.371637163716375%" headers="mcps1.2.4.1.1 "><p id="p123421958131517"><a name="p123421958131517"></a><a name="p123421958131517"></a>MobaXterm、PuTTY或其他超级终端(选其一)</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50.29502950295029%" headers="mcps1.2.4.1.2 "><p id="p18342658131511"><a name="p18342658131511"></a><a name="p18342658131511"></a>远程连接Linux编译服务器,连接模组串口工具。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p17342125851518"><a name="p17342125851518"></a><a name="p17342125851518"></a>通过互联网获取(如:<a href="https://mobaxterm.mobatek.net/" target="_blank" rel="noopener noreferrer">https://mobaxterm.mobatek.net/</a>)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row244884215147"><td class="cellrowborder" valign="top" width="16.371637163716375%" headers="mcps1.2.4.1.1 "><p id="p1044974291416"><a name="p1044974291416"></a><a name="p1044974291416"></a>CH341SER.EXE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50.29502950295029%" headers="mcps1.2.4.1.2 "><p id="p94491342131413"><a name="p94491342131413"></a><a name="p94491342131413"></a>USB转串口驱动。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p6449184214148"><a name="p6449184214148"></a><a name="p6449184214148"></a><a href="http://www.wch.cn/search?q=ch340g&t=downloads" target="_blank" rel="noopener noreferrer">http://www.wch.cn/search?q=ch340g&t=downloads</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row18342145821513"><td class="cellrowborder" valign="top" width="16.371637163716375%" headers="mcps1.2.4.1.1 "><p id="p123421958131517"><a name="p123421958131517"></a><a name="p123421958131517"></a>STM32CubeProgrammer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50.29502950295029%" headers="mcps1.2.4.1.2 "><p id="p18342658131511"><a name="p18342658131511"></a><a name="p18342658131511"></a>代码烧录工具。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p6449184214148"><a name="p6449184214148"></a><a name="p6449184214148"></a><a href="https://pan.baidu.com/s/1XfFFFs7UdE9TPdN0FdA6ag" target="_blank" rel="noopener noreferrer">https://pan.baidu.com/s/1XfFFFs7UdE9TPdN0FdA6ag</a>密码:1234</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## 安装编译基础环境<a name="section497484245614"></a>
|
||||
|
||||
### 一、连接Linux服务器<a name="section15541530155711"></a>
|
||||
|
||||
使用Windows远程登录Linux,以MobaXterm工具为例:
|
||||
|
||||
1. 打开[MobaXterm工具](https://mobaxterm.mobatek.net/), 输入Linux服务器IP地址,后点击“OK”,打开连接。
|
||||
|
||||
**图 2** MobaXterm界面示例图<a name="f825e6d7569cc487db9b744e454c7157a"></a>
|
||||
|
||||

|
||||
|
||||
2. 弹框告警选择“是\(Y\)”。
|
||||
3. 弹出界面中输入账号并按回车键,继续输入密码并回车键。
|
||||
|
||||
**图 3** 登录界面图<a name="fe1428afffbdd45f9b4a39497691ff5ff"></a>
|
||||

|
||||
|
||||
4. 登录成功。
|
||||
|
||||
**图 4** 登录成功界面<a name="f11bea69483e14bd39fef4a10b1ed1a3a"></a>
|
||||

|
||||
|
||||
|
||||
### 二、将Linux shell改为bash<a name="section182814544221"></a>
|
||||
|
||||
查看shell是否为bash,在终端运行如下命令
|
||||
|
||||
```
|
||||
ls -l /bin/sh
|
||||
```
|
||||
|
||||
如果为显示为/bin/sh -\> bash则为正常,否则请按以下方式修改:
|
||||
|
||||
**方法一**:在终端运行如下命令,然后选择 no。
|
||||
|
||||
```
|
||||
sudo dpkg-reconfigure dash
|
||||
```
|
||||
|
||||
**方法二**:先删除sh,再创建软链接。
|
||||
|
||||
```
|
||||
rm -rf /bin/sh
|
||||
sudo ln -s /bin/bash /bin/sh
|
||||
```
|
||||
|
||||
### 三、修改镜像源(可选)
|
||||
|
||||
1. 打开/etc/apt路径下的sources.list文件
|
||||
|
||||

|
||||
|
||||
2. 将原本的镜像源改为中科大镜像源,然后关闭文件并保存
|
||||
|
||||

|
||||
|
||||
```
|
||||
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
|
||||
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
|
||||
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
|
||||
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
|
||||
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
|
||||
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||
```
|
||||
|
||||
3. 更新镜像源
|
||||
|
||||
```
|
||||
sudo apt-get update
|
||||
```
|
||||
### 四、安装必要的库和工具
|
||||
- 使用如下apt-get命令安装编译所需的必要的库和工具:
|
||||
|
||||
```
|
||||
sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi cpio device-tree-compiler net-tools openssh-server git vim openjdk-11-jre-headless
|
||||
```
|
||||
### 五、安装Python3
|
||||
|
||||
1. 打开Linux编译服务器终端。
|
||||
2. 输入如下命令,查看python版本号,若为python3.7+可跳过安装Python3步骤:
|
||||
|
||||
```
|
||||
python3 --version
|
||||
```
|
||||
|
||||
如果低于python3.7版本,不建议直接升级,请按照如下步骤重新安装。以python3.8为例,按照以下步骤安装python。
|
||||
|
||||
1. 运行如下命令,查看Ubuntu版本:
|
||||
|
||||
```
|
||||
cat /etc/issue
|
||||
```
|
||||
|
||||
2. 根据Ubuntu不同版本,安装python。
|
||||
- 如果Ubuntu 版本为18+,运行如下命令。
|
||||
|
||||
```
|
||||
sudo apt-get install python3.8
|
||||
```
|
||||
|
||||
- 如果Ubuntu版本为16。
|
||||
|
||||
a. 安装依赖包
|
||||
|
||||
```
|
||||
sudo apt update && sudo apt install software-properties-common
|
||||
```
|
||||
|
||||
b. 添加deadsnakes PPA 源,然后按回车键确认安装。
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
||||
```
|
||||
|
||||
c. 安装python3.8
|
||||
|
||||
```
|
||||
sudo apt upgrade && sudo apt install python3.8
|
||||
```
|
||||
|
||||
|
||||
3. 设置python和python3软链接为python3.8。
|
||||
|
||||
```
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
|
||||
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
|
||||
```
|
||||
|
||||
4. 安装并升级Python包管理工具(pip3),任选如下一种方式。
|
||||
- **命令行方式:**
|
||||
|
||||
```
|
||||
sudo apt-get install python3-setuptools python3-pip -y
|
||||
sudo pip3 install --upgrade pip
|
||||
```
|
||||
|
||||
- **安装包方式:**
|
||||
|
||||
```
|
||||
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
||||
python get-pip.py
|
||||
```
|
||||
|
||||
### 六、安装hb
|
||||
|
||||
1. 运行如下命令安装hb
|
||||
|
||||
```
|
||||
python3 -m pip install --user ohos-build
|
||||
```
|
||||
|
||||
2. 设置环境变量
|
||||
|
||||
```
|
||||
vim ~/.bashrc
|
||||
```
|
||||
|
||||
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
|
||||
|
||||
```
|
||||
export PATH=~/.local/bin:$PATH
|
||||
```
|
||||
|
||||
执行如下命令更新环境变量。
|
||||
|
||||
```
|
||||
source ~/.bashrc
|
||||
```
|
||||
3. 执行"hb -h",有打印以下信息即表示安装成功:
|
||||
|
||||
```
|
||||
usage: hb
|
||||
|
||||
OHOS build system
|
||||
|
||||
positional arguments:
|
||||
{build,set,env,clean}
|
||||
build Build source code
|
||||
set OHOS build settings
|
||||
env Show OHOS build env
|
||||
clean Clean output
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
```
|
||||
|
||||
### 七、把ubuntu文件远程映射到Windows上
|
||||
|
||||
1. 安装RaiDrive软件
|
||||
- 下载地址:https://forspeed.rbread05.cn/down/newdown/5/28/RaiDrive.rar
|
||||
|
||||
默认安装即可。
|
||||
|
||||
2. 打开软件切换为中文语言
|
||||
|
||||

|
||||
|
||||
3. 添加链接信息
|
||||
|
||||
* 取消勾选只读
|
||||
* SFTP://______ (这个输入 三.9 获取到的地址)
|
||||
* 账户:账号和密码皆为 bearpi
|
||||
* 其他默认
|
||||
* 点击`确定`
|
||||
|
||||

|
||||
|
||||
4. 查看本地映射的ubuntu文件路径
|
||||
|
||||

|
||||
|
||||
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 48 KiB |