Permalink
Browse files

Merge branch 'master' of github.com:bettsmatt/CowsEye

  • Loading branch information...
2 parents 6e35532 + 71bae0f commit cb15c635643e918ca395e3833538a76ae36d743b @bettsmatt committed Oct 8, 2012
Showing with 1,951 additions and 701 deletions.
  1. +7 −1 CowsEyeAndroidApplication/AndroidManifest.xml
  2. BIN CowsEyeAndroidApplication/assets/River_watch.sqlite
  3. +58 −51 CowsEyeAndroidApplication/gen/nz/co/android/cowseye/R.java
  4. BIN CowsEyeAndroidApplication/libs/android-support-v4.jar
  5. BIN CowsEyeAndroidApplication/res/drawable-mdpi/screen1.jpg
  6. BIN CowsEyeAndroidApplication/res/drawable/cowgrazing.jpg
  7. BIN CowsEyeAndroidApplication/res/drawable/logo.png
  8. BIN CowsEyeAndroidApplication/res/drawable/logo_gallery.png
  9. BIN CowsEyeAndroidApplication/res/drawable/logo_grid.png
  10. BIN CowsEyeAndroidApplication/res/drawable/riverdogs.gif
  11. BIN CowsEyeAndroidApplication/res/drawable/screen1.jpg
  12. +42 −0 CowsEyeAndroidApplication/res/layout/grid_incident_gallery_layout.xml
  13. +22 −24 CowsEyeAndroidApplication/res/layout/incident_gallery_layout.xml
  14. +41 −6 CowsEyeAndroidApplication/res/layout/incident_gallery_layout_cell.xml
  15. +26 −0 CowsEyeAndroidApplication/res/layout/incident_layout_cellwithouttext.xml
  16. +37 −50 CowsEyeAndroidApplication/res/layout/main_screen_layout.xml
  17. +1 −1 CowsEyeAndroidApplication/res/layout/preview_layout.xml
  18. +6 −6 CowsEyeAndroidApplication/res/values/colors.xml
  19. +11 −5 CowsEyeAndroidApplication/res/values/strings.xml
  20. +78 −37 CowsEyeAndroidApplication/src/nz/co/android/cowseye/RiverWatchApplication.java
  21. +0 −9 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/DescriptionActivity.java
  22. +159 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/GridIncidentGalleryActivity.java
  23. +188 −178 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/IncidentGalleryActivity.java
  24. +67 −26 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/MainScreenActivity.java
  25. +5 −60 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/PreviewActivity.java
  26. +18 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/common/Constants.java
  27. +120 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/DatabaseAdapter.java
  28. +132 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/DatabaseConstructor.java
  29. +94 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/Incident.java
  30. +48 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/IncidentBuilder.java
  31. +3 −4 CowsEyeAndroidApplication/src/nz/co/android/cowseye/event/EventHandler.java
  32. +68 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/event/GetImageEvent.java
  33. +75 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/event/GetIncidentsEvent.java
  34. +107 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/service/GetImageAsyncTask.java
  35. +103 −0 CowsEyeAndroidApplication/src/nz/co/android/cowseye/service/GetIncidentsAsyncTask.java
  36. +23 −8 CowsEyeAndroidApplication/src/nz/co/android/cowseye/utility/Utils.java
  37. +238 −188 CowsEyeAndroidApplication/src/nz/co/android/cowseye/view/RiverWatchGallery.java
  38. +1 −1 Web/assets/cslib/AjaxCommons.coffee
  39. +53 −0 Web/assets/cslib/Users.coffee
  40. BIN Web/assets/img/RWBanner.png
  41. BIN Web/assets/img/rw.png
  42. BIN Web/assets/img/team.png
  43. +1 −1 Web/assets/js/AjaxCommons.js
  44. +68 −0 Web/assets/js/Users.js
  45. +20 −5 Web/pages/Admin/ApproveComment.html
  46. +3 −3 Web/pages/Admin/ApproveIncident.html
  47. +1 −1 Web/pages/Public/Feedback.html
  48. +1 −1 Web/pages/Public/GridView.html
  49. +24 −19 Web/pages/Public/Index.html
  50. +2 −16 Web/pages/Public/MapView.html
