Permalink
Browse files

First version

  • Loading branch information...
1 parent d5d95fc commit be3e2f0edb9fbcf5e413c7728f3493c545f5a1c2 @lacostej committed Jun 15, 2009
View
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>myCityBikes</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.mycitybikes.android"
+ android:versionCode="1"
+ android:versionName="1.0.0">
+ <uses-sdk android:minSdkVersion="3"></uses-sdk>
+
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <uses-library android:name="com.google.android.maps" />
+ <activity android:name=".MyCityBikesActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
+ <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
+</manifest>
View
Oops, something went wrong.
View
Oops, something went wrong.
View
@@ -0,0 +1,22 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=Google Inc.:Google APIs:3
+# apk configurations. This property allows creation of APK files with limited
+# resources. For example, if your application contains many locales and
+# you wish to release multiple smaller apks instead of a large one, you can
+# define configuration to create apks with limited language sets.
+# Format is a comma separated list of configuration names. For each
+# configuration, a property will declare the resource configurations to
+# include. Example:
+# apk-configurations=european,northamerica
+# apk-config-european=en,fr,it,de,es
+# apk-config-northamerica=en,es
+apk-configurations=
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent" android:layout_height="fill_parent">
+
+ <com.mycitybikes.android.view.MapWithLocationsView
+ android:id="@+id/mapView" android:layout_width="fill_parent"
+ android:layout_height="fill_parent" android:enabled="true"
+ android:clickable="true" android:apiKey="0WwwQvyTsMW2pnzDwD-shPoLlhADsYWQkPDjHLA" />
+
+</RelativeLayout>
View
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">MyCityBikes</string>
+</resources>
@@ -0,0 +1,222 @@
+package com.mycitybikes.android;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.util.Log;
+
+import com.mycitybikes.android.model.BikeStationStatus;
+import com.mycitybikes.android.model.StationLocation;
+import com.mycitybikes.android.util.Utils;
+
+/**
+ * Class to perform ClearChannel specific bike station operations. We only support Oslo so
+ * far.
+ *
+ * @author jerome
+ */
+public class ClearChannel {
+
+ public static void loadOsloBikeLocations(Context context, List<StationLocation> stationLocations) {
+ try {
+ AssetManager assets = context.getAssets();
+ InputStream is = assets.open("oslo2.xml");
+ loadOsloStationLocations(is, stationLocations);
+
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "Failed to load Oslo bike station locations: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ static void loadOsloStationLocations(InputStream is, List<StationLocation> stationLocations) throws IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db;
+ Document dom;
+ try {
+ db = dbf.newDocumentBuilder();
+ dom = db.parse(is);
+ } catch (Exception e) {
+ throw new IllegalStateException("Unexpected parsing issue.", e);
+ }
+
+ Node stationsNode = dom.getFirstChild();
+ if (!"stations".equals(stationsNode.getNodeName())) {
+ throw new IllegalArgumentException("Unexpected XML:" + stationsNode.getNodeName());
+ }
+ Integer id = null;
+ String description= null;
+ Double latitude = null;
+ Double longitude = null;
+ NodeList stationsChildren = stationsNode.getChildNodes();
+ for (int i = 0; i < stationsChildren.getLength(); i++) {
+ Node stationNode = stationsChildren.item(i);
+ if (stationNode.getNodeType() != Element.ELEMENT_NODE) {
+ continue;
+ }
+ if (!"station".equals(stationNode.getNodeName())) {
+ throw new IllegalArgumentException("Unexpected XML:" + stationNode.getNodeName());
+ }
+ NodeList stationChildren = stationNode.getChildNodes();
+ for (int j = 0; j < stationChildren.getLength(); j++) {
+ Node child = stationChildren.item(j);
+ if (child.getNodeType() != Element.ELEMENT_NODE) {
+ continue;
+ }
+ if ("description".equals(child.getNodeName())) {
+ description = child.getFirstChild().getNodeValue().trim();
+ } else if ("longitude".equals(child.getNodeName())) {
+ longitude = new Double(child.getFirstChild().getNodeValue());
+ } else if ("latitude".equals(child.getNodeName())) {
+ latitude = new Double(child.getFirstChild().getNodeValue());
+ } else if ("id".equals(child.getNodeName())) {
+ id = new Integer(child.getFirstChild().getNodeValue());
+ } else {
+ throw new IllegalArgumentException("Unexpected format of the XML station status " + child.getNodeName());
+ }
+ }
+
+ final StationLocation stationLocation = new StationLocation(id, description, longitude, latitude);
+ stationLocations.add(stationLocation);
+ Log.v(Constants.TAG, "loaded stationLocation: " + stationLocation);
+ }
+ }
+
+ public static BikeStationStatus readBikeStationStatus(String httpUrl) {
+ try {
+ HttpParams params = new BasicHttpParams();
+ HttpConnectionParams.setConnectionTimeout(params, 5000);
+ HttpClient httpclient = new DefaultHttpClient(params);
+
+ HttpGet httpGet = new HttpGet(httpUrl);
+ HttpResponse response = httpclient.execute(httpGet);
+ return parseStatus(response.getEntity().getContent());
+ // listener.newWikiItems(wi);
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to read/parse status information", e);
+ }
+ }
+
+ static BikeStationStatus parseStatus(InputStream content) throws IOException {
+ String s = Utils.parseISToString(content);
+ s = s.substring(s.indexOf("<string"));
+
+ int start = s.indexOf(">") + 1;
+ int end = s.indexOf("</", start);
+ String encodedContent = s.substring(start, end);
+ String decodedContent = decode(encodedContent);
+
+ Log.v(Constants.TAG, "decodedContent: " + decodedContent);
+
+ InputStream is;
+ try {
+ is = new java.io.ByteArrayInputStream(decodedContent.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("Unexpected issue.", e);
+ }
+
+ return parseBikeStationStatusDOM(is);
+ }
+
+ /*
+ private static BikeStationStatus parseBikeStationStatusXstream(InputStream is) {
+ XStream xstream = new XStream(new DomDriver());
+ xstream.alias("station", BikeStationStatus.class);
+ xstream.aliasAttribute(BikeStationStatus.class, "readyBikes", "ready_bikes");
+ xstream.aliasAttribute(BikeStationStatus.class, "emptyLocks", "empty_locks");
+ // xstream.addImplicitCollection(WikiItems.class, "entries");
+
+ BikeStationStatus bikeStationStatus = (BikeStationStatus) xstream.fromXML(is);
+ return bikeStationStatus;
+ }
+ */
+
+ private static BikeStationStatus parseBikeStationStatusDOM(InputStream is) {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db;
+ Document dom;
+ try {
+ db = dbf.newDocumentBuilder();
+ dom = db.parse(is);
+ } catch (Exception e) {
+ throw new IllegalStateException("Unexpected parsing issue.", e);
+ }
+
+ Node stationNode = dom.getFirstChild();
+ if (!"station".equals(stationNode.getNodeName())) {
+ throw new IllegalArgumentException("Unexpected XML:" + stationNode.getNodeName());
+ }
+ BikeStationStatus bikeStationStatus = new BikeStationStatus();
+ NodeList stationChildren = stationNode.getChildNodes();
+ for (int i = 0; i < stationChildren.getLength(); i++) {
+ Node child = stationChildren.item(i);
+ if ("description".equals(child.getNodeName())) {
+ String description = child.getFirstChild().getNodeValue();
+ int splitIndex = description.indexOf('-');
+ if (splitIndex != -1) {
+ description = description.substring(splitIndex + 1);
+ }
+ bikeStationStatus.setDescription(description);
+ } else if ("longitute"/*sic...*/.equals(child.getNodeName())) {
+ bikeStationStatus.setLongitude(new Double(child.getFirstChild().getNodeValue()));
+ } else if ("latitude".equals(child.getNodeName())) {
+ bikeStationStatus.setLatitude(new Double(child.getFirstChild().getNodeValue()));
+ } else if ("online".equals(child.getNodeName())) {
+ bikeStationStatus.setOnline("1".equals(child.getFirstChild().getNodeValue()));
+ } else if ("empty_locks".equals(child.getNodeName())) {
+ bikeStationStatus.setEmptyLocks(new Integer(child.getFirstChild().getNodeValue()));
+ } else if ("ready_bikes".equals(child.getNodeName())) {
+ bikeStationStatus.setReadyBikes(new Integer(child.getFirstChild().getNodeValue()));
+ } else {
+ throw new IllegalArgumentException("Unexpected format of the XML station status " + child.getNodeName());
+ }
+ }
+
+ return bikeStationStatus;
+ }
+
+ public static String getStationInfo(int stationIndex) {
+ String result;
+ try {
+ BikeStationStatus status = readBikeStationStatus(stationIndex);
+ if (!status.isOnline()) {
+ result = status.getDescription() + "\n\n(no station information)";
+ } else {
+ result = status.getDescription() + "\n\n" + status.getReadyBikes() + " bike(s)\n" + status.getEmptyLocks() + " slot(s)";
+ }
+ } catch (Exception e) {
+ result = "Error: station information not available";
+ }
+ return result;
+ }
+
+ public static BikeStationStatus readBikeStationStatus(int stationId) {
+ return ClearChannel.readBikeStationStatus("http://smartbikeportal.clearchannel.no/public/mobapp/maq.asmx/getRack?id=" + stationId);
+ }
+
+ private static String decode(String content) {
+ content = content.replaceAll("&lt;", "<");
+ content = content.replaceAll("&gt;", ">");
+ return content;
+ }
+
+}
@@ -0,0 +1,7 @@
+package com.mycitybikes.android;
+
+public class Constants {
+
+ public static final String TAG = "MyCityBikes";
+
+}
Oops, something went wrong.

0 comments on commit be3e2f0

Please sign in to comment.