diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..479d914 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/local.properties +/.idea +/.deveco +**/build \ No newline at end of file diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000..d87f3cf --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,13 @@ +{ + "app": { + "bundleName": "com.ohos.theme", + "vendor": "ohos", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "minAPIVersion": 9, + "targetAPIVersion": 9 + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json index e69de29..e29e2c4 100644 --- a/AppScope/resources/base/element/string.json +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "theme" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png index e69de29..ce307a8 100644 Binary files a/AppScope/resources/base/media/app_icon.png and b/AppScope/resources/base/media/app_icon.png differ diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000..8da18f8 --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,26 @@ +{ + "app": { + "signingConfigs": [], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + }, + ], + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default", + ], + }, + ], + }, + ], +} \ No newline at end of file diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000..563ba71 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/build \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000..7dc37bb --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.js b/entry/hvigorfile.js new file mode 100644 index 0000000..d7720ee --- /dev/null +++ b/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').hapTasks diff --git a/entry/package.json b/entry/package.json index 4b5112f..1ffd85f 100644 --- a/entry/package.json +++ b/entry/package.json @@ -1,13 +1,11 @@ { - "name": "ohosproject", - "version": "1.0.0", - "ohos": { - "org": "huawei", - "buildTool": "hvigor", - "directoryLevel": "project" - }, - "dependencies": { - "@ohos/hvigor": "0.0.1", - "@ohos/hvigor-ohos-plugin": "0.0.1" - } + "name": "entry", + "version": "1.0.0", + "ohos": { + "org": "huawei", + "buildTool": "hvigor", + "directoryLevel": "module" + }, + "dependencies": { + } } diff --git a/entry/src/main/ets/Application/AbilityStage.ts b/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000..a6cfc3e --- /dev/null +++ b/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/** + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("ExtWallpaper: MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/entry/src/main/ets/MainAbility/MainAbility.ts b/entry/src/main/ets/MainAbility/MainAbility.ts index a846362..7063e38 100644 --- a/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/entry/src/main/ets/MainAbility/MainAbility.ts @@ -15,41 +15,33 @@ import Ability from '@ohos.application.Ability' -const MODULE_TAG = 'ExtWallpaper : '; - export default class MainAbility extends Ability { onCreate(want, launchParam) { - console.info(MODULE_TAG + "onCreate"); + console.log("ExtWallpaper: MainAbility onCreate") + globalThis.abilityWant = want; } onDestroy() { - console.info(MODULE_TAG + "onDestroy"); + console.log("ExtWallpaper: MainAbility onDestroy") } onWindowStageCreate(windowStage) { - console.info(MODULE_TAG + "onWindowStageCreate"); - console.info(MODULE_TAG + "startWallpaperExtAbility begin"); - var want = { - "bundleName": "com.test.testApp", - "abilityName": "com.test.testApp.WallpaperExtAbility", - } - this.context.startAbility(want).then((data) => { - console.info(MODULE_TAG + "startAbility success:" + JSON.stringify(data)); - }).catch((error) => { - console.error(MODULE_TAG + "startAbility failed:" + JSON.stringify(error)); - }) - console.info(MODULE_TAG + "startWallpaperExtAbility end"); + // Main window is created, set main page for this ability + console.log("ExtWallpaper: MainAbility onWindowStageCreate") } onWindowStageDestroy() { - console.info(MODULE_TAG + "onWindowStageDestroy"); + // Main window is destroyed, release UI related resources + console.log("ExtWallpaper: MainAbility onWindowStageDestroy") } onForeground() { - console.info(MODULE_TAG + "onForeground"); + // Ability has brought to foreground + console.log("ExtWallpaper: MainAbility onForeground") } onBackground() { - console.info(MODULE_TAG + "onBackground"); + // Ability has back to background + console.log("ExtWallpaper: MainAbility onBackground") } -} +}; diff --git a/entry/src/main/ets/WallpaperExtAbility/WallpaperExtAbility.ts b/entry/src/main/ets/WallpaperExtAbility/WallpaperExtAbility.ts index b6c2c0f..310eef0 100644 --- a/entry/src/main/ets/WallpaperExtAbility/WallpaperExtAbility.ts +++ b/entry/src/main/ets/WallpaperExtAbility/WallpaperExtAbility.ts @@ -13,37 +13,51 @@ * limitations under the License. */ +import Extension from '@ohos.application.WallpaperExtension' +import wallPaper from '@ohos.app.wallpaperability' + const MODULE_TAG = 'ExtWallpaper : '; -export class WallpaperProxy { - private static instance: WallpaperProxy; - pixelMapCallBack = null; - - private constructor() { - console.info(MODULE_TAG + "proxy initialized"); - }; - - public static getInstance() { - if (!this.instance) { - console.info(MODULE_TAG + "proxy get fresh new"); - this.instance = new WallpaperProxy(); +export default class WallpaperExtAbility extends Extension { + onCreated(want) { + console.info(MODULE_TAG + 'ability on created start'); + super.setUiContent("pages/index"); + this.initWallpaperImage(); + console.info(MODULE_TAG + 'ability on created end'); } - console.info(MODULE_TAG + "proxy get old one"); - return this.instance; - } - public registerCallback(callback) { - console.info(MODULE_TAG + "proxy register callback type is : " + typeof callback); - this.pixelMapCallBack = callback; - } + onWallpaperChanged(wallpaperType) { + console.info(MODULE_TAG + 'ability on wallpaper changed start, type is : ' + wallpaperType); + if (wallPaper) { + this.sendPixelMapData(); + } + console.info(MODULE_TAG + 'ability on wallpaper changed end'); + } - public executeCallback(data) { - console.info(MODULE_TAG + "proxy execute callback start, data is : " + JSON.stringify(data)); - console.info(MODULE_TAG + "proxy execute callback type is : " + typeof this.pixelMapCallBack); - this.pixelMapCallBack(data); - console.info(MODULE_TAG + "proxy execute callback end"); - } -} + onDestroy() { + console.info(MODULE_TAG + 'ability on destroy'); + } -let wallpaperProxyInstance = WallpaperProxy.getInstance(); -export default wallpaperProxyInstance; + initWallpaperImage() { + console.info(MODULE_TAG + 'ability init wallpaper image start'); + if (!wallPaper) { + console.info(MODULE_TAG + 'ability init wallpaper image failed as wallpaper is null'); + return; + } + this.sendPixelMapData(); + console.info(MODULE_TAG + 'ability init wallpaper image end'); + } + + sendPixelMapData() { + wallPaper.getPixelMap(0, (err, data) => { + console.info(MODULE_TAG + 'ability get pixel map data start'); + if (err) { + console.info(MODULE_TAG + 'ability get pixel map failed, error : ' + JSON.stringify(err)); + } else { + console.info(MODULE_TAG + 'ability get pixel map, data : ' + JSON.stringify(data)); + AppStorage.SetOrCreate('slPixelData', data); + } + console.info(MODULE_TAG + 'ability get pixel map data end'); + }); + } +}; diff --git a/entry/src/main/ets/WallpaperExtAbility/WallpaperProxy.ts b/entry/src/main/ets/WallpaperExtAbility/WallpaperProxy.ts deleted file mode 100644 index b6c2c0f..0000000 --- a/entry/src/main/ets/WallpaperExtAbility/WallpaperProxy.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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. - */ - -const MODULE_TAG = 'ExtWallpaper : '; - -export class WallpaperProxy { - private static instance: WallpaperProxy; - pixelMapCallBack = null; - - private constructor() { - console.info(MODULE_TAG + "proxy initialized"); - }; - - public static getInstance() { - if (!this.instance) { - console.info(MODULE_TAG + "proxy get fresh new"); - this.instance = new WallpaperProxy(); - } - console.info(MODULE_TAG + "proxy get old one"); - return this.instance; - } - - public registerCallback(callback) { - console.info(MODULE_TAG + "proxy register callback type is : " + typeof callback); - this.pixelMapCallBack = callback; - } - - public executeCallback(data) { - console.info(MODULE_TAG + "proxy execute callback start, data is : " + JSON.stringify(data)); - console.info(MODULE_TAG + "proxy execute callback type is : " + typeof this.pixelMapCallBack); - this.pixelMapCallBack(data); - console.info(MODULE_TAG + "proxy execute callback end"); - } -} - -let wallpaperProxyInstance = WallpaperProxy.getInstance(); -export default wallpaperProxyInstance; diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets index fd9d93d..75f67b6 100644 --- a/entry/src/main/ets/pages/index.ets +++ b/entry/src/main/ets/pages/index.ets @@ -12,9 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import wallPaper from '@ohos.app.wallpaperability' -import wallpaperProxyInstance from '../WallpaperExtAbility/WallpaperProxy' const MODULE_TAG = 'ExtWallpaper : '; let changeCount = 0; @@ -22,39 +19,21 @@ let changeCount = 0; @Entry @Component struct Index { - @StorageLink('slPixelData') pixelDataByStorage: any = []; - @State pixelDataByCode: PixelMap = undefined; + @StorageLink('slPixelData') pixelData: any = []; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Image(this.pixelDataByCode !== undefined ? this.pixelDataByCode : this.pixelDataByStorage) + Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) { + Image(this.pixelData); } .width('100%') - .height('100%') + .height('100%'); } aboutToAppear() { - console.info(MODULE_TAG + "index page about to appear"); - this.registerWallpaperChangeCallback(); - console.info(MODULE_TAG + "index page about to appear end"); + console.info(MODULE_TAG + 'index page about to appear'); } onPageShow() { - console.info(MODULE_TAG + "index page show"); + console.info(MODULE_TAG + 'index page show'); } - - registerWallpaperChangeCallback() { - console.info(MODULE_TAG + 'index start to register callback'); - wallpaperProxyInstance.registerCallback((data) => { - if (data === null || typeof data === 'undefined') { - console.info(MODULE_TAG + 'index page get pixel map data in register callback is null'); - return; - } - console.info(MODULE_TAG + 'index page send pixel map data in register callback : ' + data); - this.pixelDataByCode = data; - console.info(MODULE_TAG + 'index page get pixel map data in register callback end'); - }); - AppStorage.SetOrCreate('slWallpaperProxy', wallpaperProxyInstance); - console.info(MODULE_TAG + 'end to register callback'); - } -} \ No newline at end of file +} diff --git a/entry/src/main/ets/pages/second.ets b/entry/src/main/ets/pages/second.ets new file mode 100644 index 0000000..16b751c --- /dev/null +++ b/entry/src/main/ets/pages/second.ets @@ -0,0 +1,47 @@ +/** + * 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'; + +@Entry +@Component +struct Second { + @State message: string = 'Second Page' +build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + router.back() + }) + } + .width('100%') + } + .height('100%') +} +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000..0e80d0e --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,43 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone", + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home", + ], + "actions": [ + "action.system.home", + ], + }, + ], + }, + { + "name": "WallpaperExtAbility", + "srcEntrance": "./ets/WallpaperExtAbility/WallpaperExtAbility.ts", + "description": "$string:WallpaperExtAbility_desc", + "icon": "$media:icon", + "label": "$string:WallpaperExtAbility_label", + }, + ], + }, +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index e69de29..c5be63a 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "WallpaperExtAbility_desc", + "value": "description" + }, + { + "name": "WallpaperExtAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png index e69de29..ce307a8 100644 Binary files a/entry/src/main/resources/base/media/icon.png and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index e69de29..895c316 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index", + "pages/second" + ] +} diff --git a/hvigorfile.js b/hvigorfile.js new file mode 100644 index 0000000..5f2735e --- /dev/null +++ b/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').appTasks \ No newline at end of file diff --git a/package.json b/package.json index 4b5112f..188631c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { - "name": "ohosproject", - "version": "1.0.0", - "ohos": { - "org": "huawei", - "buildTool": "hvigor", - "directoryLevel": "project" - }, - "dependencies": { - "@ohos/hvigor": "0.0.1", - "@ohos/hvigor-ohos-plugin": "0.0.1" - } + "name": "theme", + "version": "1.0.0", + "ohos": { + "org": "huawei", + "buildTool": "hvigor", + "directoryLevel": "project" + }, + "dependencies": { + "@ohos/hvigor": "file:localdep/ohos-hvigor-1.0.3-rc.tgz", + "@ohos/hvigor-base": "file:localdep/ohos-hvigor-base-1.0.3-rc.tgz", + "@ohos/hvigor-log": "file:localdep/ohos-hvigor-log-1.0.3-rc.tgz", + "@ohos/hvigor-ohos-plugin": "file:localdep/ohos-hvigor-ohos-plugin-1.0.3-rc.tgz", + "@ohos/sdkmanager-common": "file:localdep/sdkmanager-common-1.1.1.tgz" + } }