<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0">

<channel>
	<title>Paolo Casarini</title>
	
	<link>http://www.casarini.org/blog</link>
	<description>happy programming</description>
	<pubDate>Wed, 04 Aug 2010 20:59:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/casarini" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="casarini" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>AiC mobile per Android esce sul Market</title>
		<link>http://www.casarini.org/blog/2010/aic-mobile-per-android-esce-sul-market/</link>
		<comments>http://www.casarini.org/blog/2010/aic-mobile-per-android-esce-sul-market/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 20:40:29 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[family]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[AiC mobile]]></category>

		<category><![CDATA[android]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[mobile]]></category>

		<category><![CDATA[senza glutine]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=419</guid>
		<description><![CDATA[GlutenBuster è diventata l&#8217;applicazione ufficiale per la piattaforma Android dell&#8217;Associazione Italiana Celiachia e ora si chiama AiC mobile.
Con questo post segnalo che ho rilascio la versione 1.0.0 di AiC mobile e che ieri l&#8217;ho pubblicata sul Market Google in modo che chiunque sia interessato possa installarla e usufruire del prontuario AIC dei prodotti senza glutine [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="/images/ico_150.png" title="AiC mobile" align="left" width="150" height="150" /><em>GlutenBuster</em> è diventata l&#8217;applicazione ufficiale per la piattaforma Android dell&#8217;<a href="http://www.celiachia.it/">Associazione Italiana Celiachia</a> e ora si chiama <em><strong>AiC mobile</strong></em>.<br />
Con questo post segnalo che ho rilascio la versione 1.0.0 di <em>AiC mobile</em> e che ieri l&#8217;ho pubblicata sul Market Google in modo che chiunque sia interessato possa installarla e usufruire del prontuario AIC dei prodotti senza glutine sul proprio smartphone.<br />
<em>AiC mobile</em> per Android è sviluppata come <a href="http://it.wikipedia.org/wiki/Software_libero">software libero</a> (Free Software) ed è distribuita gratuitamente. Per scaricarsi il database dei prodotti, bisogna però essere registrati sul sito <a href="http://www.celiachia.it/res/etc/FormRegistrazione.aspx">www.celiachia.it</a> per creare un legame con l&#8217;associazione che certifica i prodotti.</p>
<p>Come ogni prodotto del volontariato, anche <em>AiC mobile</em> per Android, è il risultato della collaborazione di più persone che ringrazio per il loro aiuto e l&#8217;incoraggiamento che mi hanno donato: Luca Agostini, Alberto Carlana, Antonio D&#8217;Errico, Anna Ferrandino, Davide Fiorello, Mario Mestice, Antonio Pascuccio, Lorenzo Pino.</p>
<p>Per continuare:</p>
<ul>
<li><a href="http://www.casarini.org/blog/aicmobile">Presentazione del programma</a>, delle sue caratteristiche principali, screenshots, video dimostrativo e link per il download.</li>
<li>Gruppo per avere <a href="http://groups.google.it/group/android-aicmobile">supporto tecnico</a> nell&#8217;utilizzo dell&#8217;applicazione e per segnalare eventuali problemi;</li>
<li><a href="http://www.casarini.org/trac/glutenbuster">Sito di sviluppo collaborativo</a> dove è possibile accedere ai sorgenti e contribuire alle idee di sviluppo e alla stesura del codice.</li>
<li>Per installare l&#8217;applicazione:<br/><img alt="" src="/images/qr-aicmobile.png" title="aic mobile qr-code" class="alignnone" width="120" height="120" /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2010/aic-mobile-per-android-esce-sul-market/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GlutenBuster-0.3.1 released, si cercano tester!</title>
		<link>http://www.casarini.org/blog/2010/glutenbuster-031-released-si-cercano-tester/</link>
		<comments>http://www.casarini.org/blog/2010/glutenbuster-031-released-si-cercano-tester/#comments</comments>
		<pubDate>Sat, 22 May 2010 20:59:26 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[family]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[android]]></category>

		<category><![CDATA[celiachia]]></category>

		<category><![CDATA[GlutenBuster]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[mobile]]></category>

		<category><![CDATA[senza glutine]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=392</guid>
		<description><![CDATA[Ho rilasciato la prima versione pubblica di GlutenBuster, app per la piattaforma Android per la consultazione del prontuario AIC degli alimenti senza glutine.
GlutenBuster è sviluppato come software libero  (Free Software) ed è distribuito gratuitamente da sito di sviluppo collaborativo.
Sono alla ricerca di persone interessate a partecipare alla fase di test prima della pubblicazione nel [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://www.casarini.org/images/glutenbuster-icon.png" title="GlutenBuster" align="left"/>Ho rilasciato la prima versione pubblica di <a href="http://www.casarini.org/blog/glutenbuster">GlutenBuster</a>, app per la piattaforma Android per la consultazione del prontuario <a href="http://www.celiachia.it">AIC</a> degli alimenti senza glutine.</p>
<p>GlutenBuster è sviluppato come <a href="http://it.wikipedia.org/wiki/Software_libero" target="_new">software libero</a>  (Free Software) ed è distribuito gratuitamente da <a href="http://www.casarini.org/trac/glutenbuster">sito di sviluppo collaborativo</a>.</p>
<p><strong>Sono alla ricerca di persone interessate a partecipare alla fase di test</strong> prima della pubblicazione nel Google Market. Se qualcuno fosse interassato può scrivere a <a href="mailto:glutenbuster@casarini.org">glutenbuster@casarini.org</a>.</p>
<p>Per continuare:</p>
<ul>
<li><a href="/blog/glutenbuster">www.casarini.org/blog/glutenbuster</a> - Presentazione del programma, delle sue caratteristiche principali e accesso all&#8217;ultima versione disponibile pronta per essere installata sul proprio cellulare;</li>
<li><a href="/blog/glutenbuster/glutenbuster-screenshots/">www.casarini.org/blog/glutenbuster/glutenbuster-screenshots/</a> - Screenshots che mostrano alcune schermate catturate durante l&#8217;ultizzo delle principali funzionalità;</li>
<li><a href="/trac/glutenbuster">www.casarini.org/trac/glutenbuster</a> - Sito di sviluppo collaborativo dove è possibile accedere ai sorgenti e contribuire alle idee di sviluppo e alla stesura del codice.</li>
</ul>
<p><object width="512" height="320"><param name="movie" value="http://www.youtube.com/v/K2YTq_3Awik&#038;hl=it_IT&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/K2YTq_3Awik&#038;hl=it_IT&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="512" height="320"></embed></object><br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2010/glutenbuster-031-released-si-cercano-tester/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to download a file and update an Android ProgressDialog</title>
		<link>http://www.casarini.org/blog/2010/how-to-download-a-file-and-update-an-android-progressdialog/</link>
		<comments>http://www.casarini.org/blog/2010/how-to-download-a-file-and-update-an-android-progressdialog/#comments</comments>
		<pubDate>Fri, 21 May 2010 21:05:58 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[android]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[mobile]]></category>

		<category><![CDATA[networking]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=372</guid>
		<description><![CDATA[I recently made an helper class to download a file from the web and save it to the file sytem while updating a ProgressDialog to let the user know the percentage of the download made. This class has the responsibility to manage the network communication and to send messages to the UI to update the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/blog/wp-content/uploads/2009/04/android_developer.png" alt="" title="android developer" width="150" height="150" align="left" />I recently made an helper class to download a file from the web and save it to the file sytem while updating a ProgressDialog to let the user know the percentage of the download made. This class has the responsibility to manage the network communication and to send messages to the UI to update the status of the ProgressDialog previously built and displayed.</p>
<p>Before starting to write some code it may be useful to remember to declare in the AndroidManifest.xml  the request for the permission to make connections over the Internet and, if we want to save the file on the sd card, the permission to write to the external storage:</p>
<div class="igBar"><span id="lxml-5"><a href="#" onclick="javascript:showPlainTxt('xml-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-5">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;uses</span>-permission android:<span style="color: #000066;">name</span>=<span style="color: #ff0000;">"android.permission.INTERNET"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;uses</span>-permission android:<span style="color: #000066;">name</span>=<span style="color: #ff0000;">"android.permission.WRITE_EXTERNAL_STORAGE"</span><span style="font-weight: bold; color: black;">/&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The class I wrote is called <tt>DownloadThread</tt>, extends th <tt>java.lang.Thread</tt> and a constructor with four parameters:</p>
<ul>
<li>the <em>url</em> of the file to download;</li>
<li>the <em>path</em> where the downloaded file has to be written;</li>
<li>the instance of the ProgressDialog to update;</li>
<li>the handler that will receove the messages to update the UI.</li>
</ul>
<div class="igBar"><span id="ljava-6"><a href="#" onclick="javascript:showPlainTxt('java-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-6">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DownloadThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Thread</span></a> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> TAG = Home.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006600;">getSimpleName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">int</span> BUFFER_LENGTH = <span style="color: #cc66cc;color:#800000;">8192</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Handler handler;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ProgressDialog progressDialog;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> fileurl;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> filepath;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> DownloadThread<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> fileurl, <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> filepath, Handler handler, ProgressDialog dialog<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">fileurl</span> = fileurl;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">filepath</span> = filepath;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">handler</span> = handler;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">progressDialog</span> = dialog;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><span id="more-372"></span><br />
The download process has to be in a separate <em>thread</em> and it has to be started soon after the dialog is displayed. The core of this class is its <em>run</em> method where we first make the connection to the specified <em>url</em> and build the input/output streams to realize the communicaton channel and then we read from the network the file content.</p>
<div class="igBar"><span id="ljava-7"><a href="#" onclick="javascript:showPlainTxt('java-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-7">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> run<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AURL+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">URL</span></a> url = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AURL+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">URL</span></a><span style="color: #66cc66;">&#40;</span>fileurl<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AFile+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">File</span></a> file = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AFile+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span>filepath<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Open a connection to that URL. */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AURLConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">URLConnection</span></a> ucon = url.<span style="color: #006600;">openConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> length = ucon.<span style="color: #006600;">getContentLength</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; progressDialog.<span style="color: #006600;">setMax</span><span style="color: #66cc66;">&#40;</span>length<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Define InputStreams to read from the URLConnection and</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* OutputStream to write to file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">InputStream</span></a> is = ucon.<span style="color: #006600;">getInputStream</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ABufferedInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span></a> bis = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ABufferedInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span></a><span style="color: #66cc66;">&#40;</span>is<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AFileOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a> fos = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AFileOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Read bytes to the Buffer until there is nothing more to read(-1).</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> buffer = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span>BUFFER_LENGTH<span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> read;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> count = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>read = bis.<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span>buffer, <span style="color: #cc66cc;color:#800000;">0</span>, BUFFER_LENGTH<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.<span style="color: #006600;">write</span><span style="color: #66cc66;">&#40;</span>buffer, <span style="color: #cc66cc;color:#800000;">0</span>, read<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count += read; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Message msg = handler.<span style="color: #006600;">obtainMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bundle b = <span style="color: #000000; font-weight: bold;">new</span> Bundle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.<span style="color: #006600;">putInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"count"</span>, count<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.<span style="color: #006600;">sendMessage</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; fos.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span style="color: #006600;">d</span><span style="color: #66cc66;">&#40;</span>TAG, <span style="color: #ff0000;">"Error: "</span> + e<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If we delete lines 9 and 28-32 the code could run in any Java standard environment, the highlighted lines have the resposibility to communicate with the UI and to update it. In particular line 9 sets the upper boung of the progress bar in the ProgressDialog and lines 28-32 update throught the Handler instance the current value of the progress bar.</p>
<p>What we need now is the code of build the ProgressDialog in our Activity e and the related Handler that manage messages from the Thread we have just written.</p>
<div class="igBar"><span id="ljava-8"><a href="#" onclick="javascript:showPlainTxt('java-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-8">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyActvity <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">int</span> DOWNLOAD_DIALOG = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ....</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #006600;">DownloadThread</span> downloadThread;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @Override</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?q=allinurl%3ADialog+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Dialog</span></a> onCreateDialog<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> DOWNLOADDB_DIALOG:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> ProgressDialog downloadDialog = <span style="color: #000000; font-weight: bold;">new</span> ProgressDialog<span style="color: #66cc66;">&#40;</span>MyActvity.<span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadDialog.<span style="color: #006600;">setProgressStyle</span><span style="color: #66cc66;">&#40;</span>ProgressDialog.<span style="color: #006600;">STYLE_HORIZONTAL</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadDialog.<span style="color: #006600;">setMessage</span><span style="color: #66cc66;">&#40;</span>getText<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">string</span>.<span style="color: #006600;">home_progress_message</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadDialog.<span style="color: #006600;">setCancelable</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Handler handler = <span style="color: #000000; font-weight: bold;">new</span> Handler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> handleMessage<span style="color: #66cc66;">&#40;</span>Message msg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> count = msg.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"count"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadDialog.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span>count<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>count&gt;= downloadDialog.<span style="color: #006600;">getMax</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dismissDialog<span style="color: #66cc66;">&#40;</span>DOWNLOAD_DIALOG<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeDialog<span style="color: #66cc66;">&#40;</span>DOWNLOADDB_DIALOG<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.<span style="color: #006600;">makeText</span><span style="color: #66cc66;">&#40;</span>MyActvity.<span style="color: #000000; font-weight: bold;">this</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getText<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">string</span>.<span style="color: #006600;">download_ok_message</span><span style="color: #66cc66;">&#41;</span>, Toast.<span style="color: #006600;">LENGTH_SHORT</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadThread = <span style="color: #000000; font-weight: bold;">new</span> DownloadThread<span style="color: #66cc66;">&#40;</span>url, path</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler, downloadDialog<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downloadThread.<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> downloadDialog;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ... </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<br/>It's all, folks! If you want to see this class in action you can see it in a small free software project called <a href="http://www.casarini.org/trac/glutenbuster">GlutenBuster</a>. <br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2010/how-to-download-a-file-and-update-an-android-progressdialog/feed/</wfw:commentRss>
		</item>
		<item>
		<title>La mia posta dov’è?</title>
		<link>http://www.casarini.org/blog/2009/la-mia-posta-dove/</link>
		<comments>http://www.casarini.org/blog/2009/la-mia-posta-dove/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 22:55:08 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=324</guid>
		<description><![CDATA[Da un po' di giorni non mi arriva più la posta (quella tradizionale) a casa. Considerandolo un fatto piuttosto strano visto che abito in una grande città, telefono alle poste (803.160) per segnalare la cosa.
Dopo aver fatto lo slalom tra le varie scelte guidate del risponditore automatico, riesco a parlare con un operatore a cui [...]]]></description>
			<content:encoded><![CDATA[<p>Da un po' di giorni non mi arriva più la posta (quella tradizionale) a casa. Considerandolo un fatto piuttosto strano visto che abito in una grande città, telefono alle poste (803.160) per segnalare la cosa.<br />
Dopo aver fatto lo slalom tra le varie scelte guidate del risponditore automatico, riesco a parlare con un operatore a cui segnalo che da 5gg non ricevo più la posta, né io né gli altri condomini del palazzo in cui vivo.<br />
L'operatore mi chiede se stavo aspettando qualcosa in particolare e, dopo avergli detto che non aspetto nulla in particolare ma che sono abbonato ad un quotidiano che ha smesso (insieme al resto della posta) di arrivarmi, mi mette in attesa.</p>
<p>Durante la lunga attesa rifletto sul fatto che, sebbene molto cortese, il tono del mio interlocutore mi pareva strano... c'era qualcosa che non mi tornava. Io stavo contattando le Poste Italiane per segnalare che non mi arriva la posta da 5gg e il tono del mio interlocutore poteva essere paragonato a quello di un medico in sala operatoria a cui viene chiesto se ha da accendere. Come se la mia segnalazione fosse <i>off topic</i>.</p>
<p><span id="more-324"></span><br />
Dopo qualche minuto di attesa, l'operatore riprende a parlare e mi dice di aspettare la metà della settimana prossima e, se proprio non vedo arrivare nulla, di richiamare per fare la segnalazione. Quando mi chiede se va bene, gli dico di no: aspettare 10gg senza posta prima di fare una segnalazione non mi sembra giusto visto che la consegna della posta dovrebbe essere il loro compito prioritario.</p>
<p>Così dopo qualche altro minuto di attesa, l'operatore, sempre molto cortesemente, inizia la pratica per inoltrare la mia segnalazione, alla fine della quale mi fornisce il numero di pratica e mi dice che verrò contattato per essere avvisato di quando il servizio verrà riattivato.</p>
<p>Finita la telefonata, durata circa 15 minuti, rimango con il sospetto che, a mio giudizio, non doveva andare in quel modo. A dire il vero mi aspettavo:</p>
<ul>
<li>il fatto che la possibilità di segnalare problemi nella consegna della posta fosse previsto tra le possibilità del risponditore automatico e non dovessi scegliere l'opzione "per tutte le altre segnalazioni o problemi";</li>
<li>un atteggiamento interessato da parte dell'operatore, quasi stupito che una cosa così strana (n.d.r. forse l'aggettivo giusto è grave) potesse capitare;</li>
<li>che la segnalazione venisse gestita in un tempo massimo di 5 minuti (sono stato largo) e che dopo avermi chiesto le mie generalità e l'indirizzo per il quale segnalavo il problema, mi si liquidasse con un frase del tipo: "ci scusiamo per inconveniente, la ringraziamo della segnalazione, provvederemo perché il servizio sia riattivato quanto prima".</li>
</ul>
<p>E se tutto questo fosse stato ripreso per un candid camera? Idea non male, ma io voglia la mia posta!!</p>
<p><b>Aggiornamento del 22 febbraio 2010:</b><br />
Dopo due mesi le Poste italiane mi rispondo come segue:</p>
<blockquote><p>
Con riferimento alla Sua richiesta, la informiamo che la sua segnalazione è stata inoltrata agli uffici e alle strutture territoriali competenti affinché provvedano a risolvere le anomalie da Lei lamentate.<br/><br />
Spiacenti per il disagio, la ringraziamo per la sua indicazione perché ci offre l'opportunità di migliorare la qualità dei servizi in modo da renderli sempre più vicini alle aspettative dei nostri clienti.
</p></blockquote>
<p>Per fortuna la posta è tornata ad arrivare regolarmente appena si è sciolta la neve...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/la-mia-posta-dove/feed/</wfw:commentRss>
		</item>
		<item>
		<title>phpKnockClient 1.0</title>
		<link>http://www.casarini.org/blog/2009/phpknockclient-10/</link>
		<comments>http://www.casarini.org/blog/2009/phpknockclient-10/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 21:29:56 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[networking]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[port-knocking]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=318</guid>
		<description><![CDATA[I've implemented a port-knocking client implementation in PHP inspired by the knockd C implementation made by Judd Vinet.
You can can download it at this page.
If you don't know what port knocking is, it can briefly described as a way of surreptitiously offering services on a server without advertising the fact. By delivering a special sequence [...]]]></description>
			<content:encoded><![CDATA[<p>I've implemented a port-knocking client implementation in PHP inspired by the knockd C implementation made by Judd Vinet.</p>
<p>You can can download it at <a href="/blog/free-software/phpknockclient/">this page</a>.</p>
<p>If you don't know what port knocking is, it can briefly described as a way of surreptitiously offering services on a server without advertising the fact. By delivering a special sequence of “port knocks”, a user can open up access to a port for his IP only, and close it again when he’s done.</p>
<p>For more information, see the <a href="http://www.portknocking.org/" target="_new">port knocking website</a> or <a href="http://www.linuxjournal.com/article/6811" target="_new">this article</a> that is an introduction to how, using the port-knocking technic, trusted users can manipulate firewall rules to transmit information across closed ports.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/phpknockclient-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PostgreSQL 8.4 e il locale it_IT</title>
		<link>http://www.casarini.org/blog/2009/postgresql-84-e-il-locale-it_it/</link>
		<comments>http://www.casarini.org/blog/2009/postgresql-84-e-il-locale-it_it/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 20:18:38 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<category><![CDATA[PostgreSQL locale encoding]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=280</guid>
		<description><![CDATA[PostgreSQL mi accompagna nel mio lavoro da ormai 8 anni e di versione in versione mi ha sempre regalato delle soddisfazioni. Di recente, volendo migrare dalla versione 8.0.2 alla recente 8.4.1 ho dovuto litigare un po' per fargli digerire il fatto che sullo stesso server devono coesistere database LATIN1, LATIN9 e UTF-8. Con l'ultima versione, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.casarini.org/blog/wp-content/uploads/2009/10/schermata-2009-10-24-a-221703.png" alt="" title="PostgreSQL" width="138" height="141" class="alignleft size-full wp-image-287" />PostgreSQL mi accompagna nel mio lavoro da ormai 8 anni e di versione in versione mi ha sempre regalato delle soddisfazioni. Di recente, volendo migrare dalla versione 8.0.2 alla recente 8.4.1 ho dovuto litigare un po' per fargli digerire il fatto che sullo stesso server devono coesistere database LATIN1, LATIN9 e UTF-8. Con l'ultima versione, PostreSQL, è diventato infatti un po' più rigoroso nella gestione dei <em>locale</em> senza però documentare in maniera opportuna la cosa. La <a href="http://www.postgresql.org/docs/8.4/interactive/sql-createdatabase.html">documentazione ufficiale</a> non va oltre qualche esempio e quindi ho dovuto andare un po' per tentativi, e riuscire a creare i dabatase con encoding voluto e il <em>locale</em> opportuno (it_IT).</p>
<p><span id="more-280"></span>Il mio server dopo essere stato inizializzato con i valori di default presenteva la seguente situazione:</p>
<pre>
$ psql -h webdb -l
                                     List of databases
       Name        |  Owner   | Encoding | Collation  |   Ctype    |   Access privileges
-------------------+----------+----------+------------+------------+-----------------------
 postgres          | postgres | LATIN1   | C          | en_US      |
 template0         | postgres | LATIN1   | C          | en_US      | =c/postgres
                                                                   : postgres=CTc/postgres
 template1         | postgres | LATIN1   | C          | en_US      | =c/postgres
                                                                   : postgres=CTc/postgres
</pre>
<p>In questa situazione se provato a create un database in UTF-8 o LATIN9 con il comando <code>createdb -E UTF8 dbname</code> mi beccavo puntualmente il seguente errore:</p>
<pre>
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
</pre>
<p>o</p>
<pre>
createdb: database creation failed: ERROR:  encoding LATIN9 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
</pre>
<p>nel caso dell'encoding LATIN9.</p>
<p>La soluzione, seppur non immediata, c'è sfruttando proprio il comando <code>CREATE DATABASE</code> all'interno dell'interprete dei comandi. In particolare per creare un db con encoding UTF-8 e locale it_IT bisogna usare il seguente comando:</p>
<div class="igBar"><span id="lsql-11"><a href="#" onclick="javascript:showPlainTxt('sql-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-11">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #ff0000;">"nomedb"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ENCODING <span style="color: #ff0000;">'UTF8'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; LC_CTYPE=<span style="color: #ff0000;">'it_IT.UTF8'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; LC_COLLATE=<span style="color: #ff0000;">'it_IT.UTF8'</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; TEMPLATE template0; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Mentre per creare un database con encoding LATIN9 e locale it_IT il comando è il seguente:</p>
<div class="igBar"><span id="lsql-12"><a href="#" onclick="javascript:showPlainTxt('sql-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-12">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #ff0000;">"nomedb"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ENCODING <span style="color: #ff0000;">'LATIN9'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; LC_CTYPE=<span style="color: #ff0000;">'it_IT@euro'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; LC_COLLATE=<span style="color: #ff0000;">'it_IT@euro'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; TEMPLATE template0; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/postgresql-84-e-il-locale-it_it/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Italian Agile Day 2009: Aperte le Iscrizioni!</title>
		<link>http://www.casarini.org/blog/2009/italian-agile-day-2009-aperte-le-iscrizioni/</link>
		<comments>http://www.casarini.org/blog/2009/italian-agile-day-2009-aperte-le-iscrizioni/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:35:20 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=274</guid>
		<description><![CDATA[Venerdi’ 20 Novembre 2009 si terrà a Bologna il sesto Italian Agile Day. Si tratta di una conferenza gratuita di un giorno dedicata alle metodologie Agili per lo sviluppo e la gestione dei progetti software rivolta agli sviluppatori, project leaders, IT managers, tester, architetti e coach che hanno esperienze da condividere o che iniziano solo [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.casarini.org/blog/wp-content/uploads/2009/10/iad120.gif" alt="" title="Italian Agile Day 2009" width="120" height="90" class="alignleft size-full wp-image-277" />Venerdi’ 20 Novembre 2009 si terrà a Bologna il sesto <a href="http://www.agileday.it/front/2009/italian-agile-day-2009/">Italian Agile Day</a>. Si tratta di una conferenza gratuita di un giorno dedicata alle metodologie Agili per lo sviluppo e la gestione dei progetti software rivolta agli sviluppatori, project leaders, IT managers, tester, architetti e coach che hanno esperienze da condividere o che iniziano solo ora ad interessarsi a queste tematiche. La giornata ha come obiettivo la conoscenza pratica, le esperienze sul campo e un attivo coinvolgimento di tutti i partecipanti. L’accesso è libero previa registrazione, i posti sono limitati. L’evento, per la quarta volta consecutiva, si auto-finanzierà.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/italian-agile-day-2009-aperte-le-iscrizioni/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Time Capsule coi mesi contati</title>
		<link>http://www.casarini.org/blog/2009/time-capsule-coi-mesi-contati/</link>
		<comments>http://www.casarini.org/blog/2009/time-capsule-coi-mesi-contati/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 20:39:05 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[hardware]]></category>

		<category><![CDATA[nas]]></category>

		<category><![CDATA[time capsule]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=266</guid>
		<description><![CDATA[Oggi, tornato a casa, mi sono accorto che il mio prezioso Time Capsule era spento, subito ho pensato che uno dei miei figli avesse staccato la spina sotto il tavolo, ma la spina era attaccata. Poi ho dato colpa al cavetto di alimentazione, ma usandone uno diverso il Time Capsule ha continuato a non accendersi.
Rassegnato [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.casarini.org/blog/wp-content/uploads/2009/10/schermata-2009-10-19-a-222510.png" title="The Apple Time Capsule Memorial Register" width="213" height="206" class="alignleft size-full wp-image-269" />Oggi, tornato a casa, mi sono accorto che il mio prezioso Time Capsule era spento, subito ho pensato che uno dei miei figli avesse staccato la spina sotto il tavolo, ma la spina era attaccata. Poi ho dato colpa al cavetto di alimentazione, ma usandone uno diverso il Time Capsule ha continuato a non accendersi.</p>
<p>Rassegnato a portarlo a far riparare mi metto a cercare la fattura di acquisto e, trovandola, mi accorgo di possedere il mio Time Capsule da soli 18 mesi e la garanzia, in Italia, dovrebbe durare 24. L'acquisto l'ho fatto direttamente sul sito della Apple e quindi mi metto a cercare i termini di garanzia sul loro sito. Poi vado su Google e invece dell'informazione che cerco trovo il seguente articolo:</p>
<p><a href="http://www.theapplelounge.com/hardware/time-capsule-viaggiare-nel-tempo-fino-a-18-mesi/" target="_new">Time Capsule, viaggiare nel tempo… fino a 18 mesi</a></p>
<p>Continuando a cercare trovo che non solo non sono solo ad avere un Time Capsule morto a 18 mesi di vita, ma siamo in tanti e per trovare compagni di sventura basta cercare su google: <em>time capsule 18 month</em>.</p>
<p>Il link più bello è quello di un sito dove si può registrare la morte del proprio Time Capsule: <a href="http://timecapsuledead.org/" target="_new">The Apple Time Capsule Memorial Register</a>. Si può registrare il proprio Time Capsule dichiarando il giorno di acquisto e il giorno della morte... <em>curioso</em> che la media di vita dei Time Caspule registrati (attualmente 416) sia di 17 mesi e 4 giorni.</p>
<p>Domani andrò nel più vicino centro di assistenza Apple per elemosinare una riparazione in garanzia... se non me l'accorderanno, penso tirerò fuori il mio Dremel e seguirò una delle seguenti guide per la sostituzione fai-da-te dell'alimentatore:</p>
<ul>
<li><a href="http://sites.google.com/site/lapastenague/a-deconstruction-of-routers-and-modems/apple-time-capsule-repair" target="_new">Apple Time Capsule Repair Type1</a></li>
<li><a href="http://sites.google.com/site/lapastenague/a-deconstruction-of-routers-and-modems/apple-time-capsule-repair/apple-time-capsule-repair-type2" target="_new">Apple Time Capsule Repair Type2</a></li>
</ul>
<p><strong>Aggiornamento (4 novembre 2009)</strong><br />
Dopo appena 8gg lavorativi il centro d'assistenza Apple al quale mi sono rivolto mi ha chiamato dicendomi che aveva il mio Time Capsule. In realtà me ne ha dato uno nuovo, avrei preferito se avessero cambiato la sola alimentazione recuperando così i vecchi backup, ma mi è stato detto che la cosa non era possibile.<br />
Nel darmelo mi è stato specificato che il nuovo Time Capsule non era praticamente coperto da garanzia poiché si fa sempre riferimento alla data di acquisto di quello che è stato sostituito. La cosa è normale, visto che non ho pagato alcuna riparazione, ma lo zelo con il quale mi è stata precisata la cosa mi ha messo un po' di dubbi: quanto durerà?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/time-capsule-coi-mesi-contati/feed/</wfw:commentRss>
		</item>
		<item>
		<title>eBook reader e DRM incompatibili</title>
		<link>http://www.casarini.org/blog/2009/ebook-reader-e-drm-incompatibili/</link>
		<comments>http://www.casarini.org/blog/2009/ebook-reader-e-drm-incompatibili/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:57:08 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[digital publishing]]></category>

		<category><![CDATA[bebook]]></category>

		<category><![CDATA[cybook]]></category>

		<category><![CDATA[eReader]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=257</guid>
		<description><![CDATA[Con un po' di meraviglia scopro che per qualche problema legale i DRM di Adobe e della Mobipocket non possono essere implementati sullo stesso eBook reader. Così viene sostenuto, recentemente, da molte case produttrici di eBook reader con tecnologia eInk.
Possiedo da qualche tempo un BeBook che, come ho già scritto, è un ottimo lettore di [...]]]></description>
			<content:encoded><![CDATA[<p>Con un po' di meraviglia scopro che per qualche problema legale i DRM di Adobe e della Mobipocket non possono essere implementati sullo stesso eBook reader. Così viene sostenuto, recentemente, da molte case produttrici di eBook reader con tecnologia eInk.</p>
<p>Possiedo da qualche tempo un BeBook che, come <a href="/blog/2009/ho-provato-il-cybook-e-ho-comprato-il-bebook/">ho già scritto</a>, è un ottimo lettore di eBook che, come molti suoi simili (CyBook, Handlin V3, EZReader, etc), legge eBook in formato Mobipocket con e senza DRM. Da poco tempo, per lui e per molti suoi simili, le varie case produttrici stanno rilasciando dei nuovi firmware in grado di leggere eBook in formato ePub e PDF con il DRM di Adobe. La lettura di questi ultimi formati senza DRM è già possibile, ma è evidente che poter trasformare il proprio lettore in un device in grado di gestire il DRM di Adobe è un notevole passo in avanti.</p>
<p>Se però da un parte si fa un passo in avanti, dall'altra viene fatto un notevole passo indietro poiché a tutti questi lettori, con i nuovi firmware, viene tolta la capacità di leggere eBook in formato Mobipocket con DRM! Unica soluzione proposta per poter continuare a leggere i propri libri acquistati in tale formato è mantenere il vecchio firmware, oppure cambiare il firmware in base al DRM che si deve usare... comodo!</p>
<p>Questo atteggiamento mi sembra molto riprovevole nei confronti di utenti che hanno acquistato un oggetto privo di qualsiasi legame con le aziende produttrici dei contenuti (a differenza di chi ha acquistato un kindle, per esempio). Non si capisce poi quali possano essere questi problemi legali visto che la convivenza di software per la lettura di formati Mobipocket e PDF con e senza DRM convivono tranquillamente e giustamente su quasi ogni sistema operativo. A me sembra tanto una imposizione di Adobe, che per paura di perdere il treno (il secondo per nella fattispecie), prova ad imporre a questi piccoli produttori il suo DRM in alternativa a quello della Mobipocket già usato da Amazon.</p>
<p>Mi chiedo se non ci si possa in qualche modo organizzare per sottoporre all'attenzione di queste aziende il disappunto degli loro utenti. Per il momento ho aperto una <a href="http://mybebook.com/forum/viewtopic.php?f=4&#038;t=1515">richiesta di spegazioni</a> nel forum di supporto per il BeBook, chi si vuole accodare o volesse proporre altre strade, è il benvenuto!</p>
<p><strong>Aggiornamento (11 agosto 2009)</strong><br />
Dalle risposte che mi sono state date sul forum di supporto del BeBook non si tratta di problemi legali, ma di problemi di licenza. In particolare, differentemente rispetto a quanto avevo supposto in un primo momento, i "cattivi" sono quelli di Amazon che forniscono la possibilità di usare il loro DRM su Mobipocket in licenza solo su lettori che non hanno altri software di DRM al loro interno.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/ebook-reader-e-drm-incompatibili/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP SOAP Messages with Attachments</title>
		<link>http://www.casarini.org/blog/2009/php-soap-messages-with-attachments/</link>
		<comments>http://www.casarini.org/blog/2009/php-soap-messages-with-attachments/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:25:14 +0000</pubDate>
		<dc:creator>paolo</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://www.casarini.org/blog/?p=241</guid>
		<description><![CDATA[This article is to make a simple example on how you can manage SOAP Messages with Attachements in PHP and, in particular, I'll describe how to use the PEAR::SOAP package to transmit files associated to a SOAP message as attachments in their native format in a multipart MIME structure for transport (SOAP Messages with Attachments [...]]]></description>
			<content:encoded><![CDATA[<p>This article is to make a simple example on how you can manage SOAP Messages with Attachements in PHP and, in particular, I'll describe how to use the PEAR::SOAP package to transmit files associated to a SOAP message as attachments in their native format in a multipart MIME structure for transport (<a href="http://www.w3.org/TR/SOAP-attachments">SOAP Messages with Attachments</a> specifications).</p>
<p>Even if the PEAR::SOAP package is not yet considered stable and even if it lacks completely of documentation, the use of it is the only way I found to solve this problem. Nor the standard SOAP PHP5 implementation, nor the Zend_Soap package in the Zend Framework provides any way to manage attachments to SOAP messages.</p>
<p><span id="more-241"></span></p>
<p>The first problem you have with PEAR::SOAP is the lack of documentation, no API documentation, no examples, nothing except what you can find within the source code. So, if you want to use it in the proper way, you have to read and understand the source code and make many many tests.</p>
<p>The example I'll make will invoke an operation that requires a binary file as first parameter. First we have to create a SOAP client using the <i>wsdl</i> of the webservice to invoke. Assuming you have correctly installed the PEAR:SOAP package, the code to create a client is very simple.</p>
<div class="igBar"><span id="lphp-17"><a href="#" onclick="javascript:showPlainTxt('php-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-17">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require</span> <span style="color:#FF0000;">"SOAP/Client.php"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$wsdl</span> = <span style="color:#000000; font-weight:bold;">new</span> SOAP_WSDL<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'http://somehost.com/webservice.wsdl'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$client</span> = <span style="color:#0000FF;">$wsdl</span>-&gt;<span style="color:#006600;">getProxy</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Once you have a client for the webservice to invoke it's time to set some options, for example if the target webservice needs an HTTP authentication you have to set <i>user</i> and <i>pass</i> options.</p>
<div class="igBar"><span id="lphp-18"><a href="#" onclick="javascript:showPlainTxt('php-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">setOpt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'user'</span>, <span style="color:#FF0000;">'myusername'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">setOpt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'pass'</span>, <span style="color:#FF0000;">'mypassword'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we assume to have a webservice with a <tt>register</tt> operation that takes only one parameter and this parameter is an xml file. If the xml file has to be transferrered as an attachment we have first to build a SOAP_Attachment object, then we have to chose the method used by the framework to transport the binary content and finally we have to invoke the <tt>register</tt> operation passing the created attachment as parameter.</p>
<div class="igBar"><span id="lphp-19"><a href="#" onclick="javascript:showPlainTxt('php-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$v</span> = <span style="color:#000000; font-weight:bold;">new</span> SOAP_Attachment<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'contentID'</span>, <span style="color:#FF0000;">'text/xml; charset=utf-8'</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$xml</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">setOpt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Mime'</span>, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ret</span> = <span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$v</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you don't have the binary file already loaded in a string, but you have a file on your filesystem, the first line of the last code snippet has to be modified as follows:</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$v</span> = <span style="color:#000000; font-weight:bold;">new</span> SOAP_Attachment<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'contentID'</span>, <span style="color:#FF0000;">'text/xml; charset=utf-8'</span>, <span style="color:#FF0000;">'filename.xml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casarini.org/blog/2009/php-soap-messages-with-attachments/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
