Skip to content

Commit fe478cd

Browse files
author
野松
committed
Merge branch 'dev_5.25.0' into deploy
2 parents c7d7bda + 3108bdc commit fe478cd

File tree

106 files changed

+492
-2891
lines changed

Some content is hidden

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

106 files changed

+492
-2891
lines changed

Android/LuaViewDemo/LuaViewDemo.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,5 @@
101101
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
102102
<orderEntry type="library" exported="" name="glide-3.7.0" level="project" />
103103
<orderEntry type="module" module-name="LuaViewSDK" exported="" />
104-
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
105104
</component>
106105
</module>
622 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Created by LuaView.
2+
-- Copyright (c) 2017, Alibaba Group. All rights reserved.
3+
--
4+
-- This source code is licensed under the MIT.
5+
-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
6+
7+
-- Created by LuaView.
8+
-- Copyright (c) 2017, Alibaba Group. All rights reserved.
9+
--
10+
-- This source code is licensed under the MIT.
11+
-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
12+
13+
code = [[
14+
a = {}
15+
a.x = function()
16+
local btn = Button()
17+
btn:frame(0, 0, 100, 100)
18+
btn:text("button")
19+
-- btn:callback(function
20+
-- Toast("btn clicked")
21+
-- end)
22+
end
23+
24+
a.x()
25+
]]
26+
27+
28+
--hi = load(code)
29+
--hi()
30+
31+
32+
33+
load("local btn = Button(); btn:text('yyy'); btn:callback(function Toast('x') end)")()
34+
35+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- 活动指示器
2+
local SCREEN_WIDTH = System:screenSize()
3+
4+
local scrollView = HScrollView()
5+
6+
7+
for i = 0, 10, 1 do
8+
local btn = Label()
9+
btn:text("BTN" .. i)
10+
btn:frame(i * 60, 10, 59, 80)
11+
btn:backgroundColor(0xff00ff00)
12+
scrollView:addView(btn)
13+
end
14+
15+
scrollView:xy(0, 300)
16+
scrollView:size(SCREEN_WIDTH, 100)
17+
scrollView:backgroundColor(0xffcccccc)
18+
scrollView:showScrollIndicator(false)
19+
20+
21+
scrollView:callback({
22+
Scrolling = function(x, y)
23+
print("Scrolling", x, y)
24+
print(scrollView:offset())
25+
end
26+
})

