<?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>Everyday Developer</title>
	<atom:link href="http://www.aviyehuda.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aviyehuda.com</link>
	<description>http://www.aviyehuda.com</description>
	<lastBuildDate>Sun, 25 Dec 2011 06:00:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Use Clover to generate code coverage reports of your integration/automation tests</title>
		<link>http://www.aviyehuda.com/2011/12/use-clover-to-generate-code-coverage-reports-of-your-integrationautomation-tests/</link>
		<comments>http://www.aviyehuda.com/2011/12/use-clover-to-generate-code-coverage-reports-of-your-integrationautomation-tests/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 04:45:29 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Clover]]></category>
		<category><![CDATA[code_coverage]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=885</guid>
		<description><![CDATA[Clover is a great tool for generating code coverage reports from your unit tests. It can be executed as a plugin in Eclipse, Maven or Ant. However, not everyone knows that it can also be used to collect coverage data of integration tests. This post explains how to collect coverage data with clover at runtime. [...]]]></description>
			<content:encoded><![CDATA[<p><!-- img style="float:left;padding:10px;" src="/images/clover/clover_anim.gif" / --><br />
<img style="float:left;padding:10px;" src="http://www.atlassian.com/en/wac/software/clover/overview/productLogo/imageBinary/clover_logo_landing.png"  /><br />
<a href="http://www.atlassian.com/software/clover/">Clover</a> is a great tool for generating code coverage reports from your unit tests. It can be executed as a plugin in Eclipse, Maven or Ant.<br />
However, not everyone knows that it can also be used to collect coverage data of integration tests.<br />
This post explains how to collect coverage data with clover at runtime.<br />
This post assumes that you already know what are unit and integration tests.<br />
This post assumes that you know what Clover is, and already used it either with Eclipse, Ant or Maven.</p>
<p><font color='red'>*</font>Let me assured you that even though the directions bellow seems complicated and clumsy at first, after doing them once or twice it is really easy to repeat them.</p>
<p><br/><br />
<strong>Motivation</strong><br />
The default action of Clover is to gather code coverage information during build time or compile time. Therefore, This information includes just the coverage data created by unit tests.</p>
<p>If you are developing web applications, you probably use more technologies to test your applications beside unit tests. These technologies may include HTTPUnit/<a href="http://www.aviyehuda.com/category/java/java-technologies/htmlunit-java-technologies-java/">HTMLUnit </a>or automation technologies (like Selenium). These technologies do not work at build time, they can only work during run time, where a web server is up and running and HTTP calls are made.<br />
As a result, the code coverage made during build time is not reflecting the actual code coverage. We should be able to test the coverage while a server is running.</p>
<p><br/><br />
<strong>The idea</strong><br />
The idea is that we will first run clover regularly during build time. We will than take the clover artifacts, put them in our server and then run the integration tests.<br />
While running the integration tests, the clover database will be updated and we would be able to generate reports from it which will reflect both unit and integration tests.</p>
<p><br/><br />
<strong>Step 1 &#8211; Preparation</strong></p>
<ul>
<li>Make sure that you have a web/application server (Tomcat/JBoss/weblogic&#8230;) with your web application already deployed.</li>
<li>Execute clover on your application as you would normally do (either by compiling the code on eclipse or by building with Maven or Ant, it doesn&#8217;t matter).<br />
<br/>The result of this action would be:</p>
<ol>
<li><strong>Clover DB files.</strong><br />
One of the outcome of executing the clover on your code are the DB files.<br />
The DB files hold all the information about your code and the coverage itself.</p>
<p>The location of those files may change depending on the way you use clover and according to the way you configured clover in your environment.</p>
<p>This is how the files looks like<br />
<center><img src="/images/clover/db.png" /></center></p>
<p>the .db file holds the information regarding your code (classes, methods and so on). All the other files hold all the coverage data.</p>
<p>It is important that you will locate those files because we are going to use them in the next step.</li>
<li><strong>An instrumented code.</strong><br />
Another outcome of clover is that it instruments your code. A clover call is injected into each method so it would be reported in the coverage calculation.<br />
We will need this code. we will use this instrumented code in runtime to update the coverage data.</p>
<p>If you use Eclipse than the generated classes would be instrumented. If you use Maven or Ant than most chances are that a jar with all the instrumented code would be generated separately.<br />
Search the instrument code jar. Again, I can&#8217;t tell you exactly where it is located, but usually it generates a jar with a &#8216;clover&#8217; postfix. Example: if your jar name is my_app.jar, than the generated instrumented code jar will probably be something like my_app-clover.jar.<br />
So you will need to do some detective work here to find the instrumented classes/jar. If you are not sure whether the classes are instrumented or not, just decompile one of them with  Jad and search for the word clover inside of it.	</li>
<li><strong>A code coverage report.</strong><br />
This is a report with the unit test coverage. We don&#8217;t really need this, but it would be good so that we would be able to compare it with the report we will generate at the end.</li>
</ol>
</li>
</ul>
<p><br/><br />
<strong>Step 2 &#8211; Updating the server</strong><br />
The next steps are very important, please make sure you do them properly.</p>
<ul>
<li>Replacing the existing application jar/classes with the instrumented jar/classes.<br />
Take the instrumented jar/classes  that were created by the clover and add it to your server&#8217;s classpath instead of the original jar/classes.<br />
The instrumented code will cause the clover DB to be updated with the runtime data.</li>
<p><br/></p>
<li>Adding clover jars and license.<br />
Since we will use clover on runtime we will need also the clover jars in our server&#8217;s classpath.<br />
So add the clover own jars to your server&#8217;s classpath. If you are using clover with Eclipse than these jars are located in the plugin folder of Eclipse. If you are using Maven than they will be loacted in your repository.</p>
<p><font color='red'>*</font> Make sure you are using the same version of clover in your server as you used to generate the DB files and instrumented code, otherwise it will not work and you will get error messages.<br />
Also add the clover license file to the same location as the jars.</li>
<p><br/>
<li>Adding the clover <a href="http://www.aviyehuda.com/java/">java </a>argument.<br />
Add the following java arg <strong>-Dclover.initstring.basedir={<em>location of the db files that were created by the clover</em>}</strong>.<br />
<font color='red'>*</font>Notice &#8211; the path you have entered above is the path of the <strong>folder </strong>which contains the DB files.<br />
Example:<br />
-Dclover.initstring.basedir=C:/workspace/MyWebApp/target/clover.<br />
This java argument is used by the clover to locate the DB files and update them.</li>
</ul>
<p><br/><br />
<strong>Step 3 &#8211; Restarting the server and running the tests</strong><br />
Now that hopefully all is set properly all that you need to do now is to restart your server and than running your integration tests.<br />
The tests should trigger the instrumented code which will call the clover API&#8217;s and will update the clover DB. </p>
<ol>
While running the tests:</p>
<li>Look at your log/console and search for error messages from clover.</li>
<li>Look at the folder which holds the clover DB files. If everything is going as it should, new files will be created in this folder while running the tests. </li>
</ol>
<p>If not everything is going well the first time, don&#8217;t discourage, just go over each of the steps again.</p>
<p><br/><br />
<strong>Step 4  &#8211; Generating an updated report</strong><br />
If everything went well and new files were created in the DB folder than that means you just need to generate a new report.<br />
If you are using clover with eclipse than you can simply push the reload button <img src="/images/clover/refresh.png"  />  to reload the coverage data.<br />
If you are using Maven or Ant you can execute just the task which generates the report.<br />
Another way is to use the clover <a href="http://confluence.atlassian.com/display/CLOVER/HtmlReporter">HtmlReporter </a>to generate a report easily.</p>
<p>Now compare the new report to the old report. You should see that the new report coverage is much bigger than the old one since it contains also the integration tests coverage.</p>
<p><font color='red'>*</font>Notice that not all the data is updated, even though the percentages are being updated, for some reason the calls counter does not.</p>
<p><br/><br />
To summarize. As mentioned; yes, these instructions seems a bit complicated but after you succeed the first time, it is very easy to repeat it. In the company I work for we even made this whole process automatic and we are able to generate a full coverage report with unit and integrated tests combined.</p>
<p><br/><br />
<center><img src="/images/clover/report.png" width="50%" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/12/use-clover-to-generate-code-coverage-reports-of-your-integrationautomation-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android development &#8211; Custom Animation</title>
		<link>http://www.aviyehuda.com/2011/07/android-development-custom-animation/</link>
		<comments>http://www.aviyehuda.com/2011/07/android-development-custom-animation/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:19:15 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1841</guid>
		<description><![CDATA[&#160; Android developers web site provide you with 2 predefined animation techniques which you can use in your applications &#8211; Tween animation and frame animation. They are super easy to implement and work quite nice. If you are using Android 3.0 or above, you should check out Property Animation technicqe. But what if you need [...]]]></description>
			<content:encoded><![CDATA[<table >
<tr>
<td><img src="/images/android_anim.jpg" alt="android" width="120"  /></td>
<td width="5%" >&nbsp;</td>
<td style="vertical-align: top" ><em>Android developers web site provide you with 2 predefined animation techniques which you can use in your applications &#8211; <a href="http://developer.android.com/guide/topics/graphics/view-animation.html#tween-animation">Tween animation </a> and <a href="http://developer.android.com/guide/topics/graphics/view-animation.html#frame-animation">frame animation</a>. They are super easy to implement and work quite nice.<br />
If you are using Android 3.0 or above, you should check out <a href="http://developer.android.com/guide/topics/graphics/animation.html">Property Animation </a>technicqe. </em></td>
</tr>
<tr>
<td colspan=3 valign='top' ><em>But what if you need to create your own customized animations and you are using older versions? Don&#8217;t worry, that is easy to do as well, here is how you do it.</em>
</td>
</tr>
</table>
<p><br/></p>
<p>To create a customized animation you need to follow these 3 steps.<br />
For the explanation, we will create a simple animation that changes the background of a button gradually from black to red.</p>
<p><strong>Step 1 &#8211; Extend the Animation class and set the properties</strong><br />
Create a class which extends Android <a href="http://developer.android.com/reference/android/view/animation/Animation.html">Animation </a>class.<br />
This class will hold the logic of your animation.<br />
See my example:</p>
<pre class="brush: java; title: ; notranslate">
public class BGColorAnimation extends Animation {

	private View view;
	private int currentRedColor;

	//The steps to skip between colors
	private static int STEP_SIZE=30;
	private static int ANIMATION_DURATION=50;

	public BGColorAnimation(View view) {
		this.view=view;
		setDuration(ANIMATION_DURATION);
		setRepeatCount(255/STEP_SIZE);
		setFillAfter(true);
		setInterpolator(new AccelerateInterpolator());

		setAnimationListener(new MyAnimationListener());
	}
}
</pre>
<ul>
<li>As you see, there is not much in this class since my animation is not that complicated.</li>
<li>Notice that I have made all the necessary animation parameters initialization from inside the constructor, but you can defiantly initialize them from outside the class.</li>
<li>There are 2 important parameters which determines the behavior of the animation:
<ol>
<li>RepeatCount &#8211; the number of steps this animation has.</li>
<li>Duration &#8211; the sleep time between 2 steps.</li>
</ol>
</li>
<li>On each step, the animation listener will be triggered.</li>
</ul>
<p><strong>Step 2 &#8211; Implement AnimationListener interface</strong><br />
Create a class which implements <a href="http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html">Animation.AnimationListener</a>.<br />
As mentioned, it is triggered on each animation step.</p>
<pre class="brush: java; title: ; notranslate">
class MyNumbersAnimationListener implements AnimationListener{
	    	private int index;

	    	class MyAnimationListener implements AnimationListener{

		@Override
		public void onAnimationEnd(Animation animation) {

		}

		@Override
		public void onAnimationRepeat(Animation animation) {
			// Change color of the view
			view.setBackgroundColor(
				Color.rgb(currentRedColor+=STEP_SIZE, 0, 0));
		}

		@Override
		public void onAnimationStart(Animation animation) {
			view.setBackgroundColor(Color.BLACK);
			currentRedColor=0;
		}

	}
</pre>
<p><br/><br />
In fact, I see no reason why not doing both steps in the same class:<br />
<br/></p>
<pre class="brush: java; title: ; notranslate">
public class BGColorAnimation extends Animation implements
		Animation.AnimationListener {

	private View view;
	private int currentRedColor;

	// The steps to skip between colors
	private static int STEP_SIZE= 30;
	private static int ANIMATION_DURATION = 50;

	public BGColorAnimation(View view) {
		this.view = view;
		setDuration(ANIMATION_DURATION);
		setRepeatCount(255 / STEP_SIZE);
		setFillAfter(true);
		setInterpolator(new AccelerateInterpolator());

		setAnimationListener(this);
	}

	@Override
	public void onAnimationEnd(Animation animation) {

	}

	@Override
	public void onAnimationRepeat(Animation animation) {
		view.setBackgroundColor(
			Color.rgb(currentRedColor += STEP_SIZE, 0, 0));
	}

	@Override
	public void onAnimationStart(Animation animation) {
		view.setBackgroundColor(Color.BLACK);
		currentRedColor = 0;
	}

}
</pre>
<p><strong>Step 3 &#8211; Start the animation from a view</strong><br />
Animations are triggered from a view.<br />
Example:</p>
<pre class="brush: java; title: ; notranslate">
Button button = (Button)findViewById(R.id.b_colors);
button.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					button.startAnimation(new BGColorAnimation(button));
				}
			});
</pre>
<p><a href="/downloads/AnimationTest.zip"><img src="/ficons/zip.gif" alt="zip"> Download demo project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/07/android-development-custom-animation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Android quick tip: use System.arraycopy()</title>
		<link>http://www.aviyehuda.com/2011/06/android-quick-tip-use-system-arraycopy/</link>
		<comments>http://www.aviyehuda.com/2011/06/android-quick-tip-use-system-arraycopy/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 22:15:22 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1844</guid>
		<description><![CDATA[Well it&#8217;s a well known fact that the java native function System.arraycopy() is a useful way to copy one array to another since it is native, but is that also the case for Android? And if so, how much more useful is it? To answer these questions I have made a simple test and ran [...]]]></description>
			<content:encoded><![CDATA[<p>Well it&#8217;s a well known fact that the java native function <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#arraycopy(java.lang.Object, int, java.lang.Object, int, int)"> System.arraycopy()</a> is a useful way to copy one array to another since it is native, but is that also the case for Android? And if so, how much more useful is it?</p>
<p>To answer these questions I have made a simple test and ran it as a java program on my PC and than as an Android activity. </p>
<p>Here is the test for the PC:</p>
<pre class="brush: java; title: ; notranslate">
 private static final int SIZE_OF_ARRAY = 10000000;
	private static long time;

	public static void main(String[] args) {

		        Integer [] sourceArray = new Integer[SIZE_OF_ARRAY];
		        Integer [] destinationArray = new Integer[SIZE_OF_ARRAY];
		        fillArray(sourceArray);

		        startBenchmark();
		        naiveCopy(sourceArray,destinationArray);
		        stopBenchmark();

		        startBenchmark();
		        System.arraycopy(sourceArray, 0, destinationArray, 0,
						  sourceArray.length);
		        stopBenchmark();
		    }

			private static void naiveCopy(Integer [] src, Integer [] dst) {
				for (int i = 0; i &lt; src.length; i++) {
					dst[i]=src[i];
				}

			}

			private static void fillArray(Integer [] src) {
				for (int i = 0; i &lt; src.length; i++) {
					src[i]=i;
				}

			}

			private static void startBenchmark() {
				time = System.currentTimeMillis();
			}

			private static void stopBenchmark() {
				time = System.currentTimeMillis() - time;
				System.out.println( &quot;time=&quot;+time);

			}
</pre>
<p>Here are the results while running it from my PC (java 7, 8GB memory, CPU intel i5):<br />
Naive algorithm &#8211; 14 ms<br />
System.arraycopy(); &#8211; 6 ms.</p>
<p>Arraycopy does the task in less than half of the time.</p>
<p>Now to use it on Android &#8211; here is the code:</p>
<pre class="brush: java; title: ; notranslate">
public class ArrayCopyTestActivity extends Activity {
    private static final int SIZE_OF_ARRAY = 1000000;
	private long time;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Integer [] sourceArray = new Integer[SIZE_OF_ARRAY];
        Integer [] dst = new Integer[SIZE_OF_ARRAY];
        fillArray(sourceArray);

        startBenchmark();
        naiveCopy(sourceArray,dst);
        stopBenchmark();

        startBenchmark();
        System.arraycopy(sourceArray, 0, dst, 0, sourceArray.length);
        stopBenchmark();
    }

	private void naiveCopy(Integer [] src, Integer [] dst) {
		for (int i = 0; i &lt; src.length; i++) {
			dst[i]=src[i];
		}

	}

	private void fillArray(Integer [] src) {
		for (int i = 0; i &lt; src.length; i++) {
			src[i]=i;
		}

	}

	private void startBenchmark() {
		time = System.currentTimeMillis();
	}

	private void stopBenchmark() {
		time = System.currentTimeMillis() - time;
		Log.d(&quot;array copy test&quot;, &quot;time=&quot;+time);

	}
}
</pre>
<p>* Notice I have reduced the size of the Array from 10 million to 1 million, this is due to restrictions on memory for applications in Android.</p>
<p><br/><br />
The results from running it on my device (nexus 1):<br />
Naive algorithm &#8211; <font color=red>182 ms</font><br />
System.arraycopy(); &#8211; 12 ms.</p>
<p>This means that the fact that System.arraycopy() is better than the regular copy is even more true for Android.<br />
In short than, always use  <strong>System.arraycopy()</strong> especially on Android.</p>
<p><a href="/downloads/arraycopy/ArrayCopyTest.java"><img src="/ficons/text.gif" alt="" /> Test for PC</a><br />
<a href="/downloads/arraycopy/ArrayCopyTestActivity.java"><img src="/ficons/text.gif" alt="" /> Test for Android</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/06/android-quick-tip-use-system-arraycopy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HtmlUnit &#8211; A quick introduction</title>
		<link>http://www.aviyehuda.com/2011/05/htmlunit-a-quick-introduction/</link>
		<comments>http://www.aviyehuda.com/2011/05/htmlunit-a-quick-introduction/#comments</comments>
		<pubDate>Mon, 16 May 2011 11:20:31 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[HtmlUnit]]></category>
		<category><![CDATA[integration_tests]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=888</guid>
		<description><![CDATA[HtmlUnit is an open source java library for creating HTTP calls which imitate the browser functionality. HtmlUnit is mostly used for integration testing upon Unit test frameworks such as JUnit or TestNG. This is done by requesting web pages and asserting the results. Simple Example WebClient As you can see in the example, the WebClient [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li> HtmlUnit is an open source java library for creating HTTP calls which imitate the browser functionality.
</li>
<li> HtmlUnit is mostly used for integration testing upon Unit test frameworks such as JUnit or TestNG. This is done by requesting web pages and asserting the results.
</li>
</ul>
<p><a name="Simple_Example"></a><br />
<h2> Simple Example </h2>
<hr />
<pre class="brush: java; title: ; notranslate">@Test
public void testGoogle(){
	WebClient webClient = new WebClient();
	HtmlPage currentPage = webClient.getPage(&quot;http://www.google.com/&quot;);
	assertEquals(&quot;Google&quot;, currentPage.getTitleText());
}</pre>
<p><a name="WebClient"></a><br />
<h2> WebClient </h2>
<hr />
<ul>
<li> As you can see in the example, the WebClient is the starting point. It is the browser simulator.
</li>
<li> WebClient.getPage() is just like typing an address in the browser. It returns an HtmlPage object.
</li>
</ul>
<p><a name="HtmlPage"></a><br />
<h2> HtmlPage </h2>
<hr />
<ul>
<li> HtmlPage represents a single web page along with all of it&#8217;s client&#8217;s data (HTML, JavaScript, CSS &#8230;).
</li>
<li> The HtmlPage lets you access to many of a web page content:
</li>
</ul>
<p><a name="Page_source"></a><br />
<h3> Page source </h3>
<ul>
<li> You can receive the page source as text or as XML.
</li>
</ul>
<pre class="brush: java; title: ; notranslate">HtmlPage currentPage =
		webClient.getPage(&quot;http://www.google.com/&quot;);
String textSource = currentPage.asText();
String xmlSource = currentPage.asXml();</pre>
<p><a name="HTML_Elements"></a><br />
<h3> HTML Elements </h3>
<ul>
<li> HtmlPage lets you ability to access any of the page HTML elements and all of their attributes and sub elements. This includes tables, images, input fields, divs or any other Html element you may imagine.
</li>
<li> Use the function <b>getHtmlElementById()</b> to get any of the page elements.
</li>
</ul>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage = webClient.getPage(&quot;http://www.google.com/&quot;);
HtmlImage imgElement = (HtmlImage)currentPage.getHtmlElementById(&quot;logo&quot;);
System.out.println(imgElement.getAttribute(&quot;src&quot;));</pre>
<p><a name="Anchors"></a><br />
<h3> Anchors </h3>
<ul>
<li> Anchor is the representation of the Html tag <i>&lt;a href=&#8221;&#8230;&#8221; &gt;link&lt;/a&gt;</i>.
</li>
<li> Use the functions <b>getAnchorByName()</b>, <b>getAnchorByHref()</b> and <b>getAnchorByText()</b> to easily access any of the anchors in the page.
</li>
</ul>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage = webClient.getPage(&quot;http://www.google.com/&quot;);
HtmlAnchor advancedSearchAn =
		currentPage.getAnchorByText(&quot;Advanced Search&quot;);
currentPage = advancedSearchAn.click();
assertEquals(&quot;Google Advanced Search&quot;,currentPage.getTitleText());</pre>
<p><a name="Dom_elements_by_XPath"></a><br />
<h3> Dom elements by XPath </h3>
<ul>
<li> You can access any of the page elements by using <a href="http://www.w3schools.com/xpath/xpath_syntax.asp" class="external text" title="http://www.w3schools.com/xpath/xpath_syntax.asp" rel="nofollow">XPath</a>.
</li>
</ul>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage =
	webClient.getPage(&quot;http://www.google.com/search?q=avi&quot;);

//Using XPath to get the first result in Google query
HtmlElement element = (HtmlElement)currentPage.getByXPath(&quot;//h3&quot;).get(0);
DomNode result = element.getChildNodes().get(0);</pre>
<p><a name="Form_control"></a><br />
<h3> Form control </h3>
<ul>
<li> A large part of controlling your HTML page is to control the form elements:</p>
<ul>
<li> HtmlForm
</li>
<li> HtmlTextInput
</li>
<li> HtmlSubmitInput
</li>
<li> HtmlCheckBoxInput
</li>
<li> HtmlHiddenInput
</li>
<li> HtmlPasswordInput
</li>
<li> HtmlRadioButtonInput
</li>
<li> HtmlFileInput
</li>
</ul>
</li>
</ul>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage = webClient.getPage(&quot;http://www.google.com/&quot;);

//Get the query input text
HtmlInput queryInput = currentPage.getElementByName(&quot;q&quot;);
queryInput.setValueAttribute(&quot;aviyehuda&quot;);

//Submit the form by pressing the submit button
HtmlSubmitInput submitBtn = currentPage.getElementByName(&quot;btnG&quot;);
currentPage = submitBtn.click();</pre>
<p><a name="Tables"></a><br />
<h3> Tables </h3>
<pre class="brush: java; title: ; notranslate">currentPage = webClient.getPage(&quot;http://www.google.com/search?q=htmlunit&quot;);
final HtmlTable table = currentPage.getHtmlElementById(&quot;nav&quot;);
for (final HtmlTableRow row : table.getRows()) {
System.out.println(&quot;Found row&quot;);
    for (final HtmlTableCell cell : row.getCells()) {
       System.out.println(&quot;   Found cell: &quot; + cell.asText());
    }
}</pre>
<p><a name="JavaScript_support"></a><br />
<h2> JavaScript support </h2>
<hr />
<ul>
<li> HtmlUnit uses the <a href="http://www.mozilla.org/rhino/" class="external text" title="http://www.mozilla.org/rhino/" rel="nofollow">Mozilla Rhino</a> JavaScript engine.
</li>
<li> This lets you the ability to run pages with JavaScript or even run JavaScript code by command.
</li>
</ul>
<pre class="brush: java; title: ; notranslate">ScriptResult result = currentPage.executeJavaScript(JavaScriptCode);</pre>
<ul>
<li> By default JavaScript exceptions will crash your tests. If you wish to ignore JavaScript exceptions use this:
</li>
</ul>
<pre class="brush: java; title: ; notranslate">webClient().setThrowExceptionOnScriptError(false);</pre>
<ul>
<li> If you would like to turn off the JavaScript all together, use this:
</li>
</ul>
<pre class="brush: java; title: ; notranslate">currentPage.getWebClient().setJavaScriptEnabled(false);</pre>
<p><a name="HTTP_elements"></a><br />
<h2> HTTP elements </h2>
<hr />
<a name="URL"></a><br />
<h3> URL </h3>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage =
	webClient.getPage(&quot;http://www.google.co.uk/search?q=htmlunit&quot;);
URL url = currentPage.getWebResponse().getRequestSettings().getUrl()</pre>
<p><a name="Response_status"></a><br />
<h3> Response status </h3>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage = webClient.getPage(&quot;http://www.google.com/&quot;);
assertEquals(200,currentPage.getWebResponse().getStatusCode());
assertEquals(&quot;OK&quot;,currentPage.getWebResponse().getStatusMessage());</pre>
<p><a name="Cookies"></a><br />
<h3> Cookies </h3>
<pre class="brush: java; title: ; notranslate">Set&lt;Cookie&gt; cookies = webClient.getCookieManager().getCookies();
for (Cookie cookie : cookies) {
	System.out.println(cookie.getName() + &quot; = &quot; + cookie.getValue());
}</pre>
<p><a name="Response_headers"></a><br />
<h3> Response headers </h3>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage =
	webClient.getPage(&quot;http://www.google.com/search?q=htmlunit&quot;);

List&lt;NameValuePair&gt; headers =
	currentPage.getWebResponse().getResponseHeaders();
for (NameValuePair header : headers) {
	System.out.println(header.getName() + &quot; = &quot; + header.getValue());
}</pre>
<p><a name="Request_parameters"></a><br />
<h3> Request parameters </h3>
<pre class="brush: java; title: ; notranslate">List&lt;NameValuePair&gt; parameters =
	currentPage.getWebResponse().getRequestSettings().getRequestParameters();
for (NameValuePair parameter : parameters) {
	System.out.println(parameter.getName() + &quot; = &quot; + parameter.getValue());
}</pre>
<p><a name="Making_assertions"></a><br />
<h2> Making assertions </h2>
<hr />
<ul>
<li> HtmlUnit comes with a set of assetions:
</li>
</ul>
<pre>   assertTitleEquals(HtmlPage, String)
   assertTitleContains(HtmlPage, String)
   assertTitleMatches(HtmlPage, String)
   assertElementPresent(HtmlPage, String)
   assertElementPresentByXPath(HtmlPage, String)
   assertElementNotPresent(HtmlPage, String)
   assertElementNotPresentByXPath(HtmlPage, String)
   assertTextPresent(HtmlPage, String)
   assertTextPresentInElement(HtmlPage, String, String)
   assertTextNotPresent(HtmlPage, String)
   assertTextNotPresentInElement(HtmlPage, String, String)
   assertLinkPresent(HtmlPage, String)
   assertLinkNotPresent(HtmlPage, String)
   assertLinkPresentWithText(HtmlPage, String)
   assertLinkNotPresentWithText(HtmlPage, String)
   assertFormPresent(HtmlPage, String)
   assertFormNotPresent(HtmlPage, String)
   assertInputPresent(HtmlPage, String)
   assertInputNotPresent(HtmlPage, String)
   assertInputContainsValue(HtmlPage, String, String)
   assertInputDoesNotContainValue(HtmlPage, String, String)
</pre>
<p><br/></p>
<ul>
<li> You can still of course use the framework&#8217;s assertions. For example, if you are using JUnit, you can still use assertTrue() and so on.
</li>
<li> Here are a few examples:
</li>
</ul>
<pre class="brush: java; title: ; notranslate">WebClient webClient = new WebClient();
HtmlPage currentPage =
      webClient.getPage(&quot;http://www.google.com/search?q=htmlunit&quot;);

assertEquals(200,currentPage.getWebResponse().getStatusCode());
assertEquals(&quot;OK&quot;,currentPage.getWebResponse().getStatusMessage());
WebAssert.assertTextPresent(currentPage, &quot;htmlunit&quot;);
WebAssert.assertTitleContains(currentPage, &quot;htmlunit&quot;);
WebAssert.assertLinkPresentWithText(currentPage, &quot;Advanced search&quot;);
assertTrue(currentPage.getByXPath(&quot;//h3&quot;).size()&gt;0); //result number
assertNotNull(webClient.getCookieManager().getCookie(&quot;NID&quot;));</pre>
<p><a name="External_links"></a><br />
<h2> See also </h2>
<hr />
<ul>
<li> <a href="http://htmlunit.sourceforge.net/" class="external text" title="http://htmlunit.sourceforge.net/" rel="nofollow">Product main page</a>
</li>
<li> <a href="http://sourceforge.net/projects/htmlunit/" class="external text" title="http://sourceforge.net/projects/htmlunit/" rel="nofollow">Download page</a>
</li>
<li> <a href="http://htmlunit.sourceforge.net/dependencies.html" class="external text" title="http://htmlunit.sourceforge.net/dependencies.html" rel="nofollow">Jar dependencies</a>
</li>
</ul>
<p><br/></p>
<p><a href="/downloads/htmlUnitExample.zip"><img src="/ficons/zip.gif">&nbsp;Download example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/05/htmlunit-a-quick-introduction/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Android Development &#8211; Preferences</title>
		<link>http://www.aviyehuda.com/2011/05/android-development-preferences/</link>
		<comments>http://www.aviyehuda.com/2011/05/android-development-preferences/#comments</comments>
		<pubDate>Sun, 08 May 2011 02:15:59 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1667</guid>
		<description><![CDATA[&#160; If you have ever developed an application for mobile, most chances are you have found yourself wanting to create a settings page. The user uses the settings page to set configuration parameters and these parameters are saved even after the program is closed. In this post I will explain how to create a settings [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="/images/preferences/android_preferences.jpg" alt="android" width="120"  /></td>
<td width="5%" >&nbsp;</td>
<td style="vertical-align: top" ><em>If you have ever developed an application for mobile, most chances are you have found yourself wanting to create a settings page.<br />
The user uses the settings page to set configuration parameters and these parameters are saved even after the program is closed.<br />
In this post I will explain how to create a settings page very easily. All code examples are available to download at the bottom.</em>
</td>
</tr>
</table>
<p><br/><br />
Android designers have developed a framework to make the developers life a lot easier.<br />
Preference Framework is a framework composed of a hierarchy of preference objects which are translated to UI objects.<br />
This mechanism is built on top of the <strong>shared preferences</strong> mechanism which stores the values.</p>
<p><br/><strong>Shared Preferences Mechanism</strong><br />
Before we can explain how to build a settings page with the preferences framework we need to get to know the shared preferences mechanism.<br />
<a href="http://developer.android.com/reference/android/content/SharedPreferences.html">Shared Preferences</a> is a simple  key-value storage mechanism of primitive types and Strings.<br />
These values are stored even if the program is terminated.<br />
Use it to store simple variables you wish to save between sessions of the program.</p>
<pre class="brush: java; title: ; notranslate">public class MyActivity extends Activity {
     @Override
    protected void onCreate(Bundle state){
       super.onCreate(state);

// Restore preferences
       SharedPreferences settings = getSharedPreferences(“MyParams”, 0);  // zero is the default
       boolean booleanParam = settings.getBoolean(&quot;booleanParam&quot;, false); //false is the defaulr
    }

    @Override
    protected void onStop(){
       super.onStop();

	// Change preferences
      SharedPreferences settings = getSharedPreferences(“MyParams”, 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putBoolean(&quot;booleanParam&quot;, true);

	// Save changes
	 editor.commit();        

         }
}</pre>
<p><br/><br />
<strong>Preferences Framework</strong><br />
As mentioned, the preference framework is a framework which is built on top of the shared preferences mechanism.<br />
But opposed to what you have seen above, in this case you don&#8217;t even have to save and load the data every time, the OS does that for you.<br />
Furthermore, this framework offers UI objects that hold persistent preferences.</p>
<p><strong>Types of preferences objects</strong></p>
<ul>
<li>CheckBoxPreference &#8211; displays a checkbox and stores boolean values</li>
<li>EditTextPreference &#8211; displays a edit text box and stores string values</li>
<li>ListPreference  &#8211; displays a drop down list.</li>
<li>RingtonePreference &#8211; displays a list of existing ringtones in the system.</li>
</ul>
<p><br/><br />
<strong>Step 1 &#8211; Creating XML preferences menu</strong><br />
First we will create the XML file which represents our settings page.</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;PreferenceScreen
	xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
	android:title=&quot;Settings&quot;&gt;
	&lt;PreferenceCategory android:title=&quot;First Category&quot;&gt;
		&lt;CheckBoxPreference android:key=&quot;MyBoolean&quot;
			android:title=&quot;Boolean Value&quot;&gt;&lt;/CheckBoxPreference&gt;
		&lt;EditTextPreference android:key=&quot;MyText&quot;
			android:title=&quot;String Value&quot;
			android:dialogTitle=&quot;Edit this text&quot;
			android:dependency=&quot;MyBoolean&quot;&gt;&lt;/EditTextPreference&gt;
	&lt;/PreferenceCategory&gt;

	&lt;PreferenceCategory android:title=&quot;Seconed Category&quot;&gt;
		&lt;RingtonePreference android:showDefault=&quot;true&quot;
			android:key=&quot;Audio&quot; android:title=&quot;Select sound&quot;
			android:ringtoneType=&quot;notification&quot;&gt;
		&lt;/RingtonePreference&gt;
		&lt;ListPreference android:title=&quot;Group Choice Test &quot;
			android:entries=&quot;@array/PreferencesGroupItems&quot;
			android:entryValues=&quot;@array/PreferencesGroupValues&quot;
			android:dialogTitle=&quot;Choose an option please&quot;&gt;
		&lt;/ListPreference&gt;
	&lt;/PreferenceCategory&gt;
&lt;/PreferenceScreen&gt;</pre>
<p>*Notice: </p>
<ul>
<li>You can create categories to divide the preferences to groups according to the context. Here we have created 2 categories.</li>
<li>ListPreference requires 2 arrays, one for the values and one for the labels. Both are taken from values/strings.xml.</li>
<li>You can create dependency between prefrences by using the dependency field. For example, I have made the text field depended on the checkbox, which means, it will be disabled if the checkbox is not checked. </li>
<li>Put this xml file under /res/xml/my_prefrences.xml</li>
</ul>
<p><br/><br />
<strong>Step 2 &#8211; Extending the PrefrencesActivity</strong></p>
<pre class="brush: java; title: ; notranslate">public class PreferencesActivity extends PreferenceActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.my_prefrences);
	}

}</pre>
<ul>
<li>As you see, all this activity does is to load the preferences xml file.</li>
</ul>
<p><br/><br />
<strong>Step 3 &#8211; Calling the PrefrencesActivity</strong><br />
Now we will create a button in our main activity that will trigger the preferences activity.</p>
<pre class="brush: java; title: ; notranslate"> @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ((Button)findViewById(R.id.Button01))
		.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent settingsActivity = new Intent(getBaseContext(),
                        PreferencesActivityTest.class);
				startActivity(settingsActivity);

			}
		});
    }</pre>
<p><br/><br />
<strong>Step 4 &#8211; Using the preferences</strong><br />
We can now use the preferences values anywhere in our main Activity.</p>
<pre class="brush: java; title: ; notranslate">SharedPreferences preferences =
			 PreferenceManager.getDefaultSharedPreferences(this);

String myText =	preferences.getString(&quot;MyText&quot;, &quot;default value&quot;);
boolean MyBoolean = preferences.getBoolean(&quot;MyBoolean&quot;, false);</pre>
<p><br/><center><br />
<img src="/images/preferences/device_pref1.png"  /><br />
<br/></center><br />
<strong>Custom Preference</strong><br />
You also have the option to add your own customized preference item.<br />
We will talk about this in another post.</p>
<p><a href="/downloads/PreferencesTest.zip"><img src="/ficons/zip.gif" alt="zip"> Download demo project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/05/android-development-preferences/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android &#8211; Creating links using linkify</title>
		<link>http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/</link>
		<comments>http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 15:42:09 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1597</guid>
		<description><![CDATA[&#160; Linkify is a class that lets you create links from a TextView or a Spannable. You can create links not just to web pages, but also to locations on the map, emails and even phone numbers. *Note: the examples bellow may not always work in the emulator. Web address: Phone number: Map address: Email [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png" alt="android" width="80" /></td>
<td width="5%" >&nbsp;</td>
<td style="vertical-align: top" ><em><a href="http://developer.android.com/reference/android/text/util/Linkify.html">Linkify </a>is a class that lets you create links from a TextView or a Spannable.<br />
You can create links not just to web pages, but also to locations on the map, emails and even phone numbers.</em>
</td>
</tr>
</table>
<p><strong>*Note</strong>: the examples bellow may not always work in the emulator.</p>
<p><br/><strong>Web address:</strong></p>
<pre class="brush: java; title: ; notranslate">TextView myWebSite = new TextView(this);
myWebSite .setText(&quot;http://http://www.dzone.com/&quot;);
Linkify.addLinks(myWebSite , Linkify.WEB_URLS);</pre>
<p><center><br />
<img src="/images/Linkify/linkify1.jpg" alt="" /><br />
</center></p>
<p><br/><strong>Phone number:</strong></p>
<pre class="brush: java; title: ; notranslate">TextView myPhone = (TextView) findViewById(R.id.my_web_site);
myPhone .setText(“5552323233”);
Linkify.addLinks(myPhone  , Linkify.PHONE_NUMBERS);</pre>
<p><center><br />
<img src="/images/Linkify/linkify2.jpg" alt="" /><br />
</center><br />
<br/><strong>Map address:</strong></p>
<pre class="brush: java; title: ; notranslate">TextView myLocation = new TextView(this);
myLocation.setText(&quot;436 Mayfield Ave, Stanford, CA&quot;);
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);</pre>
<p><center><br />
<img src="/images/Linkify/linkify4.jpg" alt="" /><br />
</center></p>
<p><br/><strong>Email address:</strong></p>
<pre class="brush: java; title: ; notranslate">TextView myEmail= (TextView) findViewById(R.id.my_web_site);
myEmail.setText(“aviyehuda@gmail.com”);
Linkify.addLinks(myEmail  , Linkify.EMAIL_ADDRESSES);</pre>
<p><center><br />
<img src="/images/Linkify/linkify3.jpg" alt="" /><br />
</center><br />
<br/><strong>Auto detect:</strong><br />
Use Linkify.ALL to automatically detect the link type.</p>
<pre class="brush: java; title: ; notranslate">Linkify.addLinks(myTextView , Linkify.ALL);</pre>
<p><br/><strong>More than one option:</strong><br />
You can choose more than a single option for the link type.</p>
<pre class="brush: java; title: ; notranslate">Linkify.addLinks(myTextView, Linkify.PHONE_NUMBERS | Linkify.WEB_URLS);</pre>
<p><br/><strong>Using pattern:</strong><br />
You can use a regular expression for detecting text parts and transform only them to links instead of the whole text.</p>
<pre class="brush: java; title: ; notranslate"> TextView myCustomLink = new TextView(this);
Pattern pattern = Pattern.compile(&quot;[a-zA-Z]+&amp;&quot;);
myCustomLink.setText(&quot;press Linkify&amp; or on Android&amp; to search it on google&quot;);
Linkify.addLinks(myCustomLink,pattern, &quot;http://www.google.ie/search?q=&quot;);
mainLayout.addView(myCustomLink);</pre>
<p><center><br />
<img src="/images/Linkify/linkify5.jpg" alt="" /><br />
</center></p>
<p><br/><strong>MatchFilter:</strong><br />
MatchFilter is used for more complicated filters.</p>
<pre class="brush: java; title: ; notranslate">MatchFilter myMatchFilter = new MatchFilter() {
	@Override
	public boolean acceptMatch(CharSequence cs, int start, int end) {
		return start &gt; 48;
	}
};

TextView myCustomLink2 = new TextView(this);
Pattern pattern2 = Pattern.compile(&quot;[a-zA-Z]+&quot;);
myCustomLink2.setText(&quot;press one of these words to search it on google: Android Linkify dzone&quot;);
Linkify.addLinks(myCustomLink2,pattern2, &quot;http://www.google.ie/search?q=&quot;, myMatchFilter, null);
mainLayout.addView(myCustomLink2);</pre>
<p><center><br />
<img src="/images/Linkify/linkify6.jpg" alt="" /><br />
</center>      </p>
<p><br/><strong>TransformFilter:</strong><br />
So fat the text we have filtered stayed the same. But sometimes you need the text to be different than the text which is appended to the link.</p>
<pre class="brush: java; title: ; notranslate">
  TransformFilter myTransformFilter = new TransformFilter() {
	@Override
	public String transformUrl(Matcher match, String url) {
		return url.substring(1); //remove the $ sign
	}
};

TextView myCustomLink3 = new TextView(this);
Pattern pattern3 = Pattern.compile(&quot;\\$[a-zA-Z]+&quot;);
myCustomLink3.setText(&quot;press $Linkify or on $Android to search it on google&quot;);
Linkify.addLinks(myCustomLink3,pattern3, &quot;http://www.google.ie/search?q=&quot;, null, myTransformFilter);
mainLayout.addView(myCustomLink3);</pre>
<p><br/></p>
<p><center><br />
<img src="/images/Linkify/linkify7.jpg" alt="" /><br />
</center></p>
<p><br/><br />
<a href="/downloads/LinkifyTest.java"><img src="/ficons/text.gif" alt="" /> Download code example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android &#8211; Multithreading in a UI environment</title>
		<link>http://www.aviyehuda.com/2010/12/android-multithreading-in-a-ui-environment/</link>
		<comments>http://www.aviyehuda.com/2010/12/android-multithreading-in-a-ui-environment/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 17:45:59 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[multithreading]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1415</guid>
		<description><![CDATA[Why do we need multithreading in Android applications? Let&#8217;s say you want to do a very long operation when the user pushes a button. If you are not using another thread, it will look something like this: What will happen? The UI freezes. This is a really bad UI experience. The program may even crash. [...]]]></description>
			<content:encoded><![CDATA[<p><!--</p>
<p>need to read</p>
<p>http://jyro.blogspot.com/2009/11/android-asynctask-template.html</p>
<p>http://sirinsevinc.wordpress.com/2010/05/11/118/</p>
<p>also read</p>
<p>http://mindtherobot.com/blog/675/android-architecture-message-based-mvc/</p>
<p>issues<br />
Activity.runonuithread<br />
postdelayed - http://www.muktosoft.com/timer-in-android-the-better-way/<br />
--><br />
<br/><center><img src="/images/AndroidMultithreading/android_threads.png" alt="android" width="150" /></center><br />
 <strong>Why do we need multithreading in Android applications?</strong><br />
Let&#8217;s say you want to do a very long operation when the user pushes a button.<br />
If you are not using another thread, it will look something like this:</p>
<pre class="brush: java; title: ; notranslate">((Button)findViewById(R.id.Button01)).setOnClickListener(
             new OnClickListener() {

			@Override
			public void onClick(View v) {
            int result = doLongOperation();
            updateUI(result);
			}
		});</pre>
<p>What will happen?<br />
The UI freezes. This is a really bad UI experience. The program may even crash.</p>
<p><br/><br />
<strong>The problem in using threads in a UI environment</strong><br />
So what will happen if we use a Thread for a long running operation.<br />
Let&#8217;s try a simple example:</p>
<pre class="brush: java; title: ; notranslate">((Button)findViewById(R.id.Button01)).setOnClickListener(
new OnClickListener() {

			@Override
			public void onClick(View v) {

				(new Thread(new Runnable() {

					@Override
					public void run() {
                    int result = doLongOperation();
                    updateUI(result);
					}
				})).start();

			}</pre>
<p>The result in this case is that the application crashes.<br />
<code><font style="font-size:12px"  color="red">12-07 16:24:29.089: ERROR/AndroidRuntime(315): FATAL EXCEPTION: Thread-8<br />
12-07 16:24:29.089: ERROR/AndroidRuntime(315): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.<br />
12-07 16:24:29.089: ERROR/AndroidRuntime(315):     at ...</font></code></p>
<p>Clearly the Android OS wont let threads other than the main thread change UI elements.</p>
<p>But why?<br />
Android UI toolkit, like many other UI environments, is not thread-safe.</p>
<p><br/><br />
<strong>The solution</strong></p>
<ul>
<li>A queue of messages. Each message is a job to be handled.</li>
<li>Threads can add messages.</li>
<li>Only a single thread pulls messages one by one from the queue.</li>
</ul>
<p><insert image here></p>
<p>The same solution was implemented in swing (<a href="http://en.wikipedia.org/wiki/Event_dispatching_thread">Event dispatching thread</a><br />
and <a href="http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/SwingUtilities.html#invokeLater%28java.lang.Runnable%29">SwingUtilities.invokeLater() </a>)</p>
<p><br/></p>
<p><br/><strong>Handler</strong><br />
The <a href="http://developer.android.com/reference/android/os/Handler.html">Handler </a>is the middleman between a new thread and the message queue.</p>
<p><br/><strong>Option 1</strong> &#8211; Run the new thread and use the handler to send messages for ui changes</p>
<pre class="brush: java; title: ; notranslate">final Handler myHandler = new Handler(){
	@Override
public void handleMessage(Message msg) {
		updateUI((String)msg.obj);
}

};

(new Thread(new Runnable() {

	@Override
	public void run() {
		Message msg = myHandler.obtainMessage();

		msg.obj = doLongOperation();

		myHandler.sendMessage(msg);
	}
})).start();</pre>
<p>* keep in mind that updating the UI should still be a short operation, since the UI freezes during the updating process.</p>
<p>Other possibilities:<br />
handler.obtainMessage with parameters<br />
handler.sendMessageAtFrontOfQueue()<br />
handler.sendMessageAtTime()<br />
handler.sendMessageDelayed()<br />
handler.sendEmptyMessage()</p>
<p><br/></p>
<p><strong>Option 2</strong> &#8211; run the new thread and use the handler to post a runnable which updates the GUI.</p>
<pre class="brush: java; title: ; notranslate">final Handler myHandler = new Handler();

				(new Thread(new Runnable() {

					@Override
					public void run() {
						final String res = doLongOperation();
						myHandler.post(new Runnable() {

							@Override
							public void run() {
								updateUI(res);
							}
						});
					}
				})).start();

			}</pre>
<p><br/><br/><br />
<img src="/images/AndroidMultithreading/android_threading.png" alt="android multithreading" width="100%" /><br />
<br/><br />
<br/><strong>Looper</strong><!--</p>
<p>http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/</p>
<p>http://developer.android.com/reference/android/os/Looper.html</p>
<p>--><br />
If we want to dive a bit deeper into the android mechanism we have to understand what is a <a href="http://developer.android.com/reference/android/os/Looper.html">Looper</a>.<br />
We have talked about the message queue that the main thread pulls messages and runnables from it and executes them.<br />
We also said that each handler you create has a reference to this queue.<br />
What we haven&#8217;t said yet is that the main thread has a reference to an object named Looper.<br />
The Looper gives the Thread the access to the message queue.<br />
Only the main thread has executes to the Looper by default.</p>
<p>Lets say you would like to create a new thread and you also want to take advantage of the message queue functionality in that thread.</p>
<pre class="brush: java; title: ; notranslate">(new Thread(new Runnable() {

						@Override
						public void run() {

							innerHandler = new Handler();

							Message message = innerHandler.obtainMessage();
							innerHandler.dispatchMessage(message);
						}
					})).start();</pre>
<p>Here we created a new thread which uses the handler to put a message in the messages queue.</p>
<p>This will be the result:<br />
<code><font style="font-size:12px" color="red">12-10 20:41:51.807: ERROR/AndroidRuntime(254): Uncaught handler: thread Thread-8 exiting due to uncaught exception<br />
12-10 20:41:51.817: ERROR/AndroidRuntime(254): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()<br />
12-10 20:41:51.817: ERROR/AndroidRuntime(254):     at android.os.Handler.<init>(Handler.java:121)<br />
12-10 20:41:51.817: ERROR/AndroidRuntime(254):     at ...</font></code></p>
<p><br/><br />
The new created thread does not have a Looper with a queue attached to it. Only the UI thread has a Looper.<br />
We can however create a Looper for the new thread.<br />
In order to do that we need to use 2 functions: <a href="http://developer.android.com/reference/android/os/Looper.html#prepare()">Looper.prepare()</a> and <a href="http://developer.android.com/reference/android/os/Looper.html#loop()">Looper.loop()</a>.</p>
<pre class="brush: java; title: ; notranslate">(new Thread(new Runnable() {

					@Override
					public void run() {

						Looper.prepare();
						innerHandler = new Handler();

						Message message = innerHandler.obtainMessage();
						innerHandler.dispatchMessage(message);
						Looper.loop();
					}
				})).start();</pre>
<p><br/></p>
<p>If you use this option, don&#8217;t forget to use also the quit() function so the Looper will not loop for ever.</p>
<pre class="brush: java; title: ; notranslate">@Override
	protected void onDestroy() {
		innerHandler.getLooper().quit();
		super.onDestroy();
	}</pre>
<p><br/></p>
<p><br/><br/><strong>AsyncTask</strong><br />
I have explained to you that a Handler is the new thread&#8217;s way to communicate with the UI thread.<br />
If while reading this you were thinking to yourself, isn&#8217;t there an easier way to do all of that&#8230; well, you know what?! There is.</p>
<p>Android team has created a class called  <a href="http://developer.android.com/reference/android/os/AsyncTask.html">AsyncTask </a>which is in short a thread that can handle UI.</p>
<p>Just like in java you extend the class Thread and  a <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html">SwingWorker </a>in Swing, in Android you extend the class AsyncTask.<br />
There is no interface here like Runnable to implement I&#8217;m afraid.</p>
<pre class="brush: java; title: ; notranslate">class MyAsyncTask extends AsyncTask&lt;Integer, String, Long&gt; {

    	@Override
    	protected Long doInBackground(Integer... params) {

    		long start = System.currentTimeMillis();
    		for (Integer integer : params) {
    			publishProgress(&quot;start processing &quot;+integer);
    			doLongOperation();
    			publishProgress(&quot;done processing &quot;+integer);
    		}

    		return start - System.currentTimeMillis();
    	}

    	@Override
    	protected void onProgressUpdate(String... values) {
    		updateUI(values[0]);
    	}

    	@Override
    	protected void onPostExecute(Long time) {
    		updateUI(&quot;Done with all the operations, it took:&quot; +
                                     time + &quot; millisecondes&quot;);
    	}

    	@Override
    	protected void onPreExecute() {
    		updateUI(&quot;Starting process&quot;);
    	}

    	public void doLongOperation() {

    		try {
    			Thread.sleep(1000);
    		} catch (InterruptedException e) {
    			e.printStackTrace();
    		}

    	}

    }</pre>
<p><br/></p>
<p>This is how you start this thread:</p>
<pre class="brush: java; title: ; notranslate">MyAsyncTask aTask = new MyAsyncTask();
aTask.execute(1, 2, 3, 4, 5);</pre>
<p><br/></p>
<p>AsyncTask defines 3 <strong>generic types</strong>:<br />
AsyncTask<{type of the input}, {type of the update unit}, {type of the result}><br />
You don&#8217;t have to use all of them &#8211; simply use &#8216;Void&#8217; for any of them.</p>
<p><br/></p>
<p>Notice that AsyncTask has 4 <strong>operations</strong>, which are executed by order.<br />
<strong>1. onPreExecute()</strong> &#8211; is invoked before the execution.<br />
<strong>2. onPostExecute() </strong>-  is invoked after the execution.<br />
<strong>3. doInBackground() </strong>- the main operation. Write your heavy operation here.<br />
<strong>4. onProgressUpdate()</strong> &#8211; Indication to the user on progress. It is invoked every time  <a href="http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress%28Progress...%29">publishProgress()</a> is called.</p>
<p>* Notice:  doInBackground() is invoked on a background thread where onPreExecute(), onPostExecute() and onProgressUpdate() are invoked on the UI thread since their purpose is to update the UI.</p>
<p><br/><br />
Android developer website also mentions these 4 rules regarding the AsyncTask:</p>
<ul>
<li>The task instance must be created on the UI thread.</li>
<li>execute(Params&#8230;) must be invoked on the UI thread.</li>
<li>Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params&#8230;), onProgressUpdate(Progress&#8230;) manually.</li>
<li>The task can be executed only once (an exception will be thrown if a second execution is attempted.)</li>
</ul>
<p><br/><br />
<strong>Timer  + TimerTask</strong><br />
Another option is to use a <a href="http://developer.android.com/reference/java/util/Timer.html">Timer</a>.<br />
Timer is a comfortable way to dispatch a thread in the future, be it once or more.</p>
<p>Instead of doing this:</p>
<pre class="brush: java; title: ; notranslate">Runnable threadTask = new Runnable() {

	@Override
	public void run() {

		while(true){
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			doSomething();
		}
	}
};

(new Thread(threadTask)).start();</pre>
<p>do this:</p>
<pre class="brush: java; title: ; notranslate">TimerTask timerTask = new TimerTask() {
	@Override
	public void run() {
		doSomething();
	}
}; 

Timer timer = new Timer();
timer.schedule(timerTask, 2000,2000);</pre>
<p>which is a bit more elegant.</p>
<p>Bare in mind, you still have to use Handler if you need to do UI operations.</p>
<p><br/><br />
Download sources:</p>
<p><a href="/downloads/AndroidMultithreading/MultithreadingTest.zip"><img src="/ficons/zip.gif" alt="zip"> Download demo project 1</a><br />
<a href="/downloads/AndroidMultithreading/TimerTaskTest.zip"><img src="/ficons/zip.gif" alt="zip"> Download demo project 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2010/12/android-multithreading-in-a-ui-environment/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Android &#8211; Opening a new screen</title>
		<link>http://www.aviyehuda.com/2010/11/andoid-opening-a-new-screen/</link>
		<comments>http://www.aviyehuda.com/2010/11/andoid-opening-a-new-screen/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 12:12:39 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Android_UI]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1297</guid>
		<description><![CDATA[&#160; Opening a new screen is fairly easy in android. This post will show you almost all you need to know about switching back and forth between screens in your Android application. Add all activities to manifest Each screen is usually an Activity. Each activity should be mentioned in the manifest file. The simple use [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png" alt="android" width="80" /></td>
<td width="5%" >&nbsp;</td>
<td style="vertical-align: top" ><em>Opening a new screen is fairly easy in android. This post will show you almost all you need to know about switching back and forth between screens in your Android application.</em>
</td>
</tr>
</table>
<p><br/><br/><strong>Add all activities to manifest</strong></p>
<ul>
<li>Each screen is usually an <a href="http://developer.android.com/reference/android/app/Activity.html">Activity</a>.</li>
<li>Each activity should be mentioned in the manifest file.</li>
</ul>
<pre class="brush: xml; highlight: [7,16]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
	package=&quot;com.aviyehuda.puzzle&quot; android:versionCode=&quot;1&quot;
	android:versionName=&quot;1.0&quot;&gt;
	&lt;application android:icon=&quot;@drawable/icon&quot;
			android:label=&quot;@string/app_name&quot;&gt;
		&lt;activity android:name=&quot;MyActivity&quot;&gt;

			&lt;intent-filter&gt;
				&lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
				&lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
			&lt;/intent-filter&gt;

		&lt;/activity&gt;

		&lt;activity android:name=&quot;.MyActivity2&quot; &gt;

		&lt;/activity&gt;

&lt;/application&gt;
&lt;uses-sdk android:minSdkVersion=&quot;6&quot; /&gt;
&lt;/manifest&gt; </pre>
<p><br/><strong>The simple use</strong></p>
<pre class="brush: java; title: ; notranslate">Intent in = new Intent(MyActivity.this, MyActivity2.class);
startActivity(in);</pre>
<ul>
<li>Bear in mind that every time you will call the function startActivity(intent) a new instance of MyActivity2 will be created.</li>
</ul>
<p><br/><strong>Passing a parameter</strong></p>
<ul>
<li>In most times you need to pass a parameter to the new screen. You do that by using the function <a href="http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String, android.os.Bundle)">putExtra()</a>.</li>
<li>This function </li>
</ul>
<pre class="brush: java; title: ; notranslate">
Intent in = new Intent(myactivity.this, MyActivity2.class);
in.putExtra(&quot;myKey&quot;, &quot;new1&quot;);
startActivity(in);</pre>
<p><br/><strong>Receiving a parameter</strong></p>
<ul>
<li>And of course you will need to receive that parameter on the other side.</li>
</ul>
<pre class="brush: java; title: ; notranslate">String s= getIntent().getExtras().get(&quot;myKey&quot;).toString()</pre>
<p><br/><strong>Going back</strong></p>
<ul>
<li>If you need to go back to the previous screen and terminate the current screen, than all you have to do is to use the function <a href="http://developer.android.com/reference/android/app/Activity.html#finish()">finish()</a> from anywhere in the new Activity.</li>
</ul>
<pre class="brush: java; title: ; notranslate">finish();</pre>
<p><br/><strong>Open for result</strong></p>
<ul>
<li>When you need to open a new screen and get result back from it, than use the function <a href="http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)">startActivityForResult()</a>  instead of <strong>startActivity()</strong></li>
</ul>
<pre class="brush: java; title: ; notranslate">Intent in = new Intent(myactivity.this, MyActivity2.class);
startActivityForResult(in, 0);</pre>
<p><br/><strong>Returning a result</strong></p>
<pre class="brush: java; title: ; notranslate">Intent in = getIntent();
in.putExtra(&quot;result&quot;, &quot;some parameter&quot;);
setResult(RESULT_OK,in);
finish();</pre>
<p><br/><strong>Getting the result from the new activity</strong></p>
<pre class="brush: java; title: ; notranslate">@Override
    protected void onActivityResult(int requestCode,
                                     int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);

    	Log.d(&quot;Result&quot;,&quot;&quot;+data.getExtras().get(&quot;result&quot;));
    } </pre>
<p><br/><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2010/11/andoid-opening-a-new-screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which client will dominate?</title>
		<link>http://www.aviyehuda.com/2010/11/which-client-will-dominate/</link>
		<comments>http://www.aviyehuda.com/2010/11/which-client-will-dominate/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 15:42:45 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[ClientSide]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Technologies]]></category>
		<category><![CDATA[JEE/Network]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1335</guid>
		<description><![CDATA[I first got into the magical world of the internet in the happy 90&#8242;s. Back then you could find 3 basic types of network application clients: Internet lightweight web sites (HTML, JS), installed applications with network connection like ICQ or Applets. The years went by, the internet connection got faster and richer applications came out [...]]]></description>
			<content:encoded><![CDATA[<p> I first got into the magical world of the internet in the happy 90&#8242;s. Back then you could find 3 basic types of network application clients: Internet lightweight web sites (HTML, JS), installed applications with network connection like ICQ or Applets.<br />
The years went by, the internet connection got faster and richer applications came out of the desktop and into the browser. The web applications clients became fatter. Even if the desktop applications still exist, they have clearly become a lot less common. That was about the time I started developing in java.</p>
<p>The obvious solution for many of these fat clients were the java web frameworks like Struts, JSF and all the others. But as the years went by a new approach became more and more popular &#8211; the Ajax web applications, with GMail in the lead. </p>
<p>Fat clients never looked better and the usability was excellent. It is almost as if we are using  desktop applications (!?!). JavaScript was never so cool. Libraries like JQuery are born every day as well as some new solutions like GWT to make our life with JavaScript easier.</p>
<p>But the story doesn&#8217;t end here. With the birth of the smart cellphones an old player came back to life &#8211; that&#8217;s right, the installed application. The small screen and slow connection makes the rich client web sites a bit hard to handle. IPhone followed by Android and Blackberry clearly encourage this approach with their application markets, so obviously installed applications are dominators in the mobile network applications arena.</p>
<p>But what&#8217;s next? Will the mobile installed applications suffer the same fate as the desktop applications? Clearly the arrival of HTML5 won&#8217;t make their life easier. Or maybe the installed applications will survive with the help of technologies such as JavaFX. Maybe both will manage to have a share.</p>
<p>What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2010/11/which-client-will-dominate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use fiddler+firefox to download files from streaming sites.</title>
		<link>http://www.aviyehuda.com/2010/11/how-to-use-fiddlerfirefox-to-download-files-from-streaming-sites/</link>
		<comments>http://www.aviyehuda.com/2010/11/how-to-use-fiddlerfirefox-to-download-files-from-streaming-sites/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 14:17:28 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[fiddler]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[sniffing]]></category>

		<guid isPermaLink="false">http://www.aviyehuda.com/?p=1290</guid>
		<description><![CDATA[I love discovering new music. Recently I am using blip.fm a lot. I like the idea of being proposed music I would love by someone who has the same taste of music like me. For me, it is the ultimate internet use. One trouble though, is that it usually takes me at least 3-5 times [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.fiddler2.com/Fiddler/images/FiddlerLogo.png" alt="" /></p>
<p><em>I love discovering new music. Recently I am using <a href="http://blip.fm/AviY" target="_blank">blip.fm</a> a lot. I like the idea of being proposed music I would love by someone who has the same taste of music like me. For me, it is the ultimate internet use.<br />
<br/>One trouble though, is that it usually takes me at least 3-5 times to hear a song before I would know I actually like it. I have found that the best thing is to download about 10-20 songs to my cellular phone and hear them again and again for a few times.<br />
<br/>In this post I will show you how to do that quite easily using fiddler and firefox.<br />
<br/>You can also do the same to download other file types like swf movies and so on.<br />
<br/>If you are using other browser than Firefox, that&#8217;s OK, it can also work with other browsers.<br />
</em><br />
<strong>Step 1 &#8211; Download and install Fiddler </strong></p>
<ul>
<li>Fiddler is a sniffing software which I like very much. It is super easy.</li>
<li>Please download it from <a href="http://www.fiddler2.com/Fiddler2/version.asp">here</a> and install it.</li>
<li>You will also have to install the script editor add-on. Please download it from <a href="http://www.fiddler2.com/fiddler/FSE.asp">here</a>. This add on lets you do a verity of actions to your web traffic, it is really a very useful add on.</li>
</ul>
<p><strong>Step 2 &#8211; Configure the script</strong> </p>
<ul>
<li>Open Fiddler.</li>
<li>Go to &#8220;FiddlerScript&#8221; tab on the top right tab bar.</li>
<li>Go to &#8220;OnBeforeResponse&#8221; function. You can do that by choosing it from the &#8220;Go to&#8221; drop down list.</li>
<li>Paste this snippet to the end of the function body.</li>
<pre class="brush: jscript; title: ; notranslate">if(oSession.url.Contains(&quot;.mp3&quot;)){
         FiddlerApplication.Log.LogFormat(&quot;downloading &quot;+oSession.url);
         System.Diagnostics.Process.Start(&quot;firefox.exe&quot;,oSession.url);
}</pre>
<p>This script will cause the fiddler to execute firefox with the link of of each mp3 file he sniffs in the network traffic. Notice I am also appending a small parameter at the end of the file URL. I do this so the fiddler will not go into a loop and download the same file again and again.</p>
<li>Press the &#8220;Save Script&#8221; button at the top of the script editor window.</li>
</ul>
<p><center><br />
<a href="http://www.aviyehuda.com/images/FiddlerFirefox/1.jpg"><img src="http://www.aviyehuda.com/images/FiddlerFirefox/1.jpg" alt="fiddler"  width="250px" /></a><br />
</center><br />
<strong>Step 3 &#8211; configure your firefox to download mp3 automatically</strong></p>
<ul>
<li>You may or may not need to do this step because your firefox is maybe already configured to download mp3 files.</li>
<li>If it&#8217;s not or you are not sure please open up your firefox. Go to &#8220;Tools&#8221; > &#8220;options&#8221; > &#8220;Applications&#8221;. Type &#8220;mp3&#8243; in the search input field and make sure that the action for this file type is &#8220;Save File&#8221;. Press &#8220;OK&#8221; and that is it.</li>
</ul>
<p><center><br />
<a href="http://www.aviyehuda.com/images/FiddlerFirefox/2.jpg"><img src="http://www.aviyehuda.com/images/FiddlerFirefox/2.jpg" width="250px" alt="firefox" /></a><br />
</center><br />
<strong>Step 4 &#8211; start to download</strong></p>
<ul>
<li>Go to blip.fm (or any other mp3 streaming site) and start listen to mp3s.</li>
<li>Notice that in blip.fm you can listen to swf or mp3 files. The script I have shown you above, downloads only mp3s. You van easily change it to download swf files.</li>
<li>Notice that blip.fm gives you the ability to skip the videos and just focus on the mp3s, this is even better for our use.</li>
</ul>
<p>And that it is. While you listen to the music, for every mp3 the fiddler will sniff, it will fire up the firefox which will than start to download the mp3s to your computer automatically.<br />
Actually you don&#8217;t even have to listen to the whole song, you can just wait for a few seconds until the song starts and go right away to the next song.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviyehuda.com/2010/11/how-to-use-fiddlerfirefox-to-download-files-from-streaming-sites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

