<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Five Minutes</title>
	<atom:link href="http://www.fiveminutes.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fiveminutes.eu</link>
	<description>Technology and Marketing Solutions</description>
	<lastBuildDate>Fri, 04 May 2012 09:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How we&#8217;ve created the LaLa Lunchbox iPhone app</title>
		<link>http://www.fiveminutes.eu/how-weve-created-the-lala-lunchbox-iphone-app/</link>
		<comments>http://www.fiveminutes.eu/how-weve-created-the-lala-lunchbox-iphone-app/#comments</comments>
		<pubDate>Fri, 04 May 2012 09:58:13 +0000</pubDate>
		<dc:creator>Merlin Rebrović</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3879</guid>
		<description><![CDATA[A few days ago the LaLa Lunchbox app landed on App Store. Even after such a short time, it got some great feedback. Things like that happen if you have a client that knows what problems need to be solved, &#8230; <a href="http://www.fiveminutes.eu/how-weve-created-the-lala-lunchbox-iphone-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img style="border: none" class="alignleft size-full wp-image-3882" src="http://www.fiveminutes.eu/wp-content/uploads/2012/05/lala_logo.jpg" alt="" width="190" height="184" />A few days ago the <a href="http://www.lalalunchbox.com/">LaLa Lunchbox</a> app landed on App Store. Even after such a short time, it got some great feedback. Things like that happen if you have a client that knows what <a href="http://lalalunchbox.com/blog/how-it-all-began">problems need to be solved</a>, but is flexible enough to let the professionals do their work. This post is about the design and development process of the app.<span id="more-3879"></span></p>
<h2>Wireframes, prototypes and design</h2>
<p>The first step of any process is finding out who the users are. In this case, there are two groups that use the app <strong>simultaneously</strong> &#8211; parents and children. Parents manage children&#8217;s accounts, food items and browse through a groceries list. Children use the central part of the application &#8211; the lunchbox &#8211; to prepare their meals for the week. The former part had to be efficient and organized. The latter had to be fun and engaging like a game. Those two requirements are not easily mixed together.</p>
<p>We had great and continuous communication with the client and used online wireframing tools extensively. The path between the client&#8217;s initial idea and a finished product is very obscure and if all situations are not thought through, it&#8217;ll bite you near the end. That&#8217;s why <strong>wireframing is all about problem solving</strong>.</p>
<p><img src="http://www.fiveminutes.eu/wp-content/uploads/2012/05/lala_paper.jpg" alt="" width="430" height="430" class="alignleft size-full wp-image-3890" /><br />
<img style="border: none" src="http://www.fiveminutes.eu/wp-content/uploads/2012/05/lala_wireframe-e1336125392155.jpg" alt="" width="447" height="438" class="alignleft size-full wp-image-3881" /></p>
<p>During that phase the dev team was brought in. They checked the technical feasibility and brought a different perspective with good questions and discussions. This is also the best time to quickly prototype some new ideas (new types of selection, animation, etc) and see how they behave on a device.</p>
<p>Designing for grown-ups and children at the same time is not easy, but we&#8217;ll let the pictures do the talking.</p>
<p><img style="border: none" class="aligncenter size-full wp-image-3880" src="http://www.fiveminutes.eu/wp-content/uploads/2012/05/lala_iphone1.jpg" alt="" width="450" height="510" /><br />
<img style="border: none" src="http://www.fiveminutes.eu/wp-content/uploads/2012/05/lala_iphone2.jpg" alt="" width="450" height="510" class="aligncenter size-full wp-image-3887" /></p>
<p>About 40% of the total time spent on the app was on design and user experience before the first line of production code was written. It was a good decision.</p>
<h2>Development and QA</h2>
<p>Coding custom game-like consumer application is never an easy task. There are many non-standard technical requirements and if you want to impress your users, you&#8217;ll have to code <em>like a boss</em>. One of the examples is the custom scroll and inertia our dev team implemented because the out-of-the-box solution just wasn&#8217;t good enough for our specific situation. Small things like that and not cutting corners is the way to a great application and user experience.</p>
<p>As soon as the first usable builds landed on a device, QA team started tracking bugs and testing all edge cases. Finding those as early as possible saved us time later.</p>
<h2>Complete involvement</h2>
<p>In the second half of development, the whole team and the client were fully involved. The design team didn&#8217;t just said <em>&#8220;OK, we did our part&#8221;</em>. They used development builds to conduct user testing, sometimes very short, sometimes more elaborate. The dev team implemented the feedback from testing and QA made sure everything worked as planned without problems.</p>
<p>Waterfall workflows where functional departments do their work on a project and pass it on to never see it again are things of the past and should never be used if you want to create this type of consumer application. Be agile and respond to feedback.</p>
<p>If you have children and value the effort that has been put into the LaLa Lunchbox app, be sure to check it out on <a href="http://itunes.apple.com/us/app/lala-lunchbox/id519037961">App Store</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/how-weve-created-the-lala-lunchbox-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We&#8217;ve built a Spotify app for Matador Records!</title>
		<link>http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/</link>
		<comments>http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 11:01:57 +0000</pubDate>
		<dc:creator>Srđan Stanić</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3296</guid>
		<description><![CDATA[Spotify is an awesome music streaming service launched in 2008 by a Swedish startup. Just recently it became available in 14 different countries including US and UK. What&#8217;s rather interesting about this particular music streaming service is that at the &#8230; <a href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left">
<p><a rel="attachment wp-att-3416" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/spotify-logo-96x96-no-tagline/"><img class="size-full wp-image-3416 alignleft" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/spotify-logo-96x96-no-tagline.png" alt="Spotify logo" width="96" height="96" /></a></p>
<p><a title="Spotify website" href="http://www.spotify.com/" target="_blank">Spotify</a> is an awesome music streaming service launched in 2008 by a Swedish startup. Just recently it became available in <a title="Spotify on Wikipedia" href="http://en.wikipedia.org/wiki/Spotify" target="_blank">14 different countries</a> including US and UK. What&#8217;s rather interesting about this particular music streaming service is that at the end of last year they introduced an <a title="Spotify apps introduction blog post" href="http://www.spotify.com/se/blog/archives/2011/11/30/say-hello-to-spotify-apps/" target="_blank">app platform</a>. It opened up a whole new world inside the Spotify desktop client. There were various cool apps released in the first batch, like <a title="Last.fm Spotify app" href="http://open.spotify.com/app/lastfm" target="_blank">Last.fm</a> and <a title="Moodagent Spotify app" href="http://open.spotify.com/app/moodagent" target="_blank">Moodagent</a>. Be sure to check them out if you&#8217;re a Spotify user.</p>
<p style="text-align: left">But the first batch of apps was just a start. Two weeks ago, a <a title="More Spotify apps blog post" href="http://www.spotify.com/se/blog/archives/2012/03/22/more-apps-for-you-to-play-with/" target="_blank">second batch of apps</a> went out. And we are proud to be a part of it. We got an opportunity to build a Spotify app for <a title="Matador Records website" href="http://www.matadorrecords.com/" target="_blank">Matador Records</a>. It&#8217;s a well-known independent record label famous for their <a title="Indie rock wikipedia article" href="http://en.wikipedia.org/wiki/Indie_rock" target="_blank">indie rock</a> artists and bands. So we jumped on the opportunity and went to work.</p>
<p style="text-align: left"><span id="more-3296"></span></p>
<p style="text-align: left">The goal was to create a simple, but usable and useful app that will provide some real value for the end user. While we had a bunch of cool ideas, due to the tight deadline, we needed to restrain ourselves and focus on the most important information we could provide. So we concluded that what Matador Records music fans really care about are releases and tour dates. After about a week of development, here is what we got.</p>
<p style="text-align: left">
<p style="text-align: center"><a rel="attachment wp-att-3346" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/screen-shot-2012-04-06-at-2-24-09-pm/"><img class="size-medium wp-image-3346 aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/Screen-Shot-2012-04-06-at-2.24.09-PM-514x380.png" alt="Matador Records Spotify app" width="514" height="380" /></a></p>
<p><span style="text-align: left">On the home screen you can see new and upcoming releases. Upcoming releases appear only if announced, though.</span></p>
<p><span style="text-align: left"> </span></p>
<p style="text-align: center"><a rel="attachment wp-att-3356" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/screen-shot-2012-04-06-at-2-26-58-pm/"><img class="size-medium wp-image-3356 aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/Screen-Shot-2012-04-06-at-2.26.58-PM-389x380.png" alt="New and Upcoming releases" width="389" height="380" /></a></p>
<p><span style="text-align: left"> </span></p>
<p style="text-align: left">If you scroll down a bit, you can see the upcoming concerts from Matador Records bands.</p>
<p style="text-align: left">
<p style="text-align: center"><a rel="attachment wp-att-3349" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/screen-shot-2012-04-06-at-2-29-03-pm/"><img class="size-medium wp-image-3349 aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/Screen-Shot-2012-04-06-at-2.29.03-PM-475x380.png" alt="Upcoming concerts" width="475" height="380" /></a></p>
<p style="text-align: left">
<p>If you want to explore further, <em>All releases</em> tab shows the whole history of Matador Records releases. Most curious fans will definitely want to check out some of the older albums from early 90&#8242;s, which they can easily filter out in the app.</p>
<p style="text-align: center"><a rel="attachment wp-att-3344" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/screen-shot-2012-04-06-at-2-13-36-pm/"><img class="size-medium wp-image-3344 aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/Screen-Shot-2012-04-06-at-2.13.36-PM-580x350.png" alt="Releases from 1993" width="580" height="350" /></a></p>
<p>Although listening to the music via Spotify is awesome, both at home and on the go, what every true fan really wants is to see the band performing live in her or his neighborhood. That&#8217;s why <em>Tour dates</em> tab contains all concerts planned for this year with dates and locations.</p>
<p style="text-align: center"><a rel="attachment wp-att-3345" href="http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/screen-shot-2012-04-06-at-2-22-24-pm/"><img class="size-medium wp-image-3345 aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/Screen-Shot-2012-04-06-at-2.22.24-PM-389x380.png" alt="Tour dates" width="389" height="380" /></a></p>
<p><span style="text-align: left">Initial feedback from the users is very positive and there are also improvement </span><a title="Matador Records Spotify app review" href="http://www.sosoactive.com/matador-records-spotify-app-review/" target="_blank">suggestions</a><span style="text-align: left">. We are aware there is room for improvements and we hope to have them in the app soon.</span></p>
<p style="text-align: left">We invite you to <a title="Matador Records Spotify App" href="http://open.spotify.com/app/matadorrecords" target="_blank">check out</a> the app and let us know in the comments how you liked it.</p>
<p style="text-align: left">P.S.</p>
<p style="text-align: left">Few notes to the developers:</p>
<p>1. pay special attention to developing a responsive design so that your app still looks great when the user decides to resize the client window</p>
<p>2. expect rigorous QA from the Spotify team, follow the <a title="Spotify Apps Guidelines" href="https://developer.spotify.com/technologies/apps/guidelines/" target="_blank">guidelines</a> as much as you can</p>
<p>3. useful resources: <a title="Apps API Docs" href="https://developer.spotify.com/technologies/apps/docs/" target="_blank">Spotify Apps API Documentation</a>, <a title="StackOverflow tag Spotify" href="http://stackoverflow.com/questions/tagged/spotify" target="_blank">StackOverflow</a>, <a title="Spotify Apps Demo" href="https://github.com/ptrwtts/kitchensink" target="_blank">Demo application</a> for the Spotify Apps API created by Peter Watts. (Thanks dude!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/weve-built-a-spotify-app-for-matador-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Be aware of the users in Spring!</title>
		<link>http://www.fiveminutes.eu/be-aware-of-the-users-in-spring/</link>
		<comments>http://www.fiveminutes.eu/be-aware-of-the-users-in-spring/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 08:19:54 +0000</pubDate>
		<dc:creator>Ante Brkić</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Five Minutes]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3370</guid>
		<description><![CDATA[session scoped spring bean for keeping track of the logged in user in the spring layer <a href="http://www.fiveminutes.eu/be-aware-of-the-users-in-spring/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I tried to be figurative in the header only to break the spleen mood of this rainy morning. <a rel="attachment wp-att-3371" href="http://www.fiveminutes.eu/be-aware-of-the-users-in-spring/250px-fruhling_bluhender_kirschenbaum/"><img class="alignright size-full wp-image-3371" src="http://www.fiveminutes.eu/wp-content/uploads/2012/04/250px-Frühling_blühender_Kirschenbaum.jpg" alt="" width="250" height="188" /></a>This blog is about <a href="http://www.springsource.org/">Spring Framework</a> and keeping track of the session data, particularly logged in user.</p>
<p><span id="more-3370"></span></p>
<p>The problem: very simple, i need to send an user id with each http request sent from out Spring layer to the REST API server. We use <a href="http://www.stripesframework.org/display/stripes/Home">Stripes</a> as a front-end layer and user is easily accessible there from the session as at the login time we store user in the session. But the problem with Spring Framework is that it is not session aware by default, particularly, all Spring beans are singletons, that is, only one instance of object exists for the whole application. Setting userId in a static field for example would result in overwriting of that field each time the new user logs in as that field would be shared.</p>
<p>Obvious solution would be to send user it with each call made from Stripes to Spring, but i think that Robert C. Martin, author of <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a> would be very disappointed to see that. I think there are several reasons why this approach, well &#8211; is not good, to be polite:</p>
<p>- adding mandatory parameter to each and every call is simply a burden to the developer<br />
- it adds a lot of duplication<br />
- it is error prone</p>
<ul></ul>
<p>So, after googling the topic i found that it is possible to change the scope of Spring bean using the configuration. It is possible to change scope from default singleton to prototype, request and the one we need here &#8211; session. This approach is only possible in web-aware applications, but we certainly have one, and it means that bean instantiation will be made per session</p>
<p>Now we have a session scoped object which is used to keep track of the logged in user and is also responsible for factoring of the http requests. Now the information that needs to be added to each http request is really close (in the same object).</p>
<p>Another point is that this session scoped object (i simply named it <em>SessionScope</em>) needs to be accessible from every other bean that consumes http request factory and also by the user management service as it needs to initially set the userId. This means that we need to <em>SessionScope </em>bean as a dependency (Spring calls this <em>collaborator</em>) but we can not simply add it as a standard dependency as the beans that are using this session bean are still singleton beans, and technically this would result in our collaborator bean to act like a singleton bean also (it would be injected once the singleton bean is created), so we need to add element:</p>
<p><code> &lt;aop:scoped-proxy/&gt; </code></p>
<p>in the session bean configuration and the result will be that only proxy object is injected, and by default, <a href="http://cglib.sourceforge.net/">cglib</a> will take care of the session management of real per-session data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/be-aware-of-the-users-in-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Heap Dump</title>
		<link>http://www.fiveminutes.eu/java-heap-dump/</link>
		<comments>http://www.fiveminutes.eu/java-heap-dump/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 13:34:08 +0000</pubDate>
		<dc:creator>Marin Martinić</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3277</guid>
		<description><![CDATA[Memory leaks are notoriously hard to debug. Java, with its built in garbage collector, handles most memory leak issues. <a href="http://www.fiveminutes.eu/java-heap-dump/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-2778" src="http://www.fiveminutes.eu/wp-content/uploads/2011/09/javaLogo.png" alt="" width="150" height="150" />Memory leaks are notoriously hard to debug. Java, with its built in garbage collector, handles most memory leak issues. True memory leak happens when objects are stored in memory but are not accessible by running code. These kinds of inaccessible objects are handled by Java garbage collector (in most cases). Another type of memory leak happens when we have an unneeded reference to the object somewhere. These are not true memory leaks as objects are still accessible, but none the less can cause some nasty bugs.<br />
<span id="more-3277"></span><br />
For example, storing large objects in session and not cleaning its references. This kind of issue will often go unnoticed until we get a large number of concurrent users and your application starts throwing out of memory errors. Without load test this will most probably happen in production.<br />
One way to find memory leaks is analyzing heap dumps. There are several ways to get a heap dump (not including 3rd party tools):</p>
<p><strong>1. HeapDumpOnCtrlBreak</strong><br />
Add this option when starting JVM. It will create heap dump every time ctrl+break (kill -3) signal is sent to JVM. HeapDumpPath is used to set location of heap dumps.</p>
<p><strong>2. HeapDumpOnOutOfMemoryError</strong><br />
This JVM option will create heap dump every time when your application throws an OutOfMemoryError. HeapDumpPath is used to set location of heap dumps.</p>
<p><strong>3. Jmap</strong><br />
Jmap is a tool that comes with JDK installation. To use it we need a PID of our java process.<br />
Then we can use it like this:<br />
<code>jmap -dump:file=D:\temp\heapdumps\dump.bin pid 1234</code></p>
<p><strong>4. Jmap (from the application)</strong><br />
We can also use jmap from our code. To get a pid from code use we need to use java.lang.management.ManagementFactory.<br />
<code><br />
String name = ManagementFactory.getRuntimeMXBean().getName();<br />
String pid = name.substring(0, name.indexOf("@"));<br />
After that we can start jmap process like this:<br />
String[] cmd = { "jmap", "-dump:file=D:\\temp\\heapdumps\\dump.bin", pid };<br />
Process p = Runtime.getRuntime().exec(cmd);<br />
</code><br />
<strong>5. HotSpotDiagnosticMXBean</strong><br />
This option is available in Java 1.6+ and uses sun.management.ManagementFactory.<br />
<code><br />
ManagementFactory.getDiagnosticMXBean().dumpHeap("D:\\temp\\heapdumps\\dump.bin", true);<br />
</code></p>
<p>When we get the heap dump we need to use a tool like VisualVM (also included in JDK installation)to actually try and find the leak.<br />
There are of course a lot of different tools, free and commercial, that can provide monitoring and creating of heap dumps. But in some cases there are restrictions in including 3rd party tools in the picture and that is where this list comes in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/java-heap-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using mock objects for Stripes-Spring testing</title>
		<link>http://www.fiveminutes.eu/using-mock-objects-for-stripes-spring-testing/</link>
		<comments>http://www.fiveminutes.eu/using-mock-objects-for-stripes-spring-testing/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 13:15:32 +0000</pubDate>
		<dc:creator>Ante Brkić</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Five Minutes]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software testing]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3255</guid>
		<description><![CDATA[Usage of mocked container stripes junit testing which uses mocked spring objects for fast and precise testing. <a href="http://www.fiveminutes.eu/using-mock-objects-for-stripes-spring-testing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-3256" href="http://www.fiveminutes.eu/using-mock-objects-for-stripes-spring-testing/test/"><img class="alignright size-full wp-image-3256" src="http://www.fiveminutes.eu/wp-content/uploads/2012/02/test.jpg" alt="" width="177" height="203" /></a></p>
<p>It is very easy to create a mock objects of your <a href="http://www.springsource.org/">Spring</a> layer, and not only does it allow you to create a consistent junit tests, but in the process you will end up with a mocked spring layer which you can use for fast front-end development!<br />
Let&#8217;s see how.</p>
<p><span id="more-3255"></span></p>
<p>First of all, <em>junit</em> testing of <a href="http://www.stripesframework.org/display/stripes/Home">Stripes</a> comes in a two flavors, first one invoking your action beans directly and as expected is a simple approach but with a big disadvantage (among others) &#8211; you can not test spring beans as injection is not started. Second approach, which really looks much more convenient and is introduced into Stripes with version 1.1.1 (wow, that was 6 years ago!) is so called &#8220;Mock Container Usage Approach&#8221;, so it requires a little bit more work.</p>
<p>For the later, we need to create a <em>MockServlerContext</em> which we will use for each test, so we want to do it with a singleton class (it takes a while to initialize <em>MockServletContext</em> as it actually boots the simulator container). After that, in each test we create <em>MockRoundtrip</em> (based on mocked context), which is a simulation of a request. So, for <em>MockRoundtrip</em>, we set parameters which would &#8220;in real life&#8221; be set from the JSP (or other presentation layer, Stripes authors mention that <strong><a href="http://freemarker.sourceforge.net/">FreeMarker</a></strong> can also be used with Stripes), call &#8220;execute&#8221; and then assert results. But i have skipped the important part and that is configuring of <em>MockServlerContext</em>. This is done java-style, in our singleton, and simulates <em>web.xml</em> configuration. Here i will just say that this is the place where we define which spring configuration file we want to use. But let me first just say a few words about spring mock object and i will return here really fast.</p>
<p>So in our project we connect to the remote server using the <a href="http://en.wikipedia.org/wiki/Representational_state_transfer">REST</a> paradigm, while communicating using JSON objects. This is slow when looking from the perspective that for <em>junit</em> tests you do not really depend on over-the-wire communication, and you know how it goes, test servers are shared among many people and so on, and also, you do not want your <em>junit</em> tests to really on the data that everybody can edit, right? So one layer of <em>junit</em> tests is definitely this, connecting to mock objects that do include spring beans, but not the real ones that use REST calls, but fake ones, that just return some fixed data.</p>
<p>And i promised to return to <em>MockServletContext</em> configuration, so now is the good time because there the developer specifies that the configuration that will be used is the one that points to the mocked spring layer. That way, our <em>junit</em> tests are fast and consistent.</p>
<p><code><br />
filterParams.put("ActionResolver.Packages", "your.package.with.actions");<br />
filterParams.put("Interceptor.Classes", "net.sourceforge.stripes.integration.spring.SpringInterceptor");<br />
filterParams.put("ActionBeanContext.Class", "your.subclass.of.ActionBeanContext");<br />
filterParams.put("LocalePicker.Locales", "en_US:UTF-8");<br />
mockServletContext.addFilter(StripesFilter.class, "StripesFilter", filterParams);</code></p>
<p><code> </code></p>
<p><code> // spring configuration file<br />
mockServletContext.addInitParameter("contextConfigLocation", "classpath:applicationContext.mock.xml");<br />
</code><br />
Once you have established two versions of spring configuration, it is extremely easy to switch between those two: it is a matter of commenting/uncommenting a line in your <em>web.xml</em>.</p>
<p>For more details on this subject see <a href="http://www.stripesframework.org/display/stripes/Unit+Testing">this</a>, or just ask :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/using-mock-objects-for-stripes-spring-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing Spring Integration</title>
		<link>http://www.fiveminutes.eu/introducing-spring-integration/</link>
		<comments>http://www.fiveminutes.eu/introducing-spring-integration/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 12:14:45 +0000</pubDate>
		<dc:creator>Samir Čauš</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3197</guid>
		<description><![CDATA[Introducing spring Integration trough polling database example. <a href="http://www.fiveminutes.eu/introducing-spring-integration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fiveminutes.eu/introducing-spring-integration/placeholder_video_spring_projects/" rel="attachment wp-att-3246"><img src="http://www.fiveminutes.eu/wp-content/uploads/2012/02/placeholder_video_spring_projects-150x150.png" alt="Spring Integration" width="150" height="150" class="alignleft size-thumbnail wp-image-3246" /></a>
<p>Recently, we worked on a project that required frequent polling of database table, processing each row, and writing output to different database table(s). The data tables are incoming and outgoing sms messages, and load would get quite high sometimes. We also had to support load balancing. Since our services are already done with spring &#8211; the choice was to try <a href="http://www.springsource.org/spring-integration">Spring Integration</a>.</p>
<p><span id="more-3197"></span></p>
<p>So what is Spring Integration? &#8220;Spring Integration provides an extension of the Spring programming model to support <a href="http://www.eaipatterns.com/">Enterprise Integration Patterns</a>. It enables lightweight messaging within Spring-based applications and supports integration with external systems via declarative adapters.&#8221;</p>
<p>Basic concepts when designing Spring Integration applications are Messages (java objects with metadata), Channels (pipes that messages go trough) and Message Endpoints.<br />
Message endpoints can be various &#8211; like Transformer (transforms data), Router(route data), Filter (filters data), Splitter (splits messages), Aggregator (inverse of Splitter), Service Activator (connecting messages to Services) and most important Channel Adapters.</p>
<p>Channel Adapters connects Message Channels to &#8220;external&#8221; world. They can be inbound (create new messages) and outbound (consumes messages). The choice of connection type is pretty big &#8211; like AMQP, JDBC, Web Services, FTP, File, HTTP, TCP, UDP, JMS, Mail, MongoDb, RMI, XML, XMPP, Stream and even <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#twitter">Twitter</a>.</p>
<div id="attachment_3202" class="wp-caption alignleft" style="width: 590px"><a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#samples-cafe"><img src="http://www.fiveminutes.eu/wp-content/uploads/2012/02/cafe-eip-580x290.png" alt="Spring Integration Sample" width="580" height="290" class="size-medium wp-image-3202" /></a><p class="wp-caption-text">Spring Integration Sample</p></div>
<p>Back to our application. Its very easy to add polling of database table. Just add <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#jdbc-inbound-channel-adapter">Jdbc Inbound Channel Adapter</a> that will poll database table with query that you specify (load balancing is working as we are using oracles &#8220;select for update nowait skip locked&#8221; syntax which skips rows with read lock). Specify properties like channel (name of channel where will message go), data-source, row-mapper (converts table row to java objects), update (query that is executed after table is read &#8211; you want to delete row once it is processed or put some flag) and fixed-rate (polling interval). There is also possibility to add <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#transactions">transaction </a>support , or define cron expression instead of fixed rate polling, but we didn&#8217;t need that. What we needed is to add Thread pool with Spring <a href="http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/scheduling.html">Task Executor</a>, and combine this with Spring Integration by  setting message channel as <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#channel-implementations">ExecutorChannel</a></p>
<pre><code>
	&lt;int-jdbc:inbound-channel-adapter query="${db.select.userrequest.query}"
		channel="smsInboundChannel" data-source="dataSource" row-mapper="userRequestMapper"
		update="${db.delete.userrequest.query}"  max-rows-per-poll="${db.poller.maxrowsperpoll}" &gt;
			&lt;int:poller fixed-rate="${db.poller.fixedrate}"  &gt;
			&lt;/int:poller&gt;
	&lt;/int-jdbc:inbound-channel-adapter&gt;
</pre>
<p></code><br />
That's it. Now we just needed to make a Spring Integration <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#chain">chain</a>. Add splitter to separate messages per row. Add Service Activator to process message. Finally add <a href="http://static.springsource.org/spring-integration/reference/htmlsingle/#jdbc-outbound-channel-adapter">Jdbc Outbound Channel Adapter</a> to write to database.The possibilities are numerous. And since everything is done using Spring concepts, the code is easily maintainable and testable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/introducing-spring-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check user permission using aspect-oriented programming</title>
		<link>http://www.fiveminutes.eu/check-user-permission-using-aspect-oriented-programming/</link>
		<comments>http://www.fiveminutes.eu/check-user-permission-using-aspect-oriented-programming/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 09:24:50 +0000</pubDate>
		<dc:creator>Kristijan Rebernišak</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Five Minutes]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3147</guid>
		<description><![CDATA[In this post we will show a example of simple and clean way to check your users permissions across your application using aspect-oriented programming (AOP). In computing, AOP is a programming paradigm which aims to increase modularity by allowing the &#8230; <a href="http://www.fiveminutes.eu/check-user-permission-using-aspect-oriented-programming/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this post we will show a example of simple and clean way to check your users permissions across your application using aspect-oriented programming (AOP).<br />
<span id="more-3147"></span><br />
In computing, AOP is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns. AOP forms a basis for aspect-oriented software development. Read more about it <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">here</a>.</p>
<p>This example is extracted from a web aplication project build on dependency injection framework <a href="http://code.google.com/p/google-guice/">Google Guice</a>. To compliment dependency injection, Guice supports method interception that divides a problem into aspects rather than objects. This feature enables you to write code that is executed each time a matching method is invoked. It&#8217;s suited for cross cutting concerns (&#8220;aspects&#8221;), such as transactions, security and logging.</p>
<p>Now lets define our simple user base with this three types:</p>
<pre class="brush: java; gutter: true">public enum UserType {
     ADMIN,
     CUSTOMER,
     GUEST;
 }</pre>
<p>To mark select methods that need user validation, we define an annotation:</p>
<pre class="brush: java; gutter: true">import com.google.inject.BindingAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@BindingAnnotation
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiresUserType {
    UserType value();
}</pre>
<p>&#8230;and apply it to the methods that need to be intercepted:</p>
<pre class="brush: java; gutter: true">public class ProductService implements IProductService {

    @RequiresUserType(CUSTOMER)
    public Product view(Key key) {
        ...
    }

    @RequiresUserType(ADMIN)
    public void delete(Key key) {
        ...
    }
}</pre>
<p>Next, we define the interceptor by implementing the <em>org.aopalliance.intercept.MethodInterceptor</em> interface. When we need to call through to the underlying method, we do so by calling <em>invocation.proceed()</em>:</p>
<pre class="brush: java; gutter: true">public class UserValidationInterceptor implements MethodInterceptor {

    public Object invoke(MethodInvocation invocation) throws Throwable {
        final UserType requiredType = invocation.getMethod().getAnnotation(RequiresUserType.class).value();
        //cross check current user type and throw an exception if validation fails
        ...
        //if everything checks out proceed to method execution
        return invocation.proceed();
    }
}</pre>
<p>Finally, we configure everything. This is where we create matchers for the classes and methods to be intercepted. In this case we match any class, but only the methods with our <em>@RequiresUserType</em> annotation:</p>
<pre class="brush: java; gutter: true">import com.google.inject.AbstractModule;
import com.google.inject.matcher.Matchers;

public class SecurityModule extends AbstractModule {
    protected void configure() {
        bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresUserType.class), new UserValidationInterceptor());
    }
}</pre>
<p>The method interceptor API implemented by Guice is a part of a public specification called <a href="http://aopalliance.sourceforge.net/">AOP Alliance</a>. This makes it possible to use the same interceptors across a variety of frameworks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/check-user-permission-using-aspect-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracing Zombie objects in Objective C</title>
		<link>http://www.fiveminutes.eu/tracing-zombie-objects-in-objective-c/</link>
		<comments>http://www.fiveminutes.eu/tracing-zombie-objects-in-objective-c/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 08:55:56 +0000</pubDate>
		<dc:creator>Drago Ružman</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3134</guid>
		<description><![CDATA[Tracing Zombie objects can be challenging from time to time. This post shows a simple way to trace memory management calls to an object and discover why did it become a Zombie. <a href="http://www.fiveminutes.eu/tracing-zombie-objects-in-objective-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If an object gets deallocated too early, other objects still might have references to it and accessing it will lead to crash. Enabling Zombie objects will prevent crashes because objects are never actually deallocated and we&#8217;ll get an exception if we try to access such an object. But figuring out which object is causing trouble is just smaller part of the job. We need to find out where is the extra release (or missing retain) that is causing troubles. <span id="more-3134"></span></p>
<p>In smaller projects or when objects in question are localized to a smaller number of classes, we can find the bug by static code investigation. But if the object is used in a larger scope and often conditionally, we might want to take a look at what is going on in runtime.</p>
<p>To trace memory management related calls to our class, we will need to expand retain, release and autorelease methods. Simplest variant will just call super method, so we can put a breakpoint and see where is it called from. This can be useful, but usually there are lots of instances of the same class and lots of calls to those methods, so this isn&#8217;t really practical. It would be much more practical to log all calls to retain/release/autorelease and then dump the data when we need it. We can save three types of information to our log &#8211; current event (is it release, retain or autorelease), current time and what is most important, call stack trace so we know how exactly did we end up here. All this information can be stored into a simple array which will we add to the class we want to trace (of course, we want to allocate and release this array where appropriate).</p>
<p><code> </code></p>
<pre><code>NSMutableArray* _memTrace;</code></pre>
<p><code> </code></p>
<p>We can fill the _memTrace array with a call to the following method:</p>
<p><code> </code></p>
<pre><code>-(void) addMemTraceEvent:(NSString*)event
{
    [_memTrace addObject:[NSString stringWithFormat:@"%@ %@ at %@",
                          [NSDate date],
                          event,
                          [NSThread callStackSymbols]
                          ]];
}</code></pre>
<p><code> </code></p>
<p>We are using [NSDate date] to get current date and time and [NSThread callStackSymbols] to fetch current call stack trace.</p>
<p>To dump _memTrace, we can use following code:</p>
<p><code> </code></p>
<pre><code>-(void) dumpMemTrace
{
    NSLog(@"%@", _memTrace);
}</code></pre>
<p><code> </code></p>
<p>We can now update our memory management methods, so they log all calls to them:</p>
<p><code> </code></p>
<pre><code>-(void)release
{
    [self addMemTraceEvent:@"release"];

    [super release];
}

-(id)retain
{
    [self addMemTraceEvent:@"retain"];

    return [super retain];
}

-(id)autorelease
{
    [self addMemTraceEvent:@"autorelease"];

    return [super autorelease];
}</code></pre>
<p><code> </code></p>
<p>Now, when such updated object makes a Zombie access exception, we can simply call -dumpMemTrace from gdb&#8217;s command window, examine the log and find the extra release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/tracing-zombie-objects-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Drag&amp;Drop on tree structure with SmartGwt</title>
		<link>http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/</link>
		<comments>http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 13:41:51 +0000</pubDate>
		<dc:creator>Ante Brkić</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3044</guid>
		<description><![CDATA[Today i'm going to show how easy it is implement drag&#38;drop functionality on a visually represented tree structure using SmartGwt. <a href="http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left"><a rel="attachment wp-att-3045" href="http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/tree1/"><img class="size-medium wp-image-3045  aligncenter" src="http://www.fiveminutes.eu/wp-content/uploads/2011/11/tree1-382x380.jpg" alt="The Tree" width="382" height="380" /></a>It has never been as easy to create a thin client web application as it is with the tools such as GWT and it&#8217;s third party library SmartGwt. This is a deadly combination which has out-of-the-box support for drag&amp;drop, asynchronous remote procedure calls, localization, history management and much more inherited from GWT (Google Web Toolkit) and accompanied with numerous customizable widgets (lists, trees, buttons, layout support widgets, HTML5 support&#8230;). In this text, a simple drag&amp;drop implementation will be demonstrated.</p>
<p><span id="more-3044"></span><br />
<span style="font-family: Arial">After setting up the required environment (see links below), we need a class that will implement EntryPoint interface, which will force it to implement onModuleLoad() method, with self-explanatory name.<br />
</span></p>
<p>Now, let&#8217;s create our tree structures:</p>
<p><code>Tree leftTree = new Tree();</code></p>
<p><code>leftTree.setModelType(TreeModelType.CHILDREN);</code></p>
<p><code> </code></p>
<p><code>leftTree.setRoot ...</code></p>
<p><code> </code></p>
<p>Setting model type to CHILDREN means that we will specify children nodes for each node. Other way would be to use PARENT type and then we would be specifying parent ids for each node that has a parent.</p>
<p>We set the actual data using setRoot method. I omitted the details for readability here. Numerous other method for filling up the tree could be used also, like variants of simple add, addList or even connecting our structure to some data source like XML Schema, relational database or EJB.</p>
<p>Note that this is only a data structure and we still need some &#8220;physical&#8221; representation:</p>
<p><code>final PartsTreeGrid leftGrid = new PartsTreeGrid();</code></p>
<p><code>leftGrid.setDragDataAction(DragDataAction.MOVE);</code></p>
<p><code> </code></p>
<p><code>leftGrid.setData(leftTree);</code></p>
<p><code>grid1.getData().openAll();</code></p>
<p><code> </code></p>
<p>DragDataAction.MOVE means that the dragged item will not stay in the originating tree (in contrast to DragDataAction.COPY).</p>
<p>setData is used to bind earlier created data-set to this graphical representation.</p>
<p>PartsTreeGrid is actually a custom extension of TreeGrid adding some face-lifting instructions, and i will emphasize only these lines here:</p>
<p><code>setCanReorderRecords(true);</code></p>
<p><code>setCanAcceptDroppedRecords(true);</code></p>
<p><code> </code></p>
<p><code>setCanDragRecordsOut(true);</code></p>
<p><code> </code></p>
<p>Yes, this is all you have to do to enable drag&amp;drop in your application!</p>
<p>Analogously we add the gird to the right and also the arrow buttons to demonstrate transfer of the selected nodes with mouse click.</p>
<p>And to demonstrate the layout capabilities let&#8217;s see how we construct our parts together:</p>
<p><code>HStack grids = new HStack(10);</code></p>
<p><code>grids.setHeight(160);</code></p>
<p><code> </code></p>
<p><code>grids.addMember(leftGrid);</code></p>
<p><code>grids.addMember(moveControls);</code></p>
<p><code>grids.addMember(rightGrid);</code></p>
<p><code>grids.draw();</code></p>
<p><code> </code></p>
<p>Those familiar with Java Swing will see the similarities. Basically we create appropriate layout and fill it with elements. Layouts can be nested, so combining horizontal and vertical layouts (or some more complex layouts) we can create whatever we want to.</p>
<p>Ah i almost forgot! Our program is finishe<a rel="attachment wp-att-3048" href="http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/capture/"><img class="alignright size-full wp-image-3048" src="http://www.fiveminutes.eu/wp-content/uploads/2011/11/Capture.png" alt="" width="466" height="215" /></a>d.</p>
<p>OK, almost completely, this example is using demonstration framework, but what we would additionally need to do would be to create a simple html page referencing generated JavaScript code (GWT is compiled into JavaScript) and add our grid to the rootPanel using</p>
<p><code>RootLayoutPanel.get().add(...</code></p>
<p><code> </code></p>
<p>If we were not connected to some data source, then now we need to manually handle the data changes. We could subscribe the gird for changes, update the data on exit event or else, whatever suits our needs.</p>
<p>For info about GWT please see: <a href="http://code.google.com/intl/hr-HR/webtoolkit/">http://code.google.com/intl/hr-HR/webtoolkit/</a></p>
<p>For info about SmartGwt, see: <a href="http://code.google.com/p/smartgwt/">http://code.google.com/p/smartgwt/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/using-dragdrop-on-tree-structure-with-smartgwt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cross-platform javascript touch scrolling</title>
		<link>http://www.fiveminutes.eu/cross-platform-javascript-touch-scrolling/</link>
		<comments>http://www.fiveminutes.eu/cross-platform-javascript-touch-scrolling/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 23:59:48 +0000</pubDate>
		<dc:creator>Matija Šmalcelj</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.fiveminutes.eu/?p=3024</guid>
		<description><![CDATA[Currently CSS position:fixed property is only partially supported on mobile devices. iOS below version 5 doesn&#8217;t support it at all and Android is plagued by fragmentation hell. To solve these problems developers created libraries for JavaScript scrolling powered by CSS3 &#8230; <a href="http://www.fiveminutes.eu/cross-platform-javascript-touch-scrolling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.fiveminutes.eu/wp-content/uploads/2011/11/touchscreen1.jpg" alt="" width="250" height="167" class="alignleft size-full wp-image-3037" />Currently CSS position:fixed property is only partially supported on mobile devices. iOS below version 5 doesn&#8217;t support it at all and Android is plagued by fragmentation hell. To solve these problems developers created libraries for JavaScript scrolling powered by CSS3 transitions. We recently wrote from scratch cross-platform mobile web site which uses a combination of native scroll and multiple touch scroll libraries depending on device. In this post I&#8217;d like to share our experiences..</p>
<p><span id="more-3024"></span></p>
<p>Only recently in version 5 iOS began to support CSS position:fixed and before that fixed positioned elements behaved like they&#8217;re absolute positioned relative to document body. On Android it is officially supported since version 2.2 but actual behavior of scroll greatly depends on device and manufacturer with end result ranging from great user experience on some Androids v2.2 to horrible glitchy animation on latest versions. Thumbs up to HTC which did a good job on improving stock browsers with their HTC Sense framework and because of that fixed positioning mostly works fine.</p>
<p>JavaScript touch scroll libraries offer a way out of this mess by trying to provide stable cross platform scroll emulation. Basically the idea is to attach JavaScript handlers to document&#8217;s touch events, detect swipe gestures on scrollable element, and emulate scroll behavior with CSS3 transitions. At first these JavaScript libraries enabled only basic scrolling, but today there are features like pinch zoom, fancy fading scrollbars, pull to refresh, etc. </p>
<h2>iOS devices</h2>
<p>On iOS there no support for position fixed until version 5 that only recently came out. By far the best library to use is <a href="http://cubiq.org/iscroll-4">Matteo Spinelli&#8217;s iScroll</a> because of both features it offers and overall smoothness that almost resembles native scroll. Current version is 4 which is a complete rewrite of older iScroll 3 and offers much more than just scrolling. It comes in two flavors, full version with all features and support for desktop browsers, and lite version which offers only touch scrolling in mobile Webkit. It&#8217;s written in pure JavaScript and doesn&#8217;t require any third party library to function (e.g. jQuery). Unlike version 3, iScroll v4 no longer supports automatic refresh when content updates so you&#8217;ll have to call refresh method manually. Although performance is very good, you might want to use native scroll in iOS5 which can be detected through browser&#8217;s user agent.<br />
<code><br />
if ((navigator.userAgent.match(/iPhone/i)<br />
&nbsp;&nbsp;|| navigator.userAgent.match(/iPod/i)<br />
&nbsp;&nbsp;|| navigator.userAgent.match(/iPad/i))<br />
&nbsp;&nbsp;&amp;&amp; navigator.userAgent.match(/ OS 5_/i)) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// do not use iScroll<br />
}<br />
</code></p>
<h2>Android</h2>
<p>To get usable and consistent scroll experience on Android proved to be a real challenge. Although position fixed is officially supported since version 2.2 this was only partially true and in most cases did not work. We tested a lot of libraries and best one is <a href="https://github.com/neave/touch-scroll">touchScroll jQuery plugin by Paul Neave</a>. Under the hood it uses the same scrolling logic as iScroll but works much better and refreshes automatically when content updates. Few things to keep in mind is that there&#8217;s a bug causing content flicker when elastic bounce is turned off so it&#8217;s best to leave it active. Also there&#8217;s no way of destroying touchScroll once it&#8217;s been activated.<br />
<br />
One other bug we noticed is present only on vanilla Androids (e.g. Nexus S) where scroll freezes after returning to page using back button. To fix this rewrite touch event bindings to use addEventListener instead of jQuery bind() method and fix bug in getTouches(e) method:</p>
<p><code><br />
function getTouches(e) {<br />
&nbsp;&nbsp;if (e.originalEvent) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (e.originalEvent.touches &amp;&amp; e.originalEvent.touches.length) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e.originalEvent.touches;<br />
&nbsp;&nbsp;&nbsp;&nbsp;} else if (e.originalEvent.changedTouches &amp;&amp; e.originalEvent.changedTouches.length) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e.originalEvent.changedTouches;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (e.touches.length) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e.touches;<br />
&nbsp;&nbsp;&nbsp;&nbsp;} else if (e.changedTouches.length) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e.changedTouches;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return null;<br />
}<br />
</code><br />
Like I said before HTCs handle position fixed much better so you might want to use native scroll. This will also prevent problems with input fields being offset that sometimes occur on HTC devices. For detection you can once again use user agent string but it&#8217;s not 100% reliable because Android browser allows user to change it.<br />
<code><br />
if (navigator.userAgent.match(/ HTC/i)<br />
&nbsp;&nbsp;// other Androids that don't have HTC in user agent<br />
&nbsp;&nbsp;|| navigator.userAgent.match(/ Desire_A8181/i)<br />
&nbsp;&nbsp;|| navigator.userAgent.match(/ myTouch4G/i)<br />
&nbsp;&nbsp;|| navigator.userAgent.match(/ ADR6200/i)) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// do not use touchScroll<br />
}<br />
</code></p>
<h2>Tips for better performance</h2>
<ul>
<li>1. do not use CSS gradients</li>
<li>2. keep content simple and reduce number of html elements</li>
<li><b>3. if possible avoid JavaScript scroll entirely. From user experience point of view mobile web sites shouldn&#8217;t try to emulate mobile application with fixed header and footer</b></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fiveminutes.eu/cross-platform-javascript-touch-scrolling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

