add ResourceLoader plugin

This commit is contained in:
pengfei.zhou
2021-11-18 16:38:35 +08:00
committed by osborn
parent ea85559977
commit d746c5b4d4
22 changed files with 312 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
api 'com.github.penfeizhou:jsc4a:0.2.5'
api 'com.github.penfeizhou:jsc4a:0.3.0'
//api "pub.doric:jse:${rootProject.ext.Version}"
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation('com.github.penfeizhou.android.animation:glide-plugin:2.17.0') {

View File

@@ -37,6 +37,7 @@ import pub.doric.plugin.NetworkPlugin;
import pub.doric.plugin.NotchPlugin;
import pub.doric.plugin.NotificationPlugin;
import pub.doric.plugin.PopoverPlugin;
import pub.doric.plugin.ResourceLoaderPlugin;
import pub.doric.plugin.ShaderPlugin;
import pub.doric.plugin.StatusBarPlugin;
import pub.doric.plugin.StoragePlugin;
@@ -112,6 +113,7 @@ public class DoricRegistry {
this.registerNativePlugin(CoordinatorPlugin.class);
this.registerNativePlugin(NotchPlugin.class);
this.registerNativePlugin(KeyboardPlugin.class);
this.registerNativePlugin(ResourceLoaderPlugin.class);
this.registerViewNode(RootNode.class);
this.registerViewNode(TextNode.class);

View File

@@ -1,3 +1,18 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pub.doric.plugin;
import android.animation.Animator;

View File

@@ -0,0 +1,71 @@
/*
* Copyright [2021] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pub.doric.plugin;
import com.bumptech.glide.Glide;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JavaValue;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise;
import pub.doric.resource.DoricResource;
import pub.doric.utils.DoricLog;
/**
* @Description: This is for loading resource into js as ArrayBuffer
* @Author: pengfei.zhou
* @CreateDate: 2021/11/18
*/
@DoricPlugin(name = "resourceLoader")
public class ResourceLoaderPlugin extends DoricJavaPlugin {
public ResourceLoaderPlugin(DoricContext doricContext) {
super(doricContext);
}
@DoricMethod
public void load(JSObject resource, final DoricPromise promise) {
final String type = resource.getProperty("type").asString().value();
final String identifier = resource.getProperty("identifier").asString().value();
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(getDoricContext(), type, identifier);
if (doricResource != null) {
doricResource.fetchRaw().setCallback(new AsyncResult.Callback<byte[]>() {
@Override
public void onResult(byte[] rawData) {
promise.resolve(new JavaValue(rawData));
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
DoricLog.e("Cannot load resource type = %s, identifier = %s, %s", type, identifier, t.getLocalizedMessage());
promise.reject(new JavaValue("Load error"));
}
@Override
public void onFinish() {
}
});
} else {
DoricLog.e("Cannot find loader for resource type = %s, identifier = %s", type, identifier);
promise.reject(new JavaValue("Load error"));
}
}
}

View File

@@ -15,12 +15,9 @@
*/
package pub.doric.resource;
import java.io.InputStream;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
/**
* @Description: This represents a resource entity
* @Author: pengfei.zhou