Permalink
Browse files

Migrating to Android 4.1; new permissions, new threading in BaseConne…

…ctor
  • Loading branch information...
1 parent d1af870 commit b9f30a688c5d11bf73f4a08a3902b56dab14c950 @jottinger committed Oct 15, 2012
@@ -1,21 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.redhat.osas.sensor" android:versionCode="1" android:versionName="1.0-SNAPSHOT">
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.redhat.osas.sensor"
+ android:versionCode="1"
+ android:versionName="1.0-SNAPSHOT">
<uses-feature android:name="android.hardware.sensor.light"/>
- <uses-feature android:name="android.hardware.telephony"/>
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- <uses-permission android:name="android.permission.INTERNET"/>
-
- <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <uses-feature
+ android:name="android.hardware.telephony"/>
+ <uses-permission
+ android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission
+ android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission
+ android:name="android.permission.INTERNET"/>
+ <uses-sdk android:minSdkVersion="15"/>
+ <application
+ android:icon="@drawable/icon"
+ android:label="@string/app_name">
<activity android:name=".LightSensorActivity">
<intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
+ <action
+ android:name="android.intent.action.MAIN"/>
+ <category
+ android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
-
</manifest>
View
@@ -1,73 +1,73 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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>
- <parent>
- <artifactId>sensor</artifactId>
- <groupId>com.redhat.osas.sensor</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <groupId>com.redhat.osas.sensor</groupId>
- <artifactId>android-sensor</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>apk</packaging>
- <name>android-sensor</name>
-
- <properties>
- <platform.version>2.3.3</platform.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>com.google.android</groupId>
- <artifactId>android</artifactId>
- <version>${platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>common-data</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>httpconnector</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.9.8</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>com.jayway.maven.plugins.android.generation2</groupId>
- <artifactId>android-maven-plugin</artifactId>
- <version>3.1.1</version>
- <configuration>
- <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
- <assetsDirectory>${project.basedir}/assets</assetsDirectory>
- <resourceDirectory>${project.basedir}/res</resourceDirectory>
- <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
- <sdk>
- <platform>10</platform>
- </sdk>
- <undeployBeforeDeploy>true</undeployBeforeDeploy>
- </configuration>
- <extensions>true</extensions>
- </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>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+ <parent>
+ <artifactId>sensor</artifactId>
+ <groupId>com.redhat.osas.sensor</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <groupId>com.redhat.osas.sensor</groupId>
+ <artifactId>android-sensor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>apk</packaging>
+ <name>android-sensor</name>
+
+ <properties>
+ <platform.version>2.3.3</platform.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android</artifactId>
+ <version>${platform.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>common-data</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>httpconnector</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.8</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
+ <artifactId>android-maven-plugin</artifactId>
+ <version>3.1.1</version>
+ <configuration>
+ <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
+ <assetsDirectory>${project.basedir}/assets</assetsDirectory>
+ <resourceDirectory>${project.basedir}/res</resourceDirectory>
+ <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
+ <sdk>
+ <platform>15</platform>
+ </sdk>
+ <undeployBeforeDeploy>true</undeployBeforeDeploy>
+ </configuration>
+ <extensions>true</extensions>
+ </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>
+</project>
@@ -2,6 +2,8 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
public abstract class BaseConnector implements Connector {
public static final String ERROR_MESSAGE =
@@ -33,14 +35,21 @@ public void disconnect() {
}
@Override
- public void publish(String data) {
- if (!isConnected()) {
- if (uri == null) {
- throw new ConnectorException(ERROR_MESSAGE);
+ public void publish(final String data) {
+ ExecutorService service = Executors.newSingleThreadExecutor();
+ service.submit(new Runnable() {
+ @Override
+ public void run() {
+ if (!isConnected()) {
+ if (uri == null) {
+ throw new ConnectorException(ERROR_MESSAGE);
+ }
+ connect(uri);
+ }
+ doPublish(data);
}
- connect(uri);
- }
- doPublish(data);
+ });
+ service.shutdown();
}
protected void doPublish(String data) {
@@ -18,8 +18,7 @@
HttpPost httppost;
@Override
- public void connect(String uri) {
- this.uri=uri;
+ protected void doConnect(String URI) {
httppost = new HttpPost(uri);
}

0 comments on commit b9f30a6

Please sign in to comment.