Android Framework(I)Android Spring Json

Android Framework(I)Android Spring Json

1. Backgroud of Spring Android and Json
First, learn from spring.
Spring Mobile project that provides extensions to Spring MVC for developing mobile web apps.
Spring Android project that supports the development of native Android clients that communicate with spring-based back-ends.

Spring Mobile
1. A HandlerInterceptor that uses a DeviceResolver to detect the Device that originated the current HttpServletRequest.
2. The ability to inject the detected Device into @Controller methods and view templates to vary logic by device type.

Interceptor /WEB-INF/spring/appServlet/servlet-context.xml
<interceptors>
      <beans:bean class="org.springframework.mobile.device.mvc.DeviceResolvingHandlerInterceptor" />
</interceptors>

JSP template:
Please try again<c:if test="${!currentDevice.mobile}"> or <a href="<c:url value="/signup" />">sign up</a></c:if>

Tiles-based page layout:
<definition name="page" templateExpression="/WEB-INF/layouts/${currentDevice.mobile ? 'mobile/' : 'standard/'}page.jsp"

Spring Android
The client side need to exchange data with the server over HTTPS via REST. We need to store username and password credentials on the
device itself, we opted for OAuth. RestTemplate for the REST API calls, and Spring Security for the OAuth client.

RestTemplate restTemplate = new RestTemplate(new CommonsClientHttpRequestFactory());
Event event = restTemplate.getForObject("https://myapp.com/event/{name}", Event.class, "springone2gx");

Greenhouse project URL
http://www.springsource.org/greenhouse
Run the green house locally
http://www.springsource.org/greenhouse/guide

Web APP
get the source codes
git clone https://github.com/SpringSource/greenhouse.git greenhouse

Greenhouse for Android
get the source codes
git clone https://github.com/SpringSource/greenhouse-android.git greenhouse-android

>vi pom.xml
add sdk path and platform to them

<sdk>
   <path>/home/luohua/tools/android-sdk-linux_x86</path>
   <platform>7</platform>
</sdk>
<emulator>
<avd>G7</avd>
</emulator>

Another example:
svn checkout http://geonames-android.googlecode.com/svn/trunk/ geonames-android-read-only

spring android samples:
git clone git://github.com/SpringSource/spring-android-samples.git spring-android-samples

spring android source:
git clone --recursive git://github.com/SpringSource/spring-android.git spring-android

2. Spring Android and Maven

Maven Configuration
Maven Android Plugin
Android applications are deployed to the device as an apk file, not a jar. You must specify this in the packageing configuration.
<packaging>apk</packaging>
<build>
...snip...
</build>
<repositories>
...snip...
</repositories>

Build Enviroment
>vi /etc/enviroment
ANDROID_HOME=/home/luohua/tools/android-sdk-linux_x86
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/luohua/tools/android-sdk-linux_x86/tools:
/home/luohua/tools/android-sdk-linux_x86/platform-tools"

Configure an Android Virtual Device
...snip...

Sample Application
>git clone git://git.springsource.org/spring-mobile/samples.git spring-mobile-samples

>cd spring-android-showcase
start the server side
>cd server
>mvn install
>cp /home/luohua/.m2/repository/org/springframework/android/spring-android-showcase-server
/1.0.0-BUILD-SNAPSHOT/spring-android-showcase-server-1.0.0-BUILD-SNAPSHOT.war
/home/luohua/tools/apache-tomcat-7.0.12/webapps/spring-android-showcase-server.war
>bin/startup.sh
verify the server side with this URL
http://localhost:8080/spring-android-showcase-server/

run the Android Client
modify the pom.xml <sdk><path><platform><emulator><avd>
>mvn clean install
>mvn android:emulator-start

problem here, the window of the emulator is too big
solution:
>telnet localhost 5554
>window scale 0.65
>quit

>mvn android:deploy

Problem: pkg: /data/local/tmp/spring-android-showcase-client.apkFailure [INSTALL_FAILED_OLDER_SDK]
That is only because of the version.
verify the AndroidManifest.xml
<uses-sdk android:minSdkVersion="4" />

modify the pom.xml:
<platform>10</platform>
<avd>10</avd>

I find an app named spring-android

>adb logcat

we can see the logs.

3. Spring Android and Eclipse IDE
Installing Plugins using the Eclipse Marketplace Client
Help ----> Eclipse Marketplace...
m2eclipse-android    click 'Go' and 'Install'
egit                                     click 'Go' and 'Install'

And in another way, we can install this manly
ADT
https://dl-ssl.google.com/android/eclipse

MAVEN2
http://m2eclipse.sonatype.org/sites/m2e

MAVEN2-ANDROID
https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/

Fetch the Sample Project
>git clone git://git.springsource.org/spring-mobile/samples.git spring-mobile-samples

create a Android Project in existing directory of spring-android-showcase/client
enable mavenmanagement

create a Dynamic Web Project in existing directory of spring-android-showcase/server
enable mavenmanagement


references:
http://www.makeurownrules.com/rest-spring-maven-android
http://code.google.com/p/geonames-android/
http://blog.springsource.com/2010/12/17/spring-android-and-maven-part-1/
http://www.springsource.org/spring-android




你可能感兴趣的:(spring,android,json,git,mobile)