[Jprogramming] access camera on handheld devices

bob therriault bobtherriault at mac.com
Wed Dec 19 18:48:16 UTC 2012


This is an update to the iPad Lab interface that uses the hview to allow access to J labs. 

The top row of buttons selects lab categories. The lab buttons provide a view of the opening page of the lab. At the moment javaScript in hview cannot activate the lab in J, but I do provide the information required to access the real lab through an alert box. 

Any feedback is appreciated. I believe that this may suggest opportunities for richer user interaction for J on the iPad (or for that matter JHS since the script is HTML-CSS-JavaScript based).

Cheers, bob

cocurrent 'uxjlab'
require '~addons/ide/ios/labs.ijs'
require '~addons/labs/labsx/lab.ijs'
clear ''
jx 85 NB. out of range used to initialize labs, suggestions on how to do this elegantly are welcome!

getlabtext=: 3 : 0
labopen_jlab_ y { LABFILES_jlab_
i=.110&>.([:{.(LF,')',LF)I.@:E.;)SECTIONDATA_jlab_ NB. 110 character message minimum
LABTEXT=:LABTEXT,<(i{.])>@{.SECTIONDATA_jlab_
)

CATCOLOR=: ;:'OrangeRed LightSalmon Gold Lime DodgerBlue Fuchsia' NB. Category colors
CATCLASS=:~.LABCATS_jlab_
LABNAMES=:(([:>:':'i.~])}.])each LABTITLES_jlab_
LABNUMS=:": each <"0 at i.@#LABTITLES_jlab_
LABTEXT=:<'' 
getlabtext"0 i.  #LABTITLES_jlab_

CSS=:JS=:HTML=:''

CATSTYLE=:;(<'[name='),each CATCLASS,each(<'] { color:'),each CATCOLOR,each(<'; } ')
BUTTONSTYLE=:;(<'button { display:inline; color:'),each CATCOLOR,each(<'; font-size:1em; text-shadow:1px 1px 2px #000000; } .catButton { font-size:1.3em; opacity:1; display:inline; }')
GROUPSTYLE=:;(<'div[name='),each CATCLASS ,each(<'] {width:70%; display:none } div[name='),each CATCLASS ,each(<'] .on {width:70%; display:inline } div[name=core] {width:70%; display:inline-block }')
PARASTYLE=:'p { display:none; }'
CSS=:'<style> ',CATSTYLE,GROUPSTYLE,BUTTONSTYLE,PARASTYLE,' </style>'

CATBUTTONS=: ;('<button onclick="showLabs(this)" class="catButton" name="',,&'" id="',,&'">',,&'</button>')each CATCLASS
LABBUTTONS=: (('" id="',,&'" >',,&'</button>') each)  each (LABCATS_jlab_ </.LABNAMES)
LABBUTTONS=:  (LABCATS_jlab_ </.LABCATS_jlab_)(,each) each LABBUTTONS
LABBUTTONS=:('<button onclick="labText(this)" width=150px; class="labButton" name="'&,each)each LABBUTTONS
LABBUTTONS=:((<'">'),,&(<'</div>'))each LABBUTTONS
LABBUTTONS=:;;(('<div name="'&,)each CATCLASS); each LABBUTTONS
FIRSTLAB=: ;('<p >',,&'</p>')each  LABTEXT NB. all hidden until lab button shows appropriate lab info
HTML=: CATBUTTONS,LABBUTTONS,FIRSTLAB

JS=: ' function showLabs(t) { var dl =document.getElementsByTagName("div").length; for(var i=0;i<dl;i++) { var x= document.getElementsByTagName("div")[i]; if(x.getAttribute("name")===t.getAttribute("name")) { x.style.display="inline-block";} else {x.style.display="none";};};}'
JS=: JS,' function labText(t){var r=confirm(t.getAttribute("id")+ "\n\n"+document.getElementsByTagName("p")[ labNum(t)+1].innerHTML);if (r===true){alert(" Type  jx "+ labNum(t)+ " in J''s text entry box to begin the lab.\n \n Press return with empty text entry box to advance through the lessons. \n \n J remains active, allowing you to try things out by entering code in the box before moving on!");}}'
JS=: JS,' function labNum(t){ var bl =document.getElementsByTagName("button").length; for(var i=0;i<bl;i++) { var x= document.getElementsByTagName("button")[i]; if(x.getAttribute("id")===t.getAttribute("id")) { return i-6;}};}'NB. subtract 6 to account for 6 category buttons
JS=:'<script>',JS,'</script>'

jux=: 3 : 0
jy '<html><head>',CSS,'</head><body>',JS,HTML,'</body></html>'
)

jux_z_=:jux_uxjlab_
jux ''

On 2012-12-14, at 2:30 PM, bob therriault wrote:

> Hi Brian,
> 
> When you click on the category buttons, the different lab buttons associated with the category should appear, and when you click on the lab button, an alert should pop up that tells you what number should be used as an argument to jx.  Eric replied in an earlier post in this thread, "I don't think the current release will allow javascript running in the html view to call J." So the issue is not whether JavaScript runs (it clearly does), but that it does not have a channel to send information back to the J interpreter. That is why my alerts can tell you what you need to do, but they can not get J to do it for you. Interestingly enough there are some events that can trigger J code (the swipes to go back and forth on the hview come to mind).
> 
> So the next step would be to provide a conduit where events in JavaScript trigger J code. Until that bridge is built, we can sit in the land of J and create Javascript text and run it, but once we are in JavaScript land we can not send anything back to J (other than finger swipes). I think Eric would have the best understanding of the mechanisms, so just take my explanation as hand waving at this point.
> 
> Cheers, bob
> 
> 
> 
> 
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list