Adding internal Search function to Screnegraph Brightscript Channell

扶醉桌前 提交于 2020-04-30 11:22:49

问题


I need to add search functionality to my Brightscript scenegraph script for a Roku Channel. Does anyone have a simple Search sample, or a script I can use to add to a "sliding panel" Roku channel script?

RoSearch has been depreciated.

The current page is very similar to the Sliding Panel example.

Need working Search feature on my Roku Channel.

<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>

回答1:


first read following thinds : https://developer.roku.com/en-gb/docs/developer-program/discovery/search/implementing-search.md

these code for a search functionality. it applies static way.

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

this code writes in main.brs file

I hope this code is helpful.




回答2:


Most of the search screens in SceenGraph use a combination of MiniKeyboard with a combination of any type of list or grid, such are MarkupGrid. You add these component to your panels or a group component and manage the transition yourself.



来源:https://stackoverflow.com/questions/56502580/adding-internal-search-function-to-screnegraph-brightscript-channell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!