I am creating a POC for simple search functionality in my channel. I am able to Show the search popup as required when I am pressing ok on the input area of search screen it is showing the keyboard screen according to expectation.
But when I am closing the keyboard by pressing Ok or Cancel button the Keyboard screen doesn't close. I just go at back of the search screen and when I close the search screen it closes the keyboard screen.
To sea the behaviour I have just make 2 more methods for showKeyboard
showKeyboard2() and showKeyboard3()
and I am surprise when I call them in place of showKeyboard() like:
when I call showKeyboard2() method it never shows the keyboard which is absolutely correct behaviour
but when I call showKeyboard3() it opens the keyboard but after 5 seconds it again takes the keyboard in back of the search in place of closing it.
Please have a look of my code I am giving with this post and suggest that what should I do to close the keyboard successfully.
Function Main()
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
list = []
list.push({Color:"#FFFFFF", CompossionMode:"Source"})
list.push({
Text:"Press OK to show Search Screen",
TextAttrs:{color:"#000000", font:"Medium", HAlign:"Left",VAlign:"Top", Direction:"LeftToRight"},
TargetRect:{x:300, y:100, w:500, h:40}
})
canvas.SetLayer(0, list)
canvas.show()
while true
msg = wait(0, port)
if(Type(msg) = "roImageCanvasEvent")
if(msg.IsremoteKeyPressed())
index = msg.GetIndex()
if(index = 6) 'OK key pressed
showSearchPopupScreen("Title")
end if
else if(msg.IsScreenClossed())
end if
else
print "Unexpected Event."
end if
end while
End Function
function showSearchPopupScreen(searchType as String)
selectedRow = 0
REM** Show Lower opacity background screen
facadeCanvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
facadeCanvas.SetMessagePort(port)
facadeCanvas.SetLayer(0, {Color:"#99000000", CompossionMode:"Source_Over"})
facadeCanvas.show()
REM ** Show the SearchPopupScreen
popupCanvas = CreateObject("roImageCanvas")
popupCanvas.SetMessagePort(port)
popupCanvas.AllowUpdates(false)
list = []
list.push({
url:"pkg:/images/HD/canvasBack.png",
TargetRect:{x:240, y:210, w:700, h:300}
})
list.push({
Text:"Enter " + searchType + " Name:",
TextAttrs:{color:"#000000", font:"Medium", HAlign:"Left",VAlign:"Top", Direction:"LeftToRight"},
TargetRect:{x:300, y:250, w:500, h:40}
})
list.push({
url:"pkg:/images/HD/input_text_bg.png",
TargetRect:{x:390, y:300, w:400, h:70}
})
list.push({
url:"pkg:/images/HD/ok.png",
TargetRect:{x:515, y:400, w:150, h:55}
})
popupCanvas.SetLayer(0, list)
popupCanvas.SetLayer(1, {url:"pkg:/images/HD/input_text_bg_hover.png", TargetRect:{x:390, y:300, w:400, h:70}})
popupCanvas.AllowUpdates(true)
popupCanvas.show()
while true
msg = wait(0, port)
if(Type(msg) = "roImageCanvasEvent")
if(msg.IsremoteKeyPressed())
index = msg.GetIndex()
if(index = 0) 'Back key pressed
return -1
else if(index = 2) 'Up key pressed
print "popup canvas Up key pressed."
if(selectedRow = 1)
popupCanvas.SetLayer(1, {url:"pkg:/images/HD/input_text_bg_hover.png", TargetRect:{x:390, y:300, w:400, h:70}})
selectedRow = 0
end if
else if(index = 3) 'Down key pressed
print "popup canvas Up key pressed."
if(selectedRow = 0)
popupCanvas.SetLayer(1, {url:"pkg:/images/HD/hover.png", TargetRect:{x:515, y:400, w:150, h:55}})
selectedRow = 1
end if
else if(index = 4) 'Left move
else if(index = 5) 'Right move
else if(index = 6)
print "Selected Row: "selectedRow
'result = showKeyboard()
'result = showKeyboard2()
result = showKeyboard3()
end if
else if(msg.IsScreenClosed())
return -1
end if
else
showPopupScreen()
end if
end while
end function
function showKeyboard() as Dynamic
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
screen.SetDisplayText("Enter Director Name")
screen.setSecureText(false)
screen.AddButton(1, "Ok")
screen.AddButton(2, "Cancel")
screen.Show()
result = invalid
while true
msg = wait(0, port)
if type(msg) = "roKeyboardScreenEvent"
print "KeyBoard Event: "
print Type(msg)
print msg
if (msg.isScreenClosed())
print "Comes into isScreenClosed event of KeyboardScreen.."
exit while
else if (msg.isButtonPressed())
if msg.GetIndex() = 1
print "Text Entered: " screen.GetText()
if(screen.GetText().trim() <> "")
result = screen.GetText()
exit while
else
dialog = CreateObject("roMessageDialog")
dialog.SetMessagePort(screen.GetMessagePort())
dialog.SetTitle("Alert!!")
dialog.SetText("Field cannot be empty.")
dialog.AddButton(1, "Ok")
dialog.EnableBackButton(true)
dialog.Show()
end if
else if msg.GetIndex() = 2
exit while
end if
end if
else if type(msg) = "roMessageDialogEvent"
if (msg.isButtonPressed())
if (msg.GetIndex() = 1)
dialog.close()
end if
else if (msg.isScreenClosed())
dialog.close()
end if
else
print "Un-expected event"
end if
end while
screen.close()
return result
end function
function showKeyboard2() as Dynamic
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
screen.SetDisplayText("Enter Director Name")
screen.setSecureText(false)
screen.AddButton(1, "Ok")
screen.AddButton(2, "Cancel")
screen.Show()
screen.close()
return ""
end function
function showKeyboard3() as Dynamic
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
screen.SetDisplayText("Enter Director Name")
screen.setSecureText(false)
screen.AddButton(1, "Ok")
screen.AddButton(2, "Cancel")
screen.Show()
sleep(5000)
screen.close()
return ""
end function