! Numeric Input for the html
! by Antonis June 2012
! Required file: numkeyb.html 

! stay a little in the console screen
for i=3 to 0 step -1
 print "Going to graphics screen after ";
 print replace$(str$(i),".0",""); " seconds"
 pause 1000
 next i
 
! go to graphics screen
gr.open 255,255,0,0,0,1
gr.color 255,255,255,255,1
gr.text.size 30
gr.text.draw tx,5,30,"Touch screen"
gr.render
do
 gr.touch touched,x,y
until touched

! goto html screen
popup " Going to html screen",0,0,0
! html must be opened before doing any html command
html.open
! Load the file, htmlDemo1.html
html.load.url "file:///sdcard/rfo-basic/data/numkeyb.html"
! The user now sees the html
! We can now monitor the user
! actions
mynum$=""
! loop until enter is pressed
do

! loop until data$ is not ""
 do
    html.get.datalink data$
 until data$ <> ""

! The first four characters of data$
! identify the type of data returned.
 type$ = left$(data$, 4)

! Trim the first four characters from data$
 data$ = mid$(data$,5)
! Get the first three characters from data$
 dat$=left$(data$, 3)
! Act on the data type
 sw.begin type$
! Back Key hit: quit
 sw.case "BAK:"
    html.close
    print "Program terminated!"
    end 
  sw.break
! An error occured
 sw.case "ERR:"
   print "Error: " + data$
 sw.break
! User data returned
 sw.case "DAT:"
	   if dat$ = "ent" 
		  print "Enter pressed"
		  d_u.break
       elseif dat$="del"
	      print "Delete pressed"
          mynum$=left$(mynum$,len(mynum$)-1)
          print "Current number ";mynum$  
	   else	 
           mynum$=mynum$+data$
		   print data$; " pressed, ";
           print "Current number ";mynum$
	   endif
  sw.break
 sw.default
   print "Unexpected data type:", type$ + data$
   END 
 sw.end
until dat$ = "ent"

! enter pressed:
! input finished, closing html
! going to graphics screen
html.clear.cache
html.close
! update graphics screen
gr.text.draw tx,5,130,"You typed: "+mynum$
gr.text.draw tx,5,230,"Touch screen again"
gr.render
do
 gr.touch touched,x,y
until touched

! close graphics screen
! & return to console screen
gr.close
popup " Going to Console screen",0,0,0
print "Your number is: ";mynum$
end
