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.

From Grails to Android: A Simple Journey

427 views

Published on

One of the key new features of Grails 3 is the build system now being a set of plugins for the Gradle build tool. The Android Framework also uses the Gradle build system to build, test, run and package applications. In this talk, learn how to move from developing applications for Grails 3 to Android. We’re going to cover the following:

Project Structure Similarities
Use of Gradle Commands
User Interface: GSP Pages vs. Android Layout XML Files Dependency Injection: Spring vs. Dagger 2

Walk away with the foundation you need to tackle your first Android application!

Published in: Software
  • Be the first to comment

From Grails to Android: A Simple Journey

  1. 1. FROM GRAILS TO ANDROID A SIMPLE JOURNEY
  2. 2. GRAILS @BRWNGRLDEV
  3. 3. ANDROID @BRWNGRLDEV
  4. 4. OVERVIEW @BRWNGRLDEV
  5. 5. OVERVIEW ▸Project Structure @BRWNGRLDEV
  6. 6. OVERVIEW ▸Project Structure ▸User Interface @BRWNGRLDEV
  7. 7. OVERVIEW ▸Project Structure ▸User Interface ▸Dependency Injection @BRWNGRLDEV
  8. 8. OVERVIEW ▸Project Structure ▸User Interface ▸Dependency Injection ▸Persistence @BRWNGRLDEV
  9. 9. PROJECT STRUCTURE @BRWNGRLDEV
  10. 10. GRAILS APP STRUCTURE grails create-app @BRWNGRLDEV
  11. 11. GRAILS APP STRUCTURE grails create-app @BRWNGRLDEV
  12. 12. GRAILS APP STRUCTURE @BRWNGRLDEV
  13. 13. ANDROID APP STRUCTURE @BRWNGRLDEV
  14. 14. ANDROID APP STRUCTURE @BRWNGRLDEV
  15. 15. ANDROID APP STRUCTURE @BRWNGRLDEV ▸app directory
  16. 16. ANDROID APP STRUCTURE @BRWNGRLDEV ▸app directory ▸test directories
  17. 17. ANDROID APP STRUCTURE @BRWNGRLDEV ▸app directory ▸test directories ▸gradle wrapper
  18. 18. ANDROID APP STRUCTURE @BRWNGRLDEV
  19. 19. ANDROID APP STRUCTURE @BRWNGRLDEV most source code
  20. 20. ANDROID APP STRUCTURE @BRWNGRLDEV images
  21. 21. ANDROID APP STRUCTURE @BRWNGRLDEV views
  22. 22. ANDROID APP STRUCTURE @BRWNGRLDEV launcher icons
  23. 23. LAUNCHER ICONS @BRWNGRLDEV https://developer.android.com/guide/practices/ui_guidelines/icon_design_launcher.html
  24. 24. ANDROID APP STRUCTURE @BRWNGRLDEV strings, colors, sizes, etc.
  25. 25. DOMAIN MODELS @BRWNGRLDEV
  26. 26. GRAILS DOMAIN CLASS @BRWNGRLDEV
  27. 27. GRAILS DOMAIN CLASS @BRWNGRLDEV ▸BookSpec ▸BookController ▸BookControllerSpec ▸/book/edit.gsp ▸/book/create.gsp ▸/book/index.gsp ▸/book/show.gsp
  28. 28. ANDROID DOMAIN CLASS @BRWNGRLDEV
  29. 29. ANDROID DOMAIN CLASS @BRWNGRLDEV ▸Book
  30. 30. ANDROID DOMAIN CLASS @BRWNGRLDEV ▸Book
  31. 31. ANDROID DOMAIN CLASS @BRWNGRLDEV
  32. 32. ANDROID DOMAIN CLASS @BRWNGRLDEV
  33. 33. ANDROID DOMAIN CLASS @BRWNGRLDEV MVP
  34. 34. ANDROID DOMAIN CLASS @BRWNGRLDEV ▸BookTest ▸BookPresenter ▸BookPresenterTest ▸BookView ▸BookActivity ▸BookActivityTest ▸activity_book.xml ▸activity_insert_update_book.xml
  35. 35. @BRWNGRLDEV
  36. 36. CONFIGURATION @BRWNGRLDEV
  37. 37. GRAILS - BUILD.GRADLE @BRWNGRLDEV
  38. 38. GRAILS - BUILD.GRADLE @BRWNGRLDEV
  39. 39. ANDROID - BUILD.GRADLE @BRWNGRLDEV
  40. 40. ANDROID - BUILD.GRADLE @BRWNGRLDEV
  41. 41. ANDROID - BUILD.GRADLE @BRWNGRLDEV
  42. 42. GRADLE COMMANDS @BRWNGRLDEV ▸gradle tasks ▸gradle clean ▸gradle test ▸gradle assemble
  43. 43. GRADLE COMMANDS @BRWNGRLDEV ▸gradle tasks ▸gradle clean ▸gradle test ▸gradle assemble
  44. 44. PROJECT STRUCTURE @BRWNGRLDEV ▸Folder layout ▸Domain models ▸Gradle Configuration
  45. 45. @BRWNGRLDEV
  46. 46. USER INTERFACE @BRWNGRLDEV
  47. 47. GRAILS UI @BRWNGRLDEV
  48. 48. GRAILS GSP PAGE @BRWNGRLDEV
  49. 49. GRAILS GSP PAGE @BRWNGRLDEV
  50. 50. GRAILS GSP PAGE @BRWNGRLDEV
  51. 51. GRAILS GSP PAGE @BRWNGRLDEV
  52. 52. GRAILS GSP PAGE @BRWNGRLDEV <f:display bean=“book”/>
  53. 53. ANDROID UI @BRWNGRLDEV
  54. 54. ANDROID UI @BRWNGRLDEV
  55. 55. @BRWNGRLDEV XML?! ARE YOU KIDDING ME?!!!
  56. 56. @BRWNGRLDEV XML?! ARE YOU KIDDING ME?!!!
  57. 57. @BRWNGRLDEV XML?! ARE YOU KIDDING ME?!!!
  58. 58. @BRWNGRLDEV XML?! ARE YOU KIDDING ME?!!!
  59. 59. ANDROID LAYOUT GUI @BRWNGRLDEV
  60. 60. ANDROID LAYOUT GUI @BRWNGRLDEV
  61. 61. ANDROID LAYOUT GUI @BRWNGRLDEV
  62. 62. ANDROID XML LAYOUT @BRWNGRLDEV
  63. 63. ANDROID XML LAYOUT @BRWNGRLDEV
  64. 64. ANDROID XML LAYOUT @BRWNGRLDEV
  65. 65. ANDROID XML LAYOUT @BRWNGRLDEV
  66. 66. STYLE & SIZE RESOURCES @BRWNGRLDEV
  67. 67. STYLE & SIZE RESOURCES @BRWNGRLDEV
  68. 68. STYLE & SIZE RESOURCES @BRWNGRLDEV
  69. 69. STYLE & SIZE RESOURCES @BRWNGRLDEV
  70. 70. STYLE & SIZE RESOURCES @BRWNGRLDEV ▸colors ▸styles ▸strings ▸sizes ▸themes
  71. 71. STYLE & SIZE RESOURCES @BRWNGRLDEV strings, colors, sizes, etc.
  72. 72. https://www.flickr.com/photos/bionicteaching/14668480106
  73. 73. https://developer.android.com/training/basics/supporting-devices/screens.html DEVELOPER DOCS @BRWNGRLDEV
  74. 74. USER INTERFACE @BRWNGRLDEV ▸GSP pages ▸XML layout ▸Resource folders
  75. 75. @BRWNGRLDEV
  76. 76. DEPENDENCY INJECTION @BRWNGRLDEV
  77. 77. DEPENDENCY INJECTION @BRWNGRLDEV THE CLIENT DELEGATES TO EXTERNAL CODE (THE INJECTOR) THE RESPONSIBILITY OF PROVIDING ITS DEPENDENCIES. https://en.wikipedia.org/wiki/Dependency_injection
  78. 78. GRAILS - DEPENDENCY INJECTION @BRWNGRLDEV
  79. 79. GRAILS - DEPENDENCY INJECTION @BRWNGRLDEV
  80. 80. GRAILS - DEPENDENCY INJECTION @BRWNGRLDEV
  81. 81. GRAILS - DEPENDENCY INJECTION @BRWNGRLDEV
  82. 82. ANDROID - SIMPLE APPROACH @BRWNGRLDEV public class Injector { }
  83. 83. ANDROID - SIMPLE APPROACH @BRWNGRLDEV public class Injector { private static BookService bookService; }
  84. 84. ANDROID - SIMPLE APPROACH @BRWNGRLDEV public class Injector { private static BookService bookService; public static BookService provideBookService () {
 if ( bookService == null ) {
 bookService = new BookService();
 }
 return bookService;
 } }
  85. 85. ANDROID - SIMPLE APPROACH @BRWNGRLDEV public class Activity { private BooksPresenter booksPresenter; @Override
 protected void onCreate (Bundle savedInstanceState) {
 … booksPresenter = new BooksPresenter( Injector.provideBookService() ); } }
  86. 86. ANDROID - DAGGER @BRWNGRLDEV http://google.github.io/dagger/
  87. 87. ANDROID - DAGGER @BRWNGRLDEV public class BooksPresenter { private final BookService bookService; }
  88. 88. ANDROID - DAGGER @BRWNGRLDEV public class BooksPresenter { private final BookService bookService; @Inject BooksPresenter(BookService bookService) { this.bookService = bookService; } }
  89. 89. ANDROID - DAGGER @BRWNGRLDEV @Module public class AppModule { }
  90. 90. ANDROID - DAGGER @BRWNGRLDEV @Module public class AppModule { @Provides @Singleton BookService provideBookService() { return new BookService(); } }
  91. 91. ANDROID - DAGGER @BRWNGRLDEV @Provides @Singleton BookService provideBookService() { return new BookService(); } @Inject BooksPresenter(BookService bookService) { this.bookService = bookService; }
  92. 92. DEPENDENCY INJECTION @BRWNGRLDEV ▸Spring ▸Simple Injector ▸Dagger
  93. 93. @BRWNGRLDEV
  94. 94. PERSISTENCE @BRWNGRLDEV
  95. 95. @BRWNGRLDEV http://gorm.grails.org/latest/
  96. 96. @BRWNGRLDEV GORM def book = new Book(title: ‘Clean Code’) book.save()
  97. 97. @BRWNGRLDEV GORM def book = new Book(title: ‘Clean Code’) book.save() def book = Book.findByTitle(‘Clean Code’) println book
  98. 98. @BRWNGRLDEV GORM def book = new Book(title: ‘Clean Code’) book.save() def book = Book.findByTitle(‘Clean Code’) println book def book = Book.get(1) book.delete()
  99. 99. https://developer.android.com/training/basics/data-storage/databases.html ANDROID @BRWNGRLDEV
  100. 100. https://developer.android.com/training/basics/data-storage/databases.html ANDROID @BRWNGRLDEV
  101. 101. SQLITE @BRWNGRLDEV SQLiteDatabase db = dbHelper.getWritableDatabase();
  102. 102. SQLITE @BRWNGRLDEV SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME_TITLE, title);
  103. 103. SQLITE @BRWNGRLDEV SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME_TITLE, title); db.insert( TABLE_NAME, null, values);
  104. 104. SQLITE VS. GORM @BRWNGRLDEV SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME_TITLE, title); db.insert( TABLE_NAME, null, values); def book = new Book(title: ‘Clean Code’) book.save()
  105. 105. REALM @BRWNGRLDEV http://realm.io
  106. 106. REALM @BRWNGRLDEV
  107. 107. REALM @BRWNGRLDEV ▸Easy to Set Up
  108. 108. REALM @BRWNGRLDEV ▸Easy to Set Up ▸Faster than ORMs
  109. 109. REALM @BRWNGRLDEV ▸Easy to Set Up ▸Faster than ORMs ▸Has a Fluent API
  110. 110. REALM - CREATING A RECORD @BRWNGRLDEV realm.executeTransaction( new Realm.Transaction()
 {
 @Override
 public void execute (Realm realm)
 {
 Book book = realm.createObject(Book.class); book.setTitle(“Clean Code");
 }
 } );
  111. 111. REALM - CREATING A RECORD @BRWNGRLDEV realm.executeTransaction( new Realm.Transaction()
 {
 @Override
 public void execute (Realm realm)
 {
 Book book = realm.createObject(Book.class); book.setTitle(“Clean Code");
 }
 } );
  112. 112. REALM - QUERY @BRWNGRLDEV RealmResults<Book> results = realm.where(Book.class) .equalTo("title", “Clean Code") .or() .equalTo("title", “Clean Codez") .findAll();
  113. 113. REALM - QUERY @BRWNGRLDEV RealmResults<Book> results = realm.where(Book.class) .equalTo("title", “Clean Code") .or() .equalTo("title", “Clean Codez") .findAll();
  114. 114. REALM - CHANGE LISTENERS @BRWNGRLDEV bookListener = new RealmChangeListener() { @Override public void onChange(Book book) { // make changes }};
  115. 115. REALM - CHANGE LISTENERS @BRWNGRLDEV bookListener = new RealmChangeListener() { @Override public void onChange(Book book) { // make changes }}; book = realm.where(Book.class).equalTo("id", 1).findFirst(); book.addChangeListener(bookListener);
  116. 116. PERSISTENCE @BRWNGRLDEV ▸GORM ▸Sqlite ▸Realm
  117. 117. @BRWNGRLDEV
  118. 118. SUMMARY @BRWNGRLDEV
  119. 119. SUMMARY ▸Project Structure @BRWNGRLDEV
  120. 120. SUMMARY ▸Project Structure ▸User Interface @BRWNGRLDEV
  121. 121. SUMMARY ▸Project Structure ▸User Interface ▸Dependency Injection @BRWNGRLDEV
  122. 122. SUMMARY ▸Project Structure ▸User Interface ▸Dependency Injection ▸Persistence @BRWNGRLDEV
  123. 123. KEY TAKEAWAY @BRWNGRLDEV
  124. 124. KEY TAKEAWAY @BRWNGRLDEV ANDROID IS REALLY HARD!
  125. 125. KEY TAKEAWAY @BRWNGRLDEV ANDROID IS REALLY HARD! FUN
  126. 126. THANKS! @brwngrldev +AnnyceDavis www.adavis.info @BRWNGRLDEV

×