Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pressureNET 2.1

  • Loading branch information...
commit a92e69760f37d8c0c6016ae254499e57cf910f9e 1 parent 0dedebf
@JacobSheehy authored
Showing with 3,394 additions and 0 deletions.
  1. +59 −0 AndroidManifest.xml
  2. +40 −0 proguard.cfg
  3. +11 −0 project.properties
  4. BIN  res/drawable-hdpi/bg_widget_1.png
  5. BIN  res/drawable-hdpi/bg_widget_2.png
  6. BIN  res/drawable-hdpi/bg_widget_3.png
  7. BIN  res/drawable-hdpi/black.9.png
  8. BIN  res/drawable-hdpi/border.9.png
  9. BIN  res/drawable-hdpi/button_error.png
  10. BIN  res/drawable-hdpi/button_normal.png
  11. BIN  res/drawable-hdpi/button_pressed.png
  12. BIN  res/drawable-hdpi/button_success.png
  13. BIN  res/drawable-hdpi/ic_launcher.png
  14. BIN  res/drawable-hdpi/ic_logo.png
  15. BIN  res/drawable-hdpi/ic_marker.png
  16. BIN  res/drawable-hdpi/ic_menu_barometer.png
  17. BIN  res/drawable-hdpi/ic_menu_log.png
  18. BIN  res/drawable-hdpi/ic_menu_refresh.png
  19. BIN  res/drawable-hdpi/ic_menu_settings.png
  20. BIN  res/drawable-hdpi/ic_menu_stats.png
  21. BIN  res/drawable-hdpi/ic_menu_update.png
  22. BIN  res/drawable-hdpi/ic_menu_vis.png
  23. BIN  res/drawable-hdpi/ic_tend_down.png
  24. BIN  res/drawable-hdpi/ic_tend_up.png
  25. BIN  res/drawable-hdpi/icon.png
  26. BIN  res/drawable-hdpi/marker.png
  27. BIN  res/drawable-hdpi/marker_blue_dark_hdpi.png
  28. BIN  res/drawable-hdpi/marker_green_dark_hdpi.png
  29. BIN  res/drawable-hdpi/simplidark.9.png
  30. BIN  res/drawable-hdpi/subtleglow.9.png
  31. BIN  res/drawable-ldpi/bg_widget_1.png
  32. BIN  res/drawable-ldpi/bg_widget_2.png
  33. BIN  res/drawable-ldpi/bg_widget_3.png
  34. BIN  res/drawable-ldpi/black.9.png
  35. BIN  res/drawable-ldpi/border.9.png
  36. BIN  res/drawable-ldpi/button_error.png
  37. BIN  res/drawable-ldpi/button_normal.png
  38. BIN  res/drawable-ldpi/button_pressed.png
  39. BIN  res/drawable-ldpi/button_success.png
  40. BIN  res/drawable-ldpi/ic_launcher.png
  41. BIN  res/drawable-ldpi/ic_logo.png
  42. BIN  res/drawable-ldpi/ic_marker.png
  43. BIN  res/drawable-ldpi/ic_menu_barometer.png
  44. BIN  res/drawable-ldpi/ic_menu_log.png
  45. BIN  res/drawable-ldpi/ic_menu_refresh.png
  46. BIN  res/drawable-ldpi/ic_menu_settings.png
  47. BIN  res/drawable-ldpi/ic_menu_stats.png
  48. BIN  res/drawable-ldpi/ic_menu_update.png
  49. BIN  res/drawable-ldpi/ic_menu_vis.png
  50. BIN  res/drawable-ldpi/ic_tend_down.png
  51. BIN  res/drawable-ldpi/ic_tend_up.png
  52. BIN  res/drawable-ldpi/icon.png
  53. BIN  res/drawable-ldpi/marker.png
  54. BIN  res/drawable-ldpi/simplidark.9.png
  55. BIN  res/drawable-ldpi/subtleglow.9.png
  56. BIN  res/drawable-mdpi/bg_widget_1.png
  57. BIN  res/drawable-mdpi/bg_widget_2.png
  58. BIN  res/drawable-mdpi/bg_widget_3.png
  59. BIN  res/drawable-mdpi/black.9.png
  60. BIN  res/drawable-mdpi/border.9.png
  61. BIN  res/drawable-mdpi/button_error.png
  62. BIN  res/drawable-mdpi/button_normal.png
  63. BIN  res/drawable-mdpi/button_pressed.png
  64. BIN  res/drawable-mdpi/button_success.png
  65. BIN  res/drawable-mdpi/ic_launcher.png
  66. BIN  res/drawable-mdpi/ic_logo.png
  67. BIN  res/drawable-mdpi/ic_marker.png
  68. BIN  res/drawable-mdpi/ic_menu_barometer.png
  69. BIN  res/drawable-mdpi/ic_menu_log.png
  70. BIN  res/drawable-mdpi/ic_menu_refresh.png
  71. BIN  res/drawable-mdpi/ic_menu_settings.png
  72. BIN  res/drawable-mdpi/ic_menu_stats.png
  73. BIN  res/drawable-mdpi/ic_menu_update.png
  74. BIN  res/drawable-mdpi/ic_menu_vis.png
  75. BIN  res/drawable-mdpi/ic_tend_down.png
  76. BIN  res/drawable-mdpi/ic_tend_up.png
  77. BIN  res/drawable-mdpi/icon.png
  78. BIN  res/drawable-mdpi/marker.png
  79. BIN  res/drawable-mdpi/simplidark.9.png
  80. BIN  res/drawable-mdpi/subtleglow.9.png
  81. BIN  res/drawable-xhdpi/bg_widget_1.png
  82. BIN  res/drawable-xhdpi/bg_widget_2.png
  83. BIN  res/drawable-xhdpi/bg_widget_3.png
  84. BIN  res/drawable-xhdpi/black.9.png
  85. BIN  res/drawable-xhdpi/border.9.png
  86. BIN  res/drawable-xhdpi/button_error.png
  87. BIN  res/drawable-xhdpi/button_normal.png
  88. BIN  res/drawable-xhdpi/button_pressed.png
  89. BIN  res/drawable-xhdpi/button_success.png
  90. BIN  res/drawable-xhdpi/ic_launcher.png
  91. BIN  res/drawable-xhdpi/ic_logo.png
  92. BIN  res/drawable-xhdpi/ic_marker.png
  93. BIN  res/drawable-xhdpi/ic_menu_barometer.png
  94. BIN  res/drawable-xhdpi/ic_menu_log.png
  95. BIN  res/drawable-xhdpi/ic_menu_refresh.png
  96. BIN  res/drawable-xhdpi/ic_menu_settings.png
  97. BIN  res/drawable-xhdpi/ic_menu_stats.png
  98. BIN  res/drawable-xhdpi/ic_menu_update.png
  99. BIN  res/drawable-xhdpi/ic_menu_vis.png
  100. BIN  res/drawable-xhdpi/ic_tend_down.png
  101. BIN  res/drawable-xhdpi/ic_tend_up.png
  102. BIN  res/drawable-xhdpi/marker.png
  103. BIN  res/drawable-xhdpi/simplidark.9.png
  104. BIN  res/drawable-xhdpi/subtleglow.9.png
  105. BIN  res/drawable/preview.png
  106. +8 −0 res/drawable/widget_button_drawable.xml
  107. +22 −0 res/layout/logviewer.xml
  108. +33 −0 res/layout/main.xml
  109. +28 −0 res/layout/settings.xml
  110. +3 −0  res/layout/singleuserchart.xml
  111. +72 −0 res/layout/small_widget_layout.xml
  112. +38 −0 res/menu/settings.xml
  113. +4 −0 res/values-v14/dimens.xml
  114. +4 −0 res/values/dimens.xml
  115. +45 −0 res/values/strings.xml
  116. +10 −0 res/values/styles.xml
  117. +7 −0 res/xml/widget_info.xml
  118. +70 −0 src/ca/cumulonimbus/barometernetwork/BarometerMapView.java
  119. +1,050 −0 src/ca/cumulonimbus/barometernetwork/BarometerNetworkActivity.java
  120. +68 −0 src/ca/cumulonimbus/barometernetwork/BarometerReading.java
  121. +150 −0 src/ca/cumulonimbus/barometernetwork/DBAdapter.java
  122. +15 −0 src/ca/cumulonimbus/barometernetwork/GeneralBroadcastReceiver.java
  123. +7 −0 src/ca/cumulonimbus/barometernetwork/LocalChartActivity.java
  124. +33 −0 src/ca/cumulonimbus/barometernetwork/LogViewerActivity.java
  125. +67 −0 src/ca/cumulonimbus/barometernetwork/ReadingSender.java
  126. +73 −0 src/ca/cumulonimbus/barometernetwork/ScienceHandler.java
  127. +60 −0 src/ca/cumulonimbus/barometernetwork/SecureHttpClient.java
  128. +314 −0 src/ca/cumulonimbus/barometernetwork/SettingsActivity.java
  129. +128 −0 src/ca/cumulonimbus/barometernetwork/SingleUserChartActivity.java
  130. +469 −0 src/ca/cumulonimbus/barometernetwork/SubmitReadingService.java
  131. +81 −0 src/ca/cumulonimbus/barometernetwork/Unit.java
  132. +299 −0 src/ca/cumulonimbus/barometernetwork/WidgetButtonService.java
  133. +126 −0 src/ca/cumulonimbus/barometernetwork/WidgetProvider.java
