This commit is contained in:
2026-03-10 14:50:57 +08:00
commit 439503661d
56 changed files with 2893 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

35
libservice/build.gradle Normal file
View File

@@ -0,0 +1,35 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
namespace 'com.cocos.service'
defaultConfig {
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
sourceSets.main {
java.srcDirs "src"
res.srcDirs 'res'
jniLibs.srcDirs 'libs'
manifest.srcFile "AndroidManifest.xml"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation project(':libcocos')
}

21
libservice/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# 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 *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,185 @@
/****************************************************************************
Copyright (c) 2017-2020 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.
****************************************************************************/
package com.cocos.service;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.os.Bundle;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
public final class SDKWrapper {
private SDKWrapper() {}
private static class SDKWrapperInstance {
private static final SDKWrapper mInstance = new SDKWrapper();
}
public static SDKWrapper shared() { return SDKWrapperInstance.mInstance; }
@SuppressWarnings("unused")
public interface SDKInterface {
default void init(Context context) {}
default void onStart() {}
default void onPause() {}
default void onResume() {}
default void onStop() {}
default void onDestroy() {}
default void onRestart() {}
default void onNewIntent(Intent intent) {}
default void onActivityResult(int requestCode, int resultCode, Intent data) {}
default void onConfigurationChanged(Configuration newConfig) {}
default void onRestoreInstanceState(Bundle savedInstanceState) {}
default void onSaveInstanceState(Bundle outState) {}
default void onBackPressed() {}
default void onLowMemory() {}
}
private WeakReference<Activity> mActivity = null;
private List<SDKInterface> serviceInstances;
private void loadSDKInterface() {
ArrayList<SDKInterface> instances = new ArrayList<>();
try {
String json = this.getJson("service.json");
JSONObject jsonObject = new JSONObject(json);
JSONArray serviceClasses = jsonObject.getJSONArray("serviceClasses");
if (serviceClasses == null) return;
int length = serviceClasses.length();
for (int i = 0; i < length; i++) {
instances.add((SDKInterface) Class.forName(serviceClasses.getString(i)).newInstance());
}
} catch (Exception ignored) { }
this.serviceInstances = instances;
}
@SuppressWarnings("SameParameterValue")
private String getJson(String fileName) {
StringBuilder sb = new StringBuilder();
try {
AssetManager am = this.mActivity.get().getAssets();
BufferedReader br = new BufferedReader(new InputStreamReader(am.open(fileName)));
String next;
while (null != (next = br.readLine())) { sb.append(next); }
} catch (IOException e) {
sb.delete(0, sb.length());
}
return sb.toString().trim();
}
public Activity getActivity() { return this.mActivity.get(); }
public void init(Activity activity) {
this.mActivity = new WeakReference<>(activity);
this.loadSDKInterface();
for (SDKInterface sdk : this.serviceInstances) {
sdk.init(activity);
}
}
public void onResume() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onResume();
}
}
public void onPause() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onPause();
}
}
public void onDestroy() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onDestroy();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onActivityResult(requestCode, resultCode, data);
}
}
public void onNewIntent(Intent intent) {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onNewIntent(intent);
}
}
public void onRestart() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onRestart();
}
}
public void onStop() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onStop();
}
}
public void onBackPressed() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onBackPressed();
}
}
public void onConfigurationChanged(Configuration newConfig) {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onConfigurationChanged(newConfig);
}
}
public void onRestoreInstanceState(Bundle savedInstanceState) {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onRestoreInstanceState(savedInstanceState);
}
}
public void onSaveInstanceState(Bundle outState) {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onSaveInstanceState(outState);
}
}
public void onStart() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onStart();
}
}
public void onLowMemory() {
for (SDKInterface sdk : this.serviceInstances) {
sdk.onLowMemory();
}
}
}