import org.average.whereami.CredentialStore;
-//import java.lang.Long;
+import java.lang.Math;
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.util.Log;
public final class LastLocation extends Oracle {
private Latitude latitude;
- public LastLocation(final CredentialStore store) {
+ private String[] loc_names;
+ private String[] loc_lats;
+ private String[] loc_lons;
+ private String[] loc_dists;
+
+ public LastLocation(final Resources res, final CredentialStore store) {
+ loc_names = res.getStringArray(R.array.loc_names);
+ loc_lats = res.getStringArray(R.array.loc_lats);
+ loc_lons = res.getStringArray(R.array.loc_lons);
+ loc_lons = res.getStringArray(R.array.loc_dists);
+
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = new JacksonFactory();
AccessTokenResponse token = store.read();
private String locationMessage(Double lat, Double lon, Long tsm) {
Log.v(TAG, "entering locationMessage(" + lat +
"," + lon + "," + tsm + ")");
- return "Location: " + lat + "N " + lon + "E at " + tsm/1000;
+ String locmsg = "<UNSET>";
+ for (int i = 0; i < loc_names.length; i++) {
+ Double dist = haversine(lat, lon,
+ Double.parseDouble(loc_lats[i]),
+ Double.parseDouble(loc_lons[i]));
+ Log.v(TAG, "Dist from " + loc_names[i] +
+ " is " + dist);
+ //if ((loc_dists[i] == "0") ||
+ // (dist < Double.parseDouble(loc_dists[i]))) {
+ // locmsg = loc_names[i];
+ // break;
+ //}
+ }
+ return locmsg;
+ }
+
+ private Double toRad(Double deg) {
+ return deg * 3.14159265 / 180;
+ }
+
+ private Double haversine(Double lat1, Double lon1,
+ Double lat2, Double lon2) {
+ Double dlat = toRad(lat2 - lat1);
+ Double dlon = toRad(lon2 - lon1);
+ Double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) +
+ Math.sin(dlon / 2) * Math.sin(dlon / 2) *
+ Math.cos(toRad(lat1)) * Math.cos(toRad(lat2));
+ Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+ return 6371 * c;
}
}
import com.google.common.collect.Lists;
import android.content.Context;
+import android.content.res.Resources;
import android.content.SharedPreferences;
import android.util.Log;
private Calendar calendar;
- public PhoneLog(final CredentialStore store) {
+ public PhoneLog(final Resources res, final CredentialStore store) {
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = new JacksonFactory();
AccessTokenResponse token = store.read();
tvs = (TextView)findViewById(R.id.timestamp);
ut = new UpdateTarget[] {
new UpdateTarget((TextView)findViewById(R.id.location),
- new PhoneLog(store)),
+ new PhoneLog(res, store)),
new UpdateTarget((TextView)findViewById(R.id.phonecall),
- new LastLocation(store))
+ new LastLocation(res, store))
};
Log.w(TAG, "created UI, about to start update task");
mHandler.post(updateClock);