Skip to content

Commit d7fd696

Browse files
authored
Merge pull request #23 from VideoOS/marge
Marge
2 parents ff814c0 + e96a059 commit d7fd696

File tree

95 files changed

+8009
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+8009
-280
lines changed

VideoOS/LuaViewSDK/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ android {
5353
dependencies {
5454
compile fileTree(dir: 'libs', include: ['*.jar'])
5555
provided project(path: ':VenvyLibrary')
56+
compile project(path: ':venvy_svga')
5657
provided 'com.android.support:support-v4:25.3.1'
5758
provided 'com.android.support:recyclerview-v7:25.3.1'
5859
provided 'com.android.support:appcompat-v7:25.3.1'

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/LuaHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import cn.com.venvy.lua.binder.VenvyMediaViewBinder;
1818
import cn.com.venvy.lua.binder.VenvyMqttBinder;
1919
import cn.com.venvy.lua.binder.VenvyNativeBinder;
20+
import cn.com.venvy.lua.binder.VenvyNotificationBinder;
2021
import cn.com.venvy.lua.binder.VenvySvgaBinder;
2122
import cn.com.venvy.lua.binder.VenvyWebViewBinder;
2223
import cn.com.venvy.lua.bridge.LVHttpBridge;
@@ -40,6 +41,7 @@ public class LuaHelper {
4041
private static LVHttpBridge lvHttpBridge;
4142
private static VenvyMediaViewBinder mediaViewBinder;
4243
private static VenvyHttpRequestBinder httpRequestBinder;
44+
private static VenvyNotificationBinder notificationBinder;
4345

4446
public static void initLuaConfig() {
4547
LuaView.registerImageProvider(ImageProviderImpl.class);
@@ -77,6 +79,7 @@ private static void registerNativeLibs(@NonNull LuaView luaView, Platform platfo
7779
getActivityLifeCycleBinder(),
7880
getKeyboardBinder(),
7981
getMediaViewBinder(),
82+
getNotificationBinder(),
8083
getNativeBinder(platform, viewGroup), getHttpRequestBinder(platform));
8184
luaView.setUseStandardSyntax(true);//是否使用标准语法
8285
}
@@ -91,6 +94,10 @@ private static VenvyHttpRequestBinder getHttpRequestBinder(Platform platform) {
9194
return target;
9295
}
9396

97+
private static VenvyNotificationBinder getNotificationBinder() {
98+
return notificationBinder == null ? notificationBinder = new VenvyNotificationBinder() : notificationBinder;
99+
}
100+
94101
private static UIGradientViewBinder getUiGradientViewBinder() {
95102
return uiGradientViewBinder == null ? uiGradientViewBinder = new UIGradientViewBinder() : uiGradientViewBinder;
96103
}
@@ -148,5 +155,6 @@ public static void destroy() {
148155
lvHttpBridge = null;
149156
mediaViewBinder = null;
150157
httpRequestBinder = null;
158+
notificationBinder = null;
151159
}
152160
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.com.venvy.lua.binder;
2+
3+
import com.taobao.luaview.fun.base.BaseFunctionBinder;
4+
import com.taobao.luaview.fun.base.BaseVarArgUICreator;
5+
import com.taobao.luaview.view.interfaces.ILVView;
6+
7+
import org.luaj.vm2.Globals;
8+
import org.luaj.vm2.LuaValue;
9+
import org.luaj.vm2.Varargs;
10+
import org.luaj.vm2.lib.LibFunction;
11+
12+
import cn.com.venvy.lua.maper.VenvyNotificationMapper;
13+
import cn.com.venvy.lua.view.VenvyLVNotificationCallback;
14+
15+
/**
16+
* Created by mac on 18/3/29.
17+
*/
18+
19+
public class VenvyNotificationBinder extends BaseFunctionBinder {
20+
21+
public VenvyNotificationBinder() {
22+
super("Notification");
23+
}
24+
25+
@Override
26+
public Class<? extends LibFunction> getMapperClass() {
27+
return VenvyNotificationMapper.class;
28+
}
29+
30+
@Override
31+
public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
32+
return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) {
33+
@Override
34+
public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) {
35+
return new VenvyLVNotificationCallback(globals, metaTable, varargs);
36+
}
37+
};
38+
}
39+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cn.com.venvy.lua.maper;
2+
3+
import android.text.TextUtils;
4+
5+
import com.taobao.luaview.fun.mapper.LuaViewLib;
6+
import com.taobao.luaview.fun.mapper.ui.UIViewMethodMapper;
7+
import com.taobao.luaview.util.LuaUtil;
8+
9+
import org.luaj.vm2.LuaFunction;
10+
import org.luaj.vm2.LuaTable;
11+
import org.luaj.vm2.LuaValue;
12+
import org.luaj.vm2.Varargs;
13+
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
import cn.com.venvy.common.bean.NotificationInfo;
18+
import cn.com.venvy.lua.ud.VenvyUDNotificationCallback;
19+
20+
/**
21+
* Created by mac on 18/3/29.
22+
*/
23+
@LuaViewLib(revisions = {"20190828已对标"})
24+
public class VenvyNotificationMapper<U extends VenvyUDNotificationCallback> extends UIViewMethodMapper<U> {
25+
private static final String TAG = "VenvyNotificationMapper";
26+
private static final String[] sMethods = new String[]{
27+
"registerNotification",
28+
"postNotification",
29+
"removeNotification",
30+
};
31+
32+
@Override
33+
public List<String> getAllFunctionNames() {
34+
return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods);
35+
}
36+
37+
@Override
38+
public Varargs invoke(int code, U target, Varargs varargs) {
39+
final int optcode = code - super.getAllFunctionNames().size();
40+
switch (optcode) {
41+
case 0:
42+
return registerNotification(target, varargs);
43+
case 1:
44+
return postNotification(target, varargs);
45+
case 2:
46+
return removeNotification(target, varargs);
47+
}
48+
return super.invoke(code, target, varargs);
49+
}
50+
51+
public LuaValue registerNotification(U target, Varargs args) {
52+
if (args.narg() > 0) {
53+
final String tag = LuaUtil.getString(args, 2);
54+
final LuaFunction callback = args.optfunction(3, null);
55+
if (TextUtils.isEmpty(tag)) {
56+
return LuaValue.NIL;
57+
}
58+
if (callback != null && callback.isfunction()) {
59+
return target.registerNotification(callback, tag);
60+
}
61+
}
62+
return LuaValue.NIL;
63+
}
64+
65+
public LuaValue postNotification(U target, Varargs args) {
66+
if (args.narg() > 0) {
67+
String tag = LuaUtil.getString(args, 2);
68+
if (TextUtils.isEmpty(tag)) {
69+
return LuaValue.NIL;
70+
}
71+
LuaTable table = LuaUtil.getTable(args, 3);
72+
Map<String, String> messageMap = LuaUtil.toMap(table);
73+
NotificationInfo info = new NotificationInfo();
74+
info.messageInfo = messageMap;
75+
target.postNotification(tag, info);
76+
}
77+
return LuaValue.NIL;
78+
}
79+
80+
public LuaValue removeNotification(U target, Varargs args) {
81+
if (args.narg() > 0) {
82+
String tag = LuaUtil.getString(args, 2);
83+
if (TextUtils.isEmpty(tag)) {
84+
return LuaValue.NIL;
85+
}
86+
target.removeNotification(tag);
87+
}
88+
return LuaValue.NIL;
89+
}
90+
}

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/plugin/LVEventPlugin.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Created by Arthur on 2017/8/21.
3030
* <p>
3131
* * A类小程序 L uaView://defaultLuaView?template=xxx.lua&id=xxx
32-
* * 跳转B类小程序 LuaView://applets?appletId=xxxx&type=x(type: 1横屏,2竖屏)
32+
* * 跳转B类小程序 LuaView://applets?appletId=xxxx&type=x&appType=x(type: 1横屏,2竖屏,appType: 1 lua,2 H5)
3333
* *
3434
* * B类小程序容器内部跳转 LuaView://applets?appletId=xxxx&template=xxxx.lua&id=xxxx&(priority=x)
3535
*/
@@ -89,16 +89,29 @@ public Varargs invoke(Varargs args) {
8989
info.withTargetViewParent(mPlatform.getContentViewGroup()).withTargetPlatform("platform", mPlatform).navigation();
9090
} else if (protocolHost.equalsIgnoreCase("applets")) {
9191
String type = info.getBundle().getString("type");
92-
VenvyLog.d("type is "+type);
92+
String appType = info.getBundle().getString("appType");
93+
if(TextUtils.isEmpty(appType)){
94+
VenvyLog.d("appType is null");
95+
// appType为空默认指定为lua
96+
appType = String.valueOf(VenvyObservableTarget.Constant.CONSTANT_APP_TYPE_LUA);
97+
}
98+
VenvyLog.d("type is "+type+" , appType is "+appType);
9399
if(TextUtils.isEmpty(type)){
94100
// B类小程序内部跳转
95101
info.withTargetViewParent(mPlatform.getContentViewGroup()).withTargetPlatform("platform", mPlatform).navigation();
102+
103+
// Bundle bundle = new Bundle();
104+
// bundle.putString(VenvyObservableTarget.KEY_APPLETS_ID, info.getBundle().getString("appletId"));
105+
// bundle.putString(VenvyObservableTarget.Constant.CONSTANT_TEMPLATE, info.getBundle().getString("template"));
106+
// bundle.putString(VenvyObservableTarget.Constant.CONSTANT_ID, info.getBundle().getString("id"));
107+
// bundle.putString(VenvyObservableTarget.Constant.CONSTANT_DATA, JsonUtil.toString(table));
96108
ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_ADD_LUA_SCRIPT_TO_VISION_PROGRAM, null);
97109
}else{
98110
// 发起一个视联网小程序
99111
Bundle bundle = new Bundle();
100112
bundle.putString(VenvyObservableTarget.KEY_APPLETS_ID, info.getBundle().getString("appletId"));
101113
bundle.putString(VenvyObservableTarget.KEY_ORIENTATION_TYPE, type);
114+
bundle.putString(VenvyObservableTarget.Constant.CONSTANT_APP_TYPE, appType);
102115
if (table != null) {
103116
bundle.putString(VenvyObservableTarget.Constant.CONSTANT_DATA, JsonUtil.toString(table));
104117
}

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/plugin/LVVideoPlugin.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import cn.com.venvy.Config;
1313
import cn.com.venvy.Platform;
14+
import cn.com.venvy.common.bean.VideoFrameSize;
1415
import cn.com.venvy.common.bean.VideoPlayerSize;
1516
import cn.com.venvy.common.debug.DebugStatus;
1617
import cn.com.venvy.common.interf.ScreenStatus;
@@ -29,6 +30,7 @@ public static void install(VenvyLVLibBinder venvyLVLibBinder, Platform platform)
2930
venvyLVLibBinder.set("isDebug", sIsDebug == null ? sIsDebug = new IsDebug() : sIsDebug);
3031
venvyLVLibBinder.set("setDebug", sChangeEnvironment == null ? sChangeEnvironment = new ChangeEnvironment() : sChangeEnvironment);
3132
venvyLVLibBinder.set("getVideoSize", new VideoSize(platform));
33+
venvyLVLibBinder.set("getVideoFrame", new VideoFrame(platform));
3234
venvyLVLibBinder.set("currentDirection", new CurrentScreenDirection(platform));
3335
venvyLVLibBinder.set("isFullScreen", new IsFullScreen(platform));
3436
venvyLVLibBinder.set("appKey", new AppKey(platform));
@@ -254,6 +256,35 @@ public Varargs invoke(Varargs args) {
254256
}
255257
}
256258