View
59 AndroidManifest.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="ca.cumulonimbus.barometernetwork"
+ android:versionCode="210"
+ android:versionName="2.1">
+ <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="14" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <application android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name">
+ <activity android:name="ca.cumulonimbus.barometernetwork.SettingsActivity"
+ android:label="@string/settings"
+ android:theme="@android:style/Theme.Holo.Light.Dialog"
+ android:excludeFromRecents="true">
+ </activity>
+
+ <activity android:name="ca.cumulonimbus.barometernetwork.LogViewerActivity"
+ android:label="@string/logViewer"
+ android:excludeFromRecents="true"
+ android:theme="@android:style/Theme.Holo.Light.Dialog"></activity>
+ <activity android:name="ca.cumulonimbus.barometernetwork.SingleUserChartActivity"
+ android:label="@string/chartView"
+ android:excludeFromRecents="true"
+ android:theme="@android:style/Theme.Holo.Light.Dialog"></activity>
+ <activity android:name="ca.cumulonimbus.barometernetwork.BarometerNetworkActivity"
+ android:label="@string/app_name"
+ android:theme="@style/CustomTheme"
+ android:logo="@drawable/ic_launcher">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <receiver android:name=".WidgetProvider" >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ <action android:name="ca.cumulonimbus.barometernetwork.WidgetProvider.ACTION_SUBMIT_AND_UPDATE"/>
+ <action android:name="ca.cumulonimbus.barometernetwork.WidgetProvider.ACTION_UPDATEUI"/>
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" />
+ </receiver>
+ <receiver android:name="ca.cumulonimbus.barometernetwork.GeneralBroadcastReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
+ <service android:enabled="true" android:name=".SubmitReadingService">
+ <action android:name="ca.cumulonimbus.barometernetwork.WidgetProvider.ACTION_SUBMIT_SINGLE"/>
+ </service>
+ <service android:enabled="true" android:name=".WidgetButtonService">
+ <intent-filter>
+ <action android:name="ca.cumulonimbus.barometernetwork.WidgetProvider.ACTION_UPDATEUI"/>
+ </intent-filter>
+ </service>
+ <uses-library android:name="com.google.android.maps" />
+ </application>
+</manifest>
View
40 proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
11 project.properties
@@ -0,0 +1,11 @@
+# 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,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=Google Inc.:Google APIs:12
View
BIN  res/drawable-hdpi/bg_widget_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/bg_widget_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/bg_widget_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/black.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/border.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/button_error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/button_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/button_pressed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/button_success.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_marker.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_barometer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_log.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_settings.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_stats.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_update.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_menu_vis.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_tend_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/ic_tend_up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/marker.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/marker_blue_dark_hdpi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/marker_green_dark_hdpi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-hdpi/simplidark.9.png
Diff not rendered
View
BIN  res/drawable-hdpi/subtleglow.9.png
Diff not rendered
View
BIN  res/drawable-ldpi/bg_widget_1.png
Diff not rendered
View
BIN  res/drawable-ldpi/bg_widget_2.png
Diff not rendered
View
BIN  res/drawable-ldpi/bg_widget_3.png
Diff not rendered
View
BIN  res/drawable-ldpi/black.9.png
Diff not rendered
View
BIN  res/drawable-ldpi/border.9.png
Diff not rendered
View
BIN  res/drawable-ldpi/button_error.png
Diff not rendered
View
BIN  res/drawable-ldpi/button_normal.png
Diff not rendered
View
BIN  res/drawable-ldpi/button_pressed.png
Diff not rendered
View
BIN  res/drawable-ldpi/button_success.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_launcher.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_logo.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_marker.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_barometer.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_log.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_refresh.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_settings.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_stats.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_update.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_menu_vis.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_tend_down.png
Diff not rendered
View
BIN  res/drawable-ldpi/ic_tend_up.png
Diff not rendered
View
BIN  res/drawable-ldpi/icon.png
Diff not rendered
View
BIN  res/drawable-ldpi/marker.png
Diff not rendered
View
BIN  res/drawable-ldpi/simplidark.9.png
Diff not rendered
View
BIN  res/drawable-ldpi/subtleglow.9.png
Diff not rendered
View
BIN  res/drawable-mdpi/bg_widget_1.png
Diff not rendered
View
BIN  res/drawable-mdpi/bg_widget_2.png
Diff not rendered
View
BIN  res/drawable-mdpi/bg_widget_3.png
Diff not rendered
View
BIN  res/drawable-mdpi/black.9.png
Diff not rendered
View
BIN  res/drawable-mdpi/border.9.png
Diff not rendered
View
BIN  res/drawable-mdpi/button_error.png
Diff not rendered
View
BIN  res/drawable-mdpi/button_normal.png
Diff not rendered
View
BIN  res/drawable-mdpi/button_pressed.png
Diff not rendered
View
BIN  res/drawable-mdpi/button_success.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_launcher.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_logo.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_marker.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_barometer.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_log.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_refresh.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_settings.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_stats.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_update.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_menu_vis.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_tend_down.png
Diff not rendered
View
BIN  res/drawable-mdpi/ic_tend_up.png
Diff not rendered
View
BIN  res/drawable-mdpi/icon.png
Diff not rendered
View
BIN  res/drawable-mdpi/marker.png
Diff not rendered
View
BIN  res/drawable-mdpi/simplidark.9.png
Diff not rendered
View
BIN  res/drawable-mdpi/subtleglow.9.png
Diff not rendered
View
BIN  res/drawable-xhdpi/bg_widget_1.png
Diff not rendered
View
BIN  res/drawable-xhdpi/bg_widget_2.png
Diff not rendered
View
BIN  res/drawable-xhdpi/bg_widget_3.png
Diff not rendered
View
BIN  res/drawable-xhdpi/black.9.png
Diff not rendered
View
BIN  res/drawable-xhdpi/border.9.png
Diff not rendered
View
BIN  res/drawable-xhdpi/button_error.png
Diff not rendered
View
BIN  res/drawable-xhdpi/button_normal.png
Diff not rendered
View
BIN  res/drawable-xhdpi/button_pressed.png
Diff not rendered
View
BIN  res/drawable-xhdpi/button_success.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_launcher.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_logo.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_marker.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_barometer.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_log.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_refresh.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_settings.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_stats.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_update.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_menu_vis.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_tend_down.png
Diff not rendered
View
BIN  res/drawable-xhdpi/ic_tend_up.png
Diff not rendered
View
BIN  res/drawable-xhdpi/marker.png
Diff not rendered
View
BIN  res/drawable-xhdpi/simplidark.9.png
Diff not rendered
View
BIN  res/drawable-xhdpi/subtleglow.9.png
Diff not rendered
View
BIN  res/drawable/preview.png
Diff not rendered
View
8 res/drawable/widget_button_drawable.xml
@@ -0,0 +1,8 @@
+ <selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true"
+ android:drawable="@drawable/button_pressed" /> <!-- pressed -->
+ <item android:state_focused="true"
+ android:drawable="@drawable/button_success" /> <!-- focused -->
+ <item android:drawable="@drawable/button_normal" /> <!-- default -->
+ </selector>
+
View
22 res/layout/logviewer.xml
@@ -0,0 +1,22 @@
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/linearLayout1"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:minWidth="350dip"
+ >
+
+ <EditText
+ android:id="@+id/editLog"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="top"
+ android:layout_weight="1"
+ android:editable="false"
+ android:maxLines="10"
+ android:scrollbars="vertical"
+ android:textSize="8pt" >
+
+ </EditText>
+
+ </LinearLayout>
View
33 res/layout/main.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+ <LinearLayout android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:id="@+id/fullLayout" android:weightSum="1">
+ <LinearLayout
+ android:id="@+id/topButtonLayout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal" >
+ <TextView android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/textReading"
+ android:text="@string/empty"
+ android:gravity="right"></TextView>
+ </LinearLayout>
+ <LinearLayout android:layout_width="match_parent" android:id="@+id/layoutMapContainer" android:layout_height="match_parent">
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:weightSum="1" android:id="@+id/layoutMapView" android:layout_height="1180dp">
+ <ca.cumulonimbus.barometernetwork.BarometerMapView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mapview"
+ android:layout_width="fill_parent"
+ android:clickable="true"
+ android:apiKey=""
+ android:layout_height="fill_parent"
+ />
+ </LinearLayout>
+ </LinearLayout>
+ </LinearLayout>
+</LinearLayout>
View
28 res/layout/settings.xml
@@ -0,0 +1,28 @@
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:weightSum="1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/outsideLayout" android:minWidth="450dip" android:minHeight="200dip" >
+ <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
+ <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
+ <CheckBox android:id="@+id/checkboxRefresh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/refreshFrequency" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_weight="0.5" android:minWidth="100dip"></CheckBox>
+ <Spinner
+ android:id="@+id/spinnerFrequency"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:layout_weight="0.5"
+ android:minWidth="100dip" >
+ </Spinner>
+ </TableRow>
+ <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content">
+ <TextView android:id="@+id/textUnits" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/units" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_gravity="center_vertical" android:layout_weight="0.5"></TextView>
+ <Spinner android:layout_height="wrap_content" android:id="@+id/spinnerUnits" android:layout_width="257dip" android:layout_weight="0.5" android:layout_gravity="right"></Spinner>
+ </TableRow>
+ <TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right">
+
+ <Button android:text="@string/delete" android:id="@+id/buttonDelete" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+ </TableRow>
+ <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right">
+
+ <Button android:text="@string/close" android:id="@+id/buttonClose" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+ </TableRow>
+ </TableLayout>
+ </LinearLayout>
View
3  res/layout/singleuserchart.xml
@@ -0,0 +1,3 @@
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layoutChartView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="220dip" android:minHeight="350dip">
+ <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webViewChart"></WebView>
+ </LinearLayout>
View
72 res/layout/small_widget_layout.xml
@@ -0,0 +1,72 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="@dimen/widget_margin"
+ >
+
+ <LinearLayout
+ android:id="@+id/layoutSmallWidget"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/bg_widget_2" >
+
+ <ImageButton
+ android:id="@+id/widgetSmallSubmitButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:src="@drawable/widget_button_drawable"
+ android:paddingLeft="8dp"
+ android:background="@null"
+ android:maxHeight="62dp"/>
+
+
+ <LinearLayout
+ android:id="@+id/linearLayout1"
+ android:layout_width="match_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:paddingLeft="-5dp"
+ >
+
+
+ <ImageView
+ android:id="@+id/widget_tendency_image_up"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@null"
+ android:maxHeight="62dp"
+ android:paddingBottom="25dp"
+ android:paddingTop="8dp"
+ android:src="@drawable/ic_tend_up"
+ android:layout_gravity="top"/>
+
+ <ImageView
+ android:id="@+id/widget_tendency_image_down"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@null"
+ android:maxHeight="62dp"
+ android:src="@drawable/ic_tend_down"
+ android:visibility="invisible"
+ android:layout_gravity="bottom"/>
+
+
+ </LinearLayout>
+
+
+ <TextView
+ android:id="@+id/widgetSmallText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:paddingLeft="3dp"
+ android:paddingRight="3dp"
+ android:clickable="true"
+ />
+
+ </LinearLayout>
+
+
+
+</FrameLayout>
View
38 res/menu/settings.xml
@@ -0,0 +1,38 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <!--
+ <item android:id="@+id/menu_load_data_vis"
+ android:title="@string/data_visualization"
+ android:icon="@drawable/ic_menu_vis"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+ -->
+ <item android:id="@+id/menu_my_info"
+ android:title="@string/my_info"
+ android:icon="@drawable/ic_menu_stats"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+ <item android:id="@+id/menu_submit_reading"
+ android:title="@string/submitReading"
+ android:icon="@drawable/ic_menu_update"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+ <item android:id="@+id/menu_log_viewer"
+ android:title="@string/view_log"
+ android:icon="@drawable/ic_menu_log"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+ <!--
+ <item android:id="@+id/menu_reload"
+ android:title="@string/load"
+ android:icon="@drawable/ic_menu_refresh"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+ -->
+
+ <item android:id="@+id/menu_settings"
+ android:title="@string/settings"
+ android:icon="@drawable/ic_menu_settings"
+ android:enabled="true"
+ android:showAsAction="ifRoom|withText" />
+
+</menu>
View
4 res/values-v14/dimens.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <dimen name="widget_margin">0dp</dimen>
+</resources>
View
4 res/values/dimens.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <dimen name="widget_margin">15dp</dimen>
+</resources>
View
45 res/values/strings.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">pressureNET</string>
+ <string name="currentReading">Current Reading:</string>
+ <string name="empty"></string>
+ <string name="submitReading">Submit Reading</string>
+ <string name="addDataToMap">Add to Map</string>
+ <string name="load">Reload</string>
+ <string name="settings">Settings</string>
+ <string name="showSettings">Show Settings</string>
+ <string name="hideSettings">Hide Settings</string>
+ <string name="cacheSetting">Cache Data (up to 1M)</string>
+ <string name="enableAuto">Enable Auto-Submit</string>
+ <string name="disableAuto">Disable Auto-Submit</string>
+ <string name="statusStart">Status: </string>
+ <string name="chartView">Chart View (millibars over days)</string>
+ <string name="refreshFrequency">Auto-Submit</string>
+ <string name="submitEvery">Submit Every:</string>
+ <string-array name="refresh_frequency">
+ <item>1 minute</item>
+ <item>5 minutes</item>
+ <item>10 minutes</item>
+ <item>1 hour</item>
+ <item>6 hours</item>
+ <item>12 hours</item>
+ <item>1 day</item>
+ <item>1 week</item>
+ </string-array>
+ <string-array name="default_units">
+ <item>Millibars (mbar)</item>
+ <item>Hectopascals (hPa)</item>
+ <item>Standard Atmosphere (atm)</item>
+ <item>Millimeteres of Mercury (mmHg)</item>
+ <item>Inches of Mercury (inHg)</item>
+ </string-array>
+ <string name="units">Units: </string>
+ <string name="close">Close</string>
+ <string name="showLocalGraph">Show Local Graph</string>
+ <string name="delete">Delete User Data</string>
+ <string name="deleteWarning">Warning: This will permanently delete all the data you have submitted to pressureNET.</string>
+ <string name="my_info">My Info</string>
+ <string name="logViewer">Log Viewer (last 24h)</string>
+ <string name="view_log">View Log</string>
+ <string name="data_visualization">Data Visualization</string>
+</resources>
View
10 res/values/styles.xml
@@ -0,0 +1,10 @@
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <style name="CustomTheme" parent="android:Theme.Holo.Light">
+ <item name="android:actionBarStyle">@style/ActionBarStyle</item>
+ </style>
+ <style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
+ <item name="android:background">#33b5e5</item>
+ </style>
+
+</resources>
View
7 res/xml/widget_info.xml
@@ -0,0 +1,7 @@
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="129dp"
+ android:minHeight="57dp"
+ android:updatePeriodMillis="3600000"
+ android:previewImage="@drawable/preview"
+ android:initialLayout="@layout/small_widget_layout">
+</appwidget-provider>
View
70 src/ca/cumulonimbus/barometernetwork/BarometerMapView.java
@@ -0,0 +1,70 @@
+package ca.cumulonimbus.barometernetwork;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Canvas;
+import android.view.MotionEvent;
+
+import com.google.android.maps.MapView;
+
+public class BarometerMapView extends MapView {
+
+ int oldZoomLevel = -1;
+ public static final String CUSTOM_INTENT = "ca.cumulonimbus.barometernetwork.REFRESHMAP";
+
+ public class OutgoingReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent i = new Intent();
+ i.setAction(CUSTOM_INTENT);
+ context.sendBroadcast(i);
+ }
+
+ }
+
+ public void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+ try {
+ if (getZoomLevel() != oldZoomLevel) {
+ Intent i = new Intent();
+ i.setAction(CUSTOM_INTENT);
+ getContext().sendBroadcast(i);
+ oldZoomLevel = getZoomLevel();
+ }
+ } catch(Exception e) {
+ // TODO: See onTouchEvent.
+
+ }
+ }
+
+ public BarometerMapView(android.content.Context context,
+ android.util.AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public boolean onTouchEvent(MotionEvent ev) {
+ try {
+ if (ev.getAction() == MotionEvent.ACTION_UP) {
+ Intent i = new Intent();
+ i.setAction(CUSTOM_INTENT);
+ getContext().sendBroadcast(i);
+ }
+ } catch(Exception e) {
+ // TODO: Investigate. Stack trace on Android Developer console. Report Oct 19, 2011.
+ // Autorefresh failed. User can still press Reload to get new data.
+ }
+ return super.onTouchEvent(ev);
+ }
+
+ public BarometerMapView(android.content.Context context,
+ android.util.AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public BarometerMapView(android.content.Context context,
+ java.lang.String apiKey) {
+ super(context, apiKey);
+ }
+}
View
1,050 src/ca/cumulonimbus/barometernetwork/BarometerNetworkActivity.java
@@ -0,0 +1,1050 @@
+package ca.cumulonimbus.barometernetwork;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.security.MessageDigest;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+
+import android.app.ActionBar;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.provider.Settings.Secure;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.ItemizedOverlay;
+import com.google.android.maps.MapActivity;
+import com.google.android.maps.MapController;
+import com.google.android.maps.MapView;
+import com.google.android.maps.Overlay;
+import com.google.android.maps.OverlayItem;
+
+public class BarometerNetworkActivity extends MapActivity implements SensorEventListener {
+
+ double mLatitude = 0.0;
+ double mLongitude = 0.0;
+ double mReading = 0.0;
+ double mTimeOfReading = 0.0;
+ SensorManager sm;
+
+ private String mAppDir = "";
+ boolean mExternalStorageAvailable = false;
+ boolean mExternalStorageWriteable = false;
+
+ private String android_id;
+
+ private String localHistoryFile = "recent.txt";
+
+ public String statusText = "";
+ private final Handler statusHandler = new Handler();
+ private final Handler mapHandler = new Handler();
+
+ private String serverURL = "";
+
+ public static final String PREFS_NAME = "pressureNETPrefs";
+
+ private String mUpdateServerFrequency;
+ private boolean mUpdateServerAutomatically;
+ Intent serviceIntent;
+
+ Unit mUnit = null;
+
+ private DBAdapter dbAdapter;
+
+ private boolean barometerDetected = true;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ setUpDatabase();
+ setUpBarometer();
+ getStoredPreferences();
+ getLocationInformation();
+ setId();
+ setUpFiles();
+ setUpMap();
+ startSendingData();
+ setUpActionBar();
+ }
+
+
+ /**
+ * Some devices have barometers, other's don't. Fix up the UI
+ * a bit so that most useful elements show for the right users
+ */
+ public void cleanUI(Menu menu) {
+ if(barometerDetected) {
+ // keep the UI as-is. default assumes barometer exists :)
+ // ensure the right items are always visible, though, in case of detection error
+ } else {
+ // hide some menu items that are barometer-specific
+ menu.removeItem(R.id.menu_my_info);
+ menu.removeItem(R.id.menu_submit_reading);
+ menu.removeItem(R.id.menu_log_viewer);
+
+ }
+ }
+
+ public void setUpDatabase() {
+ try {
+ dbAdapter = new DBAdapter(this);
+ dbAdapter.open();
+ } catch(Exception e) {
+ Toast.makeText(getApplicationContext(), "Unable to open local database. No problem (no local history.)", Toast.LENGTH_LONG).show();
+ }
+ }
+
+
+ // Add a new barometer reading to the local database
+ // Having this allows user to view trends but keeps
+ // the data offline (no server visibility to the data.)
+ public void addToLocalDatabase(BarometerReading br) {
+ try {
+ dbAdapter.addReading(br.getReading(), br.getLatitude(), br.getLongitude(), br.getTime());
+ } catch(RuntimeException re) {
+ // :(
+ }
+ }
+
+ public double convertfromMillibarTo(double read) {
+ String abbrev = mUnit.getAbbreviation();
+ if(abbrev.contains("mbar")) {
+ // No change. reading comes to us in mbar.
+ return read;
+ } else if(abbrev.contains("hPa")) {
+ // mbar = hpa.
+ return read;
+ } else if(abbrev.contains("atm")) {
+ return read * 0.000986923;
+ } else if(abbrev.contains("mmHg")) {
+ return read * 0.75006;
+ } else if(abbrev.contains("inHg")) {
+ return read * 0.02961;
+ }
+ return 0.0;
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.settings, menu);
+ return true;
+ }
+
+
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ cleanUI(menu);
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(item.getItemId()==R.id.menu_settings) {
+ Intent i = new Intent(this, SettingsActivity.class);
+ i.putExtra("hasBarometer", barometerDetected);
+ startActivityForResult(i, 1);
+ } else if(item.getItemId()==R.id.menu_my_info) {
+ Intent intent = new Intent(getApplication(), SingleUserChartActivity.class);
+ intent.putExtra("userid", android_id);
+ intent.putExtra("selfstats", "yes");
+ intent.putExtra("appdir", mAppDir);
+ startActivityForResult(intent, 0);
+ } else if(item.getItemId()==R.id.menu_submit_reading) {
+ getLocationInformation();
+ submitDataToServer();
+ } else if(item.getItemId()==R.id.menu_log_viewer) {
+ showRecentHistory();
+ } /*else if(item.getItemId()==R.id.menu_load_data_vis) {
+ Uri uri = Uri.parse("http://cumulonimbus.ca");
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(intent);
+
+ } *//*else if(item.getItemId()==R.id.menu_reload) {
+ loadAndShowData();
+ }/*
+ // Show a graph of local data points. Local is defined by
+ // visible map region. Intended for viewing tendencies
+ else if(item.getItemId()==R.id.menu_showLocalGraph) {
+ Intent intent = new Intent(getApplication(), LocalChartActivity.class);
+ intent.putExtra("appdir", mAppDir);
+ intent.putExtra("regioninfo","");
+ startActivityForResult(intent, 0);
+ }*/
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private String fullUnitToRealAbbrev(String unit) {
+ if(unit.contains("mbar")) {
+ return "mbar";
+ } else if(unit.contains("mmHg")) {
+ return "mmHg";
+ } else if(unit.contains("inHg")) {
+ return "inHg";
+ } else if(unit.contains("hPa")) {
+ return "hPa";
+ } else if(unit.contains("atm")) {
+ return "atm";
+ } else {
+ return "mbar";
+ }
+ }
+
+ // Give a quick overview of recent
+ // submissions
+ public void showRecentHistory() {
+ String log = "";
+ ArrayList<BarometerReading> recents = new ArrayList<BarometerReading>();
+ try {
+ dbAdapter.open();
+ recents = dbAdapter.fetchRecentReadings(24); // the last few hours
+ dbAdapter.close();
+ for (BarometerReading r : recents) {
+ String d = new Date((long)r.getTime()).toLocaleString();
+ DecimalFormat df = new DecimalFormat("####.00");
+ String unit = fullUnitToRealAbbrev(mUnit.getAbbreviation());
+ double reading = convertfromMillibarTo(r.getReading());
+ log += d + ": " + df.format(reading) + " " + unit + "\n";
+ }
+ Intent intent = new Intent(this, LogViewerActivity.class);
+ intent.putExtra("log", log);
+ startActivity(intent);
+ } catch(Exception e) {
+
+ }
+
+ /*String message = ScienceHandler.findTendency(recents);
+ AlertDialog alertDialog = new AlertDialog.Builder(BarometerNetworkActivity.this).create();
+ alertDialog.setTitle("Tendency");
+ alertDialog.setMessage(message);
+ alertDialog.show();*/
+
+ }
+
+
+ public void setUpActionBar() {
+ // TODO: Compatible Action Bar
+ ActionBar bar = getActionBar();
+ bar.setDisplayUseLogoEnabled(true);
+ bar.setTitle("");
+
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ setUpBarometer();
+ getStoredPreferences();
+ getLocationInformation();
+ }
+
+ // Periodically send barometer readings if allowed by Preferences
+ // pref check done inside the service; start the service even if no
+ // data is sent to allow the widget to use the service
+ // probably should rename away from startSendingData
+ private void startSendingData() {
+ log("start sending data");
+ try {
+ serviceIntent = new Intent(this, SubmitReadingService.class);
+ //serviceIntent.putExtra("appdir", mAppDir);
+ startService(serviceIntent);
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+
+ }
+
+ // Get the user preferences
+ private void getStoredPreferences() {
+ try {
+ SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
+ mUpdateServerAutomatically = settings.getBoolean("autoupdate", true);
+ mUpdateServerFrequency = settings.getString("autofrequency", "10 minutes");
+ log("shared prefs: " + mUpdateServerFrequency + " " + mUpdateServerAutomatically);
+
+ // Units
+ String abbrev = settings.getString("units", "mbar");
+ mUnit = new Unit(abbrev);
+ log("abbrev: " + abbrev);
+
+ } catch(Exception e) {
+ log(e.getMessage());
+ mUpdateServerAutomatically = false;
+ }
+ }
+
+ // Set a unique identifier so that updates from the same user are
+ // seen as updates and not new data. MD5 to minimize privacy problems. (?)
+ public void setId() {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+
+ String actual_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
+ byte[] bytes = actual_id.getBytes();
+ byte[] digest = md.digest(bytes);
+ StringBuffer hexString = new StringBuffer();
+ for(int i = 0; i< digest.length; i++) {
+ hexString.append(Integer.toHexString(0xFF & digest[i]));
+ }
+ android_id = hexString.toString();
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+ }
+
+
+
+ // Used to write a log to SD card. Not used unless logging enabled.
+ public void setUpFiles() {
+ try {
+ File homeDirectory = getExternalFilesDir(null);
+ if(homeDirectory!=null) {
+ mAppDir = homeDirectory.getAbsolutePath();
+ }
+ } catch (Exception e) {
+ //log(e.getMessage());
+ }
+ }
+
+ // Start getting barometer readings.
+ public void setUpBarometer() {
+ log("set up barometer");
+ try {
+ sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ Sensor bar = sm.getDefaultSensor(Sensor.TYPE_PRESSURE);
+
+ if(bar!=null) {
+ boolean running = sm.registerListener(this, bar, SensorManager.SENSOR_DELAY_NORMAL);
+ log(running + "");
+ barometerDetected = true;
+ } else {
+ barometerDetected = false;
+
+ //Toast.makeText(getApplicationContext(), "No barometer detected.", Toast.LENGTH_SHORT).show();
+ }
+ invalidateOptionsMenu(); // ensure right right menus are showing, given barometer detection status
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+ }
+
+ // Zoom into the user's location, add pinch zoom controls
+ public void setUpMap() {
+ log("setting up map");
+ // Add zoom
+ BarometerMapView mapView = (BarometerMapView) findViewById(R.id.mapview);
+ mapView.setBuiltInZoomControls(true);
+
+ // Set default coordinates (centered around the user's location)
+
+ log("about to get controller");
+ try {
+ MapController mc = mapView.getController();
+
+ mc.setZoom(5);
+ if(mLatitude!=0.0) {
+ //mc.setCenter(new GeoPoint((int)(mLatitude*1E6), (int)(mLongitude*1E6)));
+ }
+
+ mapView.invalidate();
+ mapView.refreshDrawableState();
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+
+ }
+
+ LocationManager mLocationManager;
+ LocationListener locationListener;
+
+ // Get the user's location from the location service, preferably GPS.
+ public void getLocationInformation() {
+ log("getting location information");
+ // get the location
+ // Acquire a reference to the system Location Manager
+ mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+
+ // Define a listener that responds to location updates
+ locationListener = new LocationListener() {
+ public void onLocationChanged(Location location) {
+ // Called when a new location is found by the network location provider.
+ try {
+ boolean first = false;
+ if(mLatitude==0.0) {
+ log("latitude is 0");
+ first = true;
+ }
+ double latitude = location.getLatitude();
+ double longitude = location.getLongitude();
+ mLatitude = latitude;
+ mLongitude = longitude;
+ if(first) {
+ log("first location start");
+ setUpMap();
+ loadAndShowData();
+ log("end");
+ }
+ } catch(Exception e) {
+ log("On Location change failed.");
+ }
+ }
+
+ public void onStatusChanged(String provider, int status, Bundle extras) {}
+
+ public void onProviderEnabled(String provider) {}
+
+ public void onProviderDisabled(String provider) {}
+ };
+
+ // Register the listener with the Location Manager to receive location updates
+ try {
+ mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
+
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+
+ }
+
+ // Custom map overlays for barometer readings
+ public class MapOverlay extends ItemizedOverlay<OverlayItem> {
+
+ private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
+ Context mContext;
+ private int mTextSize;
+
+ @Override
+ protected boolean onTap(int index) {
+ // Open the chart view
+ OverlayItem item = mOverlays.get(index);
+ String snippet = item.getSnippet();
+
+ Intent intent = new Intent(getApplication(), SingleUserChartActivity.class);
+ intent.putExtra("userid", snippet);
+ intent.putExtra("appdir", mAppDir);
+ startActivityForResult(intent, 0);
+ return true;
+ }
+
+ public MapOverlay(Drawable defaultMarker, Context context, int textSize) {
+ super(boundCenterBottom(defaultMarker));
+ mContext = context;
+ mTextSize = textSize;
+ }
+
+ public MapOverlay(Drawable defaultMarker, Context context) {
+ super(defaultMarker);
+ mContext = context;
+ }
+
+ public MapOverlay(Drawable defaultMarker) {
+ super(boundCenterBottom(defaultMarker));
+ }
+
+ public void addOverlay(OverlayItem overlay) {
+ mOverlays.add(overlay);
+ populate();
+ }
+
+ public void removeOverlay(OverlayItem overlay)
+ {
+ mOverlays.remove(overlay);
+ populate();
+ }
+
+ @Override
+ protected OverlayItem createItem(int i) {
+ return mOverlays.get(i);
+ }
+ @Override
+ public int size() {
+ return mOverlays.size();
+ }
+
+ // Draw all the overlay data points onto the map. Include an icon as well as
+ @Override
+ public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
+ {
+ super.draw(canvas, mapView, shadow);
+
+ if (shadow == false)
+ {
+ //cycle through all overlays
+ for (int index = 0; index < mOverlays.size(); index++)
+ {
+ try {
+ OverlayItem item = mOverlays.get(index);
+
+ // Converts lat/lng-Point to coordinates on the screen
+ GeoPoint point = item.getPoint();
+ Point ptScreenCoord = new Point() ;
+ mapView.getProjection().toPixels(point, ptScreenCoord);
+
+ //Paint
+ Paint paint = new Paint();
+ paint.setTextAlign(Paint.Align.CENTER);
+ paint.setTextSize(mTextSize);
+ paint.setShadowLayer(15, 5, 5, 0);
+ paint.setARGB(255, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
+ paint.setAntiAlias(true);
+
+ //String toPrint = item.getTitle().substring(0, item.getTitle().length() - 5);
+ String toPrint = item.getTitle().split(" ")[0];
+ Double value = Double.parseDouble(toPrint);
+ DecimalFormat df = new DecimalFormat("####.00");
+ toPrint = df.format(value);
+
+ //show text to the right of the icon
+ float textWidth = paint.measureText(toPrint);
+ Paint bgPaint = new Paint();
+ bgPaint.setColor(Color.WHITE);
+
+ Rect rect = new Rect((int)(ptScreenCoord.x - (textWidth / 2) - 2), ptScreenCoord.y, (int)(ptScreenCoord.x + (textWidth / 2) + 2), ptScreenCoord.y + mTextSize + 5);
+ canvas.drawRoundRect(new RectF(rect), 6, 6, bgPaint);
+ canvas.drawText(toPrint, ptScreenCoord.x, ptScreenCoord.y+mTextSize, paint);
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+ }
+ }
+ }
+ }
+
+ // Assume that matching latitude and longitude can only be you.
+ public boolean brIsMe(BarometerReading br) {
+ return ((br.getAndroidId().equals(android_id)));
+ }
+
+ // Put a bunch of barometer readings on the map.
+ public void addDataToMap(ArrayList<BarometerReading> list, boolean showTendencies, HashMap<String, String> tendencies) {
+ log("add data to map");
+ BarometerMapView mv = (BarometerMapView) findViewById(R.id.mapview);
+
+ List<Overlay> mapOverlays = mv.getOverlays();
+
+ Drawable drawable = this.getResources().getDrawable(R.drawable.ic_marker);
+ Drawable selfDrawable = this.getResources().getDrawable(R.drawable.ic_marker);
+ //Drawable upArrowDrawable = this.getResources().getDrawable(R.drawable.ic_tend_up);
+ //Drawable downArrowDrawable = this.getResources().getDrawable(R.drawable.ic_tend_down);
+
+
+ mapOverlays.clear();
+
+ // add a bunch of coords
+ log("starting adding total " + list.size());
+ try {
+ for(BarometerReading br : list) {
+ // log(br.getReading() + "");
+ MapOverlay overlay;
+
+ // Pick an overlay icon depending on the BR and
+ // the current settings. BR aging icon? Tendency?
+ overlay = new MapOverlay(drawable, this, 20); // default
+ if(showTendencies) {
+
+
+ /*
+ *
+ * TODO: implement tendencies on the server side.
+ *
+ *
+ *
+ //log("tendencies size: " + tendencies.size());
+ //log(br.getAndroidId());
+ String tendency = tendencies.get(br.getAndroidId());
+ log("tendency " + tendency);
+ if(tendency.equals("Rising")) {
+ overlay = new MapOverlay(upArrowDrawable, this, 20);
+ } else if(tendency.equals("Falling")) {
+ overlay = new MapOverlay(downArrowDrawable, this, 20);
+ } else if(tendency.equals("Steady")) {
+ overlay = new MapOverlay(drawable, this, 20);
+ } else {
+ overlay = new MapOverlay(drawable, this, 20); // default
+ }
+ */
+ } else {
+ if(brIsMe(br)) {
+ overlay = new MapOverlay(selfDrawable, this, 20);
+ } else {
+ overlay = new MapOverlay(drawable, this, 20);
+ }
+ }
+
+ GeoPoint point = new GeoPoint((int)((br.getLatitude()) * 1E6), (int)((br.getLongitude()) * 1E6));
+ String snippet = br.getAndroidId();
+ String textForTitle = convertfromMillibarTo(br.getReading()) + " " + mUnit.getAbbreviation();
+ OverlayItem overlayitem = new OverlayItem(point, textForTitle, snippet);
+ overlay.addOverlay(overlayitem);
+ mapOverlays.add(overlay);
+
+ mv.invalidate();
+ //mv.refreshDrawableState();
+ }
+ } catch(Exception e) {
+ log("add data error: " + e.getMessage());
+ }
+ log("end of adddatatomap");
+ }
+
+ // Runnable to refresh the map. Can be called when another
+ // thread wishes to refresh the view.
+ private final Runnable refreshMap = new Runnable() {
+ public void run() {
+ BarometerMapView mapView = (BarometerMapView) findViewById(R.id.mapview);
+ mapView.invalidate();
+ mapView.refreshDrawableState();
+ }
+ };
+
+ // Assemble a list of BarometerReadings. This is the opposite of function barometerReadingToWeb in the servlet.
+ public ArrayList<BarometerReading> csvToBarometerReadings(String[] readings) {
+ ArrayList<BarometerReading> readingsList = new ArrayList<BarometerReading>();
+ for(int i = 0; i<readings.length; i++) {
+ try {
+ String[] values = readings[i].split(",");
+ BarometerReading br = new BarometerReading();
+ br.setLatitude(Double.parseDouble(values[0]));
+ br.setLongitude(Double.parseDouble(values[1]));
+ br.setReading(Double.parseDouble(values[2]));
+ br.setTime(Double.parseDouble(values[3]));
+ br.setTimeZoneOffset(Integer.parseInt(values[4]));
+ br.setAndroidId(values[5]);
+ readingsList.add(br);
+ } catch(NumberFormatException nfe) {
+ // Likely, tomcat returned an error.
+ log("Server error? " + nfe.getMessage());
+ }
+ }
+
+ return readingsList;
+ }
+
+ // Assemble a HashMap of userIDs and tendencies. //This is the opposite of function barometerReadingToWeb in the servlet.
+ public HashMap<String, String> csvToBarometerTendencies(String[] readings) {
+ log("csv to barometer tendencies : " + readings[0] + ", " + readings.length);
+ HashMap<String, String> tendencies = new HashMap<String, String>();
+ for(int i = 0; i<readings.length; i++) {
+ try {
+ String[] values = readings[i].split(",");
+
+ for(String a : values) {
+ log(a);
+ }
+ log("tendency check " + values[5]);
+ tendencies.put(values[5], values[6]); // userid, tendency
+ } catch(Exception e) {
+ // Likely, the server returned an error.
+ log("Server error tendencies? " + e.getMessage());
+ }
+ }
+
+ return tendencies;
+ }
+
+ // When we get a download, split up the data into barometer readings
+ // or tendency information and display it on the map.
+ public void processDownloadResult(String result) {
+ log("process download result");
+ if(!result.equals("")) {
+ if(result.contains("local_data return;")) {
+ result = result.substring("local_data return;".length());
+ String[] csvReading = result.split(";");
+ ArrayList<BarometerReading> readings = csvToBarometerReadings(csvReading);
+ addDataToMap(readings, false, null);
+ } else if(result.contains("local_data_tendency return;")) {
+ result = result.substring("local_data_tendency return;".length());
+ String[] csvReading = result.split(";");
+ ArrayList<BarometerReading> readings = csvToBarometerReadings(csvReading);
+ HashMap<String, String> tendencies = csvToBarometerTendencies(csvReading);
+ addDataToMap(readings, true, tendencies);
+ }
+ } else {
+ // updateStatusText("Error: No data."); ancient
+
+ }
+ }
+
+ // Preparation for sending a barometer reading through the network.
+ // Take the object and NVP it.
+ public List<NameValuePair> barometerReadingToNVP(BarometerReading br) {
+ List<NameValuePair> nvp = new ArrayList<NameValuePair>();
+ nvp.add(new BasicNameValuePair("latitude",br.getLatitude() + ""));
+ nvp.add(new BasicNameValuePair("longitude",br.getLongitude() + ""));
+ nvp.add(new BasicNameValuePair("reading",br.getReading() + ""));
+ nvp.add(new BasicNameValuePair("time",br.getTime() + ""));
+ nvp.add(new BasicNameValuePair("tzoffset",br.getTimeZoneOffset() + ""));
+ nvp.add(new BasicNameValuePair("text",br.getAndroidId() + ""));
+ return nvp;
+ }
+
+ public void submitDataToServer() {
+ new ReadingSender().execute("");
+ }
+
+ public void loadAndShowData() {
+ new DataDownload().execute("");
+ }
+
+ private BroadcastReceiver receiveForMap =
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(BarometerMapView.CUSTOM_INTENT)) {
+ loadAndShowData();
+ }
+ }
+ };
+
+ // Send data to the server in the background.
+ private class ReadingSender extends AsyncTask<String, Integer, Long> {
+ @Override
+ protected Long doInBackground(String... arg0) {
+
+ if((mLatitude == 0.0) || (mLongitude == 0.0) || (mReading == 0.0)) {
+ //don't submit
+ return null;
+ }
+
+ BarometerReading br = new BarometerReading();
+ br.setLatitude(mLatitude);
+ br.setLongitude(mLongitude);
+ br.setTime(Calendar.getInstance().getTimeInMillis());
+ br.setTimeZoneOffset(Calendar.getInstance().getTimeZone().getOffset((long)br.getTime()));
+ br.setReading(mReading);
+ br.setAndroidId(android_id);
+
+
+ DefaultHttpClient client = new SecureHttpClient(getApplicationContext());
+ HttpPost httppost = new HttpPost(serverURL);
+ // keep a history of readings on the user's device
+ addToLocalDatabase(br);
+
+ try {
+ List<NameValuePair> nvps = barometerReadingToNVP(br);
+ httppost.setEntity(new UrlEncodedFormEntity(nvps));
+ HttpResponse response = client.execute(httppost);
+ } catch(ClientProtocolException cpe) {
+ log(cpe.getMessage());
+ // TODO: alert of failed submit
+ } catch(IOException ioe) {
+ log(ioe.getMessage());
+ // TODO: alert of failed submit
+ }
+ return null;
+ }
+
+ protected void onPostExecute(Long result) {
+
+ Toast.makeText(getApplicationContext(), "Submitted Reading", Toast.LENGTH_SHORT).show();
+ loadAndShowData();
+ }
+ }
+
+ // Download data from the server in the background
+ private class DataDownload extends AsyncTask<String, String, String> {
+
+ @Override
+ protected String doInBackground(String... arg0) {
+ log("DataDownload doInBackground start");
+
+ String responseText = "";
+
+ try {
+ log("DataDownload doInBackground start try block");
+
+ // Instantiate the custom HttpClient
+ DefaultHttpClient client = new SecureHttpClient(getApplicationContext());
+
+ HttpPost post = new HttpPost(serverURL);
+
+ List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+
+ String type = "local_data";
+
+ if(type.equals("all_data")) {
+ nvps.add(new BasicNameValuePair("download","all_data"));
+ } else if(type.equals("recent_data")) {
+ nvps.add(new BasicNameValuePair("download","recent_data"));
+ nvps.add(new BasicNameValuePair("days","1"));
+ } else if(type.equals("local_data")) {
+ BarometerMapView mv = (BarometerMapView) findViewById(R.id.mapview);
+ GeoPoint center = mv.getMapCenter();
+ int latSpan = mv.getLatitudeSpan();
+ int longSpan = mv.getLongitudeSpan();
+
+ nvps.add(new BasicNameValuePair("download", "local_data"));
+ nvps.add(new BasicNameValuePair("centerlat", center.getLatitudeE6() + ""));
+ nvps.add(new BasicNameValuePair("centerlon", center.getLongitudeE6() + ""));
+ nvps.add(new BasicNameValuePair("latspan", latSpan + ""));
+ nvps.add(new BasicNameValuePair("longspan", longSpan + ""));
+ } else if(type.equals("local_tendency_data")) {
+ BarometerMapView mv = (BarometerMapView) findViewById(R.id.mapview);
+ GeoPoint center = mv.getMapCenter();
+ int latSpan = mv.getLatitudeSpan();
+ int longSpan = mv.getLongitudeSpan();
+ nvps.add(new BasicNameValuePair("download", "local_tendency_data"));
+ nvps.add(new BasicNameValuePair("centerlat", center.getLatitudeE6() + ""));
+ nvps.add(new BasicNameValuePair("centerlon", center.getLongitudeE6() + ""));
+ nvps.add(new BasicNameValuePair("latspan", latSpan + ""));
+ nvps.add(new BasicNameValuePair("longspan", longSpan + ""));
+ }
+
+ post.setEntity(new UrlEncodedFormEntity(nvps));
+
+
+ // Execute the GET call and obtain the response
+ HttpResponse getResponse = client.execute(post);
+ HttpEntity responseEntity = getResponse.getEntity();
+
+
+ BufferedReader r = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
+
+ StringBuilder total = new StringBuilder();
+ String line;
+ if(r!=null) {
+ while((line = r.readLine()) != null) {
+ total.append(line);
+ }
+ responseText = total.toString();
+ }
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+ return responseText;
+ }
+ protected void onPostExecute(String result) {
+ log("datadownload post execute " + result);
+ processDownloadResult(result);
+
+ mapHandler.postDelayed(refreshMap, 100);
+ }
+ }
+
+ /*
+ * TODO: remove in favour of externalized Unit class
+ */
+ public class Unit {
+ double value;
+ String abbrev;
+
+ // Conversion factors from http://www.csgnetwork.com/meteorologyconvtbl.html
+ public void convertToPreferredUnit(String unit) {
+ //log("converting " + mReading + " to " + unit);
+ try {
+ if(abbrev.contains("mbar")) {
+ // No change. reading comes to us in mbar.
+ this.value = mReading;
+ } else if(abbrev.contains("hPa")) {
+ // mbar = hpa.
+ this.value = mReading;
+ } else if(abbrev.contains("atm")) {
+ this.value = mReading * 0.000986923;
+ } else if(abbrev.contains("mmHg")) {
+ this.value = mReading * 0.75006;
+ } else if(abbrev.contains("inHg")) {
+ this.value = mReading* 0.02961;
+ } else {
+ // default to mb
+ this.value = mReading;
+ }
+ } catch(Exception e) {
+ // Probably no barometer reading.
+ log(e.getMessage());
+ }
+ }
+
+ public void updateReadingFromOutside() {
+ convertToPreferredUnit(this.abbrev);
+ }
+
+ public String getDisplayText() {
+ return value + " " + abbrev;
+ }
+
+ public Unit(String abbrev) {
+ convertToPreferredUnit(abbrev);
+ this.abbrev = abbrev;
+ }
+ public double getValue() {
+ return value;
+ }
+ public void setValue(double value) {
+ this.value = value;
+ }
+ public String getAbbreviation() {
+ return abbrev;
+ }
+ public void setAbbreviation(String abbreviation) {
+ this.abbrev = abbreviation;
+ }
+ }
+
+ // Stop listening to the barometer when our app is paused.
+ @Override
+ protected void onPause() {
+ super.onPause();
+ sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ mLocationManager.removeUpdates(locationListener);
+ sm.unregisterListener(this);
+ unregisterReceiver(receiveForMap);
+ dbAdapter.close();
+ }
+
+ // Register a broadcast listener
+ @Override
+ protected void onResume() {
+ super.onResume();
+ registerReceiver(receiveForMap, new IntentFilter(BarometerMapView.CUSTOM_INTENT));
+ // Check for auto-send settings change.
+ getStoredPreferences();
+ getLocationInformation();
+ if(mUpdateServerAutomatically) {
+ // Start the update service.
+ try {
+ log("on resume restarting the update service");
+ serviceIntent = new Intent(this, SubmitReadingService.class);
+ serviceIntent.putExtra("appdir", mAppDir);
+ stopService(serviceIntent);
+ startService(serviceIntent);
+ } catch(Exception e) {
+ log(e.getMessage());
+ }
+ } else {
+ // Stop the update service.
+ try {
+ stopService(serviceIntent);
+ } catch(Exception e) {
+ serviceIntent = new Intent(this, SubmitReadingService.class);
+ serviceIntent.putExtra("appdir", mAppDir);
+ stopService(serviceIntent);
+ log(e.getMessage());
+ }
+ }
+ setUpBarometer();
+ updateVisibleReading();
+ loadAndShowData();
+ setUpDatabase();
+ }
+
+ // Must exist for the MapView.
+ @Override
+ protected boolean isRouteDisplayed() {
+ return false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ // TODO Auto-generated method stub
+ try {
+ dbAdapter.close();
+ sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ sm.unregisterListener(this);
+ mLocationManager.removeUpdates(locationListener);
+ unregisterReceiver(receiveForMap);
+ } catch(Exception e) {
+
+ }
+ super.onDestroy();
+ }
+
+ // Must exist for the Barometer. Unlikely to change, and if it does
+ // change it doesn't really matter for us.
+ @Override
+ public void onAccuracyChanged(Sensor arg0, int arg1) {
+
+ }
+
+ public void updateVisibleReading() {
+ mUnit.updateReadingFromOutside();
+ double value = mUnit.getValue();
+ TextView textView = (TextView) findViewById(R.id.textReading);
+ if(value!=0.0) {
+ textView.setVisibility(View.VISIBLE);
+ String abbrev = mUnit.getAbbreviation();
+ DecimalFormat df = new DecimalFormat("####.00");
+ String toPrint = df.format(value);
+ textView.setText(toPrint + " " + abbrev);
+ } else {
+ textView.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ switch (event.sensor.getType()) {
+ case Sensor.TYPE_PRESSURE:
+ mReading = event.values[0];
+ updateVisibleReading();
+ break;
+ }
+ }
+
+ // Log data to SD card for debug purposes.
+ // To enable logging, ensure the Manifest allows writing to SD card.
+ public void logToFile(String text) {
+ try {
+ OutputStream output = new FileOutputStream(mAppDir + "/log.txt", true);
+ String logString = (new Date()).toString() + ": " + text + "\n";
+ output.write(logString.getBytes());
+ output.close();
+ } catch(FileNotFoundException e) {
+
+ } catch(IOException ioe) {
+
+ }
+ }
+
+ public void log(String text) {
+ //logToFile(text);
+ //System.out.println(text);
+ }
+}
View
68 src/ca/cumulonimbus/barometernetwork/BarometerReading.java
@@ -0,0 +1,68 @@
+package ca.cumulonimbus.barometernetwork;
+
+import java.io.Serializable;
+
+/**
+ * Hold data on a single barometer reading.
+ * @author jacob
+ *
+ */
+public class BarometerReading implements Serializable {
+ private static final long serialVersionUID = 4085660664718400896L;
+ double latitude;
+ double longitude;
+ double time;
+ double reading;
+ int timeZoneOffset;
+ String androidId;
+
+ public String toString() {
+ String ret = "Reading: " + reading + "\n" +
+ "Latitude: " + latitude + "\n" +
+ "Longitude: " + longitude + "\n" +
+ "ID: " + androidId + "\n" +
+ "Time: " + time + "\n" +
+ "TZOffset: " + timeZoneOffset + "\n";
+
+ return ret;
+ }
+
+
+
+ public String getAndroidId() {
+ return androidId;
+ }
+ public void setAndroidId(String androidId) {
+ this.androidId = androidId;
+ }
+ public int getTimeZoneOffset() {
+ return timeZoneOffset;
+ }
+ public void setTimeZoneOffset(int timeZoneOffset) {
+ this.timeZoneOffset = timeZoneOffset;
+ }
+ public double getLatitude() {
+ return latitude;
+ }
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+ public double getLongitude() {
+ return longitude;
+ }
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+ public double getReading() {
+ return reading;
+ }
+ public double getTime() {
+ return time;
+ }
+ public void setTime(double time) {
+ this.time = time;
+ }
+ public void setReading(double reading) {
+ this.reading = reading;
+ }
+}
View
150 src/ca/cumulonimbus/barometernetwork/DBAdapter.java
@@ -0,0 +1,150 @@
+package ca.cumulonimbus.barometernetwork;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+
+public class DBAdapter {
+
+ public static final String KEY_READING = "reading";
+ public static final String KEY_TIME = "time";
+ public static final String KEY_LATITUDE = "latitude";
+ public static final String KEY_LONGITUDE = "longitude";
+ public static final String KEY_ROWID = "_id";
+
+ private static final String TAG = "pressureNETDbAdapter";
+ private DatabaseHelper mDbHelper;
+ private SQLiteDatabase mDb;
+
+ /**
+ * Database creation sql statement
+ */
+ private static final String DATABASE_CREATE =
+ "create table barometer_readings (_id integer primary key autoincrement, "
+ + "reading real not null, "
+ + "latitude real not null, "
+ + "longitude real not null, "
+ + "time integer not null);";
+
+ private static final String DATABASE_NAME = "pressurenet_data";
+ private static final String DATABASE_TABLE = "barometer_readings";
+ private static final int DATABASE_VERSION = 1;
+
+ private final Context mCtx;
+
+ private static class DatabaseHelper extends SQLiteOpenHelper {
+
+ DatabaseHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+