diff --git a/README_zh.md b/README_zh.md index 0441cfd2ca8116aff9bd9ba0aff98516580804f3..882b3319eb05751a75932cca82f3000dc3dcc365 100644 --- a/README_zh.md +++ b/README_zh.md @@ -21,6 +21,8 @@ - [`TicTacToeGame:`井字过三关(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/CompleteApps/TicTacToeGame) - ETSUI - [`eTSBuildCommonView:`创建简单视图(eTS)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/ETSUI/eTSBuildCommonView) + - [`eTSBuildCommonView:`创建简单视图(eTS)(API8)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/ETSUI/eTSBuildCommonView(API8)) + - [`eTSArkUIAnimation:`动画(eTS)(API8)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/ETSUI/eTSArkUIAnimation) - [`eTSDefiningPageLayoutAndConnection:`页面布局和连接(eTS)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/ETSUI/eTSDefiningPageLayoutAndConnection) - [`eTSDrawingAndAnimation:`绘图和动画(eTS)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/ETSUI/eTSDrawingAndAnimation) - JAVAUI @@ -87,12 +89,14 @@ - [`Compass:`指南针(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/device/Compass) - [`Location:`位置(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/device/Location) - [`Setting:`设置(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/device/Setting) + - [`Sensor:`传感器(eTS)(API8)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/device/Sensor) - media - [`Audio:`音频(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/Audio) - [`AudioPlayer:`媒体会话(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/AudioPlayer) - [`Camera:`相机(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/Camera) - [`PixelMap:`图像(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/PixelMap) - [`VideoPlayer:`视频播放(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/VideoPlayer) + - [`MediaQuery:`媒体查询(eTS)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/media/MediaQuery) - native - [`JSNativeDemo:`JSNativeDemo(JS,C++)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/native/JSNativeDemo) - [`NativeImage:`Native_image(Java,C++)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/native/NativeImage) @@ -111,6 +115,9 @@ - thread - [`EventHandler:`线程间通信(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/thread/EventHandler) - [`TaskDispatcher:`线程管理(Java)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/thread/TaskDispatcher) +- utils + - [`UtilUrlString:`URL字符串解析(eTS) (API8)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/utils/UtilUrlString) + - [`XmlTextConvert:`xml文本转换(eTS) (API8)](https://gitee.com/harmonyos/harmonyos_app_samples/tree/master/utils/XmlTextConvert) ## 使用说明 diff --git a/device/Sensor/README.md b/device/Sensor/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e5951778c3358722bf427f2d95b9cda775780fea --- /dev/null +++ b/device/Sensor/README.md @@ -0,0 +1,15 @@ +### Device Management - Sensor + +##### Introduction + +This sample uses the orientation sensor APIs to implement the compass effect. + +##### Usage + +When you rotate your device, the compass pointer rotates with it. The rotation angle is an angle away from the north and is displayed in the lower part of the home screen of the sample app. + +##### Constraints + +After opening the sample app, you need to make a figure 8 until your compass is calibrated. + +This sample can only be run on standard-system devices. (Currently, only wagner is supported.) diff --git a/device/Sensor/README_zh.md b/device/Sensor/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..341f6f10a6839422ad269cc52edd28da520086a1 --- /dev/null +++ b/device/Sensor/README_zh.md @@ -0,0 +1,17 @@ +### 传感器 + +##### 简介 + +本示例采用了传感器接口中的方向传感器,实现了指南针的效果。 + +##### 使用说明 + +转动设备,指针跟随转动,转动的角度为偏离正北方的角度,并在界面下方显示。 + +##### 约束与限制 + +1.打开应用后需要对传感器进行画8校准。 + +2.本示例仅支持在标准系统上运行(目前仅支持wagner)。 + +3.本示例需要使用3.0.0.961及以上的DevEco Studio版本才可编译运行。 \ No newline at end of file diff --git a/device/Sensor/build-profile.json5 b/device/Sensor/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93837fc1d8d6dc6643e776931d00938fa9f0e42e --- /dev/null +++ b/device/Sensor/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "compileSdkVersion": 8, + "compatibleSdkVersion": 8, + "products": [ + { + "name": "default", + "signingConfig": "default" + }, + ], + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default", + ], + }, + ], + }, + ], +} \ No newline at end of file diff --git a/device/Sensor/entry/build-profile.json5 b/device/Sensor/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae58d1d0a70c602c9cfe1909b00dfec899ba1944 --- /dev/null +++ b/device/Sensor/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'faMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/device/Sensor/entry/hvigorfile.js b/device/Sensor/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..bcec4c99653062cbf17702c40a2dd2a7b809b81a --- /dev/null +++ b/device/Sensor/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').legacyHapTasks diff --git a/device/Sensor/entry/package.json b/device/Sensor/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..dfa2726ff1c9ad35dcbf24c5feb7928630b5c6d2 --- /dev/null +++ b/device/Sensor/entry/package.json @@ -0,0 +1,11 @@ +{ + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "version": "1.0.0", + "dependencies": {} +} diff --git a/device/Sensor/entry/src/main/config.json b/device/Sensor/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..649cb6a83eea448f498d14d3324a99e425232559 --- /dev/null +++ b/device/Sensor/entry/src/main/config.json @@ -0,0 +1,71 @@ +{ + "app": { + "bundleName": "ohos.samples.etssensor", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etssensor", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/Index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.VIBRATE" + } + ] + } +} \ No newline at end of file diff --git a/device/Sensor/entry/src/main/ets/MainAbility/app.ets b/device/Sensor/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2eb18d66dc1b9324405a13e48bce34d033da27b2 --- /dev/null +++ b/device/Sensor/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/device/Sensor/entry/src/main/ets/MainAbility/pages/Index.ets b/device/Sensor/entry/src/main/ets/MainAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b096d63f05ddd2fb687db5597959318f0ba6091f --- /dev/null +++ b/device/Sensor/entry/src/main/ets/MainAbility/pages/Index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 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 sensor from '@ohos.sensor' + +const TAG = '[sensor]' + +@Entry +@Component +struct Index { + @State angle: number = 0 + @State calibration: number = 0 + @State angleTest: string = '0°' + + aboutToAppear() { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data){ + console.info(`${TAG} component: on`) + console.info(`${TAG} X-coordinate component: ${data.beta}`) + console.info(`${TAG} Y-coordinate component: ${data.gamma}`) + console.info(`${TAG} Z-coordinate component: ${data.alpha}`) + this.calibration = Math.round(data.alpha) + this.angle = -(this.calibration - 135) + if ((this.calibration - 90) < 0) { + this.angleTest = (270 + this.calibration) + '°' + } else { + this.angleTest = (this.calibration - 90) + '°' + } + }.bind(this), { interval: 10000000 }) + } + + build() { + Column() { + Column() { + Text('北') + .fontSize(20) + .margin({ left: '60%' }) + + Image($r('app.media.compass')) + .objectFit(ImageFit.Auto) + .rotate({ + x: 0, + y: 0, + z: 1, + angle: this.angle + }) + .size({ width: '40%', height: '70%' }) + } + .width('100%') + .margin({ top: '10%' }) + + Text(this.angleTest) + .fontSize(30) + } + } +} \ No newline at end of file diff --git a/device/Sensor/entry/src/main/resources/base/element/string.json b/device/Sensor/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..084cf4d482f22eeec6ca55e012ed3e9626725131 --- /dev/null +++ b/device/Sensor/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSSensor" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/device/Sensor/entry/src/main/resources/base/media/compass.png b/device/Sensor/entry/src/main/resources/base/media/compass.png new file mode 100644 index 0000000000000000000000000000000000000000..3c5de9be290be6f5991816e5827f9b222566a9f1 Binary files /dev/null and b/device/Sensor/entry/src/main/resources/base/media/compass.png differ diff --git a/device/Sensor/entry/src/main/resources/base/media/icon.png b/device/Sensor/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/device/Sensor/entry/src/main/resources/base/media/icon.png differ diff --git a/device/Sensor/hvigorfile.js b/device/Sensor/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..cff9f0dfcf8cb00cca34e7f50d61380cf5496868 --- /dev/null +++ b/device/Sensor/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').legacyAppTasks \ No newline at end of file diff --git a/device/Sensor/package.json b/device/Sensor/package.json new file mode 100644 index 0000000000000000000000000000000000000000..caee6f42c70e8c188cc7892962e9f708a8c402d5 --- /dev/null +++ b/device/Sensor/package.json @@ -0,0 +1,15 @@ +{ + "devDependencies":{}, + "name":"etssensor", + "ohos":{ + "org":"huawei", + "directoryLevel":"project", + "buildTool":"hvigor" + }, + "version":"1.0.0", + "dependencies":{ + "@ohos/hvigor-ohos-plugin":"1.0.6", + "hypium":"^1.0.0", + "@ohos/hvigor":"1.0.6" + } +} \ No newline at end of file diff --git a/device/Sensor/screenshots/device/sensor.png b/device/Sensor/screenshots/device/sensor.png new file mode 100644 index 0000000000000000000000000000000000000000..f6afc87e0a11cba98366d9ff60a7f3dd68c09dbe Binary files /dev/null and b/device/Sensor/screenshots/device/sensor.png differ diff --git a/media/MediaQuery/README.md b/media/MediaQuery/README.md new file mode 100644 index 0000000000000000000000000000000000000000..07da093220d2cbe1ec78ef87de74324ec8510ac3 --- /dev/null +++ b/media/MediaQuery/README.md @@ -0,0 +1,15 @@ +# ArkUI - Media Query + +### Introduction + + This sample shows how to use **MediaQuery** to display different UI effects on different devices. + +### Usage + +1. On a portrait device, the news list is displayed on the home screen of the sample app. You can touch a piece of news to access the details page. + +2. On a landscape device, the news list is displayed on the left side of the home screen of the sample app, and the news details are displayed on the right side. You can touch any news on the left to show its details on the right. + +### Constraints + +This sample can only be run on standard-system devices. diff --git a/media/MediaQuery/README_zh.md b/media/MediaQuery/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..3adc9bfa2f5647c72b516b3dce895b53c046de33 --- /dev/null +++ b/media/MediaQuery/README_zh.md @@ -0,0 +1,17 @@ +# 媒体查询 + +### 简介 + +此Demo展示如何使用媒体查询,完成在不同设备上显示不同的界面效果。 + +### 使用说明 + +1.在竖屏设备上,首页展示新闻列表,点击新闻进入详情界面。 + +2.在横屏设备上,首页左侧展示新闻列表,右侧显示新闻详情,点击新闻右侧显示所点击的新闻的详情。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行。 + +2.本示例需要使用3.0.0.961及以上的DevEco Studio版本才可编译运行。 diff --git a/media/MediaQuery/build-profile.json5 b/media/MediaQuery/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93837fc1d8d6dc6643e776931d00938fa9f0e42e --- /dev/null +++ b/media/MediaQuery/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "compileSdkVersion": 8, + "compatibleSdkVersion": 8, + "products": [ + { + "name": "default", + "signingConfig": "default" + }, + ], + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default", + ], + }, + ], + }, + ], +} \ No newline at end of file diff --git a/media/MediaQuery/entry/build-profile.json5 b/media/MediaQuery/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae58d1d0a70c602c9cfe1909b00dfec899ba1944 --- /dev/null +++ b/media/MediaQuery/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'faMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/media/MediaQuery/entry/hvigorfile.js b/media/MediaQuery/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..bcec4c99653062cbf17702c40a2dd2a7b809b81a --- /dev/null +++ b/media/MediaQuery/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').legacyHapTasks diff --git a/media/MediaQuery/entry/package.json b/media/MediaQuery/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..9f23d7bbc710fcbf9efd89bb8e164f0d1d83453b --- /dev/null +++ b/media/MediaQuery/entry/package.json @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "ohos": { + "org": "huawei", + "buildTool": "hvigor", + "directoryLevel": "module" + }, + "dependencies": {} +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/config.json b/media/MediaQuery/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a467ac4779c7aab88b5ea5fe3b0e22d0c9f6df21 --- /dev/null +++ b/media/MediaQuery/entry/src/main/config.json @@ -0,0 +1,68 @@ +{ + "app": { + "bundleName": "ohos.samples.etsmediaquery", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsmediaquery", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "srcPath": "", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/Index", + "pages/New" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/app.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b99d22ade609cefd8d0294dacea119adbe2ffbb --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/common/NewView.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/common/NewView.ets new file mode 100644 index 0000000000000000000000000000000000000000..03b148ab688919c7c6b342744094227a432bbbc2 --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/common/NewView.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 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. + */ +@Component +export struct NewView{ + @Link currentNew:any + + build(){ + Column(){ + Text(this.currentNew.content) + .fontSize(22) + .width('100%') + Image(this.currentNew.img) + .width('100%') + .objectFit(ImageFit.Fill) + .margin({top:10,bottom:10}) + .height('30%') + } + .height('100%') + .padding(15) + .layoutWeight(3) + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleBar.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleBar.ets new file mode 100644 index 0000000000000000000000000000000000000000..4230ec81db189644cfa021dd18781fff1c29da9a --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleBar.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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. + */ +@Component +export struct TitleBar { + private title: Resource = $r("app.string.entry_MainAbility") + + build() { + Row() { + Text(this.title) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .fontSize(30) + .layoutWeight(1) + } + .width('100%') + .height('8%') + .constraintSize({ minHeight: 50 }) + .padding({ left: 10 }) + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleWithBack.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleWithBack.ets new file mode 100644 index 0000000000000000000000000000000000000000..57d3a8c652510d4588a82287a057b678315986ad --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/common/TitleWithBack.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 router from '@ohos.router' + +@Component +export struct TitleBar { + private title: string = '' + + build() { + Row() { + Image($r('app.media.back')) + .size({ width: 50, height: '100%' }) + .objectFit(ImageFit.Contain) + .margin({ left: 10 }) + .onClick(() => { + router.back() + }) + Text(this.title) + .fontColor(Color.Black) + .fontSize(25) + .layoutWeight(1) + } + .size({ width: '100%', height: '8%' }) + .constraintSize({ minHeight: 50 }) + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/model/New.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/model/New.ets new file mode 100644 index 0000000000000000000000000000000000000000..261f6186d6845c727fc2f6763aca6b506690f8a3 --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/model/New.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 const newsList = [{ title: $r('app.string.new_title1'), publisher: $r('app.string.new_publisher1'), newId: 0 }, + { title: $r('app.string.new_title2'), publisher: $r('app.string.new_publisher2'), newId: 1 }, + { title: $r('app.string.new_title3'), publisher: $r('app.string.new_publisher3'), newId: 2 }, + { title: $r('app.string.new_title4'), publisher: $r('app.string.new_publisher4'), newId: 3 }] + +export const newsContent = [{ newId: 0, content: $r('app.string.new_content1'), img: $r('app.media.new1') }, + { newId: 1, content: $r('app.string.new_content2'), img: $r('app.media.new2') }, + { newId: 2, content: $r('app.string.new_content3'), img: $r('app.media.new3') }, + { newId: 3, content: $r('app.string.new_content4'), img: $r('app.media.new4') }] + +export function getNew(id) { + for (let i = 0;i < newsContent.length; i++) { + if (newsContent[i].newId == id) { + return newsContent[i] + } + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/pages/Index.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..166e3c85c63534b819c59ea9c1c35899de5c3301 --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/pages/Index.ets @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 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 router from '@ohos.router' +import mediaQuery from '@ohos.mediaquery' +import { TitleBar } from '../common/TitleBar' +import { newsList, getNew } from '../model/New' +import { NewView } from '../common/NewView' + +@Entry +@Component +struct Index { + private listener = mediaQuery.matchMediaSync('screen and (min-aspect-ratio: 1.5) or (orientation: landscape)') + @State currentNew: any = getNew(0) + @State isLand: boolean = false + + onLand(mediaQueryResult) { + console.info(`[eTSMediaQuery.Index]onLand: mediaQueryResult.matches=${mediaQueryResult.matches}`) + if (mediaQueryResult.matches) { + this.isLand = true + } else { + this.isLand = false + } + } + + aboutToAppear() { + this.listener.on('change', this.onLand.bind(this)) + } + + build() { + Row() { + Column() { + TitleBar() + List() { + ForEach(newsList, (item) => { + ListItem() { + Flex({ + direction: FlexDirection.Column, + alignContent: FlexAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text(item.title) + .width('100%') + .fontSize(22) + Text(item.publisher) + .width('100%') + .fontSize(18) + .fontColor(Color.Gray) + } + .padding(10) + .height('10%') + .constraintSize({ minHeight: 80 }) + .backgroundColor(Color.White) + } + .onClick(() => { + if (!this.isLand) { + router.push({ + params: { title: item.title, newId: item.newId }, + url: 'pages/New' }) + } else { + this.currentNew = getNew(item.newId) + } + }) + }, item => JSON.stringify(item)) + } + .layoutWeight(1) + .divider({ strokeWidth: 1, startMargin: 15, endMargin: 15 }) + .padding({ left: 10, right: 10 }) + } + .layoutWeight(2) + .height('100%') + .backgroundColor('#F5F5F5') + + if (this.isLand) { + NewView({ currentNew: $currentNew }) + } + } + .size({ width: '100%', height: '100%' }) + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/ets/MainAbility/pages/New.ets b/media/MediaQuery/entry/src/main/ets/MainAbility/pages/New.ets new file mode 100644 index 0000000000000000000000000000000000000000..e19df2dfb4c57dbea8927f57e27a0f0a0f8a6da4 --- /dev/null +++ b/media/MediaQuery/entry/src/main/ets/MainAbility/pages/New.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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 router from '@ohos.router' +import { NewView } from '../common/NewView' +import { getNew } from '../model/New' +import { TitleBar } from '../common/TitleWithBack' + +@Entry +@Component +struct New { + private newId: number = router.getParams()['newId'] + private title: string = router.getParams()['title'] + @State currentNew: { newId: number,content: Resource, img: Resource } = undefined + + aboutToAppear() { + this.currentNew = getNew(this.newId) + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + TitleBar({ title: this.title }) + NewView({ currentNew: $currentNew }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/resources/base/element/string.json b/media/MediaQuery/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e3181d50ba8261c3ad20cdc210afc145b135cbc0 --- /dev/null +++ b/media/MediaQuery/entry/src/main/resources/base/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSMediaQuery" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "new_title1", + "value": "Cats are kept daily today." + }, + { + "name": "new_title2", + "value": "Winter Olympic food record." + }, + { + "name": "new_title3", + "value": "What are you doing during the pandemic。" + }, + { + "name": "new_title4", + "value": "Exquisite women's dressing skills." + }, + { + "name": "new_publisher1", + "value": "Hot news." + }, + { + "name": "new_publisher2", + "value": "CCTV News." + }, + { + "name": "new_publisher3", + "value": "Baby elephant video。" + }, + { + "name": "new_publisher4", + "value": "Vogue." + }, + { + "name": "new_content1", + "value": "daily:\n(1) Cut your nails once a week or so.\n(2) You can take a bath once a month for twenty days or a month.\n(3) Change the cat litter of the pot about once a week, and a bag of 18L cat litter can be used for about 20 days.\n(4) Cats can be neutered after six months of age." + }, + { + "name": "new_content2", + "value": "The athletes' menu has 678 specialties for about 200 specialties per day for athletes from all over the world\nIn terms of catering services, the service standards, time and content of the three Winter Olympic villages in Beijing, Yanqing and Zhangjiakou are unified." + }, + { + "name": "new_content3", + "value": "Of course, the first thing we have to correct is the mentality, that is, the mentality of fighting the epidemic, there are many party members and volunteers rushing to the front line, eating instant noodles at the checkpoint, using simple prevention and control measures, close contact with outsiders to collect information, you can dedicate yourself like them, through effective ways to contribute their own strength。" + }, + { + "name": "new_content4", + "value": "Since ancient times, the beauty that can withstand the blows of the years, generally will know how to manage their own women, such a beauty will not be because of the passage of time, the loss of collagen on the face, will make the image of the whole person greatly discounted, but through the accumulation of exquisite collocation, so that the image of the whole person looks always so elegant and decent." + } + ] +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/resources/base/media/back.png b/media/MediaQuery/entry/src/main/resources/base/media/back.png new file mode 100644 index 0000000000000000000000000000000000000000..b3d744266caee755cf833b70a13d4726782e7b7f Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/back.png differ diff --git a/media/MediaQuery/entry/src/main/resources/base/media/icon.png b/media/MediaQuery/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/icon.png differ diff --git a/media/MediaQuery/entry/src/main/resources/base/media/new1.png b/media/MediaQuery/entry/src/main/resources/base/media/new1.png new file mode 100644 index 0000000000000000000000000000000000000000..408057b38163cdc5d9dc360014717e2dcc744cff Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/new1.png differ diff --git a/media/MediaQuery/entry/src/main/resources/base/media/new2.png b/media/MediaQuery/entry/src/main/resources/base/media/new2.png new file mode 100644 index 0000000000000000000000000000000000000000..e136d552c3ea57088ea911d122a876819741234f Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/new2.png differ diff --git a/media/MediaQuery/entry/src/main/resources/base/media/new3.png b/media/MediaQuery/entry/src/main/resources/base/media/new3.png new file mode 100644 index 0000000000000000000000000000000000000000..34690f9986b41c3f1b479d8472ffd512fcb6a927 Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/new3.png differ diff --git a/media/MediaQuery/entry/src/main/resources/base/media/new4.png b/media/MediaQuery/entry/src/main/resources/base/media/new4.png new file mode 100644 index 0000000000000000000000000000000000000000..edfa1afc4b5fd4a7e96e057f3b6a1b7c1f936966 Binary files /dev/null and b/media/MediaQuery/entry/src/main/resources/base/media/new4.png differ diff --git a/media/MediaQuery/entry/src/main/resources/en/element/string.json b/media/MediaQuery/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e3181d50ba8261c3ad20cdc210afc145b135cbc0 --- /dev/null +++ b/media/MediaQuery/entry/src/main/resources/en/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSMediaQuery" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "new_title1", + "value": "Cats are kept daily today." + }, + { + "name": "new_title2", + "value": "Winter Olympic food record." + }, + { + "name": "new_title3", + "value": "What are you doing during the pandemic。" + }, + { + "name": "new_title4", + "value": "Exquisite women's dressing skills." + }, + { + "name": "new_publisher1", + "value": "Hot news." + }, + { + "name": "new_publisher2", + "value": "CCTV News." + }, + { + "name": "new_publisher3", + "value": "Baby elephant video。" + }, + { + "name": "new_publisher4", + "value": "Vogue." + }, + { + "name": "new_content1", + "value": "daily:\n(1) Cut your nails once a week or so.\n(2) You can take a bath once a month for twenty days or a month.\n(3) Change the cat litter of the pot about once a week, and a bag of 18L cat litter can be used for about 20 days.\n(4) Cats can be neutered after six months of age." + }, + { + "name": "new_content2", + "value": "The athletes' menu has 678 specialties for about 200 specialties per day for athletes from all over the world\nIn terms of catering services, the service standards, time and content of the three Winter Olympic villages in Beijing, Yanqing and Zhangjiakou are unified." + }, + { + "name": "new_content3", + "value": "Of course, the first thing we have to correct is the mentality, that is, the mentality of fighting the epidemic, there are many party members and volunteers rushing to the front line, eating instant noodles at the checkpoint, using simple prevention and control measures, close contact with outsiders to collect information, you can dedicate yourself like them, through effective ways to contribute their own strength。" + }, + { + "name": "new_content4", + "value": "Since ancient times, the beauty that can withstand the blows of the years, generally will know how to manage their own women, such a beauty will not be because of the passage of time, the loss of collagen on the face, will make the image of the whole person greatly discounted, but through the accumulation of exquisite collocation, so that the image of the whole person looks always so elegant and decent." + } + ] +} \ No newline at end of file diff --git a/media/MediaQuery/entry/src/main/resources/zh/element/string.json b/media/MediaQuery/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..79d35d325c596168b3956f71773e075bd561fbac --- /dev/null +++ b/media/MediaQuery/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTS媒体查询" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "new_title1", + "value": "冬日养猫日常." + }, + { + "name": "new_title2", + "value": "冬奥美食记." + }, + { + "name": "new_title3", + "value": "疫情期间你在干什么。" + }, + { + "name": "new_title4", + "value": "精致女人穿搭技巧." + }, + { + "name": "new_publisher1", + "value": "热点新闻." + }, + { + "name": "new_publisher2", + "value": "央视新闻." + }, + { + "name": "new_publisher3", + "value": "小象视频。" + }, + { + "name": "new_publisher4", + "value": "时尚." + }, + { + "name": "new_content1", + "value": "日常:\n①一周左右剪一次指甲 。\n②二十来天或者一个月可以洗一次澡澡 。\n③一周左右换一次屎盆子的猫砂,一袋18L的猫砂大概可以用20天。\n④猫咪六个月大以后可以做绝育 。" + }, + { + "name": "new_content2", + "value": "运动员菜单678道特色菜品每天约200道供各国运动员食用\n在餐饮服务上,北京、延庆、张家口三个冬奥村的服务标准、时间和内容统一。" + }, + { + "name": "new_content3", + "value": "我们首先要摆正的当然是心态,那就是抗疫的心态,有不少党员、志愿者冲到第一线,在检查点吃着泡面,用着简单的防控措施,近距离接触外来人员去采集信息,你可以像他们一样去奉献自己,通过有效的途径去贡献自己的力量。" + }, + { + "name": "new_content4", + "value": "自古以来,经得起岁月打击的美人,一般都是会懂得经营自己的女人,这样的美人不会因为岁月的流逝,脸上胶原蛋白的流失,就会让整个人的形象大打折扣,而是通过日积月累的精致搭配,让整个人的形象看起来永远那么优雅又得体。" + } + ] +} \ No newline at end of file diff --git a/media/MediaQuery/hvigorfile.js b/media/MediaQuery/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..cff9f0dfcf8cb00cca34e7f50d61380cf5496868 --- /dev/null +++ b/media/MediaQuery/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').legacyAppTasks \ No newline at end of file diff --git a/media/MediaQuery/package.json b/media/MediaQuery/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4655808b050819f5e94abe98971d3c5e5ce7dce8 --- /dev/null +++ b/media/MediaQuery/package.json @@ -0,0 +1,15 @@ +{ + "devDependencies":{}, + "name":"etsmediaquery", + "ohos":{ + "org":"huawei", + "directoryLevel":"project", + "buildTool":"hvigor" + }, + "version":"1.0.0", + "dependencies":{ + "@ohos/hvigor-ohos-plugin":"1.0.6", + "hypium":"^1.0.0", + "@ohos/hvigor":"1.0.6" + } +} \ No newline at end of file diff --git a/media/MediaQuery/screenshots/device/land.png b/media/MediaQuery/screenshots/device/land.png new file mode 100644 index 0000000000000000000000000000000000000000..91bded8d3e95dc5ccdbb9990c35fbea30f49f62f Binary files /dev/null and b/media/MediaQuery/screenshots/device/land.png differ diff --git a/media/MediaQuery/screenshots/device/main.png b/media/MediaQuery/screenshots/device/main.png new file mode 100644 index 0000000000000000000000000000000000000000..a7d4382cda03d318c47413bda71462df65372f95 Binary files /dev/null and b/media/MediaQuery/screenshots/device/main.png differ diff --git a/media/MediaQuery/screenshots/device/new.png b/media/MediaQuery/screenshots/device/new.png new file mode 100644 index 0000000000000000000000000000000000000000..171076aa80b4c1c3853feccc0c237b9c1411e9af Binary files /dev/null and b/media/MediaQuery/screenshots/device/new.png differ