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).

Donn Felker

April 20, 2013
Tweet

More Decks by Donn Felker

Other Decks in Programming

Transcript

  1. open source dagger action bar sherlock otto http-request gson view

    pager indicator robotium maven android maven plugin fragments Saturday, April 20, 13
  2. Why is it so fast? - Compile Time Validation -

    Compile Time Code Generation Saturday, April 20, 13
  3. 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
  4. 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
  5. 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
  6. 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
  7. must extend wait .. no .. no need to extend

    anything! WOO WOO! http://square.github.io/dagger/ Saturday, April 20, 13
  8. usage getSupportActionBar() native calls supports theming must use Sherlock themes

    as parent actionbarsherlock.com Saturday, April 20, 13
  9. 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
  10. Use Cases Activity / Fragment Communication Service / Fragment /

    Activity Communication Basic Message Passing between objects in scope Saturday, April 20, 13
  11. 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
  12. 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
  13. 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
  14. <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
  15. resources google group ch14 of sonatype book goo.gl/3Waf5 (sample next)

    code.google.com/p/maven-android-plugin/ Saturday, April 20, 13
  16. 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
  17. 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
  18. uses template for your next project use as a reference

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