<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.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:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tuto Mobile » Tutoriels Android</title>
	
	<link>http://www.tutomobile.fr</link>
	<description>Tutorial Android, iPhone, Windows mobile</description>
	<lastBuildDate>Fri, 23 Dec 2011 10:48:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TutoMobileTutorielsAndroid" /><feedburner:info uri="tutomobiletutorielsandroid" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:copyright>Tuto Mobile</media:copyright><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Software How-To</media:category><itunes:author>Axon</itunes:author><itunes:explicit>no</itunes:explicit><itunes:subtitle>Tutorial Android, iPhone, Windows mobile</itunes:subtitle><itunes:category text="Technology"><itunes:category text="Software How-To" /></itunes:category><item>
		<title>[Concours] Résultats du concours pour gagner 4 formation video2brain Android</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/Dhasp5CqqZc/</link>
		<comments>http://www.tutomobile.fr/concours-resultats-du-concours-pour-gagner-4-formation-video2brain-android/14/05/2011/#comments</comments>
		<pubDate>Sat, 14 May 2011 07:54:22 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[concours]]></category>
		<category><![CDATA[video2brain]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1819</guid>
		<description><![CDATA[Comme promis je vous donne]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Comme promis je vous donne les résultat du <a href="http://www.tutomobile.fr/concours-gagner-4-formations-videos-pour-apprendre-le-developpement-android/09/05/2011/">concours que l&#8217;on a organisé cette semaine</a>. Il y avait deux formations <a href="http://www.video2brain.com/fr/" target="_blank">video2brain</a> Devenez un développeur Android – Vol. 1 &amp; 2 à gagner en participant via les commentaire et deux autres formations en participant via <a href="https://twitter.com/TutoMobile" target="_blank">Twitter</a>. Ce qui nous fait un total de lot de <strong>319€</strong> ! Je vous remercie à avoir été aussi nombreux à participer.<span id="more-1819"></span> Vous avez été <strong>98</strong> à participer via les commentaires et <strong>53</strong> via Twitter ! Cela montre votre réel intérêt pour la plateforme Android et votre envie d&#8217;apprendre à développer. Enfin je tenais à remercier <a href="http://www.video2brain.com/fr" target="_blank">video2brain</a> de nous offrir ces quatres superbes lots qui feront le bonheur des quatres gagnants ! (on se croirait un peu au festival de Cannes avec tous ces remerciements ! <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<p style="text-align: justify;">Bon je ne vais pas faire durer le suspens plus longtemps et je vais commencer par annoncer les gagnants du concours Twitter. Ils ont été tiré au sort automatiquement par le site <a href="http://socontest.com/contests/hi-tech/formation-video-android-video2brain-2011-05-13-23-59-00.html" target="_blank">SoContest</a>. Il s&#8217;agit donc de : <a href="https://twitter.com/#!/cthiebot/status/67560824826372096" target="_blank"><strong>@cthiebot</strong></a> et de <a style="font-weight: bold;" href="http://twitter.com/Tagapetio/status/68787711280037889" target="_blank">@Tagapetio</a>. Bravo à eux ! Je les contacterais dans la journée en message privé.</p>
<p style="text-align: justify;">Je passe maintenant aux vainqueurs du concours via les commentaires. Comme je vous l&#8217;avais annoncée, j&#8217;ai tiré au sort les deux gagnants via le site <a href="http://www.random.org/" target="_blank">random.org</a>, et voici ce qu&#8217;il m&#8217;a retourné :</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/05/random_1.png" rel="lightbox[1819]"><img class="alignnone size-full wp-image-1822" title="random_1" src="http://www.tutomobile.fr/wp-content/uploads/2011/05/random_1.png" alt="" width="160" height="189" /></a> <a href="http://www.tutomobile.fr/wp-content/uploads/2011/05/random_2.png" rel="lightbox[1819]"><img class="alignnone size-full wp-image-1823" title="random_2" src="http://www.tutomobile.fr/wp-content/uploads/2011/05/random_2.png" alt="" width="161" height="190" /></a></p>
<p style="text-align: justify;">Ce qui signifie que les gagnants sont :</p>
<ul>
<li>58 : <strong>Justine </strong>(Je consulte quotidiennement ce site pour me former à android et iphone et ça m’a beaucoup aidé ! Merci beaucoup !!!)</li>
<li>71 : <strong>Jul’ </strong>(Ces formations m’intéressent énormément, merci pour ce concours ! *croise les doigts*)</li>
</ul>
<p>Bravo aux gagnants, je les contacterai dans la journée ! Encore merci aux autre d&#8217;avoir participé, et restez avec nous car quelques choses me dis qu&#8217;un autre concours devrait faire son apparitions dans les jours à venir&#8230; <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/Dhasp5CqqZc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/concours-resultats-du-concours-pour-gagner-4-formation-video2brain-android/14/05/2011/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/concours-resultats-du-concours-pour-gagner-4-formation-video2brain-android/14/05/2011/</feedburner:origLink></item>
		<item>
		<title>[Concours] Gagner 4 formations vidéos pour apprendre le développement Android</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/DLuf3gcDApQ/</link>
		<comments>http://www.tutomobile.fr/concours-gagner-4-formations-videos-pour-apprendre-le-developpement-android/09/05/2011/#comments</comments>
		<pubDate>Mon, 09 May 2011 08:06:12 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[concours]]></category>
		<category><![CDATA[video2brain]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1797</guid>
		<description><![CDATA[Comme je vous l&#8217;avais plus]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Comme je vous l&#8217;avais plus ou moins annoncé vendredi dans le <a href="http://www.tutomobile.fr/gestion-des-preferences-tutoriel-android-n%C2%B025/06/05/2011/">tutoriel vidéo Android sur les Preferences</a>, grâce à <a href="http://www.tutomobile.fr">TutoMobile</a> et <a href="http://www.video2brain.com/fr/" target="_blank">video2brain</a>, vous allez pouvoir gagner des formations vidéos pour apprendre à développer sous Android.<span id="more-1797"></span></p>
<p style="text-align: justify;">video2brain propose deux formations Android : <a href="http://www.video2brain.com/fr/products-149.htm" target="_blank">Devenez un développeur Android &#8211; Vol. 1</a> (39.95€) et <a href="http://www.video2brain.com/fr/products-242.htm" target="_blank">Devenez un développeur Android &#8211; Vol. 2</a> (39.80€). Ce sont ces deux formations que nous allons faire gagner à quatre d&#8217;entre vous, soit un total de lot de <strong>319€</strong> !</p>
<p style="text-align: justify;">Vous avez jusqu&#8217;au vendredi 13 mai 23h59 pour tenter votre chance. Pour cela il y a deux moyens de gagner :</p>
<ul style="text-align: justify;">
<li>(<strong>2 gagnants</strong>) le premier sera de laisser un commentaire sur cette article (tirage au sort grace à <a href="http://www.random.org/" target="_blank">random.org</a>, une seule participation par personne est autorisée)</li>
<li>(<strong>2 gagnants</strong>) le second, vous devrez poster sur Twitter le tweet qui suit (et part la même occasion vous pouvez nous suivre mais ce n&#8217;est pas obligatoire <a href="http://twitter.com/TutoMobile" target="_blank">@TutoMobile</a>) :</li>
</ul>
<p style="text-align: center;"><strong><em>Gagner une formation de développement Android (http://goo.gl/vy2zP) grâce à @TutoMobile et @video2brainfr #concours &#8211; http://sct.me/M7U</em></strong></p>
<p style="text-align: center;"><strong><span style="color: #ff0000;">Attention :mettez bien les http aux liens sinon votre candidature n&#8217;est pas pris en compte ! </span></strong></p>
<p style="text-align: justify;">N&#8217;hésitez pas à partager ce concours sur Twitter, Facebook, mail ou autre pour nous remercier, se sera notre plus belle récompense ! <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p style="text-align: center;"><strong>BONNE CHANCE A TOUS !</strong></p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/DLuf3gcDApQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/concours-gagner-4-formations-videos-pour-apprendre-le-developpement-android/09/05/2011/feed/</wfw:commentRss>
		<slash:comments>114</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/concours-gagner-4-formations-videos-pour-apprendre-le-developpement-android/09/05/2011/</feedburner:origLink></item>
		<item>
		<title>Gestion des Preferences [Tutoriel Android n°25]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/g1ZLizzmvWs/</link>
		<comments>http://www.tutomobile.fr/gestion-des-preferences-tutoriel-android-n%c2%b025/06/05/2011/#comments</comments>
		<pubDate>Fri, 06 May 2011 14:10:44 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Preferences]]></category>
		<category><![CDATA[tutoriel]]></category>
		<category><![CDATA[video2brain]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1775</guid>
		<description><![CDATA[Au vue des réactions (positives)]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Au vue des réactions (positives) sur le premier <a href="http://www.tutomobile.fr/application-multivue-avec-xcode-4-partie-1-tutoriel-iphone-n%C2%B010/01/04/2011/" target="_blank">tutoriel vidéo iPhone</a>, voici un tutoriel vidéo Android. Nous allons apprendre à utiliser les Preferences. Il s&#8217;agit de fichiers très utile permettant par exemple la sauvegarde des paramètres de vos applications.<span id="more-1775"></span></p>
<p style="text-align: justify;">Ce tutoriel vidéo vous est proposé par <a href="http://www.video2brain.com/fr/" target="_blank">video2brain</a> qui propose de nombreuses formations vidéos sur les logiciels Adobe mais pas seulement. Ils proposent notamment deux formations Android complètes (<a href="http://www.video2brain.com/fr/products-149.htm" target="_blank">Volume 1</a> et <a href="http://www.video2brain.com/fr/products-242.htm" target="_blank">Volume 2</a>) !</p>
<p style="text-align: justify;"><strong>D&#8217;ailleurs soyez présent lundi car nous allons vous proposer un petit jeu concours vous permettant de gagner, pas un, ni deux mais quatre accès gratuit et illimité au deux formations Android ! <a href="http://www.tutomobile.fr/concours-gagner-4-formations-videos-pour-apprendre-le-developpement-android/09/05/2011/">TENTER VOTRE CHANCE ICI</a></strong></p>
<p style="text-align: justify;">En attendant, je vous laisse regarder ce tuto vidéo, bon apprentissage :</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="338" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=23366544&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed type="application/x-shockwave-flash" width="600" height="338" src="http://vimeo.com/moogaloop.swf?clip_id=23366544&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/g1ZLizzmvWs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/gestion-des-preferences-tutoriel-android-n%c2%b025/06/05/2011/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<enclosure url="http://vimeo.com/moogaloop.swf?clip_id=23366544&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00adef&amp;amp;fullscreen=1&amp;amp;autoplay=0&amp;amp;loop=0" length="-1" type="application/x-shockwave-flash" /><media:content url="http://vimeo.com/moogaloop.swf?clip_id=23366544&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00adef&amp;amp;fullscreen=1&amp;amp;autoplay=0&amp;amp;loop=0" type="application/x-shockwave-flash" /><itunes:explicit>no</itunes:explicit><itunes:subtitle>Au vue des réactions (positives)</itunes:subtitle><itunes:author>Axon</itunes:author><itunes:summary>Au vue des réactions (positives)</itunes:summary><itunes:keywords>Tutoriels Android, Android, Preferences, tutoriel, video2brain</itunes:keywords><feedburner:origLink>http://www.tutomobile.fr/gestion-des-preferences-tutoriel-android-n%c2%b025/06/05/2011/</feedburner:origLink></item>
		<item>
		<title>Mon premier Widget sous Android  [Tutoriel Android n°25]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/uJSKqED-29U/</link>
		<comments>http://www.tutomobile.fr/mon-premier-widget-sous-android-tutoriel-android-n%c2%b025/25/03/2011/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 08:00:39 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[tutoriel]]></category>
		<category><![CDATA[Widget]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1670</guid>
		<description><![CDATA[Dans ce tutoriel, nous allons]]></description>
			<content:encoded><![CDATA[<div>
<p style="text-align: justify;">Dans ce tutoriel, nous allons aborder une facette très importante d’Android mais beaucoup moins utilisée par les développeurs. Il s’agit du développement de Widget. Nous allons créer un petit widget.<span id="more-1670"></span></p>
<p style="text-align: justify;">Tout d’abord, je tiens à remercier <a href="http://tutomobile.fr/">tutomobile.fr</a> pour m’avoir donné la chance d’écrire un article sur ce site.<em><strong>[Note d'Axon] Merci à <a href="http://www.tutos-android.com/" target="_blank">Nazim Benbourahla</a> d&#8217;avoir écrit ce tutoriel [/Note d'Axon]</strong></em></p>
</div>
<h3>Qu’est ce qu’un Widget ?</h3>
<div>
<p>Un Widget est un élément que vous pouvez placer sur votre bureau. Cet élément offre une possibilité d’interaction avec l’utilisateur, ainsi qu’un accès facile à certaines informations. Dans cette grande famille de Widget, on peut en distinguer deux types :</p>
<ul>
<li><strong>Les widgets natifs </strong>: Ceux qui sont installés nativement avec le téléphone, comme votre barre de recherche google, l’horloge, la météo (sur HTC par exemple)..</li>
<li><strong>Les widgets non natifs</strong> : Ces widgets sont placés lors de l’installation de nouvelles applications ou rajoutés par l’utilisateur.</li>
</ul>
</div>
<div>Android donne la possibilité à tous les utilisateurs de personnaliser leurs bureaux, en y disposant des widgets sur les différents bureaux.<br />
Prenons des exemples plus clairs pour comprendre ce qu’est un Widget :</p>
<ul>
<li>Barre de recherche Google.</li>
<li>Horloge.</li>
<li>Raccourcis réseaux sociaux.</li>
<li>Raccourcis de contrôle du lecteur MP3.</li>
</ul>
</div>
<h3>Comment créer un Widget</h3>
<p style="text-align: justify;">
<div>Afin que ce tutoriel ne soit pas trop difficile, certains pré-requis sont nécessaires. Notamment les bases de la programmation sur Android et la création d’une vue sous Android. <em><strong>[Note d'Axon] Je vous conseille d&#8217;aller faire un tour sur le blog de Nazim Benbourahla où il y a de nombreux tutos très intéressant : <a href="http://www.tutos-android.com" target="_blank">http://www.tutos-android.com</a> [/Fin note d'Axon]</strong></em></div>
<div>La création de Widget est disponible depuis la version 1.5 d’Android et cela grâce au framework <strong>AppWidget</strong>.</div>
<div style="text-align: justify;">
<div>
<p>Ce framework permet aux développeurs de créer leurs propres Widget. Chaque widget est un <strong>BroadcastReceiver </strong>couplé avec un fichier XML de metadata qui décrit les détails du Widget. Vous pouvez aussi facilement rajouter un Widget à une application que vous avez déjà créée.</p>
<p>Voici les différentes méthodes que vous pouvez surcharger dans la classe <strong>AppWidget </strong>:</p>
<ul>
<li><strong>OnEnabled()</strong> : Appelez quand votre Widget est créé. L’initialisation de votre Widget et ses données peuvent être effectuées ici.</li>
<li><strong>OnDisabled()</strong> : Appelez juste avant que le Widget soit supprimé et suivi de la méthode OnDeleted().</li>
<li><strong>OnUpdates()</strong> : Appelez quand le Widget nécessite une mise à jour de son interface.</li>
<li><strong>OnDeleted()</strong> : Appelez quand le WIdget est supprimé.</li>
<li><strong>OnReceive()</strong> : L’implementation par défaut de cette méthode est de récupèrer un évènement et appelle la méthode correspondante (voir au dessus).</li>
</ul>
<p>Pour créer un Widget , nous avons besoin des éléments suivants :</p>
<ul>
<li>Objet <strong>AppWidgetProviderInfo</strong> : Il décrit :
<ul>
<li>Les metadatas pour un widget donné.</li>
<li>Le <strong>AppWidget Layout</strong>.</li>
<li>Les fréquences de mises à jour du widget</li>
<li>La classe <strong>AppWidgetProvider </strong>(Ce fichier est défini en XML).</li>
</ul>
</li>
<li>Implémenter la classe <strong>AppWidgetProvider </strong>: Cette classe définit comment s’effectuent les échanges avec votre Widget. Il est principalement basé sur les événements <strong>Broadcast</strong>. Donc nous aurons besoin d’un <strong>BroadCast Receiver</strong>.</li>
<li>Bien sûr une vue pour votre Widget</li>
</ul>
</div>
</div>
<p style="text-align: justify;">
<h3>Mon premier Widget “Hello Word”</h3>
<div style="text-align: justify;">
<p>Nous allons avancer doucement dans ce tutoriel et créer notre HelloWorldWidget.</p>
<p>Pour commencer créez un projet “<strong>HelloWorldWidget</strong>” avec les données suivantes :</p>
<ul>
<li>Build Target / Version du SDK : <strong>Version 2.2</strong>.</li>
<li>Nom de l’application : <strong>My Hello World Widget</strong>.</li>
<li>Nom du package : <strong>com.android.tuto.widget</strong>.</li>
<li>Activité créée : <strong>HelloWorldWidgetActivity</strong>.</li>
</ul>
<p>Dans votre fichier de vue <strong>main.xml</strong> (res/layout), créez une vue avec un <strong>textView </strong>comme ci-dessous.</p>
</div>
<p style="text-align: justify;">

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_gravity</span>=<span style="color: #ff0000;">&quot;center&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/hello_world_widget&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/hello_world_widget&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_gravity</span>=<span style="color: #ff0000;">&quot;center&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:layout_marginTop</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:padding</span>=<span style="color: #ff0000;">&quot;10dip&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;#FFF&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div>Donc ce fichier ressemble à un simple fichier de vue sans aucune complexité.<br />
Maintenant dans le fichier de ressource <strong>strings.xml</strong>, il faut rajouter la variable hello_world_widget. ce qui donnera :</div>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hello&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Hello World, HelloWorldWidgetActivity!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>My Hello World Widget<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hello_world_widget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Bienvenue dans mon Widget Hello World :) <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div>Plus haut nous parlions d’un fichier de configuration XML du widget. Donc pour ce fichier il suffit de créer un dossier xml dans votre dossier res. Dans ce dernier créer un fichier <strong>my_widget_provider.xml</strong> qui contiendra le code suivant :</div>
<div>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appwidget-provider</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:minWidth</span>=<span style="color: #ff0000;">&quot;160dip&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:minHeight</span>=<span style="color: #ff0000;">&quot;80dip&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:updatePeriodMillis</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">   		 <span style="color: #000066;">android:initialLayout</span>=<span style="color: #ff0000;">&quot;@layout/main&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</div>
<div>
<div>
<p>Petite explication sur ce code :</p>
<ul>
<li><strong>android:minWidth</strong> : Largeur minimum du widget.</li>
<li><strong>android:minHeight</strong> : Hauteur minimum du Widget.</li>
<li><strong>android:updatePeriodMillis</strong> : Temps de mise à jour du Widget.</li>
<li><strong>android:initialLayout</strong> : vue qui sera appliqué au Widget.</li>
</ul>
<p style="text-align: justify;">Modifiez la classe Java (<strong>HelloWorldWidgetActivity</strong>). Ce qui donnera simplement le code suivant</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.android.tuto.widget</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.appwidget.AppWidgetProvider</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorldWidgetActivity <span style="color: #000000; font-weight: bold;">extends</span> AppWidgetProvider <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;" lang="java">Pour finir il faut modifier le manifest comme ci-dessous :</p>
<p style="text-align: justify;" lang="java">

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;com.android.tuto.widget&quot;</span> <span style="color: #000066;">android:versionCode</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:versionName</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">android:icon</span>=<span style="color: #ff0000;">&quot;@drawable/icon&quot;</span> <span style="color: #000066;">android:label</span>=<span style="color: #ff0000;">&quot;@string/app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;receiver</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;.HelloWorldWidgetActivity&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">android:label</span>=<span style="color: #ff0000;">&quot;@string/app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.appwidget.action.APPWIDGET_UPDATE&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta-data</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.appwidget.provider&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">android:resource</span>=<span style="color: #ff0000;">&quot;@xml/my_widget_provider&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/receiver<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div style="text-align: justify;">Nous allons tester tout cela. Lancez le projet. On a l’impression que rien ne se passe, tout simplement parce que l’on vient de créer un Widget qu’il faudra mettre sur votre bureau.<br />
Pour cela il faut suivre les étapes suivantes :</p>
<p>1. Une fois arrivé sur l’écran d’acceuil de l’emulateur, cliquez longuement sur le bouton Home.</p>
</div>
<p><a href="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_1.jpg" rel="lightbox[1670]"><img class="aligncenter size-full wp-image-1676" title="widget_1" src="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_1.jpg" alt="" width="339" height="496" /></a> 2. Cliquez sur Widget</p>
<div style="text-align: justify;">
<p><a href="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_2.jpg" rel="lightbox[1670]"><img class="aligncenter size-full wp-image-1677" title="widget_2" src="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_2.jpg" alt="" width="332" height="496" /></a>3. Un autre écran apparaît, il suffit de choisir notre Widget</p>
<div><a href="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_3.jpg" rel="lightbox[1670]"><img class="aligncenter size-full wp-image-1678" title="widget_3" src="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_3.jpg" alt="" width="335" height="497" /></a></div>
<div>4. Ce qui donnera <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<p><a href="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_4.jpg" rel="lightbox[1670]"><img class="aligncenter size-full wp-image-1679" title="widget_4" src="http://www.tutomobile.fr/wp-content/uploads/2011/03/widget_4.jpg" alt="" width="329" height="499" /></a></p>
</div>
<p style="text-align: justify;">Voila notre premier Widget Hello World est fini.</p>
<h3 style="text-align: justify;">Conclusion</h3>
<p style="text-align: justify;">Donc ce tutoriel s’arrête là, en espérant qu’il vous ait aidé à comprendre comment fonctionnent les Widget et le framwork AppWidget. En espérant que cette collaboration avec tutomobile se poursuive. N’hésitez pas à me contacter sur mon site ou commenter cet article.</p>
</div>
</div>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/uJSKqED-29U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/mon-premier-widget-sous-android-tutoriel-android-n%c2%b025/25/03/2011/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/mon-premier-widget-sous-android-tutoriel-android-n%c2%b025/25/03/2011/</feedburner:origLink></item>
		<item>
		<title>Réaliser une custom ProgressBar/SeekBar sur Android [Tutoriel Android n°24]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/8XMS5Tfen2A/</link>
		<comments>http://www.tutomobile.fr/realiser-une-progressbar-seekbar-personnalisee-sur-android-tutoriel-android-n%c2%b024/10/02/2011/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 14:41:39 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[ProgressBar]]></category>
		<category><![CDATA[SeekBar]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1615</guid>
		<description><![CDATA[Dans cet article, on va]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Dans cet article, on va faire une pierre deux coups, on va apprendre à modifier la SeekBar (comparable au UISlider sur <a href="http://www.tutomobile.fr/category/tutorial-iphone/">iPhone</a> pour ceux qui connaissent) qui peut s’avérer utile comme timeline sur un lecteur audio/video, et la ProgressBar Horizontale (et uniquement l’horizontale, il existe en effet des ProgressBar dites « indéterminée » que l’ont peut comparer à ce qu’on appelle un loader, ou icône de chargement), qui peut être utilisée pour observer la progression d’un téléchargement par exemple.<span id="more-1615"></span><br />
Ces deux widget se ressemblent beaucoup et pour cause : ils utilisent le même design (pas du tout à mon goût).</p>
<div id="attachment_1616" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/progressbar1.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1616 " title="progressbar1" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/progressbar1.jpg" alt="" width="480" height="294" /></a><p class="wp-caption-text">Figure 1 - ProsgressBar/SeekBar d&#39;origines et résultats finaux</p></div>
<div id="attachment_1617" class="wp-caption aligncenter" style="width: 329px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/loading.png" rel="lightbox[1615]"><img class="size-full wp-image-1617 " title="loading" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/loading.png" alt="" width="319" height="67" /></a><p class="wp-caption-text">Figure 2 - ProgressBar type &quot;loader&quot;</p></div>
<h3>A l’assaut des styles de la ProgressBar (Horizontale !)</h3>
<p style="text-align: justify;">Une ProgressBar par défaut se constitue d’une image de type loading, qu’on pourra retrouver dans les fichiers images du SDK sous le nom de « spinner » (exemple : spinner_black_48.png). Pour obtenir une ProgressBar Horizontale (que l’on abrégera par PBH pour la suite de notre article), il suffit d’ajouter un style bien précis à la ProgressBar que l’on a déclaré dans le fichier XML de notre Activity :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ProgressBar</span></span>
<span style="color: #009900;">        <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;?android:attr/progressBarStyleHorizontal&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:progress</span>=<span style="color: #ff0000;">&quot;50&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:max</span>=<span style="color: #ff0000;">&quot;100&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:secondaryProgress</span>=<span style="color: #ff0000;">&quot;80&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>On remarquera ici plusieurs attributs pour notre PBH :</p>
<ul>
<li>Max :  permet de définir la valeur totale de la progression de notre barre, je mets toujours 100 pour avoir une notion de pourcentage dans nos calculs, ce qui les simplifiera.</li>
<li>Progress : indique tout simplement le niveau de progression</li>
<li>secondProgress : indique un deuxième niveau de progression, ce qui peut être utile dans une écoute de musique en streaming par exemple, ou le progress indique la progression de lecture, et le secondProgress indique la progression du téléchargement.</li>
<li>Style : le style de notre barre, il fait appelle ici à l’attribut de style  (un attribut de style est en fait une référence/un pointeur de style) de la PBH native d’Android.</li>
</ul>
<h4>Retour aux sources…</h4>
<p style="text-align: justify;">C’est ici que nous allons intervenir, nous allons étendre le style de la PBH (comme si l’on étendait une classe Java) et en l’appliquant à notre progressBar. La documentation des styles sur Android est très faible, elle ne fait qu’indiquer les styles disponibles, sans vraiment nous indiquer à quoi ils correspondent et comment ils sont construits, nous allons donc faire un tour dans les sources pour nous documenter.<br />
Comme l’indique le fichier themes.xml  des sources :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;progressBarStyleHorizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:style/Widget.ProgressBar.Horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">L’attribut de style progressBarStyleHorizontal fait référence au style Widget.ProgressBar.Horizontal, où l’on trouvera les spécifications dans le fichiers styles.xml :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Widget.ProgressBar.Horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:indeterminateOnly&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:progressDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:drawable/progress_horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:indeterminateDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:drawable/progress_indeterminate_horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:minHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>20dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:maxHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>20dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">On ne va pas s’intéresser ici à “inderterminateOnly” et à “indeterminateDrawable », qui concerne les PBH qui n’indique pas l’évolution de progression de la barre (mais vous pouvez également modifier l’image si ça vous chante <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<p style="text-align: justify;">Pour modifier ce style, rien de plus simple !</p>
<p style="text-align: justify;">On va créer un fichier styles.xml dans notre projet, et y insérer notre nouveau style en indiquant qu’il est une extension de Widget.ProgressBar.Horizontal :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CustomProgressBarHorizontal&quot;</span> <span style="color: #000066;">parent</span>=<span style="color: #ff0000;">&quot;android:Widget.ProgressBar.Horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:progressDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@drawable/custom_progress_bar_horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:minHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>10dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:maxHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>20dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Par manque d’imagination, j’ai appelé ce nouveau style CustomProgressBarHorizontal. Vous remarquerez que j’ai modifié la hauteur minimum (minHeight)  pour avoir la possibilité d’avoir une barre plus fine, et que j’ai modifié l’image qui est utilisée en tant que progressDrawable (qui en fait un fichier xml, qui définit les images de fond, de progress, et de secondaryProgress de notre barre).</p>
<p style="text-align: justify;">Et là, PAF ! Eclipse (désolé pour ceux qui utilise un autre IDE) n’est pas content et nous indique que le drawable custom_progress_bar_horizontal n’existe pas, ce qui est plutôt logique, puisqu’on ne l’a pas encore créée.</p>
<p style="text-align: justify;">Une fois de plus, on va s’aider des sources pour comprendre comment la classe ProgressBar utilise le fichier xml, il suffit ici d’aller fouiller dans les fichiers de notre SDK : %ANDROID_SDK_PATH%/platforms/android-n/data/res/drawable/ (où n est la version de l’API)</p>
<p style="text-align: justify;">Le fichier progress_horizontal est un fichier XML contenant des drawable, des classes bien pratiques permettant de faire des dessins plus ou moins basiques (dégradé, angle, cercle, etc…) à l’aide du XML, je vous conseille d’aller faire un tour du la <a href="http://developer.android.com/guide/topics/resources/drawable-resource.html" target="_blank">documentation des drawable</a> pour vous y familiariser.</p>
<p style="text-align: justify;">Dans ce fichier, on y retrouve un layer-list, qui est en fait un tableau d’autres drawable. Ces drawables sont dessinés les uns au dessus des autres en suivant l’ordre dans lequel ils sont écrits dans le fichier : donc pour notre PBH, il faudra donc dessiner le background, le secondaryProgress et le progress pour finir :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layer-list</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/background&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#ff9d9e9d&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:centerColor</span>=<span style="color: #ff0000;">&quot;#ff5a5d5a&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:centerY</span>=<span style="color: #ff0000;">&quot;0.75&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#ff747674&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/secondaryProgress&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#80ffd300&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:centerColor</span>=<span style="color: #ff0000;">&quot;#80ffb600&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:centerY</span>=<span style="color: #ff0000;">&quot;0.75&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#a0ffcb00&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/progress&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#ffffd300&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:centerColor</span>=<span style="color: #ff0000;">&quot;#ffffb600&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:centerY</span>=<span style="color: #ff0000;">&quot;0.75&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#ffffcb00&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layer-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Quand on regarde de plus près, on remarque que ces drawables sont de simples rectangles (shapes) comprenant des coins arrondis et un dégradé.</p>
<p style="text-align: justify;">Pour modifier notre PBH, on va ici faire simple et modifier les dégradés (les simplifier et changer les  couleurs), cela peut sembler un peu simple, mais cela suffira à modifier notre PBH pour qu’elle puisse corresponde au thème général de votre application  et qu’elle soit identique sur tous les terminaux.</p>
<p style="text-align: justify;">Ce qui nous donne les codes suivant, avec un thème bleu à notre PBH :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layer-list</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/background&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#ffffffff&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:centerColor</span>=<span style="color: #ff0000;">&quot;#ffdddddd&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:centerY</span>=<span style="color: #ff0000;">&quot;0.50&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#ffffffff&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/secondaryProgress&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#770e75af&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#771997e1&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;90&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@android:id/progress&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span> <span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#ff0e75af&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#ff1997e1&quot;</span></span>
<span style="color: #009900;">		     <span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;90&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/clip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layer-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">On aura donc un fond blanc avec un léger dégradé vers le gris en son centre. On laisse les coins arrondis (border-radius) à 5dip, ce qui nous fera l’effet un demi cercle sur les extrémités de notre PBH si on lui fixe un layout_height à wrap_content  (et oui, n’oubliez pas qu’on a mis le minHeight de notre style à 10dip <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).  En appliquant notre style à la PBH, on aura donc le rendu suivant :</p>
<p style="text-align: justify;">
<div id="attachment_1623" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/custom_progress_bar_horizontal.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1623" title="custom_progress_bar_horizontal" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/custom_progress_bar_horizontal.jpg" alt="" width="480" height="120" /></a><p class="wp-caption-text">Figure 3 - Custom ProgressBar Horizontale</p></div>
<p style="text-align: justify;"><em>Remarque : cela ne vous coûte rien de garder les mêmes ID pour vos drawables (android.R.id.progress par exemple), ils sont utilisées dans la classe ProgressBar.java des sources, cela vous évitera quelques petits soucis</em>.</p>
<h3><strong>Customisation de la SeekBar </strong></h3>
<p style="text-align: justify;"><strong><br />
</strong>Quand on regarde le visuel d’une SeekBar, ce n’est rien d’autre qu’une progressBar Horizontale avec un petit « sélectionneur « en plus : chez Google, ils l’ont baptisé thumb (traduction anglaise de « pouce »).</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/progress_seek_bar_comparaison.jpg" rel="lightbox[1615]"><img class="aligncenter size-full wp-image-1625" title="progress_seek_bar_comparaison" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/progress_seek_bar_comparaison.jpg" alt="" width="480" height="105" /></a></p>
<p style="text-align: justify;">Libre à chacun d’apprécier ou pas le design de ce thumb, personnellement, ce n’est toujours pas mon cas.</p>
<p style="text-align: justify;">Je ne vais bien entendu pas m’étaler ici sur la modification de la barre de progression, il suffit de reprendre la première partie de cet article, mais je vous ferai juste remarquer que si l’on regarde une fois de plus les sources, le progressDrawable de la seekBar fait appel au même fichier que la PBH :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Widget.SeekBar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:indeterminateOnly&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:progressDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:drawable/progress_horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:indeterminateDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:drawable/progress_horizontal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:minHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>20dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:maxHeight&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>20dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:thumb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@android:drawable/seek_thumb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:thumbOffset&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>8dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:focusable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">On va  s’intéresser ici aux items  « thumb » et « thumbOffset » (décalage du thumb).<br />
La customisation du thumb va se faire de la même manière que celle de la PBH, on va étendre le style du widget SeekBar, en modifiant le drawable du thumb.</p>
<p style="text-align: justify;">Remarque : il est également possible de changer le thumb et le thumbOffSet directement dans les attributs d’une SeekBar lors sa déclaration dans le layout de notre Activity, mais je trouve plus propre le fait de le faire dans l’extension du style, de plus, si vous avez plusieurs SeekBar, vous n’aurez pas à ses attributs à chaque fois, c’est le style que vous aurez appliqué qui s’en chargera.</p>
<p style="text-align: justify;">Dans notre nouveau style de SeekBar, on change donc notre thumb :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:thumb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@drawable/seek_bar_thumb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Et, comme dans les sources, ce fichier sera un fichier XML comprenant un &lt;selector&gt; , un autre drawable (stateListDrawable) qui définit plusieurs autres drawables selon l’état du widget, des états qui dépendent la plupart du temps des actions de l’utilisateur : focus, pressed, selected, etc… :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;selector</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_pressed</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">android:drawable</span>=<span style="color: #ff0000;">&quot;@drawable/custom_thumb_state_pressed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_focused</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">android:drawable</span>=<span style="color: #ff0000;">&quot;@drawable/custom_thumb_state_selected&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_selected</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">android:drawable</span>=<span style="color: #ff0000;">&quot;@drawable/custom_thumb_state_selected&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:drawable</span>=<span style="color: #ff0000;">&quot;@drawable/custom_thumb_state_default&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/selector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Ces 4 items, dont les noms parlent d’eux même, sont dans notre cas d’autres fichiers XML, comprenant des formes (shape), comme on a pu les rencontrer dans la première partie de cette article (cf. <a href="http://developer.android.com/guide/topics/resources/drawable-resource.html" target="_blank">documentation des drawable </a>).</p>
<p style="text-align: justify;">Voici par exemple celui qui décrit l’état « normal » (par défaut) de notre thumb (les deux autres  sont quasiment identiques, juste les couleurs définies sont modifiées) :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:shape</span>=<span style="color: #ff0000;">&quot;oval&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;size</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;35dip&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:height</span>=<span style="color: #ff0000;">&quot;35dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stroke</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;1dip&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:color</span>=<span style="color: #ff0000;">&quot;#ffffffff&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;#ffcdcdcd&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;#fff8f8f8&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:type</span>=<span style="color: #ff0000;">&quot;linear&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Un simple disque, de rayon 35dip, avec une bordure et un dégradé :</p>
<div id="attachment_1627" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_default.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1627" title="seek_bar_default" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_default.jpg" alt="" width="480" height="88" /></a><p class="wp-caption-text">Figure 5 - SeekBar avec thumb par défaut</p></div>
<div id="attachment_1628" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_focused.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1628" title="seek_bar_focused" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_focused.jpg" alt="" width="480" height="88" /></a><p class="wp-caption-text">Figure 4 - seekBar etat focused</p></div>
<div id="attachment_1629" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_pressed.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1629" title="seek_bar_pressed" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_bar_pressed.jpg" alt="" width="480" height="88" /></a><p class="wp-caption-text">Figure 7 - seekBar état pressed</p></div>
<div id="attachment_1630" class="wp-caption aligncenter" style="width: 490px"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/bottom_offset_bug.jpg" rel="lightbox[1615]"><img class="size-full wp-image-1630" title="bottom_offset_bug" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/bottom_offset_bug.jpg" alt="" width="480" height="88" /></a><p class="wp-caption-text">Figure 6 - seekbar état normal</p></div>
<p style="text-align: justify;">Lorsque l’on glisse le sélecteur au fond à droite, on remarque que l’image est coupée, chose qui se reproduira du côté gauche, et c’est là qu’intervient le <em>thumbOffSet</em>.</p>
<h4><strong>Quel ThumbOffSet choisir ?</strong></h4>
<p style="text-align: justify;">Le style de la SeekBar android, qu’on a pu voir plus haut dans cet article, définit un thumbOffSet par défaut à 8dip, pourquoi 8dip ? Il n’y a qu’à regarder les fichiers images utilisées pour le thumb de base !</p>
<p style="text-align: justify;">Pour cela, sur votre poste, regardez de plus près</p>
<p style="text-align: justify;">%ANDROID_SDK_PATH%/platforms/android-7/data/res/drawable-mdpi/seek_thumb_normal.jpg</p>
<p style="text-align: justify;">(pour un terminal avec une densité moyenne, un dip est égal à un pixel, c’est pour cela que j’ai choisis le dossier drawable-mdpi : plus de renseignements sur les densité d’écran <a href="http://developer.android.com/guide/practices/screens_support.html" target="_blank">ici</a>).</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_thumb_normal.png" rel="lightbox[1615]"><img class="alignleft size-full wp-image-1631" title="seek_thumb_normal" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/seek_thumb_normal.png" alt="" width="32" height="29" /></a></p>
<p style="text-align: justify;">On s’aperçoit que l’image à une largeur de 32 pixel, et qu’elle possède deux zones de vide de 8 pixels de chaque côté du thumb qui y est dessiné, ce qui explique le 8 pour le thumbOffset dans le style par défaut des seekBar.</p>
<p style="text-align: justify;"><em><span style="text-decoration: underline;">Remarque</span></em><em> : rien ne vous empêche effectivement de créer vos thumb avec des fichiers image, à l’aide notamment de Photoshop ou Gimp, j’ai choisis ici de les créer à l’aide des drawable android et de leur xml.</em></p>
<p style="text-align: justify;">Comme nos thumb sont des drawable en xml, ils n’auront pas de marges vides, nous allons donc mettre notre thumbOffset à 0dip dans notre style :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CustomSeekBar&quot;</span> <span style="color: #000066;">parent</span>=<span style="color: #ff0000;">&quot;android:Widget.SeekBar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:progressDrawable&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@drawable/custom_seek_bar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:thumb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>@drawable/seek_bar_thumb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;android:thumbOffset&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>0dip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Et on l’insère dans le layout de notre Activity :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SeekBar</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:progress</span>=<span style="color: #ff0000;">&quot;50&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:max</span>=<span style="color: #ff0000;">&quot;100&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;@style/CustomSeekBar&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:secondaryProgress</span>=<span style="color: #ff0000;">&quot;80&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_margin</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p style="text-align: justify;">Il n’y a plus qu’à admirer le résultat final de notre article  ! <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/offset0.png" rel="lightbox[1615]"><img class="aligncenter size-full wp-image-1632" title="offset0" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/offset0.png" alt="" width="480" height="800" /></a></p>
<p style="text-align: justify;">
<p style="text-align: justify;">Vous pouvez trouver les <a href="http://www.mediafire.com/?ndt1drc6ucomwev" target="_blank">sources du projet ici</a>.</p>
<p style="text-align: justify;">Je tenais à remercier Alex (dit Sakaroz) qui a écrit ce tutorial Android très intéressant. Je vous invite à aller faire un tour sur son blog : <a href="http://blog.sakaroz.com/" target="_blank">http://blog.sakaroz.com/</a> et son site pro : <a href="http://www.sakaroz.com/" target="_blank">http://www.sakaroz.com/</a></p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/8XMS5Tfen2A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/realiser-une-progressbar-seekbar-personnalisee-sur-android-tutoriel-android-n%c2%b024/10/02/2011/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/realiser-une-progressbar-seekbar-personnalisee-sur-android-tutoriel-android-n%c2%b024/10/02/2011/</feedburner:origLink></item>
		<item>
		<title>Le RIL (Radio Interface Layer) Android</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/29yRpRvijq8/</link>
		<comments>http://www.tutomobile.fr/le-ril-radio-interface-layer-android/08/02/2011/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 08:00:40 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1600</guid>
		<description><![CDATA[Lorsqu&#8217;on code une application Android]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify">Lorsqu&#8217;on code une application Android (un apk), on ne sait pas forcément ce qu&#8217;il se passe derrière. Il peut être intéressant de se pencher sur l&#8217;architecture globale Android pour mieux comprendre ce qu&#8217;il se passe derrière l&#8217;API fournie par le SDK (enfin c&#8217;est mon idée).<span id="more-1600"></span></p>
<p style="text-align: justify">Les mobiles Android, sont comme la plupart des smartphones d&#8217;aujourd&#8217;hui composés généralement d&#8217;au moins 2 cœurs, 1 pour l&#8217;Application (Linux et Android) et 1 pour le Modem (ou Baseband ou encore Radio).</p>
<p style="text-align: justify">Petit rappel sur les Telecoms :<br />
Le Modem (2G/3G/LTE) est composé de plusieurs couches protocolaires définies par les standards 3GPP (3rd Generation Partnership Project).<br />
C&#8217;est lui qui s&#8217;attache au réseau, gère les appels (entrants/sortants), les SMS, la connexion de données du mobile (PDP), la carte SIM etc&#8230;</p>
<p style="text-align: justify">Généralement, un Modem est composé comme suit :</p>
<p style="text-align: justify"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/3.png" rel="lightbox[1600]"><img class="aligncenter size-full wp-image-1601" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/3.png" alt="" width="124" height="224" /></a></p>
<p style="text-align: justify">Les différentes couches sont:</p>
<ol style="text-align: justify">
<li>AT (ou      MMI) : c&#8217;est la couche en contact avec le monde extérieur, c&#8217;est par ici      qu&#8217;arrivent les actions utilisateurs (passer un appel, lire un contact,      etc.)</li>
<li>Abstraction      Layer : elle est en charge de transcrire les commandes AT ou les actions      utilisateurs gérées par la MMI en commandes NAS</li>
<li>NAS : Pour      Non-Access Stratum, elle est constituée des modules CM (connection      management), MM (mobility management), CC (call control), SS, SMS, SM etc.</li>
<li>AS : Pour      Access Stratum, elle est la tour de contrôle du Modem, elle gère la      cellule courante, les mesures des cellules voisines, le passage d&#8217;une      technologie à l&#8217;autre (2G-3G et inversement) durant un appel (handover) ou      non (cell change), etc. Elle      est composée de modules tels que RR, RLC, MAC</li>
<li>L1 : Pour      Layer 1, c&#8217;est la couche basse qui gère les canaux physiques et pilote la      radio.</li>
</ol>
<p style="text-align: justify">Généralement, les Modems seuls (la plupart des téléphones mobiles) sont pilotés par la MMI (Man Machine Interface), ou IHM, c&#8217;est en gros ce que voit l&#8217;utilisateur (icônes, menus, boutons&#8230;)</p>
<p style="text-align: justify">Vous l&#8217;aurez compris, avec les smartphones, c&#8217;est à ce niveau qu&#8217;Android intervient, c&#8217;est la MMI. Bien entendu, Android ne se cantonne pas qu&#8217;à ca. Il gère au travers du système Linux, le multimédia, les périphériques (Wifi, Bluetooth, Camera&#8230;), la batterie, le filesystem (SDCARD, &#8230;) , etc.</p>
<p style="text-align: justify">Pour piloter le Modem, et dans le but d&#8217;offrir l&#8217;interface la plus étendue possible (applicable au plus grands nombre de Modems existants), Google a décidé d&#8217;utiliser les commandes AT.</p>
<p style="text-align: justify">Les commandes AT sont des commandes ASCII définies par les standards 3GPP (27.007 et 27.005 pour les SMS) permettant de piloter un modem.</p>
<p style="text-align: justify">Voici le principe général d&#8217;une commande AT (<a href="http://www.technologuepro.com/gsm/commande_at.htm" target="_blank">site</a>) :</p>
<p style="text-align: justify"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/Image2.jpg" rel="lightbox[1600]"><img class="aligncenter size-full wp-image-1602" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/Image2.jpg" alt="" width="557" height="330" /></a></p>
<p style="text-align: justify">Sur les smartphones Android, l&#8217;Application (Linux Android) envoie les commandes AT pour piloter le Modem. Les fournisseurs ont donc mis en place des moyens d&#8217;envoyer ces commandes d&#8217;un OS à l&#8217;autre. D&#8217;autres fournisseurs, se sont passés des commandes AT et envoient directement des commandes de la couche &laquo;&nbsp;Abstraction Layer&nbsp;&raquo; depuis l&#8217;Application (on perd alors toute portabilité sur d&#8217;autres Modems). Bref, je ne rentrerai pas dans le détail, car la discussion pourrait être longue&#8230;</p>
<p style="text-align: justify">En résumé, nous avons d&#8217;une part, un Modem piloté par commandes AT et d&#8217;autre part, Android qui doit piloter ce Modem. C&#8217;est a ce moment qu&#8217;intervient le RIL (Radio interface Layer).</p>
<p style="text-align: justify">Le principe du RIL n&#8217;est pas nouveau, il existait déjà avec Windows Mobile. Et son utilité reste assez simple, transformer les requêtes Android (appelées RIL_REQUEST) en commandes AT.</p>
<p style="text-align: justify">Le RIL est un démon écrit en C, Android s&#8217;y connecte par le biais du RILJ (pour RIL java) au travers d&#8217;une socket où les objets sont (dé)sérialisés pour y être transportés.</p>
<p style="text-align: justify">Le RIL écrit ensuite les commandes AT sur une socket ou tout autre port (tty, &#8230;) et elles sont alors convoyées jusqu&#8217;au Modem, ce dernier renvoie alors le retour des commandes sur le port ouvert.</p>
<p style="text-align: justify">Voici un schéma permettant de mieux comprendre le principe général :</p>
<p style="text-align: justify"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/4.png" rel="lightbox[1600]"><img class="aligncenter size-full wp-image-1603" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/4.png" alt="" width="441" height="264" /></a></p>
<p style="text-align: justify">Prenons un exemple concret, l&#8217;appel sortant (ou MO Call).</p>
<p>Lorsque l&#8217;utilisateur presse le &laquo;&nbsp;bouton vert&nbsp;&raquo;, la requête passe au travers du Framework pour arriver jusqu&#8217;au RILJ par la méthode dial qui va alors préparer une RIL_REQUEST_DIAL et fournir les paramètres nécessaires pour passer l&#8217;appel (numéro et présentation du numéro appelant).</p>
<p>Voici le code de la méthode dial RIL.java</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span>
dial <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> address, <span style="color: #000066; font-weight: bold;">int</span> clirMode, Message result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 RILRequest rr <span style="color: #339933;">=</span> RILRequest.<span style="color: #006633;">obtain</span><span style="color: #009900;">&#40;</span>RIL_REQUEST_DIAL, result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 rr.<span style="color: #006633;">mp</span>.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 rr.<span style="color: #006633;">mp</span>.<span style="color: #006633;">writeInt</span><span style="color: #009900;">&#40;</span>clirMode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>RILJ_LOGD<span style="color: #009900;">&#41;</span> riljLog<span style="color: #009900;">&#40;</span>rr.<span style="color: #006633;">serialString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&amp;gt; &quot;</span> <span style="color: #339933;">+</span> requestToString<span style="color: #009900;">&#40;</span>rr.<span style="color: #006633;">mRequest</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 send<span style="color: #009900;">&#40;</span>rr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify">Cette requête est ensuite reçue par le RIL (Google a fourni le reference-ril.c pour exemple), qui transforme cette requête en commande ATD :</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">void</span> requestDial<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span>data<span style="color: #339933;">,</span> size_t datalen<span style="color: #339933;">,</span> RIL_Token t<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
RIL_Dial <span style="color: #339933;">*</span>p_dial<span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>cmd<span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>clir<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ret<span style="color: #339933;">;</span>
&nbsp;
p_dial <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>RIL_Dial <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>data<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>p_dial<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>clir<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span> clir <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;I&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/*invocation*/</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span> clir <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;i&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/*suppression*/</span>
        <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span> clir <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>   <span style="color: #808080; font-style: italic;">/*subscription default*/</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
asprintf<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>cmd<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;ATD%s%s;&quot;</span><span style="color: #339933;">,</span> p_dial<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>address<span style="color: #339933;">,</span> clir<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ret <span style="color: #339933;">=</span> at_send_command<span style="color: #009900;">&#40;</span>cmd<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
free<span style="color: #009900;">&#40;</span>cmd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* success or failure is ignored by the upper layer here.
       it will call GET_CURRENT_CALLS and determine success that way */</span>
RIL_onRequestComplete<span style="color: #009900;">&#40;</span>t<span style="color: #339933;">,</span> RIL_E_SUCCESS<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify">Pour un appel au 0612345678, le Modem va recevoir ATD0612345678;</p>
<p style="text-align: justify">Le RIL passe ensuite en mode lecture, en attente de réception de la réponse finale qui peut être OK, NO CARRIER si l&#8217;appel n&#8217;a pas été établie ou +CME ERROR: xx lorsqu&#8217;une erreur est survenue (xx code de l&#8217;erreur).</p>
<p style="text-align: justify">Une fois la réponse traitée, il (le RIL) envoie au Framework (RILJ) la RIL_RESPONSE avec les paramètres (si besoin).</p>
<p style="text-align: justify">Le RIL dépile ensuite les autres requêtes (envoie de SMS, activation des données, mesure du signal, etc.) et les exécute une à une. L&#8217;information de l&#8217;appel remonte quant à elle jusqu&#8217;au Dialer par le biais des interfaces.</p>
<p style="text-align: justify">Note: le seul bémol de cette architecture, c&#8217;est que, par défaut, le RIL empile les requêtes à destination du Modem. Alors qu&#8217;avec quelques modifications, on pourrait ouvrir plusieurs canaux AT (car les Modems le supportent) et exécuter des requêtes en parallèle pour gagner en efficacité. Mais tout cela reste du ressort des constructeurs.</p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/29yRpRvijq8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/le-ril-radio-interface-layer-android/08/02/2011/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/le-ril-radio-interface-layer-android/08/02/2011/</feedburner:origLink></item>
		<item>
		<title>Partager un texte sur Twitter, Facebook, etc. [Tutoriel Android n°23]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/TuXfht7HAT0/</link>
		<comments>http://www.tutomobile.fr/partager-un-element-sur-twitter-facebook-etc-tutoriel-android-n%c2%b023/05/02/2011/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 08:00:58 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[partage]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1566</guid>
		<description><![CDATA[Nous allons voir dans ce]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Nous allons voir dans ce <a href="http://www.tutomobile.fr" target="_blank">tutorial</a>, comment faire pour partager un texte, que l&#8217;on aura saisi dans un EditText, sur <a href="http://twitter.com/TutoMobile" target="_blank">Twitter</a>, <a href="http://www.facebook.com/pages/Tuto-Mobile/132774283400523" target="_blank">Facebook</a> ou toutes autres applications qui permettent le partage de message (c&#8217;est à dire par mail, sms, et toutes les applications du style Friend Stream, Peep, etc&#8230;)<span id="more-1566"></span></p>
<p style="text-align: justify;">Nous allons utiliser une interface graphique très simple, qui se compose d&#8217;un EditText et d&#8217;un bouton pour déclencher le partage. Voici donc le contenu du main.xml :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span>  </span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/edittext&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/share&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Partager&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">On déclare notre EditText et notre Button (pour une meilleur lisibilité dans le code) :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> EditText text<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> share<span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">On les relie avec l&#8217;interface graphique</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">text <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">edittext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
share <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">share</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">On créer un OnClickListener pour lancer l&#8217;action de partage lorsque le Button est appuyer.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">share.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span>
        <span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		@Override
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">final</span> Intent MessIntent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_SEND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        	MessIntent.<span style="color: #006633;">setType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        	MessIntent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_TEXT</span>, text.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        	VotreActivity.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">startActivity</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">createChooser</span><span style="color: #009900;">&#40;</span>MessIntent, <span style="color: #0000ff;">&quot;Partager avec...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">Examinons ce code:</p>
<p style="text-align: justify;">&gt;&gt;&gt; Création de l&#8217;Intent, MessIntent est le nom donner, à vous de choisir le votre =D</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Intent MessIntent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_SEND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">&gt;&gt;&gt; Définition du type d&#8217;Intent. J&#8217;en ai essayer d&#8217;autre mais lui seul permet d&#8217;utiliser toutes les applications disponibles.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">MessIntent.<span style="color: #006633;">setType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">&gt;&gt;&gt; Définition du texte (on récupère le texte de l&#8217;EditText) à publier sur Twitter, Facebook ou autres.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">MessIntent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_TEXT</span>, text.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">&gt;&gt;&gt; Lancement de l&#8217;Intent créer précédemment. MessIntent est l&#8217;Intent créer, et &laquo;&nbsp;Partager avec&#8230;.&nbsp;&raquo; correspond au titre de la boite de dialogue qui s&#8217;ouvrira pour vous proposer l&#8217;application à utiliser pour partager votre texte.<br />
VotreActivity.this est le nom de votre activité en cours, qui est donc à remplacer par la votre).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">VotreActivity.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">startActivity</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">createChooser</span><span style="color: #009900;">&#40;</span>MessIntent, <span style="color: #0000ff;">&quot;Partager avec...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">Vous savez désormais comment envoyer un message sur les réseaux sociaux ou autres. Je vous met deux petites screens pour que vous voyez ce que vous devriez obtenir :</p>
<p style="text-align: center;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/share_twitter_fb_1.png" rel="lightbox[1566]"><img class="alignnone size-full wp-image-1581" title="share_twitter_fb_1" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/share_twitter_fb_1.png" alt="" width="224" height="336" /></a> <a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/share_twitter_fb_2.png" rel="lightbox[1566]"><img class="alignnone size-full wp-image-1582" title="share_twitter_fb_2" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/share_twitter_fb_2.png" alt="" width="224" height="336" /></a></p>
<p style="text-align: justify;">Je partage en &laquo;&nbsp;bonus&nbsp;&raquo; une modification simple du code qui vous permettra d&#8217;ouvrir Gmail avec une adresse et un sujet pré-rempli.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Intent emailIntent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>android.<span style="color: #006633;">content</span>.<span style="color: #006633;">Intent</span>.<span style="color: #006633;">ACTION_SEND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
emailIntent.<span style="color: #006633;">setType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plain/text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
emailIntent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_SUBJECT</span>, <span style="color: #0000ff;">&quot;SujetDuMessage&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
emailIntent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>android.<span style="color: #006633;">content</span>.<span style="color: #006633;">Intent</span>.<span style="color: #006633;">EXTRA_EMAIL</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;VotreEmail@gmail.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
VotreActivity.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">startActivity</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">createChooser</span><span style="color: #009900;">&#40;</span>emailIntent, <span style="color: #0000ff;">&quot;Email Envoyer...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: justify;">Je pense qu&#8217;il n&#8217;est pas nécessaire d&#8217;expliquer ce code qui ressemble beaucoup au précédent néanmoins si vous avez des questions, n&#8217;hésitez pas. En tout cas pré-remplir un mail peut être utile pour avoir des retour sur vos application par les utilisateurs.</p>
<p style="text-align: justify;">Cette article a été rédigé par <strong>TecKnologikS </strong>(merci à lui <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). Pour le remercier, vous pouvez télécharger ses applications et surtout faire vos retours pour qu&#8217;il puisse les améliorer : <a href="https://market.android.com/details?id=fr.tecknologiks.verbesirreguliersanglais" target="_blank">Verbes Irréguliers Anglais</a>, <a href="https://market.android.com/details?id=fr.tecknologiks.sexydes" target="_blank">Des Coquins</a>, <a href="https://market.android.com/details?id=fr.tecknologiks.hasard" target="_blank">Hasard</a>.</p>
<p style="text-align: justify;">Si vous avez besoin d&#8217;un retour sur vos applications n&#8217;hésitez pas à lui envoyer un mail pour lui demander : tecknologiksdev [at] gmail [point] com (remplacer [at] par @ et [point] par .) <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/TuXfht7HAT0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/partager-un-element-sur-twitter-facebook-etc-tutoriel-android-n%c2%b023/05/02/2011/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/partager-un-element-sur-twitter-facebook-etc-tutoriel-android-n%c2%b023/05/02/2011/</feedburner:origLink></item>
		<item>
		<title>Utiliser une ProgressDialog dans ses applications Android [Tutoriel Android n°22]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/7QuKBlw5HAc/</link>
		<comments>http://www.tutomobile.fr/utiliser-une-progressdialog-dans-ses-applications-android-tutoriel-android-n%c2%b022/03/02/2011/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 10:48:57 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[ProgressDialog]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1533</guid>
		<description><![CDATA[Le but de ce post]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Le but de ce post est d&#8217;expliquer un peu comment utiliser une <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a> dans son application. Il peut être parfois utile d&#8217;afficher durant de longues opérations une barre de progression renseignant l&#8217;utilisateur sur l&#8217;avancement. Android fourni un moyen via la <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a>.<span id="more-1533"></span></p>
<p>Cependant, qui dit longue opération dit souvent Thread. Or Android est connu pour bien différencier l&#8217;affichage du traitement (Modèle MVC) et seul le Thread propriétaire des objets graphiques (View) ne peut les modifier. En gros, lorsque votre Activity charge le layout, elle est la seule à pouvoir agir dessus.</p>
<p>C&#8217;est ce que je vais m&#8217;efforcer d&#8217;illustrer avec l&#8217;exemple ci-dessous.</p>
<p style="text-align: justify;">Prenons l&#8217;exemple d&#8217;une application ayant a effectuer 2 opérations assez longues (doLongOperation1 et doLongOperation2). Ces opérations sont consécutives ; doLongOperation2 a besoin que doLongOperation1 soit terminée pour démarrer. Elles sont exécutées dans un second Thread qui sera lui, démarré depuis l&#8217;Activity.</p>
<p>Au moment où le second Thread est démarré, on obtient quelque chose du genre :</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-1534" title="1" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/1.png" alt="" width="581" height="369" /></p>
<p style="text-align: justify;">Soit en gros le code suivant:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> compute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  mProgressDialog <span style="color: #339933;">=</span> ProgressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Please wait&quot;</span>,
          <span style="color: #0000ff;">&quot;Long operation starts...&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          doLongOperation1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          doLongOperation2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Mais durant l&#8217;exécution des opérations, on peut imaginer que l&#8217;on ait besoin d&#8217;informer l&#8217;utilisateur sur le type d&#8217;opération en cours et donc mettre à jour le message de la <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a>. Pour ce faire on pourrait utiliser la méthode setMessage de <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a>.</p>
<p>Donc grosso-modo quelque chose comme ca :</p>
<p style="text-align: justify;">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> compute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  mProgressDialog <span style="color: #339933;">=</span> ProgressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Please wait&quot;</span>,
          <span style="color: #0000ff;">&quot;Long operation starts...&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          mProgressDialog.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing long operation 1...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          doLongOperation1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          mProgressDialog.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing long operation 2...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          doLongOperation2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Mais, on l&#8217;a vu plus tôt, seul le Thread propriétaire des objets graphiques ne peut les modifier. L&#8217;objet mProgressDialog, créé dans le Thread de l&#8217;Activity, ne peut être modifier par un Thread annexe, au risque de lancer une <strong>CalledFromWrongThreadException </strong>avec le message au combien explicite :</p>
<p><strong>Only the original thread that created a view hierarchy can touch its views.</strong></p>
<p>Pour réaliser notre opération, il faut donc que le second Thread soit capable d&#8217;informer le Thread de l&#8217;Activity. C&#8217;est ce que propose la classe <a href="http://developer.android.com/reference/android/os/Handler.html">Handler</a> avec le principe des objets Message qu&#8217;elle véhicule. En gros un <a href="http://developer.android.com/reference/android/os/Handler.html">Handler</a>, possède une queue (une file) de messages qu&#8217;il dépile un à un. Ces messages sont constitués d&#8217;un identifiant (int what) et peuvent contenir des données.<br />
Il suffit de créer un objet de type <a href="http://developer.android.com/reference/android/os/Handler.html">Handler</a>, et de l&#8217;utiliser pour préparer (appel à obtainMessage), envoyer (appel à sendMessage) et recevoir (override de handleMessage) les objet de type Message</p>
<p>Pour notre exemple, on définira 3 types de messages avec les 3 identifiants suivants :</p>
<ol style="text-align: justify;">
<li>MSG_ERR:      une erreur s&#8217;est produite, la <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a> disparait et on informe      l&#8217;utilisateur</li>
<li>MSG_IND:      une indication en cours de traitement à besoin d&#8217;être donnée à      l&#8217;utilisateur (via la <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a>)</li>
<li>MSG_CNF:      le traitement est terminé, on confirme à l&#8217;utilisateur que tout s&#8217;est bien      passé (la <a href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog</a> disparait).</li>
</ol>
<p style="text-align: justify;">Bref, dans le cas nominal, on obtient donc ce qui suit:</p>
<p><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/2.png" rel="lightbox[1533]"><img class="aligncenter size-full wp-image-1538" title="2" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/2.png" alt="" width="661" height="469" /></a></p>
<p style="text-align: justify;">Soit le code suivant:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.jde.tutorial</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.ProgressDialog</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Handler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Message</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.util.Log</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View.OnClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Toast</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProgressBarActivity <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">protected</span> ProgressDialog mProgressDialog<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Context</span> mContext<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> ErrorStatus status<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MSG_ERR <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MSG_CNF <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MSG_IND <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> TAG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ProgressBarActivity&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">enum</span> ErrorStatus <span style="color: #009900;">&#123;</span>
    NO_ERROR, ERROR_1, ERROR_2
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// registers the OnClickListener to our button</span>
    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">btn</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                @Override
                <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    compute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> compute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    mProgressDialog <span style="color: #339933;">=</span> ProgressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Please wait&quot;</span>,
            <span style="color: #0000ff;">&quot;Long operation starts...&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// useful code, variables declarations...</span>
    <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        @Override
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Message msg <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">String</span> progressBarData <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Doing long operation 1...&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// populates the message</span>
            msg <span style="color: #339933;">=</span> mHandler.<span style="color: #006633;">obtainMessage</span><span style="color: #009900;">&#40;</span>MSG_IND, <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span> progressBarData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// sends the message to our handler</span>
            mHandler.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// starts the first long operation</span>
            status <span style="color: #339933;">=</span> doLongOperation1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ErrorStatus.<span style="color: #006633;">NO_ERROR</span> <span style="color: #339933;">!=</span> status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;error while parsing the file status:&quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// error management, creates an error message</span>
                msg <span style="color: #339933;">=</span> mHandler.<span style="color: #006633;">obtainMessage</span><span style="color: #009900;">&#40;</span>MSG_ERR,
                        <span style="color: #0000ff;">&quot;error while parsing the file status:&quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">// sends the message to our handler</span>
                mHandler.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                progressBarData <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Doing long operation 2...&quot;</span><span style="color: #339933;">;</span>
                mProgressDialog.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span>progressBarData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// populates the message</span>
                msg <span style="color: #339933;">=</span> mHandler.<span style="color: #006633;">obtainMessage</span><span style="color: #009900;">&#40;</span>MSG_IND,
                        <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span> progressBarData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// sends the message to our handler</span>
                mHandler.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// starts the second long operation</span>
                status <span style="color: #339933;">=</span> doLongOperation2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ErrorStatus.<span style="color: #006633;">NO_ERROR</span> <span style="color: #339933;">!=</span> status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;error while computing the path status:&quot;</span>
                            <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// error management,creates an error message</span>
                    msg <span style="color: #339933;">=</span> mHandler.<span style="color: #006633;">obtainMessage</span><span style="color: #009900;">&#40;</span>MSG_ERR,
                            <span style="color: #0000ff;">&quot;error while computing the path status:&quot;</span>
                                    <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// sends the message to our handler</span>
                    mHandler.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    msg <span style="color: #339933;">=</span> mHandler.<span style="color: #006633;">obtainMessage</span><span style="color: #009900;">&#40;</span>MSG_CNF,
                            <span style="color: #0000ff;">&quot;Parsing and computing ended successfully !&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// sends the message to our handler</span>
                    mHandler.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/** fake operation for testing purpose */</span>
<span style="color: #000000; font-weight: bold;">protected</span> ErrorStatus doLongOperation2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> ErrorStatus.<span style="color: #006633;">NO_ERROR</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/** fake operation for testing purpose */</span>
<span style="color: #000000; font-weight: bold;">protected</span> ErrorStatus doLongOperation1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> ErrorStatus.<span style="color: #006633;">NO_ERROR</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">final</span> Handler mHandler <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Handler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> handleMessage<span style="color: #009900;">&#40;</span>Message msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> text2display <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #006633;">what</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">case</span> MSG_IND<span style="color: #339933;">:</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mProgressDialog.<span style="color: #006633;">isShowing</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                mProgressDialog.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> msg.<span style="color: #006633;">obj</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> MSG_ERR<span style="color: #339933;">:</span>
            text2display <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> msg.<span style="color: #006633;">obj</span><span style="color: #339933;">;</span>
            Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>mContext, <span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">+</span> text2display,
                    Toast.<span style="color: #006633;">LENGTH_LONG</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mProgressDialog.<span style="color: #006633;">isShowing</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                mProgressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> MSG_CNF<span style="color: #339933;">:</span>
            text2display <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> msg.<span style="color: #006633;">obj</span><span style="color: #339933;">;</span>
            Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>mContext, <span style="color: #0000ff;">&quot;Info: &quot;</span> <span style="color: #339933;">+</span> text2display,
                    Toast.<span style="color: #006633;">LENGTH_LONG</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mProgressDialog.<span style="color: #006633;">isShowing</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                mProgressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// should never happen</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">C&#8217;est à travers la méthode surchargée handleMessage que le message est dépilé. On teste ensuite le type de message (what) et on applique le traitement désiré.<br />
Note: dans la méthode handleMessage, on se trouve à nouveau dans le Thread de l&#8217;Activity, c&#8217;est donc pour ça que l&#8217;opération est possible.</p>
<p style="text-align: justify;">Voila ce que vous devriez avoir :</p>
<p style="text-align: center;"><a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_1.png" rel="lightbox[1533]"><img class="size-full wp-image-1546 alignnone" title="ProgressDialog_1" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_1.png" alt="" width="179" height="269" /></a> <a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_2.png" rel="lightbox[1533]"><img class="size-full wp-image-1547 alignnone" title="ProgressDialog_2" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_2.png" alt="" width="179" height="269" /></a> <a href="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_3.png" rel="lightbox[1533]"><img class="size-full wp-image-1548 alignnone" title="ProgressDialog_3" src="http://www.tutomobile.fr/wp-content/uploads/2011/02/ProgressDialog_3.png" alt="" width="179" height="269" /></a></p>
<p style="text-align: justify;">En espérant que ceci vous aura aidé.</p>
<p style="text-align: justify;">Les sources du projet, c&#8217;est <a href="https://sites.google.com/site/pubjde/pub/ProgressBarSample.zip?attredirects=0&amp;d=1">ici</a></p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/7QuKBlw5HAc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/utiliser-une-progressdialog-dans-ses-applications-android-tutoriel-android-n%c2%b022/03/02/2011/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<enclosure url="https://sites.google.com/site/pubjde/pub/ProgressBarSample.zip?attredirects=0&amp;amp;d=1" length="33567" type="application/zip; charset=UTF-8" /><media:content url="https://sites.google.com/site/pubjde/pub/ProgressBarSample.zip?attredirects=0&amp;amp;d=1" fileSize="33567" type="application/zip; charset=UTF-8" /><itunes:explicit>no</itunes:explicit><itunes:subtitle>Le but de ce post</itunes:subtitle><itunes:author>Axon</itunes:author><itunes:summary>Le but de ce post</itunes:summary><itunes:keywords>Tutoriels Android, ProgressDialog, tutoriel</itunes:keywords><feedburner:origLink>http://www.tutomobile.fr/utiliser-une-progressdialog-dans-ses-applications-android-tutoriel-android-n%c2%b022/03/02/2011/</feedburner:origLink></item>
		<item>
		<title>Envoyer un SMS [Tutoriel Android n°21]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/slbRHLeNrAY/</link>
		<comments>http://www.tutomobile.fr/envoyer-un-sms-tutoriel-android-n%c2%b021/16/12/2010/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 22:41:23 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1452</guid>
		<description><![CDATA[Voici un nouveau tutoriel Android]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Voici un nouveau <a href="http://www.tutomobile.fr/category/tutorial-android/" target="_self">tutoriel Android</a> (depuis bien longtemps les plus exigeants d&#8217;entre vous diront&#8230; <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).  C&#8217;est un lecteur de Tuto Mobile qui me l&#8217;a envoyé, il s&#8217;agit de <strong>dia100daly</strong>, donc merci à lui. Dans ce tutoriel nous allons apprendre à envoyer des SMS. Peut être qu&#8217;un jour vous aurez envie de faire une application qui envoie des SMS qui sais. C&#8217;est toujours bien de savoir  comment faire (en plus cela sera nécessaire pour le prochain tutoriel) <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Enfin trêve de bavardage.<span id="more-1452"></span></p>
<p style="text-align: justify;">Commençons par créer un projet avec la version 1.6 d&#8217;Android pour être conforme à tous les autres tutoriels Android du site. Pour ma part il s&#8217;appelle  <em>EnvoieSms</em> avec une activité qui porte le même nom (vous pouvez l&#8217;appelé comme vous voulez).</p>
<h3 style="text-align: justify;">Code XML</h3>
<p style="text-align: justify;">Avant de vous donner le code XML que nous allons utiliser pour faire l&#8217;interface graphique, je vais vous montrer le rendu que l&#8217;on souhaite à la fin :</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2010/12/EnvoieSMS.png" rel="lightbox[1452]"><img class="aligncenter size-full wp-image-1454" title="EnvoieSMS" src="http://www.tutomobile.fr/wp-content/uploads/2010/12/EnvoieSMS.png" alt="" width="336" height="495" /></a></p>
<p style="text-align: justify;">Donc pour obtenir cette petite interface très simple voici le code XML correspondant :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/numero&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/numero&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/message&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/message&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;200sp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/envoyer&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/envoyer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Pas de panique si vous avez des erreurs c&#8217;est parce que vous n&#8217;avez pas créé les ressources String. Créez les ressources qu&#8217;il faut dans le fichier <em>String.xml</em> comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;numero&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Numero<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Envoie Sms<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Message<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;envoyer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Envoyer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3 style="text-align: justify;">Code JAVA</h3>
<p style="text-align: justify;">Nous allons maintenant mettre en place le mécanisme d&#8217;envoi de SMS. Pour cela nous avons juste besoin d&#8217;utiliser un objet de type <a href="http://developer.android.com/reference/android/telephony/gsm/SmsManager.html" target="_blank">SmsManager</a>.</p>
<p style="text-align: justify;">Sans plus tarder éditons notre activité de départ EnvoieSms et insérer le code Java (commenté) suivant:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sdiawara.envoiesms</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.telephony.gsm.SmsManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View.OnClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Toast</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EnvoieSms <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//On récupère le bouton créer en XML grâce à son id</span>
        <span style="color: #003399;">Button</span> btnEnvoie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">envoyer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//On récupère les deux EditText correspondant aux champs pour entrer le numéro et le message</span>
        <span style="color: #000000; font-weight: bold;">final</span> EditText numero <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">numero</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">final</span> EditText message <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//On affecte un écouteur d'évènement au bouton</span>
        btnEnvoie.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;deprecation&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">//On récupère ce qui a été entré dans les EditText</span>
				<span style="color: #003399;">String</span> num <span style="color: #339933;">=</span> numero.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">String</span> msg <span style="color: #339933;">=</span> message.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//Si le numéro est supérieur à 4 charactère et que le message n'est pas vide on lance la procédure d'envoi</span>
				<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>num.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">&amp;&amp;</span> msg.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//Grâce à l'objet de gestion de SMS (SmsManager) que l'on récupère grâce à la méthode static getDefault()</span>
					<span style="color: #666666; font-style: italic;">//On envoit le SMS à l'aide de la méthode sendTextMessage</span>
					SmsManager.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">sendTextMessage</span><span style="color: #009900;">&#40;</span>num, <span style="color: #000066; font-weight: bold;">null</span>, msg, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">//On efface les deux EditText</span>
					numero.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					message.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//On affiche un petit message d'erreur dans un Toast</span>
					Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>EnvoieSms.<span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Enter le numero et/ou le message&quot;</span>, Toast.<span style="color: #006633;">LENGTH_SHORT</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3 style="text-align: justify;">AndroidManifest.xml</h3>
<p style="text-align: justify;">Voilà nous avons presque fini il nous reste juste à demander la permission d&#8217;envoyer des messages. Pour cela ouvrez le fichier <em>AndroidManifest.xml</em> et ajoutez cette ligne :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.SEND_SMS&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/uses-permission<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">Vous pouvez maintenant tester. Pour bien voir que ça marche nous allons utiliser deux émulateurs. Je suppose que vous en disposer déjà d&#8217;un , nous allons donc en créer un deuxième. Cliquez sur le menu <strong><em>Windows</em></strong> &gt;&gt;&gt; <em><strong>Android SDK and AVD Manager</strong></em>. Ensuite cliquez sur <strong><em>New </em></strong>pour créer un nouvel émulateur, donnez lui le nom que vous voulez, cliquez sur <strong><em>Create AVD</em></strong> et sélectionnez ce nouvel émulateur puis cliquez sur <strong><em>Start</em></strong>. Il ne reste plus qu&#8217;a lancer votre projet avec l&#8217;un des émulateurs et à rentrer le numéro qui apparaît sur l&#8217;autre émulateur comme numéro du destinataire. Voilà tout devrait marcher normalement !</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2010/12/envoie_sms_1.png" rel="lightbox[1452]"><img class="aligncenter size-full wp-image-1462" title="envoie_sms_1" src="http://www.tutomobile.fr/wp-content/uploads/2010/12/envoie_sms_1.png" alt="" width="560" height="423" /></a></p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2010/12/envoie_sms_2.png" rel="lightbox[1452]"><img class="aligncenter size-full wp-image-1463" title="envoie_sms_2" src="http://www.tutomobile.fr/wp-content/uploads/2010/12/envoie_sms_2.png" alt="" width="560" height="421" /></a></p>
<p style="text-align: justify;">A bientôt pour un prochain tutoriel. <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p style="text-align: justify;">
<p style="text-align: justify;">
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/slbRHLeNrAY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/envoyer-un-sms-tutoriel-android-n%c2%b021/16/12/2010/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/envoyer-un-sms-tutoriel-android-n%c2%b021/16/12/2010/</feedburner:origLink></item>
		<item>
		<title>Personnaliser un AlertDialog [Tutoriel Android n°20]</title>
		<link>http://feedproxy.google.com/~r/TutoMobileTutorielsAndroid/~3/cHCW51-JV1I/</link>
		<comments>http://www.tutomobile.fr/personnaliser-un-alertdialog-tutoriel-android-n%c2%b020/04/11/2010/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 15:44:08 +0000</pubDate>
		<dc:creator>Axon</dc:creator>
				<category><![CDATA[Tutoriels Android]]></category>
		<category><![CDATA[AlertDialog]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.tutomobile.fr/?p=1249</guid>
		<description><![CDATA[Voici un tuto qui va]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Voici un tuto qui va surement en aider plus d&#8217;un. Parfois lorsque vous développez vos applications <a href="http://www.tutomobile.fr/category/tutorial-android/" target="_self">Android</a> je suis sûr que vous aimeriez créer une boite de dialogue (<strong><em>AlertDialog</em></strong>) un peu personnalisé en y ajoutant par exemple un <strong><em>EditText</em></strong> ou n&#8217;importe quoi d&#8217;autre. Pas facile de trouver un tuto clair sur ce sujet sur le net. Je vais donc tenter de vous expliquer comment personnaliser un <strong><em>AlertDialog</em></strong> facilement.<span id="more-1249"></span></p>
<p style="text-align: justify;">Créez votre projet Android (moi je suis encore et toujours sous Android 1.6) et attaquons notre tutorial. Nous allons faire un <strong><em>AlertDialog</em></strong> personnalisé avec un <strong><em>TextView</em></strong> et un <strong><em>EditText</em></strong>. Il n&#8217;y a rien de transcendant la dedans mais si vous comprenez cet exemple vous saurez faire tout ce que vous voudrez. Voici donc à quoi ressemblera notre <strong><em>AlertDialog</em></strong> :</p>
<p style="text-align: center;"><a href="http://www.tutomobile.fr/wp-content/uploads/2010/11/AlertDialog_personnaliser.png" rel="lightbox[1249]"><img class="aligncenter size-full wp-image-1260" title="AlertDialog_personnaliser" src="http://www.tutomobile.fr/wp-content/uploads/2010/11/AlertDialog_personnaliser.png" alt="" width="480" height="320" /></a></p>
<h3>Code XML</h3>
<p style="text-align: justify;">Pour commencer, créez un nouveau layout que vous allez appeler <em>alertdialogperso.xml</em>. C&#8217;est dans ce fichier que nous allons mettre tout ce qu&#8217;on souhaite voir dans notre AlertDialog personnalisé. Nous nous y mettons un TextView et un EditText l&#8217;un en dessous de l&#8217;autre. On obtient donc le code suivant :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RelativeLayout</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">android:padding</span>=<span style="color: #ff0000;">&quot;15dip&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/TextView1&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Entrer quelque chose ci-dessous :&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:paddingBottom</span>=<span style="color: #ff0000;">&quot;10dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/EditText1&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_below</span>=<span style="color: #ff0000;">&quot;@id/TextView1&quot;</span>  <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RelativeLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: justify;">
<h3>Code Java</h3>
<p>Maintenant il suffit d&#8217;affecter ce layout à un <em>AlertDialog </em>grâce au code Java. Pour cela, nous allons utiliser la classe <a href="http://developer.android.com/reference/android/view/LayoutInflater.html" target="_blank">LayoutInflater</a> qui va nous permettre de faire de notre layout un objet View qui sera alors affecté à l&#8217;<em>AlertDialog</em> grâce à la méthode <em>setView()</em>. Voici le code commenté :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tutomobile.android.alertdialogperso</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.AlertDialog</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.DialogInterface</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.LayoutInflater</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Toast</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tutoriel18_Android <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On instancie notre layout en tant que View</span>
        LayoutInflater factory <span style="color: #339933;">=</span> LayoutInflater.<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">View</span> alertDialogView <span style="color: #339933;">=</span> factory.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">alertdialogperso</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Création de l'AlertDialog</span>
        AlertDialog.<span style="color: #006633;">Builder</span> adb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AlertDialog.<span style="color: #006633;">Builder</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On affecte la vue personnalisé que l'on a crée à notre AlertDialog</span>
        adb.<span style="color: #006633;">setView</span><span style="color: #009900;">&#40;</span>alertDialogView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On donne un titre à l'AlertDialog</span>
        adb.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Titre de notre boite de dialogue&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On modifie l'icône de l'AlertDialog pour le fun ;)</span>
        adb.<span style="color: #006633;">setIcon</span><span style="color: #009900;">&#40;</span>android.<span style="color: #006633;">R</span>.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_dialog_alert</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On affecte un bouton &quot;OK&quot; à notre AlertDialog et on lui affecte un évènement</span>
        adb.<span style="color: #006633;">setPositiveButton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OK&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> DialogInterface.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>DialogInterface dialog, <span style="color: #000066; font-weight: bold;">int</span> which<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            	<span style="color: #666666; font-style: italic;">//Lorsque l'on cliquera sur le bouton &quot;OK&quot;, on récupère l'EditText correspondant à notre vue personnalisée (cad à alertDialogView)</span>
            	EditText et <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>alertDialogView.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">EditText1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            	<span style="color: #666666; font-style: italic;">//On affiche dans un Toast le texte contenu dans l'EditText de notre AlertDialog</span>
            	Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>Tutoriel18_Android.<span style="color: #000000; font-weight: bold;">this</span>, et.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, Toast.<span style="color: #006633;">LENGTH_SHORT</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//On crée un bouton &quot;Annuler&quot; à notre AlertDialog et on lui affecte un évènement</span>
        adb.<span style="color: #006633;">setNegativeButton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Annuler&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> DialogInterface.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>DialogInterface dialog, <span style="color: #000066; font-weight: bold;">int</span> which<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            	<span style="color: #666666; font-style: italic;">//Lorsque l'on cliquera sur annuler on quittera l'application</span>
            	finish<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        adb.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Maintenant si vous lancez votre application vous devriez voir apparaître une boîte de dialogue similaire à celle présenté au début du tutoriel. Entrez quelque chose dans l&#8217;EditText puis cliquez sur &laquo;&nbsp;OK&nbsp;&raquo;. La boite de dialogue devrait se fermer et le texte que vous avez entré devrait apparaître dans un Toast, comme sur la capture d&#8217;écran ci-dessous. Si vous cliquez sur &laquo;&nbsp;Annuler&nbsp;&raquo;, l&#8217;application doit se fermer normalement.</p>
<p style="text-align: justify;"><a href="http://www.tutomobile.fr/wp-content/uploads/2010/11/AlertDialog_personnaliser2.png" rel="lightbox[1249]"><img class="aligncenter size-full wp-image-1262" title="AlertDialog_personnaliser2" src="http://www.tutomobile.fr/wp-content/uploads/2010/11/AlertDialog_personnaliser2.png" alt="" width="480" height="320" /></a></p>
<p style="text-align: justify;">Vous êtes désormais capable de personnaliser comme vous le souhaitez un AlertDialog. Vous pouvez donc créez toutes les boîtes de dialogue que vous voulez. J&#8217;espère que ce petit tutoriel vous aura plus et surtout qu&#8217;il vous servira. Merci d&#8217;avance à tout ceux qui partegeront ce tuto sur <a href="http://twitter.com/TutoMobile" target="_blank">Twitter</a> et <a href="http://www.facebook.com/pages/Tuto-Mobile/132774283400523" target="_blank">Facebook</a>. Et n&#8217;oubliez pas de voter pour cet article si vous l&#8217;avez aimé, grâce au petit &laquo;&nbsp;+&nbsp;&raquo; en haut à gauche du tuto (à côté du coeur). <img src='http://www.tutomobile.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TutoMobileTutorielsAndroid/~4/cHCW51-JV1I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.tutomobile.fr/personnaliser-un-alertdialog-tutoriel-android-n%c2%b020/04/11/2010/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.tutomobile.fr/personnaliser-un-alertdialog-tutoriel-android-n%c2%b020/04/11/2010/</feedburner:origLink></item>
	<copyright>Tuto Mobile</copyright><media:credit role="author">Axon</media:credit><media:rating>nonadult</media:rating></channel>
</rss>

