Non Conventional Android Programming En

2,145
-1

Published on

Learn as you can developing software for mobile devices using only html, css and javascript and how you can use Spring Framework in software for mobile devices

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,145
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
56
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Non Conventional Android Programming En

  1. 1. Non-conventional Android Programming
  2. 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. 3. http://www.pro-netics.it [email_address]
  4. 4. Once upon a time...
  5. 5. New Features <ul><li>GPS
  6. 6. Compass
  7. 7. Camere
  8. 8. Hi-Res Screen
  9. 9. WI-FI
  10. 10. UMTS / HSPDA
  11. 11. Multi-touch </li></ul>
  12. 12. Where we going?
  13. 13. (market)
  14. 14. Too much devices
  15. 15. Many languages for many devices <ul><li>IPhone: Objective C
  16. 16. Android: Java
  17. 17. BlackBerry: Java
  18. 18. Nokia/Symbian: Java e C++
  19. 19. Windows Mobile: .NET e C </li></ul>
  20. 20. Write once, run anywhere Do you remember?
  21. 21. PhoneGap HTML + JAVASCRIPT + CSS = PhoneGap.com
  22. 22. PhoneGap CROSS PLATFORM + API NATIVE INTERFACES + OPEN SOURCE = PhoneGap.com
  23. 23. What I'm able to do? ...and coming soon: camera, maps and file manager
  24. 24. Examples //GEO REFERENCING var getLocation = function () { var suc = function ( p ){ alert ( p . coords . latitude + &quot; &quot; + p . coords . longitude ); }; var fail = function (){ alert ( &quot;Location not available!&quot; );}; navigator . geolocation . getCurrentPosition ( suc , fail , undefined ); } //VIBRACALL navigator . notification . vibrate ( 0 ); //BEEEEEEP navigator . notification . beep ( 2 );
  25. 25. 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 ( &quot;test&quot; ). src = &quot;data:image/jpeg;base64,&quot; + data ; }
  26. 26. 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/
  27. 27. 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 , &quot;DroidGap&quot; ); appView.addJavascriptInterface( geo , &quot;Geo&quot; ); appView.addJavascriptInterface( accel , &quot;Accel&quot; ); appView.addJavascriptInterface( launcher , &quot;GapCam&quot; ); }
  28. 28. Why Android? <ul><li>Open Source
  29. 29. Linux and Java based (Dalvik)
  30. 30. So many Devices
  31. 31. OS highly customized </li></ul>?
  32. 32. Android 2.0 (Eclair) in deep <ul><li>Multiple Google accounts management
  33. 33. Microsoft Excange Server support
  34. 34. Home, Menu and Back buttons become optional
  35. 35. New HTML5 web browser
  36. 36. Camera application improved (flash, digital zoom, etc...)
  37. 37. SMS and MMS are now searchable </li></ul>
  38. 38. MOTOROLA DROID http://droiddoes.com
  39. 39. What about Spring?
  40. 40. SpringME <ul><li>Object configuration through XML
  41. 41. No reflection needed, auto-code generation
  42. 42. The final package does not contain extra libraries
  43. 43. Developed and maintained by Wilfred Springer, ex Tom Tom Software Architect
  44. 44. Apache MAVEN artifact plugin
  45. 45. Designed for J2ME but also suitable for GWT and Android </li></ul>
  46. 46. SpringME: how does it works? <ul><li>Spring use reflection for Dependency Injection Class cl = Class.forName(&quot;Person&quot;); Object instance = cl.newInstance(); Method meth = cl.getDeclaredMethod(&quot;setName&quot;); method.invoke(instance, new Object[] { &quot;Nick Hornby&quot; }); --------------------------------------------------------- ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(...); BeanFactory factory = (BeanFactory) appContext; Person frank = (Person)factory.getBean(“frank”);
  47. 47. SpringME produce the code through the Apache Maven plugin Person instance = new Person(); instance.setName(&quot;Wilfred Springer&quot;); --------------------------------------------------------- BeanFactory factory = new BeanFactory(); Person frank1 = (Person)factory.getBean(“frank”); Person frank2 = factory.getFrank(); </li></ul>
  48. 48. Android + Maven <ul><li>Install the Android SDK
  49. 49. Setup the env variable ANDROID_SDK_15
  50. 50. 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
  51. 51. 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 </li></ul>
  52. 52. Android + Maven <ul><li>Create a pom.xml file (we'll see it in the next slide)
  53. 53. Let's clean up the mess: rm -r bin build.xml build.properties libs
  54. 54. Create the emulator: android create avd --name mavenandroidadv --target 3
  55. 55. Execute the emulator: emulator -avd mavenandroidadv
  56. 56. Create our package with: mvn install (.apk file)
  57. 57. Let's deploy the .apk into our device: mvn com.jayway.maven.plugins.android.generation2:maven-android-plugin:deploy </li></ul>
  58. 58. ... <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
  59. 60. Android + Maven + SpringME <ul><li>Modify the pom.xml adding the SpringME plugin
  60. 61. 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>
  61. 62. Create the Greeting.java class
  62. 63. 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(...)); }
  63. 64. Repeat 8 and 9 steps mvn com.jayway.maven.plugins.android.generation2:maven-android-plugin:deploy </li></ul>
  64. 65. ... <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> ...
  65. 66. 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>
  66. 67. 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; } }
  67. 69. Links and resources: <ul><li>Android http://www.android.com
  68. 70. PhoneGap http://phonegap.com
  69. 71. SpringME http://springframework.me http://sourceforge.net/projects/springme/
  70. 72. SpringME book http://www.scribd.com/doc/8611209/Spring-ME
  71. 73. Maven for Android http://code.google.com/p/maven-android-plugin http://code.google.com/p/masa
  72. 74. Android development guidelines http://developer.android.com/guide/practices/design/performance.html
  73. 75. Android, IPhone and IPod Touch Big Picture http://mashable.com/2009/09/15/iphone-android-apps-visualized/ </li></ul>
  74. 76. Examples download: http://jesty.it/non-conventional-android-programming.zip The archive file contains: <ul><li>PhoneGap for Android demo
  75. 77. Apache Maven for Android examples
  76. 78. SpringME examples </li></ul>...all fully functional !!! :)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×