require "import"
import "android.widget.*"
import "android.view.*"
local txt,a=service.getText(node),2
local t1,t2,t3,t4,t11,t21={},{},{},{},{},{}
for n=1,utf8.len(txt),1 do
if "。"==utf8.sub(txt,n,n)
j=utf8.sub(txt,n,n+20)
table.insert(t11,n)
table.insert(t1,n..j)
end
if ","==utf8.sub(txt,n,n)d=utf8.sub(txt,n,n+20)
table.insert(t21,n)
table.insert(t2,n..d)
end
if "\n"==utf8.sub(txt,n,n)
h=utf8.sub(txt,n,n+20)
table.insert(t3,a.."行"..h.."位置在"..n)
a=a+1
table.insert(t4,n)
end
end
layout=
{
LinearLayout,
orientation=1,
layout_width=-1,
layout_height=-1,
{
EditText,
hint="输入数字",
HintTextColor='#ff00ffff',
id="edit",
Gravity="center_horizontal",
textColor="#ff00ffff",
layout_width=-1,
layout_height="10%h",
layout_weight=1,
inputType="number"
},
{
EditText,
hint="输入关键字",
HintTextColor='#ff00ffff',
id="e2",
Gravity="center_horizontal",
textColor="#ff00ffff",
layout_width=-1,
layout_height="10%h",
layout_weight=1,
},
{Button,
text="光标跳转,共"..utf8.len(txt).."个字",
onClick="gbtz",
textColor="#ff00ffff",
layout_width=-1,
layout_height="10%h",
layout_weight=1,},
{Button,
text="逗号跳转"..string.format("共%d个逗号",#t2),
onClick="tzdh",
textColor="#ff00ffff",
layout_width=-1,
layout_weight=1,},
{Button,
text="句号跳转"..string.format("共%d个句号",#t1),
onClick="tzjh",
textColor="#ff00ffff",
layout_width=-1,
layout_weight=1,},
{Button,
text="按行跳转"..string.format("共%d行",#t4+1),
onClick="tzh",
textColor="#ff00ffff",
layout_width=-1,
layout_weight=1,},
{Button,
text="自定义跳转",
onClick="zdytz",
textColor="#ff00ffff",
layout_width=-1,
layout_weight=1,},
}
dlg=LuaDialog()
.setView(loadlayout(layout))
.show()
function gbtz()
dlg.hide()
if edit.text==""
print("请输入数字")
else
service.setSelection(node,tonumber(edit.text))
end
end
function tzdh()
dlg.hide()
require"import"
dlg=LuaDialog()
dlg.setTitle(string.format("共%d个逗号",#t2))
dlg.setItems(t2)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.setSelection(node,tonumber(t21))
end
end
function tzjh()
dlg.hide()
require"import"
dlg=LuaDialog()
dlg.setTitle(string.format("共%d个句号",#t1))
dlg.setItems(t1)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.setSelection(node,tonumber(t11))
end
end
function tzh()
dlg.hide()
require"import"
dlg=LuaDialog()
dlg.setTitle(string.format("共%d行",#t4+1))
dlg.setItems(t3)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.setSelection(node,tonumber(t4))
end
end
function zdytz()
dlg.hide()
require"import"
local t5,t51={},{}
for n=1,utf8.len(txt),1 do
if e2.text==utf8.sub(txt,n,n)
z=utf8.sub(txt,n,n+20)
table.insert(t5,n..z)
table.insert(t51,n)
end
end
local dlg=LuaDialog()
dlg.setTitle(string.format("共%d个",#t5))
dlg.setItems(t5)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.setSelection(node,tonumber(t51))
end
end
return true
来自解说社区客户端 |