add ResourceLoader plugin
This commit is contained in:
parent
ea85559977
commit
d746c5b4d4
@ -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') {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Base64Resource, Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal, RemoteResource, MainBundleResource, AndroidAssetsResource, AssetsResource } from "doric";
|
||||
import { Base64Resource, DrawableResource, Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal, RemoteResource, MainBundleResource } from "doric";
|
||||
import { colors, label } from "./utils";
|
||||
import { img_base64 } from "./image_base64";
|
||||
|
||||
|
67
doric-demo/src/ResourceDemo.tsx
Normal file
67
doric-demo/src/ResourceDemo.tsx
Normal file
@ -0,0 +1,67 @@
|
||||
import {
|
||||
Base64Resource,
|
||||
DrawableResource,
|
||||
Group,
|
||||
Panel,
|
||||
jsx,
|
||||
Color,
|
||||
layoutConfig,
|
||||
Image,
|
||||
RemoteResource,
|
||||
MainBundleResource,
|
||||
Scroller,
|
||||
VLayout,
|
||||
Text,
|
||||
Gravity,
|
||||
resourceLoader,
|
||||
} from "doric";
|
||||
import { colors, label } from "./utils";
|
||||
import { img_base64 } from "./image_base64";
|
||||
import { loge } from "doric/lib/src/util/log";
|
||||
|
||||
@Entry
|
||||
export class ResourceDemo extends Panel {
|
||||
build(root: Group): void {
|
||||
<Scroller parent={root} layoutConfig={layoutConfig().most()}>
|
||||
<VLayout
|
||||
layoutConfig={layoutConfig().mostWidth().fitHeight()}
|
||||
space={10}
|
||||
gravity={Gravity.Center}
|
||||
>
|
||||
<Text
|
||||
layoutConfig={layoutConfig().mostWidth().justHeight()}
|
||||
textSize={30}
|
||||
textColor={Color.WHITE}
|
||||
backgroundColor={colors[5]}
|
||||
textAlignment={Gravity.Center}
|
||||
height={50}
|
||||
>
|
||||
Image Demo
|
||||
</Text>
|
||||
{label("Button")}
|
||||
<Image
|
||||
image={
|
||||
Environment.platform === "Android"
|
||||
? new DrawableResource("doric_icon_back")
|
||||
: new MainBundleResource("Hanabi.ttf")
|
||||
}
|
||||
/>
|
||||
<Image
|
||||
image={
|
||||
new RemoteResource("https://p.upyun.com/demo/webp/webp/jpg-0.webp")
|
||||
}
|
||||
/>
|
||||
<Image
|
||||
image={new Base64Resource(img_base64[0])}
|
||||
onClick={async () => {
|
||||
const resource = new RemoteResource(
|
||||
"https://p.upyun.com/demo/webp/webp/jpg-0.webp"
|
||||
);
|
||||
const rawData = await resourceLoader(context).load(resource);
|
||||
loge(rawData.byteLength);
|
||||
}}
|
||||
/>
|
||||
</VLayout>
|
||||
</Scroller>;
|
||||
}
|
||||
}
|
@ -4203,6 +4203,14 @@ function keyboard(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function resourceLoader(context) {
|
||||
return {
|
||||
load: function (resource) {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
var __values = (undefined && undefined.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) { return m.call(o); }
|
||||
@ -4628,6 +4636,7 @@ exports.popover = popover;
|
||||
exports.pullable = pullable;
|
||||
exports.refreshable = refreshable;
|
||||
exports.repeat = repeat;
|
||||
exports.resourceLoader = resourceLoader;
|
||||
exports.scroller = scroller;
|
||||
exports.slideItem = slideItem;
|
||||
exports.slider = slider;
|
||||
|
@ -3222,6 +3222,14 @@ function keyboard(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function resourceLoader(context) {
|
||||
return {
|
||||
load: (resource) => {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -3559,6 +3567,7 @@ exports.popover = popover;
|
||||
exports.pullable = pullable;
|
||||
exports.refreshable = refreshable;
|
||||
exports.repeat = repeat;
|
||||
exports.resourceLoader = resourceLoader;
|
||||
exports.scroller = scroller;
|
||||
exports.slideItem = slideItem;
|
||||
exports.slider = slider;
|
||||
|
@ -4750,6 +4750,14 @@ function keyboard(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function resourceLoader(context) {
|
||||
return {
|
||||
load: (resource) => {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -5328,6 +5336,7 @@ exports.popover = popover;
|
||||
exports.pullable = pullable;
|
||||
exports.refreshable = refreshable;
|
||||
exports.repeat = repeat;
|
||||
exports.resourceLoader = resourceLoader;
|
||||
exports.scroller = scroller;
|
||||
exports.slideItem = slideItem;
|
||||
exports.slider = slider;
|
||||
|
9
doric-js/index.d.ts
vendored
9
doric-js/index.d.ts
vendored
@ -112,6 +112,7 @@ declare module 'doric/lib/src/native/index.native' {
|
||||
export * from 'doric/lib/src/native/coordinator';
|
||||
export * from 'doric/lib/src/native/notch';
|
||||
export * from 'doric/lib/src/native/keyboard';
|
||||
export * from 'doric/lib/src/native/resourceLoader';
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/util/index.util' {
|
||||
@ -1344,6 +1345,14 @@ declare module 'doric/lib/src/native/keyboard' {
|
||||
};
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/native/resourceLoader' {
|
||||
import { Resource } from "doric/lib/src/util/resource";
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
export function resourceLoader(context: BridgeContext): {
|
||||
load: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
};
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/util/color' {
|
||||
import { Modeling } from "doric/lib/src/util/types";
|
||||
/**
|
||||
|
6
doric-js/lib/src/native/imageDecoder.d.ts
vendored
Normal file
6
doric-js/lib/src/native/imageDecoder.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { Resource } from "../util/resource";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function imageDecoder(context: BridgeContext): {
|
||||
getBitmapInfo: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
};
|
25
doric-js/lib/src/native/imageDecoder.js
Normal file
25
doric-js/lib/src/native/imageDecoder.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
export function imageDecoder(context) {
|
||||
return {
|
||||
getBitmapInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getBitmapInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => {
|
||||
return context.callNative('imageDecoder', 'decode', resource);
|
||||
},
|
||||
};
|
||||
}
|
1
doric-js/lib/src/native/index.native.d.ts
vendored
1
doric-js/lib/src/native/index.native.d.ts
vendored
@ -10,3 +10,4 @@ export * from './statusbar';
|
||||
export * from './coordinator';
|
||||
export * from './notch';
|
||||
export * from './keyboard';
|
||||
export * from './resourceLoader';
|
||||
|
@ -25,3 +25,4 @@ export * from './statusbar';
|
||||
export * from './coordinator';
|
||||
export * from './notch';
|
||||
export * from './keyboard';
|
||||
export * from './resourceLoader';
|
||||
|
5
doric-js/lib/src/native/resourceLoader.d.ts
vendored
Normal file
5
doric-js/lib/src/native/resourceLoader.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { Resource } from "../util/resource";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function resourceLoader(context: BridgeContext): {
|
||||
load: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
};
|
7
doric-js/lib/src/native/resourceLoader.js
Normal file
7
doric-js/lib/src/native/resourceLoader.js
Normal file
@ -0,0 +1,7 @@
|
||||
export function resourceLoader(context) {
|
||||
return {
|
||||
load: (resource) => {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel());
|
||||
},
|
||||
};
|
||||
}
|
29
doric-js/src/native/imageDecoder.ts
Normal file
29
doric-js/src/native/imageDecoder.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { Resource } from "../util/resource"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
|
||||
export function imageDecoder(context: BridgeContext) {
|
||||
return {
|
||||
getBitmapInfo: (resource: Resource) => {
|
||||
return context.callNative('imageDecoder', 'getBitmapInfo', resource) as Promise<ArrayBuffer>
|
||||
},
|
||||
decodeToPixels: (resource: Resource) => {
|
||||
return context.callNative('imageDecoder', 'decode', resource) as Promise<ArrayBuffer>
|
||||
},
|
||||
}
|
||||
}
|
@ -24,4 +24,5 @@ export * from './notification'
|
||||
export * from './statusbar'
|
||||
export * from './coordinator'
|
||||
export * from './notch'
|
||||
export * from './keyboard'
|
||||
export * from './keyboard'
|
||||
export * from './resourceLoader'
|
25
doric-js/src/native/resourceLoader.ts
Normal file
25
doric-js/src/native/resourceLoader.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import { Resource } from "../util/resource"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
|
||||
export function resourceLoader(context: BridgeContext) {
|
||||
return {
|
||||
load: (resource: Resource) => {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel()) as Promise<ArrayBuffer>;
|
||||
},
|
||||
}
|
||||
}
|
9
doric-web/dist/index.js
vendored
9
doric-web/dist/index.js
vendored
@ -4824,6 +4824,14 @@ function keyboard(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function resourceLoader(context) {
|
||||
return {
|
||||
load: (resource) => {
|
||||
return context.callNative('resourceLoader', 'load', resource.toModel());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class Observable {
|
||||
constructor(provider, clz) {
|
||||
this.observers = new Set;
|
||||
@ -5161,6 +5169,7 @@ exports.popover = popover;
|
||||
exports.pullable = pullable;
|
||||
exports.refreshable = refreshable;
|
||||
exports.repeat = repeat;
|
||||
exports.resourceLoader = resourceLoader;
|
||||
exports.scroller = scroller;
|
||||
exports.slideItem = slideItem;
|
||||
exports.slider = slider;
|
||||
|
10
doric-web/dist/index.js.map
vendored
10
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user