September, 2010


7
Sep 10

Adding touch support to jQueryUI

I needed a quick and dirty way of getting the jQueryUI Slider component to work with the touch events on the iPhone and iPad (iOS) so after a little thinking I started writing a few lines of jQuery that would listed to the touch events and pass them on to the relevant jQuery core classes so that any components based on jQuery would get the events for Free.

 

About 10 minutes in it occured to me that this must have been done before and while i like hacking with touch events, I did a quick Google and found the exact script i was about to write.

If your looking to add  touch support to jQueryUI components look no further than this Google Code project

 


5
Sep 10

iPad Multi-Touch – in Javascript.

ipad_touches_small.jpg

I recently came across a nice article/experiment from Matt Gemmell (@mattgemmell) where he decided to test how many simultaneous touches the iPad Multi Touch display would register, it turns out its 11 and he put together a pretty impressive demo app to prove it (see the Screen Shot).

At first sight you would think its a pretty complex application to achieve this, i mean all the multi touch stuff and the animation seems quite complex, however anybody who knows the iOS SDK will tell you that this stuff is trivial at best, and while Matt has done a great job of pulling it all together its far from complex.

The SDK that wasn’t mean’t to be

This application got me thinking about the iOS SDK and the fact that Apple originally didn’t want us writing native applications and in fact they wanted us to write Browser based applications in Javascript, HTML5 and CSS3.

Now its pretty clear to me that the native apps we see (in abundance) on the app store like Angry Birds, Twitterific, Pulse, Things, Pages, etc… could be written using JS, HTML5 and CSS3 but they would most definitely be poorer for it, come on, the runtime performance, the slick User Experience, simply can’t be replecated to the same level with an app running inside a Browser! (let the flame war begin)

So on that note i decided to replicate Matt’s Multi Touch application in Javascript, HTML5 and CSS3, so with a little digging around in Apples documentation I found all the Javascript events that expose touches (touchstart, touchend and touchmove) and began hacking!

Now let me say right now that this is one hours worth of hacking and the end goal was to build an application that was comparable to Matt’s, I suspect some of the code could be optimised, in fact I really hope that is the case when it comes to the Canvas drawing methods (but that is another story for another post).

multitouchtest.pngNow for some reason I fully expected the JS version to respond to less touches than the native version but in fact its 11 just like Matt’s Version, I also expected the animation to be less “smooth” and jerky when I was moving my fingers around, and I was spot on. The iPad benefits from multithreading and a graphics rendering pipeline, where the Browser that my app is running in does not so any processing I do to draw, calculate or respond to touch events all happens in the same thread as well as the browsers rendering code, this in a nut shell is the reason why these apps will not compete with Naive apps, I may in the near future re visit this topic and look at using HTML5 Web-Workers which in theory would give me the ability to run background threads, but i suspect that even that wouldn’t help too much for applications that are so closely coupled to the rendering engine.

Anyway, here is the application I wrote (visit it on an iOS device) it works almost exactly like the Original albeit its not as smooth. The source code is all inline (for your convenience) so feel free to take a look (lift, steal, optimise, laugh at, etc…) and let me know what you think.

My Conclusion

The iPad really is a “Magical” device, and with Great tools like Sencha Touch web developers are better placed than ever before when it comes to building native-ish applications, but I really believe that these apps will be the poorer relations to their native cousins. So keep learning Obj-C folks!