use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class VibratorMethodMapper method vibrate.
/**
* 开始震动
*
* @param vibrator
* @param varargs
* @return
*/
public LuaValue vibrate(U vibrator, Varargs varargs) {
if (varargs.narg() > 2 || (varargs.narg() > 1 && varargs.istable(2))) {
final LuaTable luaTable = LuaUtil.getTable(varargs, 2);
final Integer repeat = LuaUtil.toJavaInt(varargs.arg(3));
return vibrator.vibrate(luaTable, repeat);
} else {
final Double time = LuaUtil.getDouble(varargs, 2);
return vibrator.vibrate((long) (time != null ? time * DateUtil.ONE_SECOND : DateUtil.ONE_SECOND));
}
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class HttpMethodMapper method post.
/**
* pos 请求
*
* @param http
* @param varargs
* @return
*/
public LuaValue post(U http, Varargs varargs) {
final String url = LuaUtil.getString(varargs, 2);
final LuaTable params = LuaUtil.getTable(varargs, 3, 2);
final LuaFunction callback = LuaUtil.getFunction(varargs, 4, 3, 2);
return http.post(url, params, callback);
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class LVCustomViewPagerIndicator method createView.
/**
* create view
*
* @param pos
* @return
*/
private LuaValue createView(int pos, int currentItem) {
Globals globals = this.mLuaUserdata.getGlobals();
// View封装
final LVViewGroup container = createCellLayout();
final UDViewGroup cell = new UDViewGroup(container, globals, null);
// 对外数据封装,必须使用LuaTable
final UDLuaTable cellData = new UDLuaTable(cell);
// call init
globals.saveContainer(container);
// 初始化
this.mLuaUserdata.callCellInit(cellData, pos, currentItem);
globals.restoreContainer();
// set tag
View view = cellData.getView();
if (view != null) {
view.setTag(Constants.RES_LV_TAG, cellData);
}
return cellData;
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class LVCustomViewPagerIndicator method setCurrentItem.
@Override
public void setCurrentItem(int item) {
if (mViewPager == null) {
throw new IllegalStateException("ViewPager has not been bound.");
}
mSelectedIndex = item;
mViewPager.setCurrentItem(item);
int tabCount = mLayout.getChildCount();
for (int i = 0; i < tabCount; i++) {
View child = mLayout.getChildAt(i);
boolean isSelected = (i == item);
child.setSelected(isSelected);
if (isSelected) {
animateTo(item);
}
// TODO 这里需要优化一下,实现的太低效,有bug
Object obj = child.getTag(Constants.RES_LV_TAG);
if (obj instanceof LuaValue) {
LuaValue cellData = (LuaValue) obj;
// 绘制
mLuaUserdata.callCellLayout(cellData, i, item);
}
}
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class GlobalsExtender method doLoad.
/**
* 真正地加载一个库
*
* @param globals
* @param p
*/
public boolean doLoad(final Globals globals, Prototype p) {
boolean isAnyLoaded = false;
if (p != null && p.k != null && p.k.length > 0) {
StringBuffer sb = new StringBuffer();
for (LuaValue name : p.k) {
if (LuaUtil.isString(name)) {
sb.append(name).append(" ");
isAnyLoaded = (doLoad(globals, name.checkjstring()) != null) || isAnyLoaded;
}
}
}
return isAnyLoaded;
}
Aggregations