Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tour D Horizon Des Drawables

8,615 views

Published on

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Tour D Horizon Des Drawables

  1. 1. Tour d’horizon des Drawables Dessiner c’est gagner !!!
  2. 2. Note générale 2
  3. 3. Introduction Le B.A.-ba des Drawables 3
  4. 4. Introduction C’est quoi un Drawable? 4
  5. 5. Introduction C’est quoi un Drawable? • Entité qui peut être « dessinée » • Une forme, un gradient, une image, un 9- patch, etc. 4
  6. 6. Introduction C’est quoi un Drawable? • Entité qui peut être « dessinée » • Une forme, un gradient, une image, un 9- patch, etc. • Composant essentiel du SDK Android 4
  7. 7. Introduction C’est quoi un Drawable? • Entité qui peut être « dessinée » • Une forme, un gradient, une image, un 9- patch, etc. • Composant essentiel du SDK Android • Instanciable en Java ou XML 4
  8. 8. Introduction Pourquoi est-ce si important? • Gestion du multi-device facilitée • Abstraction de ce qui est « dessinable » • Plus simple d’utilisation • Plus évolué que les Bitmaps ! • Possibilité de modifier des widgets sans les étendre 5
  9. 9. Introduction Architecture 6
  10. 10. Introduction Architecture Drawable 6
  11. 11. Introduction Architecture Drawable ColorDrawable GradientDrawable 6
  12. 12. Introduction Architecture Drawable ColorDrawable GradientDrawable LayerDrawable 6
  13. 13. « How-to » basique Hello Drawables ! 7
  14. 14. « How-to » basique Premier essai private Drawable mDrawable; public DrawableView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDrawable = context.getResources().getDrawable(R.drawable.my_drawable); } public void onDraw(Canvas canvas) { super.onDraw(canvas); mDrawable.draw(canvas); } 8
  15. 15. « How-to » basique Gné ? Ça marche pas ! 9
  16. 16. « How-to » basique Gné ? Ça marche pas ! • Mon Canvas n’est pas dans un état « acceptable » ? 9
  17. 17. « How-to » basique Gné ? Ça marche pas ! • Mon Canvas n’est pas dans un état « acceptable » ? • J’ai oublié de mettre la vue dans mon layout ? 9
  18. 18. « How-to » basique Gné ? Ça marche pas ! • Mon Canvas n’est pas dans un état « acceptable » ? • J’ai oublié de mettre la vue dans mon layout ? • .... Je n’ai pas définit la taille de mon Drawable 9
  19. 19. « How-to » basique Gné ? Ça marche pas ! • Mon Canvas n’est pas dans un état « acceptable » ? • J’ai oublié de mettre la vue dans mon layout ? • .... Je n’ai pas définit la taille de mon Drawable • setBounds(), getIntrinsic[Width/Height]() 9
  20. 20. « How-to » basique La solution ! private Drawable mDrawable; public DrawableView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDrawable = context.getResources().getDrawable(R.drawable.my_drawable); mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight()); } public void onDraw(Canvas canvas) { super.onDraw(canvas); mDrawable.draw(canvas); } 10
  21. 21. Les fonctionnalités Ça permet quoi les Drawables? 11
  22. 22. Quelques fonctionnalités Généralités • Emplacement / taille : • setBounds(), getIntrinsic[Width/Height] (), getMinimum[Width/Height](), etc. • Etat courant : • setState(), state_[pressed/focused/...], setLevel(), etc. • Affichage : setAlpha(), setDither(), ... 12
  23. 23. Quelques fonctionnalités Drawable.Callback • Un Drawable doit pouvoir « s’invalider » • Utilité de l’interface Drawable.Callback • View implémente Drawable.Callback • Méthode d’aide verifyDrawable() 13
  24. 24. Quelques fonctionnalités Drawable.Callback public class DrawableView extends View { private Drawable mDrawable; public DrawableView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDrawable = context.getResources().getDrawable(R.drawable.my_drawable); mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight()); } @Override protected boolean verifyDrawable(Drawable who) { return who == mDrawable || super.verifyDrawable(who); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mDrawable.draw(canvas); } } 14
  25. 25. Principe d’état constant Problématique private static final int OPAQUE = 255; private static final int TRANSLUCENT = 70; Book book = ...; TextView listItem = ...; listItem.setText(book.getTitle()); Drawable star = getContext().getResources().getDrawable(R.drawable.star); if (book.isFavorite()) { star.setAlpha(OPAQUE); } else { star.setAlpha(TRANSLUCENT); } Extrait de http://www.curious-creature.org/2009/05/02/drawable-mutations/ 15
  26. 26. Principe d’état constant Explication du phéomène • Android « factorise » les états des Drawables • Minimise l’empreinte mémoire 16
  27. 27. Principe d’état constant Explication du phéomène 17
  28. 28. Principe d’état constant Explication du phéomène Drawable Drawable 17
  29. 29. Principe d’état constant Explication du phéomène Drawable Drawable ConstantState 17
  30. 30. Principe d’état constant Explication du phéomène Drawable Drawable ConstantState 17
  31. 31. Principe d’état constant Résolution du « problème » • Pas de fonctionnalité « copy-on-write » • Utilisation de la méthode mutate() : • Copie de l’état constant • Mise du flag mMutated à true • Appel multiple à mutated() sans effet 18
  32. 32. Principe d’état constant Résolution du « problème » Drawable Drawable 19
  33. 33. Principe d’état constant Résolution du « problème » Muté Muté Drawable Drawable ConstantState ConstantState 19
  34. 34. Principe d’état constant Résolution du « problème » Muté Muté Drawable Drawable ConstantState ConstantState 19
  35. 35. Principe d’état constant Résolution du « problème » private static final int OPAQUE = 255; private static final int TRANSLUCENT = 70; Book book = ...; TextView listItem = ...; listItem.setText(book.getTitle()); Drawable star = getContext().getResources().getDrawable(R.drawable.star); if (book.isFavorite()) { star.mutate().setAlpha(OPAQUE); } else { star.mutate().setAlpha(TRANSLUCENT); } Extrait de http://www.curious-creature.org/2009/05/02/drawable-mutations/ 20
  36. 36. Instanciation Enfin les travaux pratiques ! 21
  37. 37. Instancier un drawable Le résultat voulu 22
  38. 38. Instancier un drawable Le résultat voulu 22
  39. 39. Instancier un drawable Deux possibilités : Java ... float density = getContext().getResources().getDisplayMetrics().density; // gradient from #4e525c to #31343c int[] colors = new int[] {Color.rgb(78, 82, 92), Color.rgb(49, 52, 60)}; GradientDrawable gradient = new GradientDrawable(Orientation.BOTTOM_TOP, colors); gradient.setShape(GradientDrawable.OVAL); gradient.setStroke((int) (3 * density), Color.WHITE, 4 * density, 5 * density); 23
  40. 40. Instancier un drawable ... et XML <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <gradient android:startColor="#4e525c" android:endColor="#31343c" android:angle="90" /> <stroke android:width="3dip" android:color="#fff" android:dashWidth="4dip" android:dashGap="5dip" /> </shape> 24
  41. 41. Drawable Listing em o D Code disponible sur http://www.github.com/cyrilmottier/DrawablePresentation 25
  42. 42. BitmapDrawable • Très largement utilisé • Pourtant méconnu / mal connu • Souvent utilisé tel quel • context.getResources().getDrawable(R.drawable.image) (où image est un fichier de type png ou jpg) • Contrôles plus poussés disponibles • tileMode, gravity, etc. 26
  43. 43. BitmapDrawable android:tileMode <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" /> 27
  44. 44. BitmapDrawable android:tileMode <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" /> 27
  45. 45. BitmapDrawable android:tileMode <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" android:tileMode="clamp" /> 28
  46. 46. BitmapDrawable android:tileMode <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" android:tileMode="repeat" /> 29
  47. 47. BitmapDrawable android:tileMode <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" android:tileMode="mirror" /> 30
  48. 48. BitmapDrawable android:gravity <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" android:gravity="center" /> 31
  49. 49. BitmapDrawable android:gravity <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http:// schemas.android.com/apk/res/android" android:src="@drawable/pattern" android:gravity="top|right" /> 32
  50. 50. NinePatchDrawable Mon préféré héhé ! 33
  51. 51. NinePatchDrawable Mon préféré héhé ! • Instanciation simple : • getDrawable(R.drawable.image) (image ayant l’extension .9.png) • Concept d’image « étirable » 33
  52. 52. NinePatchDrawable Mon préféré héhé ! 34
  53. 53. StateListDrawable • Présent partout : • Boutons • Checkboxes • Changement de l’apparence fonction de l’état courant 35
  54. 54. Dernière démos On finit en beauté ? 36
  55. 55. A quoi ça sert tout ça? Flatten Hierarchy em o D Code disponible sur http://www.github.com/cyrilmottier/DrawablePresentation 37
  56. 56. Créer son Drawable • Étendre de Drawable (ou une classe fille) • Définir les méthodes abstraites • setAlpha, setColorFilter, draw, etc. • Redéfinir si nécessaire 38
  57. 57. RemoteDrawable em o D Code disponible sur http://www.github.com/cyrilmottier/DrawablePresentation 39
  58. 58. Références • En savoir plus : • http://android.cyrilmottier.com • Code source : • http://android.git.kernel.org/ • http://github.com/cyrilmottier 40
  59. 59. Des questions ? N’hésitez pas ! 41

×