diff --git a/application/AppScope/app.json b/application/AppScope/app.json index 73903a844dc8b8a4e590f07c36b23142b99ae8ad..6dd83f4fdaed00e33acd04b80cbdea3a9511f885 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000041, - "versionName": "1.0.41", + "versionCode": 10000042, + "versionName": "1.0.42", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index 6ff633fb2022cf0a3a547adacf6443c8b529b54f..e43d9ffcb46007f31983bfaa7a7c9a0a1034375a 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000041, - "versionName": "1.0.41", + "versionCode": 10000042, + "versionName": "1.0.42", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/entry/src/main/ets/mechextability/MechExtAbility.ets b/application/entry/src/main/ets/mechextability/MechExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6c237f3178d29caea779ccff79fda82e28e76bb --- /dev/null +++ b/application/entry/src/main/ets/mechextability/MechExtAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../utils/Logger'; + +const TAG: string = '[MechExtAbility]'; + +export default class MechExtAbility extends UIExtensionAbility { + onCreate() { + logger.info(`${TAG} UIExtAbility onCreate`); + AppStorage.setOrCreate('currentColorMode', this.context.config.colorMode); + AppStorage.setOrCreate('currentFontSizeScale', this.context.config.fontSizeScale); + } + + onForeground() { + logger.info(`${TAG} UIExtAbility onForeground`); + } + + onBackground() { + logger.info(`${TAG} UIExtAbility onBackground`); + } + + onDestroy() { + logger.info(`${TAG} UIExtAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + logger.info(`${TAG} UIExtAbility onSessionCreate.`); + let param: Record = { + 'session': session + }; + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/MechControl', storage); + session.setWindowBackgroundColor('#00000000'); + logger.info(`${TAG} onSessionCreate end.`); + } + + onSessionDestroy(session: UIExtensionContentSession) { + logger.info(`${TAG} UIExtAbility onSessionDestroy`); + } +} \ No newline at end of file diff --git a/application/entry/src/main/ets/pages/MechControl.ets b/application/entry/src/main/ets/pages/MechControl.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5320487f9a7de3ebe4c1770e03f7becc8eec351 --- /dev/null +++ b/application/entry/src/main/ets/pages/MechControl.ets @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2025 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 { logger } from '../utils/Logger'; +import mechanicManager from '@ohos.distributedHardware.mechanicManager'; +import { BusinessError } from '@ohos.base'; + +const TAG = '[MechControl_Page] : '; + +@Entry +@Component +struct MechControl { + @State isTrackingEnabled: boolean = false; + @State currentTrackingLayoutText: ResourceStr = $r('app.string.mech_center'); + @State currentTrackingLayoutImage: ResourceStr = $r('app.media.track_layout_center'); + + + aboutToAppear() { + logger.info(`${TAG} aboutToAppear in`); + } + + @Builder + IntelligentTracking(){ + Column(){ + Button() { + Image(this.isTrackingEnabled ? $r('app.media.intelligent_tracking') :$r('app.media.intelligent_tracking_dark')) + .width(20) + .height(20) + .margin({left: 3, top: 3}) + } + .width('40vp') + .height('40vp') + .backgroundColor(this.isTrackingEnabled ? $r('app.color.color_0A59F7_blue') : $r('sys.color.ohos_id_color_component_normal')) + .onClick(() => { + this.isTrackingEnabled = !this.isTrackingEnabled; + try { + if (this.isTrackingEnabled) { + logger.info(`${TAG} enable camera tracking`); + mechanicManager.setCameraTrackingEnabled(true); + } else { + logger.info(`${TAG} disable camera tracking`); + mechanicManager.setCameraTrackingEnabled(false); + } + } catch (error) { + let code: number = (error as BusinessError).code; + let message: string = (error as BusinessError).message; + logger.error(`${TAG} setCameraTrackingEnabled failed. error.code: ${code}, message: ${message}`); + } + logger.info(`${TAG} onClick end, isTrackingEnabled = ${this.isTrackingEnabled}`); + }) + + Text($r('app.string.mech_intelligent_tracking')) + .fontSize(12) + .lineHeight(16) + .fontWeight(FontWeight.Medium) + .fontColor($r('app.color.color_black')) + .margin({ left: 0, top: 4, right: 0 }) + .textAlign(TextAlign.Center) + + Text(this.isTrackingEnabled ? $r('app.string.mech_enable'): $r('app.string.mech_close')) + .fontSize(10) + .lineHeight(13) + .fontWeight(FontWeight.Regular) + .fontColor($r('app.color.color_black')) + .margin({ top: 2 }) + .textAlign(TextAlign.Center) + } + } + + @Builder + TrackingLayout(){ + Column(){ + Button() { + Image(this.currentTrackingLayoutImage) + .width(20) + .height(20) + } + .width('40vp') + .height('40vp') + .backgroundColor($r('app.color.color_0A59F7_blue')) + .onClick(() => { + this.isTrackingEnabled = !this.isTrackingEnabled; + try { + if (this.isTrackingEnabled) { + logger.info(`${TAG} enable camera tracking`); + mechanicManager.setCameraTrackingEnabled(true); + + this.currentTrackingLayoutImage = $r('app.media.track_layout_center'); + } else { + logger.info(`${TAG} disable camera tracking`); + mechanicManager.setCameraTrackingEnabled(false); + + this.currentTrackingLayoutImage = $r('app.media.track_layout_center_dark'); + } + } catch (error) { + let code: number = (error as BusinessError).code; + let message: string = (error as BusinessError).message; + logger.error(`${TAG} setCameraTrackingEnabled failed. error.code: ${code}, message: ${message}`); + } + logger.info(`${TAG} onClick end, isTrackingEnabled = ${this.isTrackingEnabled}`); + }) + + Text($r('app.string.mech_tracking_layout')) + .fontSize(12) + .lineHeight(16) + .fontWeight(FontWeight.Medium) + .fontColor($r('app.color.color_black')) + .margin({ left: 0, top: 4, right: 0 }) + .textAlign(TextAlign.Center) + + Text(this.currentTrackingLayoutText) + .fontSize(10) + .lineHeight(13) + .fontWeight(FontWeight.Regular) + .fontColor($r('app.color.color_black')) + .margin({ top: 2 }) + .textAlign(TextAlign.Center) + } + } + + build() { + Column() { + + Flex({ + direction: FlexDirection.Row, + justifyContent: FlexAlign.SpaceEvenly, + alignItems: ItemAlign.Center + }) { + this.IntelligentTracking(); + + if (this.isTrackingEnabled) { + this.TrackingLayout(); + } + } + .width('100%') + .height('100%') + + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + } +} \ No newline at end of file diff --git a/application/entry/src/main/module.json b/application/entry/src/main/module.json index 9765740fab2d8dc3b64d4ce3a9556bf57a0f1294..56bb9fa4a6a1905f828af65845f2ac4db5010136 100644 --- a/application/entry/src/main/module.json +++ b/application/entry/src/main/module.json @@ -62,6 +62,14 @@ "label": "$string:ContinueSwitchAbility_label", "type": "sys/commonUI", "exported": true + }, + { + "name": "MechExtAbility", + "srcEntry": "./ets/mechextability/MechExtAbility.ets", + "description": "$string:MechExtAbility_desc", + "label": "$string:MechExtAbility_label", + "type": "sys/commonUI", + "exported": true } ], "metadata": [ diff --git a/application/entry/src/main/module.json5 b/application/entry/src/main/module.json5 index f36e6173d19533d2fa3d1300a1126805d0cce179..ddfce3b718fb05f238801c2b28eecbb5a8d0feef 100644 --- a/application/entry/src/main/module.json5 +++ b/application/entry/src/main/module.json5 @@ -76,6 +76,14 @@ "label": "$string:ContinueSwitchAbility_label", "type": "sys/commonUI", "exported": true + }, + { + "name": "MechExtAbility", + "srcEntry": "./ets/mechextability/MechExtAbility.ets", + "description": "$string:MechExtAbility_desc", + "label": "$string:MechExtAbility_label", + "type": "sys/commonUI", + "exported": true } ], "metadata": [ diff --git a/application/entry/src/main/resources/base/element/color.json b/application/entry/src/main/resources/base/element/color.json index a502679e22110f52b43ac081da1fec94ac0d700b..0faa42567967233d6b8c91fc499c51fff0aa48ed 100644 --- a/application/entry/src/main/resources/base/element/color.json +++ b/application/entry/src/main/resources/base/element/color.json @@ -7,6 +7,14 @@ { "name": "color_0A59F7_blue", "value": "#0A59F7" + }, + { + "name": "color_black", + "value": "#000000" + }, + { + "name": "color_image_enable", + "value": "#FFFFFF" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/base/element/string.json b/application/entry/src/main/resources/base/element/string.json index 3bc025a8b48b1c0dd099608fa9c829e26ca14f8a..e425191732e119bd4daa57807c5918b148f7d49a 100644 --- a/application/entry/src/main/resources/base/element/string.json +++ b/application/entry/src/main/resources/base/element/string.json @@ -107,6 +107,42 @@ "attr": { "priority": "LT" } + }, + { + "name": "MechExtAbility_desc", + "value": "description" + }, + { + "name": "MechExtAbility_label", + "value": "label" + }, + { + "name": "mech_intelligent_tracking", + "value": "Intelligent Tracking" + }, + { + "name": "mech_tracking_layout", + "value": "Tracking Layout" + }, + { + "name": "mech_enable", + "value": "enable" + }, + { + "name": "mech_close", + "value": "close" + }, + { + "name": "mech_left", + "value": "left" + }, + { + "name": "mech_center", + "value": "center" + }, + { + "name": "mech_right", + "value": "right" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/intelligent_tracking.svg b/application/entry/src/main/resources/base/media/intelligent_tracking.svg new file mode 100644 index 0000000000000000000000000000000000000000..aee450d9ca66e9b1d8735661e5b158896dba556f --- /dev/null +++ b/application/entry/src/main/resources/base/media/intelligent_tracking.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/intelligent_tracking_dark.svg b/application/entry/src/main/resources/base/media/intelligent_tracking_dark.svg new file mode 100644 index 0000000000000000000000000000000000000000..11e123ab9f1b6c0c518c0bb346c240bba0d674ed --- /dev/null +++ b/application/entry/src/main/resources/base/media/intelligent_tracking_dark.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_center.svg b/application/entry/src/main/resources/base/media/track_layout_center.svg new file mode 100644 index 0000000000000000000000000000000000000000..7abb97c027b0fe5913e5f8fbc8c9c45e253dfc56 --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_center.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_center_dark.svg b/application/entry/src/main/resources/base/media/track_layout_center_dark.svg new file mode 100644 index 0000000000000000000000000000000000000000..6dc793cd347fc08a86f51484d7877dd880618045 --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_center_dark.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_left.svg b/application/entry/src/main/resources/base/media/track_layout_left.svg new file mode 100644 index 0000000000000000000000000000000000000000..4efb202a6d94024dc7257dc1121e2bf1353c8d21 --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_left.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_left_dark.svg b/application/entry/src/main/resources/base/media/track_layout_left_dark.svg new file mode 100644 index 0000000000000000000000000000000000000000..e06939a71286a02a747185aff0da2fdda05dee37 --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_left_dark.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_right.svg b/application/entry/src/main/resources/base/media/track_layout_right.svg new file mode 100644 index 0000000000000000000000000000000000000000..c7d0a930dfd023935e969367887b7f698e8982dc --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_right.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/media/track_layout_right_dark.svg b/application/entry/src/main/resources/base/media/track_layout_right_dark.svg new file mode 100644 index 0000000000000000000000000000000000000000..343e3eb5a7517962e951e25d14b5e36e139e7c8a --- /dev/null +++ b/application/entry/src/main/resources/base/media/track_layout_right_dark.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/application/entry/src/main/resources/base/profile/main_pages.json b/application/entry/src/main/resources/base/profile/main_pages.json index 3556def338622bb9a6057cf0f23423fb8f637a95..ad262871755261c6da53b863f5a76577a5f1c370 100644 --- a/application/entry/src/main/resources/base/profile/main_pages.json +++ b/application/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,7 @@ { "src": [ "pages/DHardwareUI", - "pages/ContinueSwitch" + "pages/ContinueSwitch", + "pages/MechControl" ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_CN/element/string.json b/application/entry/src/main/resources/zh_CN/element/string.json index 366159569662a5e8d1f45ad6621f603bf0a2ff3a..544819ed2da1c0ccf4912ae467e0616ca86bd1d4 100644 --- a/application/entry/src/main/resources/zh_CN/element/string.json +++ b/application/entry/src/main/resources/zh_CN/element/string.json @@ -107,6 +107,42 @@ "attr": { "priority": "translate" } + }, + { + "name": "MechExtAbility_desc", + "value": "description" + }, + { + "name": "MechExtAbility_label", + "value": "label" + }, + { + "name": "mech_intelligent_tracking", + "value": "智能跟踪" + }, + { + "name": "mech_tracking_layout", + "value": "跟踪布局" + }, + { + "name": "mech_enable", + "value": "开启" + }, + { + "name": "mech_close", + "value": "关闭" + }, + { + "name": "mech_left", + "value": "居左" + }, + { + "name": "mech_center", + "value": "居中" + }, + { + "name": "mech_right", + "value": "居右" } ] } \ No newline at end of file