Search in sources :

Example 16 with Varargs

use of org.luaj.vm2.Varargs in project LuaViewSDK by alibaba.

the class UIImageViewMethodMapper method startAnimationImages.

/**
 * 开始帧动画
 *
 * @param view
 * @param varargs 时间是秒而不是毫秒
 * @return
 */
@Deprecated
public LuaValue startAnimationImages(U view, Varargs varargs) {
    // TODO 支持UDImageView和UDBitmap
    final LuaTable imagesTable = varargs.opttable(2, null);
    final double duration = varargs.optdouble(3, 1f);
    boolean repeat = false;
    if (varargs.isnumber(4)) {
        repeat = varargs.optint(4, -1) > 0;
    } else {
        repeat = varargs.optboolean(4, false);
    }
    if (imagesTable != null && imagesTable.length() > 0) {
        final String[] images = new String[imagesTable.length()];
        int i = 0;
        for (LuaValue key : imagesTable.keys()) {
            images[i++] = imagesTable.get(key).optjstring(null);
        }
        return view.startAnimationImages(images, (int) duration * 1000, repeat);
    }
    return view;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaValue(org.luaj.vm2.LuaValue)

Example 17 with Varargs

use of org.luaj.vm2.Varargs in project LuaViewSDK by alibaba.

the class UIViewGroupMethodMapper method flexChildren.

/**
 * Flexbox 设置childViews
 *
 * @param view
 * @param varargs
 * @return
 */
public LuaValue flexChildren(U view, Varargs varargs) {
    ArrayList<UDView> flexChildren = new ArrayList<UDView>();
    LuaValue children = varargs.arg(2);
    if (children != null && children instanceof LuaTable) {
        // 子节点以一个表的形式作为参数传入
        for (int i = 0; i <= children.length(); i++) {
            LuaValue luaValue = children.get(i + 1);
            if (luaValue != null && luaValue instanceof UDView) {
                flexChildren.add((UDView) luaValue);
            }
        }
    } else {
        for (int i = 2; i <= varargs.narg(); i++) {
            LuaValue luaValue = varargs.optvalue(i, null);
            if (luaValue != null && luaValue instanceof UDView) {
                flexChildren.add((UDView) luaValue);
            }
        }
    }
    view.setChildNodeViews(flexChildren);
    return view;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) UDView(com.taobao.luaview.userdata.ui.UDView) ArrayList(java.util.ArrayList) LuaValue(org.luaj.vm2.LuaValue)

Example 18 with Varargs

use of org.luaj.vm2.Varargs in project LuaViewSDK by alibaba.

the class UIViewGroupMethodMapper method addView.

/**
 * 添加子类
 *
 * @param view
 * @param varargs
 * @return
 */
public LuaValue addView(U view, Varargs varargs) {
    final LuaValue luaValue = varargs.optvalue(2, null);
    final Integer pos = LuaUtil.getInt(varargs, 3);
    if (luaValue instanceof UDView) {
        return view.addView((UDView) luaValue, pos);
    }
    return view;
}
Also used : UDView(com.taobao.luaview.userdata.ui.UDView) LuaValue(org.luaj.vm2.LuaValue)

Example 19 with Varargs

use of org.luaj.vm2.Varargs in project LuaViewSDK by alibaba.

the class BitmapMethodMapper method sprite.

// --------------------------------------- API --------------------------------------------------
/**
 * 切割bitmap
 *
 * @param bitmap
 * @param varargs
 * @return
 */
public LuaValue sprite(U bitmap, Varargs varargs) {
    final int x = DimenUtil.dpiToPx(varargs.arg(2));
    final int y = DimenUtil.dpiToPx(varargs.arg(3));
    final int width = DimenUtil.dpiToPx(varargs.arg(4));
    final int height = DimenUtil.dpiToPx(varargs.arg(5));
    final LuaFunction callback = LuaUtil.getFunction(varargs, 6);
    return bitmap.sprite(x, y, width, height, callback);
}
Also used : LuaFunction(org.luaj.vm2.LuaFunction)

Example 20 with Varargs

use of org.luaj.vm2.Varargs in project LuaViewSDK by alibaba.

the class LuaUtil method getValue.

/**
 * get value of given type, from varargs in position [poslist]
 *
 * @param type
 * @param varargs
 * @param poslist
 * @return
 */
private static Object getValue(final int type, final Varargs varargs, Object defaultValue, int... poslist) {
    Object result = null;
    if (varargs != null) {
        if (poslist != null && poslist.length > 0) {
            LuaValue value = null;
            for (int i = 0; i < poslist.length; i++) {
                if (varargs.narg() >= poslist[i]) {
                    value = varargs.arg(poslist[i]);
                    result = parseValue(type, value);
                }
                if (result != null) {
                    break;
                }
            }
        }
    }
    return result != null ? result : defaultValue;
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Aggregations

Varargs (org.luaj.vm2.Varargs)24 LuaTable (org.luaj.vm2.LuaTable)22 LuaValue (org.luaj.vm2.LuaValue)20 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)16 LuaString (org.luaj.vm2.LuaString)10 LuaFunction (org.luaj.vm2.LuaFunction)5 LuaViewApi (com.taobao.luaview.fun.mapper.LuaViewApi)2 UDView (com.taobao.luaview.userdata.ui.UDView)2 List (java.util.List)2 LuanObjImage (net.schattenkind.androidLove.luan.obj.LuanObjImage)2 Buffer (org.luaj.vm2.Buffer)2 LuaThread (org.luaj.vm2.LuaThread)2 Point (android.graphics.Point)1 Sensor (android.hardware.Sensor)1 SoundPool (android.media.SoundPool)1 UDBitmap (com.taobao.luaview.userdata.kit.UDBitmap)1 UDData (com.taobao.luaview.userdata.kit.UDData)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1