diff --git a/entry/src/main/ets/pages/subpages/file/SWNewFile.ets b/entry/src/main/ets/pages/subpages/file/SWNewFile.ets index 0ba014a8..5ab201f4 100644 --- a/entry/src/main/ets/pages/subpages/file/SWNewFile.ets +++ b/entry/src/main/ets/pages/subpages/file/SWNewFile.ets @@ -17,29 +17,21 @@ export struct SWNewFile { @Local scaleBtn:number=0.05; //文本宽度统一缩放系数 @Local scalingText:number=0.04; - @Local subWin: window.Window | undefined = undefined; + aboutToAppear(): void { this.docCreateTime=CurrentTime(); } - async initSubWindow(){ - this.subWin= await mwsInfo.winStage?.createSubWindow('dirPicker'); - this.subWin?.loadContent('pages/SubWindow/File/SWNewFile'); - } - - async selectDir(): Promise{ + selectDir():string{ let selectDirStr=''; let context =this.getUIContext().getHostContext() as common.Context; - if(this.subWin){ - this.subWin.destroyWindow(); - } - await this.initSubWindow(); try { let documentSelectOptions = new picker.DocumentSelectOptions(); - let documentPicker = new picker.DocumentViewPicker(context,this.subWin as window.Window); + let documentPicker = new picker.DocumentViewPicker(context); documentSelectOptions.selectMode=picker.DocumentSelectMode.FOLDER; documentPicker.select(documentSelectOptions,(err: BusinessError,documentSelectResult: Array) => { selectDirStr =documentSelectResult.toString(); + return selectDirStr; }) } catch (error) { const err: BusinessError = error as BusinessError; @@ -69,8 +61,8 @@ export struct SWNewFile { .fontColor($r('sys.color.font_emphasize')) .fontWeight(FontWeight.Medium) .fontSize($r('sys.float.Body_L')) - .onClick(async () => { - this.dir= await this.selectDir(); + .onClick(() => { + this.dir= this.selectDir(); }) }.height('10%') Row({space:5}){ diff --git a/entry/src/main/ets/pages/titletabs/TitleColumnSub.ets b/entry/src/main/ets/pages/titletabs/TitleColumnSub.ets index 68b27357..e19b7b02 100644 --- a/entry/src/main/ets/pages/titletabs/TitleColumnSub.ets +++ b/entry/src/main/ets/pages/titletabs/TitleColumnSub.ets @@ -9,7 +9,7 @@ import { FileMenuData } from "../layout/FileMenuData"; import { mwInfo } from '../displaywindowinfo/DispWinInfo' import { SubColumnMenu} from "../customcontroller/Button"; import { fileIo } from "@kit.CoreFileKit"; - +import { common,Want } from "@kit.AbilityKit"; @ComponentV2 export struct TitleColumnSub { @@ -66,7 +66,17 @@ export struct TitleColumnSub { SubColumnMenu({menus:DisplayMode}) Blank().layoutWeight(1) Button('TabsBar显示/隐藏').onClick(()=>{ - this.$subOverlayState(!this.subOverlayState); + //this.$subOverlayState(!this.subOverlayState); + let want: Want = { + deviceId: '', + bundleName: 'com.example.opencax', + abilityName: 'SubWinAbility' + }; + // 调用 context 启动 + let context =getContext(this) as common.UIAbilityContext; + context.startAbility(want).then(() => { + console.info('yes'); + }) }) }.width('100%') .height('100%') diff --git a/entry/src/main/ets/subwinability/SubWinAbility.ets b/entry/src/main/ets/subwinability/SubWinAbility.ets new file mode 100644 index 00000000..0b4ea906 --- /dev/null +++ b/entry/src/main/ets/subwinability/SubWinAbility.ets @@ -0,0 +1,72 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window, display, AppStorageV2, ColorMetrics } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class SubWinAbility extends UIAbility { + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + //Load page + windowStage.loadContent('pages/subpages/file/SWNewFile', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + + //Get Main Window + windowStage.getMainWindow((err, data) => { + if (err.code) { + console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`); + return; + } + //moveWindowTo + data.moveWindowTo(50, 50) + //resize mainWindow Size + data.resize(200,400, (err) => { + if (err.code) { + console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`); + return; + } + }); + + let color: string = '#00000000'; + try { + data.setWindowBackgroundColor(color); + data.setWindowShadowEnabled(true); + } catch (exception) { + console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); + }; + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index c06fd370..0aa00b79 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -42,6 +42,27 @@ ] } ] + }, + { + "name": "SubWinAbility", + "srcEntry": "./ets/subwinability/SubWinAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:base_opencax_logo", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:base_start_background", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "launchType":"standard", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] } ], "extensionAbilities": [