我需要为Roku频道的Brightscript场景图脚本添加搜索功能。有没有人有一个简单的搜索示例,或者我可以用来添加到"滑动面板"Roku 通道脚本的脚本?
RoSearch 已折旧。
当前页面与滑动面板示例非常相似。
需要在我的 Roku 频道上工作搜索功能。
<component name = "minikeyboardexample" extends = "Group" initialFocus = "exampleMiniKeyboard" >
<script type="text/brightscript" >
<![CDATA[
sub init()
m.testlabel = m.top.FindNode("testLabel")
m.testpostergrid = m.top.FindNode("testPosterGrid")
m.testpostergridcontent = createObject("roSGNode","ContentNode")
m.readPosterGridTask = createObject("roSGNode","postergridCR")
m.readPosterGridTask.setField("postergriduri","http://test-xml.xml")
m.readPosterGridTask.observeField("gotitem","buildpostergrid")
m.readPosterGridTask.observeField("gotcontent","showpostergrid")
m.readPosterGridTask.control = "RUN"
m.top.setFocus(true)
end sub
sub buildpostergrid()
gridposter = createObject("roSGNode","ContentNode")
gridposter.hdgridposterurl = m.readPosterGridTask.hdgridposterurl
gridposter.hdposterurl = m.readPosterGridTask.hdposterurl
gridposter.sdgridposterurl = m.readPosterGridTask.sdgridposterurl
gridposter.sdposterurl = m.readPosterGridTask.sdposterurl
gridposter.shortdescriptionline1 = m.readPosterGridTask.shortdescriptionline1
gridposter.shortdescriptionline2 = m.readPosterGridTask.shortdescriptionline2
gridposter.x = m.readPosterGridTask.xposterpos
gridposter.y = m.readPosterGridTask.yposterpos
gridposter.w = m.readPosterGridTask.wnumcols
gridposter.h = m.readPosterGridTask.hnumrows
m.testpostergridcontent.appendChild(gridposter)
end sub
sub showpostergrid()
m.testlabel.text = "Here's the PosterGrid: "
m.testpostergrid.content=m.testpostergridcontent
m.testpostergrid.visible=true
m.testpostergrid.setFocus(true)
end sub
]]>
</script>
<children>
<MiniKeyboard id = "exampleMiniKeyboard" />
<Label id="testLabel" translation="[100,32]" text="Building PosterGrid... " />
<PosterGrid
id="testPosterGrid"
translation="[100,100]"
basePosterSize="[240,240]"
itemSpacing="[32,32]"
caption1NumLines="1"
caption2NumLines="1"
numColumns="4"
numRows="3"
/>
</children>
</component>
首先阅读以下 thinds : https://developer.roku.com/en-gb/docs/developer-program/discovery/search/implementing-search.md
这些代码用于搜索功能。它应用静态方式。
sub Main()
''Search Screen UI
'REM ******************************************************
'REM Main routine - example of search screen usage
'REM ******************************************************
print "start"
'toggle the search suggestions vs. search history behavior
'this allow you to generate both versions of the example below
displayHistory = false
history = CreateObject("roArray", 1, true)
'prepopulate the search history with sample results
history.Push("seinfeld")
history.Push("fraiser")
history.Push("cheers")
port = CreateObject("roMessagePort")
screen = CreateObject("roSearchScreen")
'commenting out SetBreadcrumbText() hides breadcrumb on screen
screen.SetBreadcrumbText("", "Search Channel")
screen.SetMessagePort(port)
if displayHistory
screen.SetSearchTermHeaderText("Recent Searches:")
screen.SetSearchButtonText("search")
screen.SetClearButtonText("clear history")
screen.SetClearButtonEnabled(true) 'defaults to true
screen.SetSearchTerms(history)
else
screen.SetSearchTermHeaderText("Suggestions:")
screen.SetSearchButtonText("search")
screen.SetClearButtonEnabled(false)
endif
print "Doing show screen..."
screen.Show()
print "Waiting for a message from the screen..."
' search screen main event loop
done = false
while done = false
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSearchScreenEvent"
if msg.isScreenClosed()
print "screen closed"
done = true
else if msg.isCleared()
print "search terms cleared"
history.Clear()
else if msg.isPartialResult()
print "partial search: "; msg.GetMessage()
if not displayHistory
screen.SetSearchTerms(GenerateSearchSuggestions(msg.GetMessage()))
endif
else if msg.isFullResult()
print "full search: "; msg.GetMessage()
history.Push(msg.GetMessage())
if displayHistory
screen.AddSearchTerm(msg.GetMessage())
end if
'uncomment to exit the screen after a full search result:
'done = true
else
print "Unknown event: "; msg.GetType(); " msg: "; sg.GetMessage()
endif
endif
endwhile
print "Exiting..."
End Sub
Function GenerateSearchSuggestions(partSearchText As String) As Object
availableContent = [
"ch1"
"ch2"
"ch3"
"ch4"
"ch5"
"ch6"
"ch7"
"ch8"
]
suggestions = []
if partSearchText <> ""
partSearchText = LCase(partSearchText)
for each available in availableContent
if available.Instr(partSearchText) >= 0
suggestions.Push(available)
end if
end for
end if
return suggestions
End Function
End sub
此代码写入 main.brs 文件
我希望这段代码对您有所帮助。
SceenGraph 中的大多数搜索屏幕都使用迷你键盘与任何类型的列表或网格的组合,例如 MarkupGrid。您可以将这些组件添加到面板或组组件中,并自行管理过渡。