HMS

Home Media Server for Roku Players
git clone https://www.brianlane.com/git/HMS
Log | Files | Refs | README | LICENSE

generalDlgs.brs (4674B)


      1 '**********************************************************
      2 '**  Video Player Example Application - General Dialogs 
      3 '**  November 2009
      4 '**  Copyright (c) 2009 Roku Inc. All Rights Reserved.
      5 '**********************************************************
      6 
      7 '******************************************************
      8 'Show basic message dialog without buttons
      9 'Dialog remains up until caller releases the returned object
     10 '******************************************************
     11 
     12 Function ShowPleaseWait(title As dynamic, text As dynamic) As Object
     13     if not isstr(title) title = ""
     14     if not isstr(text) text = ""
     15 
     16     port = CreateObject("roMessagePort")
     17     dialog = invalid
     18 
     19     'the OneLineDialog renders a single line of text better
     20     'than the MessageDialog.
     21     if text = ""
     22         dialog = CreateObject("roOneLineDialog")
     23     else
     24         dialog = CreateObject("roMessageDialog")
     25         dialog.SetText(text)
     26     endif
     27 
     28     dialog.SetMessagePort(port)
     29 
     30     dialog.SetTitle(title)
     31     dialog.ShowBusyAnimation()
     32     dialog.Show()
     33     return dialog
     34 End Function
     35 
     36 '******************************************************
     37 'Retrieve text for connection failed
     38 '******************************************************
     39 
     40 Function GetConnectionFailedText() as String
     41     return "We were unable to connect to the service.  Please try again in a few minutes."
     42 End Function
     43 
     44 '******************************************************
     45 'Show connection error dialog
     46 '
     47 'Parameter: retry t/f - offer retry option
     48 'Return 0 = retry, 1 = back
     49 '******************************************************
     50 
     51 Function ShowConnectionFailedRetry() as dynamic
     52     Dbg("Connection Failed Retry")
     53     title = "Can't connect to video service"
     54     text  = GetConnectionFailedText()
     55     return ShowDialog2Buttons(title, text, "try again", "back")
     56 End Function
     57 
     58 '******************************************************
     59 'Show Amzon connection error dialog with only an OK button
     60 '******************************************************
     61 
     62 Sub ShowConnectionFailed()
     63     Dbg("Connection Failed")
     64     title = "Can't connect to video service"
     65     text  = GetConnectionFailedText()
     66     ShowErrorDialog(text, title)
     67 End Sub
     68 
     69 '******************************************************
     70 'Show error dialog with OK button
     71 '******************************************************
     72 
     73 Sub ShowErrorDialog(text As dynamic, title=invalid as dynamic)
     74     if not isstr(text) text = "Unspecified error"
     75     if not isstr(title) title = ""
     76     ShowDialog1Button(title, text, "Done")
     77 End Sub
     78 
     79 '******************************************************
     80 'Show 1 button dialog
     81 'Return: nothing
     82 '******************************************************
     83 
     84 Sub ShowDialog1Button(title As dynamic, text As dynamic, but1 As String)
     85     if not isstr(title) title = ""
     86     if not isstr(text) text = ""
     87 
     88     Dbg("DIALOG1: ", title + " - " + text)
     89 
     90     port = CreateObject("roMessagePort")
     91     dialog = CreateObject("roMessageDialog")
     92     dialog.SetMessagePort(port)
     93 
     94     dialog.SetTitle(title)
     95     dialog.SetText(text)
     96     dialog.AddButton(0, but1)
     97     dialog.Show()
     98 
     99     while true
    100         dlgMsg = wait(0, dialog.GetMessagePort())
    101 
    102         if type(dlgMsg) = "roMessageDialogEvent"
    103             if dlgMsg.isScreenClosed()
    104                 print "Screen closed"
    105                 return
    106             else if dlgMsg.isButtonPressed()
    107                 print "Button pressed: "; dlgMsg.GetIndex(); " " dlgMsg.GetData()
    108                 return
    109             endif
    110         endif
    111     end while
    112 End Sub
    113 
    114 '******************************************************
    115 'Show 2 button dialog
    116 'Return: 0=first button or screen closed, 1=second button
    117 '******************************************************
    118 
    119 Function ShowDialog2Buttons(title As dynamic, text As dynamic, but1 As String, but2 As String) As Integer
    120     if not isstr(title) title = ""
    121     if not isstr(text) text = ""
    122 
    123     Dbg("DIALOG2: ", title + " - " + text)
    124 
    125     port = CreateObject("roMessagePort")
    126     dialog = CreateObject("roMessageDialog")
    127     dialog.SetMessagePort(port)
    128 
    129     dialog.SetTitle(title)
    130     dialog.SetText(text)
    131     dialog.AddButton(0, but1)
    132     dialog.AddButton(1, but2)
    133     dialog.Show()
    134 
    135     while true
    136         dlgMsg = wait(0, dialog.GetMessagePort())
    137 
    138         if type(dlgMsg) = "roMessageDialogEvent"
    139             if dlgMsg.isScreenClosed()
    140                 print "Screen closed"
    141                 dialog = invalid
    142                 return 0
    143             else if dlgMsg.isButtonPressed()
    144                 print "Button pressed: "; dlgMsg.GetIndex(); " " dlgMsg.GetData()
    145                 dialog = invalid
    146                 return dlgMsg.GetIndex()
    147             endif
    148         endif
    149     end while
    150 End Function