Ejemplo de uso de webview
Demostración
local html = [=[
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!DOCTYPE html>
<html>
<head>
<script src="/js/jquery.min.js"></script>
<script src="/js/jquery.json.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#toast_content").val("toast内容");
$("#close_page").click(function(){
$.post(
"/proc_queue_push",
'{"key": "来自webview的消息","value": "关闭页面"}',
function(){}
);
});
$("#show_toast").click(function(){
$.post(
"/proc_put",
$.toJSON({
key:"toast内容",
value:$("#toast_content").val()
}),
function(){}
);
$.post(
"/proc_queue_push",
'{"key": "来自webview的消息","value": "显示toast"}',
function(){}
);
});
$("#slide_down").click(function(){
$.post(
"/proc_queue_push",
'{"key": "来自webview的消息","value": "往下滑动"}',
function(){}
);
$(this).hide();
});
$("#full_vertical").click(function(){
$.post(
"/proc_queue_push",
'{"key": "来自webview的消息","value": "竖屏全屏"}',
function(){}
);
});
$("#full_landscape").click(function(){
$.post(
"/proc_queue_push",
'{"key": "来自webview的消息","value": "横屏全屏"}',
function(){}
);
});
});
</script>
</head>
<body>
<p>XXTouch WebView 演示</p>
<p><button id="close_page" type="button">点我关闭页面</button></p>
<p><button id="show_toast" type="button">显示一个toast</button><input type="text" id="toast_content" /></p>
<p><button id="full_vertical" type="button">竖屏全屏</button><button id="full_landscape" type="button">横屏全屏</button></p>
<p><button id="slide_down" type="button">视图往下滑动</button></p>
<select>
<option value="o1">第1个选项</option>
<option value="o2">第2个选项</option>
<option value="o3">第3个选项</option>
<option value="o4">第4个选项</option>
</select>
</body>
</html>
]=]
--
local w, h = screen.size()
local factor = screen.scale_factor()
--
webview.show{ -- restablecer la posición del webview en la esquina superior izquierda
x = 0,
y = 0,
width = w - 40 * factor,
height = (500) * factor,
alpha = 0,
animation_duration = 0,
}
--
webview.show{ -- deslizarlo desde la esquina superior izquierda en 0.3 segundos
html = html,
x = 20 * factor,
y = 50 * factor,
width = (w - 40 * factor),
height = (500) * factor,
corner_radius = 10,
alpha = 0.7,
animation_duration = 0.3,
}
--
proc_queue_clear("来自webview的消息", "") -- vaciar el valor del diccionario que se debe supervisar
local eid = thread.register_event( -- registrar el evento de que el diccionario supervisado tiene un valor
"来自webview的消息",
function(val)
if val == "关闭页面" then
webview.show{
x = 20 * factor,
y = 500 * factor * 2,
width = (w - 40 * factor),
height = (500 - 70) * factor,
corner_radius = 10,
alpha = 0,
animation_duration = 0.8,
}
sys.msleep(800)
webview.destroy()
sys.toast("页面线程结束")
return true -- devolver true para detener la supervisión actual
elseif val == "往下滑动" then
webview.show{
x = 20 * factor,
y = (50 + 300) * factor, -- coordenada vertical + 300
width = (w - 40 * factor),
height = (500 - 70) * factor, -- el botón de deslizar hacia abajo está oculto; ajustar la altura
corner_radius = 10,
alpha = 0.7,
animation_duration = 0.5, -- duración de 0.5 segundos
}
elseif val == "竖屏全屏" then
webview.show{} -- aquí el webview pasa a pantalla completa
elseif val == "横屏全屏" then
webview.show{rotate=90} -- aquí el webview pasa a pantalla completa horizontal
elseif val == "显示toast" then
sys.toast(proc_get("toast内容"))
end
end
)
--
sys.msleep(3000)
sys.toast("主线程结束")
Nota: el código anterior utiliza las funciones screen.size, proc_queue_clear, thread.register_event, proc_get, sys.toast y sys.msleep, que no pertenecen a este capítulo.