Android/LuaViewDemo/assets/test/UI_CollectionView.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,28 @@ local cellData = function(_, key)
5555
return {
5656
Size = function(section, row)
5757
print("Size", section, row, 10 + row * 2)
58-
return 10 + row * 2
58+
-- return 10 + row * 2
59+
return s_width, 200
5960
end,
6061
Init = function(cell, section, row) -- 初始化cell
6162
print("Init", section, row, 10 + row * 2)
6263
cell.title = Label();
6364
cell.title.backgroundColor(section == 1 and 0xff0000 or 0x00ff00)
65+
cell.title.lines(10)
66+
cell.title.maxLine(10)
6467
end,
6568
Layout = function(cell, section, row) -- cell复用时调用
6669
print("Layout", section, row, 10 + row * 2)
67-
cell.title.frame(0, 0, s_width, 10 + row * 2)
68-
cell.title.text(section .. '--' .. row)
70+
-- cell.title.frame(0, 0, s_width, 10 + row * 2)
71+
72+
cell.title.text("sfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfs")
73+
74+
print("cell-size 11", cell.title.height())
75+
76+
cell.title.adjustSize()
77+
78+
print("cell-size 22", cell.title.height())
79+
6980
end,
7081
Callback = function(cell, section, row) -- 用户点击了section和row
7182
Toast("Section " .. section .. ", Row " .. row);

Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class DemoActivity extends ListActivity {
2727
//测试标准语法
28-
public static boolean useStandardSyntax = false;
28+
public static boolean useStandardSyntax = true;
2929

3030
//非标准语法代码路径
3131
private static final String FOLDER_NAME = "test";

Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoLuaViewActivity.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,28 @@ private void extendsLuaView(final LuaView luaView) {
109109
* 加载数据
110110
*/
111111
public void loadScript(final LuaView luaView) {
112-
luaView.load(getLuaUri(), new LuaScriptLoader.ScriptExecuteCallback() {
112+
// luaView.load(getLuaUri(), new LuaScriptLoader.ScriptExecuteCallback() {
113+
// @Override
114+
// public boolean onScriptPrepared(ScriptBundle bundle) {
115+
// return false;
116+
// }
117+
//
118+
// @Override
119+
// public boolean onScriptCompiled(LuaValue value, LuaValue context, LuaValue view) {
120+
// return false;
121+
// }
122+
//
123+
// @Override
124+
// public void onScriptExecuted(String uri, boolean executedSuccess) {
125+
// //测试调用 lua function
126+
// LogUtil.d("call-lua-function return:", luaView.callLuaFunction("global_fun_test1", 1, "a", 0.1));
127+
// LogUtil.d("call-lua-function return:", JsonUtil.toString(luaView.callLuaFunction("global_fun_test2", 2, "b", 0.2)));
128+
// LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun1", 3, "c", 0.3));
129+
// LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun2", 4, "d", 0.4));
130+
// }
131+
// });
132+
133+
luaView.load("file:///android_asset/luaview/test.szip", new LuaScriptLoader.ScriptExecuteCallback() {
113134
@Override
114135
public boolean onScriptPrepared(ScriptBundle bundle) {
115136
return false;
@@ -122,11 +143,7 @@ public boolean onScriptCompiled(LuaValue value, LuaValue context, LuaValue view)
122143

123144
@Override
124145
public void onScriptExecuted(String uri, boolean executedSuccess) {
125-
//测试调用 lua function
126-
LogUtil.d("call-lua-function return:", luaView.callLuaFunction("global_fun_test1", 1, "a", 0.1));
127-
LogUtil.d("call-lua-function return:", JsonUtil.toString(luaView.callLuaFunction("global_fun_test2", 2, "b", 0.2)));
128-
LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun1", 3, "c", 0.3));
129-
LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun2", 4, "d", 0.4));
146+
130147
}
131148
});
132149
}

Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIEditTextMethodMapper.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.taobao.luaview.userdata.ui.UDEditText;
1313
import com.taobao.luaview.util.LuaViewUtil;
1414

15+
import org.luaj.vm2.LuaString;
1516
import org.luaj.vm2.LuaValue;
1617
import org.luaj.vm2.Varargs;
1718

@@ -29,7 +30,8 @@ public class UIEditTextMethodMapper<U extends UDEditText> extends UITextViewMeth
2930
private static final String TAG = "UIEditTextMethodMapper";
3031
private static final String[] sMethods = new String[]{
3132
"hint",//0
32-
"placeholder"//1
33+
"placeholder",//1
34+
"inputType"//2
3335
};
3436

3537
@Override
@@ -45,12 +47,33 @@ public Varargs invoke(int code, U target, Varargs varargs) {
4547
return hint(target, varargs);
4648
case 1:
4749
return placeholder(target, varargs);
50+
case 2:
51+
return inputType(target, varargs);
4852
}
4953
return super.invoke(code, target, varargs);
5054
}
5155

5256
//--------------------------------------- API --------------------------------------------------
5357

58+
/**
59+
* 键盘类型
60+
*/
61+
public LuaValue inputType(U view, Varargs varargs) {
62+
if (varargs.narg() > 1) {
63+
return setInputType(view, varargs);
64+
} else {
65+
return getInputType(view, varargs);
66+
}
67+
}
68+
69+
public LuaValue setInputType(U view, Varargs varargs) {
70+
final CharSequence type = LuaViewUtil.getText(varargs.optvalue(2, NIL));
71+
return view.setInputType(type);
72+
}
73+
74+
public LuaValue getInputType(U view, Varargs varargs) {
75+
return valueOf(view.getInputType());
76+
}
5477

5578
/**
5679
* 获取placeHolder内容

Android/LuaViewSDK/src/com/taobao/luaview/global/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class Constants {
2424
public static final String PARAM_URI = "uri";
2525
public static final String PAGE_PARAMS = "page_params";
2626

27+
// asset file prefix for loading luaview.load(ASSET_FILE_PREFIX + "foler/name")
28+
public static final String ASSET_FILE_PREFIX = "file:///android_asset/";
29+
2730
//Bundle encrypt and decrypt
2831
public static final String PUBLIC_KEY_PATH = "luaview/luaview_rsa_public_key.der";
2932
public static final String PUBLIC_KEY_PATH_MD5 = "luaview/luaview_rsa_public_key.der-md5";

Android/LuaViewSDK/src/com/taobao/luaview/global/LuaScriptLoader.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public interface ScriptLoaderCallback {
4545
void onScriptLoaded(final ScriptBundle bundle);//脚本加载
4646
}
4747

48+
public interface ScriptLoaderCallback2 extends ScriptLoaderCallback {
49+
void onScriptDownloadStart();//下载开始
50+
51+
void onScriptDownloadEnd(final ScriptBundle bundle);//包内设置的脚本加载
52+
}
53+
4854
/**
4955
* 脚本运行回调
5056
*/
@@ -74,6 +80,26 @@ public interface ScriptExecuteCallback {
7480
void onScriptExecuted(String uri, boolean executedSuccess);
7581
}
7682

83+
/**
84+
* 脚本运行回调
85+
*/
86+
public interface ScriptExecuteCallback2 extends ScriptExecuteCallback {
87+
88+
/**
89+
* 脚本下载开始
90+
*/
91+
void onScriptDownloadStart();
92+
93+
/**
94+
* 脚本下载完毕
95+
*
96+
* @param bundle
97+
* @return
98+
*/
99+
void onScriptDownloadEnd(ScriptBundle bundle);
100+
101+
}
102+
77103
//-----------------------------------------static methods---------------------------------------
78104

79105
/**
@@ -128,7 +154,7 @@ public void load(final String url, final ScriptLoaderCallback callback) {
128154
public void load(final String url, final String sha256, final ScriptLoaderCallback callback) {
129155
new ScriptBundleUltimateLoadTask(mContext, callback).load(url, sha256);
130156
}
131-
157+
132158

133159
//--------------------------------preload script------------------------------------------------
134160

Android/LuaViewSDK/src/com/taobao/luaview/global/LuaView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ public String getUri() {
412412
return mLuaViewCore != null ? mLuaViewCore.getUri() : null;
413413
}
414414

415+
public void setUri(String uri) {
416+
if (mLuaViewCore != null) {
417+
mLuaViewCore.setUri(uri);
418+
}
419+
}
420+
415421
public Globals getGlobals() {
416422
return mLuaViewCore != null ? mLuaViewCore.getGlobals() : null;
417423
}

Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewCore.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public static void createAsync(final Context context, final LuaViewCore.CreatedC
105105
new SimpleTask1<LuaViewCore>() {
106106
@Override
107107
protected LuaViewCore doInBackground(Object... params) {
108-
final Globals globals = LuaViewManager.createGlobalsAsync();
109-
return createLuaViewCore(context, globals);
108+
return create(context);
110109
}
111110

112111
@Override
@@ -160,7 +159,7 @@ public LuaViewCore load(final String urlOrFileOrScript, final String sha256) {
160159

161160
public LuaViewCore load(final String urlOrFileOrScript, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) {
162161
if (!TextUtils.isEmpty(urlOrFileOrScript)) {
163-
if (URLUtil.isNetworkUrl(urlOrFileOrScript)) {//url, http:// or https://
162+
if (URLUtil.isNetworkUrl(urlOrFileOrScript) || URLUtil.isAssetUrl(urlOrFileOrScript)) {//url, http:// or https:// or asset://
164163
loadUrl(urlOrFileOrScript, sha256, callback);
165164
} else {
166165
loadFile(urlOrFileOrScript, callback);
@@ -182,12 +181,35 @@ public LuaViewCore loadUrl(final String url, final String sha256) {
182181
return loadUrl(url, sha256, null);
183182
}
184183

184+
185+
/**
186+
* load url
187+
*
188+
* @param url
189+
* @param sha256
190+
* @param callback
191+
* @return
192+
*/
185193
public LuaViewCore loadUrl(final String url, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) {
186194
updateUri(url);
187195
if (!TextUtils.isEmpty(url)) {
188-
new LuaScriptLoader(mContext).load(url, sha256, new LuaScriptLoader.ScriptLoaderCallback() {
196+
new LuaScriptLoader(mContext).load(url, sha256, new LuaScriptLoader.ScriptLoaderCallback2() {
197+
@Override
198+
public void onScriptDownloadStart() {//下载开始,不一定会调用,存在调用失败的情况
199+
if (callback instanceof LuaScriptLoader.ScriptExecuteCallback2) {
200+
((LuaScriptLoader.ScriptExecuteCallback2) callback).onScriptDownloadStart();
201+
}
202+
}
203+
189204
@Override
190-
public void onScriptLoaded(ScriptBundle bundle) {
205+
public void onScriptDownloadEnd(ScriptBundle bundle) {//下载完成,不一定会调用,如果调用的话,且packageName不为空的话,则onScriptLoaded加载的是Asset预置脚本
206+
if (callback instanceof LuaScriptLoader.ScriptExecuteCallback2) {
207+
((LuaScriptLoader.ScriptExecuteCallback2) callback).onScriptDownloadEnd(bundle);
208+
}
209+
}
210+
211+
@Override
212+
public void onScriptLoaded(ScriptBundle bundle) {//脚本本地 or Asset or 网络 准备成功
191213
if (callback == null || callback.onScriptPrepared(bundle) == false) {//脚本准备完成,且不第三方自己执行
192214
loadScriptBundle(bundle, callback);
193215
} else if (callback != null) {
@@ -511,6 +533,12 @@ public String getUri() {
511533
return null;
512534
}
513535

536+
public void setUri(String uri) {
537+
if (mGlobals != null && mGlobals.getLuaResourceFinder() != null) {
538+
mGlobals.getLuaResourceFinder().setUri(uri);
539+
}
540+
}
541+
514542
public Globals getGlobals() {
515543
return mGlobals;
516544
}

0 commit comments

Comments
 (0)