package org.average.whereami;
import org.average.whereami.APIBase;
+import org.average.whereami.Oracle;
+import org.average.whereami.Utterance;
import org.average.whereami.PersistentStore;
import org.average.whereami.SayWhen;
}
@Override
- public final String getResult() {
+ public final Utterance getResult() {
try {
Log.v(TAG, "entering getResult");
Latitude.CurrentLocation.Get request =
cloc.getLongitude().toString());
Long tsm = Long.parseLong(
cloc.getTimestampMs().toString());
- return locationMessage(lat, lon, tsm);
+ return new Utterance(true,
+ locationMessage(lat, lon, tsm));
} catch (GoogleJsonResponseException e) {
Log.e(TAG, "GoogleJsonResponseException: " + e);
if (e.getResponse().getStatusCode() == 401) {
- return base.authErrorMessage;
+ return new Utterance(false,
+ base.authErrorMessage + "\n" +
+ e.getMessage());
} else {
- return e.getMessage();
+ return new Utterance(false, e.getMessage());
}
} catch (HttpResponseException e) {
Log.e(TAG, "HttpResponseException: " + e);
- return e.getMessage();
+ return new Utterance(false, e.getMessage());
} catch (IOException e) {
- e.printStackTrace();
- return e.getMessage();
+ Log.e(TAG, "IOException: " + e);
+ return new Utterance(false, e.getMessage());
}
}
package org.average.whereami;
import org.average.whereami.APIBase;
+import org.average.whereami.Utterance;
abstract public class Oracle {
this.base = apibase;
}
- abstract public String getResult();
+ abstract public Utterance getResult();
}
package org.average.whereami;
import org.average.whereami.APIBase;
+import org.average.whereami.Oracle;
+import org.average.whereami.Utterance;
import org.average.whereami.PersistentStore;
import org.average.whereami.SayWhen;
}
@Override
- public final String getResult() {
+ public final Utterance getResult() {
try {
Log.v(TAG, "entering getResult");
if (calendar_id == null || calendar_id == "") {
calendar_id = scanCalendars(calendar_name);
}
if (calendar_id == null || calendar_id == "") {
- return nocalendar + " \"" +
- calendar_name + "\"";
+ return new Utterance(true,
+ nocalendar + " \"" +
+ calendar_name + "\"");
} else {
base.store.put("calendar_id", calendar_id);
- return scanEvents(calendar_id, peer_name);
+ return new Utterance(true,
+ scanEvents(calendar_id, peer_name));
}
} catch (GoogleJsonResponseException e) {
Log.e(TAG, "GoogleJsonResponseException: " + e);
if (e.getResponse().getStatusCode() == 401) {
- return base.authErrorMessage;
+ return new Utterance(false,
+ base.authErrorMessage + "\n" +
+ e.getMessage());
} else {
- return e.getMessage();
+ return new Utterance(false,
+ e.getMessage());
}
} catch (HttpResponseException e) {
Log.e(TAG, "HttpResponseException: " + e);
- return e.getMessage();
+ return new Utterance(false, e.getMessage());
} catch (IOException e) {
- e.printStackTrace();
- return e.getMessage();
+ Log.e(TAG, "IOException: " + e);
+ return new Utterance(false, e.getMessage());
}
}
--- /dev/null
+package org.average.whereami;
+
+public class Utterance {
+ public Boolean success;
+ public String message;
+ public Utterance(Boolean success, String message) {
+ this.success = success;
+ this.message = message;
+ }
+}
import org.average.whereami.PhoneLog;
import org.average.whereami.LastLocation;
+import java.util.Random;
+
import android.app.Activity;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.AsyncTask;
import android.os.Handler;
+import android.os.SystemClock;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.content.BroadcastReceiver;
private Integer runningtasks = 0;
private SharedPreferences prefs;
private PersistentStore store;
+ private Random random = new Random();
private class UpdateTarget {
private TextView tv;
@Override
protected String doInBackground(Void... params) {
Log.v(TAG, "BgUpdate " + updater + " starting");
- return updater.getResult();
+ Utterance result = updater.getResult();
+ if (!result.success) {
+ SystemClock.sleep(1000 + random.nextInt(1000));
+ result = updater.getResult();
+ }
+ if (!result.success) {
+ Log.e(TAG, "After second attempt still " +
+ result.message);
+ }
+ return result.message;
}
@Override