Non Conventional Android Programming (English)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Non Conventional Android Programming (English) - Presentation Transcript

    1. Non-conventional Android Programming
    2. Who am I? Davide Cerbo http://jesty.it http://davide.cerbo.born-to-co.de http://www.linkedin.com/in/davidecerbo [email_address]
    3. http://www.pro-netics.it [email_address]
    4. Once upon a time...
    5. New Features
      • GPS
      • Compass
      • Camere
      • Hi-Res Screen
      • WI-FI
      • UMTS / HSPDA
      • Multi-touch
    6. Where we going?
    7. (market)
    8. Too much devices
    9. Many languages for many devices
      • IPhone: Objective C
      • Android: Java
      • BlackBerry: Java
      • Nokia/Symbian: Java e C++
      • Windows Mobile: .NET e C
    10. Write once, run anywhere Do you remember?
    11. PhoneGap HTML + JAVASCRIPT + CSS = PhoneGap.com
    12. PhoneGap CROSS PLATFORM + API NATIVE INTERFACES + OPEN SOURCE = PhoneGap.com
    13. What I'm able to do? ...and coming soon: camera, maps and file manager
    14. Examples //GEO REFERENCING var getLocation = function () { var suc = function ( p ){ alert ( p . coords . latitude + " " + p . coords . longitude ); }; var fail = function (){ alert ( "Location not available!" );}; navigator . geolocation . getCurrentPosition ( suc , fail , undefined ); } //VIBRACALL navigator . notification . vibrate ( 0 ); //BEEEEEEP navigator . notification . beep ( 2 );
    15. Examples //ACCELEROMETER var watchAccel = function () { var s = function ( a ){ document . getElementById ( 'x' ). innerHTML = roundNumber ( a . x ); document . getElementById ( 'y' ). innerHTML = roundNumber ( a . y ); document . getElementById ( 'z' ). innerHTML = roundNumber ( a . z ); }; var d = function (){}; var opt = {}; opt . frequency = 100 ; Timer = navigator . accelerometer . watchAcceleration ( s , f , opt ); } //CAMERA navigator . camera . getPicture ( dump_pic , fail , { quality : 50 }); function dump_pic ( data) { ... document . getElementById ( "test" ). src = "data:image/jpeg;base64," + data ; }
    16. Where's the trick? PhoneGap give us a startup project for every supported device. Every project is a simple application made of a web browser that work as a fullscreen app and where javascripts object will be injected. These objects has native API counterpart inside the device. We need to copy html, css, javascript and images into a specific project folder for every device that we need to deploy on. We also need to modify the project configuration, like project's name, author and so on... For Android copy these files into: ../my-android/assets/www/
    17. Just to explain... ...take a look at this piece of code extracted from DroidGap.java included in the Android startup project: private void bindBrowser(WebView appView) { gap = new PhoneGap( this , appView); geo = new GeoBroker(appView, this ); accel = new AccelListener( this , appView); launcher = new CameraLauncher(appView, this ); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface( gap , "DroidGap" ); appView.addJavascriptInterface( geo , "Geo" ); appView.addJavascriptInterface( accel , "Accel" ); appView.addJavascriptInterface( launcher , "GapCam" ); }
    18. Why Android?
      • Open Source
      • Linux and Java based (Dalvik)
      • So many Devices
      • OS highly customized
      ?
    19. Android 2.0 (Eclair) in deep
      • Multiple Google accounts management
      • Microsoft Excange Server support
      • Home, Menu and Back buttons become optional
      • New HTML5 web browser
      • Camera application improved (flash, digital zoom, etc...)
      • SMS and MMS are now searchable
    20. MOTOROLA DROID http://droiddoes.com
    21. What about Spring?
    22. SpringME
      • Object configuration through XML
      • No reflection needed, auto-code generation
      • The final package does not contain extra libraries
      • Developed and maintained by Wilfred Springer, ex Tom Tom Software Architect
      • Apache MAVEN artifact plugin
      • Designed for J2ME but also suitable for GWT and Android
    23. SpringME: how does it works?
      • Spring use reflection for Dependency Injection Class cl = Class.forName("Person"); Object instance = cl.newInstance(); Method meth = cl.getDeclaredMethod("setName"); method.invoke(instance, new Object[] { "Nick Hornby" }); --------------------------------------------------------- ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(...); BeanFactory factory = (BeanFactory) appContext; Person frank = (Person)factory.getBean(“frank”);
      • SpringME produce the code through the Apache Maven plugin Person instance = new Person(); instance.setName("Wilfred Springer"); --------------------------------------------------------- BeanFactory factory = new BeanFactory(); Person frank1 = (Person)factory.getBean(“frank”); Person frank2 = factory.getFrank();
    24. Android + Maven
      • Install the Android SDK
      • Setup the env variable ANDROID_SDK_15
      • Install Android into our maven repository , for example: mvn install:install-file -DgroupId=android -DartifactId=android -Dversion=1.5_r2 -Dpackaging=jar -Dfile=$ANDROID_SDK_15/platforms/android-1.5/android.jar
      • Let's create a brand new project: android create project --target 3 --name MavenAndroidExample --path ./maven-android-example --activity MavenAndroidActivity --package it.jesty.mavenandroid.example
    25. Android + Maven
      • Create a pom.xml file (we'll see it in the next slide)
      • Let's clean up the mess: rm -r bin build.xml build.properties libs
      • Create the emulator: android create avd --name mavenandroidadv --target 3
      • Execute the emulator: emulator -avd mavenandroidadv
      • Create our package with: mvn install (.apk file)
      • Let's deploy the .apk into our device: mvn com.jayway.maven.plugins.android.generation2:maven-android-plugin:deploy
    26. ... <dependencies> <dependency> <groupId> android </groupId> <artifactId> android </artifactId> <version> 1.5_r2 </version> <scope> provided </scope> </dependency> </dependencies> <build> <sourceDirectory> src </sourceDirectory> <plugins> <plugin> <groupId> com.jayway.maven.plugins.android.generation2 </groupId> <artifactId> maven-android-plugin </artifactId> <version> 2.1.0 </version> <configuration> <sdk> <path> ${env.ANDROID_SDK_15} </path> <platform> 1.5 </platform> </sdk> <deleteConflictingFiles> True </deleteConflictingFiles> </configuration> <extensions> true </extensions> </plugin> ... Android + Maven
    27.  
    28. Android + Maven + SpringME
      • Modify the pom.xml adding the SpringME plugin
      • Create the application-context.xml into /context: <beans> <bean id=&quot;ciao&quot; class=&quot;it.jesty....Greeting&quot; scope=&quot;prototype&quot;> <constructor-arg value=&quot;Ciao&quot; /> </bean> </beans>
      • Create the Greeting.java class
      • Modify the MavenAndroidActivity.java: public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); TextView tv = new TextView( this ); tv.setText(((Greeting)new BeanFactory().getBean( &quot;ciao&quot; )) .to( &quot;MavenAndroidActivity&quot; )); //oppure: tv.setText(((Greeting)new BeanFactory().getCiao()).to(...)); }
      • Repeat 8 and 9 steps mvn com.jayway.maven.plugins.android.generation2:maven-android-plugin:deploy
    29. ... <resources> <resource> <directory>${basedir}/context/</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory> ${basedir}/target/generated-sources/spring-me </directory> </resource> </resources> <plugins> <plugin> <groupId>me.springframework</groupId> <artifactId>spring-me-maven-plugin</artifactId> <version>1.0-SNAPSHOT</version> <executions> <execution> <goals> <goal>generate</goal> <goal>dot</goal> </goals> <phase>generate-sources</phase> </execution> </executions> <configuration> <contextFile> ${basedir}/context/application-context.xml </contextFile> <className> it.jesty.mavenandroid.example.BeanFactory </className> <dotFile>${basedir}/target/poloko-context.dot</dotFile> </configuration> </plugin> ...
    30. Android + Maven + SpringME <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot; http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring- beans-2.0.xsd&quot; default-lazy-init=&quot;true&quot; > <bean id=&quot;ciao&quot; class=&quot;it.jesty...Greeting&quot; scope=&quot;prototype&quot; > <constructor-arg value=&quot;Ciao&quot; /> </bean> <bean id=&quot;hello&quot; class=&quot;it.jest...Greeting&quot; scope=&quot;prototype&quot; > <constructor-arg value=&quot;Hello&quot; /> </bean> </beans>
    31. Android + Maven + SpringME package it.jesty.mavenandroid.example; public class Greeting { private String greeting; public Greeting(String greeting){ this .greeting = greeting; } public String to(String to){ return this .greeting + &quot;, &quot; + to; } }
    32.  
    33. Links and resources:
      • Android http://www.android.com
      • PhoneGap http://phonegap.com
      • SpringME http://springframework.me http://sourceforge.net/projects/springme/
      • SpringME book http://www.scribd.com/doc/8611209/Spring-ME
      • Maven for Android http://code.google.com/p/maven-android-plugin http://code.google.com/p/masa
      • Android development guidelines http://developer.android.com/guide/practices/design/performance.html
      • Android, IPhone and IPod Touch Big Picture http://mashable.com/2009/09/15/iphone-android-apps-visualized/
    34. Examples download: http://jesty.it/non-conventional-android-programming.zip The archive file contains:
      • PhoneGap for Android demo
      • Apache Maven for Android examples
      • SpringME examples
      ...all fully functional !!! :)
    35.  
    36.  

    + jestyjesty, 4 weeks ago

    custom

    398 views, 3 favs, 1 embeds more stats

    Learn as you can developing software for mobile dev more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 398
      • 385 on SlideShare
      • 13 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 12
    Most viewed embeds
    • 13 views on http://pronetics.wordpress.com

    more

    All embeds
    • 13 views on http://pronetics.wordpress.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories