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

<channel>
	<title>Point GPhone &#187; Tutoriaux Android</title>
	<atom:link href="http://www.pointgphone.com/tutoriaux-android/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pointgphone.com</link>
	<description>Android, site francophone de référence</description>
	<lastBuildDate>Thu, 18 Mar 2010 20:29:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tutoriel Android : Introduction aux Intents</title>
		<link>http://www.pointgphone.com/tutoriel-android-introduction-intents-7779</link>
		<comments>http://www.pointgphone.com/tutoriel-android-introduction-intents-7779#comments</comments>
		<pubDate>Sun, 20 Sep 2009 20:57:39 +0000</pubDate>
		<dc:creator>Cyril Mottier</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Cyril Mottier]]></category>
		<category><![CDATA[Google Search]]></category>
		<category><![CDATA[intent]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=7779</guid>
		<description><![CDATA[Après un petit moment d&#8217;inactivité, Cyril Mottier revient et continue sa série de tutoriaux sur le développement sous Android. Pour faire suite à un &#8220;Hello World&#8221; un peu atypique, il aborde un système important et même essentiel à Android : les Intents.

Android offre un système de communication trés ingénieux permettant de faire passer l&#8217;information entre [...]]]></description>
			<content:encoded><![CDATA[<p>Après un petit moment d&#8217;inactivité, Cyril Mottier revient et continue sa série de tutoriaux sur le développement sous Android. Pour faire suite à un <a href="http://www.pointgphone.com/tutoriel-android-hello-world-2301">&#8220;Hello World&#8221; un peu atypique</a>, il aborde un système important et même essentiel à Android : les <code>Intent</code>s.</p>
<p><span id="more-7779"></span></p>
<p>Android offre un système de communication trés ingénieux permettant de faire passer l&#8217;information entre <code>Activity</code>s ou plus généralement composants applicatifs . Ce système, déjà mentionné dans une partie précédente, est connu sous le nom d&#8217;<code>Intent</code>. Nous verrons donc dans cette partie comment transmettre l&#8217;information d&#8217;une <code>Activity</code> à une autre à l&#8217;aide de ce mécanisme d&#8217;<code>Intent</code>s. Les lecteurs n&#8217;ayant toujours pas compris la différence subtile entre <code>Activity</code> et <code>View</code> seront probablement éclairé par la lecture des lignes suivantes.</p>
<h2>Introduction</h2>
<p>Android <em>sandbox</em> les applications. Le mot &#8220;sandbox&#8221; est un anglicisme qui signifie simplement &#8220;bac à sable&#8221;. Il vous paraît très probablement étrange de parler de &#8220;bac à sable&#8221; dans un problème d&#8217;informatique mais c&#8217;est pourtant bel et bien la traduction adéquate dans le contexte. Le <em>sandboxing</em> est une pratique de plus en plus courante dans la téléphonie mobile qui consiste à séparer presque totalement les applications entre elles. Lorsque Android exécute une application, il restreint cette dernière à des actions bien définies (accès mémoire, accès sur les capteurs, etc&#8230;). Cette pratique permet de protéger le système au maximum en évitant de laisser des applications faire comme bon leurs semble.</p>
<p>Malgré l&#8217;énorme apport sur la sécurité, le <em>sandoxing</em> restreint fortement la communication entre applications. C&#8217;est dans l&#8217;optique de contourner ce &#8220;problème&#8221;, que les <code>Intent</code>s ont été conçus. Pour faire simple, un <code>Intent</code> est un ensemble de données qui peut être passé à un autre composant applicatif (de la même application ou non) de façon implicite (requête pour une action &#8211; lire de la musique ou scanner un code barre par exemple) ou explicite (lancement d&#8217;une classe précise).</p>
<p><em>Le développement sur iPhone suit également cette règle de &#8220;sandboxing&#8221;. Malheureusement le système de communication entre application appelé &#8220;URL scheme&#8221; est beaucoup moins évolutif et permissif. Ce dernier consiste simplement à enregistrer l&#8217;application auprès du système qui laissera alors les applications démarrer l&#8217;application pour une URI (sous Safari par exemple). Cela montre très clairement l&#8217;avantage d&#8217;Android sur l&#8217;iPhone en matière de communication entre composants applicatifs. De plus, ce qui est faisable avec l&#8217;iPhone l&#8217;est très souvent sous Android &#8211; et inversement.</em></p>
<h2>Démarrage d&#8217;une <code>Activity</code> grâce aux <code>Intents</code></h2>
<p>Pour bien décrire le système des <code>Intent</code>s, nous allons créer une petite application (sans aucun but réel, je l&#8217;accorde) composée de 2 écrans : le premier dispose d&#8217;un bouton permettant de démarrer une nouvelle <code>Activity</code> de façon explicite. La seconde <code>Activity</code> affichera simplement un champ de recherche permettant d&#8217;effectuer une recherche sur Google. Le code de cette application est disponible dans ce <a href="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/09/part4.zip">dossier zippé</a>.</p>
<h3>Démarrage d&#8217;une activité de façon explicite</h3>
<p>Pour commencer, créons une première <code>Activity</code> qui affichera un unique bouton central. Le code XML ci-dessous est composé d&#8217;une unique balise <code>Button</code>. Cette simplicité de l&#8217;interface graphique provient du fait que l&#8217;espace disponible au développeur pour afficher son application (l&#8217;intégralité de l&#8217;écran moins la barre de tâches et la barre de nom) est disponible sous la forme d&#8217;un <code>FrameLayout</code>. L&#8217;image ci-dessous montre la hiérarchie des vues générées avec ce fichier XML. On aperçoit facilement (en bleu) un <code>FrameLayout</code>.</p>
<p><img class="alignnone size-full" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/09/hierarchy.png" /></p>
<p>Les paramètres <code>android:layout_gravity="center"</code> et <code>android:text="Cliquez ici pour démarrer"</code> permettent respectivement de centrer le bouton dans sa vue parente et de définir le texte du bouton.</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;Button</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:id</span>=<span style="color: #ff0000;">&quot;@+id/button&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:layout_gravity</span>=<span style="color: #ff0000;">&quot;center&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Cliquez ici pour démarrer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Notre interface graphique étant prête, il suffit maintenant de créer notre première <code>Activity</code>. Pour faciliter la compréhension, j&#8217;ai préféré directement commenter le code. N&#8217;oubliez pas d&#8217;inclure cette nouvelle <code>Activity</code> dans le fichier Manifest.xml pour qu&#8217;Android autorise son exécution.</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.cyrilmottier.android.tutorial4</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.content.Intent</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.View</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>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * La classe EntryPoint implémente l'interface View.OnClickListener. Cela permet ainsi
 * d'enregistrer l'activité auprès des vues pour qu'elle puiise recevoir les évènements de &quot;clic&quot;.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EntryPoint <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * Cette variable permettra de conserver une référence sur le bouton
	 * de l'interface
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> mButton<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * La redéfinition de la méthode onCreate(Bundle) permet d'effectuer des actions
	 * supplémentaires à l'Activity de base.
	 */</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>
        <span style="color: #666666; font-style: italic;">/*
         * On créé l'interface graphique en utilisant le fichier entry.xml.
         * Ce dernier étant disponible comme ressource (dans /res/layout), il suffit d'utiliser
         * le fichier R.java et sa sous-classe layout.
         */</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">entry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*
         * Récupère une référence sur le bouton en utilisant son identifiant
         */</span>
        mButton <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;">button</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*
         * On enregistre l'activité auprès du bouton pour recevoir les évènements
         * &quot;clic&quot; provoqué par l'utilisateur.
         */</span>
        mButton.<span style="color: #006633;">setOnClickListener</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: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/*
     * La méthode onClick(View) provient de l'interface View.OnClickListener.
     */</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;">if</span> <span style="color: #009900;">&#40;</span>v <span style="color: #339933;">==</span> mButton<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">/*
			 * Nous sommes maintenant sûr que la vue ayant été cliquée est le bouton
			 * de notre interface. Il suffit donc de créer un nouvel Intent pour démarrer
			 * la seconde activité.
			 */</span>
			Intent intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>EntryPoint.<span style="color: #000000; font-weight: bold;">this</span>, GoogleSearch.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			startActivity<span style="color: #009900;">&#40;</span>intent<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></pre></div></div>

<p>Notre première <code>Activity</code> est maintenant terminée. Le lancement d&#8217;une nouvelle <code>Activity</code> de façon explicite s&#8217;effectue en deux lignes. La première, <code>Intent intent = new Intent(EntryPoint.this, GoogleSearch.class);</code> crée simplement un nouvel <code>Intent</code> dont le contexte de départ est l&#8217;<code>Activity</code> courante (<code>EntryPoint.this</code>) et l&#8217;<code>Activity</code> de destination se nomme <code>GoogleSearch</code>.</p>
<h3>Démarrage d&#8217;une activité de façon implicite</h3>
<p>Il ne nous reste maintenant plus qu&#8217;à définir l&#8217;<code>Activity</code> <code>GoogleSearch</code> en utilisant des principes similaires à ceux précédemment décrits. Commençons, tout d&#8217;abord par créer l&#8217;interface graphique :</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>
<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: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;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:padding</span>=<span style="color: #ff0000;">&quot;10px&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:text</span>=<span style="color: #ff0000;">&quot;Entrez la recherche à effectuer dans le champ ci-dessous puis cliquez sur le bouton&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:layout_marginBottom</span>=<span style="color: #ff0000;">&quot;10px&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:gravity</span>=<span style="color: #ff0000;">&quot;center_horizontal&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/editText&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_marginBottom</span>=<span style="color: #ff0000;">&quot;5px&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 style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ImageButton</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/imageButton&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:src</span>=<span style="color: #ff0000;">&quot;@drawable/logo_google&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_gravity</span>=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/ImageButton<span style="color: #000000; font-weight: bold;">&gt;</span></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>

<p>Il ne me semble pas très important de décrire le fichier XML précédent car il peut être considéré comme classique. Il est à noter, tout de même, une légère différence avec les fichiers XML de notre <a href="http://www.pointgphone.com/tutoriel-android-hello-world-2301">HelloWorld</a> : les ressources de type chaines de caractères, dimensions, etc. ne sont pas externalisés dans un fichier externe. Dans notre cas cela n&#8217;a pas réellement d&#8217;impact puisque nous n&#8217;allons pas internationaliser l&#8217;application.</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.cyrilmottier.android.tutorial4</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.content.Intent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.net.Uri</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.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.ImageButton</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> GoogleSearch <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ImageButton mImageButton<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> EditText mEditText<span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</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;">google</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		mImageButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ImageButton<span style="color: #009900;">&#41;</span>findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">imageButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		mEditText <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>
		mImageButton.<span style="color: #006633;">setOnClickListener</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: #009900;">&#125;</span>
&nbsp;
	@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> view<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>view <span style="color: #339933;">==</span> mImageButton<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> requete <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.google.fr/search?q=&quot;</span> <span style="color: #339933;">+</span> mEditText.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			Intent intent <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_VIEW</span>, Uri.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>requete<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			startActivity<span style="color: #009900;">&#40;</span>intent<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></pre></div></div>

<p><img class="alignnone size-full" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/09/screen.png" /></p>
<p>Un clic sur le bouton &#8220;Google&#8221; créé un nouvel <code>Intent</code> à l&#8217;aide du constructeur <code>Intent(String,Uri)</code>. La chaine de caractère passée en paramètre est une action à effectuer (ici ACTION_VIEW : action définie par le framework qui consiste à démarrer un navigateur web sur l&#8217;<code>Uri</code> donnée). On démarre enfin l&#8217;activité par un simple <code>startActivity(Intent)</code>. Une action ne définissant pas une application en particulier, Android va tenter de chercher une application s&#8217;étant définie comme capable de répondre à l&#8217;action <code>ACTION_VIEW</code>. C&#8217;est cette &#8220;non certitude&#8221; sur l&#8217;application à ouvrir qui explique le nom de cette méthode : implicite. Généralement le navigateur utilisé est celui inclus de base dans le téléphone.</p>
<h2>Conclusion</h2>
<p>Les <code>Intent</code>s sont des composants essentiels de l&#8217;architecture Android. Le démarrage explicite ou implicite d&#8217;une <code>Activity</code> à l&#8217;aide d&#8217;<code>Intent</code>s n&#8217;est qu&#8217;une petite infime partie des possibilités de ce mécanisme. Cette partie fait donc office d&#8217;introduction aux <code>Intent</code>s et vous permet de mieux comprendre la communication entre composants applicatifs Android. Vous êtes maintenant prêts à coder vos premiers programmes à écrans multiples !<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/tutoriel-composants-android-2238" title="Tutoriel : Les composants principaux d&#039;Android">Tutoriel : Les composants principaux d&#039;Android</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-skin-emulateur-android-428" title="Tutoriel : Changer la skin de l&#039;émulateur Android">Tutoriel : Changer la skin de l&#039;émulateur Android</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-installation-sdk-android-51" title="Tutoriel : Installation du SDK Android">Tutoriel : Installation du SDK Android</a></li>
<li><a href="http://www.pointgphone.com/android-sdk-21-disponible-10426" title="Android SDK 2.1 disponible !">Android SDK 2.1 disponible !</a></li>
<li><a href="http://www.pointgphone.com/nouvelle-mise-a-jour-sdk-android-9585" title="Nouvelle mise à jour pour le SDK Android">Nouvelle mise à jour pour le SDK Android</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/tutoriel-android-introduction-intents-7779">Tutoriel Android : Introduction aux Intents</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/tutoriel-android-introduction-intents-7779/feed</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Devenez développeur Android : Formation vidéo</title>
		<link>http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172</link>
		<comments>http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:08:07 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[formation]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=7172</guid>
		<description><![CDATA[Android est une fantastique opportunité pour les développeurs qui souhaitent apprendre à développer et réaliser des applications qui peuvent potentiellement toucher des millions d&#8217;utilisateurs. Vous voulez vous lancer? Cette formation vidéo est faites pour vous !

Formation vidéo : Devenez un développeur Android
L&#8217;ami Nix et son compère Manu, qui ont déjà un certain nombre d&#8217;applications Android [...]]]></description>
			<content:encoded><![CDATA[<p>Android est une fantastique opportunité pour les développeurs qui souhaitent apprendre à développer et réaliser des applications qui peuvent potentiellement toucher des millions d&#8217;utilisateurs. Vous voulez vous lancer? Cette formation vidéo est faites pour vous !</p>
<p><span id="more-7172"></span></p>
<p style="text-align: center;"><a title="Formation vidéo Android" href="http://www.pointgphone.com/devenez-developpeur-android" target="_self">Formation vidéo : Devenez un développeur Android</a></p>
<p>L&#8217;ami Nix et son compère Manu, qui ont déjà un certain nombre d&#8217;applications Android à succès à leur actif (on leur doit aussi le site <a title="AndroLib : Toutes les applications Android, dans toutes les langues !" href="http://www.pointgphone.com/androlib-applications-android-5279" target="_self">AndroLib</a>), nous ont concocté une superbe <a href="http://www.pointgphone.com/devenez-developpeur-android" target="_self">formation vidéo</a> pour vous apprendre les bases de la programmation Android.</p>
<p><img class="alignnone size-full wp-image-7203" title="devenez-developpeur-android" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/08/devenez-developpeur-android.jpg" alt="devenez-developpeur-android" width="145" height="284" /></p>
<p>Cette formation est destinée aux développeurs qui veulent se mettre à Android rapidement, mais aussi à ceux qui aimeraient utiliser Android pour se forger une première expérience dans la programmation (mais attention, il ne s&#8217;agit pas d&#8217;un cours de programmation).</p>
<p>Voici la table des matières, où chaque partie correspond à une vidéo, pour un total de plus de 8 heures de formation !</p>
<p><strong>Prise en main</strong></p>
<ul>
<li>Présentation d&#8217;Android</li>
<li>Téléchargement d&#8217;Eclipse et du SDK Android</li>
<li>Installation d&#8217;Eclipse et présentation de l&#8217;IDE</li>
<li>Création et utilisation de l&#8217;émulateur</li>
<li>Changer l&#8217;apparence de l&#8217;émulateur</li>
<li>Première application Android</li>
<li>Perspective et DDMS</li>
<li>Le LogCat</li>
<li>Le Débuggeur</li>
<li>Installation du pilote USB</li>
<li>Faire une capture d&#8217;écran</li>
<li>Importer un projet</li>
<li>Android Debug Bridge (ADB)</li>
<li>Communiquer avec l&#8217;émulateur</li>
<li>Aide Dynamique</li>
<li>Paramétrer le téléphone</li>
</ul>
<p><strong>Vue d&#8217;ensemble</strong></p>
<ul>
<li>Introduction aux activités</li>
<li>Introduction aux sous-activités</li>
<li>Introduction aux menus</li>
<li>Introduction aux menus contextuels</li>
<li>Les notifications</li>
<li>Ouvrir des activités du système</li>
<li>Les BroadcastReceiver et Alarmes</li>
</ul>
<p><strong>Création d&#8217;une application avec UI</strong></p>
<ul>
<li>Les Layouts</li>
<li>Les vues</li>
<li>Boîte de dialogue</li>
<li>Les toasts</li>
<li>Le manifest.xml</li>
<li>Animations de contrôle</li>
<li>Internationalisation</li>
<li>List view</li>
</ul>
<p><strong>Réseau et Internet</strong></p>
<ul>
<li>Télécharger une page web (getHttp)</li>
<li>Socket</li>
<li>Les SMS</li>
<li>Envoyer un email et/ou SMS</li>
<li>Géolocalisation avec Google Map API</li>
<li>Simuler une panne réseau</li>
</ul>
<p><strong>Accès aux données</strong></p>
<ul>
<li>Les Adapters</li>
<li>Ressources</li>
<li>Les fichiers</li>
<li>Base de données SQLite</li>
<li>Gestion des préférences</li>
<li>Accéder à la liste de contacts</li>
</ul>
<p><strong>Multimédia</strong></p>
<ul>
<li>Sound</li>
<li>Dessin et SurfaceView</li>
<li>Télécharger une image depuis le web</li>
<li>Lire une vidéo</li>
<li>Reconnaissance vocale</li>
<li>OpenGL</li>
</ul>
<p><strong>Utiliser le hardware</strong></p>
<ul>
<li>TouchScreen</li>
<li>Camera</li>
<li>Utiliser les capteurs</li>
<li>Vibration</li>
<li>Le micro et Playback</li>
<li>Le Wifi</li>
</ul>
<p><strong>Aller plus loin dans le développement</strong></p>
<ul>
<li>Thread</li>
<li>Les services</li>
<li>Créer une AppWidget</li>
<li>Récupérer les informations du téléphone</li>
<li>Récupérer et changer le fond d&#8217;écran</li>
<li>Lancer des commandes du Shell Linux</li>
<li>Activer et désactiver le GPS</li>
</ul>
<p><strong>Trucs et astuces</strong></p>
<ul>
<li>Présentation et utilisation du Code QR</li>
<li>Forcer une application à se fermer</li>
<li>Astuces pour l&#8217;émulateur</li>
<li>Le Garbage Collector System.gc</li>
<li>Lister et lancer les applications installées</li>
<li>Décompiler et re-signer un fichier APK</li>
<li>Montrer les exemples du SDK</li>
</ul>
<p><strong>Publier une application dans le Market</strong></p>
<ul>
<li>Présentation du Market</li>
<li>Publier une application dans le Market</li>
<li>Mettre à jour une application dans le Market</li>
<li>AndroLib</li>
</ul>
<p>Android est la plateforme mobile du futur, et cette <a title="Formation vidéo Android" href="http://www.pointgphone.com/devenez-developpeur-android" target="_self">formation</a> est le moyen idéal pour vous y mettre pour <strong>seulement 39.95 euros</strong> ! Et croyez-moi, la qualité est au rendez-vous !</p>
<p>On vous donne rendez-vous pour l&#8217;Android Developer Challenge 3? <img src='http://www.pointgphone.com/wordpress/wp-includes/images/smilies/icon_wink.png' alt=';)' class='wp-smiley' /> </p>
<p><a title="Formation vidéo Android" href="http://www.pointgphone.com/devenez-developpeur-android" target="_self">Formation vidéo : Devenez un développeur Android</a></p>
<p>Edit : Il est possible de télécharger les vidéos ainsi que les fichiers sources des tutoriaux qui sont traités.<br />
<h3>Articles au hasard :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/htc-bigfoot-2578" title="HTC Bigfoot, successeur du HTC G1?">HTC Bigfoot, successeur du HTC G1?</a></li>
<li><a href="http://www.pointgphone.com/motorola-droid-booste-android-market-10156" title="Le Motorola Droid booste les téléchargements sur l&#8217;Android Market">Le Motorola Droid booste les téléchargements sur l&#8217;Android Market</a></li>
<li><a href="http://www.pointgphone.com/acer-a1-android-precommande-8033" title="Acer A1 avec Android disponible&#8230; en précommande">Acer A1 avec Android disponible&#8230; en précommande</a></li>
<li><a href="http://www.pointgphone.com/motorola-zeppelin-8678" title="Le Motorola Zeppelin nous tourne le dos">Le Motorola Zeppelin nous tourne le dos</a></li>
<li><a href="http://www.pointgphone.com/samsung-maj-terminaux-android-10853" title="Samsung va mettre à jour ses terminaux Android">Samsung va mettre à jour ses terminaux Android</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">Devenez développeur Android : Formation vidéo</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172/feed</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>Map application pour Android SDK 1.5, deuxième partie</title>
		<link>http://www.pointgphone.com/map-application-android-sdk-15-deuxieme-partie-4916</link>
		<comments>http://www.pointgphone.com/map-application-android-sdk-15-deuxieme-partie-4916#comments</comments>
		<pubDate>Sun, 31 May 2009 22:22:39 +0000</pubDate>
		<dc:creator>Andre</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Google Search]]></category>
		<category><![CDATA[Yahoo Search API]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=4916</guid>
		<description><![CDATA[André vous proposait récemment de découvrir les fonctionnalités maps offertes par la version 1.5 du SDK Android, voici la suite de ce tutoriel. La troisième partie est déjà en route !

Mon premier tutoriel présentait les bases d&#8217;une application Android et Google Maps élémentaire.
Ce deuxième tutoriel va présenter les notions de map overlay, de géolocalisation et [...]]]></description>
			<content:encoded><![CDATA[<p>André vous proposait récemment de découvrir les <a title="Map application pour Android SDK 1.5, première partie" href="http://www.pointgphone.com/map-application-android-sdk-15-2597" target="_self">fonctionnalités maps offertes par la version 1.5 du SDK Android</a>, voici la suite de ce tutoriel. La troisième partie est déjà en route !</p>
<p><span id="more-4916"></span></p>
<p>Mon premier tutoriel présentait les bases d&#8217;une application Android et Google Maps élémentaire.</p>
<p>Ce deuxième tutoriel va présenter les notions de map overlay, de géolocalisation et de client http. Pour cela nous présenterons une solution de recherche de services basées sur Yahoo Search API et par la même occasion cela donnera un exemple d&#8217;utilisation de REST API avec Android.</p>
<p>NB : Yahoo Search ne fonctionne qu&#8217;aux US pour l&#8217;instant, placez donc votre emulateur au dessus des US avec un geo fix approprié.</p>
<p>La license de Yahoo Search ne permet pas son utilisation a des fins commerciales.</p>
<p>Dans un prochain tutoriel nous utiliserons Google Search et n&#8217;aurons pas ces limitations.</p>
<p>Pour la réalisation du client REST (Representational State Transfer) nous utiliserons la librairie <em>HttpClient</em>. Dans <a title="GLocation" href="http://www.pointgphone.com/tutoriel-android-glocation-703" target="_self">GLocation</a> j&#8217;utilisais <em>android.net.http.RequestQueu</em>e mais cette API, bien que toujours utilisée en interne par Android, n&#8217;est plus publique. Pour la recherche de services j&#8217;utilisais une solution un peu complexe faisant appel a Google Search, mais les restrictions de droits d&#8217;usage en interdisent plus ou moins l&#8217;usage aujourd&#8217;hui..</p>
<h3><span style="font-weight: normal;">Maps Overlay avec Android SDK 1.5</span></h3>
<p>Apres avoir essayé le nouvel Overlay proposé dans la librairie MyLocationOverlay je l&#8217;ai abandonné faute de pouvoir gérer la fréquence de rafraîchissement et donc de pouvoir limiter l&#8217;usage du GPS. J&#8217;ai ensuite essayé de faire un custom Overlay pour enfin choisir l&#8217;ItemizedOverlay qui correspond bien pour gérer les résultats de la recherche.</p>
<h3><span style="font-weight: normal;">Description de l&#8217;Itemized Overlay</span></h3>
<p>L&#8217;ItemizedOverlay est un Overlay qui permet d&#8217;ajouter des OverlayItems et ensuite de les sélectionner.</p>
<p>Nous allons d&#8217;abord créer une classe Placemark, extension de la class OverlayItem qui définissent les Items contenus dans l&#8217;Overlay.</p>
<p>Chaque Object Placemark contiendra les informations de chaque point résultant de la recherche avec des accesseurs pour les extraire si nécessaire.</p>
<p>Cela permettra de récuperer toutes les propriétes venant des résultats des recherches et des les transmettre avec la position, le titre, la description a l&#8217;overlay en une fois.</p>
<p>Placemark.java :</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;">org.example.android.apis</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.android.maps.GeoPoint</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.android.maps.OverlayItem</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.map.MapPoint</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Placemark Object containing
* all informations about our search results
* Definition des parametres :
* http://developer.yahoo.com/search/local/V3/localSearch.html
*
* @author Andre Charles Legendre
*
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Placemark <span style="color: #000000; font-weight: bold;">extends</span> OverlayItem <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> mTitle<span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> mSnippet<span style="color: #339933;">;</span>
GeoPoint mPoint<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> Bundle placeBundle<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> Placemark<span style="color: #009900;">&#40;</span>GeoPoint point, <span style="color: #003399;">String</span> title, <span style="color: #003399;">String</span> snippet,
Bundle placeBundle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>point, title, snippet<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">placeBundle</span> <span style="color: #339933;">=</span> placeBundle<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mTitle</span> <span style="color: #339933;">=</span> title<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mSnippet</span> <span style="color: #339933;">=</span> snippet<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mPoint</span> <span style="color: #339933;">=</span> point<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> Bundle getBundle<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;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">placeBundle</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getid<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</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;">public</span> <span style="color: #003399;">String</span> getAddress<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Address&quot;</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;">public</span> <span style="color: #003399;">String</span> getCity<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;City&quot;</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;">public</span> <span style="color: #003399;">String</span> getState<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;State&quot;</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;">public</span> <span style="color: #003399;">String</span> getPhone<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Phone&quot;</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;">public</span> <span style="color: #003399;">String</span> getLatitude<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Latitude&quot;</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;">public</span> <span style="color: #003399;">String</span> getLongitude<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Longitude&quot;</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;">public</span> <span style="color: #003399;">String</span> getRating<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Rating&quot;</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;">public</span> <span style="color: #003399;">String</span> getAverageRating<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;AverageRating&quot;</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;">public</span> <span style="color: #003399;">String</span> getTotalRatings<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TotalRatings&quot;</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;">public</span> <span style="color: #003399;">String</span> getTotalReviews<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TotalReviews&quot;</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;">public</span> <span style="color: #003399;">String</span> getLastReviewDate<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ReviewDate&quot;</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;">public</span> <span style="color: #003399;">String</span> getLastReviewIntro<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ReviewIntro&quot;</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;">public</span> <span style="color: #003399;">String</span> getDistance<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Distance&quot;</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;">public</span> <span style="color: #003399;">String</span> getUrl<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Url&quot;</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;">public</span> <span style="color: #003399;">String</span> getClickUrl<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ClickUrl&quot;</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;">public</span> <span style="color: #003399;">String</span> getMapUrl<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MapUrl&quot;</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;">public</span> <span style="color: #003399;">String</span> getBusinessUrl<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BusinessUrl&quot;</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;">public</span> <span style="color: #003399;">String</span> getBusinessClickUrl<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;">return</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BusinessClickUrl&quot;</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;">public</span> Bundle getCategories<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;">return</span> placeBundle.<span style="color: #006633;">getBundle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Categories&quot;</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;">public</span> MapPoint getLocation<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> MapPoint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>placeBundle.
<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Latitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<span style="color: #003399;">Integer</span>.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>placeBundle.
<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Longitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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;">public</span> <span style="color: #003399;">String</span> toString<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;">return</span> <span style="color: #009900;">&#40;</span>placeBundle.<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>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Nous allons ensuite créer une classe MapDemoOverlay qui étend ItemizedOverlay.</p>
<p>Les markers des Items sont affichés automatiquement par la classe ItemizedOverlay, pour ce faire on les passe en paramètre à la création de l&#8217;Overlay.</p>
<p>La methode clé de cette classe est la methode draw. La methode draw n&#8217;a besoin d&#8217;afficher que ce qui concerne les titres et autres Toasts ou InfoWindows.</p>
<p>Une des différence majeure concernant la methode draw en 1.5 est l&#8217;utilisation de l&#8217;objet Projection pour trouver les coordonnées écran à partir des coordonnées geographiques.</p>
<p>La méthode onTap est très simple du fait que onTap de ItemizedOverlay recupère directement l&#8217;index de l&#8217;item selectionné.</p>
<p>De ce fait en utilisant l&#8217;index onTap peut directement récupérer un objet Placemark et ainsi toutes les infos fournis par Yahoo Search.</p>
<p>Place au code pour plus de clarté :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* This method is they key element of our map application
* ...
*/</span>
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">class</span> MapDemoOverlay <span style="color: #000000; font-weight: bold;">extends</span> ItemizedOverlay<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>OverlayItem<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>OverlayItem<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> items <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>OverlayItem<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><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;">public</span> MapDemoOverlay<span style="color: #009900;">&#40;</span>Drawable marker<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>boundCenterBottom<span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
populate<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: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Paint</span> innerPaint, borderPaint, textPaint<span style="color: #339933;">;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> onTap<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Placemark placeMark <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Placemark<span style="color: #009900;">&#41;</span> myLocationOverlay.<span style="color: #006633;">getItem</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MapViewDemo&quot;</span>, <span style="color: #0000ff;">&quot;ONTAP index : &quot;</span> <span style="color: #339933;">+</span> index <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; place : &quot;</span>
<span style="color: #339933;">+</span> placeMark.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onTap</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #003399;">Canvas</span> canvas, MapView myMapView, <span style="color: #000066; font-weight: bold;">boolean</span> shadow<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;">draw</span><span style="color: #009900;">&#40;</span>canvas, myMapView, shadow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Log.e(&quot;MapViewDemo&quot;, &quot;MapDemoOverlay...draw&quot;);</span>
<span style="color: #666666; font-style: italic;">// Setup our &quot;brush&quot;/&quot;pencil&quot;/ whatever...</span>
<span style="color: #003399;">Paint</span> paint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Paint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
paint.<span style="color: #006633;">setTextSize</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create a Point that represents our GPS-Location</span>
<span style="color: #003399;">Double</span> lat <span style="color: #339933;">=</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocation</span>.<span style="color: #006633;">getLatitude</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> lng <span style="color: #339933;">=</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocation</span>.<span style="color: #006633;">getLongitude</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
GeoPoint geoPoint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GeoPoint<span style="color: #009900;">&#40;</span>lat.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, lng.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Projection myprojection <span style="color: #339933;">=</span> myMapView.<span style="color: #006633;">getProjection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Point</span> point <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Point</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myprojection.<span style="color: #006633;">toPixels</span><span style="color: #009900;">&#40;</span>geoPoint, point<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Setup a color for our location</span>
paint.<span style="color: #006633;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Style</span>.<span style="color: #006633;">STROKE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
paint.<span style="color: #006633;">setARGB</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">80</span>, <span style="color: #cc66cc;">150</span>, <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nice strong Android-Green</span>
<span style="color: #666666; font-style: italic;">// Draw our name</span>
canvas.<span style="color: #006633;">drawText</span><span style="color: #009900;">&#40;</span>getString<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">map_overlay_own_name</span><span style="color: #009900;">&#41;</span>,
point.<span style="color: #006633;">x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">9</span>, point.<span style="color: #006633;">y</span>, paint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
paint.<span style="color: #006633;">setStrokeWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
paint.<span style="color: #006633;">setARGB</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
canvas.<span style="color: #006633;">drawCircle</span><span style="color: #009900;">&#40;</span>point.<span style="color: #006633;">x</span>, point.<span style="color: #006633;">y</span>, <span style="color: #cc66cc;">7</span>, paint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Log.e(&quot;MapViewDemo&quot;, &quot;MapDemoOverlay...draw</span>
paint.<span style="color: #006633;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Style</span>.<span style="color: #006633;">FILL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
drawInfoWindow<span style="color: #009900;">&#40;</span>canvas, myprojection, shadow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> placeMarks <span style="color: #339933;">=</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getSearch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Placemark placeMark<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>placeMarks <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>placeMarks<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> it <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> it <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> placeMarks.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> it<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
placeMark <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Placemark<span style="color: #009900;">&#41;</span> placeMarks.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>it<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
geoPoint <span style="color: #339933;">=</span> placeMark.<span style="color: #006633;">getPoint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myprojection.<span style="color: #006633;">toPixels</span><span style="color: #009900;">&#40;</span>geoPoint, point<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
canvas.<span style="color: #006633;">drawText</span><span style="color: #009900;">&#40;</span>placeMark.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, point.<span style="color: #006633;">x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">9</span>,
point.<span style="color: #006633;">y</span>, paint<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>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addItem<span style="color: #009900;">&#40;</span>OverlayItem item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
populate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">protected</span> OverlayItem createItem<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>OverlayItem<span style="color: #009900;">&#41;</span> items.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> size<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;">return</span> items.<span style="color: #006633;">size</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: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> drawInfoWindow<span style="color: #009900;">&#40;</span><span style="color: #003399;">Canvas</span> canvas, Projection myprojection,
<span style="color: #000066; font-weight: bold;">boolean</span> shadow<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">selectedSearchPoint</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
GeoPoint geoPoint <span style="color: #339933;">=</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">selectedSearchPoint</span>
.<span style="color: #006633;">getPoint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Point</span> point <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Point</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myprojection.<span style="color: #006633;">toPixels</span><span style="color: #009900;">&#40;</span>geoPoint, point<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Setup the info window with the right size &amp;amp; location</span>
<span style="color: #000066; font-weight: bold;">int</span> INFO_WINDOW_WIDTH <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> INFO_WINDOW_HEIGHT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>
RectF infoWindowRect <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RectF<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, INFO_WINDOW_WIDTH,
INFO_WINDOW_HEIGHT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> infoWindowOffsetX <span style="color: #339933;">=</span> point.<span style="color: #006633;">x</span> <span style="color: #339933;">-</span> INFO_WINDOW_WIDTH <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> infoWindowOffsetY <span style="color: #339933;">=</span> point.<span style="color: #006633;">y</span> <span style="color: #339933;">-</span> INFO_WINDOW_HEIGHT
<span style="color: #339933;">-</span> bubbleIcon.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
infoWindowRect.<span style="color: #006633;">offset</span><span style="color: #009900;">&#40;</span>infoWindowOffsetX, infoWindowOffsetY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Draw inner info window</span>
canvas.<span style="color: #006633;">drawRoundRect</span><span style="color: #009900;">&#40;</span>infoWindowRect, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, getInnerPaint<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Draw border for info window</span>
canvas.<span style="color: #006633;">drawRoundRect</span><span style="color: #009900;">&#40;</span>infoWindowRect, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, getBorderPaint<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Draw the MapLocation's name</span>
<span style="color: #000066; font-weight: bold;">int</span> TEXT_OFFSET_X <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> TEXT_OFFSET_Y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Glocation&quot;</span>, <span style="color: #0000ff;">&quot; selectedSearchPoint5 &quot;</span>
<span style="color: #339933;">+</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">selectedSearchPoint</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
canvas.<span style="color: #006633;">drawText</span><span style="color: #009900;">&#40;</span>MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">selectedSearchPoint</span>
.<span style="color: #006633;">getSnippet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, infoWindowOffsetX <span style="color: #339933;">+</span> TEXT_OFFSET_X,
infoWindowOffsetY <span style="color: #339933;">+</span> TEXT_OFFSET_Y, getTextPaint<span style="color: #009900;">&#40;</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>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Paint</span> getInnerPaint<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;">if</span> <span style="color: #009900;">&#40;</span>innerPaint <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
innerPaint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Paint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
innerPaint.<span style="color: #006633;">setARGB</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">225</span>, <span style="color: #cc66cc;">75</span>, <span style="color: #cc66cc;">75</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// gray</span>
innerPaint.<span style="color: #006633;">setAntiAlias</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</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;">return</span> innerPaint<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Paint</span> getBorderPaint<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;">if</span> <span style="color: #009900;">&#40;</span>borderPaint <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
borderPaint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Paint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
borderPaint.<span style="color: #006633;">setARGB</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
borderPaint.<span style="color: #006633;">setAntiAlias</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
borderPaint.<span style="color: #006633;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Style</span>.<span style="color: #006633;">STROKE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
borderPaint.<span style="color: #006633;">setStrokeWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</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;">return</span> borderPaint<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Paint</span> getTextPaint<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;">if</span> <span style="color: #009900;">&#40;</span>textPaint <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
textPaint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Paint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
textPaint.<span style="color: #006633;">setARGB</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
textPaint.<span style="color: #006633;">setAntiAlias</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</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;">return</span> textPaint<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3><span style="font-weight: normal;">Détection des changements de sélection</span></h3>
<p>Lors de la description de la class MapDemoOverlay nous avons présenté la method onTap retournant le numéro de l&#8217;item sélectionné.</p>
<p>Cette méthode ne permet pas de détecter facilement les changements de sélection.</p>
<p>Pour le faire nous allons ajouter à notre Overlay un listener ItemizedOverlay.OnFocusChangeListener .</p>
<p>Ce listener est affecté à notre Overlay par l&#8217;appel :</p>
<p>myLocationOverlay.setOnFocusChangeListener(FOCUS_LISTENER); où FOCUS_LISTENER est notre OnFocusChangeListener.</p>
<p>Dans notre cas précis le listener tiendra à jour MapViewDemo.this.selectedSearchText utilisé par draw pour afficher le contenu de infoWindow donnant des informations au sujet de l&#8217;item sélectionné par l&#8217;utilisateur.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ItemizedOverlay.<span style="color: #006633;">OnFocusChangeListener</span> FOCUS_LISTENER <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ItemizedOverlay.<span style="color: #006633;">OnFocusChangeListener</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> onFocusChanged<span style="color: #009900;">&#40;</span>ItemizedOverlay overlay, OverlayItem newFocus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newFocus <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><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><span style="color: #0000ff;">&quot;MapViewDemo&quot;</span>, <span style="color: #0000ff;">&quot;MapViewDemo ChangeFocus &quot;</span>
<span style="color: #339933;">+</span> newFocus.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">selectedSearchPoint</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Placemark<span style="color: #009900;">&#41;</span> newFocus<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Description de la gestion de la géolocalisation</h3>
<p>En utilisant la géolocalisation nous pouvons obtenir notre position immédiate.</p>
<p>Nous pouvons aussi créer un LocationListener en charge de gérer nos changements de position.</p>
<p>Pour simplifier le code nous avons groupé cela dans une méthode initMyLocation() appellée au démarrage, dans la méthode onCreate.</p>
<p>initMyLocation affiche d&#8217;abord notre position courante en appelant myLocationManager.getLastKnownLocation et initialise le rafraîchissement de notre position quand on se deplace en créant un LocationListener et en le passant en paramètre a this.myLocationManager.requestLocationUpdates.</p>
<p>Cette solution nous permet de configurer la fréquence des mises à jour de notre position à l&#8217;aide des 2 paramètres :</p>
<p>MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE</p>
<p>initMyLocation initialise aussi l&#8217;overlay dans lequel seront affichés notre geolocalisation et les résultats de nos recherches :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Initialises the MyLocationOverlay and adds it to the overlays of the map
* Prepare the things, that will give us the ability, to receive
* Information about our GPS-Position.
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> initMyLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
myLocationOverlay <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MapDemoOverlay<span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myLocationOverlay.<span style="color: #006633;">setOnFocusChangeListener</span><span style="color: #009900;">&#40;</span>FOCUS_LISTENER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myMapView.<span style="color: #006633;">getOverlays</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>myLocationOverlay<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocationManager</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LocationManager<span style="color: #009900;">&#41;</span> getSystemService<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #006633;">LOCATION_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocation</span> <span style="color: #339933;">=</span> myLocationManager.<span style="color: #006633;">getLastKnownLocation</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;gps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> lat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocation</span>.<span style="color: #006633;">getLatitude</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> lng <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myLocation</span>.<span style="color: #006633;">getLongitude</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
GeoPoint geoPoint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GeoPoint<span style="color: #009900;">&#40;</span>lat.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, lng.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myMapController</span>.<span style="color: #006633;">setCenter</span><span style="color: #009900;">&#40;</span>geoPoint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myMapController</span>.<span style="color: #006633;">setZoom</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myMapView.<span style="color: #006633;">setClickable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myMapView.<span style="color: #006633;">setEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
* Register with out LocationManager to send us an intent (whos
* Action-String we defined above) when an intent to the location
* manager, that we want to get informed on changes to our own position.
*/</span>
locListener <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LocationListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <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> onLocationChanged<span style="color: #009900;">&#40;</span>Location newLocation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">endTime</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">endTime</span> <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span> MINIMUM_TIME_BETWEEN_UPDATE_LIST<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">doUpdates</span><span style="color: #009900;">&#41;</span>
MapViewDemo.<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">updateView</span><span style="color: #009900;">&#40;</span>newLocation<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onProviderDisabled<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> provider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onProviderEnabled<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> provider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3><span style="font-weight: normal;">Utilisation de HttpClient pour appeler Yahoo Search</span></h3>
<p>La version du code est une version simpliste où l&#8217;application attend la réponse et son formattage.</p>
<p>Une version utilisable en production supposerait de créer un thread pour gérer ces traitements en background.</p>
<p>J&#8217;ai préféré simplifier pour garder la lisibilité.</p>
<p>Android propose deux libraries pour les connection http (3 si on compte les sockets).</p>
<p>La premiere est <em>android.net</em> et la second <em>org.apache.http.client.HttpClient</em> .</p>
<p>J&#8217;utilise cette dernière car j&#8217;ai déjà eu a l&#8217;utiliser par ailleurs et que c&#8217;est un outil très stable et  efficace.</p>
<p>Pour faciliter la réutilisation de ce code j&#8217;ai créé un objet <em>MapDemoConnectio</em>n en charge de gérer la connection http avec le service Yahoo Search.</p>
<p>Cet objet construit l&#8217;addresse url, l&#8217;appelle, recupère les données et lance le parsing.</p>
<p>MapDemoConnection.java :</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;">org.example.android.apis</span><span style="color: #339933;">;</span>import <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.UnsupportedEncodingException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.SocketException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.SocketTimeoutException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.HttpEntity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.HttpResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.NameValuePair</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.HttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.entity.UrlEncodedFormEntity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.methods.HttpGet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.methods.HttpPost</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.impl.client.DefaultHttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.params.BasicHttpParams</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.protocol.HTTP</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.util.EntityUtils</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.SAXException</span><span style="color: #339933;">;</span>
&nbsp;
<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.util.Xml</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* MapDemoConnection sends http requests to the web service.
*
* @author Andre Charles Legendre
*
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MapDemoConnection <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> USER_AGENT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Mozilla/4.5&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> TAG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MapDemoConnection&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> serverUrl<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> MapDemoConnection<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> serverUrl, <span style="color: #003399;">String</span> username, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">serverUrl</span> <span style="color: #339933;">=</span> serverUrl<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">password</span> <span style="color: #339933;">=</span> password<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Call Service and parse results
*
* @param resource
*            String containing text you want to search with
* @param resourceType
*            String GET or POST
* @param httpParams
*            List&amp;lt;NameValuePair&amp;gt; List of parameters send to the service
* @param myContentHandler
*            MyContentHandler Object in charge to parse the result
* @return ArrayList&amp;lt;Placemark&amp;gt; containing List of PlaceMark one for each
*         result of the search
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> parse<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> resource, <span style="color: #003399;">String</span> resourceType,
List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>NameValuePair<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> httpParams, MyContentHandler myContentHandler<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resource.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">140</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">&quot;Search text is longer than 140 characters&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">String</span> xml <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;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resourceType.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
xml <span style="color: #339933;">=</span> getRequest<span style="color: #009900;">&#40;</span>resource<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>
xml <span style="color: #339933;">=</span> postRequest<span style="color: #009900;">&#40;</span>resource,
<span style="color: #000000; font-weight: bold;">new</span> UrlEncodedFormEntity<span style="color: #009900;">&#40;</span>httpParams<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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SocketTimeoutException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
e.<span style="color: #006633;">printStackTrace</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;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SocketException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
e.<span style="color: #006633;">printStackTrace</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;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedEncodingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
e.<span style="color: #006633;">printStackTrace</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;">if</span> <span style="color: #009900;">&#40;</span>xml <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</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>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyEventHandler&quot;</span>, <span style="color: #0000ff;">&quot;xml=&quot;</span> <span style="color: #339933;">+</span> xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Xml.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>xml, myContentHandler<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>SAXException e<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><span style="color: #0000ff;">&quot;MyEventHandler&quot;</span>, <span style="color: #0000ff;">&quot;xml=&quot;</span> <span style="color: #339933;">+</span> xml <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;ERROR=&quot;</span> <span style="color: #339933;">+</span> e.<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>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> myContentHandler.<span style="color: #006633;">parse</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;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Sends a GET request to web service
*
* @param resource
* @return String response from the server
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> getRequest<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> resource<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> result <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> url <span style="color: #339933;">=</span> serverUrl <span style="color: #339933;">+</span> resource<span style="color: #339933;">;</span>
Log.<span style="color: #006633;">d</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;GET: &quot;</span> <span style="color: #339933;">+</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
HttpClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultHttpClient<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicHttpParams<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
HttpGet getMethod <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpGet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
getMethod.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;User-Agent&quot;</span>, USER_AGENT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
getMethod.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Authorization&quot;</span>, <span style="color: #0000ff;">&quot;Basic &quot;</span> <span style="color: #339933;">+</span> getCredentials<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
HttpResponse httpResponse <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>getMethod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">=</span> retrieveInputStream<span style="color: #009900;">&#40;</span>httpResponse.<span style="color: #006633;">getEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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;">Exception</span> e<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, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
e.<span style="color: #006633;">printStackTrace</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;">finally</span> <span style="color: #009900;">&#123;</span>
getMethod.<span style="color: #006633;">abort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span>TAG, result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Sends a POST request
*
* @param resource
* @param formParams
*            UrlEncodedFormEntity which is comprised of a List of
*            NameValuePairs
* @return String response from the server
* @throws SocketTimeoutException
*             , SocketException
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> postRequest<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> resource, UrlEncodedFormEntity formParams<span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">throws</span> SocketTimeoutException, <span style="color: #003399;">SocketException</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> result <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> url <span style="color: #339933;">=</span> serverUrl <span style="color: #339933;">+</span> resource<span style="color: #339933;">;</span>
Log.<span style="color: #006633;">d</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;POST: &quot;</span> <span style="color: #339933;">+</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
HttpClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultHttpClient<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicHttpParams<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
HttpPost postMethod <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpPost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// postMethod.setHeader(&quot;User-Agent&quot;, USER_AGENT);</span>
<span style="color: #666666; font-style: italic;">// postMethod.addHeader(&quot;Authorization&quot;, &quot;Basic &quot; +</span>
<span style="color: #666666; font-style: italic;">// getCredentials());</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>formParams <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
postMethod.<span style="color: #006633;">setEntity</span><span style="color: #009900;">&#40;</span>formParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
HttpResponse httpResponse <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>postMethod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">=</span> EntityUtils.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>httpResponse.<span style="color: #006633;">getEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>result <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
Log.<span style="color: #006633;">d</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;Returned response [&quot;</span> <span style="color: #339933;">+</span> httpResponse.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;] from the server: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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;">Exception</span> e<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, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
e.<span style="color: #006633;">printStackTrace</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;">finally</span> <span style="color: #009900;">&#123;</span>
postMethod.<span style="color: #006633;">abort</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;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Retrieves the content input stream from a GET request
*
* @param httpEntity
* @return String service response
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> retrieveInputStream<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> HttpEntity httpEntity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> httpEntity.<span style="color: #006633;">getContentLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">StringBuffer</span> stringBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span>length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">InputStreamReader</span> inputStreamReader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>
httpEntity.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, HTTP.<span style="color: #006633;">UTF_8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span>length<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>count <span style="color: #339933;">=</span> inputStreamReader.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span>buffer, <span style="color: #cc66cc;">0</span>, length <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
stringBuffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>buffer, <span style="color: #cc66cc;">0</span>, count<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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedEncodingException</span> e<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, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
e.<span style="color: #006633;">printStackTrace</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;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IllegalStateException</span> e<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, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
e.<span style="color: #006633;">printStackTrace</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;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<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, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
e.<span style="color: #006633;">printStackTrace</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;">return</span> stringBuffer.<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: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Retrieves the credentials
*
* @return String password
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> getCredentials<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;">return</span> password<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// return new String(Base64.encode((username + &quot;:&quot; +</span>
<span style="color: #666666; font-style: italic;">// password).getBytes()));</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Parsing des données reçues de Yahoo Search</h3>
<p style="text-align: center;"><img class="alignnone size-full wp-image-4930" title="searchmaps" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/06/searchmaps.png" alt="searchmaps" width="200" height="383" /></p>
<p>Pour le parsing nous allons créer un object MyContentHandler en charge de mettre en forme les données reçues.</p>
<p>Ces données reçues seront mises dans un ArrayList d&#8217;objects PlaceMark.</p>
<p>La fonction draw de l&#8217;ItemizedOveraly sera en charge d&#8217;afficher ces PlaceMark et de gérer leur interactivité.</p>
<p>Nous utilisons le package de org.xml.sax pour le parsing.</p>
<p>MyContentHandler extends DefaultHandler et doit donc implémenter toutes les méthodes startElement, endElement, etc.</p>
<p>En fait MapDemoConnection lance le parsing en appelant Xml.parse(xml, myContentHandler) où le paramètre xml contient les données reçues et où myContentHandler est l&#8217;objet en charge de les parser.</p>
<p>Lors du parsing myContentHandler appelle les méthodes startElement, endElement, etc. quand il reçoit une notification à chaque étape de la lecture du document.</p>
<p>MyContentHandler</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;">org.example.android.apis</span><span style="color: #339933;">;</span>import <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Set</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.Attributes</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.SAXException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.helpers.DefaultHandler</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.android.maps.GeoPoint</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.util.Log</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* MapViewDemo is the Map Activity of our application
*
* @author Andre Charles Legendre
*
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyContentHandler <span style="color: #000000; font-weight: bold;">extends</span> DefaultHandler <span style="color: #009900;">&#123;</span>
StringBuilder elementBuilder <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;">private</span> <span style="color: #003399;">String</span> id<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> numCat<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Bundle bundle<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Bundle categories<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Bundle bundles<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> title<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> snippet<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> MyContentHandler<span style="color: #009900;">&#40;</span>Activity activity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> parse<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;">return</span> getPlaceMarks<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">bundles</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> startDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Log.e(&quot;MapDemoMYCONTENTHANDLER&quot;, &quot;STARTDOCUMENT&quot;);</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">bundles</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bundle<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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> endDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MapDemoMYCONTENTHANDLER&quot;</span>, <span style="color: #0000ff;">&quot;Finish&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> startElement<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> namespaceURI, <span style="color: #003399;">String</span> localName,
<span style="color: #003399;">String</span> qName, <span style="color: #003399;">Attributes</span> atts<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Log.e(&quot;MapDemoMYCONTENTHANDLER&quot;, &quot;STARTELEMENT &quot; + localName);</span>
elementBuilder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<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>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Categories&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">numCat</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
categories <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bundle<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;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
id <span style="color: #339933;">=</span> atts.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bundle <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bundle<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>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> endElement<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> namespaceURI, <span style="color: #003399;">String</span> localName, <span style="color: #003399;">String</span> qName<span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> text <span style="color: #339933;">=</span> elementBuilder.<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;">//Log.e(&quot;MapDemoMYCONTENTHANDLER&quot;, &quot;ENDELEMENT &quot; + localName + &quot; : &quot;</span>
<span style="color: #666666; font-style: italic;">//            + text);</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ResultSetMapUrl&quot;</span><span style="color: #009900;">&#41;</span><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;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
bundles.<span style="color: #006633;">putBundle</span><span style="color: #009900;">&#40;</span>id, bundle<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Categories&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
bundle.<span style="color: #006633;">putBundle</span><span style="color: #009900;">&#40;</span>id, categories<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>localName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Category&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
categories.<span style="color: #006633;">putString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">+</span> numCat, text<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>
bundle.<span style="color: #006633;">putString</span><span style="color: #009900;">&#40;</span>localName, text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> characters<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chars, <span style="color: #000066; font-weight: bold;">int</span> i, <span style="color: #000066; font-weight: bold;">int</span> i1<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elementBuilder <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><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><span style="color: #0000ff;">&quot;MapDemoMYCONTENTHANDLER&quot;</span>, <span style="color: #0000ff;">&quot;elementBuilder NULL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
elementBuilder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
elementBuilder.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>chars, i, i1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Parse results
*
* @param mSearch
*            Bundle containing results data
* @return ArrayList&amp;lt;Placemark&amp;gt; containing List of PlaceMark one for each
*         result of the search
* @throws IOException
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> getPlaceMarks<span style="color: #009900;">&#40;</span>Bundle mSearch<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> placeMarks <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</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>mSearch <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>mSearch<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Bundle placeBundles <span style="color: #339933;">=</span> mSearch<span style="color: #339933;">;</span>
Set<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> places <span style="color: #339933;">=</span> placeBundles.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Placemark placeMark <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
Bundle Categories<span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> Latitude <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0.0000&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> Longitude <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0.0000&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> lat<span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> lng<span style="color: #339933;">;</span>
GeoPoint geoPoint<span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> fieldName<span style="color: #339933;">;</span>
Bundle placeBundle<span style="color: #339933;">;</span>
Set<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> placeFields<span style="color: #339933;">;</span>
Set<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> categories<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Iterator<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> it <span style="color: #339933;">=</span> places.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> it.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
placeBundle <span style="color: #339933;">=</span> placeBundles.<span style="color: #006633;">getBundle</span><span style="color: #009900;">&#40;</span>it.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
placeFields <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">keySet</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;">for</span> <span style="color: #009900;">&#40;</span>Iterator<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> iter <span style="color: #339933;">=</span> placeFields.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iter
.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
fieldName <span style="color: #339933;">=</span> iter.<span style="color: #006633;">next</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>fieldName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Categories&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Categories <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">getBundle</span><span style="color: #009900;">&#40;</span>fieldName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
categories <span style="color: #339933;">=</span> Categories.<span style="color: #006633;">keySet</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;">for</span> <span style="color: #009900;">&#40;</span>Iterator<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> itr <span style="color: #339933;">=</span> categories.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> itr
.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// TODO utiliser les categories</span>
@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unused&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">String</span> catName <span style="color: #339933;">=</span> Categories.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>itr
.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</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: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fieldName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Latitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Latitude <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>fieldName<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fieldName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Longitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Longitude <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>fieldName<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fieldName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
title <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>fieldName<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fieldName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LastReviewIntro&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
snippet <span style="color: #339933;">=</span> placeBundle.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>fieldName<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: #666666; font-style: italic;">// Placemark placemark = search.getPlacemark(i);</span>
<span style="color: #666666; font-style: italic;">// Log.e(&quot;GlocationMAP&quot;, &quot;MyLocationOverlay...draw</span>
<span style="color: #666666; font-style: italic;">// Search &quot; + i);</span>
Log.<span style="color: #006633;">e</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GlocationMAP&quot;</span>, <span style="color: #0000ff;">&quot;MyLocationOverlay...snippet &quot;</span>
<span style="color: #339933;">+</span> snippet<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lat <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>Latitude<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
lng <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>Longitude<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1E6<span style="color: #339933;">;</span>
geoPoint <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GeoPoint<span style="color: #009900;">&#40;</span>lat.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, lng.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
placeMark <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Placemark<span style="color: #009900;">&#40;</span>geoPoint, title, snippet,
placeBundle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// placeMark.setMarker(marker);</span>
placeMarks.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>placeMark<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: #000000; font-weight: bold;">return</span> placeMarks<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Ecran de saisie de la requête utilisateur de recherche</h3>
<p>Nous allons créer une nouvelle activité SearchActivity pour permettre à l&#8217;utilisateur de saisir une recherche.</p>
<p>SearchActivity doit créer un espace de saise du texte et un bouton pour lancer la recherche.</p>
<p>La syntaxe des recherches que l&#8217;utilisateur doir entrer est celle de Yahoo Search.</p>
<p>Votre location doit être a l&#8217;intérieur des Etats-Unis du à la limitation de Yahoo Search, autrement vous n&#8217;aurez aucun résultat.</p>
<p>On limite la longueur a 140 caractères.</p>
<p>SearchActivity.java</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;">org.example.android.apis</span><span style="color: #339933;">;</span>import <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Intent</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.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.view.View</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* SearchActivity Activity getting search from user sending result by an intent
*
* @author Andre Charles Legendre
*
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SearchActivity <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">protected</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> ACTIVITY_RESULT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;org.example.android.apis.EDIT&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> SearchActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Called with 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 icicle<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>icicle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the layout for this activity.</span>
setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">Button</span> addButton <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;">searchButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
addButton.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <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> 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>
Intent i <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// We limit length to 140 to avoid exception in</span>
<span style="color: #666666; font-style: italic;">// MapDemoConnection</span>
<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</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;">searchText</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">140</span><span style="color: #009900;">&#41;</span>
result <span style="color: #339933;">=</span> result.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">139</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
i.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>ACTIVITY_RESULT,result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
setResult<span style="color: #009900;">&#40;</span>RESULT_OK, i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On doit bien entendu déclarer cette Activity dans le fichier AndroidManifest.xml pour pouvoir l&#8217;utiliser.</p>
<p>Nous avons par ailleurs ajouté dans <em>MapViewDemo.java</em> une option au menu et un KeyEvent pour KEY_F pour lancer SearchActivity :</p>
<div class="wp_syntax">
<div class="code"><span style="font-family: monospace;"><span style="color: #0000ff;">&lt;?</span><span style="color: #2e8b57;"><strong>xml</strong></span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>version</strong></span>=<span style="color: #ff00ff;">&#8220;1.0&#8243;</span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>encoding</strong></span>=<span style="color: #ff00ff;">&#8220;utf-8&#8243;</span><span style="color: #0000ff;">?&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">manifest</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>xmlns</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>android</strong></span>=<span style="color: #ff00ff;">&#8220;<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&#8220;</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>package</strong></span>=<span style="color: #ff00ff;">&#8220;org.example.android.apis&#8221;</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">permission</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>xmlns</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>android</strong></span>=<span style="color: #ff00ff;">&#8220;<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&#8220;</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.permission.INTERNET&#8221;</span><span style="color: #008b8b;">&gt;</span><span style="color: #008b8b;">&lt;/permission&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-permission</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.permission.INTERNET&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-permission</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.permission.ACCESS_FINE_LOCATION&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">application</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>label</strong></span>=<span style="color: #ff00ff;">&#8220;@string/app_name&#8221;</span><br />
<span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>icon</strong></span>=<span style="color: #ff00ff;">&#8220;@drawable/icon&#8221;</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;MapDemoApplication&#8221;</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-library</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;com.google.android.maps&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">activity</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;.MapViewDemo&#8221;</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>label</strong></span>=<span style="color: #ff00ff;">&#8220;@string/app_name&#8221;</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">intent-filter</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">action</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.action.MAIN&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">category</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.category.DEFAULT&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">category</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.category.LAUNCHER&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;/intent-filter&gt;</span><br />
<span style="color: #008b8b;">&lt;/activity&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">activity</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;.SearchActivity&#8221;</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>label</strong></span>=<span style="color: #ff00ff;">&#8220;Find&#8221;</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">intent-filter</span><span style="color: #008b8b;">&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">action</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.action.MAIN&#8221;</span><span style="color: #008b8b;">/&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">category</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.category.GLOCATION&#8221;</span><span style="color: #008b8b;">/&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">action</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">&#8220;android.intent.action.SEARCH&#8221;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;/intent-filter&gt;</span><br />
<span style="color: #008b8b;">&lt;/activity&gt;</span><br />
<span style="color: #008b8b;">&lt;/application&gt;</span><br />
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-sdk</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>minSdkVersion</strong></span>=<span style="color: #ff00ff;">&#8220;3&#8243;</span><span style="color: #008b8b;"> /&gt;</span><br />
<span style="color: #008b8b;">&lt;/manifest&gt;</span><br />
</span></div>
</div>
<h3><span style="font-weight: normal;">Conclusion </span></h3>
<p>Nous voilà au bout de ce tutorials qui nous a permis de voir beaucoup de nouveaux éléments.</p>
<p>Il y en aura encore dans la suite, nous verrons ce que ça donne avec Google Search.</p>
<p>Nous aborderons également le composant WebView et les interactions possible avec Java et  JavaScript. Attention ça va en surprendre plus d&#8217;un&#8230;</p>
<p>J&#8217;attends vos remarques, critiques, propositions d&#8217;amelioration.</p>
<p><a href="http://www.pointgphone.com/files/MapDemoV2.zip">Télécharger les sources</a><br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/htc-magic-sfr-communique-presse-photos-officielles-1691" title="HTC Magic chez SFR : communiqué de presse et photos officielles">HTC Magic chez SFR : communiqué de presse et photos officielles</a></li>
<li><a href="http://www.pointgphone.com/mise-a-jour-google-maps-11250" title="Encore une mise à jour pour Google Maps">Encore une mise à jour pour Google Maps</a></li>
<li><a href="http://www.pointgphone.com/google-maps-navigation-europe-9820" title="Google Maps Navigation de retour en Europe">Google Maps Navigation de retour en Europe</a></li>
<li><a href="http://www.pointgphone.com/google-maps-navigation-android-donut-9432" title="Google Maps Navigation disponible officiellement pour Android 1.6 Donut">Google Maps Navigation disponible officiellement pour Android 1.6 Donut</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-android-introduction-intents-7779" title="Tutoriel Android : Introduction aux Intents">Tutoriel Android : Introduction aux Intents</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/map-application-android-sdk-15-deuxieme-partie-4916">Map application pour Android SDK 1.5, deuxième partie</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/map-application-android-sdk-15-deuxieme-partie-4916/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Map application pour Android SDK 1.5, première partie</title>
		<link>http://www.pointgphone.com/map-application-android-sdk-15-2597</link>
		<comments>http://www.pointgphone.com/map-application-android-sdk-15-2597#comments</comments>
		<pubDate>Mon, 18 May 2009 05:00:47 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2597</guid>
		<description><![CDATA[Vous aviez été nombreux à apprécier le tutoriel d&#8217;André sur la géolocalisation. Il est de retour avec un nouveau tutoriel qui vous permettra d&#8217;explorer les fonctionnalités maps et GPS du nouveau SDK Android version 1.5 !

Pour porter mon application GLocationMap sous le SDK 1.5, j&#8217;ai choisi la solution de réécriture pas à pas. Ceci m&#8217;a [...]]]></description>
			<content:encoded><![CDATA[<p>Vous aviez été nombreux à apprécier le <a title="Tutoriel Android : GLocation" href="http://www.pointgphone.com/tutoriel-android-glocation-703" target="_self">tutoriel d&#8217;André sur la géolocalisation</a>. Il est de retour avec un nouveau tutoriel qui vous permettra d&#8217;explorer les fonctionnalités maps et GPS du nouveau SDK Android version 1.5 !</p>
<p><span id="more-2597"></span></p>
<p>Pour porter mon application GLocationMap sous le SDK 1.5, j&#8217;ai choisi la solution de réécriture pas à pas. Ceci m&#8217;a paru nécessaire compte tenu des differences majeures entre le SDK 1.0 et le SDK 1.5 et me permet donc de faire une série de tutoriaux progressifs expliquant en détails l&#8217;utilisation des fonctions Maps, GPS et Location Services mais aussi les difficultés rencontrées.</p>
<p>Ce premier tutoriel va présenter les bases d&#8217;une application Android élémentaire intégrant Google Maps.</p>
<p>Nous présenterons dans les tutoriaux suivants tout ce qui concerne l&#8217;intégration de menus pour interopérer avec la carte, puis les Overlays pour ajouter des informations, puis la recuperation des infos de localisation, la communication avec des serveurs d&#8217;application et bien plus encore !</p>
<h3>Android Virtual Devices</h3>
<p>La version 1.5 du SDK Android introduit une nouveauté avec les Android Virtual Devices, des terminaux Android virtuels configurables dans les moindres détails, qui seront nécessaires au lancement de votre application.</p>
<p>Un Android Virtual Device (AVD) modélise un seul virtual device hébergeant la plateforme Android qui a au minimum son propre Kernel, system image et data partition.</p>
<p>Un emulator process peut lancer un seul AVD à la fois, mais vous pouvez créer plusieurs Android Virtual Devices et les faire tourner en parallèle.</p>
<p><strong>Création d&#8217;un AVD</strong> : <em>android create avd &#8211;name my_avd &#8211;target t</em> (t = 1 pour Android 1.1, 2 pour 1.5 etc)</p>
<p>Pour avoir la liste des avds : <em>android list avds</em></p>
<p>Vous obtenez par ex :</p>
<p><em>Available Android Virtual Devices:</em></p>
<p><em>Name: avd_1.5</em></p>
<p><em>Path: /home/rcs/.android/avd/avd_1.5.avd</em></p>
<p><em>Target: Android 1.5 (API level 3)</em></p>
<p><em>Skin: HVGA</em></p>
<p><em>&#8212;&#8212;&#8212;</em></p>
<p><em>Name: my_avd</em></p>
<p><em>Path: /home/rcs/.android/avd/my_avd.avd</em></p>
<p><em>Target: Android 1.1 (API level 2)</em></p>
<p><em>Skin: HVGA</em></p>
<p><strong>Pour utiliser un AVD</strong> :</p>
<p>Si vous lancez votre application depuis Eclipse, l&#8217;environnement de développement va identifier automatiquement l&#8217;AVD à utiliser en fonction des options de compilation que vous avez choisi.</p>
<p>Pour lancer l&#8217;émulateur vous devez specifier le nom de l&#8217;AVD que vous souhaitez utiliser : <em>emulator @my_avd</em></p>
<p><strong>Pour avoir plus de détails sur les AVD</strong> : <em>emulator -help-virtual-device</em></p>
<h3>Utiliser Google Maps avec le SDK 1.5</h3>
<p>Nous devons en premier éditer le fichier layout de notre application contenu dans le fichier /res/layout/mapview.xml :</p>
<pre class="xml"><span style="color: #0000ff;">&lt;?</span><span style="color: #2e8b57;"><strong>xml</strong></span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>version</strong></span>=<span style="color: #ff00ff;">"1.0"</span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>encoding</strong></span>=<span style="color: #ff00ff;">"utf-8"</span><span style="color: #0000ff;">?&gt;</span>
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">LinearLayout</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>xmlns</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>android</strong></span>=<span style="color: #ff00ff;">"<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"</span>
<span style="color: #008b8b;">    </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>id</strong></span>=<span style="color: #ff00ff;">"@+id/main"</span>
<span style="color: #008b8b;">    </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>layout_width</strong></span>=<span style="color: #ff00ff;">"fill_parent"</span><span style="color: #008b8b;"> </span>
<span style="color: #008b8b;">    </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>layout_height</strong></span>=<span style="color: #ff00ff;">"fill_parent"</span><span style="color: #008b8b;">&gt;</span>
    <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">com</span><span style="color: #0000ff;">.</span><span style="color: #008b8b;">google</span><span style="color: #0000ff;">.</span><span style="color: #008b8b;">android</span><span style="color: #0000ff;">.</span><span style="color: #008b8b;">maps</span><span style="color: #0000ff;">.</span><span style="color: #008b8b;">MapView</span>
<span style="color: #008b8b;">        </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>layout_width</strong></span>=<span style="color: #ff00ff;">"fill_parent"</span><span style="color: #008b8b;"> </span>
<span style="color: #008b8b;">        </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>layout_height</strong></span>=<span style="color: #ff00ff;">"fill_parent"</span>
<span style="color: #008b8b;">        </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>enabled</strong></span>=<span style="color: #ff00ff;">"true"</span>
<span style="color: #008b8b;">        </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>clickable</strong></span>=<span style="color: #ff00ff;">"true"</span>
<span style="color: #008b8b;">        </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>apiKey</strong></span>=<span style="color: #ff00ff;">"@string/mapskey"</span>
<span style="color: #008b8b;">     /&gt;</span>
<span style="color: #008b8b;">&lt;/LinearLayout&gt;</span></pre>
<p>Comme vous le voyez, notre layout ne contient pour l&#8217;instant rien d&#8217;autre qu&#8217;un MapView, élément indispensable pour une application utilisant Google Maps.</p>
<p>Les IDs du <em>LinearLayout</em> et du <em>MapView</em> sont utilisés pour rendre accessibles les Views dans l&#8217;Activity.</p>
<p>Pour utiliser les composants Google Maps  une API key est nécessaire, et sera stockée comme une ressource string référencée par la clé <em>@string/mapskey</em>.</p>
<h3>Obtenir une clé pour l&#8217;API Google Maps :</h3>
<p>Android autorise l&#8217;installation des applications signées exclusivement. Avant d&#8217;installer une application dans l&#8217;émulateur, Eclipse va automatiquement signer votre application, utilisant un certificat de debug qui vient avec le SDK Android. Eclipse crée le fichier <em>debug.keystore</em> lors de la compilation (réussie) du projet, stocké dans le répertoire ~/.android. La clé pour l&#8217;API Google Maps est basée sur ce certificat de debug. Une explication detaillée expliquant comment signer une application peut facilement se trouver en ligne.</p>
<p>Pour obtenir une Google Maps API key (en utilisant le debug certificate) vous devez suivre les étapes suivantes :</p>
<p><strong>Créer un md5 checksum du debug certificate</strong> :<br />
Trouver le debug.keystore</p>
<ul>
<li>Vista: C:\Users\\AppData\Local\Android\debug.keystore</li>
<li>XP: C:\Documents and Settings\\Android\debug.keystore</li>
<li>Mac, Linux: ~/.android/debug.keystore</li>
</ul>
<p>Et appeler la commande : <em>keytool -list -alias androiddebugkey -keystore .keystore -storepass android -keypass android</em></p>
<p>Le md5 checksum est généré et affiché à l&#8217;écran :</p>
<p><em>androiddebugkey, Apr 20, 2009, PrivateKeyEntry,</em></p>
<p><em>Certificate fingerprint (MD5): XX:YY:ZZ:AA:BB:CC:FF:CA:A7:99:AD:DD:DF:5C:12:ED</em></p>
<p><strong>Enregistrer le md5 checksum</strong> :</p>
<p><a title="Sign Up for the Android Maps API" href="Android Maps API Key Signup" target="_blank">S&#8217;enregister sur Google Code pour avoir une Maps API key</a>. Un compte google est requis pour pouvoir le faire.</p>
<p>Saisir le checksum md5 et cliquer sur le bouton &#8220;Generate API key&#8221;.</p>
<p>Vous obtenez alors une page avec votre Google Maps API key et une petite explication de comment l&#8217;utiliser dans un layout.</p>
<p><strong>Editer les resources dans le fichier string.xml</strong> :</p>
<p>Copier-coller la Google Maps API key dans le fichier string.xml pour la resource string/mapskey utilisée dans le layout :</p>
<p><span style="font-family: 'Courier New'; line-height: 18px; white-space: pre;"><span style="color: #0000ff;">&lt;?</span><span style="color: #2e8b57;"><strong>xml</strong></span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>version</strong></span>=<span style="color: #ff00ff;">&#8220;1.0&#8243;</span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>encoding</strong></span>=<span style="color: #ff00ff;">&#8220;utf-8&#8243;</span><span style="color: #0000ff;">?&gt;</span></span></p>
<pre class="xml"><span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">resources</span><span style="color: #008b8b;">&gt;</span>
    <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">string</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"app_name"</span><span style="color: #008b8b;">&gt;</span>MapDemoV1<span style="color: #008b8b;">&lt;/string&gt;</span>
    <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">string</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"mapskey"</span><span style="color: #008b8b;">&gt;</span>XXXXXXXXXX7O2PwQ5YMM6ilp5HCJ4YYYYYYYYYY<span style="color: #008b8b;">&lt;/string&gt;</span>
<span style="color: #008b8b;">&lt;/resources&gt;</span></pre>
<p><strong>Ajouter les permissions requises et les librairies au manifest</strong></p>
<p>Notre application nécessite deux permissions :</p>
<ul>
<li>Google maps impose l&#8217;accès a internet (android.permission.INTERNET)</li>
<li>La partie Localisation (à venir) impose l&#8217;accès au GPS (android.permission.ACCESS_FINE_LOCATION)</li>
</ul>
<p>De plus, la library Google Maps API (com.google.android.maps) doit être incluse dans le projet.</p>
<p>Notre fichier <em>AndroidManifest.xml</em> :</p>
<pre class="xml"><span style="color: #0000ff;">&lt;?</span><span style="color: #2e8b57;"><strong>xml</strong></span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>version</strong></span>=<span style="color: #ff00ff;">"1.0"</span><span style="color: #2e8b57;"><strong> </strong></span><span style="color: #2e8b57;"><strong>encoding</strong></span>=<span style="color: #ff00ff;">"utf-8"</span><span style="color: #0000ff;">?&gt;</span>
<span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">manifest</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>xmlns</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>android</strong></span>=<span style="color: #ff00ff;">"<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"</span>
<span style="color: #008b8b;">      </span><span style="color: #2e8b57;"><strong>package</strong></span>=<span style="color: #ff00ff;">"org.example.android.apis"</span>
<span style="color: #008b8b;">      </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>versionCode</strong></span>=<span style="color: #ff00ff;">"1"</span>
<span style="color: #008b8b;">      </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>versionName</strong></span>=<span style="color: #ff00ff;">"1.0"</span><span style="color: #008b8b;">&gt;</span>
    <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">application</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>label</strong></span>=<span style="color: #ff00ff;">"@string/app_name"</span>
<span style="color: #008b8b;">            </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>icon</strong></span>=<span style="color: #ff00ff;">"@drawable/icon"</span><span style="color: #008b8b;">&gt;</span>
                <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-library</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"com.google.android.maps"</span><span style="color: #008b8b;"> /&gt;</span>
         <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">activity</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">".MapViewDemo"</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>label</strong></span>=<span style="color: #ff00ff;">"@string/app_name"</span><span style="color: #008b8b;">&gt;</span>
            <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">intent-filter</span><span style="color: #008b8b;">&gt;</span>
                <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">action</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"android.intent.action.MAIN"</span><span style="color: #008b8b;"> /&gt;</span>
                <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">category</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"android.intent.category.LAUNCHER"</span><span style="color: #008b8b;"> /&gt;</span>
            <span style="color: #008b8b;">&lt;/intent-filter&gt;</span>
        <span style="color: #008b8b;">&lt;/activity&gt;</span>
    <span style="color: #008b8b;">&lt;/application&gt;</span>
    <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-sdk</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>minSdkVersion</strong></span>=<span style="color: #ff00ff;">"3"</span><span style="color: #008b8b;"> /&gt;</span>
        <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-permission</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"android.permission.INTERNET"</span><span style="color: #008b8b;"> /&gt;</span>
        <span style="color: #008b8b;">&lt;</span><span style="color: #008b8b;">uses-permission</span><span style="color: #008b8b;"> </span><span style="color: #2e8b57;"><strong>android</strong></span><span style="color: #0000ff;">:</span><span style="color: #2e8b57;"><strong>name</strong></span>=<span style="color: #ff00ff;">"android.permission.ACCESS_FINE_LOCATION"</span><span style="color: #008b8b;"> /&gt;</span>
<span style="color: #008b8b;">&lt;/manifest&gt;</span></pre>
<h3>Le code java</h3>
<p>Cette application doit hériter de <em>MapActivity</em> et faire reference au layout défini dans mapview.xml a l&#8217;aide de la méthode setContentView.</p>
<p>Le fichier MapViewDemo.java :</p>
<p><span style="color: #a020f0;">package</span> org.example.android.apis;</p>
<p><span style="color: #a020f0;">import</span> android.os.Bundle;<br />
<span style="color: #a020f0;">import</span> com.google.android.maps.MapActivity;<br />
 <br />
<span style="color: #2e8b57;"><strong>public</strong></span> <span style="color: #2e8b57;"><strong>class</strong></span> MapViewDemo <span style="color: #2e8b57;"><strong>extends</strong></span> MapActivity {<br />
 <br />
        <span style="color: #0000ff;">/**</span><span style="color: #6a5acd;"> Called when the activity is first created.</span><span style="color: #0000ff;"> */</span><br />
        <span style="color: #a020f0;">@Override</span><br />
        <span style="color: #2e8b57;"><strong>public</strong></span> <span style="color: #2e8b57;"><strong>void</strong></span> onCreate(Bundle savedInstanceState) {<br />
                <span style="color: #2e8b57;"><strong>super</strong></span>.onCreate(savedInstanceState);<br />
                setContentView(R.layout.mapview);<br />
        }<br />
 <br />
        <span style="color: #a020f0;">@Override</span><br />
        <span style="color: #2e8b57;"><strong>protected</strong></span> <span style="color: #2e8b57;"><strong>boolean</strong></span> isRouteDisplayed() {<br />
                <span style="color: #a52a2a;"><strong>return</strong></span> <span style="color: #ff00ff;">false</span>;<br />
        }<br />
}</p>
<p>L&#8217;application peut être lancée en sélectionnant le projet dans Eclipse, clic droit, Run As, Android Application.</p>
<h3>Compilation, exécution, debogage</h3>
<p>Il est possible de tester l&#8217;application en utilisant l&#8217;émulateur.</p>
<p>Pour compiler de facon correcte une application utilisant Google Maps avec le SDK 1.5 vous devez definir le project target comme étant un Google Maps API.</p>
<p style="text-align: center;"><img class="size-full wp-image-2654 aligncenter" title="emulator-map" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/05/emulator-map.png" alt="emulator-map" width="379" height="733" /></p>
<p>Selectionnez le projet dans Eclipse, clic droit, Properties, Android et sélectionnez sur Google Maps API comme target.</p>
<p>Pour voir défiler le log : <em>adb logcat</em> dans une fenêtre indépendante lorsque l&#8217;émulateur est lancé</p>
<p>En cas de problème vous pouvez vouloir effacer les installations précéedentes pour repartir avec un émulateur propre grâce à cette commande : <em>/tools/emulator -wipe-data @avd_1.5</em></p>
<p>Pour effacer ce que vous souhaitez seulement (attention aux erreurs !) : </p>
<p><em>/tools/adb shell (quand l&#8217;emulateur fonctionne)</em></p>
<p><em>cd /data/app</em></p>
<p><em>rm appli.apk</em></p>
<p>Pour des débugage plus complexe, consultez la doc d&#8217;Eclipse. Pour ma part je préfère éviter les erreurs que les déboger !</p>
<p>La suite très prochainement&#8230;<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/tutoriel-android-glocation-703" title="Tutoriel Android : GLocation">Tutoriel Android : GLocation</a></li>
<li><a href="http://www.pointgphone.com/mise-a-jour-google-maps-11250" title="Encore une mise à jour pour Google Maps">Encore une mise à jour pour Google Maps</a></li>
<li><a href="http://www.pointgphone.com/google-maps-navigation-europe-9820" title="Google Maps Navigation de retour en Europe">Google Maps Navigation de retour en Europe</a></li>
<li><a href="http://www.pointgphone.com/google-maps-navigation-android-donut-9432" title="Google Maps Navigation disponible officiellement pour Android 1.6 Donut">Google Maps Navigation disponible officiellement pour Android 1.6 Donut</a></li>
<li><a href="http://www.pointgphone.com/mise-a-jour-google-maps-android-5114" title="Mise à jour de Google Maps pour Android">Mise à jour de Google Maps pour Android</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/map-application-android-sdk-15-2597">Map application pour Android SDK 1.5, première partie</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/map-application-android-sdk-15-2597/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Tutoriel Android : &quot;Hello World&quot; version 1.5</title>
		<link>http://www.pointgphone.com/tutoriel-android-hello-world-2301</link>
		<comments>http://www.pointgphone.com/tutoriel-android-hello-world-2301#comments</comments>
		<pubDate>Wed, 22 Apr 2009 05:00:53 +0000</pubDate>
		<dc:creator>Cyril Mottier</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Hello World]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[tuto]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2301</guid>
		<description><![CDATA[Cyril Mottier vous avait présenté l&#8217;arborescence d&#8217;un projet Android et les principaux composants d&#8217;une application. Impatients de mettre la main à la pâte? On attaque maintenant les choses sérieuses avec une version améliorée du célèbre &#8220;Hello World&#8221;, avec le SDK Android 1.5 s&#8217;il vous plaît !

Nous y voilà enfin ! Les &#8220;guerriers&#8221; qui ont eu [...]]]></description>
			<content:encoded><![CDATA[<p>Cyril Mottier vous avait présenté l&#8217;<a title="Tutoriel : L’arborescence d’un projet Android" href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054" target="_self">arborescence d&#8217;un projet Android</a> et les <a title="Tutoriel : Les composants principaux d’Android" href="http://www.pointgphone.com/tutoriel-composants-android-2238" target="_self">principaux composants d&#8217;une application</a>. Impatients de mettre la main à la pâte? On attaque maintenant les choses sérieuses avec une version améliorée du célèbre &#8220;Hello World&#8221;, avec le SDK Android 1.5 s&#8217;il vous plaît !</p>
<p><span id="more-2301"></span></p>
<p>Nous y voilà enfin ! Les &#8220;guerriers&#8221; qui ont eu le courage de lire les deux premières parties de ce tutorial vont enfin pouvoir arriver à leurs fins. Cette fin c&#8217;est la réalisation de votre premier programme sur Android. Comme à l&#8217;accoutumée, il m&#8217;a semblé judicieux de faire ce que tout bon professeur enseigne à ses élèves lors de l&#8217;apprentissage d&#8217;une nouvelle technologie ou d&#8217;un nouveau langage : un &#8220;Hello World&#8221;.</p>
<p>Certains d&#8217;entre vous ont probablement remarqué qu&#8217;avec le plugin <strong>ADT</strong> (Android Development Tools) d&#8217;<strong>Eclipse</strong>, la création d&#8217;un nouveau projet Android revient en fait à la création d&#8217;un programme de type &#8220;Hello World&#8221;. Ce &#8220;Hello World&#8221; est d&#8217;une simplicité enfantine. Cela permet aux débutants de mieux appréhender le développement sur Android. Dans les lignes qui suivent, nous allons créer notre propre &#8220;Hello World&#8221; en modifiant l&#8217;existant. Nous tenterons de l&#8217;améliorer d&#8217;un point de vue graphique essentiellement.</p>
<p><em><strong>Note </strong>: Les exemples et les copies d&#8217;écran ci-dessous ont été effectués sur le SDK 1.5. Ce SDK introduit quelques nouveautés afin de faciliter le développement sur Android. On remarquera par exemple des changements au niveau de l&#8217;arborescence du projet par rapport à celle expliquée dans la <a title="Tutoriel : Arborescence d’un projet Android" href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054" target="_self">partie 1</a> de ce tutorial</em></p>
<p>Vous noterez dans cette partie que le code <strong>Java</strong> a volontairement été réduit au maximum. Pourquoi? La réponse est assez simple. Le développement sur Android se fait bien sûr en <strong>Java</strong> comme il a été précisé dans des parties antérieures. Néanmoins, lorsqu&#8217;il s&#8217;agit d&#8217;interface graphique, le XML est préférable car plus simple et plus lisible. En effet, les ingénieurs de chez Google ont conçu un système d&#8217;expansion (inflate) de fichiers XML pour créer des interfaces graphiques. Ces fichiers XML sont ensuite utilisés, en interne par le système, pour générer l&#8217;interface graphique. Ce dernier relit les fichiers XML puis créé les objets Java associés de façon automatique.</p>
<p><em><strong>Note </strong>: En réalité, les fichiers XML ne sont pas incorporés dans votre paquet d&#8217;installation sous forme XML. Le &#8220;parsing&#8221; (action de relire un fichier et d&#8217;en extraire les informations) est une opération relativement coûteuse. Pour contrer ce problème, les fichiers XML sont en réalité pré-parsés et incorporés sous une forme plus rapide à lire/exécuter dans le paquet d&#8217;installation. On conserve ainsi l&#8217;avantage de la lisibilité et de la facilité d&#8217;utilisation d&#8217;un point de vue utilisateur et on optimise d&#8217;autre part la relecture de ces fichiers lors de l&#8217;expansion de l&#8217;interface graphique.</em></p>
<p>Ce tutorial explique comment créer, à partir de rien, ce premier &#8220;Hello World&#8221;. La meilleure façon de bien comprendre la totalité de ce tutorial est d&#8217;en lire l&#8217;intégralité. Si vous n&#8217;avez pas réellement envie de vous attarder sur les différents points et préférez attaquer directement le code, les sources et les ressources sont disponibles dans ce <a href="http://www.pointgphone.com/files/part3.zip">fichier</a>.</p>
<p>Maintenant que les quelques précisions ont été données, nous pouvons créer notre premier &#8220;Hello World&#8221;. Pour ce faire, commençons par créer le projet dans l&#8217;environnement Eclipse. Cliquez sur <strong>File &gt; New &gt; Other&#8230; &gt; Android Project</strong>. Une boite de dialogue un peu modifiée en comparaison de celle présentée en <a title="Tutoriel : Arborescence d’un projet Android" href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054" target="_self">partie 1</a> s&#8217;ouvre. Remplissez là comme suit :</p>
<p style="text-align: center; "><img class="alignnone size-full wp-image-2305" title="new-android-project" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/new-android-project.png" alt="new-android-project" width="400" height="503" /></p>
<p>Validez la création du projet en cliquant sur <strong>Finish</strong>. Nous voilà maintenant en présence d&#8217;un projet de type &#8220;Hello World&#8221; affichant simplement un texte à l&#8217;écran. Pour lancer l&#8217;application sur l&#8217;émulateur, cliquez simplement sur <strong>Run &gt; Run</strong> ou sur l&#8217;icône représentant un cercle vert et contenant un triangle blanc. Une boite de dialogue s&#8217;ouvre alors et vous demande quel sera le type de l&#8217;exécution. Dans notre cas nous souhaitons bien sûr que l&#8217;exécution se fasse sous la forme d&#8217;&#8221;Android Application&#8221;.</p>
<p>L&#8217;objectif de cette partie est d&#8217;améliorer ce &#8220;Hello World&#8221; en n&#8217;utilisant presqu&#8217;exclusivement que du XML. Listons tout d&#8217;abord les différentes valeurs et ressources que nous utiliserons:</p>
<ul>
<li>Les chaines de caractères (<em>strings.xml</em>) : le nom de l&#8217;application, la chaine &#8220;Hello World&#8221;</li>
<li>Les couleurs (<em>colors.xml</em>) : la couleur de la chaine &#8220;Hello World&#8221;</li>
<li>Les dimensions (<em>dimensions.xml</em>) : la taille de la chaine &#8220;Hello World&#8221;</li>
<li>Les images (<em>drawable</em>) : l&#8217;image de la mascotte Android ou tout autre image qui vous fait plaisir</li>
</ul>
<p>Commençons par créer les différentes chaines de caractères que nous utiliserons. Ces éléments se trouvent dans le fichier <em>strings.xml</em>. Double cliquez sur ce dernier pour ouvrir la vue de modification. On y retrouve déjà deux chaines de caractères :</p>
<p style="text-align: center; "><img class="size-full wp-image-2306 aligncenter" title="android-resources" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/android-resources.png" alt="android-resources" width="400" height="156" /></p>
<p>La première chaine est &#8220;app_name&#8221;. C&#8217;est le nom qui sera affiché dans le &#8220;Home Screen&#8221; sous l&#8217;icône de l&#8217;application. Cette chaine a pour valeur le nom de l&#8217;application donné dans la boite de dialogue à la création du projet. Il n&#8217;est donc normalement pas nécessaire de la modifier. La chaine &#8220;hello&#8221; par contre ne satisfait pas à nos critères et nous allons donc changer sa valeur à &#8220;Hello World&#8221;. Enregistrez le fichier pour valider les changements.</p>
<p>Créons maintenant une nouvelle couleur qui servira pour l&#8217;affichage de la chaine de caractère &#8220;Hello World&#8221;. Il nous faut un fichier <em>colors.xml</em>. De base, ce fichier n&#8217;existe pas et il faut donc le créer manuellement. Pour ce faire cliquez simplement sur l&#8217;icone Android disposant d&#8217;un signe plus vert. Une boite de dialogue, qui a été introduite avec le SDK 1.5, apparait. Nous souhaitons créer un fichier <em>colors.xml</em> qui contiendra des valeurs (values) relatives aux couleurs. ADT s&#8217;occupe automatiquement de créer le fichier dans le bon répertoire (c&#8217;est à dire <em>res/values</em>).</p>
<p style="text-align: center; "><img class="size-full wp-image-2309 aligncenter" title="new-android-xml-file" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/new-android-xml-file.png" alt="new-android-xml-file" width="400" height="417" /></p>
<p>Le fichier de ressources <em>colors.xml</em> étant maintenant créé, il ne nous reste plus qu&#8217;à y ajouter une couleur. La couleur sera le blanc parfait &#8220;white&#8221; et la valeur associée &#8220;#fff&#8221;. Cliquez sur <strong>Add &gt; Color</strong> et remplissez les champs avec les valeurs adéquates. Notez qu&#8217;Android gère plusieurs formats de couleurs que sont #RGB, #ARGB, #RRGGBB et #AARRGGBB. Ce sont les notations hexadécimales des couleurs R représentant le rouge, G le vert, B le bleu et A le canal alpha (la transparence).</p>
<p>Pour créer la dimension de la chaine de caractères &#8220;Hello World&#8221;, il suffit de réitérer l&#8217;opération. Comme vous vous en doutez probablement, l&#8217;objectif est de créer un fichier <em>dimensions.xml</em> et d&#8217;y inclure le couple nom/valeur suivant : &#8220;dim_hello&#8221;/&#8221;20px&#8221;. Dans notre cas, nous utilisons les pixels (px) comme mesure mais d&#8217;autres dimensions sont disponibles :  in, mm, pt, dp et sp.</p>
<p>Ajoutons, pour finir l&#8217;image de la mascotte Android dans le dossier des <em>drawables</em>. Il suffit simplement d&#8217;effectuer un glisser/déposer dans le dossier drawable à l&#8217;aide d&#8217;Eclipse. Vous pouvez aussi directement inclure le fichier dans votre workspace puis lancer un rafraichissement de votre projet par un F5 dans Eclipse.</p>
<p><em><strong>Note </strong>: En réalité, Android peut gérer les ressources présentes dans un seul et unique fichier de valeurs. Néanmoins, l&#8217;expérience prouve que mélanger les chaines de caractères, les couleurs, les tableaux d&#8217;entier, les dimensions, etc. n&#8217;aide pas à la compréhension d&#8217;un projet. De plus lors de l&#8217;internationalisation (i18n), il est inutile de traduire des grandeurs indépendantes de la localisation telles que les couleurs ou les dimensions par exemple. Il est donc préférable de séparer l&#8217;ensemble des ressources par type comme il est fait dans ce tutorial</em>.</p>
<p>Toutes les ressources sont maintenant prêtes. Nous pouvons modifier l&#8217;interface graphique. Double-cliquez sur <em>main.xml</em>. L&#8217;éditeur de &#8220;layout&#8221; s&#8217;affiche. Il vous est possible de créer l&#8217;interface en mode graphique ou en tapant simplement le fichier XML à la main. Pour basculer entre les modes, utilisez les onglets en bas de la fenêtre. L&#8217;interface graphique étant assez facile d&#8217;utilisation, nous allons directement taper le code XML. Notre objectif est d&#8217;afficher l&#8217;image de la mascotte Android avec un &#8220;Hello World&#8221; en dessous. Le tout sera également centré quelque soit le type d&#8217;écran ou l&#8217;orientation utilisé. Le code ci-dessous représente l&#8217;interface graphique voulue :</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>
<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;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:layout_gravity</span>=<span style="color: #ff0000;">&quot;center_vertical|center_horizontal&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: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;imageView</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:layout_gravity</span>=<span style="color: #ff0000;">&quot;center_horizontal&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:src</span>=<span style="color: #ff0000;">&quot;@drawable/tex&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;textView</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:layout_gravity</span>=<span style="color: #ff0000;">&quot;center_horizontal&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/hello&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;@color/white&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:textSize</span>=<span style="color: #ff0000;">&quot;@dimen/dim_hello&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>

<p>De façon globale, l&#8217;interface graphique précédente dispose d&#8217;un unique élément <code>LinearLayout</code> à la racine englobant deux autres éléments <code>ImageView</code> et <code>TextView</code>. Etudions maintenant plus en détail l&#8217;utilité de ses éléments et surtout leurs attributs. Lorsqu&#8217;on créé une interface graphique, on souhaite &#8220;ranger&#8221; les composants graphiques afin que ces derniers s&#8217;affiche à l&#8217;écran. Parmi les possibilités les plus courantes, on trouve :</p>
<ul>
<li><code>RelativeLayout</code> qui laisse les éléments fils se positionner par rapport au parent (positionnement relatif).</li>
<li><code>AbsoluteLayout</code> qui permet aux éléments fils de se positionner de façon exacte par rapport au parent. Un élément fils définit alors une coordonnée exacte.</li>
<li><code>FrameLayout</code> est un élément très basique qui oblige l&#8217;ensemble de ces enfants à se placer au coin supérieur gauche.</li>
<li><code>LinearLayout</code> aligne l&#8217;ensemble de ses enfants dans une direction unique : horizontale ou verticale. Les éléments sont ensuite empilés les uns aprés les autres. Ce genre de layout n&#8217;affiche donc qu&#8217;un seul élément par ligne ou colonne (cela dépend de l&#8217;orientation choisie)</li>
</ul>
<p>Dans notre cas, on souhaite afficher les éléments les uns au dessous des autres. On utilise donc un <code>LinearLayout</code>. Les attributs de l&#8217;élément sont ensuite les suivants :</p>
<ul>
<li><code>xmlns:android="http://schemas.android.com/apk/res/android"</code> définit le namespace android. Cette ligne doit obligatoirement être ajoutée à l&#8217;élément racine</li>
<li><code>android:layout_width="wrap_content"</code> indique à l&#8217;élément que sa largeur doit s&#8217;adapter au contenu. Les autres valeurs possibles sont &#8220;fill_parent&#8221; qui indique que l&#8217;élément va s&#8217;agrandir pour remplir totalement son parent. Il est également possible d&#8217;utiliser une dimension pour obtenir une taille fixe</li>
<li><code>android:layout_height="wrap_content"</code> indique, à l&#8217;instar du précédent que la hauteur doit s&#8217;adapter au contenu. Cet attribut est, comme le précédent, obligatoire pour l&#8217;ensemble des éléments graphiques car il permet au système de connaitre avec exactitude la place prise par l&#8217;élément à l&#8217;écran</li>
<li><code>android:layout_gravity="center_vertical|center_horizontal"</code> oblige l&#8217;élément à se centrer de façon verticale et horizontale dans son parent</li>
<li><code>android:orientation="vertical"</code></li>
<p>permet d&#8217;orienter le layout de façon verticale. Les éléments seront empilés les un au dessous des autres</ul>
<p>On insère ensuite dans le layout l&#8217;image. Cette dernière est incluse grâce à la vue <code>ImageView</code> à laquelle on assigne, grâce à l&#8217;attribut <code>android:src</code>, l&#8217;image de la mascotte. Cette image a pour nom original &#8220;tex.png&#8221; et se trouve dans le dossier <em>drawable</em>. Pour l&#8217;inclure on utilise donc la syntaxe <code>@drawable/</code> suivi de son nom sans l&#8217;extension.  L&#8217;inclusion d&#8217;une zone de texte suit la même logique. On utilise une <code>TextView</code> à laquelle on associe les différentes valeurs préparées en début de partie. La valeur <code>android:text</code> se trouve dans le fichier <em>strings.xml</em>, on y accède donc par <code>@string/hello</code>.De la même façon, on accède à la couleur par <code>@color/white</code> et à la dimension par <code>@dimen/dim_hello</code>.  Notre interface graphique est maintenant terminée. Il nous reste à l&#8217;utiliser dans notre code Java. Il suffit de se rendre dans HelloWorld.java. Ce fichier contient 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.cyrilmottier.android.helloworld</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>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</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> HelloWorld <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
&nbsp;
    @Override
&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>
&nbsp;
        <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>
&nbsp;
        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: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On ne peut pas faire plus simple ! HelloWorld hérite bien d&#8217;<code>Activity</code> et c&#8217;est ce que nous souhaitons puisque, comme expliqué dans la <a title="Tutoriel : Les composants principaux d’Android" href="http://www.pointgphone.com/tutoriel-composants-android-2238" target="_self">partie 2</a>, une activité permet d&#8217;afficher une interface graphique à l&#8217;utilisateur. La mise en place de notre interface graphique s&#8217;effectue simplement en redéfinissant la méthode <code>onCreate</code>. On applique simplement la vue créée à l&#8217;aide de <code>setContentView(int)</code>. L&#8217;entier passé à cette méthode est la référence de notre layout. C&#8217;est ici qu&#8217;on utilise le fichier automatiquement géré <em>R.java</em>. Si vous n&#8217;avez pas changé le nom du fichier de votre interface graphique, il devrait être référencé par <code>R.layout.main</code>.</p>
<p>Nous y voilà ! Notre &#8220;Hello World&#8221; est prêt ! Cela peut sembler incroyable puisque nous n&#8217;avons presque pas écrit de code Java. C&#8217;est là que se trouve une des puissances d&#8217;Android : l&#8217;instanciation d&#8217;objets par XML. Nous avons créé ici une interface graphique mais d&#8217;autres objets non graphiques sont également instanciables via XML. Vous pouvez maintenant lancer votre premier programme sur l&#8217;émulateur et contempler le résultat :</p>
<p style="text-align: center;"><img class="size-full wp-image-2321 aligncenter" title="hello-android" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/hello-android.png" alt="hello-android" width="320" height="480" /></p>
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/android-sdk-21-disponible-10426" title="Android SDK 2.1 disponible !">Android SDK 2.1 disponible !</a></li>
<li><a href="http://www.pointgphone.com/nouvelle-mise-a-jour-sdk-android-9585" title="Nouvelle mise à jour pour le SDK Android">Nouvelle mise à jour pour le SDK Android</a></li>
<li><a href="http://www.pointgphone.com/android-sdk-2-0-dispo-8768" title="L&#8217;Android SDK 2.0 est dispo !">L&#8217;Android SDK 2.0 est dispo !</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-android-introduction-intents-7779" title="Tutoriel Android : Introduction aux Intents">Tutoriel Android : Introduction aux Intents</a></li>
<li><a href="http://www.pointgphone.com/donut-sdk-android-16-disponible-telechargement-7629" title="Donut arrive ! SDK Android 1.6 disponible au téléchargement">Donut arrive ! SDK Android 1.6 disponible au téléchargement</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/tutoriel-android-hello-world-2301">Tutoriel Android : &quot;Hello World&quot; version 1.5</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/tutoriel-android-hello-world-2301/feed</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
		<item>
		<title>Tutoriel : Développer un widget Android</title>
		<link>http://www.pointgphone.com/tutoriel-widget-android-2337</link>
		<comments>http://www.pointgphone.com/tutoriel-widget-android-2337#comments</comments>
		<pubDate>Wed, 22 Apr 2009 05:00:28 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[AppWidget]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[tutoriel]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[Wiktionary]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2337</guid>
		<description><![CDATA[Une des nouveautés de la version 1.5 du SDK Android est le framework AppWidget permettant de créer facilement des widgets, ces petits composants (comme l&#8217;horloge) à placer sur le bureau Android. Ça vous tente? Google vous propose un petit tuto !

Google vient de publier un tutoriel, expliquant comment créer un widget simple pour Android, affichant le mot du [...]]]></description>
			<content:encoded><![CDATA[<p>Une des nouveautés de la <a title="Android Cupcake : Premier aperçu du SDK" href="http://www.pointgphone.com/android-cupcake-sdk-2263" target="_self">version 1.5 du SDK Android</a> est le framework AppWidget permettant de créer facilement des widgets, ces petits composants (comme l&#8217;horloge) à placer sur le bureau Android. Ça vous tente? Google vous propose un petit tuto !</p>
<p style="text-align: center;"><span id="more-2337"></span><img class="size-full wp-image-2338 aligncenter" title="android-widget" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/android-widget.png" alt="android-widget" width="214" height="320" /></p>
<p><strong>Google</strong> vient de <a title="Introducing home screen widgets and the AppWidget framework" href="http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html" target="_self">publier un tutorie</a>l, expliquant comment créer un widget simple pour Android, affichant le mot du jour de <strong>Wiktionary</strong>.</p>
<p>C&#8217;est simple et bien expliqué, alors si le développement de <strong>widgets Android</strong> vous attire, foncez !</p>
<p>D&#8217;ailleurs, c&#8217;est un sujet très intéressant, et je reviendrais dessus dans un tutoriel maison très prochainement.<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/tutoriel-skin-emulateur-android-428" title="Tutoriel : Changer la skin de l&#039;émulateur Android">Tutoriel : Changer la skin de l&#039;émulateur Android</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-installation-sdk-android-51" title="Tutoriel : Installation du SDK Android">Tutoriel : Installation du SDK Android</a></li>
<li><a href="http://www.pointgphone.com/android-sdk-21-disponible-10426" title="Android SDK 2.1 disponible !">Android SDK 2.1 disponible !</a></li>
<li><a href="http://www.pointgphone.com/nouvelle-mise-a-jour-sdk-android-9585" title="Nouvelle mise à jour pour le SDK Android">Nouvelle mise à jour pour le SDK Android</a></li>
<li><a href="http://www.pointgphone.com/android-sdk-2-0-dispo-8768" title="L&#8217;Android SDK 2.0 est dispo !">L&#8217;Android SDK 2.0 est dispo !</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/tutoriel-widget-android-2337">Tutoriel : Développer un widget Android</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/tutoriel-widget-android-2337/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tutoriel : Les composants principaux d&#039;Android</title>
		<link>http://www.pointgphone.com/tutoriel-composants-android-2238</link>
		<comments>http://www.pointgphone.com/tutoriel-composants-android-2238#comments</comments>
		<pubDate>Tue, 14 Apr 2009 03:00:03 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Activity]]></category>
		<category><![CDATA[BroadcastReceiver]]></category>
		<category><![CDATA[ContentProvider]]></category>
		<category><![CDATA[Cyril Mottier]]></category>
		<category><![CDATA[intent]]></category>
		<category><![CDATA[Service]]></category>
		<category><![CDATA[View]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2238</guid>
		<description><![CDATA[Vous avez été nombreux à consulter le premier tutoriel de Cyril Mottier sur l&#8217;arborescence d&#8217;un projet Android. On continue avec un nouveaux tutoriel qui va vous présenter les composants principaux d&#8217;une applications Android.


Lorsque l&#8217;on aborde une nouvelle technologie, on souhaite d&#8217;emblée réaliser un premier projet. Etant passé maintes fois par cette étape, je comprend votre [...]]]></description>
			<content:encoded><![CDATA[<p>Vous avez été nombreux à consulter le premier tutoriel de Cyril Mottier sur l&#8217;<a title="Tutoriel : L’arborescence d’un projet Android" href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054" target="_self">arborescence d&#8217;un projet Android</a>. On continue avec un nouveaux tutoriel qui va vous présenter les composants principaux d&#8217;une applications Android.</p>
<p><span id="more-2238"></span></p>
<p style="text-align: center;"><img class="size-full wp-image-2240 aligncenter" title="android-activity" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/android-activity.png" alt="android-activity" width="300" height="412" /></p>
<p>Lorsque l&#8217;on aborde une nouvelle technologie, on souhaite d&#8217;emblée réaliser un premier projet. Etant passé maintes fois par cette étape, je comprend votre engouement à réaliser votre première application Android. Malheureusement, avant d&#8217;effectuer un premier et traditionnel &#8220;Hello World&#8221;, il me semblait plus utile d&#8217;introduire les composants principaux d&#8217;Android. Je tiens tout de même à rassurer ceux qui souhaiterait décrocher maintenant : nous allons attaquer le vif du sujet avec le développement d&#8217;une première application dans la prochaine partie de cette série de tutoriaux !</p>
<p>Le développement sur Android s&#8217;appuie sur des classes importantes du framework. Ces classes sont, en quelque sorte, les &#8220;briques&#8221; élémentaires sur lesquelles vos futures applications reposeront. Elles sont tellement indispensables qu&#8217;il est tout simplement impossible de contruire votre application sans passer par au moins l&#8217;une d&#8217;elles. Cette partie tente de décrire de façon globale et succincte ces différentes &#8220;briques&#8221;.</p>
<h2>Intent</h2>
<p>Les <code>Intents</code> sont des objets permettant de faire passer des messages contenant de l&#8217;information entre composants principaux. La notion d&#8217;<code>Intent</code> peut être vue comme une demande de démarrage d&#8217;un autre composant, d&#8217;une action à effectuer. La raison d&#8217;être des <code>Intent</code>s provient du modèle de sécurité d&#8217;Android. Chaque application est en effet <em>sandboxée</em>. Cela veut dire qu&#8217;une application A ne peut accéder aux données d&#8217;une application B. Grâce aux <code>Intent</code>s, les applications ont la possibilité de fournir leurs services ou données si elles le souhaite.</p>
<h2>View</h2>
<p>Les <code>View</code>s sont les composants de base de l&#8217;interface graphique. Elles permettent de construire l&#8217;interface utilisateur. Les <em>widgets</em> (nom donné à des composants graphiques &#8220;avancés&#8221; : une barre de progression, par exemple, est un widget), composants graphiques ou autres <em>layout</em> (composant permettant de placer les différents composants graphiques à l&#8217;écran) héritent en fait de cette classe élémentaire. Le rendu/dessin d&#8217;une <code>View</code> s&#8217;effectue par l&#8217;intermédiaire d&#8217;un <code>Canvas</code> (qu&#8217;on peut assimiler à une feuille transparente sur laquelle on dessine avec un crayon (<code>Paint</code>). Pour finir, la vue est le principal composant qui s&#8217;occupe de gérer les actions utilisateurs (appui sur l&#8217;écran, sur le clavier, etc.).</p>
<p>Lorsqu&#8217;on créé une application à l&#8217;aide du framework Android, le développeur doit hériter d&#8217;au moins une des 4 classes brièvement décrites ci-dessous. Ces notions de composants applicatifs vous sembleront, j&#8217;en suis sûr, totalement déroutantes au premier abord. Gardez à l&#8217;esprit que vos développements et les différentes parties de ce tutorial, vous permettront de clarifier vos idées.</p>
<h2>Activity</h2>
<p>le concept d&#8217;<code>Activity</code> repose sur la notion d&#8217;interaction utilisateur. Une <code>Activity</code> représente la fenêtre ou tout simplement l&#8217;écran qui sera affiché à l&#8217;utilisateur. Elle permet également de gérer des fonctionnalités telles que l&#8217;appui sur la touche [MENU] ou l&#8217;affichage de messages d&#8217;alerte (<code>Toast</code>). Faites bien attention à ne pas confondre la notion d&#8217;<code>Activity</code> et de <code>View</code>. Il est évident que faire la différence entre ces deux notions est difficile à ce stade de compréhension du framework. Rappelez vous que vos premières réalisations vous permettront de dissocier les deux : Soyez patient!</p>
<h2>Service</h2>
<p>La notion de service est un avantage certain sur l&#8217;iPhone. En effet, un <code>Service</code> est en fait un programme tournant en tâche de fond et n&#8217;ayant pas d&#8217;interface graphique (ce qui n&#8217;est pas réalisable, à l&#8217;heure où j&#8217;écris ces lignes, sur iPhone OS). L&#8217;exemple commun illustrant au mieux cette notion est celui du lecteur mp3. Un lecteur mp3 ne nécessite pas, pour la plupart du temps, d&#8217;interface graphique et doit tourner en tâche de fond laissant la possibilité aux autres applications de travailler/s&#8217;exécuter librement.</p>
<h2>ContentProvider</h2>
<p>Les <code>ContentProvider</code> sont, comme l&#8217;exprime leurs noms, des gestionnaires de données. Ils permettent de partager l&#8217;information entre applications. Imaginons une application qui permette de conserver les cartes de visite virtuelles d&#8217;un ensemble de personnes. Ces cartes de visite contiennent généralement le nom, le prénom et un moyen de contact de la personne. Un tel programme peut être créé sous forme de <code>ContentProvider</code> ce qui lui permettra de fournir à d&#8217;autres applications présentes sur le système les informations sur une personne. Une application tierce d&#8217;envoi de courriel peut par exemple interroger ce <code>ContentProvider</code> afin d&#8217;obtenir l&#8217;adresse courriel d&#8217;un contact.</p>
<h2>BroadcastReceiver</h2>
<p>Pour finir, un <code>BroadcastReceiver</code> est une application qui est à &#8220;l&#8217;écoute&#8221; des autres applications. Ce type d&#8217;application tente de répondre aux<code>Intents</code> qui lui sont adressés. Il ne fait donc rien d&#8217;autres que d&#8217;être à l&#8217;écoute des <code>Intents</code> envoyés par d&#8217;autres composants applicatifs.</p>
<h2>Conclusion</h2>
<p>Vous connaissez maintenant les différents éléments utilisés dans une application Android. Si vous voulez des détails sur certains points ou si vous avez des questions, n&#8217;hésites pas à les poser dans les commentaires.<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/tutoriel-android-introduction-intents-7779" title="Tutoriel Android : Introduction aux Intents">Tutoriel Android : Introduction aux Intents</a></li>
<li><a href="http://www.pointgphone.com/exemples-applications-android-google-574" title="Des exemples d&#039;applications Android par Google">Des exemples d&#039;applications Android par Google</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054" title="Tutoriel : Arborescence d&#039;un projet Android">Tutoriel : Arborescence d&#039;un projet Android</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/tutoriel-composants-android-2238">Tutoriel : Les composants principaux d&#039;Android</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/tutoriel-composants-android-2238/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Améliorer l&#039;autonomie de votre smartphone Android</title>
		<link>http://www.pointgphone.com/ameliorer-autonomie-smartphone-android-2137</link>
		<comments>http://www.pointgphone.com/ameliorer-autonomie-smartphone-android-2137#comments</comments>
		<pubDate>Mon, 06 Apr 2009 23:54:06 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[Android Market]]></category>
		<category><![CDATA[autonomie]]></category>
		<category><![CDATA[batterie]]></category>
		<category><![CDATA[Cupcake]]></category>
		<category><![CDATA[EDGE]]></category>
		<category><![CDATA[Locale]]></category>
		<category><![CDATA[Power Manager]]></category>
		<category><![CDATA[Wi-Fi]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2137</guid>
		<description><![CDATA[Un des défauts principaux du G1 ou HTC Dream (mais c&#8217;est le cas pour la majorité des smartphones de nouvelle génération) est sa faible autonomie, mais avec quelques astuces simples, vous allez pouvoir prolonger de manière efficace la durée d&#8217;utilisation de votre appareil.


Les différents mode de connexion réseau
Il est important de bien connaître les différents [...]]]></description>
			<content:encoded><![CDATA[<p>Un des défauts principaux du G1 ou <a href="http://www.pointgphone.com/htc-dream" title="HTC Dream" >HTC Dream</a> (mais c&#8217;est le cas pour la majorité des smartphones de nouvelle génération) est sa faible autonomie, mais avec quelques astuces simples, vous allez pouvoir prolonger de manière efficace la durée d&#8217;utilisation de votre appareil.</p>
<p><span id="more-2137"></span></p>
<p style="text-align: center;"><img class="size-full wp-image-2143 aligncenter" title="power-manager-android" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/power-manager-android.jpg" alt="power-manager-android" width="140" height="210" /></p>
<p><span style="text-decoration: underline;">Les différents mode de connexion réseau</span></p>
<p>Il est important de bien connaître les différents modes de connexion internet de votre téléphone et leur consommation d&#8217;énergie, pour savoir quel mode utiliser dans quel situation et ainsi optimiser l&#8217;autonomie.</p>
<p>Le <strong>HTC Dream</strong> peut se connecter à internet grâce à 3 modes de connexion, qui ont chacun leurs avantages et leurs inconvénients :</p>
<ul>
<li><strong>Wi-Fi</strong> : Le mode de connexion de plus rapide mais aussi le plus gourmand ! A utiliser de préférence quand une prise de courant est à portée, ce qui est généralement le cas quand on est à proximité d&#8217;un réseau Wi-Fi.</li>
<li><strong>3G</strong> : Le mode de connexion principal de votre G1, à condition d&#8217;être dans une zone couverte. La 3G consomme bien évidemment plus d&#8217;énergie que la 2G, mais c&#8217;est le meilleur rapport confort d&#8217;utilisation/consommation.</li>
<li><strong>2G ou EDGE</strong> : Le <strong>EDGE</strong>, c&#8217;est lent, mais c&#8217;est aussi le mode de connexion qui consomme le moins et qui vous permettra d&#8217;économiser votre batterie au maximum. A n&#8217;utiliser que si votre téléphone est presque à plat ou si vous êtes dans un zone où la 3G est absente.</li>
</ul>
<p>Bien gérer votre mode de connexion vous permettra de prolonger la durée d&#8217;utilisation de votre <strong>G1</strong>. Laborieux? Heureusement, il existe des applications pour vous simplifier la tâche.</p>
<p><span style="text-decoration: underline;">Power Manager : Une application intelligente pour gérer la batterie votre G1</span></p>
<p style="text-align: center;"><img class="size-full wp-image-2145 aligncenter" title="power-manager" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/power-manager.png" alt="power-manager" width="90" height="60" /></p>
<p>Il existe un certain nombre d&#8217;applications vous permettant de gérer les différents éléments de votre HTC Dream, mais la plus populaire est sans conteste <a title="Power Manager: Intelligent Device Management" href="http://www.android.com/market/free-tools.html#app=powermanager" target="_self">Power Manager</a>, disponible sur l&#8217;<strong>Android Market</strong>.</p>
<p>Cette application vous permettra d&#8217;activer ou désactiver les différents éléments de votre <strong>G1</strong> en fonction du taux de charge de la batterie.</p>
<p>Par exemple, vous pouvez faire en sorte que le <strong>GPS</strong> ou le <strong>BlueTooth</strong> se désactivent automatiquement quand la batterie passe sous les 30% de charge.</p>
<p>Il est également possible de régler la luminosité de l&#8217;écran (à mettre au plus bas pour économiser la batterie), la durée pendant laquelle l&#8217;écran reste allumé, désactiver la synchronisation des données, etc.</p>
<p>Vous pouvez également régler tous ces paramètres à la main en un seul clic ! <img src='http://www.pointgphone.com/wordpress/wp-includes/images/smilies/icon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p><strong>Power Manager</strong> est une application très complète, qui bien paramétrée, vous permettra d&#8217;allonger efficacement la durée de vie de votre batterie.</p>
<p>Dans un registre similaire, il y a aussi <a title="Locale" href="http://www.androidlocale.com/index.html" target="_blank">Locale</a> (application gagnante de l&#8217;<strong>Android Developer Challenge</strong>), qui vous permettra de définir des réglages selon votre localisation <strong>GPS</strong>.</p>
<p>Vous avez réglé votre HTC Dream dans les moindres détails et pourtant votre batterie se décharge encore trop vite à votre goût? Une seule solution : les accessoires !</p>
<p><span style="text-decoration: underline;">Les accessoires</span></p>
<p style="text-align: center;"><img class="size-full wp-image-2146 aligncenter" title="chargeur-g1" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/chargeur-g1.jpg" alt="chargeur-g1" width="280" height="280" /></p>
<p>Le <strong>G1</strong> est sorti il y a seulement quelques mois mais il existe déjà toute une série d&#8217;accessoires pour accompagner votre appareil. Pour le sujet qui nous intéresse à savoir l&#8217;autonomie, il existe notamment des batteries de plus grande capacité, des chargeurs externes bien plus rapides que le chargeur USB ou encore des chargeurs de voiture. Je vous proposerais d&#8217;ailleurs une sélection d&#8217;accessoires dans un prochain article.</p>
<p>Vous avez essayé certains accessoires pour améliorer l&#8217;autonomie de votre HTC Dream? Quels sont les résultats?</p>
<p><span style="text-decoration: underline;">Conclusion</span></p>
<p>En respectant ces quelques conseils et en investissant éventuellement dans une batterie de plus grand capacité, vous pourrez améliorer grandement l&#8217;autonomie de votre HTC Dream (et ils sont bien évidemment valables pour les futurs smartphones Android) et vous aurez besoin de le recharger beaucoup moins souvent.</p>
<p>Et vous, combien de temps dure la batterie de votre <strong>G1</strong> ou HTC Dream? Avec quelle utilisation?</p>
<p>Si vous avez d&#8217;autres astuces pour prolonger la durée de vie de votre batterie, n&#8217;hésitez pas à les partager dans les commentaires. J&#8217;éditerais le post avec vos suggestions.</p>
<p>A noter que <strong>Cupcake</strong>, la prochaine version d&#8217;<strong>Android</strong>, améliorera la gestion de l&#8217;énergie.</p>
<p>PS : Cet article, bien que loin d&#8217;être une traduction littérale, est clairement inspiré de <a title="G1 Power Management: How to Get More Time From Your Friendly Android" href="http://www.androidandme.com/2009/04/reviews/g1-power-management-how-to-get-more-time-from-your-friendly-android/" target="_blank">ce post</a> de l&#8217;excellent <a title="Android and Me" href="http://www.androidandme.com/" target="_self">Android and Me</a>. Ca faisait longtemps que l&#8217;idée d&#8217;un post sur le sujet me trottait dans la tête mais l&#8217;article en question est complet et je ne voyais pas l&#8217;intérêt de réinventer complètement la roue.<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/statistiques-utilisation-g1-tmobile-2100" title="Statistiques d&#039;utilisation du G1 par T-Mobile">Statistiques d&#039;utilisation du G1 par T-Mobile</a></li>
<li><a href="http://www.pointgphone.com/google-recompense-meilleurs-developpeurs-android-11126" title="Google récompense les meilleurs développeurs Android">Google récompense les meilleurs développeurs Android</a></li>
<li><a href="http://www.pointgphone.com/android-market-success-story-11121" title="Android Market : Une success story à 13 000 dollars par mois">Android Market : Une success story à 13 000 dollars par mois</a></li>
<li><a href="http://www.pointgphone.com/android-market-mise-en-avant-applications-11069" title="Android Market : Nouvelle mise en avant des applications">Android Market : Nouvelle mise en avant des applications</a></li>
<li><a href="http://www.pointgphone.com/quoi-de-neuf-android-market-la-conjugaison-freebox-mobile-newsroom-10202" title="Quoi de neuf sur l&#8217;Android Market? La Conjugaison, Freebox Mobile, NewsRoom&#8230;">Quoi de neuf sur l&#8217;Android Market? La Conjugaison, Freebox Mobile, NewsRoom&#8230;</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/ameliorer-autonomie-smartphone-android-2137">Améliorer l&#039;autonomie de votre smartphone Android</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/ameliorer-autonomie-smartphone-android-2137/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Tutoriel : Arborescence d&#039;un projet Android</title>
		<link>http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054</link>
		<comments>http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054#comments</comments>
		<pubDate>Fri, 03 Apr 2009 15:10:36 +0000</pubDate>
		<dc:creator>Cyril Mottier</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[arboresence]]></category>
		<category><![CDATA[Cyril Mottier]]></category>
		<category><![CDATA[INSA]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=2054</guid>
		<description><![CDATA[L&#8217;arrivée d&#8217;Android en France vous a donné envie de vous lancer dans le développement d&#8217;applications Android? Ca tombe bien, Cyril Mottier, élève ingénieur à l&#8217;INSA de Rennes, vous propose une série de tutoriaux pour apprendre les bases du développement sous Android. On commence avec l&#8217;arborescence d&#8217;un projet Android !

La programmation sur Android commence tout d&#8217;abord [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;arrivée d&#8217;Android en France vous a donné envie de vous lancer dans le développement d&#8217;applications Android? Ca tombe bien, Cyril Mottier, élève ingénieur à l&#8217;INSA de Rennes, vous propose une série de tutoriaux pour apprendre les bases du développement sous Android. On commence avec l&#8217;arborescence d&#8217;un projet Android !</p>
<p><span id="more-2054"></span></p>
<p>La programmation sur Android commence tout d&#8217;abord par l&#8217;installation du SDK Android fourni par Google sur <a href="http://developer.android.com/sdk/">le site des officiels des développeurs</a>. La rédaction d&#8217;une suite de tutoriaux sur le développement sur Android devrait tout naturellement contenir une partie introductive expliquant cette étape. Néanmoins, je n&#8217;ai pas souhaité inclure cette partie car elle est facilement réalisable et la documentation déjà existante est déja suffisante :</p>
<ul>
<li><a href="http://developer.android.com/sdk/">http://developer.android.com/sdk/</a> : Site officiel des développeurs Android (en anglais)</li>
<li><a href="http://www.pointgphone.com/tutoriel-installation-sdk-android-51">http://www.pointgphone.com/tutoriel-installation-sdk-android-51</a> : Un tutoriel qui date un peu sur PointGPhone mais qui reste d&#8217;actualité vu les changements quasi inexistants sur la procédure d&#8217;installation.</li>
<li><a href="http://android.cyrilmottier.com/?p=3">http://android.cyrilmottier.com/?p=3</a> : Article récent sur mon blog personnel.</li>
</ul>
<p>Comme le mentionne le titre de cette partie, l&#8217;objectif de ce tutorial est de se familiariser avec l&#8217;arborescence type d&#8217;un projet Android. Nous étudierons donc les différents packages et dossiers qui sont automatiquement créé par le plugin ADT (Android Development Tool). Pour ce faire, créons tout d&#8217;abord un premier projet avec l&#8217;EDI Eclipse. Lorsque vous faites <strong>File&gt;New&gt;Other&gt;Android Project</strong>, une boite de dialogue comme représentée ci-dessous s&#8217;ouvre :</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-2059" title="projet-android" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/projet-android.png" alt="projet-android" width="400" height="355" /></p>
<p>Cette boite de dialogue demande en réalité d&#8217;entrer plusieurs informations sur le projet :</p>
<ul>
<li><strong>Project Name</strong> : Ce nom de projet est totalement indépendant de votre application Android. Ce n&#8217;est en fait que le nom donné à votre projet dans Eclipse (nom donné au dossier dans votre workspace).</li>
<li><strong>Package Name</strong> : Nom du package principal de l&#8217;application. Le nom du package suit, en général, la règle suivante : <code><em>extension_de_votre_domaine</em>.<em>nom_du_domaine</em>.android.<em>nom_du_projet</em></code> (par exemple : <code>com.cyrilmottier.android.tutorial</code>). Le package définira en fait le nom interne de votre application sur le terminal Android.</li>
<li><strong>Activity Name</strong> : C&#8217;est le nom de l&#8217;activité qui débutera au lancement de votre application. Dans une future partie, j&#8217;expliquerai le concept d&#8217;activité mais pour l&#8217;instant nous pouvons simplement considérer qu&#8217;une activité est la couche de présentation de votre application (concept d&#8217;écran). Ce nom d&#8217;activité sera automatiquement ajouté à votre <strong>AndroidManifest.xm</strong>l (fichier qui décrit votre application au système Android et qui sera expliqué plus en détail dans la suite de ce tutorial)</li>
<li>Application Name : Pour finir vous devez entrer le nom de votre application. Cette chaine de caractère sera également inscrite dans AndroidManifest.xml et sera en fait utilisée par le système lors de l&#8217;affichage des applications dans l&#8217;écran d&#8217;accueil. C&#8217;est en réalité le nom de l&#8217;application affichée sous l&#8217;icône de l&#8217;application (nom utilisateur).</li>
</ul>
<p><em>Note : Il n&#8217;y a aucune règle régissant et reliant les différents noms donnés ci-dessus. Vous pouvez en effet avec un package <code>com.cyrilmottier.android.aviation</code>, un nom d&#8217;<code>Activity</code> <code>MonChien</code> et un nom d&#8217;application &#8220;Cuisinez !&#8221;. On remarquera néanmoins, que dans l&#8217;exemple précédent, malgré un choix fantaisique poussé à l&#8217;extrême des noms, la compréhension du projet n&#8217;est absolument pas facilitée.</em></p>
<p>Après avoir validé la boite de dialogue précédente en cliquant sur &#8220;Finish&#8221;, nous nous retrouvons maintenant en présence d&#8217;un projet type Android. Ce projet suit une arborescence bien précise qui ressemble à celle représentée ci-dessous :</p>
<p style="text-align: center;"><img class="size-full wp-image-2060 aligncenter" title="arborescence-android" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/04/arborescence-android.png" alt="arborescence-android" width="235" height="276" /></p>
<p>Comme à l&#8217;accoutumée, Android ne déroge pas à la régle et insère donc les différents packages dans le dossier <code>src</code>. C&#8217;est dans ce dossier que l&#8217;ensemble des fichiers de code (.java) doivent se trouver. Il est bien sûr possible de créer de nouveaux packages comme les développeurs Java ont l&#8217;habitude de le faire. Analysons maintenant le contenu du package <code>com.cyrilmottier.android.tutorial</code>. On y retrouve tout d&#8217;abord un fichier <code>PartOne.java</code> qui n&#8217;est autre que l&#8217;activité (<code>Activity</code>) principale de l&#8217;application. Un simple coup d&#8217;oeil au code contenu dans le fichier montre que <code>PartOne</code> hérite bien d&#8217;<code>Activity</code> :</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.cyrilmottier.android.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.os.Bundle</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> PartOne <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>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>En dessous du dossier <code>src</code>, on retrouve un fichier <strong>android.jar</strong>. C&#8217;est tout simplement ce jar qui contient l&#8217;ensemble du framework Android. Sans ce dernier, notre projet Android serait tout simplement une coquille vide.</p>
<p>On retrouve ensuite dans le package par défaut le fameux <code>R.java</code>. Ce fichier est automatiquement géré par ADT et n&#8217;est donc pas modifiable par l&#8217;utilisateur. Ce fichier contient en fait l&#8217;ensemble des références vers les ressources de votre projet. Imaginons par exemple que nous souhaitions utiliser une image (<code>Drawable</code> dans le langage Android), on y accèdera par <code>R.drawable.nom_de_l_image</code>.</p>
<p>Au même niveau que le dossier src, on retrouve un dossier nommé <code>assets</code> et qui contient simplement des données qui seront chargées sur le mobile lors de la compilation de votre projet. Les données inclues dans ce dossier ne sont normalement pas en accord avec l&#8217;arborescence classique d&#8217;un projet Android : cela peut, par exemple, être des fichiers texte décrivant la license de votre application, des fichiers audio ou vidéo, etc.</p>
<p>Un projet Android contient enfin un dossier <code>res</code> qui regroupe l&#8217;ensemble des ressources relatives au projet. C&#8217;est ce dossier qui est &#8220;lu&#8221; par ADT pour créer le fameux <code>R.java</code>. Ce dossier contient lui même des sous dossiers regroupant les ressources selon leur type. A la création d&#8217;un projet Android, les sous-dossiers créés sont :</p>
<ul>
<li><strong>drawable</strong> : regroupera l&#8217;ensemble de vos images (png, jpg, gif), <code>Drawable</code>s, etc. On pourrait traduire ce dossier par l&#8217;expression (pas vraiment française) &#8220;dessinable&#8221;.</li>
<li><strong>layout</strong> : le framework Android a l&#8217;avantage d&#8217;offrir une technique de création d&#8217;interfaces graphiques à l&#8217;aide de fichiers XML (on étudiera dans de futures parties que le concept a même été porté à l&#8217;extrême et qu&#8217;un grand nombre de classes peuvent être instanciées par XML) . C&#8217;est dans ce dossier que vous incluerez l&#8217;ensemble des fichiers décrivant vos interfaces.</li>
<li><strong>values</strong> : ce dossier contient également un ensemble de fichiers décrivant les valeurs utilisées par votre application. On peut, par exemple, y mettre des chaines de caractères (strings.xml), des tableaux (arrays.xml), des couleurs, des dimensions, etc&#8230;</li>
</ul>
<p>Pour finir, tout projet Android contient un fichier nommé <strong>AndroidManifest.xml</strong> qui définit le comportement de votre application au système Android. Ce fichier définit par exemple, le nom, l&#8217;icone (par défaut <code>drawable/icon.png</code>), le thème, la version minimale du système nécessaire à l&#8217;exécution de l&#8217;application, les activités, les services, etc. de votre application.<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/tutoriel-android-introduction-intents-7779" title="Tutoriel Android : Introduction aux Intents">Tutoriel Android : Introduction aux Intents</a></li>
<li><a href="http://www.pointgphone.com/tutoriel-composants-android-2238" title="Tutoriel : Les composants principaux d&#039;Android">Tutoriel : Les composants principaux d&#039;Android</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054">Tutoriel : Arborescence d&#039;un projet Android</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/tutoriel-arborescence-projet-android-2054/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>HTC Dream : Passer en mode root</title>
		<link>http://www.pointgphone.com/htc-dream-root-1803</link>
		<comments>http://www.pointgphone.com/htc-dream-root-1803#comments</comments>
		<pubDate>Sun, 22 Mar 2009 18:17:15 +0000</pubDate>
		<dc:creator>Point GPhone</dc:creator>
				<category><![CDATA[Tutoriaux Android]]></category>
		<category><![CDATA[HTC Dream]]></category>
		<category><![CDATA[root]]></category>

		<guid isPermaLink="false">http://www.pointgphone.com/?p=1803</guid>
		<description><![CDATA[Vous êtes frustrés par les limitations de votre HTC Dream Orange? Passez en mode root ! Attention toutefois, manipulation à vos risques et périls&#8230;


Passer en mode root ou &#8220;rooter&#8221; votre HTC Dream est une manipulation qui vous permettra d&#8217;avoir un contrôle total sur votre appareil, et vous permettra par exemple de pouvoir installer des applications [...]]]></description>
			<content:encoded><![CDATA[<p>Vous êtes frustrés par les limitations de votre <a href="http://www.pointgphone.com/htc-dream" title="HTC Dream" >HTC Dream</a> Orange? Passez en mode root ! Attention toutefois, manipulation à vos risques et périls&#8230;</p>
<p><span id="more-1803"></span></p>
<p style="text-align: center;"><img class="size-full wp-image-1806 aligncenter" title="htc-dream-root" src="http://www.pointgphone.com/wordpress/wp-content/uploads/2009/03/htc-dream-root.jpg" alt="htc-dream-root" width="340" height="500" /></p>
<p>Passer en mode root ou &#8220;rooter&#8221; votre HTC Dream est une manipulation qui vous permettra d&#8217;avoir un contrôle total sur votre appareil, et vous permettra par exemple de pouvoir <a title="Installing &amp; Run application on sdcard" href="http://forum.xda-developers.com/showthread.php?t=462882" target="_self">installer des applications sur la carte SD de votre téléphone</a> ou&#8230; permettre l&#8217;utilisation de l&#8217;apostrophe manquante du clavier du HTC Dream !</p>
<p>Réaliser cette manipulation n&#8217;est pas bien compliqué, il vous faudra <a title="Tutoriel : Installation du SDK Android" href="http://www.pointgphone.com/tutoriel-installation-sdk-android-51" target="_self">installer le SDK Android</a>, télécharger quelques fichiers et éxécuter un certain nombre de procédures dans un ordre précis, le tout <a title="Passer en mode Root un HTC Dream Orange" href="http://wiki.smartphonefrance.info/Default.aspx?Page=root-htcdream" target="_self">détaillé dans un tutoriel en français</a>.</p>
<p>Il vous sera ensuite possible d&#8217;assigner une touche à la fameuse apostrophe manquante du clavier du HTC Dream, manipulation également détaillée dans le tutoriel.</p>
<p>Vous êtes passés en mode root? Partagez votre expérience !<br />
<h3>Pour aller plus loin :</h3>
<ul class="related_post">
<li><a href="http://www.pointgphone.com/motorola-milestone-roote-10522" title="Le Motorola Milestone enfin rooté !">Le Motorola Milestone enfin rooté !</a></li>
<li><a href="http://www.pointgphone.com/eclair-htc-g1-10146" title="Un Eclair pour le HTC G1?">Un Eclair pour le HTC G1?</a></li>
<li><a href="http://www.pointgphone.com/android-20-eclair-htc-dream-8897" title="Android 2.0 Eclair sur un HTC Dream">Android 2.0 Eclair sur un HTC Dream</a></li>
<li><a href="http://www.pointgphone.com/rooter-smartphone-android-un-clic-6767" title="Rooter votre smartphone Android en un clic?">Rooter votre smartphone Android en un clic?</a></li>
<li><a href="http://www.pointgphone.com/htc-dream-orange-android-cupcake-6135" title="HTC Dream Orange : Mise à jour Android 1.5 Cupcake enfin disponible !">HTC Dream Orange : Mise à jour Android 1.5 Cupcake enfin disponible !</a></li>
</ul>
<hr />
<p><small><a href="http://www.pointgphone.com/htc-dream-root-1803">HTC Dream : Passer en mode root</a> - <a href="http://www.pointgphone.com">Point GPhone</a></small>
<br/>
Devenez développeur Android grâce à notre <a href="http://www.pointgphone.com/devenez-developpeur-android-formation-video-7172">formation vidéo</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.pointgphone.com/htc-dream-root-1803/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
