-- 设置为竖屏模式
activity.setRequestedOrientation(1)
读取颜色(随机色,随机色)

layout = {
    LinearLayout,
    orientation ='vertical',
    layout_width = 'fill',
    layout_height = 'fill',
    background = '#ffffff',
    {
        TextView,
        text = '我的主页',
        textSize = '20sp',
        textColor = '#333333',
        layout_gravity = "center|bottom",
        layout_marginTop = '35px',
    },
    {
        TextView,
        layout_width = '97.4%w',
        layout_height = '5px',
        layout_marginTop = '10dp',
        layout_marginBottom = '10dp',
        layout_gravity = 'center',
        backgroundColor = '#FFBEBEBE'
    },
    {
        GridView,
        id = "list",
        numColumns = 3,
        layout_width = 'fill',
        layout_height = 'fill',
        horizontalSpacing = "3dp",
        verticalSpacing = "0dp",
        layout_gravity = "center",
        OverScrollMode = 2
    }
}

webView.addView(loadlayout(layout))

function 布局边框(边框粗细, 边框颜色, 背景颜色, 圆角大小)
    import "android.graphics.drawable.GradientDrawable"
    drawable = GradientDrawable()
    drawable.setShape(GradientDrawable.RECTANGLE)
    drawable.setStroke(边框粗细, tonumber(边框颜色))
    drawable.setColor(tonumber(背景颜色))
    drawable.setCornerRadius(圆角大小)
    return drawable
end

item = {
    LinearLayout,
    layout_height = "48dp",
    layout_width = "fill",
    {
        LinearLayout,
        layout_height = "fill",
        layout_width = "fill",
        layout_margin = "5dp",
        BackgroundDrawable = 布局边框(4,0x66000000, 0x00000000, 15),
        {
            TextView,
            id = "name",
            layout_height = "fill",
            layout_width = "fill",
            gravity = "center",
            textColor = "#FF000000"
        },
        {
            TextView,
            id = "tools",
            layout_width = "0dp",
            layout_height = "0dp"
        },
        {
            TextView,
            id = "url",
            layout_width = "0dp",
            layout_height = "0dp"
        }
    }
}

adapter = LuaAdapter(activity, item)

function getToolsText(v)
    return v.Tag.tools and v.Tag.tools.text or ""
end

list.onItemClick = function(l, v, p, i)
    local toolsText = getToolsText(v)
    local urlText = v.Tag.url.text
     if urlText:find '://' then
       print("正在加载\n".. v.Tag.name.text)
        子页面('安卓',urlText)
    elseif toolsText:find 'diantong' then
        print ('预防误碰，请长按！')
    elseif toolsText:find 'zhinanzhen' then
        print ('预防误碰，请长按！')
    else
        WEB小程序(toolsText)
    end
end

list.onItemLongClick = function(l, v, p, i)
    if v.Tag.url.text:find '://' then
      if v.Tag.name.text:find '多功能工具' or v.Tag.name.text:find '本地' then
        print("软件内置工具，不支持使用系统默认浏览器打开😃！")
        return true
      end
        print("使用系统默认浏览器打开\n".. v.Tag.url.text)
        调用浏览器(v.Tag.url.text)
        return true
    elseif v.Tag.tools.text:find 'diantong' then
        手电筒()
        return true
    elseif v.Tag.tools.text:find 'zhinanzhen' then
        WEB小程序('zhinanzhen')
        return true
    else
        print ('暂时没有添加长按功能噢😃！')
        return true
    end
end

list.Adapter = adapter

local dataList = {
    -- tools相关数据
    {name = "更多应用", tools = "yingyong"},
    {name = "编辑器", tools = "bianjiqi1"},
    {name = "音乐播放器", tools = "music"},
    {name = "手电筒", tools = "diantong"},
    {name = "指南针", tools = "zhinanzhen"},
    -- url相关数据
    {name = "永硕网盘", url = "http://cgb0523.ysepan.com/"},
    {name = "本地搜索", url = "http://localhost:44444/jx/so/"},
    {name = "多功能工具", url = "file:///android_asset/index.html"},
    {name = "三维空间免费", url = "http://txcgb.web3v.work/dh/"},
    {name = "三维空间\nsan.txcgb.site", url = "http://san.txcgb.site/jx/so/"},
    {name = "web10301\nm.txcgb.site", url = "https://m.txcgb.site/jx/so/"},
    {name = "web10613\nmov.txcgb.site", url = "https://mov.txcgb.site/jx/so/"},
    {name = "三维空间\ntxcgb.v2free.cf", url = "http://txcgb.v2free.cf/jx/so/"},
    {name = "web10301\nyu.v2free.cf", url = "https://yu.v2free.cf/jx/so/"},
    {name = "web10613\nmov.v2free.cf", url = "https://mov.v2free.cf/jx/so/"}
}

for _, data in ipairs(dataList) do
    adapter.add(data)
end