View
8 CowsEyeAndroidApplication/AndroidManifest.xml
@@ -16,7 +16,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
- android:icon="@drawable/icon"
+ android:icon="@drawable/logo"
android:label="@string/app_name"
android:name=".RiverWatchApplication" >
<uses-library android:name="com.google.android.maps" />
@@ -68,6 +68,12 @@
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
+ <activity
+ android:label="@string/incident_view_grid_title"
+ android:name=".activity.GridIncidentGalleryActivity"
+ android:screenOrientation="portrait"
+ android:theme="@android:style/Theme.Black.NoTitleBar" >
+ </activity>
</application>
</manifest>
View
BIN CowsEyeAndroidApplication/assets/River_watch.sqlite
Binary file not shown.
View
109 CowsEyeAndroidApplication/gen/nz/co/android/cowseye/R.java
@@ -37,69 +37,72 @@
public static final int back_buttonselection=0x7f020001;
public static final int button=0x7f020002;
public static final int button_pressed=0x7f020003;
- public static final int cowgrazing=0x7f020004;
- public static final int default_thumb=0x7f020005;
- public static final int details_background=0x7f020006;
+ public static final int default_thumb=0x7f020004;
+ public static final int details_background=0x7f020005;
+ public static final int done_button=0x7f020006;
public static final int header_style=0x7f020007;
public static final int icon=0x7f020008;
public static final int location_background=0x7f020009;
- public static final int next_button=0x7f02000a;
- public static final int next_buttonselection=0x7f02000b;
- public static final int preview_image_background=0x7f02000c;
- public static final int right_arrow=0x7f02000d;
- public static final int riverdogs=0x7f02000e;
- public static final int riverwatch_button=0x7f02000f;
- public static final int screen1=0x7f020010;
- public static final int submit_button=0x7f020011;
- public static final int submit_button_selected=0x7f020012;
- public static final int you_are_here_45x45=0x7f020013;
+ public static final int logo=0x7f02000a;
+ public static final int logo_gallery=0x7f02000b;
+ public static final int logo_grid=0x7f02000c;
+ public static final int next_button=0x7f02000d;
+ public static final int next_buttonselection=0x7f02000e;
+ public static final int preview_image_background=0x7f02000f;
+ public static final int right_arrow=0x7f020010;
+ public static final int riverwatch_button=0x7f020011;
+ public static final int submit_button=0x7f020012;
+ public static final int submit_button_selected=0x7f020013;
+ public static final int you_are_here_45x45=0x7f020014;
}
public static final class id {
public static final int EnterDescriptionLabel=0x7f070003;
public static final int MainScreenLogo=0x7f070011;
- public static final int PreviewDescriptionText=0x7f07001b;
- public static final int PreviewDescriptionTitle=0x7f07001a;
- public static final int PreviewImageImage=0x7f070015;
- public static final int PreviewImageTag=0x7f070019;
- public static final int PreviewImageTagTitle=0x7f070018;
- public static final int PreviewImageTitle=0x7f070014;
- public static final int PreviewLocationTag=0x7f070016;
- public static final int PreviewLocationText=0x7f070017;
- public static final int addressEditText=0x7f07000f;
+ public static final int PreviewDescriptionText=0x7f07001c;
+ public static final int PreviewDescriptionTitle=0x7f07001b;
+ public static final int PreviewImageImage=0x7f070016;
+ public static final int PreviewImageTag=0x7f07001a;
+ public static final int PreviewImageTagTitle=0x7f070019;
+ public static final int PreviewImageTitle=0x7f070015;
+ public static final int PreviewLocationTag=0x7f070017;
+ public static final int PreviewLocationText=0x7f070018;
+ public static final int addressEditText=0x7f070010;
public static final int backButton=0x7f070001;
public static final int button=0x7f070005;
public static final int button_submit=0x7f070012;
+ public static final int button_view_gallery=0x7f070013;
public static final int capture_image_button=0x7f070020;
- public static final int contactDetailsScreenTitle=0x7f07001d;
+ public static final int contactDetailsScreenTitle=0x7f070006;
public static final int descriptionScreenTitle=0x7f070000;
public static final int descriptionText=0x7f070004;
- public static final int detailsScreenTitle=0x7f070010;
- public static final int doneButton=0x7f07000d;
- public static final int holding_thumbs_frame_layout=0x7f070009;
- public static final int holding_thumbs_linear_layout=0x7f070008;
- public static final int incident_gallery=0x7f070006;
- public static final int incident_image=0x7f07000b;
- public static final int locationScreenTitle=0x7f07000c;
- public static final int main_frame_layout=0x7f07000a;
- public static final int mapview=0x7f07000e;
+ public static final int doneButton=0x7f07000e;
+ public static final int gridview=0x7f070007;
+ public static final int incident_description=0x7f07000b;
+ public static final int incident_gallery=0x7f070008;
+ public static final int incident_image=0x7f07000a;
+ public static final int incident_progress_bar=0x7f07000c;
+ public static final int locationScreenTitle=0x7f07000d;
+ public static final int main_frame_layout=0x7f070009;
+ public static final int mapview=0x7f07000f;
public static final int nextButton=0x7f070002;
public static final int previewFrameLayout=0x7f070022;
public static final int preview_image=0x7f07001e;
public static final int preview_text=0x7f07001f;
- public static final int preview_title=0x7f070013;
+ public static final int preview_title=0x7f070014;
public static final int select_image_from_gallery_button=0x7f070021;
- public static final int submit_button=0x7f07001c;
- public static final int thumbnails_scrollview=0x7f070007;
+ public static final int submit_button=0x7f07001d;
}
public static final class layout {
public static final int description_layout=0x7f030000;
- public static final int incident_gallery_layout=0x7f030001;
- public static final int incident_gallery_layout_cell=0x7f030002;
- public static final int location_layout=0x7f030003;
- public static final int main_screen_layout=0x7f030004;
- public static final int preview_layout=0x7f030005;
- public static final int select_image_layout=0x7f030006;
- public static final int take_picture=0x7f030007;
+ public static final int grid_incident_gallery_layout=0x7f030001;
+ public static final int incident_gallery_layout=0x7f030002;
+ public static final int incident_gallery_layout_cell=0x7f030003;
+ public static final int incident_layout_cellwithouttext=0x7f030004;
+ public static final int location_layout=0x7f030005;
+ public static final int main_screen_layout=0x7f030006;
+ public static final int preview_layout=0x7f030007;
+ public static final int select_image_layout=0x7f030008;
+ public static final int take_picture=0x7f030009;
}
public static final class string {
public static final int app_name=0x7f050000;
@@ -111,16 +114,19 @@
public static final int done=0x7f05000e;
public static final int errorInGeoCoding=0x7f050024;
public static final int errorInReverseGeoCoding=0x7f05001e;
- public static final int failed_camera_please_try_again=0x7f050032;
- public static final int failed_to_connect_to_camera_message=0x7f050033;
- public static final int failure_submission_msg=0x7f050036;
- public static final int geocoordinates_text=0x7f050034;
+ public static final int failed_camera_please_try_again=0x7f050033;
+ public static final int failed_to_connect_to_camera_message=0x7f050034;
+ public static final int failure_load_images_msg=0x7f050038;
+ public static final int failure_submission_msg=0x7f050037;
+ public static final int geocoordinates_text=0x7f050035;
public static final int gps_message=0x7f050017;
public static final int gps_message_submission=0x7f050016;
public static final int gps_no_location_message=0x7f05001b;
public static final int incident_view_gallery_title=0x7f050031;
+ public static final int incident_view_grid_title=0x7f050032;
+ public static final int loading_images_title=0x7f05003c;
public static final int locationTitle=0x7f05001c;
- public static final int main_screen_image=0x7f05003a;
+ public static final int main_screen_image=0x7f05003e;
public static final int negative_button_title=0x7f05001a;
public static final int newLocationFound=0x7f050020;
public static final int next=0x7f05000f;
@@ -137,6 +143,7 @@
public static final int pleaseEnterAddress=0x7f050015;
public static final int pleaseEnterDescription=0x7f050013;
public static final int please_select_a_image=0x7f050012;
+ public static final int please_wait=0x7f05003d;
public static final int positive_button_title=0x7f050019;
public static final int preview_description=0x7f05002b;
public static final int preview_descriptiontitle=0x7f05002a;
@@ -148,12 +155,12 @@
public static final int select_image_from_gallery=0x7f05002f;
public static final int select_image_title=0x7f050026;
public static final int select_location=0x7f050002;
- public static final int sending_incident_msg=0x7f050038;
- public static final int sending_incident_msg_please_wait=0x7f050039;
- public static final int sending_incident_title=0x7f050037;
+ public static final int sending_incident_msg=0x7f05003a;
+ public static final int sending_incident_msg_please_wait=0x7f05003b;
+ public static final int sending_incident_title=0x7f050039;
public static final int submit=0x7f050005;
public static final int submit_pollution_event=0x7f05000b;
- public static final int success_submission_msg=0x7f050035;
+ public static final int success_submission_msg=0x7f050036;
public static final int tag_labeltitle=0x7f050004;
public static final int take_picture_title=0x7f050030;
public static final int thisIsTheLocationFound=0x7f05001f;
View
BIN CowsEyeAndroidApplication/libs/android-support-v4.jar
Binary file not shown.
View
BIN CowsEyeAndroidApplication/res/drawable-mdpi/screen1.jpg
Deleted file not rendered
View
BIN CowsEyeAndroidApplication/res/drawable/cowgrazing.jpg
Deleted file not rendered
View
BIN CowsEyeAndroidApplication/res/drawable/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 CowsEyeAndroidApplication/res/drawable/logo_gallery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN CowsEyeAndroidApplication/res/drawable/logo_grid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN CowsEyeAndroidApplication/res/drawable/riverdogs.gif
Deleted file not rendered
View
BIN CowsEyeAndroidApplication/res/drawable/screen1.jpg
Deleted file not rendered
View
42 CowsEyeAndroidApplication/res/layout/grid_incident_gallery_layout.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="#ffffff"
+ android:orientation="vertical" >
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ android:id="@+id/contactDetailsScreenTitle"
+ style="@style/titleHeading"
+ android:text="@string/incident_view_grid_title" />
+
+ <Button
+ android:id="@+id/backButton"
+ style="@style/backButtonStyle" />
+
+ </FrameLayout>
+
+ <GridView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/gridview"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:columnWidth="90dp"
+ android:gravity="center"
+ android:horizontalSpacing="10dp"
+ android:numColumns="auto_fit"
+ android:stretchMode="columnWidth"
+ android:verticalSpacing="10dp" />
+
+ <Button
+ android:id="@+id/backButton"
+ android:layout_width="fill_parent"
+ android:layout_height="52dp"
+ android:layout_gravity="center"
+ android:textSize="20dp" />
+
+</LinearLayout>
View
46 CowsEyeAndroidApplication/res/layout/incident_gallery_layout.xml
@@ -3,8 +3,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/details_background"
- android:orientation="vertical"
- android:weightSum="1" >
+ android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
@@ -23,8 +22,7 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="0dp"
- android:layout_weight="0.8"
+ android:layout_height="fill_parent"
android:background="@drawable/details_background"
android:orientation="horizontal" >
@@ -40,28 +38,28 @@
</nz.co.android.cowseye.view.RiverWatchGallery>
</FrameLayout>
- <ScrollView
- android:id="@+id/thumbnails_scrollview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="0.2" >
+<!-- <ScrollView -->
+<!-- android:id="@+id/thumbnails_scrollview" -->
+<!-- android:layout_width="fill_parent" -->
+<!-- android:layout_height="wrap_content" -->
+<!-- android:layout_weight="0.2" > -->
- <!-- Layout for containing thumbnails of pages -->
+<!-- Layout for containing thumbnails of pages -->
- <LinearLayout
- android:id="@+id/holding_thumbs_linear_layout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
+<!-- <LinearLayout -->
+<!-- android:id="@+id/holding_thumbs_linear_layout" -->
+<!-- android:layout_width="wrap_content" -->
+<!-- android:layout_height="wrap_content" -->
+<!-- android:orientation="horizontal" > -->
- <FrameLayout
- android:id="@+id/holding_thumbs_frame_layout"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_gravity="bottom"
- android:orientation="horizontal" >
- </FrameLayout>
- </LinearLayout>
- </ScrollView>
+<!-- <FrameLayout -->
+<!-- android:id="@+id/holding_thumbs_frame_layout" -->
+<!-- android:layout_width="wrap_content" -->
+<!-- android:layout_height="match_parent" -->
+<!-- android:layout_gravity="bottom" -->
+<!-- android:orientation="horizontal" > -->
+<!-- </FrameLayout> -->
+<!-- </LinearLayout> -->
+<!-- </ScrollView> -->
</LinearLayout>
View
47 CowsEyeAndroidApplication/res/layout/incident_gallery_layout_cell.xml
@@ -2,14 +2,49 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_frame_layout"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center_horizontal">
+ android:layout_height="fill_parent" >
<!-- Background page image -->
- <ImageView
- android:id="@+id/incident_image"
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:weightSum="1" >
+
+ <ImageView
+ android:id="@+id/incident_image"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="0.85"
+ android:gravity="top"
+ android:src="@drawable/logo_gallery" >
+ </ImageView>
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_margin="5dp"
+ android:layout_weight="0.15"
+ android:background="@drawable/riverwatch_button" >
+
+ <TextView
+ android:id="@+id/incident_description"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textColor = "#000000"
+ android:gravity="center"
+ android:maxLines="5"
+ android:scrollbars="vertical" />
+ </FrameLayout>
+ </LinearLayout>
+
+ <ProgressBar
+ android:id="@+id/incident_progress_bar"
+ style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:scaleType="center">
- </ImageView>
+ android:layout_gravity="center"
+ android:visibility="visible" />
+
</FrameLayout>
View
26 CowsEyeAndroidApplication/res/layout/incident_layout_cellwithouttext.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/main_frame_layout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <!-- Background page image -->
+
+ <ImageView
+ android:id="@+id/incident_image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:scaleType="center"
+ android:src="@drawable/logo_grid" >
+ </ImageView>
+
+ <ProgressBar
+ android:id="@+id/incident_progress_bar"
+ style="?android:attr/progressBarStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:visibility="visible" />
+
+</FrameLayout>
View
87 CowsEyeAndroidApplication/res/layout/main_screen_layout.xml
@@ -1,51 +1,38 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/details_background"
- android:orientation="vertical" >
-
- <TextView
- android:id="@+id/detailsScreenTitle"
- style="@style/titleHeading"
- android:text="@string/app_name" />
-
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
-
- <!--
- <Button
- android:id="@+id/button_view_gallery"
- style="@style/riverWatchButtonStyle"
- android:text="@string/view_submission_gallery"
- android:visibility="invisible" />
-
- <Button
- android:id="@+id/button_view_server"
- style="@style/riverWatchButtonStyle"
- android:text="Change Server"
- android:visibility="invisible" />
-
- -->
-
- <ImageView
- android:id="@+id/MainScreenLogo"
- android:layout_width="wrap_content"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:src="@drawable/cowgrazing" />
-
- <Button android:id="@+id/button_submit"
- style="@style/riverWatchButtonStyle"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/submit_pollution_event" />
-
-
-
- </LinearLayout>
-
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/details_background"
+ android:orientation="vertical" >
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ android:id="@+id/contactDetailsScreenTitle"
+ style="@style/titleHeading"
+ android:text="@string/app_name" />
+ </FrameLayout>
+
+ <ImageView
+ android:id="@+id/MainScreenLogo"
+ android:layout_width="wrap_content"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:src="@drawable/logo" />
+
+ <Button
+ android:id="@+id/button_submit"
+ style="@style/riverWatchButtonStyle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/submit_pollution_event" />
+
+ <Button
+ android:id="@+id/button_view_gallery"
+ style="@style/riverWatchButtonStyle"
+ android:text="@string/view_submission_gallery"
+ android:visibility="visible" />
+
</LinearLayout>
View
2 CowsEyeAndroidApplication/res/layout/preview_layout.xml
@@ -31,7 +31,7 @@
android:id="@+id/PreviewImageTitle"
style="@style/field_title_style"
android:layout_gravity="center_horizontal"
- android:text="@string/preview_title" />
+ android:text="@string/preview_image" />
<ImageView
android:id="@+id/PreviewImageImage"
View
12 CowsEyeAndroidApplication/res/values/colors.xml
@@ -1,6 +1,6 @@
<resources>
- <color name="back_button_start_colour">#EE5F5B</color>
+ <color name="back_button_start_colour">#EE5F5B</color>
<color name="back_button_end_colour">#BD3625</color>
<color name="done_button_start_colour">#62C462</color>
<color name="done_button_end_colour">#51A351</color>
@@ -16,9 +16,9 @@
<color name="preview_background_start">#C0BABA</color>
<color name="preview_background_end">#C0DAFF</color>
<color name="riverWatch_outline_color">#003310</color>
- <color name = "riverWatch_button_start_colour"> #5BC0DE </color>
- <color name = "riverWatch_button_end_colour"> #2F96B4 </color>
- <color name = "riverWatch_selectbutton_start_colour"> #FBB450 </color>
- <color name = "riverWatch_selectbutton_end_colour"> #F89406 </color>
-
+ <color name="riverWatch_button_start_colour">#5BC0DE</color>
+ <color name="riverWatch_button_end_colour">#2F96B4</color>
+ <color name="riverWatch_selectbutton_start_colour">#FBB450</color>
+ <color name="riverWatch_selectbutton_end_colour">#F89406</color>
+
</resources>
View
16 CowsEyeAndroidApplication/res/values/strings.xml
@@ -1,6 +1,6 @@
<resources>
- <string name="app_name">RiverWatch</string>
+ <string name="app_name">River Watch</string>
<string name="capture_image">Capture Image</string>
<string name="select_location">Select Location</string>
<string name="description_labeltitle"> Enter Image Description </string>
@@ -42,24 +42,30 @@
<string name="errorInGeoCoding">Unable to convert address to location coordinates</string>
<string name="pleaseCompleteAllSteps">Please complete all steps before submitting your incident</string>
<string name="select_image_title">Select Image</string>
- <string name="preview_title">Preview</string>
- <string name="preview_image">Picture</string>
+ <string name="preview_title">Preview Incident</string>
+ <string name="preview_image">Image</string>
<string name="preview_location">Location</string>
<string name="preview_descriptiontitle"> Description</string>
<string name="preview_description"> Description</string>
<string name="preview_imagetag"> Image Tag </string>
- <string name="preview_imagetagtitle"> Image Tag </string>
+ <string name="preview_imagetagtitle"> Tag </string>
<string name="no_preview_available">No Preview Available</string>
<string name="select_image_from_gallery">Select Image From Gallery</string>
<string name="take_picture_title">Capture Image</string>
<string name="incident_view_gallery_title">Gallery</string>
+ <string name="incident_view_grid_title">Incident Gallery </string>
+
<string name="failed_camera_please_try_again">Failed to save image, please try again</string>
<string name="failed_to_connect_to_camera_message">Failed to open camera. Please try again later</string>
<string name="geocoordinates_text">Geocoordinate location:</string>
<string name="success_submission_msg">You have succesfully submitted a river pollution incident.</string>
<string name="failure_submission_msg">Your incident submission was unsuccessful. Please try again later.</string>
+ <string name="failure_load_images_msg">Failed to obtain river pollution images. Please try again later.</string>
<string name="sending_incident_title">Incident Submission</string>
<string name="sending_incident_msg">Submitting your river pollution incident...</string>
<string name="sending_incident_msg_please_wait">Please wait</string>
- <string name = "main_screen_image"> Main Image </string>
+ <string name="loading_images_title">Loading River Pollution Images</string>
+ <string name="please_wait">Please wait...</string>
+ <string name="main_screen_image"> Main Image </string>
+
</resources>
View
115 CowsEyeAndroidApplication/src/nz/co/android/cowseye/RiverWatchApplication.java
@@ -7,11 +7,19 @@
import java.util.Timer;
import java.util.TimerTask;
+import nz.co.android.cowseye.database.DatabaseAdapter;
+import nz.co.android.cowseye.database.DatabaseConstructor;
import nz.co.android.cowseye.event.Event;
import nz.co.android.cowseye.event.EventHandler;
+import nz.co.android.cowseye.utility.Utils;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+
import android.app.Application;
import android.content.Context;
import android.database.Cursor;
+import android.database.SQLException;
import android.graphics.Bitmap;
import android.location.LocationManager;
import android.net.ConnectivityManager;
@@ -23,9 +31,11 @@
public class RiverWatchApplication extends Application {
/* Service paths */
- public static String server_path = "http://barretts.ecs.vuw.ac.nz:4567/wainz/";
- public static String submission_path = server_path + "submit/";
-
+ public static String server_path = "http://barretts.ecs.vuw.ac.nz:4567/wainz";
+ public static String submission_path = server_path + "/submit";
+ public static String get_incidents_path = server_path + "/approved";
+ public static String get_incidents_path_start = "/start=";
+ public static String get_incidents_path_number = "/number=";
private static final long timerZeroDelay = 0;
private static final long timerEventsProcessingPeriod = 300000; // 5 minutes
@@ -37,40 +47,39 @@
public EventHandler eventHandler;
private Timer updateEventsTimer;
+ private DatabaseConstructor databaseConstructor;
+ private DatabaseAdapter databaseAdapter;
//Start of application
@Override
public void onCreate() {
super.onCreate();
-// loadDatabase();
+ loadDatabase();
setupApplication();
}
private void setupApplication() {
updateEventsTimer = new Timer();
eventHandler = new EventHandler(this);
-// List<Event> unProcessdEvents = databaseAdapter.getAllUnProcessedEvents(this);
-// for(Event e : unProcessdEvents)
-// eventHandler.addEvent(e);
}
/**
* Constructs and loads the database
*/
-// private void loadDatabase(){
-// databaseConstructor = new DatabaseConstructor(this);
-// try {
-// databaseConstructor.createDataBase();
-// } catch (IOException ioe) {
-// Log.e(this.toString(),"Unable to create database");
-// }
-// try {
-// databaseConstructor.openDataBase();
-// }catch(SQLException sqle){
-// Log.e(this.toString(),"Unable to open database");
-// }
-// databaseAdapter = new DatabaseAdapter(databaseConstructor);
-// }
+ private void loadDatabase(){
+ databaseConstructor = new DatabaseConstructor(this);
+ try {
+ databaseConstructor.createDataBase();
+ } catch (IOException ioe) {
+ Log.e(this.toString(),"Unable to create database");
+ }
+ try {
+ databaseConstructor.openDataBase();
+ }catch(SQLException sqle){
+ Log.e(this.toString(),"Unable to open database");
+ }
+ databaseAdapter = new DatabaseAdapter(databaseConstructor);
+ }
// /** Adds this event to the database of events
@@ -84,9 +93,9 @@ private void setupApplication() {
// }
-// public DatabaseAdapter getDatabaseAdapter() {
-// return databaseAdapter;
-// }
+ public DatabaseAdapter getDatabaseAdapter() {
+ return databaseAdapter;
+ }
public EventHandler getEventHandler(){
@@ -196,10 +205,10 @@ public boolean isGPSEnabled(){
// }
/* Saves a bitmap to disk */
- private String saveBitmapToDisk(Bitmap bitmap) throws IOException {
+ public String saveBitmapToDisk(Bitmap bitmap, int incidentId, boolean isThumb) throws IOException {
try{
- final long num = System.currentTimeMillis();
- final String ID = getString(R.string.app_name) +num;
+// final long num = System.currentTimeMillis();
+ final String ID = getString(R.string.app_name).replace(" ", "_")+ (isThumb? "thumb" : "full") +"_"+incidentId;
File dir = this.getDir("", Context.MODE_PRIVATE);
String pathToDir = dir.getAbsolutePath();
final String pathName = pathToDir + File.separator+ ID;
@@ -209,22 +218,18 @@ private String saveBitmapToDisk(Bitmap bitmap) throws IOException {
}
catch (FileNotFoundException e) {
e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- }
+ }
throw new IOException("Could not create file or could not write to created file");
}
/** Deletes an image from local storage */
public void deleteImage(String filePath) {
File imageFile = new File(filePath);
- Log.d(toString(), "deleteImage image exists before ? "+imageFile.exists());
-
+// Log.d(toString(), "deleteImage image exists before ? "+imageFile.exists());
//delete image
if(imageFile.exists())
imageFile.delete();
- Log.d(toString(), "deleteImage image exists after ? "+imageFile.exists());
+// Log.d(toString(), "deleteImage image exists after ? "+imageFile.exists());
}
@@ -248,14 +253,51 @@ public void deleteImage(String filePath) {
//
// }
+ /**
+ * Deals with the response from a submission event return
+ * @param response from a submission event
+ * @return true if succesfull submission, otherwise false
+ */
+ public static boolean processEventResponse(HttpResponse response){
+ if(response==null)
+ return false;
+ StatusLine statusLine = response.getStatusLine();
+ if(statusLine == null)
+ return false;
+ int statusCode = statusLine.getStatusCode();
+ try{
+ switch(statusCode){
+ case Utils.HTTP_OK:
+ Log.i("app", "statusCode : "+statusCode+", Sucessful event response!");
+ return true;
+ case Utils.HTTP_LOGIC_ERROR:
+ Log.i("app", "statusCode : "+statusCode+", Logic error: Unsucessful event response!");
+ return false;
+ case Utils.HTTP_SERVER_ERROR:
+ Log.i("app", "statusCode : "+statusCode+", Server error: Unsucessful event response!");
+ return false;
+ default:
+ Log.i("app", "statusCode : "+statusCode+", ncaught error: Unsucessful event response!");
+ return false;
+ }
+ // JSONObject jsonObject = JSONHelper.parseHttpResponseAsJSON(response);
+ // Log.d("app", "jsonObject : "+jsonObject);
+ }
+ catch(Exception f){
+ Log.e("app", "Exception in JsonParsing : "+f);
+ }
+ return false;
+
+ }
+
/* Deletes the image belonging to the current event */
public void deleteImage(Event currentEvent) {
File imageFile = new File(currentEvent.getImagePath().toString());
- Log.d(toString(), "deleteImage image exists before ? "+imageFile.exists());
+// Log.d(toString(), "deleteImage image exists before ? "+imageFile.exists());
//delete image
if(imageFile.exists())
imageFile.delete();
- Log.d(toString(), "deleteImage image exists after ? "+imageFile.exists());
+// Log.d(toString(), "deleteImage image exists after ? "+imageFile.exists());
}
@@ -264,7 +306,6 @@ public String getRealPathFromURI(Uri contentURI) {
.query(contentURI, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
- Log.d(toString(), "path : "+cursor.getString(idx));
return cursor.getString(idx);
}
}
View
9 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/DescriptionActivity.java
@@ -93,7 +93,6 @@ public void onItemSelected(AdapterView<?> parent, View view, int pos,
// An item was selected. You can retrieve the selected item using
imageTag = (String) parent.getItemAtPosition(pos);
submissionEventBuilder.setImageTag(imageTags);
- Log.e("image tag is", imageTag);
}
public void onNothingSelected(AdapterView<?> parent) {
@@ -106,8 +105,6 @@ public void onNothingSelected(AdapterView<?> parent) {
*/
public void pressNextButton() {
- Log.d(toString(), "Sent image tags");
-
tosendtags = new ArrayList<String>();
nextButton.setOnClickListener(new View.OnClickListener() {
@@ -139,10 +136,6 @@ public void onClick(View v) {
imageDescription = descriptionEditText.getText().toString();
submissionEventBuilder
.setImageDescription(imageDescription);
- System.out.println("Sent DESCRIPTION");
- Log.e("image description is", imageDescription);
-
-
//checks if there has been any tags selected, else doesn't let the user progress through
if (numberOfSelections == 0) {
Toast.makeText(DescriptionActivity.this,
@@ -157,8 +150,6 @@ public void onClick(View v) {
RecordLocationActivity.class);
submissionEventBuilder.setImageTag(tosendtags);
- Log.d("hi", "reached here tan");
-
startActivity(intent);
}
View
159 ...EyeAndroidApplication/src/nz/co/android/cowseye/activity/GridIncidentGalleryActivity.java
@@ -0,0 +1,159 @@
+package nz.co.android.cowseye.activity;
+
+import java.util.List;
+import nz.co.android.cowseye.R;
+import nz.co.android.cowseye.RiverWatchApplication;
+import nz.co.android.cowseye.common.Constants;
+import nz.co.android.cowseye.database.Incident;
+import nz.co.android.cowseye.event.GetImageEvent;
+import nz.co.android.cowseye.service.GetImageAsyncTask;
+import nz.co.android.cowseye.view.RiverWatchGallery.ViewHolder;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+import android.widget.FrameLayout.LayoutParams;
+import android.widget.GridView;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+
+
+public class GridIncidentGalleryActivity extends Activity {
+
+ private Button backButton;
+
+ private RiverWatchApplication myApplication;
+ private LayoutInflater inflater;
+
+ private List<Incident> incidents;
+ private Handler handler;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.grid_incident_gallery_layout);
+
+ myApplication = (RiverWatchApplication) getApplication();
+ incidents = myApplication.getDatabaseAdapter().getAllIncidents();
+ this.handler = new Handler();
+ // Cache the LayoutInflate to avoid asking for a new one each time.
+ inflater = LayoutInflater.from(this);
+
+ GridView gridview = (GridView) findViewById(R.id.gridview);
+ gridview.setAdapter(new ImageAdapter(this));
+ gridview.setOnItemClickListener(new OnItemClickListener() {
+ Intent intent = new Intent(GridIncidentGalleryActivity.this,
+ IncidentGalleryActivity.class);
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View view,
+ int position, long arg3) {
+
+ intent.putExtra("Page Number", position);
+ startActivity(intent);
+
+ }
+ });
+
+ backButton = (Button) findViewById(R.id.backButton);
+ backButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ onBackPressed();
+ }
+ });
+
+ }
+
+ private class ImageAdapter extends BaseAdapter {
+ private Context mContext;
+
+ public ImageAdapter(Context c) {
+ mContext = c;
+ }
+
+ public int getCount() {
+ return incidents.size();
+ }
+
+ public Incident getItem(int position) {
+ return incidents.get(position);
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ // create a new ImageView for each item referenced by the Adapter
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ final ViewHolder holder;
+ if (convertView == null) { // if it's not recycled, initialize some
+ // attributes
+ convertView = inflater.inflate(R.layout.incident_layout_cellwithouttext, null);
+ holder = new ViewHolder();
+
+ holder.imageView = (ImageView) convertView.findViewById(R.id.incident_image);
+ holder.descriptionView = (TextView)convertView.findViewById(R.id.incident_description);
+ holder.progressBar = (ProgressBar) convertView.findViewById(R.id.incident_progress_bar);
+
+ holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ holder.imageView.setPadding(8, 8, 8, 8);
+ convertView.setTag(holder);
+ } else {
+ // Get the ViewHolder back to get fast access to the View
+ holder = (ViewHolder) convertView.getTag();
+ }
+ buildView(position, holder);
+
+ return convertView;
+ }
+ }
+
+ public class ViewHolder {
+ ProgressBar progressBar;
+ ImageView imageView;
+ TextView descriptionView;
+ }
+
+ /* Build a View for the MyGalleryImage adapter */
+ public void buildView(int position, final ViewHolder holder) {
+ Incident incident = incidents.get(position);
+ // try to get from local storage
+ String localImageUri = incident.getLocalThumbnailUrl();
+ if (localImageUri != null && !localImageUri.equals("")){
+ setImage(holder, localImageUri, position);
+ }
+ else {
+ /**
+ * If fails to get from local storage, put a progress bar in and
+ * download
+ */
+ // launch asynctask to get image
+ GetImageEvent event = new GetImageEvent(incident.getThumbnailUrl());
+ new GetImageAsyncTask(myApplication, this, holder, event, position, incident.getId()).execute();
+ }
+ }
+
+ public void setImage(ViewHolder holder, String pathName, int positionInArray) {
+ if (pathName != null && !pathName.equals("")) {
+ incidents.get(positionInArray).setLocalThumbnailUrl(pathName);
+ Bitmap bm = BitmapFactory.decodeFile(pathName);
+ holder.imageView.setImageBitmap(bm);
+ holder.progressBar.setVisibility(View.INVISIBLE);
+ }
+ }
+
+}
View
366 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/IncidentGalleryActivity.java
@@ -1,222 +1,232 @@
package nz.co.android.cowseye.activity;
-import java.util.ArrayList;
import java.util.List;
import nz.co.android.cowseye.R;
import nz.co.android.cowseye.RiverWatchApplication;
-import nz.co.android.cowseye.event.SubmissionEventBuilder;
+import nz.co.android.cowseye.common.Constants;
+import nz.co.android.cowseye.database.Incident;
import nz.co.android.cowseye.utility.Utils;
import nz.co.android.cowseye.view.RiverWatchGallery;
import android.app.Activity;
-import android.graphics.Color;
+import android.content.Intent;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.ImageButton;
-import android.widget.ImageView.ScaleType;
-import android.widget.LinearLayout;
-import android.widget.ScrollView;
public class IncidentGalleryActivity extends Activity {
private Button backButton;
private RiverWatchGallery myGallery;
private RiverWatchApplication myApplication;
-
- private FrameLayout thumbnailsLayout; // this is the layout that will contain the thumbnails of the pages
- private LinearLayout holdingThumbsLayout;
- private ScrollView scrollView; // the scrollview for containing the thumbnails
- private boolean thumbnailLayoutOrigami = false;
- private boolean thumbnailsStarted = false;
- private ArrayList<ImageButton> thumbnails;
- private ArrayList<String> thumbnailPaths;
+ // private FrameLayout thumbnailsLayout; // this is the layout that will
+ // contain the thumbnails of the pages
+ // private LinearLayout holdingThumbsLayout;
+ // private ScrollView scrollView; // the scrollview for containing the
+ // thumbnails
+ // private boolean thumbnailLayoutOrigami = false;
+ // private boolean thumbnailsStarted = false;
+ // private ArrayList<ImageButton> thumbnails;
private int currentPosition = 0;
- public static Matrix skewUpMatrix;
- public static Matrix skewDownMatrix;
- public static RectF imageRectangleSkewedUp;
- public static RectF imageRectangleSkewedDown;
-
- private static final float THUMBNAIL_SKEW = 0.3f;
- private static final int THUMBNAIL_WIDTH = 100;
- private static final int THUMBNAIL_HEIGHT = 75;
- private static final float THUMBNAIL_SCALEX = 0.8f;
- private static final float THUMBNAIL_SCALEY = 0.8f;
- public static final int UNSELECTED_ALPHA = 160;
- public static final int SELECTED_ALPHA = 255;
+// public static Matrix skewUpMatrix;
+// public static Matrix skewDownMatrix;
+// public static RectF imageRectangleSkewedUp;
+// public static RectF imageRectangleSkewedDown;
+
+ // private static final float THUMBNAIL_SKEW = 0.3f;
+ // private static final int THUMBNAIL_WIDTH = 100;
+ // private static final int THUMBNAIL_HEIGHT = 75;
+ // private static final float THUMBNAIL_SCALEX = 0.8f;
+ // private static final float THUMBNAIL_SCALEY = 0.8f;
+// public static final int UNSELECTED_ALPHA = 160;
+// public static final int SELECTED_ALPHA = 255;
+
+ private int pageNumber;
+
+ private List<Incident> incidents;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.incident_gallery_layout);
+ myApplication = (RiverWatchApplication) getApplication();
+ Intent intent = getIntent();
+ pageNumber = intent.getIntExtra("Page Number", 1);
+ incidents = myApplication.getDatabaseAdapter().getAllIncidents();
+
setupUI();
- thumbnailPaths = new ArrayList<String>();
- thumbnailPaths.add("123");
- thumbnailPaths.add("1213");
- thumbnailPaths.add("11223");
- thumbnailPaths.add("1223");
- setupThumbnails();
- constructMatrices();
- constructImageRectangleBounds();
- redrawThumbnails();
+
+ // setupThumbnails();
+ // constructMatrices();
+ // constructImageRectangleBounds();
+ // redrawThumbnails();
}
private void setupUI() {
- backButton = (Button)findViewById(R.id.backButton);
- //goes backwards
+ backButton = (Button) findViewById(R.id.backButton);
+ // goes backwards
backButton.setOnClickListener(new Utils.BackEventOnClickListener(this));
-
- myApplication = (RiverWatchApplication)getApplication();
myGallery = (RiverWatchGallery) (findViewById(R.id.incident_gallery));
- //TODO show ProgressDialog querying for image downloads
- List<String> imageUris = new ArrayList<String>();
- imageUris.add(SubmissionEventBuilder.getSubmissionEventBuilder(myApplication).getImagePath().toString());
- imageUris.add(SubmissionEventBuilder.getSubmissionEventBuilder(myApplication).getImagePath().toString());
- imageUris.add(SubmissionEventBuilder.getSubmissionEventBuilder(myApplication).getImagePath().toString());
-
- myGallery.setupUI(myApplication, this, imageUris);
- }
-
- private void setupThumbnails(){
- thumbnailsStarted = false;
- holdingThumbsLayout = (LinearLayout) findViewById(R.id.holding_thumbs_linear_layout);
- thumbnailsLayout = (FrameLayout)findViewById(R.id.holding_thumbs_frame_layout);
- scrollView = (ScrollView) findViewById(R.id.thumbnails_scrollview);
- thumbnails = new ArrayList<ImageButton>();
- }
- /* Constructs the matrices for skewing the thumbnails */
- private void constructMatrices(){
- skewUpMatrix = new Matrix();
- skewUpMatrix.postSkew(0f, THUMBNAIL_SKEW*-1, THUMBNAIL_WIDTH/2,0);
- skewUpMatrix.postScale(THUMBNAIL_SCALEX, THUMBNAIL_SCALEY,0, THUMBNAIL_HEIGHT);
- skewDownMatrix = new Matrix();
- skewDownMatrix.postSkew(0f, THUMBNAIL_SKEW*1, THUMBNAIL_WIDTH/2,0);
- skewDownMatrix.postScale(THUMBNAIL_SCALEX, THUMBNAIL_SCALEY,0, THUMBNAIL_HEIGHT);
- }
-
- /* Constructs the rectangles for the bounds of the image after skewing */
- private void constructImageRectangleBounds(){
- imageRectangleSkewedUp = new RectF(0, 0, THUMBNAIL_WIDTH,THUMBNAIL_HEIGHT);
- skewUpMatrix.mapRect(imageRectangleSkewedUp);
- imageRectangleSkewedDown= new RectF(0, 0, THUMBNAIL_WIDTH,THUMBNAIL_HEIGHT);
- skewDownMatrix.mapRect(imageRectangleSkewedDown);
- }
-
- /** Sets the selected page to the given thumbnail position */
- public void setThumbnailSelection(int pos){
- if(pos!=currentPosition ){
- if(thumbnails!=null && thumbnails.size()>0 && thumbnails.size()>pos){
- //set alpha on old thumbnail and remove color filter
- ImageButton oldImage = thumbnails.get(currentPosition);
- oldImage.setAlpha(UNSELECTED_ALPHA);
- oldImage.setBackgroundColor(0000);
- currentPosition = pos;
- //set alpha on new thumbnail and put on color filter
- ImageButton newImage = thumbnails.get(currentPosition);
- newImage.setBackgroundColor(Color.BLACK);
- newImage.setAlpha(SELECTED_ALPHA);
-
- repositionScrollView(newImage);
- }
- }
- }
- /* Repositions the scroll view to fit the new image selected */
- private void repositionScrollView(ImageButton newImage) {
- //TODO use layoutparams
- // double edgeImage = newImage.getX();
- // double edgeScroll = bhsv.getScrollX();
- //
- // // move scrollview right if image is offscreen on the left
- // if(edgeImage < edgeScroll)
- // bhsv.scrollTo((int) edgeImage, 0);
- // edgeImage = newImage.getX()+newImage.getDrawable().getIntrinsicWidth();
- // edgeScroll = bhsv.getScrollX()+bhsv.getWidth();
- // // move scrollview left if image is offscreen on the right
- // if(edgeImage > edgeScroll){
- // bhsv.scrollTo((int) edgeImage-bhsv.getWidth(), 0);
- // }
- }
+ myGallery.setupUI(myApplication, incidents);
+ myGallery.setImageAdapterSelection(pageNumber);
- // /** Deletes all the thumnbnails in the content layout */
- // private void resetThumbnails(){
- // thumbnailsLayout.removeAllViews();
- // thumbnails = new ArrayList<ImageButton>();
- // }
- //
- public void redrawThumbnails() {
- if(thumbnails==null)
- return;
- // resetThumbnails();
- int maxHeight = 0;
- //x coordinate of the last thumbnail placed
- float lastX = 0f;
- for(int pos = 0; pos < thumbnailPaths.size(); pos++){
- //create image
- ImageButton image = new ImageButton(this);
- int wd;
- int ht;
- image.setImageResource(R.drawable.default_thumb);
- image.setOnClickListener(new ThumbnailClickListener(pos));
- if(thumbnailLayoutOrigami){
- image.setPadding(0, 0, 0, 0);
- image.setScaleType(ScaleType.MATRIX);
-
- boolean skewUp = (pos%2==0)? true : false;
- image.setImageMatrix((skewUp)? skewUpMatrix : skewDownMatrix);
- wd = (int) ((skewUp)? imageRectangleSkewedUp.width() : imageRectangleSkewedDown.width());
- ht = (int) ((skewUp)? imageRectangleSkewedUp.height()*1.5 : imageRectangleSkewedDown.height()*1.5);
- if(ht > maxHeight)
- maxHeight = ht;
- }
- else{
- wd = image.getDrawable().getIntrinsicWidth();
- ht = image.getDrawable().getIntrinsicHeight();
- if(ht > maxHeight)
- maxHeight = ht;
- lastX+=15;
- }
- image.setBackgroundDrawable(null);
- if(pos!=currentPosition)
- image.setAlpha(UNSELECTED_ALPHA);
- else
- image.setAlpha(SELECTED_ALPHA);
-// image.setX(lastX);
-// image.setLayoutParams(new FrameLayout.LayoutParams()))
- thumbnails.add(image);
- holdingThumbsLayout.addView(image);
-// thumbnailsLayout.addView(image,lp);
- lastX+=wd;
- }
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int) lastX, maxHeight);
- thumbnailsLayout.setLayoutParams(lp);
}
- public void setThumbnailsLayout(FrameLayout layout){
- thumbnailsLayout = layout;
- holdingThumbsLayout.addView(thumbnailsLayout);
- }
+ //
+ // private void setupThumbnails(){
+ // thumbnailsStarted = false;
+ // holdingThumbsLayout = (LinearLayout)
+ // findViewById(R.id.holding_thumbs_linear_layout);
+ // thumbnailsLayout =
+ // (FrameLayout)findViewById(R.id.holding_thumbs_frame_layout);
+ // scrollView = (ScrollView) findViewById(R.id.thumbnails_scrollview);
+ // thumbnails = new ArrayList<ImageButton>();
+ // }
+
+ // /* Constructs the matrices for skewing the thumbnails */
+ // private void constructMatrices(){
+ // skewUpMatrix = new Matrix();
+ // skewUpMatrix.postSkew(0f, THUMBNAIL_SKEW*-1, THUMBNAIL_WIDTH/2,0);
+ // skewUpMatrix.postScale(THUMBNAIL_SCALEX, THUMBNAIL_SCALEY,0,
+ // THUMBNAIL_HEIGHT);
+ // skewDownMatrix = new Matrix();
+ // skewDownMatrix.postSkew(0f, THUMBNAIL_SKEW*1, THUMBNAIL_WIDTH/2,0);
+ // skewDownMatrix.postScale(THUMBNAIL_SCALEX, THUMBNAIL_SCALEY,0,
+ // THUMBNAIL_HEIGHT);
+ // }
+
+ // /* Constructs the rectangles for the bounds of the image after skewing */
+ // private void constructImageRectangleBounds(){
+ // imageRectangleSkewedUp = new RectF(0, 0,
+ // THUMBNAIL_WIDTH,THUMBNAIL_HEIGHT);
+ // skewUpMatrix.mapRect(imageRectangleSkewedUp);
+ // imageRectangleSkewedDown= new RectF(0, 0,
+ // THUMBNAIL_WIDTH,THUMBNAIL_HEIGHT);
+ // skewDownMatrix.mapRect(imageRectangleSkewedDown);
+ // }
+ //
+ // /** Sets the selected page to the given thumbnail position */
+ // public void setThumbnailSelection(int pos){
+ // if(pos!=currentPosition ){
+ // if(thumbnails!=null && thumbnails.size()>0 && thumbnails.size()>pos){
+ // //set alpha on old thumbnail and remove color filter
+ // ImageButton oldImage = thumbnails.get(currentPosition);
+ // oldImage.setAlpha(UNSELECTED_ALPHA);
+ // oldImage.setBackgroundColor(0000);
+ // currentPosition = pos;
+ // //set alpha on new thumbnail and put on color filter
+ // ImageButton newImage = thumbnails.get(currentPosition);
+ // newImage.setBackgroundColor(Color.BLACK);
+ // newImage.setAlpha(SELECTED_ALPHA);
+ //
+ // repositionScrollView(newImage);
+ // }
+ // }
+ // }
+ // /* Repositions the scroll view to fit the new image selected */
+ // private void repositionScrollView(ImageButton newImage) {
+ // //TODO use layoutparams
+ // // double edgeImage = newImage.getX();
+ // // double edgeScroll = bhsv.getScrollX();
+ // //
+ // // // move scrollview right if image is offscreen on the left
+ // // if(edgeImage < edgeScroll)
+ // // bhsv.scrollTo((int) edgeImage, 0);
+ // // edgeImage =
+ // newImage.getX()+newImage.getDrawable().getIntrinsicWidth();
+ // // edgeScroll = bhsv.getScrollX()+bhsv.getWidth();
+ // // // move scrollview left if image is offscreen on the right
+ // // if(edgeImage > edgeScroll){
+ // // bhsv.scrollTo((int) edgeImage-bhsv.getWidth(), 0);
+ // // }
+ // }
+
+ // /** Deletes all the thumnbnails in the content layout */
+ // private void resetThumbnails(){
+ // thumbnailsLayout.removeAllViews();
+ // thumbnails = new ArrayList<ImageButton>();
+ // }
+
+ // public void redrawThumbnails() {
+ // if(thumbnails==null)
+ // resetThumbnails();
+ // int maxHeight = 0;
+ // //x coordinate of the last thumbnail placed
+ // float lastX = 0f;
+ // for(int pos = 0; pos < serverThumbnailImageUris.length; pos++){
+ // Log.d(toString(), "thumnbnail at pos: "+pos);
+ // //create image
+ // ImageButton image = new ImageButton(this);
+ // int wd;
+ // int ht;
+ // image.setImageResource(R.drawable.default_thumb);
+ // image.setOnClickListener(new ThumbnailClickListener(pos));
+ // if(thumbnailLayoutOrigami){
+ // image.setPadding(0, 0, 0, 0);
+ // image.setScaleType(ScaleType.MATRIX);
+ //
+ // boolean skewUp = (pos%2==0)? true : false;
+ // image.setImageMatrix((skewUp)? skewUpMatrix : skewDownMatrix);
+ // wd = (int) ((skewUp)? imageRectangleSkewedUp.width() :
+ // imageRectangleSkewedDown.width());
+ // ht = (int) ((skewUp)? imageRectangleSkewedUp.height()*1.5 :
+ // imageRectangleSkewedDown.height()*1.5);
+ // if(ht > maxHeight)
+ // maxHeight = ht;
+ // }
+ // else{
+ // wd = image.getDrawable().getIntrinsicWidth();
+ // ht = image.getDrawable().getIntrinsicHeight();
+ // if(ht > maxHeight)
+ // maxHeight = ht;
+ // lastX+=15;
+ // }
+ // image.setBackgroundDrawable(null);
+ // if(pos!=currentPosition)
+ // image.setAlpha(UNSELECTED_ALPHA);
+ // else
+ // image.setAlpha(SELECTED_ALPHA);
+ // // image.setX(lastX);
+ // FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(wd, ht);
+ // flp.setMargins((int)lastX, 0, 0, 0);
+ // image.setLayoutParams(flp);
+ // thumbnails.add(image);
+ // holdingThumbsLayout.addView(image);
+ // // thumbnailsLayout.addView(image,lp);
+ // lastX+=wd;
+ // }
+ // LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int) lastX,
+ // maxHeight);
+ // thumbnailsLayout.setLayoutParams(lp);
+ // }
+ //
+ // public void setThumbnailsLayout(FrameLayout layout){
+ // thumbnailsLayout = layout;
+ // holdingThumbsLayout.addView(thumbnailsLayout);
+ // }
/* Class for dealing with a click on the given page thumbnail */
- public class ThumbnailClickListener implements OnClickListener{
-
- private final int position;
- public ThumbnailClickListener(int position){
- this.position = position;
- }
- public void onClick(View v) {
- if(position!=currentPosition){
- setThumbnailSelection(position);
- myGallery.setImageAdapterSelection(position);
- }
- }
- }
+// public class ThumbnailClickListener implements OnClickListener {
+//
+// private final int position;
+//
+// public ThumbnailClickListener(int position) {
+// this.position = position;
+// }
+//
+// public void onClick(View v) {
+// if (position != currentPosition) {
+// // setThumbnailSelection(position);
+// myGallery.setImageAdapterSelection(position);
+// }
+// }
+// }
}
View
93 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/MainScreenActivity.java
@@ -1,6 +1,8 @@
package nz.co.android.cowseye.activity;
import org.apache.http.HttpResponse;
+import org.json.JSONArray;
+import org.json.JSONException;
import org.json.JSONObject;
import nz.co.android.cowseye.R;
@@ -10,13 +12,16 @@
import nz.co.android.cowseye.R.string;
import nz.co.android.cowseye.common.Constants;
import nz.co.android.cowseye.event.Event;
+import nz.co.android.cowseye.event.GetIncidentsEvent;
import nz.co.android.cowseye.event.SubmissionEventBuilder;
import nz.co.android.cowseye.event.SubmissionEventBuilderException;
+import nz.co.android.cowseye.service.GetIncidentsAsyncTask;
import nz.co.android.cowseye.utility.AlertBuilder;
import nz.co.android.cowseye.utility.JSONHelper;
import nz.co.android.cowseye.utility.Utils;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -48,9 +53,14 @@
private Button buttonSubmit;
private Button buttonGallery;
private RiverWatchApplication myApplication;
- private Button buttonServer;
-
- private boolean test = false;
+
+ private ProgressDialog progressDialog;
+
+ private String[] imageUrls;
+ private String[] thumbUrls;
+ private String[] descriptions;
+ private boolean loadingGridView = false;
+ private boolean haveBaseIncidents = false;
/** Called when the activity is first created. */
@@ -60,7 +70,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main_screen_layout);
myApplication = (RiverWatchApplication)getApplication();
setupUI();
- Log.d(toString(), "onCreate");
+ new GetIncidentsAsyncTask(MainScreenActivity.this, new GetIncidentsEvent(myApplication, 0, 50),myApplication).execute();
}
/** This gets called after a successfull submission event as the activity is already open and
@@ -80,43 +90,74 @@ protected boolean networkIsConnected() {
/* Sets up the UI */
private void setupUI(){
+ progressDialog = new ProgressDialog(this);
+ progressDialog.setTitle(getString(R.string.loading_images_title));
+ progressDialog.setMessage(getString(R.string.please_wait));
+ progressDialog.setCancelable(false);
+
buttonSubmit = (Button)findViewById(R.id.button_submit);
buttonSubmit.setOnClickListener(new SubmitPollutionEventOnClickListener());
-// buttonGallery = (Button)findViewById(R.id.button_view_gallery);
-// buttonGallery.setOnClickListener(new View.OnClickListener() {
-// @Override
-// public void onClick(View v) {
-// startActivity(new Intent(MainScreenActivity.this, IncidentGalleryActivity.class));
-// }
-// });
-// buttonServer = (Button)findViewById(R.id.button_view_server);
-// buttonServer.setOnClickListener(new View.OnClickListener() {
-// @Override
-// public void onClick(View v) {
-// AlertBuilder.buildServerPrompt(MainScreenActivity.this).show();
-// }
-// });
-// if(test){
-// buttonGallery.setVisibility(View.VISIBLE);
-// buttonServer.setVisibility(View.VISIBLE);
-// }
+ buttonGallery = (Button)findViewById(R.id.button_view_gallery);
+ buttonGallery.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ progressDialog.show();
+ //only get new list of incidents if we don't already have them
+ if(!haveBaseIncidents){
+ new GetIncidentsAsyncTask(MainScreenActivity.this, new GetIncidentsEvent(myApplication, 0, 50), myApplication).execute();
+ loadingGridView = true;
+ }
+ else
+ loadGridView();
+ }
+ });
+
+ }
+
+ /**Ends the web service call to get all incidents and opens the grid view if
+ * the call was succesful */
+ public void endGetIncidentsServiceCall(boolean result){
+ progressDialog.dismiss();
+ if(!result){
+ if(loadingGridView)
+ Toast.makeText(this, getString(R.string.failure_load_images_msg), Toast.LENGTH_LONG).show();
+ }
+ else{
+ haveBaseIncidents = true;
+ if(loadingGridView){
+ loadingGridView = false;
+ loadGridView();
+ }
+ }
+
+ }
+ public void loadGridView(){
+ loadingGridView = false;
+ if(progressDialog!=null)
+ progressDialog.dismiss();
+ Intent i = new Intent(MainScreenActivity.this, GridIncidentGalleryActivity.class);
+ i.putExtra(Constants.GALLERY_IMAGES_ARRAY_KEY, imageUrls);
+ i.putExtra(Constants.GALLERY_THUMBNAIL_IMAGES_ARRAY_KEY, thumbUrls);
+ i.putExtra(Constants.JSON_INCIDENT_IMAGE_DESCRIPTION_KEY,descriptions);
+ startActivity(i);
}
@Override
protected void onStart() {
super.onStart();
- myApplication.requestStartEventHandling();
+ // myApplication.requestStartEventHandling();
Log.i(toString(), "MainScreen requestStartEventHandling");
}
-
+
@Override
protected void onDestroy() {
Log.i(toString(), "MainScreen stopTimerEventHandling");
- myApplication.stopTimerEventHandling();
+ // myApplication.stopTimerEventHandling();
super.onDestroy();
}
-
+
/** Starts a submission of a pollution event */
public class SubmitPollutionEventOnClickListener implements OnClickListener{
@Override
View
65 CowsEyeAndroidApplication/src/nz/co/android/cowseye/activity/PreviewActivity.java
@@ -3,9 +3,12 @@
import java.io.IOException;
import nz.co.android.cowseye.R;
+import nz.co.android.cowseye.RiverWatchApplication;
import nz.co.android.cowseye.event.Event;
+import nz.co.android.cowseye.event.GetIncidentsEvent;
import nz.co.android.cowseye.event.SubmissionEvent;
import nz.co.android.cowseye.event.SubmissionEventBuilderException;
+import nz.co.android.cowseye.service.GetIncidentsAsyncTask;
import nz.co.android.cowseye.utility.AlertBuilder;
import nz.co.android.cowseye.utility.JSONHelper;
import nz.co.android.cowseye.utility.Utils;
@@ -162,7 +165,7 @@ protected void submitPollutionEvent() throws SubmissionEventBuilderException{
new Thread(new Runnable() {
@Override
public void run() {
- final boolean success = processSubmissionEventResponse(currentEvent.processRaw());
+ final boolean success = RiverWatchApplication.processEventResponse(currentEvent.processRaw());
handler.post(new Runnable() {
@Override
@@ -172,6 +175,7 @@ public void run() {
if(success){
Toast.makeText(PreviewActivity.this, getString(R.string.success_submission_msg), Toast.LENGTH_LONG).show();
myApplication.deleteImage(currentEvent);
+ new GetIncidentsAsyncTask(new GetIncidentsEvent(myApplication, 0, 50),myApplication).execute();
// go back to starting activity
Intent intent = new Intent(PreviewActivity.this, MainScreenActivity.class);
//Finishes all previous activities on the activity stack
@@ -194,64 +198,5 @@ public void run() {
}
- /**
- * Deals with the response from a submission event return
- * @param response from a submission event
- * @return true if succesfull submission, otherwise false
- */
- public static boolean processSubmissionEventResponse(HttpResponse response){
- if(response==null)
- return false;
- StatusLine statusLine = response.getStatusLine();
- if(statusLine == null)
- return false;
- int statusCode = statusLine.getStatusCode();
- Log.i("app", "statusCode : "+statusCode);
- try{
- switch(statusCode){
- case Utils.HTTP_OK:
- Log.i("app", "Sucessful submission!");
- return true;
- case Utils.HTTP_LOGIC_ERROR:
- Log.i("app", "Logic error: Unsucessful submission!");
- return false;
- case Utils.HTTP_SERVER_ERROR:
- Log.i("app", "Server error: Unsucessful submission!");
- return false;
- default:
- Log.i("app", "Uncaught error: Unsucessful submission!");
- return false;
- }
- // JSONObject jsonObject = JSONHelper.parseHttpResponseAsJSON(response);
- // Log.d("app", "jsonObject : "+jsonObject);
- }
- catch(Exception f){
- Log.e("app", "Exception in JsonParsing : "+f);
- }
- return false;
-
- }
-
-
- public void submitEvent(Event e){
- HttpResponse response = e.processRaw();
- Log.d(toString(), "response : "+response);
- try{
- Log.d(toString(),"Status line : "+ response.getStatusLine());
- for(Header header : response.getAllHeaders()){
- Log.d(toString(),"header : "+ header.getName() + " - > "+header.getValue());
- }
-
-
- JSONObject jsonObject = JSONHelper.parseHttpResponseAsJSON(response);
- Log.d(toString(), "jsonObject : "+jsonObject);
-
- // if(jsonObject.has(Utils.RESPONSE_CODE))
- // return ResponseCodeState.stringToResponseCode((String)jsonObject.getString(Utils.RESPONSE_CODE))==ResponseCodeState.SUCCESS;
- }
- catch(Exception f){
- Log.e(toString(), "Exception in JsonParsing : "+f);
- }
- }
}
View
18 CowsEyeAndroidApplication/src/nz/co/android/cowseye/common/Constants.java
@@ -20,6 +20,9 @@
/* Keys for information passed between activities or within for activity destroy on rotation */
public static final String IMAGE_URI_KEY = "image_uri_key";
public static final String FROM_GALLERY_KEY = "from_gallery_key";
+ public static final String GALLERY_IMAGES_ARRAY_KEY = "gallery_images_key";
+ public static final String GALLERY_THUMBNAIL_IMAGES_ARRAY_KEY = "gallery_thumbnail_images_key";
+
public static final String DESCRIPTION_KEY = "description";
public static final String CONTACT_DETAILS_KEY = "contact";
@@ -52,6 +55,21 @@
public static final String SUBMISSION_JSON_GEO_LAT = "lat";
public static final String SUBMISSION_JSON_GEO_LON = "long";
public static final String SUBMISSION_JSON_ADDRESS = "physical_location";
+
+ /* JSON keys */
+ public static final String JSON_INCIDENTS_KEY = "incidents";
+
+ public static final String JSON_INCIDENT_ID_KEY = "id";
+ public static final String JSON_INCIDENT_THUMBNAIL_URL_KEY = "thumbnail_url";
+ public static final String JSON_INCIDENT_IMAGE_URL_KEY = "image_url";
+ public static final String JSON_INCIDENT_IMAGE_DESCRIPTION_KEY = "description";
+ public static final String JSON_INCIDENT_GEOLOCATION_KEY = "geolocation";
+ public static final String JSON_INCIDENT_LATITUDE_KEY = "lat";
+ public static final String JSON_INCIDENT_LONGITUDE_KEY = "long";
+ public static final String JSON_INCIDENT_PHYSICAL_LOCATION_KEY = "physical_location";
+
+
+
}
View
120 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/DatabaseAdapter.java
@@ -0,0 +1,120 @@
+package nz.co.android.cowseye.database;
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+
+/**
+ * This class lets the user query the local database
+ * @author Mitchell Lane
+ *
+ */
+public class DatabaseAdapter {
+ /* Table Names */
+ public static final String INCIDENT_TABLE_NAME = "Incident";
+
+ /* Database Attribute Names */
+ public static final String ATTRIBUTE_INCIDENT_ID = "id";
+ public static final String ATTRIBUTE_INCIDENT_THUMBNAIL_URL = "thumbnail_url";
+ public static final String ATTRIBUTE_INCIDENT_IMAGE_URL = "image_url";
+ public static final String ATTRIBUTE_INCIDENT_DESCRIPTION = "description";
+ public static final String ATTRIBUTE_INCIDENT_LATITUDE = "latitude";
+ public static final String ATTRIBUTE_INCIDENT_LONGITUDE = "longitude";
+ public static final String ATTRIBUTE_INCIDENT_PHYSICAL_LOCATION = "physical_location";
+ public static final String ATTRIBUTE_INCIDENT_LOCAL_THUMBNAIL_URL = "local_thumbnail_url";
+ public static final String ATTRIBUTE_INCIDENT_LOCAL_IMAGE_URL = "local_image_url";
+
+ public static final int COLUMN_INCIDENT_ID = 0;
+ public static final int COLUMN_INCIDENT_THUMBNAIL_URL = 1;
+ public static final int COLUMN_INCIDENT_IMAGE_URL = 2;
+ public static final int COLUMN_INCIDENT_DESCRIPTION = 3;
+ public static final int COLUMN_INCIDENT_LATITUDE = 4;
+ public static final int COLUMN_INCIDENT_LONGITUDE = 5;
+ public static final int COLUMN_INCIDENT_PHYSICAL_LOCATION = 6;
+ public static final int COLUMN_INCIDENT_LOCAL_THUMBNAIL_URL = 7;
+ public static final int COLUMN_INCIDENT_LOCAL_IMAGE_URL = 8;
+
+ private SQLiteDatabase database;
+
+ public DatabaseAdapter(DatabaseConstructor dbHelper){
+ database = dbHelper.getDatabase();
+ }
+
+ public boolean isDatabaseOpen() {
+ return database.isOpen();
+ }
+
+ public synchronized List<Incident> getAllIncidents() {
+ List<Incident> incidents = new ArrayList<Incident>();
+ Cursor c = database.query(INCIDENT_TABLE_NAME, null, null, null, null, null, ATTRIBUTE_INCIDENT_ID + " ASC");
+ if(c != null){
+ while(c.moveToNext()){
+ IncidentBuilder builder = new IncidentBuilder();
+ builder.setId(c.getInt(COLUMN_INCIDENT_ID))
+ .setThumbnailUrl(c.getString(COLUMN_INCIDENT_THUMBNAIL_URL))
+ .setImageUrl(c.getString(COLUMN_INCIDENT_IMAGE_URL))
+ .setDescription(c.getString(COLUMN_INCIDENT_DESCRIPTION))
+ .setLatitude(c.getFloat(COLUMN_INCIDENT_LATITUDE))
+ .setLongitude(c.getFloat(COLUMN_INCIDENT_LONGITUDE))
+ .setPhysicalLocation(c.getString(COLUMN_INCIDENT_PHYSICAL_LOCATION))
+ .setLocalThumbnailUrl(c.getString(COLUMN_INCIDENT_LOCAL_THUMBNAIL_URL))
+ .setLocalImageUrl(c.getString(COLUMN_INCIDENT_LOCAL_IMAGE_URL));
+ incidents.add(builder.build());
+ }
+ }
+ return incidents;
+ }
+
+ public synchronized Incident getIncident(String id) {
+ Incident incident = new Incident();
+ IncidentBuilder builder = new IncidentBuilder();
+ Cursor c = database.query(INCIDENT_TABLE_NAME, null, ATTRIBUTE_INCIDENT_ID+ " = ?", new String[]{id}, null, null, null);
+ if(c != null && c.moveToNext()){
+ builder.setId(c.getInt(COLUMN_INCIDENT_ID))
+ .setThumbnailUrl(c.getString(COLUMN_INCIDENT_THUMBNAIL_URL))
+ .setImageUrl(c.getString(COLUMN_INCIDENT_IMAGE_URL))
+ .setDescription(c.getString(COLUMN_INCIDENT_DESCRIPTION))
+ .setLatitude(c.getFloat(COLUMN_INCIDENT_LATITUDE))
+ .setLongitude(c.getFloat(COLUMN_INCIDENT_LONGITUDE))
+ .setPhysicalLocation(c.getString(COLUMN_INCIDENT_PHYSICAL_LOCATION))
+ .setLocalThumbnailUrl(c.getString(COLUMN_INCIDENT_LOCAL_THUMBNAIL_URL))
+ .setLocalImageUrl(c.getString(COLUMN_INCIDENT_LOCAL_IMAGE_URL));
+ incident = builder.build();
+ }
+
+ return incident;
+ }
+
+ /**
+ *
+ * Updates the incident with the given content values
+ * @param valuesToChange - values to be updated
+ * */
+ public synchronized void insertIncident(Incident incident) {
+ database.insert(INCIDENT_TABLE_NAME, null, incident.getContentValues());
+ }
+ /**
+ *
+ * Updates the incident with the given content values
+ * @param valuesToChange - values to be updated
+ * */
+ public synchronized void updateIncidentTable(String incidentId, ContentValues valuesToChange) {
+ database.update(INCIDENT_TABLE_NAME, valuesToChange, ATTRIBUTE_INCIDENT_ID+" = ?", new String[]{incidentId});
+ }
+
+ public ContentValues getLocalThumbPathNameContentValues(String newPathName){
+ ContentValues cv = new ContentValues();
+ cv.put(ATTRIBUTE_INCIDENT_LOCAL_THUMBNAIL_URL, newPathName);
+ return cv;
+ }
+
+ public ContentValues getLocalImagePathNameContentValues(String newPathName){
+ ContentValues cv = new ContentValues();
+ cv.put(ATTRIBUTE_INCIDENT_LOCAL_IMAGE_URL, newPathName);
+ return cv;
+ }
+
+}
View
132 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/DatabaseConstructor.java
@@ -0,0 +1,132 @@
+package nz.co.android.cowseye.database;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import android.content.Context;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * Class for construction and copying of the Protext Time & Attendance Database
+ * @author Mitchell Lane
+ *
+ */
+public class DatabaseConstructor extends SQLiteOpenHelper{
+
+ //The Android's default system path of your application database.
+ private static String DB_PATH = "/data/data/nz.co.android.cowseye/databases/";
+ private static String DB_NAME = "River_watch.sqlite";
+ private static String MY_PATH = DB_PATH + DB_NAME;
+
+ private SQLiteDatabase myDataBase;
+ private final Context myContext;
+
+ private static final int versionNumber = 1;
+
+
+ /**
+ * Constructor
+ * Takes and keeps a reference of the passed context in order to access the application assets and resources.
+ * @param context
+ */
+ public DatabaseConstructor(Context context) {
+ super(context, DB_NAME, null, versionNumber);
+ this.myContext = context;
+ }
+
+ /**
+ * Creates an empty database on the system and rewrites it with your own database.
+ * */
+ public void createDataBase() throws IOException{
+ boolean dbExist;
+ dbExist = checkDataBase();
+ if(dbExist){
+ //do nothing - database already exists
+ }else{
+ //By calling this method an empty database will be created into the default system path
+ //of your application so we are going to be able to overwrite that database with our database.
+ this.getReadableDatabase();
+ try {
+ copyDataBase();
+ } catch (IOException e) {
+ throw new Error("Error copying database");
+ }
+ }
+
+ }
+
+ /**
+ * Check if the database already exist to avoid re-copying the file each time you open the application.
+ * @return true if it exists, false if it doesn't
+ */
+ private boolean checkDataBase(){
+ SQLiteDatabase checkDB = null;
+ try{
+ String myPath = DB_PATH + DB_NAME;
+ checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
+ }catch(SQLiteException e){
+ //database doesn't exist yet
+ }
+ if(checkDB != null){
+ checkDB.close();
+ }
+ return checkDB != null ? true : false;
+ }
+
+ /**
+ * Copies your database from your local assets-folder to the just created empty database in the
+ * system folder, from where it can be accessed and handled.
+ * This is done by transferring bytestream.
+ * */
+ private void copyDataBase() throws IOException{
+ //Open your local database as the input stream
+ InputStream myInput = myContext.getAssets().open(DB_NAME);
+
+ // Path to the just created empty database
+ String outFileName = DB_PATH + DB_NAME;
+
+ //Open the empty database as the output stream
+ OutputStream myOutput = new FileOutputStream(outFileName);
+
+ //transfer bytes from the inputfile to the outputfile
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = myInput.read(buffer))>0){
+ myOutput.write(buffer, 0, length);
+ }
+
+ //Close the streams
+ myOutput.flush();
+ myOutput.close();
+ myInput.close();
+ }
+
+ /**
+ * Opens the local database
+ * @throws SQLException
+ */
+ public void openDataBase() throws SQLException{
+ //Open the database
+ myDataBase = SQLiteDatabase.openDatabase(MY_PATH, null,SQLiteDatabase.NO_LOCALIZED_COLLATORS);
+ }
+
+ public SQLiteDatabase getDatabase(){
+ return myDataBase;
+ }
+ public synchronized void close() {
+ if(myDataBase != null)
+ myDataBase.close();
+ super.close();
+ }
+
+ public void onCreate(SQLiteDatabase db) {
+ }
+
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ }
+}
View
94 CowsEyeAndroidApplication/src/nz/co/android/cowseye/database/Incident.java
@@ -0,0 +1,94 @@
+package nz.co.android.cowseye.database;
+
+import android.content.ContentValues;
+
+public class Incident {
+ private int id;
+ private String thumbnailUrl;
+ private String imageUrl;
+ private String description;
+ private float latitude;
+ private float longitude;
+ private String physicalLocation;
+ private String localThumbnailUrl;
+ private String localImageUrl;
+
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getThumbnailUrl() {
+ return thumbnailUrl;
+ }
+ public void setThumbnailUrl(String thumbnailUrl) {
+ this.thumbnailUrl = thumbnailUrl;
+ }
+ public String getImageUrl() {
+ return imageUrl;
+ }
+ public void setImageUrl(String imageUrl) {
+ this.imageUrl = imageUrl;
+ }
+ public String getDescription() {
+ return description;
+ }
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public float getLatitude() {
+ return latitude;
+ }
+ public void setLatitude(float latitude) {
+ this.latitude = latitude;
+ }
+ public float getLongitude() {
+ return longitude;
+ }
+ public void setLongitude(float longitude) {
+ this.longitude = longitude;
+ }
+ public String getPhysicalLocation() {
+ return physicalLocation;
+ }
+ public void setPhysicalLocation(String physicalLocation) {
+ this.physicalLocation = physicalLocation;
+ }