mirror of
https://gitee.com/openharmony/applications_settings
synced 2024-11-22 22:09:58 +00:00
remove Sync postfix for adapting settingsdata api
Signed-off-by: yangpeng85 <yangpeng85@huawei.com>
This commit is contained in:
parent
7e5b214b2c
commit
262f543d1e
420
README.md
420
README.md
@ -1,400 +1,46 @@
|
||||
# Settings 源码开发说明
|
||||
# Settings<a name="EN-US_TOPIC_0000001103554544"></a>
|
||||
|
||||
## 1. 项目介绍
|
||||
Settings是基于 OpenHarmony 平台开发的基于OHOS提供基础设置功能。主要包括页面展示跳转逻辑、基础设置项(wifi设置、亮度设置、应用管理、日期和时间、关于手机)以及本设备其他应用设置项的收集、其他设备设置项收集的实现。项目采用MVVM架构模式,让各个层级之间不直接访问减少相互依赖。
|
||||
- [Introduction](#section11660541593)
|
||||
- [Architecture](#section48896451454)
|
||||
|
||||
Settings采用纯 ETS 语言开发,开发过程中不涉及任何 Java 部分的代码。
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## 2. 工程结构
|
||||
### 目录结构
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
The Settings is a system application prebuilt in OpenHarmony. It provides a human-machine interactions entry for users to set system configs like settings system time, lightness of screen and etc.
|
||||
|
||||
/applications/standard/settings
|
||||
├── entry # 主entry模块目录
|
||||
│ └── src
|
||||
│ ├── main
|
||||
│ ├── ets # ets模块目录
|
||||
│ ├── default
|
||||
│ ├── common # 公共工具存放目录
|
||||
│ ├── model # 数据管理和决策逻辑存放目录
|
||||
│ ├── pages # 组件页面存放目录
|
||||
│ ├── res # 部分图片资源
|
||||
│ ├── resources # 其它共用资源
|
||||
│ ├── app.ets # 全局ets逻辑和应用生命周期管理文件
|
||||
│ ├── resources # 资源配置文件存放目录
|
||||
│ ├── base # 默认语言场景,图片资源,字体大小,颜色资源内容存放目录
|
||||
│ ├── en_AS.element # 英文语言场景资源内容存放目录
|
||||
│ ├── rawfile # 本地配置文件存放目录
|
||||
│ ├── zh_CN.element # 中文语言场景资源内容存放目录
|
||||
│ └── config.json # 全局配置文件
|
||||
├── signature # 证书文件目录
|
||||
├── LICENSE # 许可文件
|
||||
### Architecture<a name="section48896451454"></a>
|
||||
|
||||
### 整体架构
|
||||
![](figures/en-us_image_0000001153225717.png)
|
||||
|
||||
![](./figures/en-us_image_0000001153225717.png)
|
||||
|
||||
设置 整体是 openHarmony 系统中预置的系统应用,为用户提供设置系统属性的交互界面。例如设置wifi状态,系统时间,屏幕亮度等系统属性。
|
||||
|
||||
Settings整体采用MVVM架构设计。关于MVVM架构中各层级的描述如下:
|
||||
|
||||
View:视图层,负责界面数据的展示,与用户进行交互。
|
||||
|
||||
ViewModel:视图模型,用UI Component将公用逻辑抽离,建立一套公用的ui引擎处理视图层(View)发送的业务逻辑处理请求,并连通 Model 层获取数据。
|
||||
|
||||
Model:模型层,负责处理数据,包括wifi的model,应用管理model,日期时间model等。
|
||||
|
||||
## 3. 代码使用
|
||||
### 代码下载
|
||||
基于L2的 Settings代码可以采用从码云上克隆的方式下载。
|
||||
[下载地址](https://gitee.com/openharmony/applications_settings)
|
||||
|
||||
#### 从码云克隆代码
|
||||
##### 1.配置SSH公钥
|
||||
1. 通过[登录网址](https://gitee.com/login)登录码云
|
||||
2. 在码云的个人设置中设置SSH公钥
|
||||
1. 生成SSH公私钥
|
||||
在命令窗口输入以下命令,邮箱地址替换为自己的邮箱地址,一直回车直至完成为止。
|
||||
```
|
||||
ssh-keygen -t rsa -C "xxxx@xxxx.com"
|
||||
```
|
||||
> 执行完成后,会在用户目录下的.ssh文件夹内生成 `id_rsa` 与 `id_rsa.pub` 两个文件,其中的 `id_rsa.pub` 即为生成的 SSH公钥
|
||||
>
|
||||
> ![](./figures/git_ssh_pub_key.png)
|
||||
>
|
||||
> 2. 复制公钥内容
|
||||
> 输入`cat .ssh/id_rsa.pub`,复制打印内容。
|
||||
> ![](./figures/3-1.png)
|
||||
> 3. 在设置->安全设置->SSH公钥 中设置 SSH公钥
|
||||
> 将第二步中复制的内容按照画面提示粘贴到码云上相应的内容区域,并点击确定。
|
||||
> ![](./figures/3-2.png)
|
||||
> 注意,在码云中,添加SSH公钥之后,需要进行账号的密码验证,验证通过才能成功添加。
|
||||
##### 2.下载代码
|
||||
1. 浏览器打开[下载地址](https://gitee.com/openharmony/applications_settings)。
|
||||
2. 点击“克隆/下载”按钮,选择 SSH,点击“复制”按钮。
|
||||
![](./figures/source_download_1.png)
|
||||
3. 在本地新建 Settings 目录,在 Settings 目录中执行如下命令
|
||||
```
|
||||
git clone 步骤2中复制的地址
|
||||
```
|
||||
|
||||
## 4. 基础开发说明
|
||||
|
||||
|
||||
### 多语言支持
|
||||
|
||||
#### 定义资源文件
|
||||
|
||||
- 在 `src/main/ets/resources/`目录下,根据不同的语言定义不同的文件夹下面的 `string.json` 资源文件。
|
||||
![](./figures/ds_i18n_files.png)
|
||||
|
||||
#### 引用资源
|
||||
|
||||
- 在对应ets文件中,可直接通过`$r()`引用。
|
||||
|
||||
````
|
||||
this.title = $r('app.string.world');
|
||||
this.icon = $r('app.media.icon');
|
||||
````
|
||||
|
||||
## 5. 典型接口的使用
|
||||
|
||||
1. 读取json配置文件
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
import fileio from '@ohos.fileio';
|
||||
|
||||
readLocalFile(fileName): any[]{
|
||||
try {
|
||||
let stream = FileIo.createStreamSync(fileName, 'r');
|
||||
LogUtil.info('settings readLocalFile stream:' + stream);
|
||||
let buf = new ArrayBuffer(4096);
|
||||
let len = stream.readSync(buf);
|
||||
LogUtil.info('settings readLocalFile len:' + len);
|
||||
let arr = new Uint8Array(buf);
|
||||
let charAt = ' '.charCodeAt(0);
|
||||
for (let i = len;i < 4096; i++) {
|
||||
arr[i] = charAt;
|
||||
}
|
||||
let content = String.fromCharCode.apply(null, arr);
|
||||
stream.closeSync();
|
||||
LogUtil.info('settings readLocalFile content:' + JSON.stringify(content));
|
||||
return JSON.parse(content);
|
||||
} catch (jsonError) {
|
||||
LogUtil.info('settings readLocalFile jsonError:' + jsonError);
|
||||
}
|
||||
}
|
||||
/applications/standard/settings
|
||||
├── entry # main entry module
|
||||
│ └── src
|
||||
│ ├── main
|
||||
│ ├── ets # ets module
|
||||
│ ├── default
|
||||
│ ├── common # common code and utils
|
||||
│ ├── model # data management and logic control
|
||||
│ ├── pages # code of view components
|
||||
│ ├── res # some image resources
|
||||
│ ├── resources # other resources
|
||||
│ ├── app.ets # main process
|
||||
│ ├── resources # resources configs
|
||||
│ ├── base # default language, image resources, font size and colors
|
||||
│ ├── en_AS.element # English resources
|
||||
│ ├── rawfile # local configs
|
||||
│ ├── zh_CN.element # Chinese resources
|
||||
│ └── config.json # global configs
|
||||
├── signature # Certificate files
|
||||
├── LICENSE # Copyright license file
|
||||
```
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
2. 查询所有应用信息
|
||||
|
||||
```
|
||||
import Bundle from '@ohos.bundle';
|
||||
|
||||
Bundle.getAllBundleInfo(0)
|
||||
.then((data) => {
|
||||
console.info('Settings getAllBundleInfo: '+JSON.stringify(data));
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
3. 获取wifi扫描信息
|
||||
|
||||
```
|
||||
import wifi_native_js from '@ohos.wifi_native_js';
|
||||
|
||||
getScanInfos() {
|
||||
wifi_native_js.getScanInfos(result => {
|
||||
this.animator_on = false;
|
||||
var clen = Object.keys(result).length;
|
||||
console.log("[wifi_js_test] wifi received scan info call back: " + clen);
|
||||
for (var j = 0; j < clen; j++) {
|
||||
console.log("result[0].ssid :" + result[j].ssid);
|
||||
console.info("securityType: " + result[j].securityType);
|
||||
console.info("rssi: " + result[j].rssi);
|
||||
console.info("band: " + result[j].band);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
4. Preferences 存取数据
|
||||
|
||||
```
|
||||
import storage from '@ohos.data.storage';
|
||||
// 数据存放路径
|
||||
const PREFERENCES_PATH = '/data/accounts/account_0/appdata/com.ohos.settings/sharedPreference/SettingsPreference';
|
||||
let mPreferences = Storage.getStorageSync(PREFERENCES_PATH);
|
||||
|
||||
save(key,value) {
|
||||
mPreferences.putSync(key, value);
|
||||
mPreferences.flushSync();
|
||||
}
|
||||
|
||||
get(key,defaultValue): any {
|
||||
return mPreferences.getSync(key, defaultValue);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## 6. 签名打包
|
||||
|
||||
### 签名
|
||||
|
||||
#### 签名文件的获取
|
||||
|
||||
1. 拷贝 OpenHarmony 标准版的 prebuilts\signcenter 目录到操作目录
|
||||
2. 拷贝Settings工程的 signature\settings.p7b 到该目录下
|
||||
|
||||
#### 签名文件的配置
|
||||
|
||||
打开项目工程,选择 File → Project Structure
|
||||
|
||||
![](./figures/signature_1.png)
|
||||
|
||||
选择 Modules → Signing Configs,将对应的签名文件配置如下,完成后点击Apply,再点击OK。
|
||||
|
||||
![](./figures/signature_2.png)
|
||||
|
||||
配置完成后,对应的build.gradle文件中会出现如下内容
|
||||
|
||||
![](./figures/signature_3.png)
|
||||
|
||||
### 打包
|
||||
|
||||
DevEco Studio 支持 debug 与 release 两种打包类型。可以在 OhosBuild Variants 窗口中进行切换。
|
||||
|
||||
![](./figures/ds_ohosbuild_variants.png)
|
||||
|
||||
#### debug打包
|
||||
|
||||
1. 代码准备完成后,在 OhosBuild Variants 窗口的 Selected Variant 中选择 debug。
|
||||
|
||||
![](./figures/ds_ohosbuild_variants_debug.png)
|
||||
|
||||
2. 选择Build → Build Haps(s)/APP(s) → Build Hap(s)
|
||||
|
||||
![](./figures/ds_build_haps.png)
|
||||
|
||||
3. 编译完成后,hap包会生成在工程目录下的 `\build\outputs\hap\debug\phone\`路径下(如果没有配置签名,则只会生成未签名的hap包)
|
||||
|
||||
![](./figures/ds_ohosbuild_output_dir.png)
|
||||
|
||||
#### release打包
|
||||
|
||||
1. 代码准备完成后,在 OhosBuild Variants 窗口的 Selected Variant 中选择 release
|
||||
|
||||
![](./figures/ds_ohosbuild_variants_release.png)
|
||||
|
||||
2. 选择Build → Build Haps(s)/APP(s) → Build Hap(s)
|
||||
|
||||
![](./figures/ds_build_haps.png)
|
||||
|
||||
3. 编译完成后,hap包会生成在工程目录下的 `\build\outputs\hap\release\phone\`路径下(如果没有配置签名,则只会生成未签名的hap包)
|
||||
|
||||
![](./figures/ds_ohosbuild_output_dir.png)
|
||||
|
||||
|
||||
|
||||
## 7. 安装、运行、调试
|
||||
|
||||
## 应用安装
|
||||
|
||||
配置 hdc:
|
||||
进入SDK目录中的toolchains文件夹下,获取文件路径:
|
||||
|
||||
![](./figures/sdk_catalogue.png)
|
||||
|
||||
> 注意,此处的hdc.exe如果版本较老,可能不能正常使用,需要获取新的hdc.exe文件
|
||||
|
||||
并将此路径配置到环境变量中:
|
||||
|
||||
![](./figures/sdk_environment_variable.png)
|
||||
|
||||
重启电脑使环境变量生效
|
||||
|
||||
连接开发板,打开cmd命令窗口,执行hdc list targets,弹出窗口如下:
|
||||
|
||||
![](./figures/cmd1.png)
|
||||
|
||||
等待一段时间后,窗口出现如下打印,可回到输入 hdc list targets 的命令窗口继续操作:
|
||||
|
||||
![](./figures/cmd2.png)
|
||||
|
||||
再次输入hdc list targets,出现如下结果,说明hdc连接成功
|
||||
|
||||
![](./figures/cmd3.png)
|
||||
|
||||
获取 root 权限与读写权限:
|
||||
|
||||
```
|
||||
hdc smode(当前版本可能仍不稳定,执行此命令可能导致后续的hdc target mount 失败,可不执行)
|
||||
hdc target mount(效果与remount类似)
|
||||
```
|
||||
|
||||
将签名好的 hap 包放入设备的 `/system/app` 目录下,并修改hap包的权限
|
||||
|
||||
```
|
||||
hdc file send 本地hap包路径 /system/app/hap包名称
|
||||
例如:hdc file send Settings.hap /system/app/Settings.hap
|
||||
```
|
||||
|
||||
> 注意,如果设备不存在 `/system/app` 目录,则需要手动创建该目录并修改权限。
|
||||
>
|
||||
> ```
|
||||
> hdc shell
|
||||
> cd system
|
||||
> mkdir app
|
||||
> chmod 777 app
|
||||
> ```
|
||||
>
|
||||
> `/system/app` 目录放置系统应用,例如:Launcher,SystemUI,Settings 等。
|
||||
>
|
||||
> 但hap包需要在该目录下手动设置权限
|
||||
>
|
||||
> ```
|
||||
> chmod 666 hap包名
|
||||
> ```
|
||||
>
|
||||
> 此目录应用不用手动安装,系统自动拉起。
|
||||
|
||||
## 应用运行
|
||||
|
||||
Settings 属于系统应用,在将签名的 hap 包放入 `/system/app` 目录后,重启系统,应用会自动拉起。
|
||||
|
||||
```
|
||||
hdc shell reboot (不可以直接执行hdc reboot,命令是无效的)
|
||||
```
|
||||
|
||||
> 注意,如果设备之前安装过系统应用,则需要执行如下两条命令清除设备中存储的应用信息,才能够在设备重启的时候将最新装入设备的新 hap 包正常拉起。
|
||||
>
|
||||
> ```
|
||||
> hdc shell rm -rf /data/misc_de/0/mdds/0/default/bundle_manager_service
|
||||
> hdc shell rm -rf /data/accounts
|
||||
> ```
|
||||
|
||||
## 应用调试
|
||||
|
||||
#### log打印
|
||||
- 在程序中添加 log
|
||||
```
|
||||
console.info("Setting log info");
|
||||
```
|
||||
#### log获取及过滤
|
||||
- log获取
|
||||
|
||||
将log输出至文件
|
||||
```
|
||||
hdc shell hilog > 输出文件名称
|
||||
```
|
||||
|
||||
例:
|
||||
在真实环境查看log,将全log输出到当前目录的hilog.log文件中
|
||||
|
||||
```
|
||||
hdc shell hilog > hilog.log
|
||||
```
|
||||
|
||||
- log过滤
|
||||
|
||||
在命令行窗口中过滤log
|
||||
```
|
||||
hilog | grep 过滤信息
|
||||
```
|
||||
|
||||
例:过滤包含信息 Label 的 hilog
|
||||
```
|
||||
hilog | grep Label
|
||||
```
|
||||
|
||||
## 8. 贡献代码
|
||||
|
||||
### Fork 代码仓库
|
||||
|
||||
1. 在码云上打开 Settings 代码仓库([仓库地址](https://gitee.com/openharmony/applications_settings))。
|
||||
2. 点击仓库右上角的 Forked 按钮
|
||||
![](./figures/commit_source_fork_button.png)
|
||||
3. 在弹出的画面中,选择将仓库 fork 到哪里,点击确认。
|
||||
![](./figures/commit_source_fork_confirm.png)
|
||||
4. Fork 成功之后,会在自己的账号下看见 fork 的代码仓库。
|
||||
![](./figures/commit_source_forked_repo1.png)
|
||||
|
||||
### 提交代码
|
||||
|
||||
1. 访问我们自己在码云账号上 fork 的代码仓库,点击“克隆/下载”按钮,选择 SSH,点击“复制”按钮。
|
||||
![](./figures/commit_source_clone_page.png)
|
||||
|
||||
2. 在本地新建 Settings 目录,在 Settings 目录中执行如下命令
|
||||
|
||||
```
|
||||
git clone 步骤1中复制的地址
|
||||
```
|
||||
|
||||
3. 修改代码。
|
||||
|
||||
> 将代码引入工程,以及编译工程等相关内容请参见 **3. 代码使用** 部分的相关内容。
|
||||
|
||||
4. 提交代码到 fork 仓库。
|
||||
|
||||
> 修改后的代码,首先执行 `git add` 命令,然后执行 `git commit -s` 命令与 `git push` 命令,将代码 push 到我们自己的 fork 仓中。
|
||||
> 关于代码提交的这部分内容涉及 git 的使用,可以参照 [git官网](https://git-scm.com/) 的内容,在此不再赘述。
|
||||
|
||||
### 发起 Pull Request (PR)
|
||||
|
||||
在将代码提交到 fork 仓之后,我们可以通过发起 Pull Request(PR)的方式来为 OpenHarmony 的相关项目贡献代码。
|
||||
|
||||
1. 打开 fork 仓库。选择 `Pull Requests` → `新建 Pull Request`
|
||||
|
||||
![](./figures/commit_source_new_pull_request.png)
|
||||
|
||||
2. 在 `新建 Pull Request` 画面填入标题与说明,点击 `创建` 按钮。
|
||||
|
||||
![](./figures/commit_source_new_pull_request_confirm.png)
|
||||
|
||||
3. 创建 Pull Request 完成。 PR 创建完成后,会有专门的代码审查人员对代码进行评审,评审通过之后会合入相应的代码库。
|
||||
|
||||
![](./figures/commit_source_new_pr_done.png)
|
||||
|
||||
系统应用
|
||||
System apps
|
||||
|
||||
**applications\_settings**
|
||||
|
||||
|
@ -12,7 +12,7 @@ ohos {
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
|
||||
url 'https://repo.ark.tools.huawei.com/artifactory/maven-public/'
|
||||
}
|
||||
maven {
|
||||
url 'https://mirrors.huaweicloud.com/repository/maven/'
|
||||
@ -30,7 +30,7 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
maven {
|
||||
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
|
||||
url 'https://repo.ark.tools.huawei.com/artifactory/maven-public/'
|
||||
}
|
||||
maven {
|
||||
url 'https://mirrors.huaweicloud.com/repository/maven/'
|
||||
|
20
common/component/build.gradle
Normal file
20
common/component/build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
apply plugin: 'com.huawei.ohos.library'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
22
common/component/src/main/config.json
Normal file
22
common/component/src/main/config.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.settings",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.settings.common",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "component",
|
||||
"moduleType": "har"
|
||||
}
|
||||
}
|
||||
}
|
@ -13,24 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class ConfigData {
|
||||
FILE_URI = '/data/accounts/account_0/applications/com.ohos.settings'
|
||||
+ '/com.ohos.settings/assets/entry/resources/rawfile/';
|
||||
PREFERENCES_PATH = '/data/accounts/account_0/appdata/com.ohos.settings/sharedPreference/SettingPreferences';
|
||||
BRIGHTNESS_SAVE_VALUE_KEY = 'BrightnessSaveValue';
|
||||
VOLUME_SAVE_VALUE_KEY = 'VolumeSaveValue';
|
||||
SENT_EVENT_BROADCAST_BRIGHTNESS_VALUE = 'BRIGHTNESS_VALUE';
|
||||
SENT_EVENT_BROADCAST_VOLUME_VALUE = 'VOLUME_VALUE';
|
||||
SENT_EVENT_WIFI_CONNECT_NAME = 'WIFI_CONNECT_NAME';
|
||||
BRIGHTNESS_DEFAULT_VALUE = 50;
|
||||
DEFAULT_BUNDLE_NAME = 'com.ohos.settings';
|
||||
DATE_AND_TIME_YEAR='DATE_AND_TIME_YEAR'
|
||||
DATE_AND_TIME_MONTH='DATE_AND_TIME_MONTH'
|
||||
DATE_AND_TIME_DAY='DATE_AND_TIME_DAY'
|
||||
TAG='Settings '
|
||||
|
||||
export class ComponentConfig {
|
||||
WH_100_100 = '100%';
|
||||
WH_30_100 = '30%';
|
||||
WH_33_100 = '33%';
|
||||
WH_35_100 = '35%';
|
||||
WH_40_100 = '40%';
|
||||
WH_45_100 = '45%';
|
||||
@ -48,6 +34,5 @@ export class ConfigData {
|
||||
DURATION_TIME = 200;
|
||||
}
|
||||
|
||||
let configData = new ConfigData();
|
||||
export default configData as ConfigData
|
||||
;
|
||||
let componentConfig = new ComponentConfig();
|
||||
export default componentConfig as ComponentConfig;
|
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import ISettingsController from './ISettingsController'
|
||||
|
||||
export default abstract class BaseSettingsController implements ISettingsController {
|
||||
protected getComponent: () => any;
|
||||
|
||||
/**
|
||||
* Bind component.
|
||||
*/
|
||||
bindComponent(component: any): ISettingsController{
|
||||
this.getComponent = () => component;
|
||||
|
||||
// set default property values by component
|
||||
for (var key in this) {
|
||||
if (key in component) {
|
||||
this[key] = component[key];
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind component's properties.
|
||||
*/
|
||||
bindProperties(componentProperties: string[], controllerProperties?: string[]): ISettingsController {
|
||||
for (let i = 0; i < componentProperties.length; i++) {
|
||||
this.defineBoundProperty(componentProperties[i], controllerProperties ? controllerProperties[i] : componentProperties[i]);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize data.
|
||||
*/
|
||||
initData(): ISettingsController {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribe listeners.
|
||||
*/
|
||||
subscribe(): ISettingsController {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unsubscribe listeners.
|
||||
*/
|
||||
unsubscribe(): ISettingsController {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Define bound properties.
|
||||
*/
|
||||
private defineBoundProperty(componentProperty: string, controllerProperty: string): void {
|
||||
let __v = this[controllerProperty];
|
||||
|
||||
Object.defineProperty(this, controllerProperty, {
|
||||
get: function () {
|
||||
return __v;
|
||||
},
|
||||
set: function (value) {
|
||||
__v = value;
|
||||
this.getComponent()[componentProperty] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export default interface ISettingsController {
|
||||
|
||||
/**
|
||||
* Bind component.
|
||||
*/
|
||||
bindComponent(component: any): ISettingsController;
|
||||
|
||||
/**
|
||||
* Bind component's properties.
|
||||
*/
|
||||
bindProperties(componentProperties: string[], controllerProperties?: string[]): ISettingsController
|
||||
|
||||
/**
|
||||
* Initialize data.
|
||||
*/
|
||||
initData(): ISettingsController;
|
||||
|
||||
/**
|
||||
* Subscribe listeners.
|
||||
*/
|
||||
subscribe(): ISettingsController;
|
||||
|
||||
/**
|
||||
* Unsubscribe listeners.
|
||||
*/
|
||||
unsubscribe(): ISettingsController;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseSettingsController from './BaseSettingsController.ets'
|
||||
|
||||
/**
|
||||
* Switch controller
|
||||
*/
|
||||
export default abstract class SwitchController extends BaseSettingsController {
|
||||
protected isOn: boolean = false;
|
||||
|
||||
/**
|
||||
* Set toggle value
|
||||
*/
|
||||
toggleValue(isOn: boolean) {
|
||||
this.isOn = new Boolean(isOn).valueOf()
|
||||
this.afterCurrentValueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* After current value changed
|
||||
*/
|
||||
abstract afterCurrentValueChanged();
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
|
||||
/**
|
||||
* item custom component
|
||||
@ -29,6 +29,9 @@ struct EntryComponent {
|
||||
@Prop settingArrow: string;
|
||||
@Prop settingArrowStyle: string;
|
||||
@Prop settingUri: string;
|
||||
@State titleFontColor: Color | number | string | Resource = $r('app.color.color_333333_grey');
|
||||
private enabled : boolean = true;
|
||||
private onArrowClick?: () => void;
|
||||
|
||||
build() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
||||
@ -41,10 +44,11 @@ struct EntryComponent {
|
||||
.objectFit(ImageFit.Contain);
|
||||
Column() {
|
||||
Text(this.settingTitle)
|
||||
.fontColor(this.titleFontColor)
|
||||
.fontColor($r('app.color.color_333333_grey'))
|
||||
.fontSize($r('app.float.font_20'))
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(ConfigData.MAX_LINES_3)
|
||||
.maxLines(ComponentConfig.MAX_LINES_3)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.margin({ top: $r('app.float.wh_value_10'), bottom: $r('app.float.wh_value_5') });
|
||||
Row() {
|
||||
@ -52,7 +56,7 @@ struct EntryComponent {
|
||||
.fontColor($r('app.color.color_999999_grey'))
|
||||
.fontSize($r('app.float.font_18'))
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(ConfigData.MAX_LINES_1)
|
||||
.maxLines(ComponentConfig.MAX_LINES_1)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.visibility('pages/applicationInfo' === this.settingUri ? Visibility.Visible : Visibility.None)
|
||||
.margin({ bottom: $r('app.float.wh_value_10') });
|
||||
@ -60,7 +64,7 @@ struct EntryComponent {
|
||||
.fontColor($r('app.color.color_999999_grey'))
|
||||
.fontSize($r('app.float.font_18'))
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(ConfigData.MAX_LINES_1)
|
||||
.maxLines(ComponentConfig.MAX_LINES_1)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.visibility('' === this.settingSummary || undefined === this.settingSummary ? Visibility.None : Visibility.Visible)
|
||||
.margin({ bottom: $r('app.float.wh_value_10') });
|
||||
@ -88,6 +92,6 @@ struct EntryComponent {
|
||||
.align(Alignment.End);
|
||||
}
|
||||
.margin({ left: $r('app.float.wh_value_15') })
|
||||
.width(ConfigData.WH_100_100);
|
||||
.enabled(this.enabled);
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
import Router from '@system.router';
|
||||
|
||||
/**
|
||||
@ -33,27 +33,32 @@ struct HeadComponent {
|
||||
.height($r('app.float.wh_value_50'))
|
||||
.borderRadius($r('app.float.wh_value_15'))
|
||||
.margin({
|
||||
left: $r('app.float.wh_value_15'),
|
||||
top: $r('app.float.wh_value_5'),
|
||||
bottom: $r('app.float.wh_value_5')
|
||||
})
|
||||
left: $r('app.float.wh_value_15'),
|
||||
top: $r('app.float.wh_value_5'),
|
||||
bottom: $r('app.float.wh_value_5')})
|
||||
.backgroundColor(this.isTouch ? $r('app.color.color_E3E3E3_grey') : $r('app.color.color_00000000_transparent'))
|
||||
.visibility(this.icBackIsVisibility ? Visibility.Visible : Visibility.None)
|
||||
.onTouch(() => {
|
||||
this.isTouch = true;
|
||||
AppStorage.SetOrCreate('wifiPsd', '');
|
||||
Router.back();
|
||||
})
|
||||
.onClick(()=>{
|
||||
Router.back();
|
||||
})
|
||||
.onTouch((event: TouchEvent) => {
|
||||
if (event.type === TouchType.Down) {
|
||||
this.isTouch = true;
|
||||
}
|
||||
if (event.type === TouchType.Up) {
|
||||
this.isTouch = false;
|
||||
}
|
||||
});
|
||||
Text(this.headName)
|
||||
.fontSize($r('app.float.font_24'))
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(Color.Black)
|
||||
.width(ConfigData.WH_90_100)
|
||||
.maxLines(ConfigData.MAX_LINES_1)
|
||||
.width(ComponentConfig.WH_90_100)
|
||||
.maxLines(ComponentConfig.MAX_LINES_1)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') });
|
||||
}
|
||||
.width(ConfigData.WH_100_100)
|
||||
.width(ComponentConfig.WH_100_100)
|
||||
.height($r('app.float.wh_value_70'))
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.align(Alignment.Start);
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
|
||||
/**
|
||||
* ImageAnimator component
|
||||
@ -22,7 +22,7 @@ export default
|
||||
struct ImageAnimatorComponent {
|
||||
@State imageWidth: number = 0
|
||||
@State imageHeight: number = 0
|
||||
@State whtl: number = ConfigData.value_20;
|
||||
@State whtl: number = ComponentConfig.value_20;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@ -30,7 +30,7 @@ struct ImageAnimatorComponent {
|
||||
.images([
|
||||
{
|
||||
src: 'res/image/xxxhdpi/ic_loading01.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
||||
@ -38,7 +38,7 @@ struct ImageAnimatorComponent {
|
||||
},
|
||||
{
|
||||
src: 'res/image/xxxhdpi/ic_loading02.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
||||
@ -46,7 +46,7 @@ struct ImageAnimatorComponent {
|
||||
},
|
||||
{
|
||||
src: 'res/image/xxxhdpi/ic_loading03.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
||||
@ -54,7 +54,7 @@ struct ImageAnimatorComponent {
|
||||
},
|
||||
{
|
||||
src: 'res/image/xxxhdpi/ic_loading04.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
||||
@ -62,7 +62,7 @@ struct ImageAnimatorComponent {
|
||||
},
|
||||
{
|
||||
src: 'res/image/xxxhdpi/ic_loading05.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
||||
@ -70,7 +70,7 @@ struct ImageAnimatorComponent {
|
||||
},
|
||||
{
|
||||
src: 'res/image/hdpi/ic_loading06.png',
|
||||
duration: ConfigData.DURATION_TIME,
|
||||
duration: ComponentConfig.DURATION_TIME,
|
||||
width: this.whtl,
|
||||
height: this.whtl,
|
||||
top: this.whtl,
|
135
common/component/src/main/ets/default/radioListComponent.ets
Normal file
135
common/component/src/main/ets/default/radioListComponent.ets
Normal file
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
import LogUtil from '../../../../../utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
/**
|
||||
* Radio component
|
||||
*/
|
||||
@Component
|
||||
export default
|
||||
struct RadioListComponent {
|
||||
@State dataList: any[] = [];
|
||||
@State checkedValue: string = '';
|
||||
private showRadio: boolean = true;
|
||||
private onChange?: (item : any) => void;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
List() {
|
||||
ForEach(this.dataList, (item: any) => {
|
||||
ListItem() {
|
||||
RadioComponent({
|
||||
settingIcon: item.settingIcon,
|
||||
settingTitle: item.settingTitle,
|
||||
settingSummary: item.settingSummary,
|
||||
settingValue: item.settingValue,
|
||||
showRadio: this.showRadio,
|
||||
isChecked: (this.checkedValue == item.settingValue),
|
||||
onChange:() => {
|
||||
this.checkedValue = item.settingValue;
|
||||
if (this.onChange) {
|
||||
LogUtil.info('settings RadioListComponent : onChange: settingValue = ' + item.settingValue)
|
||||
this.onChange(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
.height(item.settingIcon ? $r('app.float.audio_no_icon_height') : $r('app.float.audio_icon_height'));
|
||||
});
|
||||
}
|
||||
.divider({
|
||||
strokeWidth: 1,
|
||||
color: $r('app.color.color_E3E3E3_grey'),
|
||||
startMargin: $r('app.float.audio_start_end_margin_left'),
|
||||
endMargin: $r('app.float.audio_start_end_margin_left')
|
||||
})
|
||||
.width(ComponentConfig.WH_100_100)
|
||||
.alignSelf(ItemAlign.Start);
|
||||
}
|
||||
.width(ComponentConfig.WH_100_100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set up radio component
|
||||
*/
|
||||
@Component
|
||||
struct RadioComponent {
|
||||
private settingIcon: string = '';
|
||||
private settingTitle: string = '';
|
||||
private settingSummary: string = '';
|
||||
private settingValue: string = '';
|
||||
private isChecked: boolean = false;
|
||||
private onChange?: () => void;
|
||||
private showRadio: boolean = true;
|
||||
|
||||
build() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
||||
Row() {
|
||||
Image(this.settingIcon)
|
||||
.width($r('app.float.audio_image_common_size'))
|
||||
.height($r('app.float.audio_image_common_size'))
|
||||
.margin({ right: $r('app.float.audio_image_margin_right') })
|
||||
.visibility(this.settingIcon ? Visibility.Visible : Visibility.None)
|
||||
.objectFit(ImageFit.Contain);
|
||||
Column() {
|
||||
Text(this.settingTitle)
|
||||
.fontColor($r('app.color.color_333333_grey'))
|
||||
.fontSize($r('app.float.control_common_font_size'))
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(ComponentConfig.MAX_LINES_3)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.margin({ top: $r('app.float.audio_subtitle_margin_top'), bottom: $r('app.float.audio_subtitle_margin_bottom') });
|
||||
|
||||
Text(this.settingSummary)
|
||||
.fontColor($r('app.color.color_999999_grey'))
|
||||
.fontSize($r('app.float.audio_subtitle_font_size'))
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(ComponentConfig.MAX_LINES_1)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.visibility(this.settingSummary ? Visibility.Visible : Visibility.None)
|
||||
.margin({ bottom: $r('app.float.audio_summary_subtitle_margin_bottom') });
|
||||
}
|
||||
.margin({ left: $r('app.float.audio_title_summary_margin_left') })
|
||||
.alignItems(HorizontalAlign.Start);
|
||||
}
|
||||
.flexShrink(0)
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.align(Alignment.Start);
|
||||
|
||||
Row() {
|
||||
Radio( {value: this.settingValue} )
|
||||
.height($r('app.float.radio_component_height'))
|
||||
.margin({ right: $r('app.float.radio_component_margin_bottom_right') })
|
||||
.align(Alignment.End)
|
||||
.enabled(false)
|
||||
.checked(this.isChecked)
|
||||
.visibility(this.showRadio ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
.align(Alignment.End);
|
||||
}
|
||||
.margin({ left: $r('app.float.audio_margin_left') })
|
||||
.width(ComponentConfig.WH_100_100)
|
||||
.onClick(() => {
|
||||
LogUtil.info('settings RadioComponent : call onClick.')
|
||||
if (this.onChange) {
|
||||
this.onChange()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
103
common/component/src/main/ets/default/sliderComponent.ets
Normal file
103
common/component/src/main/ets/default/sliderComponent.ets
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
|
||||
/**
|
||||
* Slider component
|
||||
*/
|
||||
@Component
|
||||
export default struct SliderComponent {
|
||||
private visible: boolean = true;
|
||||
private min: number = 0;
|
||||
private max: number = 100;
|
||||
private step?: number = 1;
|
||||
private leftImage: string = '';
|
||||
private rightImage: string = '';
|
||||
@State clickConfirm: boolean = true;
|
||||
@State showStep: boolean = false;
|
||||
@State value: number = 0;
|
||||
private onChange?: (value: number, mode: SliderChangeMode) => void
|
||||
private summary: string | Resource; // Text details
|
||||
@State fontSize: number = 18; // Font size
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Row }) {
|
||||
Column() {
|
||||
Image(this.leftImage)
|
||||
.width($r('app.float.slider_image_width'))
|
||||
.height($r('app.float.slider_image_height'))
|
||||
.objectFit(ImageFit.Contain);
|
||||
}.align(Alignment.TopStart).visibility(this.visible ? Visibility.Visible : Visibility.None)
|
||||
.padding({ left: $r('app.float.slider_image_margin') })
|
||||
.onClick(() => {
|
||||
if (this.value != this.min && this.clickConfirm) {
|
||||
this.value = Math.max(this.min, this.value - this.step);
|
||||
this.onChangeHandler(this.value, SliderChangeMode.END);
|
||||
}
|
||||
}).align(Alignment.Center)
|
||||
|
||||
Column() {
|
||||
Row() {
|
||||
Text(this.summary)
|
||||
.fontSize(this.fontSize)
|
||||
.textAlign(TextAlign.Start);
|
||||
}
|
||||
.width(ComponentConfig.WH_83_100)
|
||||
|
||||
Slider({
|
||||
value: this.value,
|
||||
min: this.min,
|
||||
max: this.max,
|
||||
step: this.step
|
||||
})
|
||||
.selectedColor(Color.Blue)
|
||||
.blockColor(Color.Blue)
|
||||
.width(ComponentConfig.WH_100_100)
|
||||
.showSteps(this.showStep)
|
||||
.onChange((value, mode) => {
|
||||
this.onChangeHandler(value, mode)
|
||||
});
|
||||
}.align(Alignment.Center).flexGrow(1)
|
||||
|
||||
Column() {
|
||||
Image(this.rightImage)
|
||||
.width($r('app.float.slider_image_width'))
|
||||
.height($r('app.float.slider_image_height'))
|
||||
.align(Alignment.Start)
|
||||
.objectFit(ImageFit.Contain);
|
||||
}.align(Alignment.TopEnd).visibility(this.visible ? Visibility.Visible : Visibility.None)
|
||||
.padding({ right: $r('app.float.slider_image_margin') })
|
||||
.onClick(() => {
|
||||
if (this.value != this.max && this.clickConfirm) {
|
||||
this.value = Math.min(this.max, this.value + this.step);
|
||||
this.onChangeHandler(this.value, SliderChangeMode.END);
|
||||
}
|
||||
}).align(Alignment.Center)
|
||||
|
||||
}.width(ComponentConfig.WH_100_100).align(Alignment.TopStart)
|
||||
}
|
||||
|
||||
/**
|
||||
* Change handler
|
||||
*
|
||||
* @param value - Change value
|
||||
* @param mode - State
|
||||
*/
|
||||
onChangeHandler(value, mode) {
|
||||
if (this.onChange) {
|
||||
this.onChange(value, mode);
|
||||
}
|
||||
}
|
||||
}
|
92
common/component/src/main/ets/default/switchComponent.ets
Normal file
92
common/component/src/main/ets/default/switchComponent.ets
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
import SwitchController from './controller/switchController.ets'
|
||||
|
||||
/**
|
||||
* Toggle component
|
||||
*/
|
||||
@Component
|
||||
export default struct SwitchComponent {
|
||||
@Link isOn: boolean;
|
||||
@Prop title: string;
|
||||
private toggleValue: (isOn: boolean) => void;
|
||||
private controller: SwitchController;
|
||||
private cssValue: {
|
||||
fontSize?: number | string | Resource,
|
||||
height?: number | string | Resource,
|
||||
width?: number | string | Resource,
|
||||
margin?: {
|
||||
top?: number | string | Resource,
|
||||
right?: number | string | Resource,
|
||||
bottom?: number | string | Resource,
|
||||
left?: number | string | Resource
|
||||
} | number | string | Resource,
|
||||
padding: {
|
||||
top?: number | string | Resource,
|
||||
right?: number | string | Resource,
|
||||
bottom?: number | string | Resource,
|
||||
left?: number | string | Resource
|
||||
} | number | string | Resource,
|
||||
};
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
|
||||
Text(this.title)
|
||||
.cssSwitchComponentTiTle(this.cssValue?.fontSize)
|
||||
Toggle({ type: ToggleType.Switch, isOn: this.isOn })
|
||||
.cssSwitchComponentToggle()
|
||||
.onChange((isOn: boolean) => {
|
||||
this.isOn = new Boolean(isOn).valueOf();
|
||||
if (this.toggleValue) {
|
||||
this.toggleValue(isOn);
|
||||
}
|
||||
});
|
||||
}
|
||||
.cssSwitchComponentFlex(this.cssValue?.margin, this.cssValue?.padding, this.cssValue?.width, this.cssValue?.height);
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
if (this.controller) {
|
||||
// bind event handlers
|
||||
this.toggleValue = this.controller.toggleValue.bind(this.controller);
|
||||
|
||||
// bind component and initialize
|
||||
this.controller.bindComponent(this)
|
||||
.bindProperties(["isOn"])
|
||||
.initData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Extend(Text) function cssSwitchComponentTiTle (fontSize: number | string | Resource=$r('app.float.switch_title_subtitle_size')) {
|
||||
.fontColor(Color.Black)
|
||||
.fontStyle(FontStyle.Normal)
|
||||
.padding({ left: $r('app.float.switch_component_margin') })
|
||||
.fontSize(fontSize)
|
||||
}
|
||||
|
||||
@Extend(Toggle) function cssSwitchComponentToggle () {
|
||||
.width($r('app.float.switch_toggle_width'))
|
||||
.height($r('app.float.switch_toggle_height'))
|
||||
.padding({ right: $r('app.float.switch_component_margin') })
|
||||
}
|
||||
|
||||
@Extend(Flex) function cssSwitchComponentFlex (margin: any, padding: any, width: number | string | Resource=ComponentConfig.WH_100_100, height: number | string | Resource=$r('app.float.switch_component_height')) {
|
||||
.width(width)
|
||||
.height(height)
|
||||
.margin(margin)
|
||||
.padding(padding)
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import ComponentConfig from './ComponentConfig.ets';
|
||||
|
||||
/**
|
||||
* TextInput component
|
||||
@ -30,7 +30,7 @@ export default struct textInputComponent {
|
||||
.height($r('app.float.wh_value_70'))
|
||||
.backgroundColor(Color.White)
|
||||
.type(InputType.Password)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.width(ComponentConfig.WH_100_100)
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') })
|
||||
.onChange((value: string) => {
|
||||
this.contextText = value;
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"string": [
|
||||
]
|
||||
}
|
20
common/search/build.gradle
Normal file
20
common/search/build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
apply plugin: 'com.huawei.ohos.library'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
1
common/search/proguard-rules.pro
vendored
Normal file
1
common/search/proguard-rules.pro
vendored
Normal file
@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
22
common/search/src/main/config.json
Normal file
22
common/search/src/main/config.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.settings",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.settings.common",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "search",
|
||||
"moduleType": "har"
|
||||
}
|
||||
}
|
||||
}
|
50
common/search/src/main/ets/default/common/ResourceUtil.ets
Normal file
50
common/search/src/main/ets/default/common/ResourceUtil.ets
Normal file
@ -0,0 +1,50 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ConfigData from '../../../../../../utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import ResMgr from '@ohos.resourceManager';
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
/**
|
||||
* Resource util
|
||||
*/
|
||||
export class ResourceUtil {
|
||||
private resMgr: ResMgr.ResourceManager;
|
||||
|
||||
/**
|
||||
* Initialize ResourceManager
|
||||
*/
|
||||
@Log
|
||||
async initResourceManager(): Promise<void> {
|
||||
if (!this.resMgr) {
|
||||
this.resMgr = await ResMgr.getResourceManager(ConfigData.DEFAULT_BUNDLE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string value from NormalResource instance
|
||||
*
|
||||
* @param resource - NormalResource instance
|
||||
*/
|
||||
@Log
|
||||
async getString(resource): Promise<string> {
|
||||
await this.initResourceManager();
|
||||
return await this.resMgr.getString(resource.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let resourceUtil = new ResourceUtil();
|
||||
export default resourceUtil as ResourceUtil;
|
41
common/search/src/main/ets/default/common/SearchConfig.ets
Normal file
41
common/search/src/main/ets/default/common/SearchConfig.ets
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search config
|
||||
*/
|
||||
export default {
|
||||
RDB_NAME: 'settings.db',
|
||||
search: {
|
||||
TABLE_NAME: 'SEARCH_DATA',
|
||||
FIELD_ID: 'ID',
|
||||
FIELD_ICON: 'ICON',
|
||||
FIELD_TITLE: 'TITLE',
|
||||
FIELD_KEYWORD: 'KEYWORD',
|
||||
FIELD_SUMMARY: 'SUMMARY',
|
||||
FIELD_SYNONYM: 'SYNONYM',
|
||||
FIELD_URI: 'URI',
|
||||
DDL_TABLE_CREATE: 'CREATE TABLE IF NOT EXISTS SEARCH_DATA (' +
|
||||
'ID INTEGER PRIMARY KEY AUTOINCREMENT, ' +
|
||||
'URI VARCHAR(200) NOT NULL, ' +
|
||||
'ICON VARCHAR(200), ' +
|
||||
'TITLE TEXT NOT NULL COLLATE NOCASE, ' +
|
||||
'KEYWORD TEXT NOT NULL COLLATE NOCASE, ' +
|
||||
'SUMMARY TEXT, ' +
|
||||
'SYNONYM TEXT )',
|
||||
SQL_DELETE_ALL: 'DELETE FROM SEARCH_DATA',
|
||||
PATH_SEPARATOR: ' > '
|
||||
}
|
||||
}
|
77
common/search/src/main/ets/default/common/SearchUtil.ets
Normal file
77
common/search/src/main/ets/default/common/SearchUtil.ets
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import SearchData from '../model/SearchData';
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import ResourceUtil from './ResourceUtil.ets';
|
||||
|
||||
/**
|
||||
* Search util
|
||||
*/
|
||||
export class SearchUtil {
|
||||
|
||||
/**
|
||||
* Convert json to instance
|
||||
*/
|
||||
@Log
|
||||
convertJsonToInstance<T> (json: any, t: {new(): T}): T {
|
||||
var instance = new t();
|
||||
|
||||
for (var key in json) {
|
||||
if (instance.hasOwnProperty(key)) {
|
||||
instance[key] = json[key];
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert json to SearchData instance
|
||||
*/
|
||||
@Log
|
||||
async convertToSearchData(rawData): Promise<SearchData[]> {
|
||||
let result: Array<SearchData> = [];
|
||||
|
||||
for (let jsonData of rawData.data) {
|
||||
let searchData: SearchData = new SearchData();
|
||||
searchData.title = await ResourceUtil.getString(rawData.title);
|
||||
searchData.keyword = await ResourceUtil.getString(jsonData.keyword);
|
||||
searchData.summary = jsonData.summary ? await ResourceUtil.getString(jsonData.summary) : jsonData.summary;
|
||||
searchData.synonym = jsonData.synonym ? await ResourceUtil.getString(jsonData.synonym) : jsonData.synonym;
|
||||
|
||||
result.push(searchData);
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete illegal characters from search keyword
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
stripKeyword(text: string): string {
|
||||
var pattern = new RegExp("[`~!@#$%^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
|
||||
var rs = "";
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
rs = rs + text.substr(i, 1).replace(pattern, '');
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let searchUtil = new SearchUtil();
|
||||
export default searchUtil as SearchUtil;
|
29
common/search/src/main/ets/default/model/SearchData.ts
Normal file
29
common/search/src/main/ets/default/model/SearchData.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search data dto class
|
||||
*/
|
||||
export default class SearchData {
|
||||
uri: string = '';
|
||||
icon: string = '';
|
||||
title: string = '';
|
||||
keyword: string = '';
|
||||
summary: string = '';
|
||||
synonym: string = '';
|
||||
|
||||
constructor() {
|
||||
}
|
||||
}
|
220
common/search/src/main/ets/default/model/SearchModel.ets
Normal file
220
common/search/src/main/ets/default/model/SearchModel.ets
Normal file
@ -0,0 +1,220 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ConfigData from '../../../../../../utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import { BaseData } from '../../../../../../utils/src/main/ets/default/model/BaseData.ets';
|
||||
import LogUtil from '../../../../../../utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import SearchConfig from '../common/SearchConfig.ets';
|
||||
import SearchData from '../model/SearchData';
|
||||
import SearchDataProvider from '../provider/SearchDataProvider';
|
||||
import BaseParseConfModel from '../../../../../../utils/src/main/ets/default/model/BaseParseConfModel.ets';
|
||||
import ohosDataRdb from '@ohos.data.rdb';
|
||||
|
||||
/**
|
||||
* Search service class
|
||||
*/
|
||||
export default class SearchModel {
|
||||
private rdbStore;
|
||||
private searchDataConfig;
|
||||
|
||||
constructor(configData: Array<Object>) {
|
||||
this.searchDataConfig = configData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize rdb
|
||||
*/
|
||||
@Log
|
||||
private async initRdb(): Promise<void> {
|
||||
LogUtil.log('settings initRdb.');
|
||||
|
||||
if (!this.rdbStore) {
|
||||
LogUtil.log('settings RDB has not been initialized yet.');
|
||||
|
||||
// database init
|
||||
const STORE_CONFIG = { name: SearchConfig.RDB_NAME};
|
||||
this.rdbStore = await ohosDataRdb.getRdbStore(STORE_CONFIG, 1);
|
||||
LogUtil.log('settings SettingsSearch.db is ready.');
|
||||
|
||||
// table SEARCH_DATA init
|
||||
await this.rdbStore.executeSql(SearchConfig.search.DDL_TABLE_CREATE, null);
|
||||
console.log('settings table SEARCH_DATA is ready.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize search data
|
||||
*/
|
||||
@Log
|
||||
public async initSearchData(): Promise<void> {
|
||||
const searchData = await this.gatherSearchData();
|
||||
await this.initRdbSearchData(searchData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @param query - query content
|
||||
*/
|
||||
@Log
|
||||
public async search(query: string): Promise<SearchData[]> {
|
||||
if (!query) {
|
||||
return []
|
||||
}
|
||||
|
||||
await this.initRdb();
|
||||
|
||||
// query search data
|
||||
let predicates = new ohosDataRdb.RdbPredicates(SearchConfig.search.TABLE_NAME);
|
||||
predicates.like(SearchConfig.search.FIELD_KEYWORD, `%${query}%`)
|
||||
.or().like(SearchConfig.search.FIELD_SUMMARY, `%${query}%`)
|
||||
.or().like(SearchConfig.search.FIELD_SYNONYM, `%${query}%`)
|
||||
.orderByAsc(SearchConfig.search.FIELD_URI);
|
||||
|
||||
let resultSet = await this.rdbStore.query(predicates, [
|
||||
SearchConfig.search.FIELD_ICON,
|
||||
SearchConfig.search.FIELD_TITLE,
|
||||
SearchConfig.search.FIELD_KEYWORD,
|
||||
SearchConfig.search.FIELD_SUMMARY,
|
||||
SearchConfig.search.FIELD_URI
|
||||
]);
|
||||
|
||||
// build search data from resultSet
|
||||
let searchData: SearchData[] = [];
|
||||
while (resultSet.goToNextRow()) {
|
||||
const data = new SearchData();
|
||||
data.icon = resultSet.getString(0);
|
||||
data.title = resultSet.getString(1);
|
||||
data.keyword = resultSet.getString(2);
|
||||
data.summary = resultSet.getString(3);
|
||||
data.uri = resultSet.getString(4);
|
||||
searchData.push(data);
|
||||
}
|
||||
resultSet.close();
|
||||
resultSet = null;
|
||||
|
||||
return searchData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather search data from providers
|
||||
*
|
||||
* @param searchData - search data to be grouped
|
||||
*/
|
||||
@Log
|
||||
private async gatherSearchData(): Promise<SearchData[]> {
|
||||
// init uriConfigMapping
|
||||
const uriConfigMapping = new Map();
|
||||
this.searchDataConfig.forEach(config => {
|
||||
uriConfigMapping.set(config.settingUri, config);
|
||||
})
|
||||
|
||||
// get searchData (note: settingList must be the first)
|
||||
let searchData: SearchData[] = await this.getSearchData(this.searchDataConfig[0].settingUri, '', uriConfigMapping);
|
||||
LogUtil.log('settings search searchData: ' + JSON.stringify(searchData));
|
||||
|
||||
return searchData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize rdb search data
|
||||
*
|
||||
* @param searchData - search data
|
||||
*/
|
||||
@Log
|
||||
private async initRdbSearchData(searchData: SearchData[]): Promise<void> {
|
||||
LogUtil.log('settings search old data if exists.');
|
||||
await this.initRdb();
|
||||
|
||||
// delete old data if exists
|
||||
await this.rdbStore.executeSql(SearchConfig.search.SQL_DELETE_ALL, null);
|
||||
LogUtil.log('settings search old data if exists.');
|
||||
|
||||
// insert new data into table
|
||||
for (let data of searchData) {
|
||||
const valueBucket = {};
|
||||
valueBucket[SearchConfig.search.FIELD_URI] = data.uri;
|
||||
valueBucket[SearchConfig.search.FIELD_ICON] = data.icon;
|
||||
valueBucket[SearchConfig.search.FIELD_TITLE] = data.title;
|
||||
valueBucket[SearchConfig.search.FIELD_KEYWORD] = data.keyword;
|
||||
valueBucket[SearchConfig.search.FIELD_SUMMARY] = data.summary;
|
||||
valueBucket[SearchConfig.search.FIELD_SYNONYM] = data.synonym;
|
||||
let ret = await this.rdbStore.insert(SearchConfig.search.TABLE_NAME, valueBucket)
|
||||
LogUtil.log("settings: search insert data: " + ret)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search data
|
||||
*
|
||||
* @param settingUri - setting uri
|
||||
* @param settingIcon - setting icon
|
||||
* @param uriConfigMapping - uri config mapping
|
||||
*/
|
||||
@Log
|
||||
private async getSearchData(settingUri: string, settingIcon: string, uriConfigMapping: Map<string, any>): Promise<SearchData[]> {
|
||||
if (!uriConfigMapping.get(settingUri)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// get search data from provider
|
||||
const provider: SearchDataProvider = uriConfigMapping.get(settingUri).provider;
|
||||
let searchProviderData: SearchData[] = await provider.getSearchData();
|
||||
|
||||
// set uri, icon
|
||||
searchProviderData.forEach(providerData => {
|
||||
if (!providerData.uri) {
|
||||
providerData.uri = settingUri;
|
||||
}
|
||||
providerData.icon = settingIcon;
|
||||
});
|
||||
|
||||
// get setting list
|
||||
let settingConfig = ConfigData.FILE_URI.concat(uriConfigMapping.get(settingUri).settingRawJson)
|
||||
let settingList: BaseData[] = this.getSettingList(settingConfig);
|
||||
|
||||
// get child page search
|
||||
for (const setting of settingList) {
|
||||
const icon = settingIcon ? settingIcon : setting.settingIcon; // higher priority for parent icon
|
||||
const childData = await this.getSearchData(setting.settingUri, icon, uriConfigMapping);
|
||||
searchProviderData = searchProviderData.concat(childData);
|
||||
};
|
||||
|
||||
return searchProviderData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting list which includes settingUri in each setting
|
||||
*
|
||||
* @param settingConfig - setting config path
|
||||
*/
|
||||
@Log
|
||||
private getSettingList(settingConfig: string): BaseData[] {
|
||||
let result = [];
|
||||
|
||||
let settingList: any[] = BaseParseConfModel.getJsonData(settingConfig);
|
||||
settingList.forEach(setting => {
|
||||
if (setting.settingUri) {
|
||||
let baseData = new BaseData();
|
||||
baseData.settingIcon = setting.settingIcon;
|
||||
baseData.settingUri = setting.settingUri;
|
||||
result.push(baseData);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
135
common/search/src/main/ets/default/page/resultComponent.ets
Normal file
135
common/search/src/main/ets/default/page/resultComponent.ets
Normal file
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import SearchData from '../model/SearchData';
|
||||
import LogUtil from '../../../../../../utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import ConfigData from '../../../../../../utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
/**
|
||||
* result component
|
||||
*/
|
||||
@Component
|
||||
export default struct ResultComponent {
|
||||
private TEXT_TYPE_NORMAL = 1
|
||||
private TEXT_TYPE_KEYWORD = 2
|
||||
@Link highlightKeyword: string
|
||||
@State icon: string = ''
|
||||
@State data: SearchData = new SearchData()
|
||||
|
||||
@Builder HighlightText(
|
||||
spans: string[],
|
||||
fontColor: Color | Resource,
|
||||
fontSize: Resource,
|
||||
highlightFontColor: Color | Resource) {
|
||||
|
||||
Text() {
|
||||
ForEach(spans.map((item1, index1) => {
|
||||
return { index: index1, data: item1 };
|
||||
}), item => {
|
||||
|
||||
if (item.data.type == this.TEXT_TYPE_NORMAL) {
|
||||
Span(item.data.text).fontColor(fontColor).fontSize(fontSize)
|
||||
} else if (item.data.type == this.TEXT_TYPE_KEYWORD) {
|
||||
Span(item.data.text).fontColor(highlightFontColor).fontSize(fontSize)
|
||||
}
|
||||
},
|
||||
item => item.index)
|
||||
}
|
||||
.textAlign(TextAlign.Start)
|
||||
.maxLines(3)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.margin({ top: $r('app.float.wh_value_10'), bottom: $r('app.float.wh_value_5') })
|
||||
}
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Image(this.icon)
|
||||
.width($r('app.float.wh_value_50'))
|
||||
.height($r('app.float.wh_value_50'))
|
||||
.margin({ right: $r('app.float.wh_value_10') })
|
||||
.visibility(this.icon ? Visibility.Visible : Visibility.Hidden)
|
||||
.objectFit(ImageFit.Contain);
|
||||
|
||||
Column() {
|
||||
this.HighlightText(
|
||||
this.splitToHighlightText(this.data.keyword),
|
||||
$r('app.color.color_333333_grey'),
|
||||
$r('app.float.search_result_item_title_font_size'),
|
||||
Color.Blue
|
||||
)
|
||||
|
||||
if (this.data.summary) {
|
||||
this.HighlightText(
|
||||
this.splitToHighlightText(this.data.summary),
|
||||
$r('app.color.color_666666_grey'),
|
||||
$r('app.float.search_result_item_summary_font_size'),
|
||||
Color.Blue
|
||||
)
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.alignItems(HorizontalAlign.Start);
|
||||
|
||||
Image("/res/image/ic_settings_arrow.svg")
|
||||
.width($r('app.float.wh_value_40'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
}
|
||||
.padding({
|
||||
left: $r('app.float.item_common_horizontal_margin'),
|
||||
right: $r('app.float.item_common_horizontal_margin')
|
||||
})
|
||||
.flexShrink(0)
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.align(Alignment.Start)
|
||||
}
|
||||
|
||||
/**
|
||||
* split to highlight text
|
||||
* @param text
|
||||
*/
|
||||
@Log
|
||||
splitToHighlightText(text: string): any[] {
|
||||
let spans: any[] = []
|
||||
|
||||
var lowerSpans: string[] = text.toLowerCase().split(this.highlightKeyword.toLowerCase())
|
||||
var keywordStartIndex = 0
|
||||
var keywordLength = this.highlightKeyword.length
|
||||
|
||||
for (var i = 0; i < lowerSpans.length; i++) {
|
||||
var normalText = text.substr(keywordStartIndex, lowerSpans[i].length)
|
||||
spans.push({
|
||||
type: this.TEXT_TYPE_NORMAL,
|
||||
text: normalText
|
||||
})
|
||||
LogUtil.debug(ConfigData.TAG + 'ResultComponent splitToHighlightText : i = [' + i + '] push normal : ' +
|
||||
JSON.stringify(normalText));
|
||||
|
||||
// if not at last, append highlight keyword
|
||||
if (i != lowerSpans.length - 1) {
|
||||
keywordStartIndex += lowerSpans[i].length
|
||||
var keywordText = text.substr(keywordStartIndex, keywordLength)
|
||||
spans.push({
|
||||
type: this.TEXT_TYPE_KEYWORD,
|
||||
text: keywordText
|
||||
})
|
||||
LogUtil.debug(ConfigData.TAG + 'ResultComponent splitToHighlightText : i = [' + i + '] push keyword : ' +
|
||||
JSON.stringify(keywordText));
|
||||
keywordStartIndex += keywordLength
|
||||
}
|
||||
}
|
||||
|
||||
return spans
|
||||
}
|
||||
}
|
85
common/search/src/main/ets/default/page/searchHeader.ets
Normal file
85
common/search/src/main/ets/default/page/searchHeader.ets
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ResourceUtil from '../common/ResourceUtil.ets';
|
||||
import LogUtil from '../../../../../../utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import ConfigData from '../../../../../../utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import Router from '@system.router'
|
||||
|
||||
/**
|
||||
* Search header component
|
||||
*/
|
||||
@Component
|
||||
export default struct SearchHeader {
|
||||
@Link inputKeyword: string
|
||||
@State placeholder: string = ''
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
|
||||
// back
|
||||
Image($r('app.media.ic_back'))
|
||||
.width($r('app.float.wh_value_50'))
|
||||
.height($r('app.float.wh_value_50'))
|
||||
.objectFit(ImageFit.Contain)
|
||||
.onClick(() => {
|
||||
LogUtil.debug(ConfigData.TAG + 'searchPage SearchHeader : back clicked.');
|
||||
Router.back()
|
||||
})
|
||||
|
||||
// text input
|
||||
Stack({ alignContent: Alignment.End }) {
|
||||
TextInput({ placeholder: this.placeholder, text: this.inputKeyword })
|
||||
.margin({
|
||||
left: $r('app.float.search_input_horizontal_margin'),
|
||||
right: $r('app.float.search_input_horizontal_margin')
|
||||
})
|
||||
.placeholderFont({size:10,weight:FontWeight.Normal,style:FontStyle.Normal})
|
||||
.type(InputType.Normal)
|
||||
.enterKeyType(EnterKeyType.Search)
|
||||
.layoutWeight(1)
|
||||
.height($r("app.float.search_input_height"))
|
||||
.borderRadius($r("app.float.search_input_border_radius"))
|
||||
.backgroundColor(Color.White)
|
||||
.onChange((value: string) => {
|
||||
LogUtil.debug(ConfigData.TAG + 'searchPage SearchHeader : text input on change :value = ' + JSON.stringify(value));
|
||||
this.inputKeyword = value
|
||||
})
|
||||
|
||||
if (this.inputKeyword) {
|
||||
|
||||
// input text clear
|
||||
Text('×')
|
||||
.fontSize($r('app.float.font_28'))
|
||||
.width($r('app.float.wh_value_60'))
|
||||
.height($r('app.float.wh_value_60'))
|
||||
.backgroundColor($r('app.color.color_00000000_transparent'))
|
||||
.textAlign(TextAlign.Center)
|
||||
.onClick(() => {
|
||||
LogUtil.debug(ConfigData.TAG + 'searchPage SearchHeader : clear search key clicked.');
|
||||
this.inputKeyword = ''
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
.height($r('app.float.page_header_height'))
|
||||
.padding({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_60') })
|
||||
}
|
||||
|
||||
@Log
|
||||
aboutToAppear() {
|
||||
ResourceUtil.getString($r("app.string.searchHint")).then(value => this.placeholder = value)
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import Log from '../../../../../../utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import SearchUtil from '../common/SearchUtil.ets';
|
||||
import SearchData from '../model/SearchData';
|
||||
import SearchDataProvider from './SearchDataProvider';
|
||||
|
||||
/**
|
||||
* Page search data provider
|
||||
*/
|
||||
export default abstract class PageSearchDataProvider implements SearchDataProvider {
|
||||
abstract getPageSearchData(): any;
|
||||
|
||||
/**
|
||||
* Get search data
|
||||
*/
|
||||
@Log
|
||||
async getSearchData(): Promise<SearchData[]> {
|
||||
return await SearchUtil.convertToSearchData(this.getPageSearchData());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import SearchData from '../model/SearchData';
|
||||
|
||||
/**
|
||||
* Search data provider
|
||||
*/
|
||||
export default interface SearchDataProvider {
|
||||
|
||||
/**
|
||||
* Get search data
|
||||
*/
|
||||
getSearchData(): Promise<SearchData[]>;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"string": [
|
||||
]
|
||||
}
|
20
common/settingsBase/build.gradle
Normal file
20
common/settingsBase/build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
apply plugin: 'com.huawei.ohos.library'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
1
common/settingsBase/proguard-rules.pro
vendored
Normal file
1
common/settingsBase/proguard-rules.pro
vendored
Normal file
@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
22
common/settingsBase/src/main/config.json
Normal file
22
common/settingsBase/src/main/config.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.settings",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.settings.common",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "settingsBase",
|
||||
"moduleType": "har"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"string": [
|
||||
]
|
||||
}
|
20
common/utils/build.gradle
Normal file
20
common/utils/build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
apply plugin: 'com.huawei.ohos.library'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
1
common/utils/proguard-rules.pro
vendored
Normal file
1
common/utils/proguard-rules.pro
vendored
Normal file
@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
22
common/utils/src/main/config.json
Normal file
22
common/utils/src/main/config.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.settings",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.settings.common",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "utils",
|
||||
"moduleType": "har"
|
||||
}
|
||||
}
|
||||
}
|
95
common/utils/src/main/ets/default/baseUtil/ConfigData.ets
Normal file
95
common/utils/src/main/ets/default/baseUtil/ConfigData.ets
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export class ConfigData {
|
||||
FILE_URI = '/data/accounts/account_0/applications/com.ohos.settings'
|
||||
+ '/com.ohos.settings/assets/phone/resources/rawfile/';
|
||||
PREFERENCES_PATH = '/data/accounts/account_0/appdata/com.ohos.settings/sharedPreference/SettingPreferences';
|
||||
BRIGHTNESS_SAVE_VALUE_KEY = 'BrightnessSaveValue';
|
||||
|
||||
SENT_EVENT_BROADCAST_BRIGHTNESS_VALUE = 'BRIGHTNESS_VALUE';
|
||||
SENT_EVENT_BROADCAST_VOLUME_VALUE = 'VOLUME_VALUE';
|
||||
SENT_EVENT_WIFI_CONNECT_NAME = 'WIFI_CONNECT_NAME';
|
||||
SENT_EVENT_AUDIO_RINGER_MODE = 'AUDIO_RINGER_MODE';
|
||||
SENT_EVENT_AUDIO_VOLUME_VALUE = 'AUDIO_VOLUME_VALUE';
|
||||
|
||||
BRIGHTNESS_DEFAULT_VALUE = 50;
|
||||
DEFAULT_BUNDLE_NAME = 'com.ohos.settings';
|
||||
DATE_AND_TIME_YEAR='DATE_AND_TIME_YEAR'
|
||||
DATE_AND_TIME_MONTH='DATE_AND_TIME_MONTH'
|
||||
DATE_AND_TIME_DAY='DATE_AND_TIME_DAY'
|
||||
TAG='Settings '
|
||||
|
||||
// page request
|
||||
PAGE_REQUEST_CODE_KEY = 'pageRequestCode'
|
||||
PAGE_RESULT_KEY = 'pageResult'
|
||||
PAGE_RESULT_OK = -1
|
||||
PAGE_RESULT_NG = 0
|
||||
|
||||
// password request code
|
||||
PAGE_REQUEST_CODE_PASSWORD_FACE = 10001
|
||||
PAGE_REQUEST_CODE_PASSWORD_CREATE = 20001
|
||||
PAGE_REQUEST_CODE_PASSWORD_CHANGE = 20003
|
||||
PAGE_REQUEST_CODE_PASSWORD_DISABLE = 20004
|
||||
|
||||
WH_100_100 = '100%';
|
||||
WH_30_100 = '30%';
|
||||
WH_33_100 = '33%';
|
||||
WH_35_100 = '35%';
|
||||
WH_40_100 = '40%';
|
||||
WH_45_100 = '45%';
|
||||
WH_50_100 = '50%';
|
||||
WH_55_100 = '55%';
|
||||
WH_83_100 = '83%';
|
||||
WH_90_100 = '90%';
|
||||
|
||||
value_20 = 20;
|
||||
font_20 = 20;
|
||||
|
||||
MAX_LINES_1 = 1;
|
||||
MAX_LINES_2 = 2;
|
||||
MAX_LINES_3 = 3;
|
||||
DURATION_TIME = 200;
|
||||
FUNCTION_TYPE_HDC = 4;
|
||||
|
||||
TIME_FORMAT_24 = "24";
|
||||
TIME_FORMAT_12 = "12";
|
||||
TIME_PREFIX_MORNING = "上午" ;
|
||||
TIME_PREFIX_AFTERNOON = "下午";
|
||||
TIME_FORMAT_URI = "dataability:///com.ohos.settingsdata.DataAbility";
|
||||
TIME_FORMAT_KEY = 'settings.time.format';
|
||||
SETTINGSDATA_BRIGHTNESS = 'settings.screen.brightness';
|
||||
SETTINGSDATA_VOLUME_RINGTONE = 'settings.audio.ringtone';
|
||||
SETTINGSDATA_VOLUME_MEDIA = 'settings.audio.media';
|
||||
SETTINGSDATA_VOLUME_CALL = 'settings.audio.voicecall';
|
||||
SLIDER_CHANG_MODE_MOVING = 1;
|
||||
SLIDER_CHANG_MODE_END = 2;
|
||||
|
||||
//Language And Region
|
||||
ADDLANGUAGES = 'addedLanguages';
|
||||
CURRENTREGION = 'currentRegion';
|
||||
|
||||
//Storage Path
|
||||
STORAGEPATH = '/data/accounts/account_0/appdata/com.ohos.settings/files';
|
||||
|
||||
//StartAbility
|
||||
FACEAUTH_BUNDLE_NAME = 'com.ohos.settings.faceauth';
|
||||
FACEAUTH_ABILITY_NAME = 'com.ohos.settings.faceauth.enrollmentstartview';
|
||||
PERMISSION_MANAGER_BUNDLE_NAME = 'com.ohos.permissionmanager';
|
||||
PERMISSION_MANAGER_ABILITY_NAME = 'com.ohos.permissionmanager.MainAbility';
|
||||
}
|
||||
|
||||
let configData = new ConfigData();
|
||||
export default configData as ConfigData;
|
@ -17,13 +17,24 @@
|
||||
*/
|
||||
|
||||
import ConfigData from './ConfigData.ets';
|
||||
import BrightnessSettingModel from '../../model/brightnessImpl/BrightnessSettingModel.ets';
|
||||
import PreferenceUtil from './PreferenceUtil.ets';
|
||||
|
||||
export class DateAndTimeUtil {
|
||||
getSystemTime() {
|
||||
getSystemTime(isUsing24hFormat: boolean) {
|
||||
let datetime = new Date();
|
||||
let hours = datetime.getHours();
|
||||
let minutes = datetime.getMinutes();
|
||||
|
||||
let time = this.concatTime(hours, minutes)
|
||||
if (isUsing24hFormat === false) {
|
||||
if (hours < 12) {
|
||||
time = ConfigData.TIME_PREFIX_MORNING + this.concatTime(hours, minutes);
|
||||
} else if (hours === 12) {
|
||||
time = ConfigData.TIME_PREFIX_AFTERNOON + this.concatTime(hours, minutes);
|
||||
} else {
|
||||
time = ConfigData.TIME_PREFIX_AFTERNOON + this.concatTime((hours % 12), minutes);
|
||||
}
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
@ -41,9 +52,9 @@ export class DateAndTimeUtil {
|
||||
};
|
||||
|
||||
concatDate(year, month, date) {
|
||||
let nYear = BrightnessSettingModel.getStorageValue(ConfigData.DATE_AND_TIME_YEAR,'');
|
||||
let nMonth = BrightnessSettingModel.getStorageValue(ConfigData.DATE_AND_TIME_MONTH,'');
|
||||
let nDay = BrightnessSettingModel.getStorageValue(ConfigData.DATE_AND_TIME_DAY,'');
|
||||
let nYear = PreferenceUtil.getStorageValue(ConfigData.DATE_AND_TIME_YEAR,'');
|
||||
let nMonth = PreferenceUtil.getStorageValue(ConfigData.DATE_AND_TIME_MONTH,'');
|
||||
let nDay = PreferenceUtil.getStorageValue(ConfigData.DATE_AND_TIME_DAY,'');
|
||||
console.info('SettingList concatDate day:'+ nDay)
|
||||
return year + nYear + month + nMonth + date + nDay;
|
||||
};
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../../model/BaseModel.ets';
|
||||
import BaseModel from '../model/BaseModel.ets';
|
||||
import Rsm from '@ohos.resourceManager';
|
||||
import ConfigData from './ConfigData.ets';
|
||||
|
63
common/utils/src/main/ets/default/baseUtil/LogDecorator.ets
Normal file
63
common/utils/src/main/ets/default/baseUtil/LogDecorator.ets
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LogUtil from './LogUtil.ets';
|
||||
import ConfigData from './ConfigData.ets';
|
||||
|
||||
/**
|
||||
* Method log decorator
|
||||
*/
|
||||
const LogMethod = (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor): PropertyDescriptor => {
|
||||
const method = propertyDescriptor.value;
|
||||
|
||||
propertyDescriptor.value = function (...args: any[]) {
|
||||
const params = args.map(a => JSON.stringify(a)).join();
|
||||
LogUtil.info(ConfigData.TAG + `${target.constructor.name}#${methodName}(${params}) in `);
|
||||
|
||||
const result = method.apply(this, args);
|
||||
const r = JSON.stringify(result);
|
||||
|
||||
LogUtil.info(ConfigData.TAG + `${target.constructor.name}#${methodName}(${params}) out => ${r}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
return propertyDescriptor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Class decorator to log all methods
|
||||
*/
|
||||
export const LogAll = (target: any) => {
|
||||
Reflect.ownKeys(target.prototype).forEach(propertyKey => {
|
||||
let propertyDescriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(target.prototype, propertyKey);
|
||||
const method = propertyDescriptor.value;
|
||||
|
||||
if (method) {
|
||||
propertyDescriptor.value = function (...args: any[]) {
|
||||
const params = args.map(a => JSON.stringify(a)).join();
|
||||
LogUtil.info(ConfigData.TAG + `${target.name}#${propertyKey.toString()}(${params}) in `);
|
||||
|
||||
const result = method.apply(this, args);
|
||||
const r = JSON.stringify(result);
|
||||
|
||||
LogUtil.info(ConfigData.TAG + `${target.name}#${propertyKey.toString()}(${params}) out => ${r}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
Object.defineProperty(target.prototype, propertyKey, propertyDescriptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default LogMethod;
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../../model/BaseModel.ets';
|
||||
import BaseModel from '../model/BaseModel.ets';
|
||||
|
||||
/**
|
||||
* Log level
|
||||
@ -54,7 +54,6 @@ export class LogUtil extends BaseModel {
|
||||
|
||||
log(msg): void {
|
||||
console.log(msg);
|
||||
|
||||
}
|
||||
|
||||
info(msg): void {
|
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import ConfigData from './ConfigData.ets';
|
||||
import LogUtil from './LogUtil.ets'
|
||||
import Storage from '@ohos.data.storage';
|
||||
|
||||
let preference = Storage.getStorageSync(ConfigData.PREFERENCES_PATH);
|
||||
|
||||
export class PreferenceUtil {
|
||||
/**
|
||||
* Set up storage data
|
||||
*
|
||||
* @param key - key
|
||||
* @param value - value
|
||||
*/
|
||||
setStorageValue(key,value): void {
|
||||
LogUtil.info(`Set preference, key: ${key}, value: ${value}")`);
|
||||
preference.putSync(key, value);
|
||||
preference.flushSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored data
|
||||
*
|
||||
* @param key - key
|
||||
* @param defaultValue - defaultValue
|
||||
*/
|
||||
getStorageValue(key,defaultValue): any {
|
||||
let value = preference.getSync(key, defaultValue);
|
||||
LogUtil.info(`Get storage value, key: ${key}, value: ${value}`);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
let preferenceUtil = new PreferenceUtil();
|
||||
export default preferenceUtil as PreferenceUtil
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../../model/BaseModel.ets';
|
||||
import BaseModel from '../model/BaseModel.ets';
|
||||
import LogUtil from './LogUtil.ets';
|
||||
import ohosDataRdb from '@ohos.data.rdb';
|
||||
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ConfigData from './ConfigData.ets';
|
||||
import CommonEvent from '@ohos.commonevent';
|
||||
|
||||
let mCommonEventSubscribeInfo = {
|
||||
events: ['BRIGHTNESS_VALUE_SYSTEM_UI']
|
||||
};
|
||||
|
||||
let mCommonEventSubscriber = null;
|
||||
let mCustomStatusSubscriberCallBack = null;
|
||||
|
||||
/**
|
||||
* broadcast
|
||||
*/
|
||||
export class SubscriberUtils {
|
||||
/**
|
||||
* Send broadcast
|
||||
*
|
||||
* @param value - value
|
||||
* @param broadcastName - broadcastName
|
||||
*/
|
||||
sendEvent(value, broadcastName) {
|
||||
console.log(`settings SubscriberUtils sendEvent ets in value:` + value + "|broadcastName:" + broadcastName);
|
||||
let commonEventPublishData = {
|
||||
data: value
|
||||
};
|
||||
CommonEvent.publish(broadcastName, commonEventPublishData, (err, data) => {
|
||||
console.log(`settings SubscriberUtils sendEvent ets ${JSON.stringify(err)}`);
|
||||
console.log(`settings SubscriberUtils sendEvent ets ${JSON.stringify(data)}`);
|
||||
});
|
||||
console.log(`settings SubscriberUtils sendEvent ets out`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register to broadcast
|
||||
*/
|
||||
registerStatusListener(pCommonEventSubscribeInfo?, pCallback?) {
|
||||
console.info(`settings SubscriberUtils Subscriberregister status listener in`);
|
||||
|
||||
mCustomStatusSubscriberCallBack = pCallback;
|
||||
|
||||
var subscribeInfo = pCommonEventSubscribeInfo ? pCommonEventSubscribeInfo : mCommonEventSubscribeInfo;
|
||||
CommonEvent.createSubscriber(
|
||||
subscribeInfo,
|
||||
this.createStatusSubscriberCallBack.bind(this)
|
||||
);
|
||||
|
||||
console.info(`settings SubscriberUtils Subscriberregister status listener out`);
|
||||
}
|
||||
|
||||
createStatusSubscriberCallBack(err, data) {
|
||||
console.info(`settings SubscriberUtils Subscriberregister in ets ${JSON.stringify(err)} ${JSON.stringify(data)}`);
|
||||
mCommonEventSubscriber = data;
|
||||
CommonEvent.subscribe(mCommonEventSubscriber, this.statusSubscriberCallBack.bind(this));
|
||||
console.info(`settings SubscriberUtils Subscriberregister in`);
|
||||
}
|
||||
|
||||
statusSubscriberCallBack(err, data) {
|
||||
console.info(`settings SubscriberUtils statusSubscriberCallBack data ets : ${JSON.stringify(data)}`);
|
||||
console.info(`settings SubscriberUtils statusSubscriberCallBack err ets : ${JSON.stringify(err)}`);
|
||||
console.log(`settings SubscriberUtils statusSubscriberCallBack data.event ets : ${data.event} `);
|
||||
if (mCustomStatusSubscriberCallBack) {
|
||||
mCustomStatusSubscriberCallBack(err, data);
|
||||
}
|
||||
if (err) {
|
||||
console.info(`settings SubscriberUtils statusSubscriberCallBack error : ${err}`)
|
||||
return;
|
||||
}
|
||||
console.log(`settings SubscriberUtils statusSubscriberCallBack out`);
|
||||
}
|
||||
|
||||
/**
|
||||
* unRegister to broadcast
|
||||
*/
|
||||
unSubscriberListener() {
|
||||
CommonEvent.unsubscribe(mCommonEventSubscriber, () => {
|
||||
console.info('settings SubscriberUtils unSubscriberListener');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let subscriberUtils = new SubscriberUtils();
|
||||
export default subscriberUtils as SubscriberUtils;
|
@ -12,8 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../BaseModel.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import BaseModel from './BaseModel.ets';
|
||||
import LogUtil from '../baseUtil/LogUtil.ets';
|
||||
import FileIo from '@ohos.fileio';
|
||||
|
||||
const DFAULT_SIZE = 4096;
|
70
common/utils/src/main/ets/default/model/BasicDataSource.ets
Normal file
70
common/utils/src/main/ets/default/model/BasicDataSource.ets
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
export default class BasicDataSource implements IDataSource {
|
||||
private listeners: DataChangeListener[] = [];
|
||||
|
||||
public totalCount(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public getData(index: number): any {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
if (this.listeners.indexOf(listener) < 0) {
|
||||
this.listeners.push(listener);
|
||||
}
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const position = this.listeners.indexOf(listener);
|
||||
if (position >= 0) {
|
||||
this.listeners.splice(position, 1);
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataReload(): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataReloaded();
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataAdded(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataChange(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataChanged(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataDelete(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataDeleted(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataMove(from: number, to: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataMoved(from, to);
|
||||
})
|
||||
}
|
||||
}
|
4
common/utils/src/main/resources/base/element/string.json
Normal file
4
common/utils/src/main/resources/base/element/string.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"string": [
|
||||
]
|
||||
}
|
2
entry/.gitignore
vendored
2
entry/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/build
|
||||
/node_modules
|
@ -1,99 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BrightnessSettingModel from '../../model/brightnessImpl/BrightnessSettingModel.ets';
|
||||
import ConfigData from './ConfigData.ets';
|
||||
import CommonEvent from '@ohos.commonevent';
|
||||
|
||||
let mCommonEventSubscribeInfo = {
|
||||
events: ['BRIGHTNESS_VALUE_SYSTEM_UI','VOLUME_VALUE_SYSTEM_UI']
|
||||
};
|
||||
|
||||
let mCommonEventSubscriber = null;
|
||||
|
||||
/**
|
||||
* broadcast
|
||||
*/
|
||||
export class SubscriberUtils {
|
||||
/**
|
||||
* Send broadcast
|
||||
*
|
||||
* @param value - value
|
||||
* @param broadcastName - broadcastName
|
||||
*/
|
||||
sendEvent(value, broadcastName) {
|
||||
console.log(`settings settingList sendEvent ets in value:` + value + "|broadcastName:" + broadcastName);
|
||||
let commonEventPublishData = {
|
||||
data: value
|
||||
};
|
||||
CommonEvent.publish(broadcastName, commonEventPublishData, (err, data) => {
|
||||
console.log(`settings settingList sendEvent ets ${JSON.stringify(err)}`);
|
||||
console.log(`settings settingList sendEvent ets ${JSON.stringify(data)}`);
|
||||
});
|
||||
console.log(`settings settingList sendEvent ets out`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register to broadcast
|
||||
*/
|
||||
registerStatusListener() {
|
||||
console.info(`settings settingList Subscriberregister status listener in`);
|
||||
CommonEvent.createSubscriber(
|
||||
mCommonEventSubscribeInfo,
|
||||
this.createStatusSubscriberCallBack.bind(this)
|
||||
);
|
||||
console.info(`settings settingList Subscriberregister status listener out`);
|
||||
}
|
||||
|
||||
createStatusSubscriberCallBack(err, data) {
|
||||
console.info(`settings settingList Subscriberregister in ets ${JSON.stringify(err)} ${JSON.stringify(data)}`);
|
||||
mCommonEventSubscriber = data;
|
||||
CommonEvent.subscribe(mCommonEventSubscriber, this.statusSubscriberCallBack.bind(this));
|
||||
console.info(`settings settingList Subscriberregister in`);
|
||||
}
|
||||
|
||||
statusSubscriberCallBack(err, data) {
|
||||
console.info(`settings settingList statusSubscriberCallBack data ets : ${JSON.stringify(data)}`);
|
||||
console.info(`settings settingList statusSubscriberCallBack err ets : ${JSON.stringify(err)}`);
|
||||
console.log(`settings settingList statusSubscriberCallBack data.event ets : ${data.event} `);
|
||||
if ("BRIGHTNESS_VALUE_SYSTEM_UI" === data.event) {
|
||||
console.log(`settings settingList statusSubscriberCallBack data.data ets : ${data.data} `);
|
||||
let mBrightnessSetValue = AppStorage.SetAndLink('BrightnessSetValue', 150);
|
||||
mBrightnessSetValue.set(parseInt(data.data));
|
||||
BrightnessSettingModel.setBrightnessListener(parseInt(data.data));
|
||||
BrightnessSettingModel.setStorageValue(ConfigData.BRIGHTNESS_SAVE_VALUE_KEY,parseInt(data.data));
|
||||
} else if ("VOLUME_VALUE_SYSTEM_UI" === data.event) {
|
||||
console.log(`settings settingList statusSubscriberCallBack data.data volume : ${data.data} `);
|
||||
let mVolumeSetValue = AppStorage.SetAndLink('VolumeSetValue', 50);
|
||||
mVolumeSetValue.set(data.data);
|
||||
}
|
||||
if (err) {
|
||||
console.info(`settings settingList statusSubscriberCallBack error : ${err}`)
|
||||
return;
|
||||
}
|
||||
console.log(`settings settingList statusSubscriberCallBack out`);
|
||||
}
|
||||
|
||||
/**
|
||||
* unRegister to broadcast
|
||||
*/
|
||||
unSubscriberListener() {
|
||||
CommonEvent.unsubscribe(mCommonEventSubscriber, () => {
|
||||
console.info('settings settingList unSubscriberListener');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let subscriberUtils = new SubscriberUtils();
|
||||
export default subscriberUtils as SubscriberUtils;
|
@ -1,62 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../BaseModel.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import Brightness from '@ohos.brightness';
|
||||
import Storage from '@ohos.data.storage';
|
||||
|
||||
let mBrightnessPreferences = Storage.getStorageSync(ConfigData.PREFERENCES_PATH);
|
||||
|
||||
/**
|
||||
* Brightness setting
|
||||
*
|
||||
* @param brightnessValue - Brightness value
|
||||
*/
|
||||
export class BrightnessSettingModel extends BaseModel {
|
||||
setBrightnessListener(brightnessValue) {
|
||||
LogUtil.info('settings settingList BrightnessSettingModel Brightness:' + brightnessValue);
|
||||
Brightness.setValue(brightnessValue);
|
||||
LogUtil.info('settings settingList BrightnessSettingModel end');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up storage data
|
||||
*
|
||||
* @param key - key
|
||||
* @param brightnessValue - value
|
||||
*/
|
||||
setStorageValue(key,value) {
|
||||
LogUtil.info('settings BrightnessSettingModel setStorageValue Storage:' + value);
|
||||
ConfigData.BRIGHTNESS_SAVE_VALUE_KEY
|
||||
mBrightnessPreferences.putSync(key, value);
|
||||
mBrightnessPreferences.flushSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored data
|
||||
*
|
||||
* @param key - key
|
||||
* @param defaultValue - defaultValue
|
||||
*/
|
||||
getStorageValue(key,defaultValue): any {
|
||||
LogUtil.info('settings BrightnessSettingModel getStorageValue in' +
|
||||
mBrightnessPreferences.getSync(key, defaultValue));
|
||||
return mBrightnessPreferences.getSync(key, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
let brightnessSettingModel = new BrightnessSettingModel();
|
||||
export default brightnessSettingModel as BrightnessSettingModel;
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../BaseModel';
|
||||
import BaseParseConfModel from '../baseParseConfImpl/BaseParseConfModel.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import SystemTime from '@ohos.systemTime';
|
||||
/**
|
||||
* Set date and time
|
||||
*/
|
||||
export class DateAndTimeModel extends BaseModel {
|
||||
setTime(time) {
|
||||
LogUtil.info('DateAndTimeModel setTime in :' + time);
|
||||
SystemTime.setTime(time).then(data => {
|
||||
LogUtil.info(`DateAndTimeModel setTime promise then : ${data}`);
|
||||
})
|
||||
.catch(error => {
|
||||
LogUtil.info(`DateAndTimeModel setTime promise1 catch : ${error}`);
|
||||
}
|
||||
);
|
||||
LogUtil.info('DateAndTimeModel setTime out');
|
||||
}
|
||||
|
||||
public dateAndTimeListener(): any[] {
|
||||
LogUtil.info('getAboutDeviceInfoListener come in');
|
||||
return BaseParseConfModel.getJsonData(ConfigData.FILE_URI.concat('dateAndTime.json'));
|
||||
}
|
||||
}
|
||||
|
||||
let dateAndTimeModel = new DateAndTimeModel();
|
||||
export default dateAndTimeModel as DateAndTimeModel
|
||||
;
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import Audio from '@ohos.multimedia.audio';
|
||||
|
||||
export default class VolumeModel {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
setVolume(volumeValue, volumeType){
|
||||
LogUtil.info(`settings setVolume volumeValue: ${JSON.stringify(volumeValue)} volumeType:${JSON.stringify(volumeType)} `);
|
||||
|
||||
Audio.getAudioManager().setVolume(volumeType, volumeValue).then(() => {
|
||||
LogUtil.info('settings Promise returned to indicate a successful volume setting.')
|
||||
});
|
||||
}
|
||||
|
||||
getVolume(callback, volumeType) {
|
||||
LogUtil.info(`settings getVolume volumeType:${volumeType} `);
|
||||
Audio.getAudioManager().getVolume(volumeType, (err, value) => {
|
||||
if (err) {
|
||||
LogUtil.info(`settings Failed to obtain the volume. ${err.message}`);
|
||||
return;
|
||||
}
|
||||
LogUtil.info('settings Callback invoked to indicate that the volume is obtained.' + value);
|
||||
callback(value);
|
||||
})
|
||||
}
|
||||
|
||||
getMaxVolume(callback, volumeType) {
|
||||
LogUtil.info(`settings getMaxVolume volumeType:${volumeType} `);
|
||||
Audio.getAudioManager().getMaxVolume(volumeType, (err, value) => {
|
||||
if (err) {
|
||||
LogUtil.info(`settings Failed to obtain the volume. ${err.message}`);
|
||||
return;
|
||||
}
|
||||
LogUtil.info('settings Callback invoked to indicate that the volume is obtained.' + value);
|
||||
callback(value);
|
||||
})
|
||||
}
|
||||
|
||||
getMinVolume(callback, volumeType) {
|
||||
LogUtil.info(`settings getMaxVolume volumeType:${volumeType} `);
|
||||
Audio.getAudioManager().getMinVolume(volumeType, (err, value) => {
|
||||
if (err) {
|
||||
LogUtil.info(`settings Failed to obtain the volume. ${err.message}`);
|
||||
return;
|
||||
}
|
||||
LogUtil.info('settings Callback invoked to indicate that the volume is obtained.' + value);
|
||||
callback(value);
|
||||
})
|
||||
}
|
||||
}
|
@ -1,250 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import WifiNativeJs from '@ohos.wifi_native_js';
|
||||
import BaseParseConfModel from '../baseParseConfImpl/BaseParseConfModel.ets';
|
||||
import BaseModel from '../BaseModel.ets';
|
||||
import BrightnessSettingModel from '../brightnessImpl/BrightnessSettingModel.ets';
|
||||
|
||||
export class WifiModel extends BaseModel {
|
||||
private mWifiList: any[] = [];
|
||||
private remdupWifiList: any[] = [];
|
||||
private linkedInfoList: any[] = [];
|
||||
/**
|
||||
* Get WiFi switch status
|
||||
*/
|
||||
getWifiStatus() {
|
||||
LogUtil.info('WifiNativeJs isWifiActive');
|
||||
return WifiNativeJs.isWifiActive();
|
||||
}
|
||||
/**
|
||||
* WiFi enable
|
||||
*/
|
||||
getEnableWifi() {
|
||||
LogUtil.info('WifiNativeJs enableWifi');
|
||||
return WifiNativeJs.enableWifi();
|
||||
}
|
||||
/**
|
||||
* WiFi disable
|
||||
*/
|
||||
disableWifi() {
|
||||
this.linkedInfoList = [];
|
||||
LogUtil.info('WifiNativeJs disableWifi');
|
||||
return WifiNativeJs.disableWifi();
|
||||
}
|
||||
/**
|
||||
* Scan WiFi
|
||||
*/
|
||||
getScanWifi() {
|
||||
LogUtil.info('WifiNativeJs scan');
|
||||
return WifiNativeJs.scan();
|
||||
}
|
||||
/**
|
||||
* Get WiFi scan information
|
||||
*/
|
||||
getScanInfoCallBack() {
|
||||
LogUtil.info('get to wifi info start');
|
||||
this.mWifiList = [];
|
||||
this.remdupWifiList = [];
|
||||
WifiNativeJs.getScanInfos(result => {
|
||||
LogUtil.info('[wifi_js_test] wifi received scan info call back results1:' + JSON.stringify(result));
|
||||
if (result === null) {
|
||||
return;
|
||||
}
|
||||
LogUtil.info('[wifi_js_test] wifi received scan info call back results2:' + JSON.stringify(result));
|
||||
let clen = Object.keys(result)
|
||||
.length;
|
||||
let image;
|
||||
LogUtil.info('[wifi_js_test] wifi received scan info call back length:' + clen);
|
||||
for (let j = 0; j < clen; j++) {
|
||||
LogUtil.info('result[0].ssid: ' + result[j].ssid);
|
||||
LogUtil.info('securityType: ' + result[j].securityType);
|
||||
LogUtil.info('rssi: ' + result[j].rssi);
|
||||
LogUtil.info('bssid: ' + result[j].bssid);
|
||||
LogUtil.info('band: ' + result[j].band);
|
||||
LogUtil.info('frequency: ' + result[j].frequency);
|
||||
LogUtil.info('timestamp: ' + result[j].timestamp);
|
||||
LogUtil.info('SignalLevel: ' + WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band));
|
||||
if (result[j].securityType === 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 4) {
|
||||
image = '/res/image/ic_wifi_signal_4_dark.svg';
|
||||
LogUtil.info('securityType 1 and signal level 4');
|
||||
}
|
||||
if (result[j].securityType === 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 3) {
|
||||
image = '/res/image/ic_wifi_signal_3_dark.svg';
|
||||
LogUtil.info('securityType 1 and signal level 3');
|
||||
}
|
||||
if (result[j].securityType === 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 2) {
|
||||
image = '/res/image/ic_wifi_signal_2_dark.svg';
|
||||
LogUtil.info('securityType 1 and signal level 2');
|
||||
}
|
||||
if (result[j].securityType === 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 1) {
|
||||
image = '/res/image/ic_wifi_signal_1_dark.svg';
|
||||
LogUtil.info('securityType 1 and signal level 1');
|
||||
}
|
||||
if (result[j].securityType === 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 0) {
|
||||
image = '/res/image/ic_wifi_signal_1_dark.svg';
|
||||
LogUtil.info('securityType 1 and signal level 1');
|
||||
}
|
||||
if (result[j].securityType !== 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 4) {
|
||||
image = '/res/image/ic_wifi_lock_signal_4_dark.svg';
|
||||
LogUtil.info('securityType lock and level 4');
|
||||
}
|
||||
if (result[j].securityType !== 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 3) {
|
||||
image = '/res/image/ic_wifi_lock_signal_3_dark.svg';
|
||||
LogUtil.info('securityType lock and level 3');
|
||||
}
|
||||
if (result[j].securityType !== 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 2) {
|
||||
image = '/res/image/ic_wifi_lock_signal_2_dark.svg';
|
||||
LogUtil.info('securityType lock and level 2');
|
||||
}
|
||||
if (result[j].securityType !== 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 1) {
|
||||
image = '/res/image/ic_wifi_lock_signal_1_dark.svg';
|
||||
LogUtil.info('securityType lock and level 1');
|
||||
}
|
||||
if (result[j].securityType !== 1 && WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band) === 0) {
|
||||
image = '/res/image/ic_wifi_lock_signal_1_dark.svg';
|
||||
LogUtil.info('securityType lock and level 1');
|
||||
}
|
||||
|
||||
if (result[j].ssid === '' || result[j] === null) {
|
||||
LogUtil.info('result ssid empty');
|
||||
} else {
|
||||
this.mWifiList.push({
|
||||
settingSummary: '',
|
||||
settingTitle: result[j].ssid,
|
||||
settingValue: '',
|
||||
settingArrow: image,
|
||||
settingRssi: result[j].rssi,
|
||||
settingBand: result[j].band,
|
||||
bssid: result[j].bssid,
|
||||
securityType: result[j].securityType,
|
||||
signalLevel: WifiNativeJs.getSignalLevel(result[j].rssi, result[j].band),
|
||||
});
|
||||
}
|
||||
}
|
||||
LogUtil.info('original mWifiList :' + JSON.stringify(this.mWifiList));
|
||||
for (let i = 0; i < this.mWifiList.length; i++) {
|
||||
let position = this.getItemPosition(this.remdupWifiList, this.mWifiList[i].settingTitle);
|
||||
if (position !== -1) {
|
||||
if (this.remdupWifiList[position].signalLevel < this.mWifiList[i].signalLevel) {
|
||||
this.remdupWifiList.splice(position, 1);
|
||||
this.remdupWifiList.splice(position, 0, this.mWifiList[i]);
|
||||
}
|
||||
} else {
|
||||
this.remdupWifiList.push(this.mWifiList[i]);
|
||||
}
|
||||
}
|
||||
LogUtil.info('get linkedList info before0 :' + JSON.stringify(this.linkedInfoList));
|
||||
LogUtil.info('get linkedList info before1 :' + this.linkedInfoList.length);
|
||||
if (this.linkedInfoList.length === 0) {
|
||||
LogUtil.info('get linkedList info linkedInfoList empty :');
|
||||
} else {
|
||||
if (this.linkedInfoList[0].settingTitle !== '' && clen > 0) {
|
||||
LogUtil.info('get linkedList info start :');
|
||||
let index = this.getItemPosition(this.remdupWifiList, this.linkedInfoList[0].settingTitle)
|
||||
let settingTitle = this.linkedInfoList[0].settingTitle;
|
||||
let settingArrow = this.remdupWifiList[index].settingArrow;
|
||||
let settingRssi = this.linkedInfoList[0].settingRssi;
|
||||
let settingBand = this.linkedInfoList[0].settingBand;
|
||||
let bssid = this.linkedInfoList[0].bssid;
|
||||
let securityType = this.remdupWifiList[index].securityType;
|
||||
this.remdupWifiList.splice(index, 1);
|
||||
this.remdupWifiList.unshift({
|
||||
settingSummary: $r('app.string.connected'),
|
||||
settingTitle: settingTitle,
|
||||
settingValue: '',
|
||||
settingArrow: settingArrow,
|
||||
settingArrowStyle: 'wifi',
|
||||
settingRssi: settingRssi,
|
||||
settingBand: settingBand,
|
||||
bssid: bssid,
|
||||
securityType: securityType,
|
||||
});
|
||||
} else {
|
||||
LogUtil.info('get linkedList info linkedInfoList settingTitle is empty :');
|
||||
}
|
||||
}
|
||||
AppStorage.SetOrCreate('WifiList', this.remdupWifiList);
|
||||
LogUtil.info('remove duplicate ssid remdupWifiList: ' + JSON.stringify(this.remdupWifiList));
|
||||
});
|
||||
LogUtil.info('get to wifi information end ---->');
|
||||
}
|
||||
/**
|
||||
* Gets the subscript of the specified WiFi
|
||||
* @param list
|
||||
* @param ssid
|
||||
*/
|
||||
getItemPosition(list, ssid) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (ssid === list[i].settingTitle) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* Connecting equipment
|
||||
* @param obj
|
||||
*/
|
||||
connectToDevice(obj) {
|
||||
LogUtil.info('[wifi_js_test] connect to wifi');
|
||||
return WifiNativeJs.connectToDevice(obj);
|
||||
}
|
||||
/**
|
||||
* Disconnect wifi
|
||||
*/
|
||||
disConnect() {
|
||||
LogUtil.info('netWork disconnect');
|
||||
return WifiNativeJs.disConnect();
|
||||
}
|
||||
/**
|
||||
* Get connected WiFi information
|
||||
*/
|
||||
getLinkedInfo() {
|
||||
this.linkedInfoList = [];
|
||||
LogUtil.info('[wifi_js] get wifi linked info start');
|
||||
WifiNativeJs.getLinkedInfo()
|
||||
.then(data => {
|
||||
LogUtil.info("[wifi_js] get wifi linked info [promise] -> " + JSON.stringify(data));
|
||||
LogUtil.info("[wifi_js] get wifi linked info [promise] -> " + JSON.stringify(data.ssid));
|
||||
LogUtil.info('data result[0].ssid: ' + data.ssid);
|
||||
LogUtil.info('data rssi: ' + data.rssi);
|
||||
LogUtil.info('data bssid: ' + data.bssid);
|
||||
LogUtil.info('data band: ' + data.band);
|
||||
this.linkedInfoList.push({
|
||||
settingSummary: '',
|
||||
settingTitle: data.ssid,
|
||||
settingValue: '',
|
||||
settingArrow: '',
|
||||
settingRssi: data.rssi,
|
||||
settingBand: data.band,
|
||||
bssid: data.bssid,
|
||||
securityType: '',
|
||||
signalLevel: WifiNativeJs.getSignalLevel(data.rssi, data.band),
|
||||
});
|
||||
LogUtil.info("[wifi_js] get wifi linked info linkedInfoList 1" + JSON.stringify(this.linkedInfoList))
|
||||
AppStorage.SetOrCreate('linkedInfoList', this.linkedInfoList);
|
||||
LogUtil.info("[wifi_js] get wifi linked info linkedInfoList 2" + JSON.stringify(this.linkedInfoList))
|
||||
})
|
||||
.catch(error => {
|
||||
LogUtil.info("[wifi_js] linked info promise then error" + error);
|
||||
})
|
||||
LogUtil.info('[wifi_js] get wifi linked info end');
|
||||
}
|
||||
}
|
||||
|
||||
let wifiModel = new WifiModel();
|
||||
export default wifiModel as WifiModel
|
||||
;
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LogUtil from '../common/baseUtil/LogUtil.ets';
|
||||
import EntryComponent from './component/entryComponent.ets';
|
||||
import HeadComponent from './component/headComponent.ets';
|
||||
import Router from '@system.router'
|
||||
|
||||
let appInfo;
|
||||
|
||||
/**
|
||||
* application details
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
struct ApplicationInfo {
|
||||
build() {
|
||||
Column() {
|
||||
HeadComponent({ headName: $r('app.string.applicationInfo'), isActive: true });
|
||||
Row() {
|
||||
EntryComponent({
|
||||
settingIcon: appInfo.settingIcon,
|
||||
settingTitle: appInfo.settingTitle,
|
||||
settingSummary: appInfo.settingSummary,
|
||||
settingValue: '',
|
||||
settingArrow: '',
|
||||
settingArrowStyle: '',
|
||||
settingUri: appInfo.settingUri
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear(): void{
|
||||
LogUtil.info('settings ApplicationInfo aboutToAppear in');
|
||||
appInfo = Router.getParams();
|
||||
LogUtil.info('settings ApplicationInfo aboutToAppear this.item:' + JSON.stringify(appInfo));
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
LogUtil.info('settings ApplicationInfo onBackPress in');
|
||||
Router.back();
|
||||
LogUtil.info('settings ApplicationInfo onBackPress out');
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BrightnessSettingModel from '../model/brightnessImpl/BrightnessSettingModel.ets';
|
||||
import HeadComponent from './component/headComponent.ets';
|
||||
import ConfigData from '../common/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../common/baseUtil/LogUtil.ets';
|
||||
import SubscriberUtils from '../common/baseUtil/SubscriberUtil.ets';
|
||||
import Router from '@system.router';
|
||||
|
||||
const BRIGHTNESS_MIN_VALUE = 0;
|
||||
const BRIGHTNESS_MAX_VALUE = 255;
|
||||
const BRIGHTNESS_STEP_VALUE = 10;
|
||||
const SENT_EVENT_IN_BRIGHTNESS_PAGES = '-1';
|
||||
|
||||
/**
|
||||
* brightness setting
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
struct BrightnessSettings {
|
||||
@StorageLink('BrightnessSetValue') bright: number= 150;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
HeadComponent({ headName: $r('app.string.brightnessTab'), isActive: true });
|
||||
Row() {
|
||||
Image($r('app.media.ic_settings_brightness_minimum'))
|
||||
.width($r('app.float.wh_value_40'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
.objectFit(ImageFit.Contain);
|
||||
Slider({
|
||||
value: this.bright,
|
||||
min: BRIGHTNESS_MIN_VALUE,
|
||||
max: BRIGHTNESS_MAX_VALUE,
|
||||
step: BRIGHTNESS_STEP_VALUE
|
||||
})
|
||||
.selectedColor(Color.Blue)
|
||||
.blockColor(Color.Blue)
|
||||
.width(ConfigData.WH_83_100)
|
||||
.onChange((number, SliderChangeMode) => {
|
||||
this.bright = Math.round(number);
|
||||
BrightnessSettingModel.setBrightnessListener(this.bright);
|
||||
BrightnessSettingModel.setStorageValue(ConfigData.BRIGHTNESS_SAVE_VALUE_KEY, this.bright);
|
||||
SubscriberUtils.sendEvent(this.bright + '', ConfigData.SENT_EVENT_BROADCAST_BRIGHTNESS_VALUE);
|
||||
});
|
||||
Image($r('app.media.ic_settings_brightness_maximum'))
|
||||
.width($r('app.float.wh_value_40'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
.objectFit(ImageFit.Contain);
|
||||
}.padding({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') });
|
||||
}
|
||||
.align(Alignment.Center)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height(ConfigData.WH_100_100);
|
||||
}
|
||||
|
||||
private aboutToAppear(): void{
|
||||
LogUtil.info('settings BrightnessSettings aboutToDisappear in');
|
||||
this.bright = BrightnessSettingModel.getStorageValue(ConfigData.BRIGHTNESS_SAVE_VALUE_KEY,
|
||||
ConfigData.BRIGHTNESS_DEFAULT_VALUE);
|
||||
SubscriberUtils.sendEvent(SENT_EVENT_IN_BRIGHTNESS_PAGES, ConfigData.SENT_EVENT_BROADCAST_BRIGHTNESS_VALUE);
|
||||
SubscriberUtils.registerStatusListener();
|
||||
LogUtil.info('settings BrightnessSettings aboutToDisappear out');
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
LogUtil.info('settings BrightnessSettings onBackPress in');
|
||||
Router.back();
|
||||
LogUtil.info('settings BrightnessSettings onBackPress out');
|
||||
}
|
||||
|
||||
aboutToDisappear(): void{
|
||||
LogUtil.info('settings BrightnessSettings aboutToDisappear in');
|
||||
SubscriberUtils.unSubscriberListener();
|
||||
LogUtil.info('settings BrightnessSettings aboutToDisappear out');
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
|
||||
/**
|
||||
* Toggle component
|
||||
*/
|
||||
@Component
|
||||
export default
|
||||
struct SwitchComponent {
|
||||
private isOn: boolean= false;
|
||||
private title: '';
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Text(this.title)
|
||||
.fontSize($r('app.float.font_20'))
|
||||
.fontColor(Color.Black)
|
||||
.align(Alignment.Start)
|
||||
|
||||
Toggle({ type: ToggleType.Switch, isOn: false })
|
||||
.align(Alignment.End)
|
||||
.width($r('app.float.wh_value_60'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
|
||||
}
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height($r('app.float.wh_value_70'))
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.padding({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') })
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import VolumeModel from '../model/volumeControlImpl/VolumeModel.ets';
|
||||
import HeadComponent from './component/headComponent.ets';
|
||||
import ConfigData from '../common/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../common/baseUtil/LogUtil.ets';
|
||||
import SubscriberUtils from '../common/baseUtil/SubscriberUtil.ets';
|
||||
import Router from '@system.router';
|
||||
import Audio from '@ohos.multimedia.audio';
|
||||
|
||||
const VOLUME_TYPE = Audio.AudioVolumeType.MEDIA;
|
||||
const SENT_EVENT_IN_VOLUME_PAGES = '-1';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export
|
||||
struct VolumeControl {
|
||||
@State minVol: number = 0;
|
||||
@State maxVol: number = 10;
|
||||
@StorageLink('VolumeSetValue') currentVol: number = 0;
|
||||
private audioManager = Audio.getAudioManager();
|
||||
private volumeModel = new VolumeModel();
|
||||
|
||||
initVolume() {
|
||||
this.volumeModel.getMaxVolume(this.getMaxVolumeCallback.bind(this), VOLUME_TYPE);
|
||||
this.volumeModel.getMinVolume(this.getMinVolumeCallback.bind(this), VOLUME_TYPE);
|
||||
this.volumeModel.getVolume(this.getCurrentVolumeCallback.bind(this), VOLUME_TYPE);
|
||||
}
|
||||
|
||||
getMinVolumeCallback(val) {
|
||||
this.minVol = val;
|
||||
LogUtil.info(`settings getMinVolumeCallback ${this.minVol} `);
|
||||
}
|
||||
|
||||
getMaxVolumeCallback(val) {
|
||||
this.maxVol = val;
|
||||
LogUtil.info(`settings getMaxVolumeCallback ${this.maxVol} `);
|
||||
}
|
||||
|
||||
getCurrentVolumeCallback(val) {
|
||||
this.currentVol = val;
|
||||
LogUtil.info(`settings getCurrentVolumeCallback ${this.currentVol} `);
|
||||
}
|
||||
|
||||
setVolume(volumeValue, volumeType) {
|
||||
LogUtil.info(`settings setVolume = ${volumeValue} Type = ${volumeType}`)
|
||||
Audio.getAudioManager().setVolume(volumeType, volumeValue).then(() => {
|
||||
this.currentVol = volumeValue;
|
||||
LogUtil.info('settings Promise returned to indicate a successful volume setting')
|
||||
})
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
LogUtil.info('settings Start init Volume!')
|
||||
this.initVolume()
|
||||
SubscriberUtils.sendEvent(SENT_EVENT_IN_VOLUME_PAGES, ConfigData.SENT_EVENT_BROADCAST_VOLUME_VALUE);
|
||||
SubscriberUtils.registerStatusListener();
|
||||
LogUtil.info('settings Finished init Volume!')
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
HeadComponent({ headName: $r('app.string.volumeControl'), isActive: true });
|
||||
Row() {
|
||||
Slider({
|
||||
value: this.currentVol,
|
||||
min: this.minVol,
|
||||
max: this.maxVol,
|
||||
step: 1,
|
||||
style: SliderStyle.INSET
|
||||
})
|
||||
.size({ width: 300 })
|
||||
.width('100%')
|
||||
.blockColor(Color.Blue)
|
||||
.trackColor(Color.Grey)
|
||||
.selectedColor(Color.Blue)
|
||||
.onChange((value: number) => {
|
||||
this.setVolume(value, VOLUME_TYPE)
|
||||
})
|
||||
}
|
||||
.padding({
|
||||
left: $r('app.float.wh_value_15'),
|
||||
right: $r('app.float.wh_value_15')
|
||||
});
|
||||
}
|
||||
.width('85%')
|
||||
.align(Alignment.Center)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height(ConfigData.WH_100_100);
|
||||
}
|
||||
}
|
@ -1,381 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import SubscriberUtils from '../common/baseUtil/SubscriberUtil.ets';
|
||||
import WifiModel from '../model/wifiImpl/WifiModel.ets';
|
||||
import HeadComponent from './component/headComponent.ets';
|
||||
import EntryComponent from './component/entryComponent.ets';
|
||||
import ImageAnimatorComponent from './component/imageAnimatorComponent.ets';
|
||||
import ConfigData from '../common/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../common/baseUtil/LogUtil.ets';
|
||||
import BrightnessSettingModel from '../model/brightnessImpl/BrightnessSettingModel.ets';
|
||||
import Subscriber from '@ohos.commonevent';
|
||||
import router from '@system.router';
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@StorageLink('WifiList') wifiList: any[] = [];
|
||||
@StorageLink('wifiPsd') password: string = '';
|
||||
private isOn: boolean = true;
|
||||
@State isShow: boolean = true;
|
||||
private connectPsd: string = '';
|
||||
private mIndex: number = -1;
|
||||
private timeoutFlag;
|
||||
private timeoutMark;
|
||||
private intervalFlag;
|
||||
@State connectRssi: number = -1;
|
||||
@State connectBand: number = -1;
|
||||
@State connectImage: string = '';
|
||||
@State connectName: string = '';
|
||||
@State connectBssid: string = '';
|
||||
@State connectSecurityType: number = -1;
|
||||
private mCommonEventSubscriber = null;
|
||||
private wifiIsFirstConnect: boolean = false;
|
||||
private mCommonEventSubscribeInfo = {
|
||||
events: ["usual.event.wifi.CONN_STATE"]
|
||||
};
|
||||
build() {
|
||||
Column() {
|
||||
HeadComponent({ headName: $r('app.string.wifiTab'), isActive: true });
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
||||
Row() {
|
||||
Text($r('app.string.wifiTab'))
|
||||
.fontSize($r('app.float.font_22'))
|
||||
.fontColor(Color.Black)
|
||||
.textAlign(TextAlign.Start);
|
||||
}.alignItems(VerticalAlign.Center);
|
||||
Toggle({ type: ToggleType.Switch, isOn: this.isOn })
|
||||
.width($r('app.float.wh_value_50'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
.onChange((isOn: boolean) => {
|
||||
this.isOn = !this.isOn;
|
||||
LogUtil.info('Toggle onChange this.isOn:' + this.isOn);
|
||||
if (this.isOn) {
|
||||
this.switchOn();
|
||||
} else {
|
||||
this.switchOff();
|
||||
}
|
||||
});
|
||||
}
|
||||
.height($r('app.float.wh_value_70'))
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') });
|
||||
Flex({ alignItems: ItemAlign.Start }) {
|
||||
Text($r('app.string.tipsContent'))
|
||||
.fontSize($r('app.float.font_20'));
|
||||
}
|
||||
.visibility(this.isOn ? Visibility.None : Visibility.Visible)
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') });
|
||||
Column() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
||||
Text($r('app.string.wifiList'))
|
||||
.fontSize($r('app.float.font_24'))
|
||||
.align(Alignment.Start);
|
||||
Row() {
|
||||
ImageAnimatorComponent({ imageWidth: $r('app.float.wh_value_40'),
|
||||
imageHeight: $r('app.float.wh_value_40') })
|
||||
}
|
||||
.width($r('app.float.wh_value_40'))
|
||||
.visibility(this.isShow ? Visibility.Visible : Visibility.None);
|
||||
}
|
||||
.width(ConfigData.WH_100_100)
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') });
|
||||
List() {
|
||||
ForEach(this.wifiList, (item) => {
|
||||
ListItem() {
|
||||
EntryComponent({
|
||||
settingIcon: '',
|
||||
settingTitle: item.settingTitle,
|
||||
settingSummary: item.settingSummary,
|
||||
settingValue: '',
|
||||
settingArrow: item.settingArrow,
|
||||
settingArrowStyle: 'wifi',
|
||||
settingUri: ''
|
||||
});
|
||||
}.onClick(() => {
|
||||
this.connectName = item.settingTitle
|
||||
this.connectImage = item.settingArrow
|
||||
this.connectBssid = item.bssid
|
||||
this.connectSecurityType = item.securityType
|
||||
this.connectRssi = item.settingRssi
|
||||
this.connectBand = item.settingBand
|
||||
this.connectWifi();
|
||||
})
|
||||
.height($r('app.float.wh_value_60'))
|
||||
}, item => JSON.stringify(item));
|
||||
}
|
||||
.divider({
|
||||
strokeWidth: $r('app.float.wh_value_1'),
|
||||
color: $r('app.color.color_E3E3E3_grey'),
|
||||
startMargin: $r('app.float.wh_value_15'),
|
||||
endMargin: $r('app.float.wh_value_15')
|
||||
})
|
||||
.width(ConfigData.WH_100_100)
|
||||
.margin({top:$r('app.float.wh_value_20')});
|
||||
}
|
||||
.width(ConfigData.WH_100_100)
|
||||
.margin({bottom:$r('app.float.wh_value_20')})
|
||||
.layoutWeight(1)
|
||||
.visibility(this.isOn ? Visibility.Visible : Visibility.None);
|
||||
}
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height(ConfigData.WH_100_100)
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
LogUtil.info('init wifi get in');
|
||||
this.wifiStatusListener();
|
||||
this.getSwitchStatus();
|
||||
this.clearScanInfo();
|
||||
LogUtil.info('init wifi get switch status');
|
||||
if (this.isOn) {
|
||||
LogUtil.info('init wifi isOn is true');
|
||||
let that = this
|
||||
this.timeoutFlag = setTimeout(() => {
|
||||
if (WifiModel.getScanWifi()) {
|
||||
LogUtil.info('init wifi start scan');
|
||||
that.timeoutMark = setTimeout(() => {
|
||||
WifiModel.getScanInfoCallBack();
|
||||
that.isShow = false;
|
||||
AppStorage.SetOrCreate('WifiList', []);
|
||||
clearTimeout(this.timeoutFlag);
|
||||
clearTimeout(that.timeoutMark);
|
||||
LogUtil.info('init wifi wifiList' + this.wifiList);
|
||||
}, 3000);
|
||||
} else {
|
||||
LogUtil.info('init scan wifiList fail');
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
LogUtil.info('init wifi isOn is false');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Connect WiFi
|
||||
*/
|
||||
connectWifi() {
|
||||
LogUtil.info('[wifi_js_test] connect to wifi come in');
|
||||
let index = WifiModel.getItemPosition(this.wifiList, this.connectName);
|
||||
if (this.mIndex !== index) {
|
||||
this.connectPsd = '';
|
||||
this.mIndex = index;
|
||||
}
|
||||
let obj = {
|
||||
"ssid": this.connectName,
|
||||
"bssid": this.connectBssid,
|
||||
"preSharedKey": this.connectPsd,
|
||||
"isHiddenSsid": false,
|
||||
"securityType": this.connectSecurityType
|
||||
}
|
||||
|
||||
LogUtil.info('[wifi_js_test] connectSecurityType' + this.connectSecurityType);
|
||||
LogUtil.info('[wifi_js_test] connectPsd' + this.connectPsd);
|
||||
LogUtil.info('[wifi_js_test] connectName' + this.connectName);
|
||||
if (this.connectSecurityType !== 1 && '' == this.connectPsd) {
|
||||
LogUtil.info('click to detail wifiPsd');
|
||||
let name = { 'connectName': this.connectName };
|
||||
this.mIndex = index;
|
||||
router.push({
|
||||
uri: 'pages/wifiPsd',
|
||||
params: name,
|
||||
});
|
||||
LogUtil.info('jump to detail end');
|
||||
return;
|
||||
}
|
||||
if (WifiModel.connectToDevice(obj)) {
|
||||
LogUtil.info('[wifi_js_test] connect to come in');
|
||||
LogUtil.info('[wifi_js_test] connect to come in obj' + JSON.stringify(obj));
|
||||
LogUtil.info('[wifi_js_test] connect to wifiList ' + JSON.stringify(this.wifiList));
|
||||
}
|
||||
LogUtil.info('clickToSecret end:');
|
||||
}
|
||||
/**
|
||||
* Get switch status
|
||||
*/
|
||||
getSwitchStatus() {
|
||||
if (WifiModel.getWifiStatus()) {
|
||||
this.isOn = true;
|
||||
} else {
|
||||
this.isOn = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* delay time
|
||||
* @param delay
|
||||
*/
|
||||
private sleep(delay) {
|
||||
let start = (new Date()).getTime();
|
||||
while ((new Date()).getTime() - start < delay) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The switch is on
|
||||
*/
|
||||
private switchOn() {
|
||||
LogUtil.info('switchClick wifi start ---->');
|
||||
if(this.wifiList.length > 0){
|
||||
console.info('come on one');
|
||||
return;
|
||||
}
|
||||
LogUtil.info('switchClick wifi start 1---->');
|
||||
this.clearScanInfo();
|
||||
this.isShow = true;
|
||||
this.sleep(2000);
|
||||
if (WifiModel.getEnableWifi()) {
|
||||
LogUtil.info('switchClick wifi enableWifi enter ---->');
|
||||
let that = this;
|
||||
this.timeoutFlag = setTimeout(() => {
|
||||
if (WifiModel.getScanWifi()) {
|
||||
that.timeoutMark = setTimeout(() => {
|
||||
WifiModel.getScanInfoCallBack();
|
||||
that.isShow = false;
|
||||
clearTimeout(this.timeoutFlag);
|
||||
clearTimeout(that.timeoutMark);
|
||||
LogUtil.info('switchClick wifi wifiList' + JSON.stringify(this.wifiList));
|
||||
}, 3000);
|
||||
} else {
|
||||
LogUtil.info('switchClick wifi fail to scan ---->');
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
LogUtil.info('switchClick wifi fail to enableWifi ---->');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The switch is off
|
||||
*/
|
||||
private switchOff() {
|
||||
LogUtil.info('switchClick wifi off start ---->');
|
||||
if (WifiModel.disableWifi()) {
|
||||
LogUtil.info('switchClick wifi enter to disableWifi ---->');
|
||||
AppStorage.SetOrCreate('WifiList', []);
|
||||
BrightnessSettingModel.setStorageValue('wifiConnectName', '');
|
||||
this.clearScanInfo();
|
||||
} else {
|
||||
LogUtil.info('switchClick wifi off end ---->');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* WiFi status monitoring
|
||||
*/
|
||||
wifiStatusListener() {
|
||||
LogUtil.info('wifi status listener');
|
||||
Subscriber.createSubscriber(this.mCommonEventSubscribeInfo,
|
||||
this.CreateSubscriberCallBack.bind(this));
|
||||
}
|
||||
|
||||
CreateSubscriberCallBack(err, data) {
|
||||
LogUtil.info('subscriber subscribe');
|
||||
this.mCommonEventSubscriber = data;
|
||||
Subscriber.subscribe(this.mCommonEventSubscriber, this.SubscriberCallBack.bind(this));
|
||||
}
|
||||
|
||||
SubscriberCallBack(err, data) {
|
||||
LogUtil.info('subscriber call back');
|
||||
LogUtil.info('==========================>SubscriberCallBack event = ' + data.event);
|
||||
LogUtil.info('==========================>SubscriberCallBack data = ' + JSON.stringify(data));
|
||||
LogUtil.info('==========================>SubscriberCallBack data code = ' + data.code);
|
||||
LogUtil.info('SubscriberCallBack this.wifiList:' + JSON.stringify(this.wifiList));
|
||||
if (this.connectName !== '' && (data.code === 1 || data.code === 3 || data.code === 4)) {
|
||||
let wifi = { 'name': '', 'rssi': -1, 'band': -1 };
|
||||
wifi.name = this.connectName;
|
||||
wifi.rssi = this.connectRssi;
|
||||
wifi.band = this.connectBand;
|
||||
SubscriberUtils.sendEvent(JSON.stringify(wifi), ConfigData.SENT_EVENT_WIFI_CONNECT_NAME);
|
||||
BrightnessSettingModel.setStorageValue('wifiConnectName', this.connectName);
|
||||
let index = WifiModel.getItemPosition(this.wifiList, this.connectName);
|
||||
LogUtil.info('subscriber connected -1:' + JSON.stringify(this.wifiList));
|
||||
this.wifiList.splice(index, 1);
|
||||
LogUtil.info('subscriber connected 0:' + JSON.stringify(this.wifiList));
|
||||
this.wifiList.unshift({
|
||||
settingSummary: $r('app.string.connected'),
|
||||
settingTitle: this.connectName,
|
||||
settingValue: '',
|
||||
settingArrow: this.connectImage,
|
||||
settingArrowStyle: 'wifi',
|
||||
settingRssi: this.connectRssi,
|
||||
settingBand: this.connectBand,
|
||||
bssid: this.connectBssid,
|
||||
securityType: this.connectSecurityType,
|
||||
});
|
||||
LogUtil.info('subscriber connected 1:' + JSON.stringify(this.wifiList));
|
||||
this.wifiList[1].settingSummary = '';
|
||||
LogUtil.info('subscriber connected 2' + JSON.stringify(this.wifiList));
|
||||
}
|
||||
|
||||
if (data.code === 7) {
|
||||
BrightnessSettingModel.setStorageValue('wifiConnectName', '');
|
||||
}
|
||||
if (data.code === 8) {
|
||||
this.connectPsd = '';
|
||||
AppStorage.SetOrCreate('wifiPsd', '');
|
||||
}
|
||||
if (data.code === 9) {
|
||||
LogUtil.info("subscriber code nine disconnected");
|
||||
this.wifiList.unshift({
|
||||
settingSummary: '',
|
||||
settingTitle: this.wifiList[0].settingTitle,
|
||||
settingValue: '',
|
||||
settingArrow: this.wifiList[0].settingArrow,
|
||||
settingArrowStyle: 'wifi',
|
||||
settingRssi: this.wifiList[0].settingRssi,
|
||||
bssid: this.wifiList[0].bssid,
|
||||
securityType: this.wifiList[0].securityType,
|
||||
});
|
||||
this.wifiList.splice(1, 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Cancel WiFi status listening
|
||||
*/
|
||||
unSubscriberListener() {
|
||||
Subscriber.unsubscribe(this.mCommonEventSubscriber, () => {
|
||||
LogUtil.info('wifi unsubscribe');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear scan information
|
||||
*/
|
||||
clearScanInfo() {
|
||||
LogUtil.info('clear scan wifiList start---->');
|
||||
this.wifiList = [];
|
||||
LogUtil.info('clear scan wifiList end---->');
|
||||
}
|
||||
|
||||
private aboutToDisappear(): void {
|
||||
AppStorage.SetOrCreate('wifiPsd', '');
|
||||
|
||||
this.unSubscriberListener;
|
||||
this.connectPsd = '';
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
LogUtil.info('wifi onPageShow this.password:' + this.password);
|
||||
this.connectPsd = this.password;
|
||||
if (this.connectPsd !== '') {
|
||||
this.connectWifi();
|
||||
}
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
AppStorage.SetOrCreate('wifiPsd', '');
|
||||
Navigator().active(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,115 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LogUtil from '../common/baseUtil/LogUtil.ets';
|
||||
import HeadComponent from './component/headComponent.ets';
|
||||
import ConfigData from '../common/baseUtil/ConfigData.ets';
|
||||
import Router from '@system.router'
|
||||
|
||||
const WIFI_DEFAULT_PSD = '';
|
||||
|
||||
let name;
|
||||
let title;
|
||||
|
||||
/**
|
||||
* wifi password setting page
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
struct WifiPsd {
|
||||
@State text: string= '';
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
HeadComponent({
|
||||
icBackIsVisibility: true,
|
||||
headName: null === title ? $r('app.string.wifiPassword') : title,
|
||||
isActive: true
|
||||
});
|
||||
|
||||
TextInput({ placeholder: '密码', text: this.text })
|
||||
.placeholderColor(Color.Blue)
|
||||
.placeholderFont({ size: ConfigData.font_20, weight: 2, family: "sans-serif", style: FontStyle.Normal })
|
||||
.caretColor(Color.Blue)
|
||||
.height($r('app.float.wh_value_70'))
|
||||
.backgroundColor(Color.White)
|
||||
.type(InputType.Password)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.margin({ left: $r('app.float.wh_value_15'), right: $r('app.float.wh_value_15') })
|
||||
.onChange((value: string) => {
|
||||
this.text = value;
|
||||
});
|
||||
Text()
|
||||
.backgroundColor(Color.Black)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height($r('app.float.wh_value_1'))
|
||||
.margin({
|
||||
left: $r('app.float.wh_value_15'),
|
||||
right: $r('app.float.wh_value_15')
|
||||
});
|
||||
|
||||
Row() {
|
||||
Button() {
|
||||
Text($r('app.string.cancel')).fontSize($r('app.float.font_20'))
|
||||
.fontColor(Color.Blue)
|
||||
}
|
||||
.backgroundColor($r('app.color.color_E3E3E3_grey'))
|
||||
.width($r('app.float.wh_value_160'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
.align(Alignment.Center)
|
||||
.onClick(() => {
|
||||
Router.back();
|
||||
});
|
||||
Blank().width($r('app.float.wh_value_50'));
|
||||
Button() {
|
||||
Text($r('app.string.confirm')).fontSize($r('app.float.font_20'))
|
||||
.fontColor(Color.Blue)
|
||||
}
|
||||
.backgroundColor($r('app.color.color_E3E3E3_grey'))
|
||||
.width($r('app.float.wh_value_160'))
|
||||
.height($r('app.float.wh_value_40'))
|
||||
.align(Alignment.Center)
|
||||
.onClick(() => {
|
||||
AppStorage.SetOrCreate('wifiPsd', '' === this.text ? WIFI_DEFAULT_PSD : this.text);
|
||||
Router.back();
|
||||
});
|
||||
}
|
||||
.margin({
|
||||
left: $r('app.float.wh_value_15'),
|
||||
top: $r('app.float.wh_value_20'),
|
||||
right: $r('app.float.wh_value_15')
|
||||
})
|
||||
.width(ConfigData.WH_100_100)
|
||||
.align(Alignment.Bottom);
|
||||
}
|
||||
.backgroundColor(Color.White)
|
||||
.width(ConfigData.WH_100_100)
|
||||
.height(ConfigData.WH_100_100);
|
||||
}
|
||||
|
||||
aboutToAppear(): void{
|
||||
LogUtil.info('settings wifiPsd aboutToAppear start');
|
||||
name = Router.getParams();
|
||||
LogUtil.info('settings wifiPsd aboutToAppear name:' + JSON.stringify(name));
|
||||
title = name.connectName;
|
||||
LogUtil.info('settings wifiPsd aboutToAppear title:' + title);
|
||||
AppStorage.SetOrCreate('wifiPsd', '');
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
LogUtil.info('settings wifiPsd onBackPress start');
|
||||
Router.back();
|
||||
LogUtil.info('settings wifiPsd onBackPress start');
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
{
|
||||
"float": [
|
||||
{
|
||||
"name": "wh_value_1",
|
||||
"value": "1"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_5",
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_10",
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_15",
|
||||
"value": "15"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_20",
|
||||
"value": "20"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_30",
|
||||
"value": "30"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_40",
|
||||
"value": "40"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_50",
|
||||
"value": "50"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_60",
|
||||
"value": "60"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_65",
|
||||
"value": "65"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_70",
|
||||
"value": "70"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_80",
|
||||
"value": "80"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_100",
|
||||
"value": "100"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_130",
|
||||
"value": "1300"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_160",
|
||||
"value": "160"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_230",
|
||||
"value": "230"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_280",
|
||||
"value": "280"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_390",
|
||||
"value": "390"
|
||||
},
|
||||
{
|
||||
"name": "wh_value_400",
|
||||
"value": "400"
|
||||
},
|
||||
{
|
||||
"name": "font_35",
|
||||
"value": "35"
|
||||
},
|
||||
{
|
||||
"name": "font_18",
|
||||
"value": "18"
|
||||
},
|
||||
{
|
||||
"name": "font_20",
|
||||
"value": "20"
|
||||
},
|
||||
{
|
||||
"name": "font_21",
|
||||
"value": "21"
|
||||
},
|
||||
{
|
||||
"name": "font_22",
|
||||
"value": "22"
|
||||
},
|
||||
{
|
||||
"name": "font_24",
|
||||
"value": "24"
|
||||
},
|
||||
{
|
||||
"name": "font_28",
|
||||
"value": "28"
|
||||
},
|
||||
{
|
||||
"name": "font_50",
|
||||
"value": "50"
|
||||
},
|
||||
{
|
||||
"name": "control_common_font_size",
|
||||
"value": "20"
|
||||
},
|
||||
{
|
||||
"name": "slider_text_padding_left",
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"name": "volume_border_radius",
|
||||
"value": "15"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_MainAbility",
|
||||
"value": "设置"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "ETS_Empty Feature Ability"
|
||||
},
|
||||
{
|
||||
"name": "enabled",
|
||||
"value": "已开启"
|
||||
},
|
||||
{
|
||||
"name": "disabled",
|
||||
"value": "已关闭"
|
||||
},
|
||||
{
|
||||
"name": "settings",
|
||||
"value": "设置"
|
||||
},
|
||||
{
|
||||
"name": "wifiTab",
|
||||
"value": "WLAN"
|
||||
},
|
||||
{
|
||||
"name": "brightnessTab",
|
||||
"value": "亮度"
|
||||
},
|
||||
{
|
||||
"name": "applyTab",
|
||||
"value": "应用"
|
||||
},
|
||||
{
|
||||
"name": "dateAndTimeTab",
|
||||
"value": "日期和时间"
|
||||
},
|
||||
{
|
||||
"name": "aboutTab",
|
||||
"value": "关于手机"
|
||||
},
|
||||
{
|
||||
"name": "volumeControlTab",
|
||||
"value": "音量调节"
|
||||
},
|
||||
{
|
||||
"name": "volumeControl",
|
||||
"value": "音量"
|
||||
},
|
||||
{
|
||||
"name": "applicationInfo",
|
||||
"value": "应用信息"
|
||||
},
|
||||
{
|
||||
"name": "appManagement",
|
||||
"value": "应用管理"
|
||||
},
|
||||
{
|
||||
"name": "cancel",
|
||||
"value": "取消"
|
||||
},
|
||||
{
|
||||
"name": "confirm",
|
||||
"value": "确定"
|
||||
},
|
||||
{
|
||||
"name": "wifiPassword",
|
||||
"value": "密码"
|
||||
},
|
||||
{
|
||||
"name": "date",
|
||||
"value": "日期"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"value": "时间"
|
||||
},
|
||||
{
|
||||
"name": "year",
|
||||
"value": "年"
|
||||
},
|
||||
{
|
||||
"name": "month",
|
||||
"value": "月"
|
||||
},
|
||||
{
|
||||
"name": "day",
|
||||
"value": "日"
|
||||
},
|
||||
{
|
||||
"name": "tipsContent",
|
||||
"value": "为提高位置信息的精确度,应用和服务仍然会扫描WLAN网络.您可以在提高精确度中更改此设置"
|
||||
},
|
||||
{
|
||||
"name": "wifiList",
|
||||
"value": "可用WLAN列表"
|
||||
},
|
||||
{
|
||||
"name": "systemName",
|
||||
"value": "系统名称"
|
||||
},
|
||||
{
|
||||
"name": "model",
|
||||
"value": "型号"
|
||||
},
|
||||
{
|
||||
"name": "companyInfo",
|
||||
"value": "厂家信息"
|
||||
},
|
||||
{
|
||||
"name": "deviceId",
|
||||
"value": "设备"
|
||||
},
|
||||
{
|
||||
"name": "softwareVersion",
|
||||
"value": "软件版本"
|
||||
},
|
||||
{
|
||||
"name": "version",
|
||||
"value": "版本 "
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"value": "密码"
|
||||
},
|
||||
{
|
||||
"name": "connected",
|
||||
"value": "已连接"
|
||||
},
|
||||
{
|
||||
"name": "monday",
|
||||
"value": "星期一"
|
||||
},
|
||||
{
|
||||
"name": "tuesday",
|
||||
"value": "星期二"
|
||||
},
|
||||
{
|
||||
"name": "wednesday",
|
||||
"value": "星期三"
|
||||
},
|
||||
{
|
||||
"name": "thursday",
|
||||
"value": "星期四"
|
||||
},
|
||||
{
|
||||
"name": "friday",
|
||||
"value": "星期五"
|
||||
},
|
||||
{
|
||||
"name": "saturday",
|
||||
"value": "星期六"
|
||||
},
|
||||
{
|
||||
"name": "sunday",
|
||||
"value": "星期日"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_MainAbility",
|
||||
"value": "设置"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "ETS_Empty Feature Ability"
|
||||
},
|
||||
{
|
||||
"name": "enabled",
|
||||
"value": "Enabled"
|
||||
},
|
||||
{
|
||||
"name": "disabled",
|
||||
"value": "Disabled"
|
||||
},
|
||||
{
|
||||
"name": "settings",
|
||||
"value": "Settings"
|
||||
},
|
||||
{
|
||||
"name": "wifiTab",
|
||||
"value": "WLANTab"
|
||||
},
|
||||
{
|
||||
"name": "brightnessTab",
|
||||
"value": "brightnessTab"
|
||||
},
|
||||
{
|
||||
"name": "volumeControl",
|
||||
"value": "volumeControl"
|
||||
},
|
||||
{
|
||||
"name": "volumeControlTab",
|
||||
"value": "volumeControlTab"
|
||||
},
|
||||
{
|
||||
"name": "applyTab",
|
||||
"value": "applyTab"
|
||||
},
|
||||
{
|
||||
"name": "dateAndTimeTab",
|
||||
"value": "dateAndTimeTab"
|
||||
},
|
||||
{
|
||||
"name": "aboutTab",
|
||||
"value": "aboutTab"
|
||||
},
|
||||
{
|
||||
"name": "applicationInfo",
|
||||
"value": "App info"
|
||||
},
|
||||
{
|
||||
"name": "appManagement",
|
||||
"value": "Apps"
|
||||
},
|
||||
{
|
||||
"name": "cancel",
|
||||
"value": "Cancel"
|
||||
},
|
||||
{
|
||||
"name": "confirm",
|
||||
"value": "Confirm"
|
||||
},
|
||||
{
|
||||
"name": "wifiPassword",
|
||||
"value": "Password"
|
||||
},
|
||||
{
|
||||
"name": "date",
|
||||
"value": "Date"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"value": "Time"
|
||||
},
|
||||
{
|
||||
"name": "year",
|
||||
"value": "year"
|
||||
},
|
||||
{
|
||||
"name": "month",
|
||||
"value": "month"
|
||||
},
|
||||
{
|
||||
"name": "day",
|
||||
"value": "date"
|
||||
},
|
||||
{
|
||||
"name": "wifiList",
|
||||
"value": "WLAN-List which can be used"
|
||||
},
|
||||
{
|
||||
"name": "systemName",
|
||||
"value": "SystemName"
|
||||
},
|
||||
{
|
||||
"name": "model",
|
||||
"value": "Model"
|
||||
},
|
||||
{
|
||||
"name": "companyInfo",
|
||||
"value": "CompanyInfo"
|
||||
},
|
||||
{
|
||||
"name": "deviceId",
|
||||
"value": "DeviceId"
|
||||
},
|
||||
{
|
||||
"name": "softwareVersion",
|
||||
"value": "SoftwareVersion"
|
||||
},
|
||||
{
|
||||
"name": "version",
|
||||
"value": "version "
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"value": "password"
|
||||
},
|
||||
{
|
||||
"name": "connected",
|
||||
"value": "connected"
|
||||
},
|
||||
{
|
||||
"name": "monday",
|
||||
"value": "monday"
|
||||
},
|
||||
{
|
||||
"name": "tuesday",
|
||||
"value": "tuesday"
|
||||
},
|
||||
{
|
||||
"name": "wednesday",
|
||||
"value": "wednesday"
|
||||
},
|
||||
{
|
||||
"name": "thursday",
|
||||
"value": "thursday"
|
||||
},
|
||||
{
|
||||
"name": "friday",
|
||||
"value": "friday"
|
||||
},
|
||||
{
|
||||
"name": "saturday",
|
||||
"value": "saturday"
|
||||
},
|
||||
{
|
||||
"name": "sunday",
|
||||
"value": "sunday"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
[
|
||||
{
|
||||
"settingIcon": "/res/image/ic_settings_wifi.svg",
|
||||
"settingTitle": "WLAN",
|
||||
"settingAlias": "wifiTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "/res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/wifi"
|
||||
},{
|
||||
"settingIcon": "/res/image/ic_settings_display.svg",
|
||||
"settingTitle": "",
|
||||
"settingAlias": "brightnessTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "/res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/brightnessSettings"
|
||||
},
|
||||
{
|
||||
"settingIcon": "res/image/ic_settings_applications.svg",
|
||||
"settingTitle": "",
|
||||
"settingAlias": "applyTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/appManagement"
|
||||
},
|
||||
{
|
||||
"settingIcon": "/res/image/ic_settings_advanced.svg",
|
||||
"settingTitle": "",
|
||||
"settingAlias": "dateAndTimeTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "/res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/dateAndTime"
|
||||
},
|
||||
{
|
||||
"settingIcon": "/res/image/ic_settings_about.svg",
|
||||
"settingTitle": "",
|
||||
"settingAlias": "aboutTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "/res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/aboutDevice"
|
||||
},
|
||||
{
|
||||
"settingIcon": "/res/image/ic_settings_volume.svg",
|
||||
"settingTitle": "",
|
||||
"settingAlias": "volumeControlTab",
|
||||
"settingValue": "",
|
||||
"settingArrow": "/res/image/ic_settings_arrow.svg",
|
||||
"settingSummary": "",
|
||||
"settingUri": "pages/volumeControl"
|
||||
}
|
||||
]
|
@ -1,160 +0,0 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_MainAbility",
|
||||
"value": "设置"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "ETS_Empty Feature Ability"
|
||||
},
|
||||
{
|
||||
"name": "enabled",
|
||||
"value": "已开启"
|
||||
},
|
||||
{
|
||||
"name": "disabled",
|
||||
"value": "已关闭"
|
||||
},
|
||||
{
|
||||
"name": "settings",
|
||||
"value": "设置"
|
||||
},
|
||||
{
|
||||
"name": "wifiTab",
|
||||
"value": "WLAN"
|
||||
},
|
||||
{
|
||||
"name": "brightnessTab",
|
||||
"value": "亮度"
|
||||
},
|
||||
{
|
||||
"name": "applyTab",
|
||||
"value": "应用"
|
||||
},
|
||||
{
|
||||
"name": "dateAndTimeTab",
|
||||
"value": "日期和时间"
|
||||
},
|
||||
{
|
||||
"name": "aboutTab",
|
||||
"value": "关于手机"
|
||||
},
|
||||
{
|
||||
"name": "volumeControlTab",
|
||||
"value": "音量调节"
|
||||
},
|
||||
{
|
||||
"name": "volumeControl",
|
||||
"value": "音量"
|
||||
},
|
||||
{
|
||||
"name": "applicationInfo",
|
||||
"value": "应用信息"
|
||||
},
|
||||
{
|
||||
"name": "appManagement",
|
||||
"value": "应用管理"
|
||||
},
|
||||
{
|
||||
"name": "cancel",
|
||||
"value": "取消"
|
||||
},
|
||||
{
|
||||
"name": "confirm",
|
||||
"value": "确定"
|
||||
},
|
||||
{
|
||||
"name": "wifiPassword",
|
||||
"value": "密码"
|
||||
},
|
||||
{
|
||||
"name": "date",
|
||||
"value": "日期"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"value": "时间"
|
||||
},
|
||||
{
|
||||
"name": "year",
|
||||
"value": "年"
|
||||
},
|
||||
{
|
||||
"name": "month",
|
||||
"value": "月"
|
||||
},
|
||||
{
|
||||
"name": "day",
|
||||
"value": "日"
|
||||
},
|
||||
{
|
||||
"name": "tipsContent",
|
||||
"value": "为提高位置信息的精确度,应用和服务仍然会扫描WLAN网络.您可以在提高精确度中更改此设置"
|
||||
},
|
||||
{
|
||||
"name": "wifiList",
|
||||
"value": "可用WLAN列表"
|
||||
},
|
||||
{
|
||||
"name": "systemName",
|
||||
"value": "系统名称"
|
||||
},
|
||||
{
|
||||
"name": "model",
|
||||
"value": "型号"
|
||||
},
|
||||
{
|
||||
"name": "companyInfo",
|
||||
"value": "厂家信息"
|
||||
},
|
||||
{
|
||||
"name": "deviceId",
|
||||
"value": "设备"
|
||||
},
|
||||
{
|
||||
"name": "softwareVersion",
|
||||
"value": "软件版本"
|
||||
},
|
||||
{
|
||||
"name": "version",
|
||||
"value": "版本 "
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"value": "密码"
|
||||
},
|
||||
{
|
||||
"name": "connected",
|
||||
"value": "已连接"
|
||||
},
|
||||
{
|
||||
"name": "monday",
|
||||
"value": "星期一"
|
||||
},
|
||||
{
|
||||
"name": "tuesday",
|
||||
"value": "星期二"
|
||||
},
|
||||
{
|
||||
"name": "wednesday",
|
||||
"value": "星期三"
|
||||
},
|
||||
{
|
||||
"name": "thursday",
|
||||
"value": "星期四"
|
||||
},
|
||||
{
|
||||
"name": "friday",
|
||||
"value": "星期五"
|
||||
},
|
||||
{
|
||||
"name": "saturday",
|
||||
"value": "星期六"
|
||||
},
|
||||
{
|
||||
"name": "sunday",
|
||||
"value": "星期日"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 46 KiB |
24
entry/build.gradle → product/phone/build.gradle
Executable file → Normal file
24
entry/build.gradle → product/phone/build.gradle
Executable file → Normal file
@ -1,13 +1,13 @@
|
||||
apply plugin: 'com.huawei.ohos.hap'
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
arkEnabled false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
apply plugin: 'com.huawei.ohos.hap'
|
||||
ohos {
|
||||
compileSdkVersion 7
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
arkEnabled true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
1
product/phone/proguard-rules.pro
vendored
Normal file
1
product/phone/proguard-rules.pro
vendored
Normal file
@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
107
product/phone/src/main/config.json
Normal file
107
product/phone/src/main/config.json
Normal file
@ -0,0 +1,107 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.settings",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.settings",
|
||||
"name": ".MyApplication",
|
||||
"mainAbility": "com.ohos.settings.MainAbility",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "phone",
|
||||
"moduleType": "entry",
|
||||
"installationFree": true
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"visible": true,
|
||||
"name": "com.ohos.settings.MainAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"label": "$string:entry_MainAbility",
|
||||
"type": "page",
|
||||
"launchType": "standard",
|
||||
"srcPath": "default",
|
||||
"srcLanguage": "ets",
|
||||
"metaData": {
|
||||
"customizeData": [
|
||||
{
|
||||
"name": "hwc-theme"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"mode": {
|
||||
"syntax": "ets",
|
||||
"type": "pageAbility"
|
||||
},
|
||||
"pages": [
|
||||
"pages/settingList",
|
||||
"pages/searchPage",
|
||||
"pages/dateAndTime",
|
||||
"pages/application",
|
||||
"pages/applicationInfo",
|
||||
"pages/applicationStorage",
|
||||
"pages/brightnessSettings",
|
||||
"pages/aboutDevice",
|
||||
"pages/appManagement",
|
||||
"pages/wifi",
|
||||
"pages/wifiPsd",
|
||||
"pages/volumeControl",
|
||||
"pages/developerOptions",
|
||||
"pages/restoreFactorySettings",
|
||||
"pages/usersAccounts",
|
||||
"pages/multipleUsers",
|
||||
"pages/system/homePage",
|
||||
"pages/system/languageSettings/homePage",
|
||||
"pages/system/languageSettings/languageAndRegion/homePage",
|
||||
"pages/system/languageSettings/languageAndRegion/addLanguage",
|
||||
"pages/system/languageSettings/languageAndRegion/editLanguage",
|
||||
"pages/system/languageSettings/languageAndRegion/selectRegion",
|
||||
"pages/storage",
|
||||
"pages/locationServices",
|
||||
"pages/privacy",
|
||||
"pages/passwordSetting",
|
||||
"pages/passwordCheck",
|
||||
"pages/passwordInput",
|
||||
"pages/passwordRepeat"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"reqPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import AppManagementModel from '../../model/appManagementImpl/AppManagementModel.ets';
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
@LogAll
|
||||
export default class ApplicationInfoController extends BaseSettingsController {
|
||||
|
||||
/**
|
||||
* Get Uninstall api
|
||||
*/
|
||||
uninstall(bundleName: string) {
|
||||
AppManagementModel.uninstall(bundleName, (err) => {
|
||||
LogUtil.info(ConfigData.TAG + 'uninstall err : ' + JSON.stringify(err) + 'bundleName:' + bundleName);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill processes by bundle name
|
||||
*/
|
||||
killProcessesByBundleName(bundleName: string) {
|
||||
AppManagementModel.killProcessesByBundleName(bundleName, (err) => {
|
||||
LogUtil.info(ConfigData.TAG + 'killProcessesByBundleName err : ' + JSON.stringify(err) + 'bundleName:' + bundleName);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import AppManagementModel from '../../model/appManagementImpl/AppManagementModel.ets';
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
@LogAll
|
||||
export default class ApplicationStorageController extends BaseSettingsController {
|
||||
|
||||
/**
|
||||
* Clear up application data by bundle name
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
clearUpApplicationData(bundleName: string) {
|
||||
AppManagementModel.clearUpApplicationData(bundleName, (err) => {
|
||||
LogUtil.info(ConfigData.TAG + 'clearUpApplicationData err : ' + JSON.stringify(err) + 'bundleName:' + bundleName);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cache data of a specified application
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
cleanBundleCacheFiles(bundleName: string) {
|
||||
AppManagementModel.cleanBundleCacheFiles(bundleName, (err) => {
|
||||
LogUtil.info(ConfigData.TAG + 'cleanBundleCacheFiles err : ' + JSON.stringify(err) + 'bundleName:' + bundleName);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get storageList
|
||||
*/
|
||||
getStorageList() {
|
||||
return AppManagementModel.getStorageList();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import DeveloperOptionsModel from '../../model/developerOptionsImpl/DeveloperOptionsModel.ets'
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController'
|
||||
import SwitchController from '../../../../../../../../common/component/src/main/ets/default/controller/SwitchController.ets'
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
@LogAll
|
||||
export default class UsbDebuggingController extends SwitchController {
|
||||
/**
|
||||
* Initialize data.
|
||||
*/
|
||||
initData(): ISettingsController {
|
||||
super.initData();
|
||||
// usb current state
|
||||
let state = new Boolean(this.getUsbCurrentFunctions() & ConfigData.FUNCTION_TYPE_HDC).valueOf();
|
||||
this.isOn = state;
|
||||
LogUtil.info(ConfigData.TAG + `initData isOn:` + this.isOn);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get usb current functions state
|
||||
*/
|
||||
getUsbCurrentFunctions() {
|
||||
return DeveloperOptionsModel.getUsbCurrentFunctions();
|
||||
}
|
||||
|
||||
/**
|
||||
* After current value changed event
|
||||
*/
|
||||
afterCurrentValueChanged() {
|
||||
DeveloperOptionsModel.setCurrentFunctions(this.isOn);
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import LocationServicesModel from '../../model/locationServicesImpl/LocationServicesModel.ets'
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController'
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import SwitchController from '../../../../../../../../common/component/src/main/ets/default/controller/SwitchController.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
@LogAll
|
||||
export default class LocationServicesController extends SwitchController {
|
||||
|
||||
/**
|
||||
* Initialize data.
|
||||
*/
|
||||
initData(): ISettingsController {
|
||||
super.initData();
|
||||
this.isLocationEnabled((err, value) => {
|
||||
if (err) {
|
||||
LogUtil.info(ConfigData.TAG + 'initData -> isLocationEnabled err:' + JSON.stringify(err));
|
||||
this.isOn = false;
|
||||
} else {
|
||||
this.isOn = value;
|
||||
}
|
||||
})
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* obtain current location switch status
|
||||
*/
|
||||
isLocationEnabled(callback) {
|
||||
LocationServicesModel.isLocationEnabled(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* subscribe location switch changed
|
||||
*/
|
||||
subscribe(): ISettingsController {
|
||||
LocationServicesModel.onLocationServiceState((value) => {
|
||||
this.isOn = value;
|
||||
})
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* unsubscribe location switch changed
|
||||
*/
|
||||
unsubscribe(): ISettingsController {
|
||||
LocationServicesModel.offLocationServiceState((value) => {
|
||||
this.isOn = value;
|
||||
})
|
||||
return this;
|
||||
}
|
||||
|
||||
afterCurrentValueChanged() {
|
||||
if (this.isOn) {
|
||||
LocationServicesModel.enableLocation((err, data) => {
|
||||
LogUtil.info(ConfigData.TAG + 'afterCurrentValueChanged -> enableLocation err:' + JSON.stringify(err) + ',data:' + JSON.stringify(data));
|
||||
this.location(err, true);
|
||||
})
|
||||
} else {
|
||||
LocationServicesModel.disableLocation((err, data) => {
|
||||
LogUtil.info(ConfigData.TAG + 'afterCurrentValueChanged -> disableLocation err:' + JSON.stringify(err) + ',data:' + JSON.stringify(data));
|
||||
this.location(err, false);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* location switch
|
||||
*/
|
||||
location(err, data) {
|
||||
if (err) {
|
||||
this.isLocationEnabled((err, value) => {
|
||||
if (err) {
|
||||
LogUtil.info(ConfigData.TAG + 'afterCurrentValueChanged -> isLocationEnabled err:' + JSON.stringify(err));
|
||||
if (this.isOn) {
|
||||
this.isOn = false;
|
||||
}
|
||||
} else {
|
||||
this.isOn = value;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.isOn = data;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,259 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController';
|
||||
import PasswordModel, {ResultCode, PinSubType} from '../../model/passwordImpl/PasswordModel.ets';
|
||||
import Router from '@system.router';
|
||||
import prompt from '@system.prompt';
|
||||
|
||||
@LogAll
|
||||
export default class PasswordCheckController extends BaseSettingsController {
|
||||
private TAG = ConfigData.TAG + 'PasswordCheckController ';
|
||||
private pageRequestCode: number = -1
|
||||
private prevPageUri: string = undefined
|
||||
private pinChallenge: string = undefined
|
||||
private pinToken: string = undefined
|
||||
private passwordType: number = -1
|
||||
private freezingTime: number = 0
|
||||
private remainTimes: number = 0;
|
||||
private lockUi: boolean = false
|
||||
private authOk = false;
|
||||
|
||||
// private Properties
|
||||
private password: string = ''
|
||||
|
||||
initData(): ISettingsController {
|
||||
this.loadData()
|
||||
return this
|
||||
}
|
||||
|
||||
subscribe(): ISettingsController {
|
||||
PasswordModel.registerInputer();
|
||||
return this;
|
||||
};
|
||||
|
||||
unsubscribe(): ISettingsController {
|
||||
PasswordModel.unregisterInputer();
|
||||
return this;
|
||||
};
|
||||
|
||||
//------------------------------ Handler ---------------------------
|
||||
/**
|
||||
* change password type.
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
passwordOnChange(value: string) {
|
||||
if (this.lockUi) {
|
||||
return
|
||||
}
|
||||
this.password = value;
|
||||
LogUtil.info(this.TAG + 'passwordOnChange : passwordType = ' + this.passwordType + ', password = ' + this.password)
|
||||
this.checkInputDigits(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check input password digits.
|
||||
* When password type is PIN_SIX, password should be 6 digit numbers.
|
||||
* When password type is number or mixed, password should be fewer than 33 digits.
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
checkInputDigits(value: string) {
|
||||
if (this.passwordType == PinSubType.PIN_SIX) {
|
||||
if (value.length >= 6) {
|
||||
this.inputFinish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------ check ---------------------------
|
||||
/**
|
||||
* Input finish. Start simple check.
|
||||
*/
|
||||
inputFinish(event?: ClickEvent) {
|
||||
if (this.lockUi) {
|
||||
return
|
||||
}
|
||||
this.lockUi = true
|
||||
LogUtil.info(this.TAG + 'inputFinish : password = ' + this.password)
|
||||
|
||||
if (!this.password) {
|
||||
LogUtil.info(this.TAG + 'inputFinish return : password is none.')
|
||||
this.lockUi = false
|
||||
return;
|
||||
}
|
||||
|
||||
// clear page data
|
||||
this.freezingTime = -1
|
||||
this.remainTimes = -1;
|
||||
|
||||
this.checkInputSuccess()
|
||||
}
|
||||
|
||||
/**
|
||||
* Input check success.
|
||||
*/
|
||||
checkInputSuccess() {
|
||||
this.checkPasswordCorrect((result, extraInfo) => {
|
||||
LogUtil.info(this.TAG + 'checkInputSuccess : checkPasswordCorrect callback : result = ' + result + ', extraInfo = ' + JSON.stringify(extraInfo));
|
||||
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
if (extraInfo) {
|
||||
if (this.pinChallenge) {
|
||||
this.pinToken = extraInfo.token;
|
||||
}
|
||||
}
|
||||
LogUtil.info(this.TAG + 'checkInputSuccess : callback success. pinChallenge = ' + this.pinChallenge + ', pinToken = ' + this.pinToken);
|
||||
this.authSuccess()
|
||||
return;
|
||||
} else {
|
||||
if (extraInfo) {
|
||||
this.freezingTime = extraInfo.freezingTime;
|
||||
this.remainTimes = extraInfo.remainTimes;
|
||||
}
|
||||
this.lockUi = false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check password result changed.
|
||||
*/
|
||||
authSuccess() {
|
||||
LogUtil.info(`${this.TAG}resultChanged: pageRequestCode = ${this.pageRequestCode}`);
|
||||
if (this.pinToken && this.pageRequestCode == ConfigData.PAGE_REQUEST_CODE_PASSWORD_CHANGE) {
|
||||
prompt.showToast({ message: "auth success!!", duration: 3500 })
|
||||
this.authOk = true;
|
||||
|
||||
} else if (this.pinToken && this.pageRequestCode == ConfigData.PAGE_REQUEST_CODE_PASSWORD_DISABLE) {
|
||||
this.delCredential(() => {
|
||||
this.goBackCorrect();
|
||||
});
|
||||
|
||||
} else {
|
||||
this.goBackCorrect();
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------ Router -----------------------------
|
||||
/**
|
||||
* Go to password create page
|
||||
*/
|
||||
gotoPasswordCreatePage() {
|
||||
if (!this.authOk) {
|
||||
prompt.showToast({ message: "auth not succeed", duration: 3500 })
|
||||
return
|
||||
}
|
||||
LogUtil.info(`${this.TAG}gotoPasswordCreatePage : pageRequestCode: ${this.pageRequestCode}, prevPageUri = ${this.prevPageUri}, pageRequestCode: ${this.pageRequestCode}, pinChallenge: ${this.pinChallenge}, pinToken: ${this.pinToken}`);
|
||||
Router.replace({
|
||||
uri: 'pages/passwordInput',
|
||||
params: {
|
||||
'pageRequestCode': this.pageRequestCode,
|
||||
'prevPageUri': this.prevPageUri,
|
||||
'pinChallenge': this.pinChallenge,
|
||||
'pinToken': this.pinToken
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Auth check ok, return OK result.
|
||||
*/
|
||||
goBackCorrect() {
|
||||
Router.back()
|
||||
}
|
||||
|
||||
//------------------------------ api ---------------------------
|
||||
/**
|
||||
* Call api to check if has the password
|
||||
*/
|
||||
loadData() {
|
||||
PasswordModel.hasPinPassword((havePassword) => {
|
||||
LogUtil.info(this.TAG + 'hasPinPassword : havePassword = ' + havePassword);
|
||||
if (havePassword) {
|
||||
this.getAuthProperty();
|
||||
} else {
|
||||
this.goBackCorrect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call api to check the password
|
||||
*
|
||||
* @param value : password type
|
||||
*/
|
||||
checkPasswordCorrect(successCallback: (result: number, extraInfo: any) => void): void {
|
||||
PasswordModel.authPin(this.pinChallenge, this.password, (result, extraInfo) => {
|
||||
LogUtil.info(this.TAG + 'checkPasswordCorrect : result = ' + JSON.stringify(result) + ', extraInfo = ' + JSON.stringify(extraInfo));
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
LogUtil.info(`${this.TAG}checkPasswordCorrect success`);
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}checkPasswordCorrect failed`);
|
||||
}
|
||||
successCallback(result, extraInfo)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call api to get passwordType, freezingTime and remainTimes
|
||||
*
|
||||
* @param successCallback: api success callback
|
||||
*/
|
||||
getAuthProperty() {
|
||||
// todo for debug
|
||||
let data = JSON.parse('{"result":0,"authSubType":10001,"remainTimes":0,"freezingTime":0}');
|
||||
LogUtil.info(this.TAG + `getAuthProperty dummy data:${JSON.stringify(data)}`);
|
||||
this.passwordType = data.authSubType;
|
||||
this.freezingTime = data.freezingTime;
|
||||
this.remainTimes = data.remainTimes;
|
||||
// todo for debug
|
||||
|
||||
// //todo 调用该api之后,回调log能打出来,但是app崩溃
|
||||
// PasswordModel.getAuthProperty((data: any) => {
|
||||
// LogUtil.info(this.TAG + `getAuthProperty data:${JSON.stringify(data)}`);
|
||||
// this.passwordType = data.authSubType;
|
||||
// this.freezingTime = data.freezingTime;
|
||||
// this.remainTimes = data.remainTimes;
|
||||
// if (data.result === ResultCode.SUCCESS) {
|
||||
// LogUtil.info(`${this.TAG}getAuthProperty success`);
|
||||
// } else {
|
||||
// LogUtil.info(`${this.TAG}getAuthProperty failed`);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Call api to delete the credential
|
||||
*
|
||||
* @param successCallback: api success callback
|
||||
*/
|
||||
delCredential(successCallback) {
|
||||
PasswordModel.delAllCredential(this.pinToken, (result, extraInfo) => {
|
||||
LogUtil.info(`${this.TAG}delAllCredential->result:${result}, extraInfo:${JSON.stringify(extraInfo)}`);
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
LogUtil.info(`${this.TAG}delAllCredential success`);
|
||||
this.pinToken = '';
|
||||
successCallback();
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}delAllCredential failed`);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController';
|
||||
import { LogAll } from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import { PinSubType } from '../../model/passwordImpl/PasswordModel.ets';
|
||||
import Router from '@system.router';
|
||||
|
||||
let PASSWORD_MAX_LENGTH = 32
|
||||
let AUTH_SUB_TYPE_DEFAULT = PinSubType.PIN_SIX
|
||||
|
||||
@LogAll
|
||||
export default class PasswordInputController extends BaseSettingsController {
|
||||
private TAG = ConfigData.TAG + 'PasswordInputController ';
|
||||
private pageRequestCode: number = -1
|
||||
private prevPageUri: string = undefined
|
||||
private pinChallenge: string = undefined
|
||||
private pinToken: string = undefined
|
||||
private password: string = ''
|
||||
private passwordType: number = -1
|
||||
private checkMessage: string | Resource = ''
|
||||
|
||||
/**
|
||||
* Initialize data.
|
||||
*/
|
||||
initData(): ISettingsController {
|
||||
|
||||
LogUtil.info(this.TAG + 'initData start : passwordType = ' + this.passwordType)
|
||||
if (!this.passwordType || this.passwordType < 0) {
|
||||
LogUtil.info(this.TAG + 'initData : passwordType set DEFAULT')
|
||||
this.passwordType = AUTH_SUB_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
LogUtil.info(this.TAG + 'initData : passwordType = ' + this.passwordType)
|
||||
|
||||
return super.initData();
|
||||
}
|
||||
|
||||
//------------------------------ Handler ---------------------------
|
||||
/**
|
||||
* Change password type
|
||||
*
|
||||
* @param value : password type
|
||||
*/
|
||||
changePasswordType(value) {
|
||||
this.passwordType = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
passwordOnChange(value: string) {
|
||||
this.password = value;
|
||||
LogUtil.info(this.TAG + 'passwordOnChange : passwordType = ' + this.passwordType + ', password = ' + this.password)
|
||||
this.checkMessage = ''
|
||||
this.checkInputDigits(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check input password digits.
|
||||
* When password type is PIN_SIX, password should be 6 digit numbers.
|
||||
* When password type is number or mixed, password should be fewer than 33 digits.
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
checkInputDigits(value: string) {
|
||||
|
||||
// When password type is PIN_SIX, check number 6 digits
|
||||
if (this.passwordType == PinSubType.PIN_SIX) {
|
||||
this.checkMessage = ''
|
||||
if (value.length == 6) {
|
||||
this.inputFinish();
|
||||
}
|
||||
}
|
||||
|
||||
// Other type, check PIN fewer than 33 digits
|
||||
else if (this.checkMaxDigits(value)) {
|
||||
this.checkMessage = ''
|
||||
}
|
||||
|
||||
// 33 digits check error, show message
|
||||
else if (this.passwordType == PinSubType.PIN_NUMBER) {
|
||||
this.checkMessage = $r('app.string.password_PIN_check_max_error')
|
||||
} else if (this.passwordType == PinSubType.PIN_MIXED) {
|
||||
this.checkMessage = $r('app.string.password_check_max_error')
|
||||
}
|
||||
|
||||
LogUtil.info(this.TAG + 'checkInputDigits : checkMessage = ' + JSON.stringify(this.checkMessage));
|
||||
}
|
||||
|
||||
//------------------------------ check ---------------------------
|
||||
/**
|
||||
* check if the password less than 33 digits
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
checkMaxDigits(value: string): boolean {
|
||||
return value.length <= PASSWORD_MAX_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Input finish. Start simple check.
|
||||
*/
|
||||
inputFinish() {
|
||||
LogUtil.info(this.TAG + 'inputFinish : password = ' + this.password)
|
||||
|
||||
if (!this.password) {
|
||||
LogUtil.info(this.TAG + 'inputFinish return : password is none.')
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.checkMessage) {
|
||||
LogUtil.info(this.TAG + 'inputFinish return : has error yet.')
|
||||
return;
|
||||
}
|
||||
|
||||
this.checkInputSuccess()
|
||||
}
|
||||
|
||||
/**
|
||||
* Input check success.
|
||||
*/
|
||||
checkInputSuccess() {
|
||||
this.gotoRepeatPage();
|
||||
}
|
||||
|
||||
//------------------------------ Router ---------------------------
|
||||
/**
|
||||
* When password illegality check is ok, go to repeat input password page.
|
||||
*/
|
||||
gotoRepeatPage() {
|
||||
Router.replace({
|
||||
uri: 'pages/passwordRepeat',
|
||||
params: {
|
||||
'prevPageUri': this.prevPageUri,
|
||||
'pageRequestCode': this.pageRequestCode,
|
||||
'pinChallenge': this.pinChallenge,
|
||||
'pinToken': this.pinToken,
|
||||
'inputPassword': this.password,
|
||||
'passwordType': this.passwordType
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import PasswordModel, {PinSubType, ResultCode} from '../../model/passwordImpl/PasswordModel.ets';
|
||||
import Router from '@system.router';
|
||||
|
||||
let PASSWORD_MAX_LENGTH = 32
|
||||
|
||||
@LogAll
|
||||
export default class PasswordRepeatController extends BaseSettingsController {
|
||||
private TAG = ConfigData.TAG + 'PasswordRepeatController ';
|
||||
private pinToken: string = undefined
|
||||
private passwordType: number = -1
|
||||
private inputPassword: string = undefined
|
||||
private checkMessage: string | Resource = ''
|
||||
private password: string = ''
|
||||
|
||||
subscribe(): ISettingsController {
|
||||
PasswordModel.registerInputer();
|
||||
return this;
|
||||
};
|
||||
|
||||
unsubscribe(): ISettingsController {
|
||||
PasswordModel.unregisterInputer();
|
||||
return this;
|
||||
};
|
||||
|
||||
//------------------------------ Handler ---------------------------
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
passwordOnChange(value: string) {
|
||||
this.password = value;
|
||||
LogUtil.info(this.TAG + 'passwordOnChange : passwordType = ' + this.passwordType + ', password = ' + this.password)
|
||||
this.checkMessage = ''
|
||||
this.checkInputDigits(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check input password digits.
|
||||
* When password type is PIN_SIX, password should be 6 digit numbers.
|
||||
* When password type is number or mixed, password should be fewer than 33 digits.
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
checkInputDigits(value: string) {
|
||||
|
||||
// When password type is PIN_SIX, check number 6 digits
|
||||
if (this.passwordType == PinSubType.PIN_SIX) {
|
||||
this.checkMessage = ''
|
||||
if (value.length == 6) {
|
||||
this.inputFinish();
|
||||
}
|
||||
}
|
||||
|
||||
// Other type, check PIN fewer than 33 digits
|
||||
else if (this.checkMaxDigits(value)) {
|
||||
this.checkMessage = ''
|
||||
}
|
||||
|
||||
// 33 digits check error, show message
|
||||
else if (this.passwordType == PinSubType.PIN_NUMBER) {
|
||||
this.checkMessage = $r('app.string.password_PIN_check_max_error')
|
||||
} else if (this.passwordType == PinSubType.PIN_MIXED) {
|
||||
this.checkMessage = $r('app.string.password_check_max_error')
|
||||
}
|
||||
|
||||
LogUtil.info(this.TAG + 'checkInputDigits : checkMessage = ' + JSON.stringify(this.checkMessage));
|
||||
}
|
||||
|
||||
//------------------------------ check ---------------------------
|
||||
/**
|
||||
* check if the password less than 33 digits
|
||||
*
|
||||
* @param value : inputting password
|
||||
*/
|
||||
checkMaxDigits(value: string): boolean {
|
||||
return value.length <= PASSWORD_MAX_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Input finish. Start simple check.
|
||||
*/
|
||||
inputFinish() {
|
||||
LogUtil.info(this.TAG + 'inputFinish : password = ' + this.password + ', inputPassword = ' + this.inputPassword)
|
||||
|
||||
if (!this.password) {
|
||||
LogUtil.info(this.TAG + 'inputFinish return : password is none.')
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.checkMessage) {
|
||||
LogUtil.info(this.TAG + 'inputFinish return : has error yet.')
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.password == this.inputPassword) {
|
||||
if (this.pinToken) {
|
||||
this.updatePassword()
|
||||
} else {
|
||||
this.createPassword()
|
||||
}
|
||||
} else {
|
||||
// not match
|
||||
LogUtil.info(this.TAG + 'inputFinish : not match')
|
||||
this.checkMessage = $r('app.string.password_message_repeat_error')
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------ Router -----------------------------
|
||||
/**
|
||||
* Return OK result.
|
||||
*/
|
||||
goBackCorrect() {
|
||||
Router.back()
|
||||
}
|
||||
|
||||
//------------------------------ api ---------------------------
|
||||
/**
|
||||
* Call api to create password
|
||||
*/
|
||||
createPassword() {
|
||||
PasswordModel.addPinCredential(this.passwordType, this.password, (result) => {
|
||||
LogUtil.info(this.TAG + 'createPassword->result = ' + JSON.stringify(result));
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
LogUtil.info(`${this.TAG}createPassword success`);
|
||||
this.goBackCorrect()
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}createPassword failed`);
|
||||
//TODO show api message to view
|
||||
this.checkMessage = 'create failed.'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call api to update password
|
||||
*/
|
||||
updatePassword() {
|
||||
PasswordModel.updateCredential(this.passwordType, this.password, this.pinToken, (result, extraInfo) => {
|
||||
LogUtil.info(this.TAG + 'updateCredential->result = ' + JSON.stringify(result));
|
||||
LogUtil.info(this.TAG + 'updateCredential->extraInfo = ' + JSON.stringify(extraInfo));
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
LogUtil.info(`${this.TAG}updatePassword success`);
|
||||
this.goBackCorrect()
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}updatePassword failed`);
|
||||
//TODO show error message to view
|
||||
this.checkMessage = 'update failed.'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import PasswordModel from '../../model/passwordImpl/PasswordModel.ets';
|
||||
|
||||
@LogAll
|
||||
export default class PasswordSettingController extends BaseSettingsController {
|
||||
private TAG = ConfigData.TAG + 'PasswordSettingController ';
|
||||
private pinChallenge: string = '';
|
||||
private passwordList: any[] = [];
|
||||
|
||||
subscribe(): ISettingsController {
|
||||
PasswordModel.closeSession();
|
||||
PasswordModel.openSession((data) => {
|
||||
LogUtil.info(`${this.TAG}subscribe->openSession data:${data}`);
|
||||
if (data === '0') {
|
||||
LogUtil.info(`${this.TAG}subscribe->openSession failed`);
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}subscribe->openSession success`);
|
||||
}
|
||||
this.pinChallenge = data;
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
unsubscribe(): ISettingsController {
|
||||
PasswordModel.closeSession();
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load page data.
|
||||
* Get password from api. create data list of
|
||||
*/
|
||||
loadData() {
|
||||
// get password
|
||||
PasswordModel.hasPinPassword((passwordHasSet) => {
|
||||
|
||||
// update password settings list
|
||||
this.getListData(passwordHasSet , (list) => {
|
||||
LogUtil.info(this.TAG + 'getListData callback : list = ' + JSON.stringify(list));
|
||||
this.passwordList = list
|
||||
LogUtil.info(this.TAG + 'getListData callback : end ');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* When receive next page's result is ok, do here.
|
||||
*
|
||||
* @param routerParam : next page's result
|
||||
*/
|
||||
getListData(passwordHasSet: boolean, callback) {
|
||||
let list = this.getPageData();
|
||||
|
||||
for (let key in list) {
|
||||
let settingAlias = list[key].settingAlias;
|
||||
let shouldDisplay = true;
|
||||
let title;
|
||||
let requestCode = -1;
|
||||
switch (settingAlias) {
|
||||
case 'biometrics_section_title':
|
||||
shouldDisplay = passwordHasSet;
|
||||
title = $r('app.string.biometrics');
|
||||
break;
|
||||
|
||||
case 'face_recognition':
|
||||
title = $r('app.string.face_recognition')
|
||||
requestCode = ConfigData.PAGE_REQUEST_CODE_PASSWORD_FACE;
|
||||
break;
|
||||
|
||||
case 'password_section_title':
|
||||
shouldDisplay = passwordHasSet;
|
||||
title = $r('app.string.password');
|
||||
break;
|
||||
|
||||
case 'password_lock_screen':
|
||||
shouldDisplay = !passwordHasSet;
|
||||
title = $r('app.string.password_lock_screen');
|
||||
requestCode = ConfigData.PAGE_REQUEST_CODE_PASSWORD_CREATE;
|
||||
break;
|
||||
|
||||
case 'password_change_password':
|
||||
shouldDisplay = passwordHasSet;
|
||||
title = $r('app.string.password_change_password')
|
||||
requestCode = ConfigData.PAGE_REQUEST_CODE_PASSWORD_CHANGE;
|
||||
break;
|
||||
|
||||
case 'password_disable_password':
|
||||
shouldDisplay = passwordHasSet;
|
||||
title = $r('app.string.password_disable_password')
|
||||
requestCode = ConfigData.PAGE_REQUEST_CODE_PASSWORD_DISABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
list[key].settingShouldDisplay = shouldDisplay;
|
||||
list[key].settingTitle = title;
|
||||
list[key].settingRequestCode = requestCode;
|
||||
|
||||
}
|
||||
callback(list)
|
||||
|
||||
}
|
||||
|
||||
getPageData(): any[] {
|
||||
let list = [
|
||||
{
|
||||
settingIsSectionTitle: true,
|
||||
settingShouldDisplay: false,
|
||||
settingTitle: "",
|
||||
settingAlias: "biometrics_section_title",
|
||||
settingValue: "",
|
||||
settingArrow: "",
|
||||
settingRequestCode: "",
|
||||
settingUri: ""
|
||||
},
|
||||
{
|
||||
settingIsSectionTitle: false,
|
||||
settingShouldDisplay: true,
|
||||
settingTitle: "",
|
||||
settingAlias: "face_recognition",
|
||||
settingValue: "",
|
||||
settingArrow: "/res/image/ic_settings_arrow.svg",
|
||||
settingRequestCode: "",
|
||||
settingUri: ""
|
||||
},
|
||||
{
|
||||
settingIsSectionTitle: true,
|
||||
settingShouldDisplay: false,
|
||||
settingTitle: "",
|
||||
settingAlias: "password_section_title",
|
||||
settingValue: "",
|
||||
settingArrow: "",
|
||||
settingRequestCode: "",
|
||||
settingUri: ""
|
||||
},
|
||||
{
|
||||
settingIsSectionTitle: false,
|
||||
settingShouldDisplay: true,
|
||||
settingTitle: "",
|
||||
settingAlias: "password_lock_screen",
|
||||
settingValue: "",
|
||||
settingArrow: "/res/image/ic_settings_arrow.svg",
|
||||
settingRequestCode: "",
|
||||
settingUri: "pages/passwordInput"
|
||||
},
|
||||
{
|
||||
settingIsSectionTitle: false,
|
||||
settingShouldDisplay: false,
|
||||
settingTitle: "",
|
||||
settingAlias: "password_change_password",
|
||||
settingValue: "",
|
||||
settingArrow: "/res/image/ic_settings_arrow.svg",
|
||||
settingRequestCode: "",
|
||||
settingUri: "pages/passwordCheck"
|
||||
},
|
||||
{
|
||||
settingIsSectionTitle: false,
|
||||
settingShouldDisplay: false,
|
||||
settingTitle: "",
|
||||
settingAlias: "password_disable_password",
|
||||
settingValue: "",
|
||||
settingArrow: "",
|
||||
settingRequestCode: "",
|
||||
settingUri: "pages/passwordCheck"
|
||||
}
|
||||
]
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import RestoreFactorySettingsModel from '../../model/restoreFactorySettingsImpl/RestoreFactorySettingsModel.ets'
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController'
|
||||
|
||||
@LogAll
|
||||
export default class RestoreFactorySettingsController extends BaseSettingsController {
|
||||
|
||||
/**
|
||||
* Restore factorySettings
|
||||
*/
|
||||
restoreFactorySettings() {
|
||||
return RestoreFactorySettingsModel.rebootAndCleanUserData();
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import StorageModel from '../../model/StorageImpl/StorageModel.ets'
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import BaseSettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/BaseSettingsController.ets';
|
||||
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController'
|
||||
|
||||
enum Space {
|
||||
/**
|
||||
* Total space
|
||||
*/
|
||||
TOTAL_SPACE = '0',
|
||||
/**
|
||||
* Used space
|
||||
*/
|
||||
USED_SPACE = '1',
|
||||
/**
|
||||
* Remaining space
|
||||
*/
|
||||
REMAINING_SPACE = '2'
|
||||
}
|
||||
|
||||
@LogAll
|
||||
export default class storageController extends BaseSettingsController {
|
||||
private storageList: any[] = [];
|
||||
private totalSpace: number;
|
||||
private freeBytes: number;
|
||||
private usedSpace: number;
|
||||
|
||||
initData(): ISettingsController{
|
||||
super.initData();
|
||||
this.getTotalSpace();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get TotalSpace
|
||||
*/
|
||||
getTotalSpace() {
|
||||
StorageModel.getStorageDataDir((err, data: string) => {
|
||||
LogUtil.info(ConfigData.TAG + 'getStorageDataDir err: ' + JSON.stringify(err));
|
||||
LogUtil.info(ConfigData.TAG + 'getStorageDataDir data: ' + JSON.stringify(data));
|
||||
if (data && data.length > 0) {
|
||||
StorageModel.getTotalSpace(data, (err, data) => {
|
||||
LogUtil.info(ConfigData.TAG + 'getTotalSpace err: ' + JSON.stringify(err));
|
||||
LogUtil.info(ConfigData.TAG + 'getTotalSpace data: ' + JSON.stringify(data));
|
||||
if (data && data >= 0) {
|
||||
LogUtil.info(ConfigData.TAG + 'getTotalSpace success');
|
||||
this.totalSpace = data;
|
||||
this.getFreeBytes();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* get RemainingSpace
|
||||
*/
|
||||
getFreeBytes() {
|
||||
StorageModel.getStorageDataDir((err, data) => {
|
||||
LogUtil.info(ConfigData.TAG + 'getStorageDataDir err: ' + JSON.stringify(err));
|
||||
LogUtil.info(ConfigData.TAG + 'getStorageDataDir data: ' + JSON.stringify(data));
|
||||
if (data && data.length > 0) {
|
||||
StorageModel.getFreeBytes(data, (err, data) => {
|
||||
LogUtil.info(ConfigData.TAG + 'getFreeBytes err: ' + JSON.stringify(err));
|
||||
LogUtil.info(ConfigData.TAG + 'getFreeBytes data: ' + JSON.stringify(data));
|
||||
if (data && data >= 0) {
|
||||
this.storageList = [];
|
||||
LogUtil.info(ConfigData.TAG + 'getFreeBytes success');
|
||||
this.freeBytes = data;
|
||||
this.getUsedSpace();
|
||||
this.storageList = this.getStorageList();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* get UsedSpace
|
||||
*/
|
||||
getUsedSpace(){
|
||||
this.usedSpace = this.totalSpace - this.freeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get storage List
|
||||
*/
|
||||
getStorageList() {
|
||||
let storageList = StorageModel.getStorageItemList();
|
||||
for (let key in storageList) {
|
||||
LogUtil.info(ConfigData.TAG + 'Storage getStorageList key:' + key);
|
||||
switch (key) {
|
||||
case Space.TOTAL_SPACE:
|
||||
storageList[key].settingTitle = $r('app.string.totalSpace')
|
||||
storageList[key].settingValue = this.formatData(this.totalSpace);
|
||||
break;
|
||||
case Space.USED_SPACE:
|
||||
storageList[key].settingTitle = $r('app.string.usedSpace');
|
||||
storageList[key].settingValue = this.formatData(this.usedSpace);
|
||||
break;
|
||||
case Space.REMAINING_SPACE:
|
||||
storageList[key].settingTitle = $r('app.string.remainingSpace');
|
||||
storageList[key].settingValue = this.formatData(this.freeBytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
LogUtil.info(ConfigData.TAG + 'Storage getStorageList storageTitleValue out:' + JSON.stringify(storageList));
|
||||
return storageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* format data
|
||||
*/
|
||||
formatData(val) {
|
||||
let result = '';
|
||||
if (val < 1024) {
|
||||
result = `${val} B`;
|
||||
} else if (val < 1024 * 1024) {
|
||||
result = `${(val / 1024).toFixed(2)} KB`;
|
||||
} else if (val < 1024 * 1024 * 1024) {
|
||||
result = `${(val / (1024 * 1024)).toFixed(2)} MB`;
|
||||
} else if (val < 1024 * 1024 * 1024 * 1024) {
|
||||
result = `${(val / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -12,11 +12,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../BaseModel';
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import Bundle from '@ohos.bundle';
|
||||
import ResMgr from '@ohos.resourceManager';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import {BaseData} from '../BaseData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import {BaseData} from '../../../../../../../../common/utils/src/main/ets/default/model/BaseData.ets';
|
||||
import {MetaDataModel} from './MetaDataModel.ets';
|
||||
|
||||
let icon_arrow = $r('app.media.ic_settings_arrow');
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
|
||||
export class MetaDataModel {
|
||||
constructor(jsonData: string) {
|
@ -12,10 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../BaseModel';
|
||||
import BaseParseConfModel from '../baseParseConfImpl/BaseParseConfModel.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import BaseParseConfModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseParseConfModel.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
|
||||
/**
|
@ -12,10 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import BaseModel from '../BaseModel.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Bundle from '@ohos.bundle';
|
||||
import ResMgr from '@ohos.resourceManager';
|
||||
import AbilityManager from '@ohos.app.abilityManager'
|
||||
import BaseParseConfModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseParseConfModel.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
const INDEX = 0;
|
||||
const IS_INCLUDE_ABILITY_INFO = 0;
|
||||
@ -26,6 +30,7 @@ let icon_default = $r('app.media.icon_default');
|
||||
/**
|
||||
* app management service class
|
||||
*/
|
||||
@LogAll
|
||||
export class AppManagementModel extends BaseModel {
|
||||
private mBundleInfoList: any[]= [];
|
||||
/**
|
||||
@ -145,6 +150,83 @@ export class AppManagementModel extends BaseModel {
|
||||
}
|
||||
LogUtil.info('settings appManagement AppManagementModel getIconItem end');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get storageList
|
||||
*/
|
||||
getStorageList() {
|
||||
BaseParseConfModel.getJsonDataBase(ConfigData.FILE_URI.concat('applicationStorage.json'), baseData => {
|
||||
let applicationStorageList = this.setTitleValue(baseData);
|
||||
AppStorage.SetOrCreate('applicationStorageList', applicationStorageList);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Set titleValue
|
||||
*/
|
||||
setTitleValue(baseData) {
|
||||
let titleValue;
|
||||
for (let key in baseData) {
|
||||
let settingAlias = baseData[key].settingAlias;
|
||||
if ('storageTab' === settingAlias) {
|
||||
baseData[key].settingSummary = $r('app.string.storageTab')
|
||||
} else if ('totalTab' === settingAlias) {
|
||||
titleValue = $r('app.string.totalTab')
|
||||
} else if ('applyTab' === settingAlias) {
|
||||
titleValue = $r('app.string.applyTab')
|
||||
} else if ('dataTab' === settingAlias) {
|
||||
titleValue = $r('app.string.dataTab')
|
||||
} else if ('deleteDataTab' === settingAlias) {
|
||||
titleValue = $r('app.string.deleteDataTab')
|
||||
} else if ('cacheTab' === settingAlias) {
|
||||
titleValue = $r('app.string.cacheTab')
|
||||
} else if ('clearCacheTab' === settingAlias) {
|
||||
titleValue = $r('app.string.clearCacheTab')
|
||||
}
|
||||
baseData[key].settingTitle = titleValue
|
||||
}
|
||||
return baseData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear up application data by bundle name
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
clearUpApplicationData(bundleName: string, callback) {
|
||||
AbilityManager.clearUpApplicationData(bundleName, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cache data of a specified application.
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
cleanBundleCacheFiles(bundleName: string, callback) {
|
||||
Bundle.cleanBundleCacheFiles(bundleName, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall an application.
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
uninstall(bundleName: string, callback) {
|
||||
Bundle.getBundleInstaller((err: Error, bundleInstaller) => {
|
||||
if (err) {
|
||||
LogUtil.info(ConfigData.TAG + 'getBundleInstaller err : ' + JSON.stringify(err));
|
||||
}
|
||||
let installParam = { userId: 0, installFlag: 0, isKeepData: false };
|
||||
bundleInstaller.uninstall(bundleName, installParam, callback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill processes by bundle name
|
||||
* @param bundleName bundle name
|
||||
*/
|
||||
killProcessesByBundleName(bundleName: string, callback) {
|
||||
AbilityManager.killProcessesByBundleName(bundleName, callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let appManagementModel = new AppManagementModel();
|
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import settings from '@ohos.settings';
|
||||
import Brightness from '@ohos.brightness';
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
|
||||
/**
|
||||
* Brightness setting
|
||||
*
|
||||
* @param brightnessValue - Brightness value
|
||||
*/
|
||||
export class BrightnessSettingModel extends BaseModel{
|
||||
private dataAbilityHelper;
|
||||
private urivar:string;
|
||||
private settingsDataKey:string = ConfigData.SETTINGSDATA_BRIGHTNESS;
|
||||
private brightness:number = 5;
|
||||
private defaultBrightnessStr = '5';
|
||||
private TAG = ConfigData.TAG + 'BrightnessSettingModel ';
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.urivar = settings.getUri(this.settingsDataKey);
|
||||
this.dataAbilityHelper = featureAbility.acquireDataAbilityHelper(this.urivar);
|
||||
this.updateValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get brightness value in the BrightnessSettingModel
|
||||
*/
|
||||
@Log
|
||||
public getValue(){
|
||||
return this.brightness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*/
|
||||
@Log
|
||||
public setValue(brightness:number, sliderChangeMode:number){
|
||||
if(sliderChangeMode === ConfigData.SLIDER_CHANG_MODE_END){
|
||||
LogUtil.info(this.TAG + `setValue [brightness:${brightness}, sliderChangeMode:${sliderChangeMode}]`);
|
||||
this.setSettingsData(brightness);
|
||||
}else{
|
||||
this.setSystemBrightness(brightness);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set brightness value in the SettingsData
|
||||
*/
|
||||
@Log
|
||||
private setSettingsData(brightness:number){
|
||||
LogUtil.info(this.TAG + `setSettingsData [brightness:${brightness}]`);
|
||||
this.brightness = brightness;
|
||||
settings.setValue(this.dataAbilityHelper, this.settingsDataKey, brightness.toString());
|
||||
LogUtil.info(this.TAG + `setSettingsData success`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set system brightness value
|
||||
*/
|
||||
@Log
|
||||
private setSystemBrightness(brightness:number){
|
||||
this.brightness = brightness;
|
||||
Brightness.setValue(brightness);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update brightness value in the BrightnessSettingModel
|
||||
*/
|
||||
@Log
|
||||
private updateValue(){
|
||||
LogUtil.info(this.TAG + 'updateValue');
|
||||
this.brightness = parseInt(settings.getValue(this.dataAbilityHelper, this.settingsDataKey, this.defaultBrightnessStr));
|
||||
LogUtil.info(this.TAG + `updateValue success, [brightness:${this.brightness}]`);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register observer
|
||||
*/
|
||||
@Log
|
||||
public registerObserver(){
|
||||
LogUtil.info(this.TAG + 'registerObserver');
|
||||
this.dataAbilityHelper.on("dataChange", this.urivar, (err)=>{
|
||||
this.updateValue();
|
||||
})
|
||||
LogUtil.info(this.TAG + 'registerObserver success');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister observer
|
||||
*/
|
||||
@Log
|
||||
public unregisterObserver() {
|
||||
LogUtil.info(this.TAG + 'unregisterObserver');
|
||||
this.dataAbilityHelper.off("dataChange", this.urivar, (err)=>{
|
||||
LogUtil.info(this.TAG + 'unregisterObserver success');
|
||||
})
|
||||
return;
|
||||
}
|
||||
}
|
@ -12,10 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import Stable from '../../common/baseUtil/Global.ets'
|
||||
import rdbStore from '../../common/baseUtil/RdbStoreUtil.ets'
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import Stable from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/Global.ets';
|
||||
import rdbStore from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
class DataRdbModel {
|
||||
insertValues: any[] = [
|
@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import DataRdbModel from './DataRdbModel.ets';
|
||||
import Stable from '../../common/baseUtil/Global.ets';
|
||||
import LogUtil from '../../common/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../common/baseUtil/ConfigData.ets';
|
||||
import Stable from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/Global.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
class DataRdbService {
|
||||
/**
|
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import BaseParseConfModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseParseConfModel.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import SystemTime from '@ohos.systemTime';
|
||||
import settings from '@ohos.settings';
|
||||
import featureAbility from '@ohos.ability.featureAbility'
|
||||
|
||||
/**
|
||||
* Set date and time
|
||||
*/
|
||||
export class DateAndTimeModel extends BaseModel {
|
||||
timeFormat = null;
|
||||
|
||||
setTime(time) {
|
||||
LogUtil.info('DateAndTimeModel setTime in :' + time);
|
||||
SystemTime.setTime(time).then(data => {
|
||||
LogUtil.info(`DateAndTimeModel setTime promise then : ${data}`);
|
||||
})
|
||||
.catch(error => {
|
||||
LogUtil.info(`DateAndTimeModel setTime promise1 catch : ${error}`);
|
||||
}
|
||||
);
|
||||
LogUtil.info('DateAndTimeModel setTime out');
|
||||
}
|
||||
|
||||
getTimeFormat() : string {
|
||||
if (this.timeFormat === null) {
|
||||
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(ConfigData.TIME_FORMAT_URI);
|
||||
this.timeFormat = settings.getValue(dataAbilityHelper, ConfigData.TIME_FORMAT_KEY, ConfigData.TIME_FORMAT_24);
|
||||
LogUtil.info('DateAndTimeModel get time format is ' + this.timeFormat);
|
||||
}
|
||||
return this.timeFormat;
|
||||
}
|
||||
|
||||
setTimeFormatAs12H() : boolean {
|
||||
return this.setTimeFormat(ConfigData.TIME_FORMAT_12);
|
||||
}
|
||||
|
||||
setTimeFormatAs24H() : boolean {
|
||||
return this.setTimeFormat(ConfigData.TIME_FORMAT_24);
|
||||
}
|
||||
|
||||
public dateAndTimeListener(): any[] {
|
||||
LogUtil.info('getAboutDeviceInfoListener come in');
|
||||
return BaseParseConfModel.getJsonData(ConfigData.FILE_URI.concat('dateAndTime.json'));
|
||||
}
|
||||
|
||||
private setTimeFormat(format: string) : boolean {
|
||||
LogUtil.info('DateAndTimeModel set time format to ' + format);
|
||||
if (format != ConfigData.TIME_FORMAT_12 && format != ConfigData.TIME_FORMAT_24) {
|
||||
return false;
|
||||
}
|
||||
if (format === this.timeFormat) {
|
||||
return true;
|
||||
}
|
||||
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(ConfigData.TIME_FORMAT_URI);
|
||||
let ret = settings.setValue(dataAbilityHelper, ConfigData.TIME_FORMAT_KEY, format);
|
||||
if (ret === true) {
|
||||
this.timeFormat = format;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
let dateAndTimeModel = new DateAndTimeModel();
|
||||
export default dateAndTimeModel as DateAndTimeModel
|
||||
;
|
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import usb from '@ohos.usb';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
/**
|
||||
* Developer options model
|
||||
*/
|
||||
@LogAll
|
||||
export class DeveloperOptionsModel extends BaseModel {
|
||||
|
||||
/**
|
||||
* Get usb current functions state
|
||||
* @return state
|
||||
*/
|
||||
getUsbCurrentFunctions() {
|
||||
return usb.getCurrentFunctions()
|
||||
}
|
||||
|
||||
/**
|
||||
* set current functions
|
||||
* @param usbDebuggingState UsbDebugging state
|
||||
*/
|
||||
setCurrentFunctions(usbDebuggingState) {
|
||||
let funcs;
|
||||
if (usbDebuggingState) {
|
||||
funcs = ConfigData.FUNCTION_TYPE_HDC | this.getUsbCurrentFunctions()
|
||||
} else {
|
||||
funcs = (ConfigData.FUNCTION_TYPE_HDC | this.getUsbCurrentFunctions()) - ConfigData.FUNCTION_TYPE_HDC
|
||||
}
|
||||
usb.setCurrentFunctions(funcs).then((val) => {
|
||||
}).catch((err) => {
|
||||
LogUtil.info(ConfigData.TAG + `setCurrentFunctions fail:` + err);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let developerOptionsModel = new DeveloperOptionsModel();
|
||||
|
||||
export default developerOptionsModel as DeveloperOptionsModel
|
||||
;
|
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import geolocation from '@ohos.geolocation';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
export class LocationService {
|
||||
mIsStart: boolean = false;
|
||||
mListener: any;
|
||||
mLocationEventListener = geolocation?.LocationEventListener ? new (geolocation?.LocationEventListener)() :
|
||||
{
|
||||
on: (...args) => {
|
||||
},
|
||||
off: (...args) => {
|
||||
}
|
||||
};
|
||||
|
||||
startService() {
|
||||
if (this.mIsStart) {
|
||||
return;
|
||||
}
|
||||
LogUtil.info(ConfigData.TAG + 'start location service')
|
||||
this.mIsStart = true;
|
||||
this.getServiceState();
|
||||
this.mLocationEventListener.on('locationServiceState', (state) => {
|
||||
LogUtil.info(ConfigData.TAG + `start location service state: ${JSON.stringify(state)}`)
|
||||
this.mListener?.updateServiceState(state);
|
||||
});
|
||||
}
|
||||
|
||||
stopService() {
|
||||
if (!this.mIsStart) {
|
||||
return;
|
||||
}
|
||||
LogUtil.info(ConfigData.TAG + 'stop location service')
|
||||
this.mIsStart = false;
|
||||
this.mLocationEventListener.off('locationServiceState', (state) => {
|
||||
LogUtil.info(ConfigData.TAG + `stop location service state: ${JSON.stringify(state)}`)
|
||||
});
|
||||
}
|
||||
|
||||
registerListener(listener: {
|
||||
'updateServiceState': Function,
|
||||
}) {
|
||||
LogUtil.info(ConfigData.TAG + `register locations listener : ${listener}`)
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
getServiceState() {
|
||||
LogUtil.info(ConfigData.TAG + 'get location state')
|
||||
geolocation.isLocationEnabled().then((data) => {
|
||||
LogUtil.info(ConfigData.TAG + `get location state, data: ${JSON.stringify(data)}`)
|
||||
this.mListener?.updateServiceState(data);
|
||||
});
|
||||
}
|
||||
|
||||
enableLocation() {
|
||||
LogUtil.info(ConfigData.TAG + 'enable location')
|
||||
geolocation.enableLocation()
|
||||
.then((res) => LogUtil.info(ConfigData.TAG + `enable location, result: ${JSON.stringify(res)}`));
|
||||
}
|
||||
|
||||
disableLocation() {
|
||||
LogUtil.info(ConfigData.TAG + 'disable location')
|
||||
geolocation.disableLocation()
|
||||
.then((res) => LogUtil.info(ConfigData.TAG + `disable location, result: ${JSON.stringify(res)}`));
|
||||
}
|
||||
}
|
||||
|
||||
let locationService = new LocationService();
|
||||
|
||||
export default locationService as LocationService;
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import LocationService from './LocationService.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
export const LocationServiceOpenStatusKey = "LocationServiceStatus";
|
||||
|
||||
export class LocationVM {
|
||||
mIsStart: boolean = false;
|
||||
|
||||
initViewModel() {
|
||||
if (this.mIsStart) {
|
||||
return;
|
||||
}
|
||||
LogUtil.info(ConfigData.TAG + 'init location view model')
|
||||
this.mIsStart = true;
|
||||
LocationService.registerListener(this);
|
||||
LocationService.startService();
|
||||
}
|
||||
|
||||
updateServiceState(state) {
|
||||
LogUtil.info(ConfigData.TAG + `update location service state, state: ${state} `)
|
||||
AppStorage.SetOrCreate(LocationServiceOpenStatusKey, state);
|
||||
}
|
||||
|
||||
enableLocation() {
|
||||
LogUtil.info(ConfigData.TAG + 'enable location')
|
||||
LocationService.enableLocation();
|
||||
}
|
||||
|
||||
disableLocation() {
|
||||
LogUtil.info(ConfigData.TAG + 'disable location')
|
||||
LocationService.disableLocation();
|
||||
}
|
||||
}
|
||||
|
||||
let locationVM = new LocationVM();
|
||||
|
||||
export default locationVM as LocationVM;
|
@ -0,0 +1,489 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import { LogAll } from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import util from '@ohos.util';
|
||||
import UserIDM from '@ohos.useridm'
|
||||
import UserAuth from '@ohos.userauth'
|
||||
import PinAuth from '@ohos.pinauth'
|
||||
|
||||
/**
|
||||
* Credential type for authentication
|
||||
*/
|
||||
export enum AuthType {
|
||||
/**
|
||||
* Authentication type pin.
|
||||
*/
|
||||
PIN = 1,
|
||||
/**
|
||||
* Authentication type face.
|
||||
*/
|
||||
FACE = 2
|
||||
}
|
||||
|
||||
export enum PinSubType {
|
||||
/**
|
||||
* Authentication sub type six number pin.
|
||||
*/
|
||||
PIN_SIX = 10000,
|
||||
/**
|
||||
* Authentication sub type self defined number pin.
|
||||
*/
|
||||
PIN_NUMBER = 10001,
|
||||
/**
|
||||
* Authentication sub type self defined mixed pin.
|
||||
*/
|
||||
PIN_MIXED = 10002,
|
||||
}
|
||||
|
||||
/**
|
||||
* Result code
|
||||
*/
|
||||
export enum ResultCode {
|
||||
/**
|
||||
* success
|
||||
*/
|
||||
SUCCESS = 0,
|
||||
/**
|
||||
* fails
|
||||
*/
|
||||
FAIL = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication method
|
||||
*/
|
||||
export enum AuthMethod {
|
||||
/**
|
||||
* Authentication method PIN.
|
||||
*/
|
||||
PIN_ONLY = 0xF,
|
||||
/**
|
||||
* Authentication method face.
|
||||
*/
|
||||
FACE_ONLY = 0xF0
|
||||
}
|
||||
|
||||
/**
|
||||
* Credibility level of certification results
|
||||
*/
|
||||
enum AuthTrustLevel {
|
||||
/**
|
||||
* Authentication result trusted level 1.
|
||||
*/
|
||||
ATL1 = 10000,
|
||||
/**
|
||||
* Authentication result trusted level 2.
|
||||
*/
|
||||
ATL2 = 20000,
|
||||
/**
|
||||
* Authentication result trusted level 3.
|
||||
*/
|
||||
ATL3 = 30000,
|
||||
/**
|
||||
* Authentication result trusted level 4.
|
||||
*/
|
||||
ATL4 = 40000
|
||||
}
|
||||
|
||||
/**
|
||||
* Actuator attribute list
|
||||
*/
|
||||
enum GetPropertyType {
|
||||
/**
|
||||
* Authentication remain times.
|
||||
*/
|
||||
AUTH_SUB_TYPE = 1,
|
||||
/**
|
||||
* Authentication remain times.
|
||||
*/
|
||||
REMAIN_TIMES = 2,
|
||||
/**
|
||||
* Authentication freezing time.
|
||||
*/
|
||||
FREEZING_TIME = 3
|
||||
}
|
||||
|
||||
@LogAll
|
||||
export class PasswordModel extends BaseModel {
|
||||
private TAG = ConfigData.TAG + 'PasswordModel#';
|
||||
pinAuth: any;
|
||||
userAuth: any;
|
||||
userIdentityManager: any;
|
||||
password: string;
|
||||
pinSubType: number;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
this.userIdentityManager = UserIDM.constructor();
|
||||
this.pinAuth = PinAuth.constructor();
|
||||
this.userAuth = UserAuth.constructor();
|
||||
}
|
||||
|
||||
u8AToStr(val: Uint8Array): any{
|
||||
var dataString = "";
|
||||
var arrNumber = [];
|
||||
for (var i = 0; i < val.length; i++) {
|
||||
arrNumber.push(val[i]);
|
||||
}
|
||||
dataString = JSON.stringify(arrNumber);
|
||||
return dataString
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert array json to Uint8Array
|
||||
*
|
||||
* @return Uint8Array
|
||||
*/
|
||||
strToU8A(val: string): Uint8Array{
|
||||
var arr = JSON.parse(val);
|
||||
var tmpUint8Array = new Uint8Array(arr);
|
||||
return tmpUint8Array
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert encode string to Uint8Array
|
||||
*
|
||||
* @return Uint8Array
|
||||
*/
|
||||
encodeToU8A(val: string): Uint8Array{
|
||||
var textEncoder = new util.TextEncoder();
|
||||
return textEncoder.encode(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Inputer
|
||||
*/
|
||||
registerInputer(): boolean {
|
||||
let result = false;
|
||||
try {
|
||||
result = this.pinAuth.registerInputer({
|
||||
onGetData: (authSubType, inputData) => {
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData pAuthSubType:${authSubType}`);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData inAuthSubType:${this.pinSubType}`);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData inPassword:${this.password}`);
|
||||
let u8aPwd = this.encodeToU8A(this.password);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData inputData.onSetData : encodeToU8A password:${u8aPwd}`);
|
||||
inputData.onSetData(this.pinSubType, u8aPwd);
|
||||
}
|
||||
});
|
||||
LogUtil.info(`${this.TAG}registerInputer->result:${result}`);
|
||||
if(!result){
|
||||
this.unregisterInputer();
|
||||
result = this.pinAuth.registerInputer({
|
||||
onGetData: (authSubType, inputData) => {
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData(retry) pAuthSubType:${authSubType}`);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData(retry) inAuthSubType:${this.pinSubType}`);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData(retry) inPassword:${this.password}`);
|
||||
let u8aPwd = this.encodeToU8A(this.password);
|
||||
LogUtil.info(`${this.TAG}registerInputer->onGetData(retry) inputData.onSetData : encodeToU8A password:${u8aPwd}`);
|
||||
inputData.onSetData(this.pinSubType, u8aPwd);
|
||||
}
|
||||
});
|
||||
LogUtil.info(`${this.TAG}registerInputer->result(retry):${result}`);
|
||||
}
|
||||
} catch {
|
||||
LogUtil.info(`${this.TAG}registerInputer failed`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* UnregisterInputer
|
||||
*/
|
||||
unregisterInputer(): void {
|
||||
try {
|
||||
this.pinAuth.unregisterInputer();
|
||||
} catch {
|
||||
LogUtil.info(`${this.TAG}unregisterInputer failed`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Session
|
||||
* A challenge value of 0 indicates that opensession failed
|
||||
*
|
||||
* @returns challenge value
|
||||
*/
|
||||
openSession(callback: (challenge: string) => void): void {
|
||||
try {
|
||||
this.userIdentityManager.openSession((data) => {
|
||||
LogUtil.info(`${this.TAG}openSession challenge:${data}`);
|
||||
callback(this.u8AToStr(data));
|
||||
})
|
||||
} catch {
|
||||
LogUtil.info(`${this.TAG}openSession failed`);
|
||||
callback('0');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close session
|
||||
*/
|
||||
closeSession(): void {
|
||||
try {
|
||||
this.userIdentityManager.closeSession()
|
||||
LogUtil.info(`${this.TAG}closeSession success`);
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}closeSession failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel entry and pass in challenge value
|
||||
*
|
||||
* @param challenge challenge value.
|
||||
*/
|
||||
cancel(challenge: string): number {
|
||||
let result = ResultCode.FAIL;
|
||||
try {
|
||||
let data = this.strToU8A(challenge);
|
||||
let result = this.userIdentityManager.cancel(data)
|
||||
LogUtil.info(`${this.TAG}cancel success`);
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}cancel failed:` + e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user credential information, pass in credential addition method and credential information
|
||||
* (credential type, subclass, if adding user's non password credentials, pass in password authentication token),
|
||||
* and get the result callback
|
||||
*
|
||||
* @param pinSubType pinSubType
|
||||
* @param password password
|
||||
* @param onResultCall Get results callback.
|
||||
*/
|
||||
addPinCredential(pinSubType: number, password: string, onResultCall: (result: number) => void): void {
|
||||
try {
|
||||
this.pinSubType = pinSubType;
|
||||
this.password = password;
|
||||
let token = new Uint8Array([]);
|
||||
let credentialInfo = {
|
||||
credType: AuthType.PIN, credSubType: pinSubType, token: token
|
||||
}
|
||||
let callback = {
|
||||
onResult: (result, extraInfo) => {
|
||||
LogUtil.info(`${this.TAG}addPinCredential result:${JSON.stringify(result)}, extraInfo:${JSON.stringify(extraInfo)}`);
|
||||
onResultCall(result);
|
||||
}
|
||||
};
|
||||
this.userIdentityManager.addCredential(credentialInfo, callback);
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}addPinCredential failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user credential information
|
||||
*
|
||||
* @param credentialInfo (credential type, subclass, password authentication token).
|
||||
* @param onResult Get results callback.
|
||||
*/
|
||||
updateCredential(pinSubType: number, password: string, token: string, onResultCall: (result: number, extraInfo: {
|
||||
credentialId?: string;
|
||||
}) => void): void {
|
||||
try {
|
||||
this.pinSubType = pinSubType;
|
||||
this.password = password;
|
||||
let dataToken = this.strToU8A(token);
|
||||
let credentialInfo = {
|
||||
credType: AuthType.PIN, credSubType: pinSubType, token: dataToken
|
||||
}
|
||||
let callback = {
|
||||
onResult: (result, extraInfo) => {
|
||||
LogUtil.info(`${this.TAG}updateCredential result:${JSON.stringify(result)}`);
|
||||
LogUtil.info(`${this.TAG}updateCredential extraInfo:${JSON.stringify(extraInfo)}`);
|
||||
let retExtraInfo = {}
|
||||
onResultCall(result, retExtraInfo);
|
||||
}
|
||||
};
|
||||
this.userIdentityManager.updateCredential(credentialInfo, callback);
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}updateCredential failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all credential information
|
||||
*
|
||||
* @param token Password authentication token.
|
||||
* @param onResultCallback Get results callback.
|
||||
*/
|
||||
delAllCredential(token: string, onResultCallback: (result: number, extraInfo: {}) => void): void {
|
||||
try{
|
||||
let callback = {
|
||||
onResult:(result, extraInfo) => {
|
||||
LogUtil.info(`${this.TAG}delAllCredential result:${JSON.stringify(result)}`);
|
||||
LogUtil.info(`${this.TAG}delAllCredential extraInfo:${JSON.stringify(extraInfo)}`);
|
||||
let retExtraInfo = {}
|
||||
onResultCallback(result, retExtraInfo);
|
||||
}
|
||||
};
|
||||
let data = this.strToU8A(token);
|
||||
this.userIdentityManager.delUser(data, callback);
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}updateCredential failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if has pin password
|
||||
*
|
||||
* @param callback Get results callback.
|
||||
*/
|
||||
hasPinPassword(callback: (havePassword: boolean) => void): void {
|
||||
this.getPinAuthInfo((data) => {
|
||||
LogUtil.info(`${this.TAG}hasPinPassword->getPinAuthInfo data:${JSON.stringify(data)}`);
|
||||
let passwordHasSet = false;
|
||||
if(data?.length && data.length > 0){
|
||||
passwordHasSet = true;
|
||||
}
|
||||
LogUtil.info(`${this.TAG}hasPinPassword->getPinAuthInfo : before callback: passwordHasSet = ${passwordHasSet}`);
|
||||
callback(passwordHasSet)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AuthInfo
|
||||
*
|
||||
* @param authType Credential type.
|
||||
* @returns Returns all registered credential information of this type for the current user
|
||||
*/
|
||||
getPinAuthInfo(callback: (data: Array<{
|
||||
authType: number;
|
||||
authSubType: number;
|
||||
}>) => void): void {
|
||||
try {
|
||||
this.userIdentityManager.getAuthInfo(AuthType.PIN, (data) => {
|
||||
LogUtil.info(`${this.TAG}getPinAuthInfo->getAuthInfo data:${JSON.stringify(data)}`);
|
||||
let arrCredInfo = [];
|
||||
try{
|
||||
for(let i = 0; i < data.length; i++) {
|
||||
let credInfo = {
|
||||
'authType': data[i].authType,
|
||||
'authSubType': data[i].authSubType
|
||||
};
|
||||
arrCredInfo.push(credInfo);
|
||||
}
|
||||
} catch(e) {
|
||||
console.info('faceDemo pin.getAuthInfo error = ' + e);
|
||||
}
|
||||
LogUtil.info(`${this.TAG}getPinAuthInfo->getAuthInfo before callback: data array:${JSON.stringify(arrCredInfo)}`);
|
||||
callback(arrCredInfo);
|
||||
})
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}getPinAuthInfo failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auth
|
||||
*
|
||||
* @param challenge pass in challenge value.
|
||||
* @param password password
|
||||
* @param onResult Return results through callback.
|
||||
*/
|
||||
authPin(challenge: string, password: string, onResult: (result: number, extraInfo: {
|
||||
token?: string;
|
||||
remainTimes?: number;
|
||||
freezingTime?: number;
|
||||
}) => void): void {
|
||||
this.password = password;
|
||||
try {
|
||||
LogUtil.info(`${this.TAG}authPin : ( ${challenge}, ${AuthType.PIN}, ${AuthTrustLevel.ATL4} )`);
|
||||
this.userAuth.auth(this.strToU8A(challenge), AuthType.PIN, AuthTrustLevel.ATL4, {
|
||||
onResult: (result, extraInfo) => {
|
||||
try{
|
||||
LogUtil.info(`${this.TAG}userAuth.auth onResult: challenge = ${challenge}, result:${result}, extraInfo:${extraInfo}`);
|
||||
let info
|
||||
if (result === ResultCode.SUCCESS) {
|
||||
LogUtil.info(`${this.TAG}userAuth.auth onResult: result = success`);
|
||||
info = {
|
||||
'token': this.u8AToStr(extraInfo?.token),
|
||||
'remainTimes': extraInfo?.remainTimes,
|
||||
'freezingTime': extraInfo?.freezingTime
|
||||
}
|
||||
} else {
|
||||
LogUtil.info(`${this.TAG}userAuth.auth onResult: result = failed`);
|
||||
}
|
||||
onResult(result, info)
|
||||
}
|
||||
catch(e) {
|
||||
LogUtil.info(`${this.TAG}userAuth.auth onResult error = ${JSON.stringify(e)}`);
|
||||
}
|
||||
},
|
||||
|
||||
onAcquireInfo: (acquireModule, acquire, extraInfo) => {
|
||||
try{
|
||||
LogUtil.info(this.TAG + 'faceDemo pin.auth onAcquireInfo acquireModule = ' + acquireModule);
|
||||
console.info(this.TAG + 'faceDemo pin.auth onAcquireInfo acquire = ' + acquire);
|
||||
LogUtil.info(this.TAG + 'faceDemo pin.auth onAcquireInfo extraInfo = ' + JSON.stringify(extraInfo));
|
||||
}
|
||||
catch(e) {
|
||||
LogUtil.info(this.TAG + 'faceDemo pin.auth onAcquireInfo error = ' + e);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}AuthPin failed:` + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getProperty
|
||||
*
|
||||
* @param callback Return results through callback.
|
||||
*/
|
||||
getAuthProperty(callback: (data: {
|
||||
result: number;
|
||||
authSubType: number;
|
||||
remainTimes ?: number;
|
||||
freezingTime ?: number;
|
||||
}) => void): void {
|
||||
try {
|
||||
let request = {
|
||||
'authType': AuthType.PIN,
|
||||
'keys': [GetPropertyType.AUTH_SUB_TYPE, GetPropertyType.REMAIN_TIMES, GetPropertyType.FREEZING_TIME]
|
||||
}
|
||||
LogUtil.info(`${this.TAG}getAuthProperty->call api request = ${JSON.stringify(request)}`);
|
||||
|
||||
this.userAuth.getProperty(request)
|
||||
.then((data)=> {
|
||||
let i = JSON.stringify(data);
|
||||
console.info('faceDemo promise.getProperty result i = ' + i);
|
||||
console.info('faceDemo promise.getProperty result = ' + data);
|
||||
|
||||
LogUtil.info(`${this.TAG}getAuthProperty->getProperty data:${JSON.stringify(data)}`);
|
||||
callback(data);
|
||||
})
|
||||
.catch(e =>{
|
||||
LogUtil.info(`${this.TAG}getAuthProperty->getProperty failed:` + e);
|
||||
});
|
||||
} catch (e) {
|
||||
LogUtil.info(`${this.TAG}getAuthProperty failed:` + e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let passwordModel = new PasswordModel();
|
||||
export default passwordModel as PasswordModel;
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import BaseModel from '../../../../../../../../common/utils/src/main/ets/default/model/BaseModel.ets';
|
||||
import Updater from '@ohos.update';
|
||||
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import {LogAll} from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
|
||||
/**
|
||||
* Restore factorySettings model
|
||||
*/
|
||||
@LogAll
|
||||
export class RestoreFactorySettingsModel extends BaseModel {
|
||||
|
||||
|
||||
/**
|
||||
* Reboot and clean userData
|
||||
*/
|
||||
rebootAndCleanUserData(callback?: (value) => void) {
|
||||
Updater.getUpdater('/data/updater/updater.zip', 'OTA').rebootAndCleanUserData().then((value) => {
|
||||
LogUtil.log(ConfigData.TAG + "rebootAndCleanUserData value:" + value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let restoreFactorySettingsModel = new RestoreFactorySettingsModel();
|
||||
|
||||
export default restoreFactorySettingsModel as RestoreFactorySettingsModel
|
||||
;
|
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import Log from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import PageSearchDataProvider from '../../../../../../../../common/search/src/main/ets/default/provider/PageSearchDataProvider.ets';
|
||||
import WifiModel from '../../model/wifiImpl/WifiModel.ets';
|
||||
|
||||
const SEARCH_DATA = {
|
||||
title: $r('app.string.wifiTab'),
|
||||
data: [
|
||||
{
|
||||
keyword: $r('app.string.wifiTab'),
|
||||
summary: $r('app.string.tipsContent'),
|
||||
synonym: $r('app.string.wifiSynonym')
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* Dummy provider as an example, and should be removed in the further.
|
||||
*
|
||||
*/
|
||||
export class DummyProvider extends PageSearchDataProvider {
|
||||
|
||||
/**
|
||||
* Get page search data
|
||||
*/
|
||||
@Log
|
||||
getPageSearchData(): any {
|
||||
let searchData = SEARCH_DATA
|
||||
|
||||
if (WifiModel.isWiFiActive()) {
|
||||
searchData.data.push(
|
||||
{
|
||||
keyword: $r('app.string.wifiList'),
|
||||
summary: undefined,
|
||||
synonym: $r('app.string.wifiListSynonym')
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return searchData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let dummyProvider = new DummyProvider();
|
||||
export default dummyProvider as DummyProvider
|
||||
;
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import SettingListProvider from '../../model/settingListImpl/SettingListProvider.ets';
|
||||
import WifiProvider from '../../model/wifiImpl/WifiProvider.ets';
|
||||
import DummyProvider from './DummyProvider.ets';
|
||||
|
||||
/**
|
||||
* Search data config
|
||||
*/
|
||||
const SEARCH_DATA_CONFIG = [
|
||||
{
|
||||
settingUri: 'pages/settingList',
|
||||
settingRawJson: 'settinglist.json',
|
||||
provider: SettingListProvider
|
||||
},
|
||||
{
|
||||
settingUri: 'pages/wifi',
|
||||
settingRawJson: 'wifi.json',
|
||||
provider: WifiProvider
|
||||
},
|
||||
// DummyProvider as example, and should be removed in the further.
|
||||
{
|
||||
settingUri: 'pages/wifi',
|
||||
settingRawJson: 'wifi.json',
|
||||
provider: DummyProvider
|
||||
}
|
||||
];
|
||||
|
||||
export default SEARCH_DATA_CONFIG;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user