Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for OHOS interfaces #2408

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: result/coverage.xml
version: 'v0.7.3'

- name: Save Environment Cache
if: ${{ (github.event_name == 'push') && (steps.environment-cache.outputs.cache-hit != 'true') }}
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,16 @@ elseif (OHOS)
find_library(NATIVE_BUFFER_LIB native_buffer)
find_library(NATIVE_WINDOW_LIB native_window)
find_library(NATIVE_IMAGE_LIB native_image)
find_library(NATIVE_VSYNC_LIB native_vsync)
find_library(NATIVE_MEDIA_CODECBASE_LIB native_media_codecbase)
find_library(NATIVE_MEDIA_CORE_LIB native_media_core)
find_library(NATIVE_MEDIA_VDEC_LIB native_media_vdec)
find_library(NATIVE_RAWFILE_Z_LIB rawfile.z)
list(APPEND PAG_SHARED_LIBS ${PIXELMAP_NDK_LIB} ${IMAGE_SOURCE_NDK_LIB} ${PIXELMAP_LIB}
${IMAGE_SOURCE_LIB} ${ACE_NDK_LIB} ${HILOG_NDK_LIB} ${ACE_NAPI_LIB}
${NATIVE_BUFFER_LIB} ${NATIVE_WINDOW_LIB} ${NATIVE_IMAGE_LIB}
${NATIVE_MEDIA_CODECBASE_LIB} ${NATIVE_MEDIA_CORE_LIB} ${NATIVE_MEDIA_VDEC_LIB})
${NATIVE_MEDIA_CODECBASE_LIB} ${NATIVE_MEDIA_CORE_LIB} ${NATIVE_MEDIA_VDEC_LIB}
${NATIVE_VSYNC_LIB} ${NATIVE_RAWFILE_Z_LIB})

file(GLOB_RECURSE PLATFORM_FILES src/platform/ohos/*.*)
list(APPEND PAG_FILES ${PLATFORM_FILES})
Expand Down
12 changes: 12 additions & 0 deletions ohos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
/.appanalyzer
10 changes: 10 additions & 0 deletions ohos/AppScope/app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "org.libpag.PAGViewer",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
8 changes: 8 additions & 0 deletions ohos/AppScope/resources/base/element/string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "PAGViewer"
}
]
}
3 changes: 3 additions & 0 deletions ohos/AppScope/resources/base/media/app_icon.png
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换个正式的PAGViewer图标

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions ohos/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"app": {
"signingConfigs": [
],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
},
{
"name": "libpag",
"srcPath": "./libpag",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
6 changes: 6 additions & 0 deletions ohos/entry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
34 changes: 34 additions & 0 deletions ohos/entry/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
"nativeLib": {
"debugSymbol": {
"strip": true,
"exclude": []
}
}
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}
2 changes: 2 additions & 0 deletions ohos/entry/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { hapTasks } from '@ohos/hvigor-ohos-plugin';
29 changes: 29 additions & 0 deletions ohos/entry/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ohos/entry/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"license": "",
"devDependencies": {},
"author": "",
"name": "entry",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {
"libpag": "../libpag"
}
}
56 changes: 56 additions & 0 deletions ohos/entry/src/main/ets/entryability/EntryAbility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 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.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demo里这个协议去掉吧,或者更新成我们的。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,ets文件中license都更新了


import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}

onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}

onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');

windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}

onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}

onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}

onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
};
68 changes: 68 additions & 0 deletions ohos/entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as pag from 'libpag';

@Entry
@Component
struct Index {
@State message: string = "";
@State @Watch("updateMessage") stateString: string = "";
@State composition: pag.PAGComposition | null = null;
@State @Watch("updateMessage") progress: number = 0;
@State isPlaying: boolean = false;
@State repeatCount: number = 1;

aboutToAppear(): void {
let manager = getContext(this).resourceManager;
let file = pag.PAGFile.LoadFromAssets(manager, "PAG_LOGO.pag");
this.composition = file as pag.PAGComposition;
this.isPlaying = true;
}

onAnimationStart = (view: pag.PAGView) => {
this.stateString = 'PAG start';
}
onAnimationEnd = (view: pag.PAGView) => {
this.stateString = `PAG end`;
}
onAnimationRepeat = (view: pag.PAGView) => {
this.stateString = `PAG repeat`;
}
onAnimationCancel = (view: pag.PAGView) => {
this.stateString = `PAG cancel`;
}
onAnimationUpdate = (view: pag.PAGView) => {
}

updateMessage() {
this.message = this.stateString + ` progress ${this.progress.toFixed(2)}`;
}

build() {
Row() {
Column() {
pag.PAGView({
composition: this.composition,
progress: this.progress,
isPlaying: this.isPlaying,
repeatCount: this.repeatCount,
listeners: [new WeakRef(this)]
})
.height('50%')
.onClick(() => {
this.isPlaying = !this.isPlaying
})

Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.progress = 0.5;
this.repeatCount = 0;
})
.height('50%')
}
.width('100%')

}
.height('100%')
}
}
51 changes: 51 additions & 0 deletions ohos/entry/src/main/module.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023 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.
*/

{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}
8 changes: 8 additions & 0 deletions ohos/entry/src/main/resources/base/element/color.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
Loading
Loading