Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Bootstrap

Android Bootstrap

This deck was used at Desert Code Camp 2013 (spring).

Daf1617c9a4ff129239e922e8c56af1b?s=128

Donn Felker

April 20, 2013
Tweet

Transcript

  1. More With Less with android bootstrap building Saturday, April 20,

    13
  2. @donnfelker Saturday, April 20, 13

  3. Saturday, April 20, 13

  4. Building More With Less Saturday, April 20, 13

  5. agenda open source libraries examples bootstrap Saturday, April 20, 13

  6. Saturday, April 20, 13

  7. Pay with Square GitHub Gaug.es Saturday, April 20, 13

  8. tons of integration work tons of open source Saturday, April

    20, 13
  9. open source dagger action bar sherlock otto http-request gson view

    pager indicator robotium maven android maven plugin fragments Saturday, April 20, 13
  10. a fast dependency injector for Android and Java http://square.github.io/dagger/ Saturday,

    April 20, 13
  11. Why is it so fast? - Compile Time Validation -

    Compile Time Code Generation Saturday, April 20, 13
  12. public class UserActivity extends BootstrapActivity { @Inject protected AvatarLoader avatarLoader;

    protected User user; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.user_view); if(getIntent() != null && getIntent().getExtras() != null) { user = (User) getIntent().getExtras().getSerializable(USER); } getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); avatarLoader.bind(avatar, user); name.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); } } http://square.github.io/dagger/ Saturday, April 20, 13
  13. User Interface Service Layer Persistence Layer what if I a

    particular dependency down here that depends on context? service layer: goo.gl/7NQVZ persistence layer: goo.gl/j5u74 http://square.github.io/dagger/ Saturday, April 20, 13
  14. public class UserRepository { @Inject PublicKeyProvider publicKeyProvider; public void saveProfile(UserProfile

    profile) { // user publicKey to do some encryption // Now, save the encrypted profile to db/api/etc } } http://square.github.io/dagger/ Saturday, April 20, 13
  15. public class UserRepository { @Inject PublicKeyProvider publicKeyProvider; @Inject AuthService authService;

    public void saveProfile(UserProfile profile) { // Get auth token from auth service then save // user publicKey to do some encryption // Now, save the encrypted profile to api } } http://square.github.io/dagger/ Saturday, April 20, 13
  16. must extend wait .. no .. no need to extend

    anything! WOO WOO! http://square.github.io/dagger/ Saturday, April 20, 13
  17. square.github.io/dagger/ Saturday, April 20, 13

  18. action bar sherlock action bar support for pre 3.x actionbarsherlock.com

    Saturday, April 20, 13
  19. Pay with Square GitHub Gaug.es actionbarsherlock.com Saturday, April 20, 13

  20. actionbarsherlock.com Saturday, April 20, 13

  21. usage getSupportActionBar() native calls supports theming must use Sherlock themes

    as parent actionbarsherlock.com Saturday, April 20, 13
  22. must extend SherlockActivity SherlockListActivity SherlockFragmentActivity SherlockListFragmentActivity ... actionbarsherlock.com Saturday, April

    20, 13
  23. actionbarsherlock.com Saturday, April 20, 13

  24. Otto An enhanced Guava-based event bus with emphasis on Android

    support. Saturday, April 20, 13
  25. Publish an event bus.post(new AnswerAvailableEvent(42)); @Subscribe public void answerAvailable(AnswerAvailableEvent event)

    { // TODO: React to the event somehow! } Subscribing to the event Saturday, April 20, 13
  26. Use Cases Activity / Fragment Communication Service / Fragment /

    Activity Communication Basic Message Passing between objects in scope Saturday, April 20, 13
  27. Publish an event FROM A FRAGMENT bus.post(new AnswerAvailableEvent(42)); @Subscribe public

    void answerAvailable(AnswerAvailableEvent event) { // TODO: React to the event somehow! } Subscribing to the event FROM A ACTIVITY Saturday, April 20, 13
  28. usage include library via lib or maven // Register in

    onResume() bus.register(this); // Unregister in onPause() bus.unregister(this); // in onPause @Provides bus.post(event); @Subscribe Saturday, April 20, 13
  29. square.github.io/otto/ Saturday, April 20, 13

  30. http-request kevinsawicki.github.com/http-request/ A simple convenience library for using a HttpURLConnection

    to make requests and access the response. Saturday, April 20, 13
  31. kevinsawicki.github.com/http-request/ Saturday, April 20, 13

  32. kevinsawicki.github.com/http-request/ Saturday, April 20, 13

  33. Saturday, April 20, 13

  34. kevinsawicki.github.com/http-request/ Saturday, April 20, 13

  35. gson a library for working with json code.google.com/p/google-gson/ Saturday, April

    20, 13
  36. class  BagOfPrimitives  {    private  int  value1  =  1;  

     private  String  value2  =  "abc";    private  transient  int  value3  =  3;    BagOfPrimitives()  {        //  no-­‐args  constructor    } } BagOfPrimitives  obj  =  new  BagOfPrimitives(); Gson  gson  =  new  Gson(); String  json  =  gson.toJson(obj);   a pojo serialization BagOfPrimitives  obj2  =  gson.fromJson(json,  BagOfPrimitives.class); deserialization code.google.com/p/google-gson/ Saturday, April 20, 13
  37. woohoo! no more manual json parsing code.google.com/p/google-gson/ Saturday, April 20,

    13
  38. code.google.com/p/google-gson/ Saturday, April 20, 13

  39. view pager indicator viewpagerindicator.com Saturday, April 20, 13

  40. viewpagerindicator.com Saturday, April 20, 13

  41. viewpagerindicator.com Saturday, April 20, 13

  42. viewpagerindicator.com Saturday, April 20, 13

  43. android-maven-plugin an easy to use maven plugin for android code.google.com/p/maven-android-plugin/

    Saturday, April 20, 13
  44. <project  xmlns="http://maven.apache.org/POM/4.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-­‐instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/maven-­‐v4_0_0.xsd">      

     <modelVersion>4.0.0</modelVersion>        <artifactId>android-­‐bootstrap</artifactId>        <packaging>apk</packaging>        <name>Android  Bootstrap  app</name>        <url>https://github.com/donnfelker/android-­‐bootstrap</url>        <parent>                <version>1.0</version>                <groupId>com.donnfelker.android.bootstrap</groupId>                <artifactId>android-­‐bootstrap-­‐parent</artifactId>        </parent>        <properties>                <abs.version>4.1.0</abs.version>        </properties>        <dependencies>                <dependency>                        <groupId>com.google.android</groupId>                        <artifactId>android</artifactId>                        <scope>provided</scope>                        <version>${android.version}</version>                </dependency>                <dependency>                        <groupId>com.google.code.gson</groupId>                        <artifactId>gson</artifactId>                        <version>2.1</version>                </dependency>                <dependency>                        <groupId>com.github.rtyley</groupId>                        <artifactId>roboguice-­‐sherlock</artifactId>                        <version>1.4</version>                </dependency>          ...   Saturday, April 20, 13
  45. build process easier to manage code.google.com/p/maven-android-plugin/ Saturday, April 20, 13

  46. resources google group ch14 of sonatype book goo.gl/3Waf5 (sample next)

    code.google.com/p/maven-android-plugin/ Saturday, April 20, 13
  47. Saturday, April 20, 13

  48. code.google.com/p/maven-android-plugin/ Saturday, April 20, 13

  49. fragments android support library Saturday, April 20, 13

  50. download from android sdk Saturday, April 20, 13

  51. “its like selenium, but for android” code.google.com/p/robotium Saturday, April 20,

    13
  52. public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> { private Solo solo; public

    EditorTest() { super("com.test.editor", EditorActivity.class); } public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } public void testPreferenceIsSaved() throws Exception { solo.sendKey(Solo.MENU); solo.clickOnText("More"); solo.clickOnText("Preferences"); solo.clickOnText("Edit File Extensions"); Assert.assertTrue(solo.searchText("rtf")); solo.clickOnText("txt"); solo.clearEditText(2); solo.enterText(2, "robotium"); solo.clickOnButton("Save"); solo.goBack(); solo.clickOnText("Edit File Extensions"); Assert.assertTrue(solo.searchText("application/robotium")); } @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); } } code.google.com/p/robotium Saturday, April 20, 13
  53. code.google.com/p/robotium Saturday, April 20, 13

  54. androidbootstrap.com Saturday, April 20, 13

  55. Saturday, April 20, 13

  56. influences are from github and gaug.es GitHub Gaug.es androidbootstrap.com Saturday,

    April 20, 13
  57. androidbootstrap.com includes dagger otto action bar sherlock http-request gson view

    pager indicator robotium maven android maven plugin fragments api consumption image downloading image caching cache mechanism pojo support and more... ahhhhhh yeah Saturday, April 20, 13
  58. uses template for your next project use as a reference

    a how to tutorial project MVP bootstrap androidbootstrap.com Saturday, April 20, 13
  59. q & a androidbootstrap.com Saturday, April 20, 13

  60. Thank You. questions? tweet @donnfelker Saturday, April 20, 13