仓库中添加内置的demo
7
demo/native/engine/android/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
20
demo/native/engine/android/CMakeLists.txt
Executable file
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
option(APP_NAME "Project Name" "kunpocreator")
|
||||
project(${APP_NAME} CXX)
|
||||
set(CC_LIB_NAME cocos)
|
||||
set(CC_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(CC_PROJ_SOURCES)
|
||||
set(CC_COMMON_SOURCES)
|
||||
set(CC_ALL_SOURCES)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt)
|
||||
|
||||
list(APPEND CC_COMMON_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/../common/Classes/JNIAndroid/JniTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/../common/Classes/JNIAndroid/JniTools.cpp
|
||||
)
|
||||
|
||||
cc_android_before_target(${CC_LIB_NAME})
|
||||
add_library(${CC_LIB_NAME} SHARED ${CC_ALL_SOURCES})
|
||||
cc_android_after_target(${CC_LIB_NAME})
|
||||
1
demo/native/engine/android/Post-service.cmake
Normal file
@@ -0,0 +1 @@
|
||||
# Supported for Cocos Service!
|
||||
1
demo/native/engine/android/Pre-service.cmake
Normal file
@@ -0,0 +1 @@
|
||||
# Supported for Cocos Service!
|
||||
16
demo/native/engine/android/app/AndroidManifest.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<application android:extractNativeLibs="true" android:allowBackup="true" android:label="@string/app_name" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher" android:resizeableActivity="true">
|
||||
<meta-data android:name="android.app.lib_name" android:value="cocos"/>
|
||||
<activity android:name="com.cocos.game.AppActivity" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.cocos.lib.CocosEditBoxActivity" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:screenOrientation="behind" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
</application>
|
||||
</manifest>
|
||||
113
demo/native/engine/android/app/build.gradle
Normal file
@@ -0,0 +1,113 @@
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
RES_PATH = RES_PATH.replace("\\", "/")
|
||||
COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/")
|
||||
|
||||
buildDir = "${RES_PATH}/proj/build/${project.name ==~ /^[_a-zA-Z0-9-]+$/ ? project.name : 'CocosGame'}"
|
||||
android {
|
||||
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
|
||||
buildToolsVersion PROP_BUILD_TOOLS_VERSION
|
||||
ndkPath PROP_NDK_PATH
|
||||
namespace APPLICATION_ID
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId APPLICATION_ID
|
||||
minSdkVersion PROP_MIN_SDK_VERSION
|
||||
targetSdkVersion PROP_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "0.0.1"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
targets "cocos"
|
||||
arguments "-DRES_DIR=${RES_PATH}", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
|
||||
}
|
||||
ndk { abiFilters PROP_APP_ABI.split(':') }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDirs "../src", "src"
|
||||
res.srcDirs "../res", 'res', "${RES_PATH}/proj/res"
|
||||
jniLibs.srcDirs "../libs", 'libs'
|
||||
manifest.srcFile "AndroidManifest.xml"
|
||||
assets.srcDir "${RES_PATH}/data"
|
||||
jniLibs {
|
||||
// Vulkan validation layer
|
||||
// srcDir "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
version "3.22.1"
|
||||
path "../CMakeLists.txt"
|
||||
buildStagingDirectory "${RES_PATH}/proj/build"
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
release {
|
||||
if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
|
||||
storeFile file(RELEASE_STORE_FILE)
|
||||
storePassword RELEASE_STORE_PASSWORD
|
||||
keyAlias RELEASE_KEY_ALIAS
|
||||
keyPassword RELEASE_KEY_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
debuggable false
|
||||
jniDebuggable false
|
||||
renderscriptDebuggable false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// switch HIDE_SYMBOLS to OFF to skip compilation flag `-fvisibility=hidden`
|
||||
arguments "-DHIDE_SYMBOLS=ON"
|
||||
}
|
||||
}
|
||||
|
||||
if (!Boolean.parseBoolean(PROP_IS_DEBUG)) {
|
||||
getIsDefault().set(true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
debug {
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
renderscriptDebuggable true
|
||||
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
|
||||
// applicationIdSuffix ".debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar'])
|
||||
implementation project(':libservice')
|
||||
implementation project(':libcocos')
|
||||
if (Boolean.parseBoolean(PROP_ENABLE_INPUTSDK)) {
|
||||
implementation 'com.google.android.libraries.play.games:inputmapping:1.1.0-beta'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
|
||||
}
|
||||
}
|
||||
57
demo/native/engine/android/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Proguard Cocos2d-x-lite for release
|
||||
-keep public class com.cocos.** { *; }
|
||||
-dontwarn com.cocos.**
|
||||
|
||||
# Proguard Apache HTTP for release
|
||||
-keep class org.apache.http.** { *; }
|
||||
-dontwarn org.apache.http.**
|
||||
|
||||
-keep public class com.kunpo.** { *; }
|
||||
-dontwarn com.kunpo.**
|
||||
|
||||
# Proguard okhttp for release
|
||||
-keep class okhttp3.** { *; }
|
||||
-dontwarn okhttp3.**
|
||||
|
||||
-keep class okio.** { *; }
|
||||
-dontwarn okio.**
|
||||
|
||||
# Proguard Android Webivew for release. you can comment if you are not using a webview
|
||||
-keep public class android.net.http.SslError
|
||||
-keep public class android.webkit.WebViewClient
|
||||
|
||||
-keep public class com.google.** { *; }
|
||||
|
||||
-dontwarn android.webkit.WebView
|
||||
-dontwarn android.net.http.SslError
|
||||
-dontwarn android.webkit.WebViewClient
|
||||
|
||||
# This is generated automatically by the Android Gradle plugin.
|
||||
-dontwarn android.hardware.BatteryState
|
||||
-dontwarn android.hardware.lights.Light
|
||||
-dontwarn android.hardware.lights.LightState$Builder
|
||||
-dontwarn android.hardware.lights.LightState
|
||||
-dontwarn android.hardware.lights.LightsManager$LightsSession
|
||||
-dontwarn android.hardware.lights.LightsManager
|
||||
-dontwarn android.hardware.lights.LightsRequest$Builder
|
||||
-dontwarn android.hardware.lights.LightsRequest
|
||||
-dontwarn android.net.ssl.SSLSockets
|
||||
-dontwarn android.os.VibratorManager
|
||||
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package com.cocos.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.cocos.service.SDKWrapper;
|
||||
import com.cocos.lib.CocosActivity;
|
||||
import com.kunpo.KunpoHelper;
|
||||
|
||||
public class AppActivity extends CocosActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// DO OTHER INITIALIZATION BELOW
|
||||
SDKWrapper.shared().init(this);
|
||||
KunpoHelper.setActivity(this);
|
||||
// 保持屏幕常亮
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
SDKWrapper.shared().onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
SDKWrapper.shared().onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
||||
if (!isTaskRoot()) {
|
||||
return;
|
||||
}
|
||||
SDKWrapper.shared().onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
SDKWrapper.shared().onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
SDKWrapper.shared().onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
SDKWrapper.shared().onRestart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
SDKWrapper.shared().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
SDKWrapper.shared().onBackPressed();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
SDKWrapper.shared().onConfigurationChanged(newConfig);
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
SDKWrapper.shared().onRestoreInstanceState(savedInstanceState);
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
SDKWrapper.shared().onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
SDKWrapper.shared().onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
SDKWrapper.shared().onLowMemory();
|
||||
super.onLowMemory();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.kunpo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class KunpoHelper {
|
||||
private static final String TAG = "kunpo helper::";
|
||||
|
||||
private static Activity _activity = null;
|
||||
public static void setActivity(Activity activity) {
|
||||
_activity = activity;
|
||||
}
|
||||
|
||||
public static void getSystemInfo() {
|
||||
|
||||
}
|
||||
|
||||
public static String getVersionCode() {
|
||||
String localVersion = "0.0.1";
|
||||
try {
|
||||
PackageInfo packageInfo = _activity.getApplicationContext().getPackageManager().getPackageInfo(_activity.getPackageName(), 0);
|
||||
localVersion = packageInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return localVersion;
|
||||
}
|
||||
|
||||
public static int getBuildCode() {
|
||||
int localVersion = 0;
|
||||
try {
|
||||
PackageInfo packageInfo = _activity.getApplicationContext().getPackageManager().getPackageInfo(_activity.getPackageName(), 0);
|
||||
localVersion = packageInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return localVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调给JS层的接口
|
||||
* @param json 格式 { function: string, args: string }
|
||||
*/
|
||||
public static native void CallJS(String json);
|
||||
}
|
||||
8
demo/native/engine/android/build-cfg.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"ndk_module_path" :[
|
||||
"${COCOS_ROOT}",
|
||||
"${COCOS_ROOT}/cocos",
|
||||
"${COCOS_ROOT}/external"
|
||||
],
|
||||
"copy_resources": []
|
||||
}
|
||||
28
demo/native/engine/android/build.gradle
Normal file
@@ -0,0 +1,28 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
// jcenter() // keeped as anchor, will be removed soon
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.0.2'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
// jcenter() // keeped as anchor, will be removed soon
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
23
demo/native/engine/android/instantapp/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" android:installLocation="auto">
|
||||
<dist:module dist:instant="true"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<application android:extractNativeLibs="true" android:allowBackup="true" android:label="@string/app_name" android:usesCleartextTraffic="true" android:supportsRtl="true" android:icon="@mipmap/ic_launcher" android:resizeableActivity="true">
|
||||
<meta-data android:name="aia-compat-api-min-version" android:value="1"/>
|
||||
<meta-data android:name="android.app.lib_name" android:value="cocos"/>
|
||||
<activity android:name="com.cocos.game.InstantActivity" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" android:exported="true">
|
||||
<intent-filter android:order="1">
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.cocos.lib.CocosEditBoxActivity" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:screenOrientation="behind" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
</application>
|
||||
</manifest>
|
||||
100
demo/native/engine/android/instantapp/build.gradle
Normal file
@@ -0,0 +1,100 @@
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
RES_PATH = RES_PATH.replace("\\", "/")
|
||||
COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/")
|
||||
buildDir = "${RES_PATH}/proj/build/instantapp"
|
||||
|
||||
android {
|
||||
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
|
||||
buildToolsVersion PROP_BUILD_TOOLS_VERSION
|
||||
ndkPath PROP_NDK_PATH
|
||||
namespace APPLICATION_ID
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion PROP_MIN_SDK_VERSION
|
||||
targetSdkVersion PROP_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
targets "cocos"
|
||||
arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}","-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=gold"
|
||||
cppFlags "-frtti -fexceptions -fsigned-char -DANDROID_INSTANT=1"
|
||||
}
|
||||
ndk { abiFilters PROP_APP_ABI.split(':') }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDirs "../src", "src"
|
||||
res.srcDirs "../res", 'res', "${RES_PATH}/proj/res"
|
||||
jniLibs.srcDirs "../libs", 'libs'
|
||||
manifest.srcFile "AndroidManifest.xml"
|
||||
assets.srcDir "${RES_PATH}/data"
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
version "3.22.1"
|
||||
path "../CMakeLists.txt"
|
||||
buildStagingDirectory "${RES_PATH}/proj/build"
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
release {
|
||||
if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
|
||||
storeFile file(RELEASE_STORE_FILE)
|
||||
storePassword RELEASE_STORE_PASSWORD
|
||||
keyAlias RELEASE_KEY_ALIAS
|
||||
keyPassword RELEASE_KEY_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
debuggable false
|
||||
jniDebuggable false
|
||||
renderscriptDebuggable false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// switch HIDE_SYMBOLS to OFF to skip compilation flag `-fvisibility=hidden`
|
||||
arguments "-DHIDE_SYMBOLS=ON"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug {
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
renderscriptDebuggable true
|
||||
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
|
||||
// applicationIdSuffix ".debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar'])
|
||||
implementation project(':libservice')
|
||||
implementation project(':libcocos')
|
||||
}
|
||||
54
demo/native/engine/android/instantapp/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Proguard Cocos2d-x-lite for release
|
||||
-keep public class com.cocos.** { *; }
|
||||
-dontwarn com.cocos.**
|
||||
|
||||
# Proguard Apache HTTP for release
|
||||
-keep class org.apache.http.** { *; }
|
||||
-dontwarn org.apache.http.**
|
||||
|
||||
# Proguard okhttp for release
|
||||
-keep class okhttp3.** { *; }
|
||||
-dontwarn okhttp3.**
|
||||
|
||||
-keep class okio.** { *; }
|
||||
-dontwarn okio.**
|
||||
|
||||
# Proguard Android Webivew for release. you can comment if you are not using a webview
|
||||
-keep public class android.net.http.SslError
|
||||
-keep public class android.webkit.WebViewClient
|
||||
|
||||
-keep public class com.google.** { *; }
|
||||
|
||||
-dontwarn android.webkit.WebView
|
||||
-dontwarn android.net.http.SslError
|
||||
-dontwarn android.webkit.WebViewClient
|
||||
|
||||
# This is generated automatically by the Android Gradle plugin.
|
||||
-dontwarn android.hardware.BatteryState
|
||||
-dontwarn android.hardware.lights.Light
|
||||
-dontwarn android.hardware.lights.LightState$Builder
|
||||
-dontwarn android.hardware.lights.LightState
|
||||
-dontwarn android.hardware.lights.LightsManager$LightsSession
|
||||
-dontwarn android.hardware.lights.LightsManager
|
||||
-dontwarn android.hardware.lights.LightsRequest$Builder
|
||||
-dontwarn android.hardware.lights.LightsRequest
|
||||
-dontwarn android.net.ssl.SSLSockets
|
||||
-dontwarn android.os.VibratorManager
|
||||
@@ -0,0 +1,125 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package com.cocos.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.cocos.service.SDKWrapper;
|
||||
import com.cocos.lib.CocosActivity;
|
||||
|
||||
public class InstantActivity extends CocosActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// DO OTHER INITIALIZATION BELOW
|
||||
SDKWrapper.shared().init(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
SDKWrapper.shared().onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
SDKWrapper.shared().onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
||||
if (!isTaskRoot()) {
|
||||
return;
|
||||
}
|
||||
SDKWrapper.shared().onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
SDKWrapper.shared().onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
SDKWrapper.shared().onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
SDKWrapper.shared().onRestart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
SDKWrapper.shared().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
SDKWrapper.shared().onBackPressed();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
SDKWrapper.shared().onConfigurationChanged(newConfig);
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
SDKWrapper.shared().onRestoreInstanceState(savedInstanceState);
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
SDKWrapper.shared().onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
SDKWrapper.shared().onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
SDKWrapper.shared().onLowMemory();
|
||||
super.onLowMemory();
|
||||
}
|
||||
}
|
||||
BIN
demo/native/engine/android/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
demo/native/engine/android/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
demo/native/engine/android/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
demo/native/engine/android/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
demo/native/engine/android/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
2
demo/native/engine/android/res/values/strings.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<resources>
|
||||
</resources>
|
||||
1
demo/native/engine/common/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
localCfg.cmake
|
||||
64
demo/native/engine/common/CMakeLists.txt
Executable file
@@ -0,0 +1,64 @@
|
||||
enable_language(C ASM)
|
||||
set(DEVELOPMENT_TEAM "" CACHE STRING "APPLE Developtment Team")
|
||||
set(RES_DIR "" CACHE STRING "Resource path")
|
||||
set(COCOS_X_PATH "" CACHE STRING "Path to engine/native/")
|
||||
|
||||
set(TARGET_OSX_VERSION "10.14" CACHE STRING "Target MacOSX version" FORCE)
|
||||
set(TARGET_IOS_VERSION "11.0" CACHE STRING "Target iOS version" FORCE)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
option(CC_DEBUG_FORCE "Force enable CC_DEBUG in release mode" OFF)
|
||||
option(USE_SE_V8 "Use V8 JavaScript Engine" ON)
|
||||
option(USE_SE_JSVM "Use JSVM JavaScript Engine" OFF)
|
||||
option(USE_SE_JSC "Use JavaScriptCore on MacOSX/iOS" OFF)
|
||||
option(USE_V8_DEBUGGER "Compile v8 inspector ws server" ON)
|
||||
option(USE_V8_DEBUGGER_FORCE "Force enable debugger in release mode" OFF)
|
||||
option(USE_SOCKET "Enable WebSocket & SocketIO" ON)
|
||||
option(USE_AUDIO "Enable Audio" ON) #Enable AudioEngine
|
||||
option(USE_EDIT_BOX "Enable EditBox" ON)
|
||||
option(USE_VIDEO "Enable VideoPlayer Component" ON)
|
||||
option(USE_WEBVIEW "Enable WebView Component" ON)
|
||||
option(USE_MIDDLEWARE "Enable Middleware" ON)
|
||||
option(USE_DRAGONBONES "Enable Dragonbones" ON)
|
||||
option(USE_SPINE_3_8 "Enable Spine 3.8" ON)
|
||||
option(USE_SPINE_4_2 "Enable Spine 4.2" OFF)
|
||||
option(USE_WEBSOCKET_SERVER "Enable WebSocket Server" OFF)
|
||||
option(USE_JOB_SYSTEM_TASKFLOW "Use taskflow as job system backend" OFF)
|
||||
option(USE_JOB_SYSTEM_TBB "Use tbb as job system backend" OFF)
|
||||
option(USE_PHYSICS_PHYSX "Use PhysX Physics" ON)
|
||||
option(USE_OCCLUSION_QUERY "Use Occlusion Query" ON)
|
||||
option(USE_DEBUG_RENDERER "Use Debug Renderer" ON)
|
||||
option(USE_GEOMETRY_RENDERER "Use Geometry Renderer" ON)
|
||||
option(USE_WEBP "Use Webp" ON)
|
||||
|
||||
if(NOT RES_DIR)
|
||||
message(FATAL_ERROR "RES_DIR is not set!")
|
||||
endif()
|
||||
|
||||
include(${RES_DIR}/proj/cfg.cmake)
|
||||
|
||||
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/localCfg.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/localCfg.cmake)
|
||||
endif()
|
||||
|
||||
if(NOT COCOS_X_PATH)
|
||||
message(FATAL_ERROR "COCOS_X_PATH is not set!")
|
||||
endif()
|
||||
|
||||
if(USE_XR OR USE_AR_MODULE)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/xr.cmake)
|
||||
endif()
|
||||
|
||||
include(${COCOS_X_PATH}/CMakeLists.txt)
|
||||
|
||||
list(APPEND CC_COMMON_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/Game.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/Game.cpp
|
||||
|
||||
############### 添加生成的绑定类 ##############
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/SDKHelper.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/SDKHelper.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/bindings/auto/jsb_SDKHelper_auto.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/Classes/bindings/auto/jsb_SDKHelper_auto.cpp
|
||||
)
|
||||
67
demo/native/engine/common/Classes/Game.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You
|
||||
shall not use Cocos Creator software for developing other software or tools
|
||||
that's used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
|
||||
you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Game.h"
|
||||
#include "bindings/auto/jsb_SDKHelper_auto.h" // 添加新生成的绑定类头文件
|
||||
|
||||
#ifndef GAME_NAME
|
||||
#define GAME_NAME "CocosGame";
|
||||
#endif
|
||||
|
||||
#ifndef SCRIPT_XXTEAKEY
|
||||
#define SCRIPT_XXTEAKEY "";
|
||||
#endif
|
||||
|
||||
Game::Game() = default;
|
||||
|
||||
int Game::init() {
|
||||
_windowInfo.title = GAME_NAME;
|
||||
// configurate window size
|
||||
// _windowInfo.height = 600;
|
||||
// _windowInfo.width = 800;
|
||||
|
||||
#if CC_DEBUG
|
||||
_debuggerInfo.enabled = true;
|
||||
#else
|
||||
_debuggerInfo.enabled = false;
|
||||
#endif
|
||||
_debuggerInfo.port = 6086;
|
||||
_debuggerInfo.address = "0.0.0.0";
|
||||
_debuggerInfo.pauseOnStart = false;
|
||||
|
||||
_xxteaKey = SCRIPT_XXTEAKEY;
|
||||
se::ScriptEngine::getInstance()->addRegisterCallback(register_all_SDKHelper); // 注册
|
||||
|
||||
BaseGame::init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Game::onPause() { BaseGame::onPause(); }
|
||||
|
||||
void Game::onResume() { BaseGame::onResume(); }
|
||||
|
||||
void Game::onClose() { BaseGame::onClose(); }
|
||||
|
||||
CC_REGISTER_APPLICATION(Game);
|
||||
44
demo/native/engine/common/Classes/Game.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You
|
||||
shall not use Cocos Creator software for developing other software or tools
|
||||
that's used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
|
||||
you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "cocos/cocos.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call
|
||||
by Director.
|
||||
*/
|
||||
class Game : public cc::BaseGame {
|
||||
public:
|
||||
Game();
|
||||
int init() override;
|
||||
// bool init() override;
|
||||
void onPause() override;
|
||||
void onResume() override;
|
||||
void onClose() override;
|
||||
};
|
||||
38
demo/native/engine/common/Classes/JNIAndroid/JniTools.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// JniTools.cpp
|
||||
// kungpowGame
|
||||
//
|
||||
// Created by GongXH on 2021/3/26.
|
||||
//
|
||||
|
||||
#include "JniTools.h"
|
||||
#include "../SDKHelper.h"
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <java/jni/JniHelper.h>
|
||||
#include "application/ApplicationManager.h"
|
||||
using namespace cc;
|
||||
|
||||
#define KUNPO_HELPER "com/kunpo/KunpoHelper"
|
||||
|
||||
std::string JniTools::getVersionCode() {
|
||||
return JniHelper::callStaticStringMethod(KUNPO_HELPER,"getVersionCode");
|
||||
}
|
||||
|
||||
int JniTools::getBuildCode() {
|
||||
return JniHelper::callStaticIntMethod(KUNPO_HELPER,"getBuildCode");
|
||||
}
|
||||
|
||||
#pragma -mark java回调c++
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void Java_com_kunpo_KunpoHelper_CallJS(JNIEnv* env, jclass thiz, jstring jsjson)
|
||||
{
|
||||
std::string json = JniHelper::jstring2string(jsjson);
|
||||
CC_CURRENT_ENGINE()->getScheduler()->performFunctionInCocosThread([=]() {
|
||||
KunpoSDK::SDKHelper::getInstance()->callJS(json.c_str());
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
18
demo/native/engine/common/Classes/JNIAndroid/JniTools.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// JniTools.hpp
|
||||
// ZumaGame
|
||||
//
|
||||
// Created by GongXH on 2021/3/26.
|
||||
//
|
||||
|
||||
#ifndef JniTools_hpp
|
||||
#define JniTools_hpp
|
||||
#include "cocos.h"
|
||||
class JniTools
|
||||
{
|
||||
public:
|
||||
//调用Java的方法
|
||||
static std::string getVersionCode();
|
||||
static int getBuildCode();
|
||||
};
|
||||
#endif /* JniTools_hpp */
|
||||
65
demo/native/engine/common/Classes/SDKHelper.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-03-21
|
||||
* @Description:
|
||||
*/
|
||||
#include "SDKHelper.h"
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "JNIAndroid/JniTools.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#endif
|
||||
|
||||
using namespace KunpoSDK;
|
||||
namespace KunpoSDK {
|
||||
}
|
||||
|
||||
static SDKHelper helper;
|
||||
|
||||
SDKHelper * SDKHelper::getInstance() {
|
||||
return &helper;
|
||||
}
|
||||
|
||||
SDKHelper::SDKHelper() {
|
||||
|
||||
}
|
||||
|
||||
/** 获取系统信息 */
|
||||
void SDKHelper::getSystemInfo() {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// return JniTools::getSystemInfo();
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string SDKHelper::getVersionCode() {
|
||||
CC_LOG_DEBUG("SDKHelper 获取版本号");
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
return JniTools::getVersionCode();
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#endif
|
||||
|
||||
return "0.0.1";
|
||||
}
|
||||
|
||||
int SDKHelper::getBuildCode() {
|
||||
CC_LOG_DEBUG("SDKHelper 获取Build号");
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
return JniTools::getBuildCode();
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void SDKHelper::callJS(const char *jsonString) {
|
||||
se::Value callJsHandler;
|
||||
if (se::ScriptEngine::getInstance()->getGlobalObject()->getProperty("KunpoNativeCallJsHandler", &callJsHandler) && callJsHandler.isObject()) {
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(jsonString));
|
||||
callJsHandler.toObject()->call(args, callJsHandler.toObject());
|
||||
}
|
||||
}
|
||||
34
demo/native/engine/common/Classes/SDKHelper.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-03-21
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "cocos/cocos.h"
|
||||
|
||||
namespace KunpoSDK {
|
||||
|
||||
class SDKHelper {
|
||||
public:
|
||||
/** 单例 */
|
||||
static SDKHelper * getInstance();
|
||||
|
||||
SDKHelper();
|
||||
|
||||
/** 获取系统信息 */
|
||||
void getSystemInfo();
|
||||
/** 获取版本号 */
|
||||
std::string getVersionCode();
|
||||
/** 获取build号 */
|
||||
int getBuildCode();
|
||||
|
||||
/**
|
||||
* c++ 回调 js
|
||||
* 参数:jsonString 格式 { function: string, args: string }
|
||||
*/
|
||||
void callJS(const char* jsonString);
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
// clang-format off
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (https://www.swig.org).
|
||||
* Version 4.1.0
|
||||
*
|
||||
* Do not make changes to this file unless you know what you are doing - modify
|
||||
* the SWIG interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4101)
|
||||
#endif
|
||||
|
||||
|
||||
#define SWIG_STD_MOVE(OBJ) std::move(OBJ)
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "bindings/manual/jsb_global.h"
|
||||
|
||||
|
||||
#include "jsb_SDKHelper_auto.h"
|
||||
|
||||
|
||||
|
||||
se::Class* __jsb_KunpoSDK_SDKHelper_class = nullptr;
|
||||
se::Object* __jsb_KunpoSDK_SDKHelper_proto = nullptr;
|
||||
SE_DECLARE_FINALIZE_FUNC(js_delete_KunpoSDK_SDKHelper)
|
||||
|
||||
static bool js_KunpoSDK_SDKHelper_getInstance_static(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
KunpoSDK::SDKHelper *result = 0 ;
|
||||
|
||||
if(argc != 0) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
result = (KunpoSDK::SDKHelper *)KunpoSDK::SDKHelper::getInstance();
|
||||
|
||||
ok &= nativevalue_to_se(result, s.rval(), s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_KunpoSDK_SDKHelper_getInstance_static)
|
||||
|
||||
static bool js_new_KunpoSDK_SDKHelper(se::State& s) // NOLINT(readability-identifier-naming)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
|
||||
KunpoSDK::SDKHelper *result;
|
||||
result = (KunpoSDK::SDKHelper *)new KunpoSDK::SDKHelper();
|
||||
|
||||
|
||||
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
|
||||
s.thisObject()->setPrivateObject(ptr);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_new_KunpoSDK_SDKHelper, __jsb_KunpoSDK_SDKHelper_class, js_delete_KunpoSDK_SDKHelper)
|
||||
|
||||
static bool js_KunpoSDK_SDKHelper_getSystemInfo(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
KunpoSDK::SDKHelper *arg1 = (KunpoSDK::SDKHelper *) NULL ;
|
||||
|
||||
if(argc != 0) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<KunpoSDK::SDKHelper>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
(arg1)->getSystemInfo();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_KunpoSDK_SDKHelper_getSystemInfo)
|
||||
|
||||
static bool js_KunpoSDK_SDKHelper_getVersionCode(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
KunpoSDK::SDKHelper *arg1 = (KunpoSDK::SDKHelper *) NULL ;
|
||||
std::string result;
|
||||
|
||||
if(argc != 0) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<KunpoSDK::SDKHelper>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
result = (arg1)->getVersionCode();
|
||||
|
||||
ok &= nativevalue_to_se(result, s.rval(), s.thisObject() /*ctx*/);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_KunpoSDK_SDKHelper_getVersionCode)
|
||||
|
||||
static bool js_KunpoSDK_SDKHelper_getBuildCode(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
KunpoSDK::SDKHelper *arg1 = (KunpoSDK::SDKHelper *) NULL ;
|
||||
int result;
|
||||
|
||||
if(argc != 0) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<KunpoSDK::SDKHelper>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
result = (int)(arg1)->getBuildCode();
|
||||
|
||||
ok &= nativevalue_to_se(result, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_KunpoSDK_SDKHelper_getBuildCode)
|
||||
|
||||
static bool js_KunpoSDK_SDKHelper_callJS(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
KunpoSDK::SDKHelper *arg1 = (KunpoSDK::SDKHelper *) NULL ;
|
||||
char *arg2 = (char *) NULL ;
|
||||
ccstd::string temp2 ;
|
||||
|
||||
if(argc != 1) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<KunpoSDK::SDKHelper>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &temp2);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
arg2 = (char *) temp2.c_str();
|
||||
(arg1)->callJS((char const *)arg2);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_KunpoSDK_SDKHelper_callJS)
|
||||
|
||||
static bool js_delete_KunpoSDK_SDKHelper(se::State& s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_delete_KunpoSDK_SDKHelper)
|
||||
|
||||
bool js_register_KunpoSDK_SDKHelper(se::Object* obj) {
|
||||
auto* cls = se::Class::create("SDKHelper", obj, nullptr, _SE(js_new_KunpoSDK_SDKHelper));
|
||||
|
||||
cls->defineStaticProperty("__isJSB", se::Value(true), se::PropertyAttribute::READ_ONLY | se::PropertyAttribute::DONT_ENUM | se::PropertyAttribute::DONT_DELETE);
|
||||
|
||||
cls->defineFunction("getSystemInfo", _SE(js_KunpoSDK_SDKHelper_getSystemInfo));
|
||||
cls->defineFunction("getVersionCode", _SE(js_KunpoSDK_SDKHelper_getVersionCode));
|
||||
cls->defineFunction("getBuildCode", _SE(js_KunpoSDK_SDKHelper_getBuildCode));
|
||||
cls->defineFunction("callJS", _SE(js_KunpoSDK_SDKHelper_callJS));
|
||||
|
||||
|
||||
cls->defineStaticFunction("getInstance", _SE(js_KunpoSDK_SDKHelper_getInstance_static));
|
||||
|
||||
|
||||
cls->defineFinalizeFunction(_SE(js_delete_KunpoSDK_SDKHelper));
|
||||
|
||||
|
||||
cls->install();
|
||||
JSBClassType::registerClass<KunpoSDK::SDKHelper>(cls);
|
||||
|
||||
__jsb_KunpoSDK_SDKHelper_proto = cls->getProto();
|
||||
__jsb_KunpoSDK_SDKHelper_class = cls;
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool register_all_SDKHelper(se::Object* obj) {
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("KunpoSDK", &nsVal, true))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("KunpoSDK", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
/* Register classes */
|
||||
js_register_KunpoSDK_SDKHelper(ns);
|
||||
|
||||
/* Register global variables & global functions */
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
// clang-format on
|
||||
@@ -0,0 +1,51 @@
|
||||
// clang-format off
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (https://www.swig.org).
|
||||
* Version 4.1.0
|
||||
*
|
||||
* Do not make changes to this file unless you know what you are doing - modify
|
||||
* the SWIG interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "cocos/cocos.h"
|
||||
|
||||
#include "../../SDKHelper.h" // 添加这行,%include 指令表示让 swig 解析此文件,并且为此文件中的类生成绑定代码。
|
||||
|
||||
|
||||
|
||||
bool register_all_SDKHelper(se::Object* obj);
|
||||
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(KunpoSDK::SDKHelper);
|
||||
extern se::Object *__jsb_KunpoSDK_SDKHelper_proto; // NOLINT
|
||||
extern se::Class * __jsb_KunpoSDK_SDKHelper_class; // NOLINT
|
||||
|
||||
// clang-format on
|
||||
1
demo/native/engine/common/cocos-version.json
Normal file
@@ -0,0 +1 @@
|
||||
{"version":"3.8.6","skipCheck":false}
|
||||
20
demo/native/engine/common/xr.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
include(${COCOS_X_PATH}/cmake/predefine.cmake)
|
||||
|
||||
if(NOT DEFINED XR_COMMON_SOURCES)
|
||||
set(XR_COMMON_SOURCES)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED XR_LIBS)
|
||||
set(XR_LIBS)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED XR_COMMON_PATH)
|
||||
set(XR_COMMON_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../extensions/xr-plugin/common)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED XR_LIBRARY_PATH)
|
||||
set(XR_LIBRARY_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../extensions/xr-plugin/platforms)
|
||||
endif()
|
||||
|
||||
include(${XR_COMMON_PATH}/xr.cmake)
|
||||
12
demo/native/engine/harmonyos-next/.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/node_modules
|
||||
/local.properties
|
||||
/oh_modules
|
||||
/.idea
|
||||
**/build
|
||||
/.hvigor
|
||||
log.txt
|
||||
oh-package-lock.json5
|
||||
.clang-format
|
||||
.clang-tidy
|
||||
.clangd
|
||||
/entry/oh_modules
|
||||
11
demo/native/engine/harmonyos-next/AppScope/app.json5
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.kunpo.test",
|
||||
"vendor": "example",
|
||||
"versionCode": 1,
|
||||
"versionName": "0.0.1",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"distributedNotificationEnabled": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "kunpocreator"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 9.7 KiB |
19
demo/native/engine/harmonyos-next/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
# the minimum version of CMake.
|
||||
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
set(CC_LIB_NAME cocos)
|
||||
set(CC_PROJ_SOURCES)
|
||||
set(CC_COMMON_SOURCES)
|
||||
set(CC_ALL_SOURCES)
|
||||
|
||||
option(APP_NAME "Project Name" "test-cases")
|
||||
project(${APP_NAME} CXX)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -Werror=return-type")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
|
||||
|
||||
include(${COMMON_DIR}/CMakeLists.txt)
|
||||
|
||||
cc_openharmony_before_target(${CC_LIB_NAME})
|
||||
add_library(${CC_LIB_NAME} SHARED ${CC_ALL_SOURCES})
|
||||
cc_openharmony_after_target(${CC_LIB_NAME})
|
||||
36
demo/native/engine/harmonyos-next/build-profile.json5
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compatibleSdkVersion": "5.0.1(13)",
|
||||
"runtimeOS": "HarmonyOS"
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug"
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
4
demo/native/engine/harmonyos-next/entry/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
18
demo/native/engine/harmonyos-next/entry/build-profile.json5
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
apiType: 'stageMode',
|
||||
buildOption: {
|
||||
externalNativeOptions: {
|
||||
path: '../CMakeLists.txt',
|
||||
arguments: 'arm-linux-ohos -DOHOS_STL=c++_shared -DRES_DIR=/Users/gongxh/work/kunpo-lib/KunpoDemo/build/harmonyos-next -DCOMMON_DIR=/Users/gongxh/work/kunpo-lib/KunpoDemo/native/engine/common -DOPENHARMONY=1',
|
||||
abiFilters: [
|
||||
'arm64-v8a',
|
||||
],
|
||||
cppFlags: '',
|
||||
},
|
||||
},
|
||||
targets: [
|
||||
{
|
||||
name: 'default',
|
||||
},
|
||||
],
|
||||
}
|
||||
2
demo/native/engine/harmonyos-next/entry/hvigorfile.ts
Normal file
@@ -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';
|
||||
12
demo/native/engine/harmonyos-next/entry/oh-package.json5
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {},
|
||||
"author": "",
|
||||
"name": "entry",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"libcocos.so": "file:./src/main/cpp/types/libcocos"
|
||||
}
|
||||
}
|
||||
32
demo/native/engine/harmonyos-next/entry/src/main/cpp/types/libcocos/index.d.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { ContextType } from '../../../ets/common/Constants';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
|
||||
export interface context {
|
||||
onPageShow: () => void;
|
||||
onPageHide: () => void;
|
||||
workerInit: () => void;
|
||||
postMessage: (msgType: string, msgData: string) => void;
|
||||
postSyncMessage: (msgType: string, msgData: string) => Promise<boolean | string | number>;
|
||||
setPostMessageFunction: (postMessage: (msgType: string, msgData: string) => void) => void;
|
||||
setPostSyncMessageFunction: (postSyncMessage: (msgType: string, msgData: string) => void) => void;
|
||||
nativeEngineInit: () => void;
|
||||
nativeEngineStart: () => void;
|
||||
onTextChange: (param: string) => void;
|
||||
onComplete: (param: string) => void;
|
||||
onConfirm: (param: string) => void;
|
||||
shouldStartLoading: (viewTag: number, url: string) => void;
|
||||
finishLoading: (viewTag: number, url: string) => void;
|
||||
failLoading: (viewTag: number, url: string) => void;
|
||||
onBackPress: () => void;
|
||||
onCreate: () => void;
|
||||
onDestroy: () => void;
|
||||
onShow: () => void;
|
||||
onHide: () => void;
|
||||
resourceManagerInit: (resourceManager: resourceManager.ResourceManager) => void;
|
||||
writablePathInit: (cacheDir: string) => void;
|
||||
onVideoEvent: (param: string) => void;
|
||||
registerFunction: (name:string ,fun:Function) => void;
|
||||
}
|
||||
|
||||
export const getContext: (type: ContextType) => context;
|
||||
export const evalString: (value: string) => any;
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "libcocos.so",
|
||||
"types": "./index.d.ts",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information."
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import worker from '@ohos.worker';
|
||||
import { Constants } from '../common/Constants'
|
||||
|
||||
export class WorkerManager {
|
||||
private cocosWorker: worker.ThreadWorker;
|
||||
|
||||
private constructor() {
|
||||
this.cocosWorker = new worker.ThreadWorker("entry/ets/workers/cocos_worker.ts", {
|
||||
type: "classic",
|
||||
name: "CocosWorker"
|
||||
});
|
||||
this.cocosWorker.onerror = (e) => {
|
||||
let msg = e.message;
|
||||
let filename = e.filename;
|
||||
let lineno = e.lineno;
|
||||
let colno = e.colno;
|
||||
console.error(`on Error ${msg} ${filename} ${lineno} ${colno}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static getInstance(): WorkerManager {
|
||||
if (AppStorage.get(Constants.APP_KEY_WORKER_MANAGER) as WorkerManager == undefined) {
|
||||
AppStorage.setOrCreate(Constants.APP_KEY_WORKER_MANAGER, new WorkerManager);
|
||||
}
|
||||
return AppStorage.get(Constants.APP_KEY_WORKER_MANAGER) as WorkerManager;
|
||||
}
|
||||
|
||||
public getWorker(): worker.ThreadWorker {
|
||||
return this.cocosWorker;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import display from '@ohos.display';
|
||||
import I18n from '@ohos.i18n';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
import batteryInfo from '@ohos.batteryInfo';
|
||||
import connection from '@ohos.net.connection'
|
||||
import vibrator from '@ohos.vibrator';
|
||||
import process from '@ohos.process';
|
||||
import { ContextType } from "../../common/Constants"
|
||||
import cocos from "libcocos.so";
|
||||
|
||||
const displayUtils = cocos.getContext(ContextType.DISPLAY_UTILS);
|
||||
|
||||
let pro = new process.ProcessManager();
|
||||
let cutout = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: 0,
|
||||
height: 0
|
||||
};
|
||||
|
||||
globalThis.getSystemLanguage = function () {
|
||||
return I18n.System.getSystemLanguage();
|
||||
}
|
||||
|
||||
globalThis.getOSFullName = function () {
|
||||
return deviceInfo.osFullName;
|
||||
}
|
||||
|
||||
globalThis.getDeviceModel = function () {
|
||||
return deviceInfo.productModel;
|
||||
}
|
||||
|
||||
globalThis.getBatteryLevel = function () {
|
||||
return batteryInfo.batterySOC;
|
||||
}
|
||||
|
||||
globalThis.getDPI = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.densityDPI;
|
||||
}
|
||||
|
||||
globalThis.getPixelRation = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.densityPixels;
|
||||
}
|
||||
|
||||
let onDisplayChange = (data) => {
|
||||
// Monitor changes in screen orientation.
|
||||
displayUtils.onDisplayChange(globalThis.getDeviceOrientation());
|
||||
|
||||
// update screen cutout info
|
||||
globalThis.initScreenInfo();
|
||||
}
|
||||
|
||||
try {
|
||||
display.on("change", onDisplayChange);
|
||||
} catch (exception) {
|
||||
console.log('Failed to register callback. Code: ' + JSON.stringify(exception));
|
||||
}
|
||||
|
||||
globalThis.getDeviceOrientation = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.rotation;
|
||||
}
|
||||
|
||||
globalThis.getNetworkType = function () {
|
||||
let netHandle = connection.getDefaultNetSync();
|
||||
if(netHandle && netHandle.netId != 0) {
|
||||
let result = connection.getNetCapabilitiesSync(netHandle);
|
||||
if (result && result.bearerTypes) {
|
||||
return result.bearerTypes[0];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
globalThis.vibrate = function (duration) {
|
||||
console.log('begin to vibrate, duration is.' + duration);
|
||||
try {
|
||||
vibrator.startVibration({
|
||||
type: 'time',
|
||||
duration: duration * 1000
|
||||
}, {
|
||||
id: 0,
|
||||
usage: 'alarm'
|
||||
}, (error) => {
|
||||
if (error) {
|
||||
console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
|
||||
return error.code;
|
||||
}
|
||||
console.log('Vibration start sucessful.');
|
||||
return 0;
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.terminateProcess = function () {
|
||||
pro.exit(0);
|
||||
}
|
||||
|
||||
globalThis.initScreenInfo = function () {
|
||||
display.getDefaultDisplaySync().getCutoutInfo().then((data) => {
|
||||
if (data.boundingRects.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cutout.left = data.boundingRects[0].left;
|
||||
cutout.top = data.boundingRects[0].top;
|
||||
cutout.width = data.boundingRects[0].width;
|
||||
cutout.height = data.boundingRects[0].height;
|
||||
}).catch((err) => {
|
||||
console.log("get cutout info error!");
|
||||
});
|
||||
};
|
||||
globalThis.initScreenInfo();
|
||||
|
||||
globalThis.getCutoutWidth = function () {
|
||||
if(!cutout.width) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let disPlayWidth = display.getDefaultDisplaySync().width;
|
||||
if(cutout.left + cutout.width > disPlayWidth - cutout.left) {
|
||||
return disPlayWidth - cutout.left;
|
||||
}
|
||||
return cutout.left + cutout.width;
|
||||
}
|
||||
|
||||
globalThis.getCutoutHeight = function () {
|
||||
if(!cutout.height) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let orientation = globalThis.getDeviceOrientation();
|
||||
if (orientation == display.Orientation.PORTRAIT) {
|
||||
return cutout.top + cutout.height;
|
||||
} else if(orientation == display.Orientation.PORTRAIT_INVERTED) {
|
||||
let displayHeight = display.getDefaultDisplaySync().height;
|
||||
return displayHeight - cutout.top;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
export enum ContextType {
|
||||
APP_LIFECYCLE = 0,
|
||||
JSPAGE_LIFECYCLE,
|
||||
XCOMPONENT_CONTEXT,
|
||||
XCOMPONENT_REGISTER_LIFECYCLE_CALLBACK,
|
||||
NATIVE_RENDER_API,
|
||||
WORKER_INIT,
|
||||
ENGINE_UTILS,
|
||||
EDITBOX_UTILS,
|
||||
WEBVIEW_UTILS,
|
||||
DISPLAY_UTILS,
|
||||
UV_ASYNC_SEND,
|
||||
VIDEO_UTILS
|
||||
}
|
||||
|
||||
export class Constants {
|
||||
static readonly APP_KEY_WORKER_MANAGER = "app_key_worker_manager";
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import { ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import { MessageEvent } from '@ohos.worker';
|
||||
|
||||
export class PortProxy {
|
||||
private autoId: number = 0;
|
||||
public actionHandleMap = {}
|
||||
private port: ThreadWorkerGlobalScope = null;
|
||||
|
||||
public _messageHandle?: (e: MessageEvent<any>) => void;
|
||||
|
||||
constructor(worker) {
|
||||
this.port = worker;
|
||||
this.port.onmessage = this.onMessage.bind(this);
|
||||
}
|
||||
|
||||
public onMessage(e) {
|
||||
let data = e['data'];
|
||||
if (data.type != "syncResult" && this._messageHandle) {
|
||||
this._messageHandle(e);
|
||||
} else if (data.type == "syncResult") {
|
||||
const { id, response } = data.data;
|
||||
if (!this.actionHandleMap[id]) {
|
||||
return;
|
||||
}
|
||||
this.actionHandleMap[id].call(this, response);
|
||||
delete this.actionHandleMap[id];
|
||||
}
|
||||
}
|
||||
|
||||
public postReturnMessage(e: any, res: any) {
|
||||
if (e.type == "sync" && res != null && res != undefined) {
|
||||
this.port.postMessage({ type: "syncResult", data: { id: e.data.cbId, response: res } });
|
||||
}
|
||||
}
|
||||
|
||||
public postMessage(msgName: string, msgData: any) {
|
||||
this.port.postMessage({ type: "async", data: { name: msgName, param: msgData } });
|
||||
}
|
||||
|
||||
public postSyncMessage(msgName: string, msgData: any) {
|
||||
const id = this.autoId++;
|
||||
return new Promise((resolve, reject) => {
|
||||
const message = {
|
||||
type: "sync", data: { cbId: id, name: msgName, param: msgData }
|
||||
}
|
||||
this.port.postMessage(message);
|
||||
this.actionHandleMap[id] = (response) => {
|
||||
resolve(response)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
|
||||
enum EventType {
|
||||
PLAYING = 0,
|
||||
PAUSED,
|
||||
STOPPED,
|
||||
COMPLETED,
|
||||
META_LOADED,
|
||||
CLICKED,
|
||||
READY_TO_PLAY,
|
||||
UPDATE,
|
||||
QUIT_FULLSCREEN = 1000
|
||||
}
|
||||
|
||||
interface param {
|
||||
videoTag?: number,
|
||||
videoEvent?: EventType,
|
||||
args?: number
|
||||
}
|
||||
|
||||
@Observed
|
||||
export class VideoInfo {
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string | Resource = "";
|
||||
public viewTag: number = 0;
|
||||
public visible: boolean = true;
|
||||
public duration: number = 0;
|
||||
public currentTime: number = 0;
|
||||
public isFullScreen: boolean = false;
|
||||
public currentProgressRate?: number | string | PlaybackSpeed;
|
||||
public resourceType: number = 0;
|
||||
public isPreparedStart: boolean = false;
|
||||
/**
|
||||
* https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md#videocontroller
|
||||
*
|
||||
*/
|
||||
public controller: VideoController = new VideoController()
|
||||
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.viewTag = viewTag
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct CocosVideoPlayer {
|
||||
@ObjectLink videoInfo: VideoInfo;
|
||||
public workPort: PortProxy | null = null;
|
||||
|
||||
build() {
|
||||
Video({
|
||||
src: this.videoInfo.url,
|
||||
controller: this.videoInfo.controller,
|
||||
currentProgressRate: this.videoInfo.currentProgressRate as number | string | PlaybackSpeed
|
||||
})
|
||||
.position({ x: this.videoInfo.x, y: this.videoInfo.y })
|
||||
.width(this.videoInfo.w)
|
||||
.height(this.videoInfo.h)
|
||||
.controls(false)
|
||||
.autoPlay(false)
|
||||
.onStart(() => {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag as number,
|
||||
videoEvent: EventType.PLAYING as EventType
|
||||
} as param);
|
||||
})
|
||||
.onPause(() => {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag as number,
|
||||
videoEvent: EventType.PAUSED as EventType
|
||||
} as param);
|
||||
})
|
||||
.onFinish(() => {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.COMPLETED
|
||||
} as param);
|
||||
})
|
||||
.onPrepared((event): void => {
|
||||
this.videoInfo.isPreparedStart && this.videoInfo.controller.start();
|
||||
|
||||
this.videoInfo.duration = event?.duration as number;
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.READY_TO_PLAY,
|
||||
args: event?.duration
|
||||
} as param);
|
||||
})
|
||||
.onClick((event): void => {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.CLICKED
|
||||
} as param);
|
||||
})
|
||||
.onUpdate((event) => {
|
||||
this.videoInfo.currentTime = event?.time as number;
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.UPDATE,
|
||||
args: event?.time
|
||||
} as param);
|
||||
})
|
||||
.onFullscreenChange((event) => {
|
||||
if (!event?.fullscreen) {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.QUIT_FULLSCREEN
|
||||
} as param);
|
||||
}
|
||||
this.videoInfo.isFullScreen = event?.fullscreen as boolean;
|
||||
})
|
||||
.visibility(this.videoInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
import web from '@ohos.web.webview';
|
||||
|
||||
interface param {
|
||||
viewTag: number,
|
||||
url: string,
|
||||
}
|
||||
|
||||
@Observed
|
||||
export class WebViewInfo {
|
||||
// position
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
// size
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string = '';
|
||||
// tag
|
||||
public viewTag: number = 0;
|
||||
// Whether to display
|
||||
public visible: boolean = true;
|
||||
/*
|
||||
* doc : https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md#webcontroller
|
||||
*/
|
||||
public controller: web.WebviewController = new web.WebviewController();
|
||||
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.viewTag = viewTag;
|
||||
|
||||
web.once("webInited", () => {
|
||||
if (this.url != '') {
|
||||
this.controller.loadUrl(this.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct CocosWebView {
|
||||
@ObjectLink viewInfo: WebViewInfo;
|
||||
public workPort: PortProxy | null = null;
|
||||
|
||||
build() {
|
||||
Web({ src: this.viewInfo.url, controller: this.viewInfo.controller })
|
||||
.position({ x: this.viewInfo.x, y: this.viewInfo.y })
|
||||
.width(this.viewInfo.w)
|
||||
.height(this.viewInfo.h)
|
||||
.border({ width: 1 })
|
||||
.onControllerAttached(() => {
|
||||
if (this.viewInfo.url != '') {
|
||||
this.viewInfo.controller.loadUrl(this.viewInfo.url);
|
||||
}
|
||||
})
|
||||
.onPageBegin((event) => {
|
||||
this.workPort?.postMessage("onPageBegin", {
|
||||
viewTag: this.viewInfo.viewTag as number,
|
||||
url: event?.url as string
|
||||
} as param);
|
||||
})
|
||||
.onPageEnd((event) => {
|
||||
this.workPort?.postMessage("onPageEnd", { viewTag: this.viewInfo.viewTag as number, url: event?.url as string } as param)
|
||||
})
|
||||
.onErrorReceive((event) => {
|
||||
this.workPort?.postMessage("onErrorReceive", { viewTag: this.viewInfo.viewTag as number, url: this.viewInfo.url as string } as param)
|
||||
})
|
||||
.onHttpErrorReceive((event) => {
|
||||
this.workPort?.postMessage("onErrorReceive", { viewTag: this.viewInfo.viewTag as number, url: this.viewInfo.url as string } as param)
|
||||
})
|
||||
.domStorageAccess(true)// enable DOM storage permissions
|
||||
.databaseAccess(true)// enable database storage permissions
|
||||
.imageAccess(true)// enable image loading permissions
|
||||
.javaScriptAccess(true)// support JS code running
|
||||
.visibility(this.viewInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
@Observed
|
||||
export class EditboxShowInfo {
|
||||
public backgroundColor: number = 0xFFFFFFFF;
|
||||
public enterKeyType: EnterKeyType = EnterKeyType.Done;
|
||||
public type:InputType = InputType.Normal;
|
||||
public maxLength: number = 65536;
|
||||
public defaultMessage: string = '';
|
||||
public textAlign: TextAlign = TextAlign.Start;
|
||||
public showUnderline: boolean = false;
|
||||
public multiLines: boolean = false;
|
||||
// API12
|
||||
public underLineColor: number = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@CustomDialog
|
||||
export struct EditBoxDialog {
|
||||
private inputMessage: string = ''
|
||||
@ObjectLink showInfo: EditboxShowInfo;
|
||||
onTextChange?: (msg: string) => void;
|
||||
accept?: (msg: string) => void;
|
||||
controller?: CustomDialogController;
|
||||
cancel?: () => void;
|
||||
confirm?: (msg: string) => void;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Row() {
|
||||
TextInput({ text: this.showInfo.defaultMessage })
|
||||
.defaultFocus(true)
|
||||
.backgroundColor('#ffffff')
|
||||
.backgroundColor(this.showInfo.backgroundColor)
|
||||
.type(this.showInfo.type)
|
||||
.maxLength(this.showInfo.maxLength)
|
||||
.textAlign(this.showInfo.textAlign)
|
||||
.showUnderline(this.showInfo.showUnderline)
|
||||
.enterKeyType(this.showInfo.enterKeyType)
|
||||
.layoutWeight(1)
|
||||
.onChange((value) => {
|
||||
if (this.onTextChange) {
|
||||
this.onTextChange(value);
|
||||
}
|
||||
this.inputMessage = value;
|
||||
})
|
||||
.onSubmit((value) => {
|
||||
if(this.confirm) {
|
||||
this.confirm(this.inputMessage);
|
||||
}
|
||||
this.controller?.close();
|
||||
})
|
||||
Blank(8).width(16)
|
||||
Button('完成').onClick(() => {
|
||||
if (this.accept) {
|
||||
this.accept(this.inputMessage);
|
||||
}
|
||||
this.controller?.close();
|
||||
})
|
||||
}.padding({ left: 8, right: 8, top: 8, bottom: 8 })
|
||||
.backgroundColor(Color.Gray)
|
||||
.offset({ x : 0, y : 15 })
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
.justifyContent(FlexAlign.End)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import cocos, { context } from 'libcocos.so';
|
||||
import { ContextType } from '../common/Constants';
|
||||
import window from '@ohos.window';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { AbilityConstant, Want } from '@kit.AbilityKit';
|
||||
|
||||
const nativeContext: context = cocos.getContext(ContextType.ENGINE_UTILS);
|
||||
const nativeAppLifecycle: context = cocos.getContext(ContextType.APP_LIFECYCLE);
|
||||
enum windowStageType {
|
||||
hide,
|
||||
show
|
||||
}
|
||||
export default class EntryAbility extends UIAbility {
|
||||
private windowStageType: windowStageType = windowStageType.hide;
|
||||
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
globalThis.abilityWant = want;
|
||||
nativeAppLifecycle.onCreate();
|
||||
nativeContext.resourceManagerInit(this.context.resourceManager);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
nativeAppLifecycle.onDestroy();
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
nativeContext.writablePathInit(this.context.cacheDir);
|
||||
|
||||
// Get the Main window instance
|
||||
let windowClass: window.Window | undefined = undefined;
|
||||
windowStage.getMainWindow((err: BusinessError, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
windowClass = data;
|
||||
// Set whether to display the status bar and navigation bar. If they are not displayed, [] is displayed.
|
||||
let systemBarPromise = windowClass.setWindowSystemBarEnable([]);
|
||||
// Whether the window layout is displayed in full screen mode
|
||||
let fullScreenPromise = windowClass.setWindowLayoutFullScreen(true);
|
||||
// Sets whether the screen is always on.
|
||||
let keepScreenOnPromise = windowClass.setWindowKeepScreenOn(true);
|
||||
Promise.all([systemBarPromise, fullScreenPromise, keepScreenOnPromise]).then(() => {
|
||||
console.info('Succeeded in setting the window');
|
||||
}).catch((err:BusinessError) => {
|
||||
console.error('Failed to set the window, cause ' + JSON.stringify(err));
|
||||
});
|
||||
});
|
||||
// Main window is created, set main page for this ability
|
||||
windowStage.loadContent("pages/index", (err, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
});
|
||||
windowStage.on("windowStageEvent", (data) => {
|
||||
let stageEventType: window.WindowStageEventType = data;
|
||||
switch (stageEventType) {
|
||||
case window.WindowStageEventType.RESUMED:
|
||||
this.onChangeWinodowStageType(windowStageType.show);
|
||||
break;
|
||||
case window.WindowStageEventType.PAUSED:
|
||||
this.onChangeWinodowStageType(windowStageType.hide);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
this.onChangeWinodowStageType(windowStageType.show);
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
this.onChangeWinodowStageType(windowStageType.hide);
|
||||
}
|
||||
|
||||
onChangeWinodowStageType(type: windowStageType) {
|
||||
if (this.windowStageType != type) {
|
||||
this.windowStageType = type;
|
||||
this.windowStageType === windowStageType.show ? nativeAppLifecycle.onShow() : nativeAppLifecycle.onHide();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import nativerender,{context} from 'libcocos.so';
|
||||
|
||||
import { WorkerManager } from '../cocos/WorkerManager';
|
||||
import { ContextType } from '../common/Constants';
|
||||
import { EditBoxDialog, EditboxShowInfo } from '../components/EditBoxDialog';
|
||||
import { CocosWebView, WebViewInfo } from '../components/CocosWebView';
|
||||
import { CocosVideoPlayer, VideoInfo } from '../components/CocosVideoPlayer';
|
||||
import { MessageEvent } from '@ohos.worker';
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
import { common } from '@kit.AbilityKit';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
|
||||
const nativePageLifecycle :context = nativerender.getContext(ContextType.JSPAGE_LIFECYCLE);
|
||||
const engineUtils :context = nativerender.getContext(ContextType.ENGINE_UTILS);
|
||||
|
||||
|
||||
function executeMethodAsync(nativeFunc: Function, funcData: string, funCb: Function): void {
|
||||
nativeFunc && nativeFunc(funcData, funCb);
|
||||
}
|
||||
function executeMethodSync(nativeFunc: Function, funcData: string): string|boolean|number {
|
||||
return nativeFunc && nativeFunc(funcData);
|
||||
}
|
||||
engineUtils.registerFunction("executeMethodAsync", executeMethodAsync);
|
||||
engineUtils.registerFunction("executeMethodSync", executeMethodSync);
|
||||
|
||||
interface WorkerMessage {
|
||||
type: string;
|
||||
data: data;
|
||||
}
|
||||
|
||||
interface data {
|
||||
id: string,
|
||||
name: string,
|
||||
param: number | string | param
|
||||
}
|
||||
|
||||
interface param {
|
||||
tag?: number,
|
||||
url?: string,
|
||||
contents?: string,
|
||||
mimeType?: string,
|
||||
encoding?: string,
|
||||
baseUrl?: string,
|
||||
jsContents?: string,
|
||||
x?: number,
|
||||
y?: number,
|
||||
w?: number,
|
||||
h?: number,
|
||||
visible?: boolean,
|
||||
resourceType?: number,
|
||||
time?: number,
|
||||
fullScreen?: boolean
|
||||
}
|
||||
|
||||
interface editboxShowInfo {
|
||||
defaultValue?: string;
|
||||
confirmType?: string;
|
||||
inputType?: string;
|
||||
maxLength?: number;
|
||||
x?:number;
|
||||
y?:number;
|
||||
width?:number;
|
||||
height?:number;
|
||||
confirmHold?: boolean;
|
||||
isMultiline?: boolean;
|
||||
fontSize?: number;
|
||||
fontColor?: number;
|
||||
backColor?: number;
|
||||
backgroundColor?: number;
|
||||
isBold?: boolean;
|
||||
isItalic?: boolean;
|
||||
isUnderline?: boolean;
|
||||
underlineColor?: number;
|
||||
textAlignment?: number;
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State showInfo: EditboxShowInfo = new EditboxShowInfo;
|
||||
@State webViewArray: WebViewInfo[] = [];
|
||||
@State videoArray: VideoInfo[] = [];
|
||||
private webViewIndexMap: Map<number, number> = new Map<number, number>();
|
||||
private videoIndexMap: Map<number, number> = new Map<number, number>();
|
||||
private workPort: PortProxy = new PortProxy(WorkerManager.getInstance().getWorker());
|
||||
dialogController: CustomDialogController = new CustomDialogController({
|
||||
builder: EditBoxDialog({
|
||||
showInfo: this.showInfo,
|
||||
onTextChange: (msg: string): void => {
|
||||
this.showInfo.defaultMessage = msg;
|
||||
this.workPort.postMessage('onTextInput', msg);
|
||||
},
|
||||
accept: (msg: string): void => {
|
||||
this.showInfo.defaultMessage = msg;
|
||||
this.workPort.postMessage('onComplete', msg);
|
||||
},
|
||||
confirm: (msg: string): void => {
|
||||
this.showInfo.defaultMessage = msg;
|
||||
this.workPort.postMessage('onConfirm', msg);
|
||||
this.workPort.postMessage('onComplete', msg);
|
||||
},
|
||||
}),
|
||||
cancel: (): void => {
|
||||
this.workPort.postMessage('onComplete', this.showInfo.defaultMessage);
|
||||
},
|
||||
autoCancel: true,
|
||||
alignment: DialogAlignment.Bottom,
|
||||
customStyle: true,
|
||||
})
|
||||
|
||||
aboutToAppear(): void {
|
||||
console.log('[LIFECYCLE-Index] cocos aboutToAppear');
|
||||
this.workPort._messageHandle = async (e: MessageEvent<WorkerMessage>): Promise<void> => {
|
||||
let data: WorkerMessage = e.data;
|
||||
let msg = data.data;
|
||||
let result: boolean | string | number | null = null;
|
||||
switch (msg.name) {
|
||||
// EditBox
|
||||
case "showEditBox": {
|
||||
let param = msg.param as editboxShowInfo;
|
||||
this.showInfo.defaultMessage = param?.defaultValue as string;
|
||||
this.showInfo.backgroundColor = param?.backColor as number;
|
||||
if(param?.confirmType == 'done') {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Done;
|
||||
} else if(param?.confirmType == 'send') {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Send;
|
||||
} else if(param?.confirmType == 'search') {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Search;
|
||||
} else if(param?.confirmType == 'go') {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Go;
|
||||
} else if(param?.confirmType == 'next') {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Next;
|
||||
} else {
|
||||
this.showInfo.enterKeyType = EnterKeyType.Done;
|
||||
}
|
||||
if(param?.inputType == 'password') {
|
||||
this.showInfo.type = InputType.Password;
|
||||
} else if(param?.inputType === 'email') {
|
||||
this.showInfo.type = InputType.Email;
|
||||
} else if(param?.inputType === 'number') {
|
||||
this.showInfo.type = InputType.Number;
|
||||
} else if(param?.inputType === 'digit') {
|
||||
this.showInfo.type = InputType.NUMBER_DECIMAL;
|
||||
} else if(param?.inputType === 'tel') {
|
||||
this.showInfo.type = InputType.PhoneNumber;
|
||||
} else if(param?.inputType === 'url') {
|
||||
// No url support
|
||||
} else {
|
||||
this.showInfo.type = InputType.Normal;
|
||||
}
|
||||
if(param?.maxLength != undefined && param?.maxLength > 0) {
|
||||
this.showInfo.maxLength = param.maxLength;
|
||||
} else {
|
||||
this.showInfo.maxLength = 65536;
|
||||
}
|
||||
|
||||
if(param?.isUnderline != undefined) {
|
||||
this.showInfo.showUnderline = param?.isUnderline;
|
||||
this.showInfo.underLineColor = param?.underlineColor as number;
|
||||
} else {
|
||||
this.showInfo.showUnderline = false;
|
||||
}
|
||||
|
||||
if(param?.textAlignment == 0) {
|
||||
this.showInfo.textAlign = TextAlign.Start;
|
||||
} else if(param?.textAlignment == 1) {
|
||||
this.showInfo.textAlign = TextAlign.Center;
|
||||
} else if(param?.textAlignment == 2) {
|
||||
this.showInfo.textAlign = TextAlign.End;
|
||||
} else {
|
||||
this.showInfo.textAlign = TextAlign.Start;
|
||||
}
|
||||
this.dialogController.open();
|
||||
break;
|
||||
}
|
||||
case "hideEditBox": {
|
||||
this.showInfo.defaultMessage = '';
|
||||
this.dialogController.close();
|
||||
break;
|
||||
}
|
||||
// WebView
|
||||
case "createWebView": {
|
||||
this.webViewArray.push(new WebViewInfo(0, 0, 0, 0, msg.param as number));
|
||||
this.webViewIndexMap.set(msg.param as number, this.webViewArray.length - 1);
|
||||
break;
|
||||
}
|
||||
case "removeWebView": {
|
||||
if (this.webViewArray.length > 0) {
|
||||
this.webViewArray.splice(this.webViewIndexMap.get(msg?.param as number) as number, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "loadUrl": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].url = web?.url as string;
|
||||
this.webViewArray[index].controller.loadUrl(web?.url as string);
|
||||
break;
|
||||
}
|
||||
case "loadHTMLString": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.loadData(
|
||||
web?.contents as string,
|
||||
"text/html",
|
||||
"UTF-8",
|
||||
web?.baseUrl
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "loadData": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.loadData(
|
||||
web?.contents as string,
|
||||
web?.mimeType as string,
|
||||
web?.encoding as string,
|
||||
web?.baseUrl as string
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "evaluateJS": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.runJavaScript(web?.jsContents as string);
|
||||
break;
|
||||
}
|
||||
case "reload": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.refresh();
|
||||
break;
|
||||
}
|
||||
case "stopLoading": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "canGoForward": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
result = this.webViewArray[index].controller.accessForward();
|
||||
break;
|
||||
}
|
||||
case "canGoBack": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
result = this.webViewArray[index].controller.accessBackward();
|
||||
break;
|
||||
}
|
||||
case "goForward": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.forward();
|
||||
break;
|
||||
}
|
||||
case "goBack": {
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.backward();
|
||||
break;
|
||||
}
|
||||
case "setWebViewRect": {
|
||||
let web = msg.param as param
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].x = px2vp(web?.x as number) as number;
|
||||
this.webViewArray[index].y = px2vp(web?.y as number) as number;
|
||||
this.webViewArray[index].w = px2vp(web?.w as number) as number;
|
||||
this.webViewArray[index].h = px2vp(web?.h as number) as number;
|
||||
break;
|
||||
}
|
||||
case "setVisible": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].visible = web?.visible as boolean;
|
||||
break;
|
||||
}
|
||||
// video
|
||||
case "createVideo": {
|
||||
this.videoArray.push(new VideoInfo(0, 0, 0, 0, msg.param as number));
|
||||
this.videoIndexMap.set(msg.param as number, this.videoArray.length - 1);
|
||||
break;
|
||||
}
|
||||
case "removeVideo": {
|
||||
if (this.videoArray.length > 0) {
|
||||
this.videoArray.splice(this.videoIndexMap.get(msg.param as number) as number, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "setVideoUrl":
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
let resourceType = video.resourceType;
|
||||
if (resourceType == 1) {
|
||||
video.url = 'Resources/' + video.url;
|
||||
this.videoArray[index].url = $rawfile(video.url as string);
|
||||
} else {
|
||||
this.videoArray[index].url = video.url as string;
|
||||
}
|
||||
break;
|
||||
case "setVideoRect": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].x = px2vp(video?.x as number) as number;
|
||||
this.videoArray[index].y = px2vp(video?.y as number) as number;
|
||||
this.videoArray[index].w = px2vp(video?.w as number) as number;
|
||||
this.videoArray[index].h = px2vp(video?.h as number) as number;
|
||||
break;
|
||||
}
|
||||
case "startVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
if(this.videoArray[index].duration){
|
||||
this.videoArray[index].controller.start();
|
||||
}else{
|
||||
this.videoArray[index].isPreparedStart = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "pauseVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.pause();
|
||||
break;
|
||||
}
|
||||
case "stopVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "resumeVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.start();
|
||||
break;
|
||||
}
|
||||
case "getVideoDuration": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
result = this.videoArray[index].duration;
|
||||
break;
|
||||
}
|
||||
case "seekVideoTo": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].controller.setCurrentTime(video?.time as number, SeekMode.Accurate);
|
||||
break;
|
||||
}
|
||||
case "setVideoVisible": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].visible = video.visible as boolean;
|
||||
break;
|
||||
}
|
||||
case "setFullScreenEnabled": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].isFullScreen = video.fullScreen as boolean;
|
||||
break;
|
||||
}
|
||||
case "currentTime": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
result = this.videoArray[index].currentTime;
|
||||
break;
|
||||
}
|
||||
case "exitGame": {
|
||||
this.terminateSelf();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
}
|
||||
}
|
||||
if (result != null || result != undefined) {
|
||||
this.workPort.postReturnMessage(data, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
console.log('[LIFECYCLE-Index] cocos aboutToDisappear');
|
||||
// this.cocosWorker.postMessage({type: "JSPageLifecycle", data: "aboutToAppear"});
|
||||
// nativePageLifecycle.aboutToDisappear();
|
||||
}
|
||||
|
||||
onPageShow(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageShow');
|
||||
nativePageLifecycle.onPageShow();
|
||||
}
|
||||
|
||||
onPageHide(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageHide');
|
||||
nativePageLifecycle.onPageHide();
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
console.log("[LIFECYCLE-Page] cocos onBackPress");
|
||||
this.workPort.postMessage("backPress", "");
|
||||
// If disable system exit needed, remove comment "return true"
|
||||
// return true;
|
||||
}
|
||||
|
||||
terminateSelf() {
|
||||
try {
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelf((err: BusinessError) => {
|
||||
if (err.code) {
|
||||
console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
|
||||
return;
|
||||
}
|
||||
console.info('terminateSelf succeed');
|
||||
});
|
||||
} catch (err) {
|
||||
let code = (err as BusinessError).code;
|
||||
let message = (err as BusinessError).message;
|
||||
console.error(`terminateSelf failed, code is ${code}, message is ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({
|
||||
direction: FlexDirection.Column,
|
||||
alignItems: ItemAlign.Center,
|
||||
justifyContent: FlexAlign.Center
|
||||
} as FlexOptions) {
|
||||
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'cocos' })
|
||||
.onLoad((context) => {
|
||||
// Set the cache directory in the ts layer.
|
||||
this.workPort.postMessage("onXCLoad", "XComponent");
|
||||
})
|
||||
.onDestroy(() => {
|
||||
console.log('cocos onDestroy')
|
||||
})
|
||||
|
||||
ForEach(this.webViewArray, (item: WebViewInfo) => {
|
||||
CocosWebView({ viewInfo: item, workPort: this.workPort })
|
||||
}, (item: WebViewInfo): string => item.viewTag.toString())
|
||||
|
||||
ForEach(this.videoArray, (item: VideoInfo) => {
|
||||
CocosVideoPlayer({ videoInfo: item, workPort: this.workPort })
|
||||
}, (item: VideoInfo): string => item.viewTag.toString())
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import worker from '@ohos.worker';
|
||||
import cocos from 'libcocos.so';
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
import { ContextType } from '../common/Constants';
|
||||
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
|
||||
|
||||
globalThis.importPolyfill = async function () {
|
||||
await import('../cocos/oh-adapter/sys-ability-polyfill.js');
|
||||
}
|
||||
globalThis.importPolyfill();
|
||||
globalThis.oh = {};
|
||||
|
||||
|
||||
if (!(console as any).assert) {
|
||||
(console as any).assert = function(cond, msg) {
|
||||
if (!cond) {
|
||||
throw new Error(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const nativeContext = cocos.getContext(ContextType.WORKER_INIT);
|
||||
nativeContext.workerInit();
|
||||
|
||||
const nativeEditBox = cocos.getContext(ContextType.EDITBOX_UTILS);
|
||||
const nativeWebView = cocos.getContext(ContextType.WEBVIEW_UTILS);
|
||||
const appLifecycle = cocos.getContext(ContextType.APP_LIFECYCLE);
|
||||
const nativeVideo = cocos.getContext(ContextType.VIDEO_UTILS);
|
||||
|
||||
let uiPort = new PortProxy(worker.workerPort);
|
||||
|
||||
nativeContext.postMessage = function (msgType: string, msgData: string): void {
|
||||
uiPort.postMessage(msgType, msgData);
|
||||
}
|
||||
|
||||
nativeContext.postSyncMessage = async function (msgType: string, msgData: string): Promise<boolean | string | number> {
|
||||
const result = await uiPort.postSyncMessage(msgType, msgData) as boolean | string | number;
|
||||
return result;
|
||||
}
|
||||
|
||||
// The purpose of this is to avoid being GC
|
||||
nativeContext.setPostMessageFunction.call(nativeContext, nativeContext.postMessage)
|
||||
nativeContext.setPostSyncMessageFunction.call(nativeContext, nativeContext.postSyncMessage)
|
||||
|
||||
globalThis.terminateProcess = function () {
|
||||
uiPort.postMessage("exitGame",0);
|
||||
}
|
||||
|
||||
uiPort._messageHandle = function (e) {
|
||||
var data = e.data;
|
||||
var msg = data.data;
|
||||
|
||||
switch (msg.name) {
|
||||
case "onXCLoad":
|
||||
const renderContext = cocos.getContext(ContextType.NATIVE_RENDER_API);
|
||||
renderContext.nativeEngineInit();
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.oh.postMessage = nativeContext.postMessage;
|
||||
// @ts-ignore
|
||||
globalThis.oh.postSyncMessage = nativeContext.postSyncMessage;
|
||||
renderContext.nativeEngineStart();
|
||||
break;
|
||||
case "onTextInput":
|
||||
nativeEditBox.onTextChange(msg.param);
|
||||
break;
|
||||
case "onComplete":
|
||||
nativeEditBox.onComplete(msg.param);
|
||||
break;
|
||||
case "onConfirm":
|
||||
nativeEditBox.onConfirm(msg.param);
|
||||
break;
|
||||
case "onPageBegin":
|
||||
nativeWebView.shouldStartLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onPageEnd":
|
||||
nativeWebView.finishLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onErrorReceive":
|
||||
nativeWebView.failLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onVideoEvent":
|
||||
nativeVideo.onVideoEvent(JSON.stringify(msg.param));
|
||||
break;
|
||||
case "backPress":
|
||||
appLifecycle.onBackPress();
|
||||
break;
|
||||
default:
|
||||
console.error("cocos worker: message type unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:entry_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default"
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.INTERNET"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.VIBRATE"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.ACCELEROMETER"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GYROSCOPE"
|
||||
}
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"orientation": "portrait",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"startWindowIcon": "$media:icon",
|
||||
"removeMissionAfterTerminate": true,
|
||||
"startWindowBackground": "$color:white",
|
||||
"supportWindowMode": [
|
||||
"fullscreen"
|
||||
],
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
2
demo/native/engine/harmonyos-next/entry/src/main/resources/.gitignore
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
/rawfile/
|
||||
.DS_Store
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "white",
|
||||
"value": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"name": "black",
|
||||
"value": "#000000"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_label",
|
||||
"value": "kunpocreator"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "permissions_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 9.7 KiB |
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/index"
|
||||
]
|
||||
}
|
||||
22
demo/native/engine/harmonyos-next/hvigor/hvigor-config.json5
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
},
|
||||
"execution": {
|
||||
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
|
||||
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
|
||||
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
|
||||
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
|
||||
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
|
||||
},
|
||||
"logging": {
|
||||
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
|
||||
},
|
||||
"debugging": {
|
||||
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
|
||||
},
|
||||
"nodeOptions": {
|
||||
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
|
||||
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
|
||||
}
|
||||
}
|
||||
6
demo/native/engine/harmonyos-next/hvigorfile.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
13
demo/native/engine/harmonyos-next/oh-package.json5
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
modelVersion: '5.0.0',
|
||||
devDependencies: {
|
||||
'@ohos/hypium': '1.0.18',
|
||||
'@ohos/hamock': '1.0.0',
|
||||
},
|
||||
author: '',
|
||||
name: 'kunpocreator',
|
||||
description: 'example description',
|
||||
main: '',
|
||||
version: '1.0.0',
|
||||
dependencies: {},
|
||||
}
|
||||
41
demo/native/engine/ios/AppDelegate.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You
|
||||
shall not use Cocos Creator software for developing other software or tools
|
||||
that's used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
|
||||
you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import "platform/ios/AppDelegateBridge.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class ViewController;
|
||||
|
||||
@interface AppDelegate : NSObject <UIApplicationDelegate> {
|
||||
}
|
||||
|
||||
@property(nonatomic, readonly) ViewController *viewController;
|
||||
@property(nonatomic, readonly) AppDelegateBridge *appDelegateBridge;
|
||||
@end
|
||||
107
demo/native/engine/ios/AppDelegate.mm
Normal file
@@ -0,0 +1,107 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "ViewController.h"
|
||||
#import "View.h"
|
||||
|
||||
#include "platform/ios/IOSPlatform.h"
|
||||
#import "platform/ios/AppDelegateBridge.h"
|
||||
#import "service/SDKWrapper.h"
|
||||
|
||||
@implementation AppDelegate
|
||||
@synthesize window;
|
||||
@synthesize appDelegateBridge;
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
[[SDKWrapper shared] application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
appDelegateBridge = [[AppDelegateBridge alloc] init];
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||
self.window = [[UIWindow alloc] initWithFrame:bounds];
|
||||
|
||||
// Should create view controller first, cc::Application will use it.
|
||||
_viewController = [[ViewController alloc] init];
|
||||
_viewController.view = [[View alloc] initWithFrame:bounds];
|
||||
_viewController.view.contentScaleFactor = UIScreen.mainScreen.scale;
|
||||
_viewController.view.multipleTouchEnabled = true;
|
||||
[self.window setRootViewController:_viewController];
|
||||
|
||||
[self.window makeKeyAndVisible];
|
||||
[appDelegateBridge application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationWillResignActive:application];
|
||||
[appDelegateBridge applicationWillResignActive:application];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationDidBecomeActive:application];
|
||||
[appDelegateBridge applicationDidBecomeActive:application];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationDidEnterBackground:application];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationWillEnterForeground:application];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
[[SDKWrapper shared] applicationWillTerminate:application];
|
||||
[appDelegateBridge applicationWillTerminate:application];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
[[SDKWrapper shared] applicationDidReceiveMemoryWarning:application];
|
||||
}
|
||||
|
||||
@end
|
||||
45
demo/native/engine/ios/Base.lproj/LaunchScreen.storyboard
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="retina5_9" orientation="landscape">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment version="2048" identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="fm7-M6-edp"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="uRH-d6-mvd"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="812" height="375"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleAspectFill" insetsLayoutMarginsFromSafeArea="NO" image="LaunchScreenBackground.png" translatesAutoresizingMaskIntoConstraints="NO" id="YCC-wj-Gww" userLabel="Background">
|
||||
<rect key="frame" x="0.0" y="0.0" width="812" height="375"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="YCC-wj-Gww" secondAttribute="bottom" id="Naz-ae-jWI"/>
|
||||
<constraint firstAttribute="trailing" secondItem="YCC-wj-Gww" secondAttribute="trailing" id="myj-85-hk9"/>
|
||||
<constraint firstItem="YCC-wj-Gww" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="qOq-Cg-doS"/>
|
||||
<constraint firstItem="YCC-wj-Gww" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="xL7-Fo-4bl"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="50.399999999999999" y="373.15270935960592"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="LaunchScreenBackground.png" width="2208" height="1242"/>
|
||||
</resources>
|
||||
</document>
|
||||
9
demo/native/engine/ios/Base.lproj/Localizable.strings
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
*/
|
||||
|
||||
"done" = "Done";
|
||||
"next" = "Next";
|
||||
"search" = "Search";
|
||||
"go" = "Go";
|
||||
"send" = "Send";
|
||||
20
demo/native/engine/ios/CMakeLists.txt
Executable file
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
set(CMAKE_SYSTEM_NAME iOS)
|
||||
set(APP_NAME "kunpocreator" CACHE STRING "Project Name")
|
||||
|
||||
project(${APP_NAME} CXX)
|
||||
|
||||
set(CC_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(CC_UI_RESOURCES)
|
||||
set(CC_PROJ_SOURCES)
|
||||
set(CC_ASSET_FILES)
|
||||
set(CC_COMMON_SOURCES)
|
||||
set(CC_ALL_SOURCES)
|
||||
|
||||
include(${CC_PROJECT_DIR}/../common/CMakeLists.txt)
|
||||
set(EXECUTABLE_NAME ${APP_NAME}-mobile)
|
||||
|
||||
cc_ios_before_target(${EXECUTABLE_NAME})
|
||||
add_executable(${EXECUTABLE_NAME} ${CC_ALL_SOURCES})
|
||||
cc_ios_after_target(${EXECUTABLE_NAME})
|
||||
|
After Width: | Height: | Size: 216 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 23 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/29.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/40.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/57.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/58.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/60.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/80.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
demo/native/engine/ios/Images.xcassets/AppIcon.appiconset/87.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
@@ -0,0 +1 @@
|
||||
{"images":[{"size":"60x60","expected-size":"180","filename":"180.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"40x40","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"60x60","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"57x57","expected-size":"57","filename":"57.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"87","filename":"87.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"57x57","expected-size":"114","filename":"114.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"60","filename":"60.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"1024x1024","filename":"1024.png","expected-size":"1024","idiom":"ios-marketing","folder":"Assets.xcassets/AppIcon.appiconset/","scale":"1x"}]}
|
||||
6
demo/native/engine/ios/Images.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
55
demo/native/engine/ios/Info.plist
Normal file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${CC_EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIcons~ipad</key>
|
||||
<dict/>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<true/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<dict>
|
||||
<key>accelerometer</key>
|
||||
<true/>
|
||||
<key>opengles-1</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
demo/native/engine/ios/LaunchScreenBackground.png
Normal file
|
After Width: | Height: | Size: 128 KiB |
BIN
demo/native/engine/ios/LaunchScreenBackgroundLandscape.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
demo/native/engine/ios/LaunchScreenBackgroundPortrait.png
Normal file
|
After Width: | Height: | Size: 128 KiB |
1
demo/native/engine/ios/Post-service.cmake
Normal file
@@ -0,0 +1 @@
|
||||
# Supported for Cocos Service!
|
||||
1
demo/native/engine/ios/Pre-service.cmake
Normal file
@@ -0,0 +1 @@
|
||||
# Supported for Cocos Service!
|
||||
8
demo/native/engine/ios/Prefix.pch
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Prefix header for all source files of the 'HelloJavascript' target in the 'HelloJavascript' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
35
demo/native/engine/ios/ViewController.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You
|
||||
shall not use Cocos Creator software for developing other software or tools
|
||||
that's used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
|
||||
you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
@end
|
||||
76
demo/native/engine/ios/ViewController.mm
Normal file
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#import "ViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "platform/ios/AppDelegateBridge.h"
|
||||
//#include "cocos/platform/Device.h"
|
||||
|
||||
namespace {
|
||||
// cc::Device::Orientation _lastOrientation;
|
||||
}
|
||||
|
||||
@interface ViewController ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
|
||||
- (BOOL) shouldAutorotate {
|
||||
return YES;
|
||||
}
|
||||
|
||||
//fix not hide status on ios7
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Controls the application's screen edge gesture delay to prevent accidental touches
|
||||
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
|
||||
{
|
||||
return UIRectEdgeAll;
|
||||
}
|
||||
|
||||
// Controls the application's preferred home indicator auto-showing otherwise preferredScreenEdgesDeferringSystemGestures is invalidation
|
||||
- (BOOL)prefersHomeIndicatorAutoHidden {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
||||
AppDelegate* delegate = [[UIApplication sharedApplication] delegate];
|
||||
[delegate.appDelegateBridge viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
float pixelRatio = [delegate.appDelegateBridge getPixelRatio];
|
||||
|
||||
//CAMetalLayer is available on ios8.0, ios-simulator13.0.
|
||||
CAMetalLayer *layer = (CAMetalLayer *)self.view.layer;
|
||||
CGSize tsize = CGSizeMake(static_cast<int>(size.width * pixelRatio),
|
||||
static_cast<int>(size.height * pixelRatio));
|
||||
layer.drawableSize = tsize;
|
||||
}
|
||||
|
||||
@end
|
||||
42
demo/native/engine/ios/main.mm
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "platform/BasePlatform.h"
|
||||
#include "AppDelegate.h"
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
cc::BasePlatform* platform = cc::BasePlatform::getPlatform();
|
||||
if (platform->init()) {
|
||||
return -1;
|
||||
}
|
||||
platform->run(argc, argv);
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
int retVal = UIApplicationMain(argc, (char**)argv, nil, @"AppDelegate");
|
||||
[pool release];
|
||||
return retVal;
|
||||
}
|
||||
|
||||
60
demo/native/engine/ios/service/SDKWrapper.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You
|
||||
shall not use Cocos Creator software for developing other software or tools
|
||||
that's used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
|
||||
you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SDKDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
- (void)application:(UIApplication *)application
|
||||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application;
|
||||
- (void)applicationWillResignActive:(UIApplication *)application;
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application;
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application;
|
||||
- (void)applicationWillTerminate:(UIApplication *)application;
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
|
||||
|
||||
@end
|
||||
|
||||
@interface SDKWrapper : NSObject
|
||||
@property(nonatomic, strong) NSString *name;
|
||||
+ (instancetype)shared;
|
||||
- (void)application:(UIApplication *)application
|
||||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application;
|
||||
- (void)applicationWillResignActive:(UIApplication *)application;
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application;
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application;
|
||||
- (void)applicationWillTerminate:(UIApplication *)application;
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
142
demo/native/engine/ios/service/SDKWrapper.m
Normal file
@@ -0,0 +1,142 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import "SDKWrapper.h"
|
||||
|
||||
@interface SDKWrapper ()
|
||||
|
||||
@property (nonatomic, strong) NSArray *serviceInstances;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDKWrapper
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Singleton
|
||||
|
||||
static SDKWrapper *mInstace = nil;
|
||||
|
||||
+ (instancetype)shared {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
mInstace = [[super allocWithZone:NULL] init];
|
||||
[mInstace initSDKWrapper];
|
||||
});
|
||||
return mInstace;
|
||||
}
|
||||
+ (id)allocWithZone:(struct _NSZone *)zone {
|
||||
return [SDKWrapper shared];
|
||||
}
|
||||
|
||||
+ (id)copyWithZone:(struct _NSZone *)zone {
|
||||
return [SDKWrapper shared];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark private methods
|
||||
- (void)initSDKWrapper {
|
||||
[self loadSDKClass];
|
||||
}
|
||||
|
||||
- (void)loadSDKClass {
|
||||
NSMutableArray *sdks = [NSMutableArray array];
|
||||
@try {
|
||||
NSString *path = [NSString stringWithFormat:@"%@/service.json", [[NSBundle mainBundle] resourcePath]];
|
||||
NSData *data = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
id dic = obj[@"serviceClasses"];
|
||||
if (dic == nil) @throw [[NSException alloc] initWithName:@"JSON Exception" reason:@"serviceClasses not found" userInfo:nil];
|
||||
for (NSString *str in dic) {
|
||||
NSString *className = [[str componentsSeparatedByString:@"."] lastObject];
|
||||
Class clazz = NSClassFromString(className);
|
||||
if (clazz == nil) @throw [[NSException alloc] initWithName:@"Cass Exception"
|
||||
reason:[NSString stringWithFormat:@"class '%@' not found", className]
|
||||
userInfo:nil];
|
||||
id sdk = [[clazz alloc] init];
|
||||
[sdks addObject:sdk];
|
||||
}
|
||||
} @catch (NSException *e) {
|
||||
}
|
||||
self.serviceInstances = [NSArray arrayWithArray:sdks];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
for (id <SDKDelegate> sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(application:didFinishLaunchingWithOptions:)]) {
|
||||
[sdk application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidBecomeActive:)]) {
|
||||
[sdk applicationDidBecomeActive:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillResignActive:)]) {
|
||||
[sdk applicationWillResignActive:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidEnterBackground:)]) {
|
||||
[sdk applicationDidEnterBackground:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillEnterForeground:)]) {
|
||||
[sdk applicationWillEnterForeground:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillTerminate:)]) {
|
||||
[sdk applicationWillTerminate:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidReceiveMemoryWarning:)]) {
|
||||
[sdk applicationDidReceiveMemoryWarning:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
9
demo/native/engine/ios/zh-Hans.lproj/Localizable.strings
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
*/
|
||||
|
||||
"done" = "完成";
|
||||
"next" = "下一个";
|
||||
"search" = "搜索";
|
||||
"go" = "前往";
|
||||
"send" = "发送";
|
||||