Search in sources :

Example 26 with LuaValue

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));
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable)

Example 27 with LuaValue

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);
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaFunction(org.luaj.vm2.LuaFunction)

Example 28 with LuaValue

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;
}
Also used : Globals(org.luaj.vm2.Globals) UDLuaTable(com.taobao.luaview.userdata.base.UDLuaTable) UDViewGroup(com.taobao.luaview.userdata.ui.UDViewGroup) LVViewGroup(com.taobao.luaview.view.LVViewGroup) ILVView(com.taobao.luaview.view.interfaces.ILVView) HorizontalScrollView(android.widget.HorizontalScrollView) UDView(com.taobao.luaview.userdata.ui.UDView) View(android.view.View)

Example 29 with LuaValue

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);
        }
    }
}
Also used : LuaValue(org.luaj.vm2.LuaValue) ILVView(com.taobao.luaview.view.interfaces.ILVView) HorizontalScrollView(android.widget.HorizontalScrollView) UDView(com.taobao.luaview.userdata.ui.UDView) View(android.view.View)

Example 30 with LuaValue

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;
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Aggregations

LuaValue (org.luaj.vm2.LuaValue)55 LuaTable (org.luaj.vm2.LuaTable)37 Varargs (org.luaj.vm2.Varargs)12 LuaString (org.luaj.vm2.LuaString)9 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)7 UDView (com.taobao.luaview.userdata.ui.UDView)6 LuaError (org.luaj.vm2.LuaError)6 LuaFunction (org.luaj.vm2.LuaFunction)6 View (android.view.View)4 Point (android.graphics.Point)3 ILVView (com.taobao.luaview.view.interfaces.ILVView)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 HorizontalScrollView (android.widget.HorizontalScrollView)2 AerospikeException (com.aerospike.client.AerospikeException)2 LuaViewApi (com.taobao.luaview.fun.mapper.LuaViewApi)2 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2