update code for supporting build

Signed-off-by: yangpeng85 <yangpeng85@huawei.com>
This commit is contained in:
YangPeng
2022-04-11 11:36:22 +08:00
parent 6c586eb3f9
commit db0be0afe2
21 changed files with 297 additions and 147 deletions
+5
View File
@@ -0,0 +1,5 @@
/node_modules
/local.properties
/.idea
/.deveco
**/build
+13
View File
@@ -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
}
}
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "theme"
}
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 6.6 KiB

+26
View File
@@ -0,0 +1,26 @@
{
"app": {
"signingConfigs": [],
"compileSdkVersion": 9,
"compatibleSdkVersion": 9,
"products": [
{
"name": "default",
},
],
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default",
],
},
],
},
],
}
+2
View File
@@ -0,0 +1,2 @@
/node_modules
/build
+13
View File
@@ -0,0 +1,13 @@
{
"apiType": 'stageMode',
"buildOption": {
},
"targets": [
{
"name": "default",
},
{
"name": "ohosTest",
}
]
}
+2
View File
@@ -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
+2 -4
View File
@@ -1,13 +1,11 @@
{
"name": "ohosproject",
"name": "entry",
"version": "1.0.0",
"ohos": {
"org": "huawei",
"buildTool": "hvigor",
"directoryLevel": "project"
"directoryLevel": "module"
},
"dependencies": {
"@ohos/hvigor": "0.0.1",
"@ohos/hvigor-ohos-plugin": "0.0.1"
}
}
@@ -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")
}
}
+12 -20
View File
@@ -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")
}
}
};
@@ -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();
}
console.info(MODULE_TAG + "proxy get old one");
return this.instance;
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');
}
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');
});
}
};
@@ -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;
+6 -27
View File
@@ -13,48 +13,27 @@
* limitations under the License.
*/
import wallPaper from '@ohos.app.wallpaperability'
import wallpaperProxyInstance from '../WallpaperExtAbility/WallpaperProxy'
const MODULE_TAG = 'ExtWallpaper : ';
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");
}
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');
console.info(MODULE_TAG + 'index page show');
}
}
+47
View File
@@ -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%')
}
}
+43
View File
@@ -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",
},
],
},
}
@@ -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"
}
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 6.6 KiB

@@ -0,0 +1,6 @@
{
"src": [
"pages/index",
"pages/second"
]
}
+2
View File
@@ -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
+6 -3
View File
@@ -1,5 +1,5 @@
{
"name": "ohosproject",
"name": "theme",
"version": "1.0.0",
"ohos": {
"org": "huawei",
@@ -7,7 +7,10 @@
"directoryLevel": "project"
},
"dependencies": {
"@ohos/hvigor": "0.0.1",
"@ohos/hvigor-ohos-plugin": "0.0.1"
"@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"
}
}