Search in sources :

Example 16 with LuaTable

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

the class LuaViewManager method createMetatable.

//-----------------------------------------metatable--------------------------------------------
/**
     * create metatable for libs
     *
     * @return
     */
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
    //get from cache
    LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);
    if (result == null) {
        LuaTable libTable = null;
        if (LuaViewConfig.isUseNoReflection()) {
            final List<String> methodNames = getMapperMethodNames(libClass);
            libTable = LuaViewManager.bind(libClass, methodNames);
        } else {
            final List<Method> methods = getMapperMethods(libClass);
            libTable = LuaViewManager.bindMethods(libClass, methods);
        }
        result = LuaValue.tableOf(new LuaValue[] { LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable) });
        //update cache
        AppCache.getCache(CACHE_METATABLES).put(libClass, result);
    }
    return result;
}
Also used : NewIndexFunction(com.taobao.luaview.fun.mapper.ui.NewIndexFunction) LuaTable(org.luaj.vm2.LuaTable) Method(java.lang.reflect.Method) LuaValue(org.luaj.vm2.LuaValue)

Example 17 with LuaTable

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

the class UDCanvas method getDefaultPaint.

private Paint getDefaultPaint(LuaValue config) {
    if (mPaint == null) {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }
    //config
    if (config instanceof LuaTable) {
        mPaint.reset();
        final LuaValue[] keys = ((LuaTable) config).keys();
        if (keys != null && keys.length > 0) {
            String key;
            LuaValue value;
            for (int i = 0; i < keys.length; i++) {
                if (LuaUtil.isString(keys[i])) {
                    key = keys[i].optjstring(null);
                    if (!TextUtils.isEmpty(key)) {
                        key = key.toLowerCase();
                        value = config.get(keys[i]);
                        if (LuaUtil.isValid(value)) {
                            Integer pos = sPaintAttrIndex.get(key);
                            if (pos == null) {
                                continue;
                            }
                            switch(pos) {
                                case PAINT_COLOR:
                                    mPaint.setColor(ColorUtil.parse(value));
                                    break;
                                case PAINT_ALPHA:
                                    mPaint.setAlpha(LuaUtil.toAlphaInt(value));
                                    break;
                                case PAINT_STROKE_WIDTH:
                                    mPaint.setStrokeWidth(DimenUtil.dpiToPxF((float) value.optdouble(0)));
                                    break;
                                case PAINT_TEXT_SIZE:
                                    mPaint.setTextSize(DimenUtil.spToPx((float) value.optdouble(12.0f)));
                                    break;
                                case PAINT_UNDERLINE:
                                    mPaint.setUnderlineText(value.optboolean(false));
                                    break;
                                case PAINT_STRIKE_THROUGH:
                                    mPaint.setStrikeThruText(value.optboolean(false));
                                    break;
                                case PAINT_BOLD:
                                    mPaint.setFakeBoldText(value.optboolean(false));
                                    break;
                                case PAINT_LETTER_SPACING:
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        mPaint.setLetterSpacing(DimenUtil.dpiToPxF((float) value.optdouble(0)));
                                    }
                                    break;
                                case PAINT_TYPEFACE:
                                    {
                                        String typeface = value.optjstring(null);
                                        if (!TextUtils.isEmpty(typeface)) {
                                            mPaint.setTypeface(getLuaResourceFinder().findTypeface(typeface));
                                        }
                                        break;
                                    }
                                case PAINT_TEXT_SCALE_X:
                                    mPaint.setTextScaleX((float) value.optdouble(1));
                                    break;
                                case PAINT_TEXT_SKEW_X:
                                    mPaint.setTextSkewX((float) value.optdouble(0));
                                    break;
                                case PAINT_LINEAR_TEXT:
                                    mPaint.setLinearText(value.optboolean(false));
                                    break;
                                case PAINT_TEXT_ALIGN:
                                    {
                                        setPaintTextAlign(value);
                                        break;
                                    }
                                case PAINT_STYLE:
                                    {
                                        setPaintStyle(value);
                                        break;
                                    }
                                case PAINT_FILTER_BITMAP:
                                    mPaint.setFilterBitmap(value.optboolean(false));
                                    break;
                            }
                        }
                    }
                }
            }
        }
        //anti alias
        mPaint.setAntiAlias(true);
    }
    return mPaint;
}
Also used : BaseLuaTable(com.taobao.luaview.userdata.base.BaseLuaTable) LuaTable(org.luaj.vm2.LuaTable) Paint(android.graphics.Paint) LuaValue(org.luaj.vm2.LuaValue) Paint(android.graphics.Paint)

Example 18 with LuaTable

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

the class UDHttp method initVarargs.

/**
     * 初始化数据
     */
private void initVarargs() {
    final LuaValue param1 = getInitParam1();
    final LuaFunction callback = LuaUtil.getFunction(initParams, 2);
    final String method = LuaUtil.getString(param1, "method");
    final LuaTable params = LuaUtil.getTable(param1, "params");
    setMethod(method);
    setParams(params);
    setCallback(callback);
    disableConnectionReuseIfNecessary();
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaValue(org.luaj.vm2.LuaValue) LuaFunction(org.luaj.vm2.LuaFunction)

Example 19 with LuaTable

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

the class UDHttpResponse method toTable.

/**
     * convert response to LuaTable
     *
     * @return
     */
public LuaTable toTable() {
    LuaTable result = new LuaTable();
    result.set("data", new UDData(getGlobals(), getmetatable(), null).append(mData));
    result.set("code", LuaValue.valueOf(mStatusCode));
    result.set("header", LuaUtil.toTable(mHeaders));
    result.set("message", LuaValue.valueOf(mResponseMsg));
    return result;
}
Also used : BaseLuaTable(com.taobao.luaview.userdata.base.BaseLuaTable) LuaTable(org.luaj.vm2.LuaTable) UDData(com.taobao.luaview.userdata.kit.UDData)

Example 20 with LuaTable

use of org.luaj.vm2.LuaTable 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)

Aggregations

LuaTable (org.luaj.vm2.LuaTable)54 LuaValue (org.luaj.vm2.LuaValue)19 Varargs (org.luaj.vm2.Varargs)16 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)15 LuaError (org.luaj.vm2.LuaError)5 LuaFunction (org.luaj.vm2.LuaFunction)4 View (android.view.View)3 JSONObject (org.json.JSONObject)3 LibFunction (org.luaj.vm2.lib.LibFunction)3 BaseLuaTable (com.taobao.luaview.userdata.base.BaseLuaTable)2 UDView (com.taobao.luaview.userdata.ui.UDView)2 ILVView (com.taobao.luaview.view.interfaces.ILVView)2 List (java.util.List)2 LuanObjImage (net.schattenkind.androidLove.luan.obj.LuanObjImage)2 LuaString (org.luaj.vm2.LuaString)2 Paint (android.graphics.Paint)1 Sensor (android.hardware.Sensor)1 SoundPool (android.media.SoundPool)1 MotionEvent (android.view.MotionEvent)1 ViewGroup (android.view.ViewGroup)1