Commit ec2170fb authored by Dave Griffiths's avatar Dave Griffiths
Browse files

GPS and layout tweaks

parent c2098595
......@@ -37,6 +37,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION" />
<uses-sdk android:minSdkVersion="8" />
<supports-screens
......
......@@ -467,6 +467,7 @@
(define (make-directory name) (list "make-directory" 0 "make-directory" name))
;; treat this like a dialog so the callback fires
(define (list-files name path fn) (list "list-files" 0 "list-files" name fn path))
(define (gps-start name fn) (list "gps-start" 0 "gps-start" name fn))
(define (delayed name delay fn) (list "delayed" 0 "delayed" name fn delay))
(define (network-connect name ssid fn) (list "network-connect" 0 "network-connect" name fn ssid))
(define (http-request name url fn) (list "http-request" 0 "http-request" name fn url))
......
......@@ -647,7 +647,7 @@
(linear-layout
(make-id "") 'vertical fillwrap pf-col
(list
(build-grid-selector "pf-scan-nearest" "single" "Nearest Neighbour Scan: Closest Mongoose")
(build-grid-selector "pf-scan-nearest" "single" "<b>Nearest Neighbour Scan</b>: Closest Mongoose")
(build-grid-selector "pf-scan-close" "toggle" "Mongooses within 2m")
(mbutton "pf-scan-done" "Done"
(lambda ()
......@@ -689,11 +689,14 @@
(list
(mtitle "title" "Event: Pup is fed")
(build-grid-selector "pf-pupfeed-who" "single" "Who fed the pup?")
(mtext "text" "Food size")
(spacer 20)
(horiz
(mtext "text" "Food size")
(spinner (make-id "pf-pupfeed-size") (list "Small" "Medium" "Large") fillwrap
(lambda (v)
(entity-add-value! "size" "varchar" v) '()))
(entity-add-value! "size" "varchar" v) '())))
(spacer 20)
(horiz
(mbutton "pf-pupfeed-done" "Done"
(lambda ()
(entity-add-value! "parent" "varchar" (get-current 'pup-focal-id ""))
......@@ -726,9 +729,11 @@
(make-id "") 'vertical fillwrap pf-col
(list
(mtitle "title" "Event: Pup found food")
(horiz
(mtext "text" "Food size")
(spinner (make-id "pf-pupfind-size") (list "Small" "Medium" "Large") fillwrap
(lambda (v) (entity-add-value! "size" "varchar" v) '()))
(lambda (v) (entity-add-value! "size" "varchar" v) '())))
(spacer 20)
(horiz
(mbutton "pf-pupfind-done" "Done"
(lambda ()
......@@ -758,11 +763,14 @@
(list
(mtitle "title" "Event: Pup is cared for")
(build-grid-selector "pf-pupcare-who" "single" "Who cared for the pup?")
(mtext "text" "Type of care")
(spacer 20)
(horiz
(mtext "text" "Type of care")
(spinner (make-id "pf-pupcare-type") (list "Carry" "Lead" "Sniff" "Play" "Ano-genital sniff") fillwrap
(lambda (v)
(entity-add-value! "type" "varchar" v) '()))
(entity-add-value! "type" "varchar" v) '())))
(spacer 20)
(horiz
(mbutton "pf-pupcare-done" "Done"
(lambda ()
(entity-add-value! "parent" "varchar" (get-current 'pup-focal-id ""))
......@@ -816,6 +824,7 @@
(mtoggle-button "pf-pupaggr-win" "Win?"
(lambda (v)
(entity-add-value! "win" "varchar" (if v "yes" "no")) '()))))
(spacer 20)
(horiz
(mbutton "pf-pupaggr-done" "Done"
(lambda ()
......@@ -951,7 +960,7 @@
(linear-layout
(make-id "") 'vertical fillwrap gp-col
(list
(build-grid-selector "gp-mov-leader" "single" "Group movement: Leader")
(build-grid-selector "gp-mov-leader" "single" "<b>Group movement</b>: Leader")
(linear-layout
(make-id "") 'horizontal (layout 'fill-parent 90 '1 'left 0) trans-col
(list
......@@ -959,21 +968,22 @@
(lambda (v) (entity-add-value! "pack-width" "int" (string->number v)) '()))
(medit-text "gp-mov-l" "Pack depth" "numeric"
(lambda (v) (entity-add-value! "pack-depth" "int" (string->number v)) '()))
(medit-text "gp-mov-c" "How many mongooses?" "numeric"
(medit-text "gp-mov-c" "How many?" "numeric"
(lambda (v) (entity-add-value! "pack-count" "int" (string->number v)) '()))))
(linear-layout
(make-id "") 'horizontal (layout 'fill-parent 'wrap-content '1 'left 0) trans-col
(list
(vert
(mtext "" "Where to")
(spinner (make-id "gp-mov-to") (list "Latrine" "Water" "Food" "Nothing" "Den" "Unknown") fillwrap
(lambda (v) (entity-add-value! "destination" "varchar" v) '())))
(vert
(mtext "" "Direction")
(spinner (make-id "gp-mov-to") (list "To" "From") fillwrap
(lambda (v) (entity-add-value! "direction" "varchar" v) '())))
(vert
(mtext "" "Where to")
(spinner (make-id "gp-mov-to") (list "Latrine" "Water" "Food" "Nothing" "Den" "Unknown") fillwrap
(lambda (v) (entity-add-value! "destination" "varchar" v) '())))))
(spacer 20)
(horiz
(mbutton "pf-grpmov-done" "Done"
(lambda ()
......@@ -981,7 +991,7 @@
(list (replace-fragment (get-id "event-holder") "events"))))
(mbutton "pf-grpalarm-cancel" "Cancel"
(lambda ()
(list (replace-fragment (get-id "event-holder") "events")))))))))
(list (replace-fragment (get-id "event-holder") "events")))))))
(lambda (fragment arg)
(activity-layout fragment))
......@@ -1322,6 +1332,9 @@
(let ((user-id (ktv-get (get-entity db "local" 1) "user-id")))
(set-current! 'user-id user-id)
(list
(gps-start "gps" (lambda (loc)
(list (toast (number->string (car loc))
(number->string (cadr loc))))))
(update-widget 'edit-text (get-id "main-id-text") 'text user-id))))
(lambda (activity) '())
(lambda (activity) '())
......
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/standard_spinner_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
>
</TextView>
package foam.mongoose;
import java.util.Date;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
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 DorisLocationListener implements LocationListener {
protected static final int ONE_MINUTE = 60 * 1000;
protected static final int FIVE_MINUTES = 5 * ONE_MINUTE;
protected static final int ACCURACY_THRESHOLD = 30; // in meters
protected MapView mapView;
protected MapController mapController;
protected LocationManager locationManager;
protected Location currrentLocation;
String m_CallbackName;
StarwispActivity m_Context;
StarwispBuilder m_Builder;
public DorisLocationListener(LocationManager lm) {
locationManager = lm;
}
public void Start(StarwispActivity c, String name, StarwispBuilder b) {
m_CallbackName=name;
m_Context=c;
m_Builder=b;
setDeviceLocation();
}
protected void locationChanged(double latitude, double longitude) {
m_Builder.DialogCallback(m_Context,m_Context.m_Name,m_CallbackName,String.valueOf(latitude)+" "+String.valueOf(longitude));
}
protected void setDeviceLocation() {
Location lastNetLocation = null;
Location lastGpsLocation = null;
boolean netAvailable = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean gpsAvailable = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!netAvailable && !gpsAvailable) {
Log.i("DORIS","NO GPS or Net");
/* AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.location_disabled))
.setMessage(getString(R.string.location_reenable))
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
startActivity(new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton(android.R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).create().show();*/
}
if (netAvailable) {
lastNetLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if (gpsAvailable) {
lastGpsLocation = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
setBestLocation(lastNetLocation, lastGpsLocation);
// If chosen location is more than a minute old, start querying
// network/GPS
if (currrentLocation == null
|| (new Date()).getTime() - currrentLocation.getTime() > ONE_MINUTE) {
if (netAvailable) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
if (gpsAvailable) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
}
}
}
public void startLocating() {
setDeviceLocation();
}
public void stopLocating() {
if (locationManager != null) {
try {
locationManager.removeUpdates(this);
} catch (Exception ex) {
Log.e(getClass().getSimpleName(), "stopLocating", ex);
}
locationManager = null;
}
}
/**
* Convert latitude and longitude to a GeoPoint
*
* @param latitude
* Latitude
* @param longitude
* Lingitude
* @return GeoPoint
*/
protected GeoPoint getPoint(double latitude, double longitude) {
return (new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6)));
}
protected void setBestLocation(Location location1, Location location2) {
if (location1 != null && location2 != null) {
boolean location1Newer = location1.getTime() - location2.getTime() > FIVE_MINUTES;
boolean location2Newer = location2.getTime() - location1.getTime() > FIVE_MINUTES;
boolean location1MoreAccurate = location1.getAccuracy() < location2
.getAccuracy();
boolean location2MoreAccurate = location2.getAccuracy() < location1
.getAccuracy();
if (location1Newer || location1MoreAccurate) {
locationChanged(location1.getLatitude(),
location1.getLongitude());
} else if (location2Newer || location2MoreAccurate) {
locationChanged(location2.getLatitude(),
location2.getLongitude());
}
} else if (location1 != null) {
locationChanged(location1.getLatitude(), location1.getLongitude());
} else if (location2 != null) {
locationChanged(location2.getLatitude(), location2.getLongitude());
}
}
public void onLocationChanged(Location location) {
if (location != null) {
locationChanged(location.getLatitude(), location.getLongitude());
/* if (location.hasAccuracy()
&& location.getAccuracy() < ACCURACY_THRESHOLD) {
// accuracy is within ACCURACY_THRESHOLD, de-activate location
// detection
stopLocating();
}*/
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
......@@ -88,6 +88,8 @@ import android.content.DialogInterface;
import android.text.InputType;
import android.util.TypedValue;
import android.os.Handler;
import android.location.LocationListener;
import android.location.LocationManager;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog;
......@@ -105,6 +107,8 @@ public class StarwispBuilder
{
Scheme m_Scheme;
NetworkManager m_NetworkManager;
LocationManager m_LocationManager;
DorisLocationListener m_GPS;
Handler m_Handler;
public StarwispBuilder(Scheme scm) {
......@@ -803,6 +807,18 @@ public class StarwispBuilder
return;
}
if (token.equals("gps-start")) {
final String name = arr.getString(3);
if (m_LocationManager == null) {
m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
m_GPS = new DorisLocationListener(m_LocationManager);
}
m_GPS.Start((StarwispActivity)ctx,name,this);
return;
}
if (token.equals("delayed")) {
final String name = arr.getString(3);
final int d = arr.getInt(5);
......
INDIV SEX PACK BORN LITTER
DF130 F 11 11/10/2008 D0803
DF139 F 11 11/10/2008 D0803
DF169 F 11 12/05/2010 D1002
DF190 F 11 22/10/2011 D1107
DF200 F 11 16/05/2012 D1202
DF201 F 11 16/05/2012 D1202
DF208 F 11 16/05/2012 D1202
DF216 F 11 06/10/2012 D1204
DF222 F 11 26/06/2013 D1302
DF223 F 11 26/06/2013 D1302
DF225 F 11 26/06/2013 D1302
DF226 F 11 26/06/2013 D1302
DM126 M 11 08/05/2008 D0801
DM165 M 11 14/10/2009 D0904
DM168 M 11 28/12/2009 D0905
DM170 M 11 12/05/2010 D1002
DM171 M 11 12/05/2010 D1002
DM179 M 11 23/07/2010 D1003
DM180 M 11 23/07/2010 D1003
DM189 M 11 02/08/2011 D1106
DM192 M 11 22/10/2011 D1107
DM193 M 11 22/10/2011 D1107
DM194 M 11 22/10/2011 D1107
DM198 M 11 16/05/2012 D1202
DM202 M 11 16/05/2012 D1202
DM203 M 11 16/05/2012 D1202
DM204 M 11 16/05/2012 D1202
DM206 M 11 16/05/2012 D1202
DM209 M 11 16/05/2012 D1202
DM212 M 11 06/10/2012 D1204
DM213 M 11 06/10/2012 D1204
DM215 M 11 06/10/2012 D1204
DM220 M 11 16/04/2013 D1301
DM224 M 11 26/06/2013 D1302
VM107 M 14 28/07/2009 V0904
YF011 F 14 22/08/2013
YF097 F 14 16/11/2010 Y1004
YM096 M 14 16/11/2010 Y1004
UF019 F 15 01/08/2011 U1103
VF033 F 15 26/04/2006
VF137 F 15 15/10/2012 V1203
VF138 F 15 27/04/2013 V1301
VF139 F 15 19/08/2013
VF140 F 15 19/08/2013
VF141 F 15 19/08/2013
VF142 F 15 19/08/2013
VF143 F 15 19/08/2013
VM096 M 15 09/10/2008 V0803
VM123 M 15 01/11/2010 V1005
VM135 M 15 15/10/2012 V1203
VM136 M 15 15/10/2012 V1203
HM069 M 17 31/10/2003 H0304
HM092 M 17 19/04/2005 H0502
SF017 F 17 23/08/2010
SF024 F 17 13/07/2011
SF034 F 17 05/11/2012 S1205
SF038 F 17 05/11/2012 S1205
SF041 F 17 26/04/2013 S1301
SF045 F 17 26/04/2013 S1301
SM009 M 17 15/09/2008 S0804
SM013 M 17 15/09/2008 S0804
SM018 M 17 23/08/2010
SM021 M 17 11/05/2011 S1101
SM028 M 17 09/09/2011 S1102
SM037 M 17 05/11/2012 S1205
SM039 M 17 05/11/2012 S1205
UM020 M 18 01/08/2011 U1103
BF473 F 1B 22/01/2010 B1001
BF484 F 1B 07/05/2010 B1003
BF487 F 1B 07/05/2010 B1003
BF535 F 1B 02/07/2011 B1103
BF561 F 1B 20/04/2012 B1202
BF566 F 1B 20/04/2012 B1202
BF585 F 1B 27/06/2012 B1203
BF589 F 1B 27/06/2012 B1203
BF593 F 1B 17/09/2012 B1204
BF616 F 1B 03/07/2013 B1304
BF617 F 1B 03/07/2013 B1304
BF619 F 1B 03/07/2013 B1304
BF621 F 1B 03/07/2013 B1304
BF622 F 1B 03/07/2013 B1304
BF624 F 1B 03/07/2013 B1304
BF625 F 1B 03/07/2013 B1304
BF627 F 1B 03/07/2013 B1304
BM216 M 1B 27/03/2004 B0402
BM310 M 1B 20/07/2006 B0604
BM410 M 1B 15/09/2008 B0805
BM436 M 1B 25/03/2009 B0902A
BM438 M 1B 25/03/2009 B0902A
BM455 M 1B 20/06/2009 B0903
BM500 M 1B 09/12/2010 B1006
BM558 M 1B 20/04/2012 B1202
BM559 M 1B 20/04/2012 B1202
BM562 M 1B 20/04/2012 B1202
BM564 M 1B 20/04/2012 B1202
BM580 M 1B 27/06/2012 B1203
BM609 M 1B 29/04/2013 B1303
BM614 M 1B 03/07/2013 B1304
BM615 M 1B 03/07/2013 B1304
BM618 M 1B 03/07/2013 B1304
BM620 M 1B 03/07/2013 B1304
BM623 M 1B 03/07/2013 B1304
BM626 M 1B 03/07/2013 B1304
HF125 F 1H 30/11/2006 H0605
HF178 F 1H 14/10/2008 H0804
HF182 F 1H 12/03/2009 H0901
HF220 F 1H 10/11/2010 H1004
HF240 F 1H 23/04/2012 H1202
HF242 F 1H 23/04/2012 H1202
HF248 F 1H 27/06/2012 H1203
HF251 F 1H 27/06/2012 H1203
HF260 F 1H 06/06/2013 H1303
HF261 F 1H 06/06/2013 H1303
HM117 M 1H 17/05/2006 H0602
HM180 M 1H 14/10/2008 H0804
HM195 M 1H 18/12/2009 H0905
HM216 M 1H 10/11/2010 H1004
HM217 M 1H 10/11/2010 H1004
HM222 M 1H 10/11/2010 H1004
HM223 M 1H 10/11/2010 H1004
HM241 M 1H 23/04/2012 H1202
HM243 M 1H 23/04/2012 H1202
HM246 M 1H 23/04/2012 H1202
HM253 M 1H 27/06/2012 H1203
TF249 F 2 02/10/2008 T0804
TF284 F 2 24/06/2010 T1003
TF285 F 2 24/06/2010 T1003
TF297 F 2 21/04/2012 T1202
TF298 F 2 21/04/2012 T1202
TF299 F 2 21/04/2012 T1202
TF319 F 2 06/07/2012 T1203
TF321 F 2 06/07/2012 T1203
TF322 F 2 06/07/2012 T1203
TF332 F 2 26/01/2013 T1301
TF334 F 2 26/01/2013 T1301
TF336 F 2 26/01/2013 T1301
TM233 M 2 30/07/2008 T0803
TM236 M 2 02/10/2008 T0804
TM272 M 2 02/02/2010 T1001
TM279 M 2 15/04/2010 T1002
TM283 M 2 24/06/2010 T1003
TM286 M 2 24/06/2010 T1003
TM300 M 2 21/04/2012 T1202
TM304 M 2 21/04/2012 T1202
TM307 M 2 21/04/2012 T1202
TM309 M 2 21/04/2012 T1202
TM312 M 2 21/04/2012 T1202
TM317 M 2 06/07/2012 T1203
TM323 M 2 06/07/2012 T1203
TM335 M 2 26/01/2013 T1301
TM339 M 2 08/04/2013 T1302
TP355 P 2 28/09/2013 T1305
TP356 P 2 28/09/2013 T1305
TP357 P 2 28/09/2013 T1305
TP358 P 2 28/09/2013 T1305
TP359 P 2 28/09/2013 T1305
TP360 P 2 28/09/2013 T1305
TP361 P 2 28/09/2013 T1305
TP362 P 2 28/09/2013 T1305
TP363 P 2 28/09/2013 T1305
FF166 F 4B 10/01/2010 F1001
FF196 F 4B 28/10/2011 F1104
FM176 M 4B 06/12/2010
FM178 M 4B 06/12/2010
FM188 M 4B 07/04/2011
FM191 M 4B 07/04/2011
FM199 M 4B 18/02/2013 F1301
FF165 F 4E 10/01/2010 F1001
FF187 F 4E 07/04/2011
FF190 F 4E 07/04/2011
MM002 M 4E 27/03/2012
MM004 M 4E 22/08/2012
GF092 F 7A 06/04/2011 G1101
GF093 F 7A 06/04/2011 G1101
GF096 F 7A 12/07/2011 G1102
GF100 F 7A 22/10/2011 G1103
GF106 F 7A 16/06/2012 G1201
GF118 F 7A 22/04/2013 G1301
GM035 M 7A 12/05/2006 G0602
GM049 M 7A 22/10/2007
GM060 M 7A 05/05/2009 G0902
GM061 M 7A 05/05/2009 G0902
GM065 M 7A 23/07/2009 G0903
GM080 M 7A 26/04/2010 G1002
GM082 M 7A 26/04/2010 G1002
GM087 M 7A 28/11/2010 G1004
GM089 M 7A 28/11/2010 G1004
GM090 M 7A 06/04/2011 G1101
GM097 M 7A 12/07/2011 G1102
GM099 M 7A 22/10/2011 G1103
GM105 M 7A 16/06/2012 G1201
GM110 M 7A 01/12/2012 G1203
GM111 M 7A 01/12/2012 G1203
GM112 M 7A 01/12/2012 G1203
GM114 M 7A 01/12/2012 G1203
GM115 M 7A 01/12/2012 G1203
GM117 M 7A 22/04/2013 G1301
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment