Building More with Less

56
More With Less with android bootstrap building Wednesday, February 6, 13

description

Slides for the talk given at AppsWorld America 2013

Transcript of Building More with Less

Page 1: Building More with Less

More With Lesswith android bootstrap

building

Wednesday, February 6, 13

Page 2: Building More with Less

@donnfelker

Wednesday, February 6, 13

Page 3: Building More with Less

Wednesday, February 6, 13

Page 4: Building More with Less

Building More With Less

Wednesday, February 6, 13

Page 5: Building More with Less

agenda

open sourcelibrariesexamplesbootstrap

Wednesday, February 6, 13

Page 6: Building More with Less

Wednesday, February 6, 13

Page 7: Building More with Less

Pay with Square GitHub Gaug.es

Wednesday, February 6, 13

Page 8: Building More with Less

tons of integration work

tons of open source

Wednesday, February 6, 13

Page 9: Building More with Less

open source

roboguiceaction bar sherlockhttp-requestgsonview pager indicatorrobotiummavenandroid maven pluginfragments

Wednesday, February 6, 13

Page 10: Building More with Less

roboguicedependency injection for android

roboguice.org

Wednesday, February 6, 13

Page 11: Building More with Less

class RoboWay extends RoboActivity {     @InjectView(R.id.name)             TextView name;     @InjectView(R.id.thumbnail)        ImageView thumbnail;     @InjectResource(R.drawable.icon)   Drawable icon;     @InjectResource(R.string.app_name) String myName;     @Inject                            LocationManager loc;

    public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);        name.setText( "Hello, " + myName );     } }

roboguice.org

Wednesday, February 6, 13

Page 12: Building More with Less

User Interface

Service Layer

Persistence Layerwhat if I need a string

resource down here?

service layer: goo.gl/7NQVZ persistence layer: goo.gl/j5u74

roboguice.org

Wednesday, February 6, 13

Page 13: Building More with Less

public class UserRepository {

    @InjectResource(R.string.public_key) String publicKey;

    public void saveProfile(UserProfile profile) {         // user publicKey to do some encryption // Now, save the encrypted profile to db/api/etc     } }

roboguice.org

Wednesday, February 6, 13

Page 14: Building More with Less

public class UserRepository {

    @InjectResource(R.string.public_key) String publicKey;     @Inject protected 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     } }

roboguice.org

Wednesday, February 6, 13

Page 15: Building More with Less

must extend

RoboActivityRoboListActivityRoboFragmentActivityRoboListFragmentActivity...

roboguice.org

Wednesday, February 6, 13

Page 16: Building More with Less

roboguice.org

Wednesday, February 6, 13

Page 17: Building More with Less

action bar sherlockaction bar support for pre 3.x

actionbarsherlock.com

Wednesday, February 6, 13

Page 18: Building More with Less

Pay with Square GitHub Gaug.es

actionbarsherlock.com

Wednesday, February 6, 13

Page 19: Building More with Less

actionbarsherlock.com

Wednesday, February 6, 13

Page 20: Building More with Less

usage

getSupportActionBar()

native calls

supports theming

must use Sherlock themes as parent

actionbarsherlock.com

Wednesday, February 6, 13

Page 21: Building More with Less

must extend

SherlockActivitySherlockListActivitySherlockFragmentActivitySherlockListFragmentActivity...

actionbarsherlock.com

Wednesday, February 6, 13

Page 22: Building More with Less

ruh roh.roboguice and actionbarsherlock must both extend activity

actionbarsherlock.com

Wednesday, February 6, 13

Page 23: Building More with Less

roboguice-sherlockcombines roboguice and sherlock

github.com/rtyley/roboguice-sherlock

Wednesday, February 6, 13

Page 24: Building More with Less

public  class  CarouselActivity  extends  RoboSherlockFragmentActivity  {

       @InjectView(id.tpi_header)  private  TitlePageIndicator  indicator;        @InjectView(id.vp_pages)  private  ViewPager  pager;

       @Override        protected  void  onCreate(Bundle  savedInstanceState)  {

               requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

               super.onCreate(savedInstanceState);                setContentView(R.layout.carousel_view);

               pager.setAdapter(new  BootstrapPagerAdapter(getResources(),  getSupportFragmentManager()));

               indicator.setViewPager(pager);                pager.setCurrentItem(1);        }

}

github.com/rtyley/roboguice-sherlock

Wednesday, February 6, 13

Page 25: Building More with Less

github.com/rtyley/roboguice-sherlock

Wednesday, February 6, 13

Page 26: Building More with Less

http-request

kevinsawicki.github.com/http-request/

A simple convenience library for using a HttpURLConnection to make requests and access the response.

Wednesday, February 6, 13

Page 27: Building More with Less

kevinsawicki.github.com/http-request/

Wednesday, February 6, 13

Page 28: Building More with Less

kevinsawicki.github.com/http-request/

Wednesday, February 6, 13

Page 29: Building More with Less

Wednesday, February 6, 13

Page 30: Building More with Less

kevinsawicki.github.com/http-request/

Wednesday, February 6, 13

Page 31: Building More with Less

gsona library for working with json

code.google.com/p/google-gson/

Wednesday, February 6, 13

Page 32: Building More with Less

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/

Wednesday, February 6, 13

Page 33: Building More with Less

woohoo! no more manual json parsing

code.google.com/p/google-gson/

Wednesday, February 6, 13

Page 34: Building More with Less

code.google.com/p/google-gson/

Wednesday, February 6, 13

Page 35: Building More with Less

view pager indicator

viewpagerindicator.com

Wednesday, February 6, 13

Page 36: Building More with Less

viewpagerindicator.com

Wednesday, February 6, 13

Page 37: Building More with Less

viewpagerindicator.com

Wednesday, February 6, 13

Page 38: Building More with Less

viewpagerindicator.com

Wednesday, February 6, 13

Page 39: Building More with Less

android-maven-pluginan easy to use maven plugin for android

code.google.com/p/maven-android-plugin/

Wednesday, February 6, 13

Page 40: Building More with Less

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

