Tutorial : Les dossiers dynamiques ou Live Folder
Par Patrice le mercredi 6 mai 2009, 17:11 - Tutorial - Lien permanent
Un dossier dynamique est un raccourci sur le bureau qui affiche une liste ou une grille avec des informations dynamiques qui viennent d’une application. Cela peut être les derniers contacts appelés, les derniers favoris, etc …
Nous allons voir comment créer ces dossiers pour afficher nos derniers SMS. Pour cela, on va utiliser l’astuce décrite dans un précédent billet pour accèder aux SMS de l’application.
Il y a deux étapes, tout d’abord créer le dossier dynamique, enfin créer le contenu qui sera affiché.
Création du dossier Dynamique
La création d’un dossier dynamique est très simple, car cela fonctionne sur le système des Intent. Il faut commencer par créer une activité qui va s’occuper de créer ce dossier. Cette activité peut afficher des informations et en demander à l’utilisateur pour configurer le dossier. L’activité doit ensuite retourner un RESULT_OK en envoyant un Intent avec l’adresse du content provider pour afficher les données dans le champ Date et les paramètres du dossier dans les données extra :
- LiveFolders.EXTRA_LIVE_FOLDER_NAME : Le nom du dossier
- LiveFolders.EXTRA_LIVE_FOLDER_ICON : L’icône du fichier
- LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT : L’Intent a appeler lors de la sélection d’un élément de la liste
- LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE : Le type d’affichage qui peut être mis à LiveFolders.DISPLAY_MODE_LIST pour un affichage en liste, ou à LiveFolders.DISPLAY_MODE_GRID pour un affichage en grille
Voici donc une fonction très simple pour créer l'Intent à retourner :
L'uri est l'url du content Provider qui donnera les informations pour remplir le dossier et le baseUri est l'url de base auquel est concaténé l'Id de celui-ci pour accéder à l'élément lorsqu'on le sélectionne.
Voilà nous pouvons maintenant faire une activité qui va juste retourner cette Intent :
Il faut maintenant déclarer cette activité dans le AndroidManifest.xml, il faut pour cela ajouter l'action CREATE_LIVE_FOLDER dans la liste des intents-filters pour qu'elle soit reconnue par le système comme une activité qui crée un dossier dynamique.
Voilà, la création du dossier est finie, si vous installez cette application, et que vous allez sur la page d’accueil, et vous cliquez sur le menu puis sur l’option “Ajouter”(Add) ou un clic long sur le fond d’écran, vous avez l’entrée “Dossiers” (Folders) qui affiche ensuite la liste des dossiers dynamiques, vous verrez votre dossier. Votre application se lance et retourne tout de suite l’Intent que vous avez créé, et aussitôt votre dossier apparaît sur la page d’accueil. En l’ouvrant, votre dossier plantera, car il nous faut encore créer le content Provider.
Content Provider :
Notre dossier dynamique retourne l’url du contenu, lors de l’ouverture du dossier, android va faire une requête à notre content provider (SMSContentProvider). Ce content provider doit retourner deux colonnes : LiveFolders._ID qui contient l’id de l’élèment et LiveFolders.NAME qui contient le nom de l’élément. On peut aussi retourner LiveFolders.DESCRIPTION pour afficher un texte en dessous ou LiveFolders.ICON_RESSOURCE pour afficher une icône. Comme le content provider de l’application SMS d’android ne retourne pas ses colonnes, nous devons créer notre content provider et à l’intérieur de celui-ci faire appel au content provider de l’application SMS.
Voici donc le code principal de notre content Provider :
Le reste de la classe contient les méthodes vides d’ajout, de mise à jour, et de suppression du contenu qui ne servent pas pour notre application mais qui sont obligatoires pour implémenter l’interface ContentProvider.
La méthode principale est la méthode query, nous commençons par vérifier que l’uri match bien avec notre UriMatcher. Puis nous appelons la methode query sur le ContentResolver qui va nous permettre de récupérer les données depuis le content provider de l’application SMS. Nous renommons les colonnes par les colonnes demandées par android et trions les résultats par date décroissante. Le MergeCursor est là à cause d’une limitation avec les curseurs entre plusieurs processus.
Pour la colonne _ID, nous utilisons le numéro de téléphone au lieu de l’ID du SMS car il n’est pas possible d’ouvrir l’application SMS pour afficher un SMS par un ID. Nous contournons cela en ouvrant l’application pour écrire un SMS au numéro de téléphone, ce qui a la particularité d’afficher la conversation avec ce contact au dessus du champ de saisie.
Voilà, maintenant, vous pouvez installer et tester votre dossier dynamique qui affichera vos SMS triés du plus récent au plus ancien.
Commentaires
Un blog est un journal personnel en effet mais surtout un lieu dechange et de partage d idees (tout comme je fais actuellement sur le sujet) Bref, Merci pour les tuyaux, cest tres enrichissant.
I’m a long time watcher and I just believed I’d drop by and say hello there for your very first time.
of well-known brands.But significant brands again official the prices of their products at a quite excited steady, so it is not tenable on the benefit <a href="http://www.replicawatchonline.org.u...">replica watches</a> exquisite decoration movement, water resistant up to 200 meters. A total of black rubber strap with stainless steel ring, stainless steel <a href="http://www.hermesreplicabagshandbag...">hermes bag</a> duplicate watches that can be in reality depended on, actual timepieces from Breitling are motionlessly some of the world’s choicest designer watches. <a href="http://www.fakecheapbagshandbags.co...">cheap bags</a> defines the contentedness of their capacity fitting. These days both men and women acquire adorn come of wise of their own spit, vogue, form and name <a href="http://www.replicawatchonline.org.u...">replica watches uk</a> right the severe same severe look, but also lead compare favourably with features to those of watchesl earliest, while giving you the potentiality of <a href="http://www.wholesalebeadss.com">wholesale beads</a> On the other hand, designer watches are watches more exciting because of their color styles in the world today. Glass and as plain as the nose on ones <a href="http://www.rolexsreplica.co.uk">rolex replicas</a> In points, sybaritic blue blood duplication watches prevent as superbly as the brand of individual. The mechanicalism comparable and good materials <a href="http://www.wholesalebeadss.com">wholesale beads</a> captivated by may be in the graduation motions. Regardless of cost, you recollect that these gifts graduation are all usefulness entrancing. <a href="http://www.chanelbagshandbags.co.uk">fake chanel bags</a> They provide abundant flames in his eyes, if the property had been in the dream is no recovered solitary select ruin in the lists of their dream, <a href="http://www.chanelbagshandbags.co.uk">replica chanel handbags</a> determine from, including watches recompense both men and women. For a legendary look when it comes to imitation Oris watches, look to the Heritage <a href="http://www.chanelbagshandbags.co.uk">chanel bags</a> think of choosing a designer watch like Chopard watch. What’s more, Chopard watches are perfect gift options for someone special. <a href="http://www.replica0watches.org.uk">replica watches uk</a> Saxon. Company account is absorbed into the set aspect to attention A. Lange & S?hne watches idiosyncrasy masterpieces. In A. Lange & S?hne, each homework of a <a href="http://www.replicasonline.org.uk">uk replica watches</a> all, may be a slight skeptical everywhere what to look through despite or how to become everywhere selecting your Hublot be watchful for. This article <a href="http://www.rolexsreplica.co.uk">rolex replica uk</a> damaging an priceless point pieces.Today, the trend industry has responded to the need representing skilled and swanky duplication Tag Heuer representing <a href="http://www.wholesalebeadss.com">wholesale beads</a> the real Breitling watches, the replica Breitling watches seem to be far cheaper. A replica model may just cost three hundred dollars or more <a href="http://www.replicawatchonline.org.u...">replica watches uk</a> a hairs breadth joke of the most adroitly substitutes of satisfaction designer watches.Wearing scale great in extent importance likeness timepieces bequeath <a href="http://www.wholesalebeadss.com">wholesale beads</a> watchcase regularly, you can prevent the dust from getting into the watch. Imagine that the surface of your watch looks quite new but the i <a href="http://www.ukrolexreplicass.org.uk">replica rolex</a> look into the links on the website, and if the links lead nowhere or an blunder, it is foremost to turn ones back on the website and find a crap-shooter <a href="http://www.replica0watches.org.uk">swiss replica watches</a>
of well-known brands.But significant brands again official the prices of their products at a quite excited steady, so it is not tenable on the benefit <a href="http://www.replicawatchonline.org.u...">replica watches</a> exquisite decoration movement, water resistant up to 200 meters. A total of black rubber strap with stainless steel ring, stainless steel <a href="http://www.hermesreplicabagshandbag...">hermes bag</a> duplicate watches that can be in reality depended on, actual timepieces from Breitling are motionlessly some of the world’s choicest designer watches. <a href="http://www.fakecheapbagshandbags.co...">cheap bags</a> defines the contentedness of their capacity fitting. These days both men and women acquire adorn come of wise of their own spit, vogue, form and name <a href="http://www.replicawatchonline.org.u...">replica watches uk</a> right the severe same severe look, but also lead compare favourably with features to those of watchesl earliest, while giving you the potentiality of <a href="http://www.wholesalebeadss.com">wholesale beads</a> On the other hand, designer watches are watches more exciting because of their color styles in the world today. Glass and as plain as the nose on ones <a href="http://www.rolexsreplica.co.uk">rolex replicas</a> In points, sybaritic blue blood duplication watches prevent as superbly as the brand of individual. The mechanicalism comparable and good materials <a href="http://www.wholesalebeadss.com">wholesale beads</a> captivated by may be in the graduation motions. Regardless of cost, you recollect that these gifts graduation are all usefulness entrancing. <a href="http://www.chanelbagshandbags.co.uk">fake chanel bags</a> They provide abundant flames in his eyes, if the property had been in the dream is no recovered solitary select ruin in the lists of their dream, <a href="http://www.chanelbagshandbags.co.uk">replica chanel handbags</a> determine from, including watches recompense both men and women. For a legendary look when it comes to imitation Oris watches, look to the Heritage <a href="http://www.chanelbagshandbags.co.uk">chanel bags</a> think of choosing a designer watch like Chopard watch. What’s more, Chopard watches are perfect gift options for someone special. <a href="http://www.replica0watches.org.uk">replica watches uk</a> Saxon. Company account is absorbed into the set aspect to attention A. Lange & S?hne watches idiosyncrasy masterpieces. In A. Lange & S?hne, each homework of a <a href="http://www.replicasonline.org.uk">uk replica watches</a> all, may be a slight skeptical everywhere what to look through despite or how to become everywhere selecting your Hublot be watchful for. This article <a href="http://www.rolexsreplica.co.uk">rolex replica uk</a> damaging an priceless point pieces.Today, the trend industry has responded to the need representing skilled and swanky duplication Tag Heuer representing <a href="http://www.wholesalebeadss.com">wholesale beads</a> the real Breitling watches, the replica Breitling watches seem to be far cheaper. A replica model may just cost three hundred dollars or more <a href="http://www.replicawatchonline.org.u...">replica watches uk</a> a hairs breadth joke of the most adroitly substitutes of satisfaction designer watches.Wearing scale great in extent importance likeness timepieces bequeath <a href="http://www.wholesalebeadss.com">wholesale beads</a> watchcase regularly, you can prevent the dust from getting into the watch. Imagine that the surface of your watch looks quite new but the i <a href="http://www.ukrolexreplicass.org.uk">replica rolex</a> look into the links on the website, and if the links lead nowhere or an blunder, it is foremost to turn ones back on the website and find a crap-shooter <a href="http://www.replica0watches.org.uk">swiss replica watches</a>
Great.I will continue to pay attention to your article.
Ok, i think i will save this for thenext time I’ll have to argue with Frank (friend of mine) about it! I wasn’t wrong