259+
private static class VideoFrame extends VarArgFunction {
260+
private Platform mPlatform;
261+
262+
VideoFrame(Platform platform) {
263+
this.mPlatform = platform;
264+
}
265+
266+
@Override
267+
public Varargs invoke(Varargs args) {
268+
269+
if (mPlatform == null || mPlatform.getMediaControlListener() == null) {
270+
LuaValue[] luaValue = new LuaValue[]{LuaValue.valueOf(0), LuaValue.valueOf(0), LuaValue.valueOf(0), LuaValue.valueOf(0)};
271+
return LuaValue.varargsOf(luaValue);
272+
}
273+
VideoFrameSize videoFrameSize = mPlatform.getMediaControlListener().getVideoFrameSize();
274+
if (videoFrameSize == null) {
275+
LuaValue[] luaValue = new LuaValue[]{LuaValue.valueOf(0), LuaValue.valueOf(0), LuaValue.valueOf(0), LuaValue.valueOf(0)};
276+
return LuaValue.varargsOf(luaValue);
277+
}
278+
float videoWidth = DimenUtil.pxToDpi(videoFrameSize.mVideoFrameWidth);
279+
float videoHeight = DimenUtil.pxToDpi(videoFrameSize.mVideoFrameHeight);
280+
float x = DimenUtil.pxToDpi(videoFrameSize.mVideoFrameX);
281+
float y = DimenUtil.pxToDpi(videoFrameSize.mVideoFrameY);
282+
LuaValue[] luaValue = new LuaValue[]{LuaValue.valueOf(x), LuaValue.valueOf(y), LuaValue.valueOf(videoWidth), LuaValue.valueOf(videoHeight)};
283+
return LuaValue.varargsOf(luaValue);
284+
285+
}
286+
}
287+
257288
/**
258289
* 判断sdk是否是debug状态
259290
*/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package cn.com.venvy.lua.ud;
2+
3+
import android.os.Bundle;
4+
import android.text.TextUtils;
5+
6+
import com.taobao.luaview.userdata.ui.UDView;
7+
import com.taobao.luaview.util.LuaUtil;
8+
9+
import org.luaj.vm2.Globals;
10+
import org.luaj.vm2.LuaValue;
11+
import org.luaj.vm2.Varargs;
12+
13+
import java.io.Serializable;
14+
15+
import cn.com.venvy.common.bean.NotificationInfo;
16+
import cn.com.venvy.common.observer.ObservableManager;
17+
import cn.com.venvy.common.observer.VenvyObservable;
18+
import cn.com.venvy.common.observer.VenvyObserver;
19+
import cn.com.venvy.lua.view.VenvyLVNotificationCallback;
20+
21+
/**
22+
* Created by mac on 18/3/29.
23+
*/
24+
25+
public class VenvyUDNotificationCallback extends UDView<VenvyLVNotificationCallback> implements VenvyObserver {
26+
LuaValue registerNotificationCallback;
27+
public static final String OBSERVABLE_NOTIFICATION_MESSAGE = "Observable_notification_message";
28+
public static final String OBSERVABLE_NOTIFICATION_TAG = "Observable_notification_tag";
29+
30+
public VenvyUDNotificationCallback(VenvyLVNotificationCallback view, Globals globals, LuaValue metatable, Varargs initParams) {
31+
super(view, globals, metatable, initParams);
32+
}
33+
34+
public VenvyUDNotificationCallback registerNotification(LuaValue callbacks, String tag) {
35+
if (callbacks != null) {
36+
registerNotificationCallback = callbacks;
37+
ObservableManager.getDefaultObserable().addObserver(tag, this);
38+
}
39+
return this;
40+
}
41+
42+
public void postNotification(String tag, NotificationInfo message) {
43+
if (TextUtils.isEmpty(tag)) {
44+
return;
45+
}
46+
Bundle bundle = new Bundle();
47+
bundle.putSerializable(OBSERVABLE_NOTIFICATION_MESSAGE, message);
48+
bundle.putString(OBSERVABLE_NOTIFICATION_TAG, tag);
49+
ObservableManager.getDefaultObserable().sendToTarget(tag, bundle);
50+
}
51+
52+
public void removeNotification(String tag) {
53+
ObservableManager.getDefaultObserable().removeObserverByTag(tag);
54+
}
55+
56+
@Override
57+
public void notifyChanged(VenvyObservable observable, String tag, Bundle bundle) {
58+
if (bundle == null) {
59+
return;
60+
}
61+
if (!TextUtils.equals(tag, bundle.getString(OBSERVABLE_NOTIFICATION_TAG))) {
62+
return;
63+
}
64+
Serializable serializable = bundle.getSerializable(OBSERVABLE_NOTIFICATION_MESSAGE);
65+
if (serializable == null) {
66+
if (registerNotificationCallback != null) {
67+
if (serializable != null && serializable instanceof NotificationInfo) {
68+
LuaUtil.callFunction(registerNotificationCallback, LuaValue.NIL);
69+
}
70+
}
71+
return;
72+
}
73+
NotificationInfo info = (NotificationInfo) serializable;
74+
if (registerNotificationCallback != null) {
75+
if (serializable != null && serializable instanceof NotificationInfo) {
76+
LuaUtil.callFunction(registerNotificationCallback, LuaUtil.toTable(info.messageInfo));
77+
}
78+
}
79+
}
80+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.com.venvy.lua.view;
2+
3+
import android.view.View;
4+
5+
import com.taobao.luaview.userdata.ui.UDView;
6+
import com.taobao.luaview.view.interfaces.ILVView;
7+
8+
import org.luaj.vm2.Globals;
9+
import org.luaj.vm2.LuaValue;
10+
import org.luaj.vm2.Varargs;
11+
12+
import cn.com.venvy.lua.ud.VenvyUDNotificationCallback;
13+
14+
/**
15+
* Created by mac on 18/3/29.
16+
*/
17+
18+
public class VenvyLVNotificationCallback extends View implements ILVView {
19+
20+
private VenvyUDNotificationCallback mLuaUserdata;
21+
22+
public VenvyLVNotificationCallback(Globals globals, LuaValue metaTable, Varargs varargs) {
23+
super(globals.getContext());
24+
this.mLuaUserdata = new VenvyUDNotificationCallback(this, globals, metaTable, varargs);
25+
}
26+
27+
@Override
28+
protected void onAttachedToWindow() {
29+
super.onAttachedToWindow();
30+
}
31+
32+
@Override
33+
public UDView getUserdata() {
34+
return mLuaUserdata;
35+
}
36+
37+
@Override
38+
protected void onDetachedFromWindow() {
39+
super.onDetachedFromWindow();
40+
}
41+
}

0 commit comments

Comments
 (0)