               <dependency>                        <groupId>com.github.kevinsawicki</groupId>                        <artifactId>wishlist</artifactId>                        <version>0.3</version>                        <type>apklib</type>                </dependency>                <dependency>                        <groupId>junit</groupId>                        <artifactId>junit</artifactId>                        <version>4.10</version>                        <scope>test</scope>                </dependency>                <dependency>                        <groupId>org.hamcrest</groupId>                        <artifactId>hamcrest-­‐library</artifactId>                        <version>1.3.RC2</version>                        <scope>test</scope>                </dependency>                <dependency>                        <groupId>org.mockito</groupId>                        <artifactId>mockito-­‐core</artifactId>                        <version>1.9.0</version>                        <scope>test</scope>                </dependency>        </dependencies>        <build>                <plugins>                        <plugin>                                <groupId>com.jayway.maven.plugins.android.generation2</groupId>                                <artifactId>android-­‐maven-­‐plugin</artifactId>                        </plugin>                        <plugin>                                <artifactId>maven-­‐compiler-­‐plugin</artifactId>                                <version>2.3.2</version>                                <configuration>                                        <source>1.6</source>                                        <target>1.6</target>                                </configuration>                        </plugin>                </plugins>        </build>        <profiles>                <profile>                        <id>release</id>                        <!-­‐-­‐  via  this  activation  the  profile  is  automatically  used  when  the  release  is  done  with  the  maven  release                        plugin  -­‐-­‐>                        <activation>                                <property>                                        <name>performRelease</name>                                        <value>true</value>                                </property>                        </activation>                        <build>                                <plugins>                                        <plugin>                                                <groupId>org.apache.maven.plugins</groupId>                                                <artifactId>maven-­‐jarsigner-­‐plugin</artifactId>                                                <executions>                                                        <execution>                                                                <id>signing</id>                                                                <goals>                                                                        <goal>sign</goal>                                                                        <goal>verify</goal>                                                                </goals>                                                                <phase>package</phase>                                                                <inherited>true</inherited>                                                                <configuration>                                                                        <removeExistingSignatures>true</removeExistingSignatures>                                                                        <archiveDirectory  />                                                                        <!-­‐-­‐  These  values  can  either  be  placed  directly  into  to  file  below,  or  provided                                                                        via  the  command  line  during  the  build  process  as  such:                                                                          "mvn  clean  release  -­‐Dbootstrap.sign.keystore=foobar"  ...  etc.                                                                          This  will  keep  the  keystore  out  of  your  file  so  no  prying  eyes  can  see.                                                                          Also,  if  you  have  a  ci  (Continuous  Integration)  profile,  these  values  can  be                                                                          passed  in  via  the  build  server.  -­‐-­‐>                                                                        <keystore>${bootstrap.sign.keystore}</keystore>                                                                        <alias>${bootstrap.sign.alias}</alias>                                                                        <storepass>${bootstrap.sign.storepass}</storepass>                                                                        <keypass>${bootstrap.sign.keypass}</keypass>                                                                        <verbose>true</verbose>                                                                </configuration>                                                        </execution>                                                </executions>                                        </plugin>                                        <!-­‐-­‐  the  signed  apk  then  needs  to  be  zipaligned  -­‐-­‐>                                        <plugin>                                                <groupId>com.jayway.maven.plugins.android.generation2</groupId>                                                <artifactId>android-­‐maven-­‐plugin</artifactId>                                                <inherited>true</inherited>                                                <configuration>                                                        <sign>                                                                <debug>false</debug>                                                        </sign>                                                        <zipalign>                                                                <verbose>true</verbose>                                                                <outputApk>${project.build.directory}/${project.artifactId}-­‐${project.version}-­‐signed-­‐aligned.apk</outputApk>                                                        </zipalign>                                                        <manifest>                                                                <debuggable>false</debuggable>                                                        </manifest>                                                </configuration>                                                <executions>                                                        <execution>                                                                <id>alignApk</id>                                                                <phase>package</phase>                                                                <goals>                                                                        <goal>zipalign</goal>                                                                </goals>                                                        </execution>                                                </executions>                                        </plugin>                                </plugins>                        </build>                </profile>        </profiles></project>

Wednesday, February 6, 13

Page 41: Building More with Less

build process easier to manage

code.google.com/p/maven-android-plugin/

Wednesday, February 6, 13

Page 42: Building More with Less

resources

google group

ch14 of sonatype book goo.gl/3Waf5 (sample next)

code.google.com/p/maven-android-plugin/

Wednesday, February 6, 13

Page 43: Building More with Less

Wednesday, February 6, 13

Page 44: Building More with Less

code.google.com/p/maven-android-plugin/

Wednesday, February 6, 13

Page 45: Building More with Less

fragments android support library

Wednesday, February 6, 13

Page 46: Building More with Less

download from android sdk

Wednesday, February 6, 13

Page 47: Building More with Less

“its like selenium, but for android”

code.google.com/p/robotium

Wednesday, February 6, 13

Page 48: Building More with Less

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

Wednesday, February 6, 13

Page 49: Building More with Less

code.google.com/p/robotium

Wednesday, February 6, 13

Page 50: Building More with Less

androidbootstrap.com

Wednesday, February 6, 13

Page 51: Building More with Less

Wednesday, February 6, 13

Page 52: Building More with Less

influences are from github and gaug.es

GitHub Gaug.es

androidbootstrap.com

Wednesday, February 6, 13

Page 53: Building More with Less

androidbootstrap.com

includesroboguiceaction bar sherlockhttp-requestgsonview pager indicatorrobotiummavenandroid maven pluginfragmentsapi consumptionimage downloadingimage cachingcache mechanismpojo supportand more...

ahhhhhh yeah

Wednesday, February 6, 13

Page 54: Building More with Less

uses

template for your next projectuse as a referencea how to tutorialproject MVP bootstrap

androidbootstrap.com

Wednesday, February 6, 13

Page 55: Building More with Less

q & a

androidbootstrap.com

Wednesday, February 6, 13

Page 56: Building More with Less

Thank You.questions? tweet @donnfelker

Wednesday, February 6, 13