Permalink
Browse files

sfalma updates

  • Loading branch information...
1 parent 052a7ca commit 849b0cc59de1386188598d17241e882953a47ab5 Jon Vlachoyiannis committed Mar 8, 2011
View
@@ -9,3 +9,6 @@ server/site.db
example/gen/*
BRANCH_TODO
build/*
+*~
+\#*
+.\#
View
@@ -27,12 +27,13 @@ Mads Kristiansen, mads.kristiansen@nullwire.com
Glen Humphrey
Evan Charlton
Peter Hewitt
+Jon Vlachoyiannis, jon@sfalma.com
-->
<project default="package">
<property file="local.properties" />
- <property name="version.num" value="0.3.0" />
+ <property name="version.num" value="0.6.0" />
<property name="build.dir" value="./build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
@@ -41,9 +42,9 @@ Peter Hewitt
</path>
<target name="stamp-version">
- <delete file="src/com/nullwire/trace/G.java" quiet="true" />
- <copy file="src/com/nullwire/trace/G.template"
- tofile="src/com/nullwire/trace/G.java">
+ <delete file="src/com/sfalma/trace/G.java" quiet="true" />
+ <copy file="src/com/sfalma/trace/G.template"
+ tofile="src/com/sfalma/trace/G.java">
<filterchain>
<replacetokens>
<token key="__TRACEVERSION__"
@@ -0,0 +1,107 @@
+package com.sfalma.trace;
+
+import android.os.AsyncTask;
+
+/**
+ * Copied from android-autostarts:
+ * http://github.com/miracle2k/android-autostarts
+ *
+ * Android's ASyncTask is very useful, but using a background thread
+ * can be though in the context of the Activity lifecycle, at least
+ * if you'd prefer your background task to not restart with an
+ * orientation change.
+ *
+ * This version of ASyncTask tries to alleviate those pains. The idea
+ * is that you "retain" an instance of this task on orientation change.
+ * The task can be "connected" to exactly one or zero objects at any
+ * time. On orientation change, the old instance disconnects itself,
+ * then the new one connects.
+ *
+ * The object you connect to typically is something that references
+ * back to your activity (might be the activity itself), and which your
+ * task needs to do it's job (for example, where it posts it's results
+ * to).
+ *
+ * This class ensures that whenever a new object connects while the task
+ * is still active, the preExecute() handler is run again, and if the
+ * task finished while no object was connected, the processPostExecute()
+ * handler is run the next time an activity connects.
+ *
+ * Note "processPostExecute()", which is a replacement for the
+ * "postExcute()" method of ASyncTask which you should use instead.
+ *
+ * TODO: there is a small chance at race conditions here when checking
+ * for mWrapped and setting mPostProcessingDone. We should fix those
+ * by using a lock.
+ */
+public abstract class ActivityAsyncTask<Connect, Params, Progress, Result>
+ extends AsyncTask<Params, Progress, Result> {
+
+ protected volatile Connect mWrapped;
+ private volatile boolean mPostProcessingDone;
+ private Result mResult;
+
+ public ActivityAsyncTask(Connect initialConnect) {
+ super();
+ mPostProcessingDone = false;
+ connectTo(initialConnect);
+ }
+
+ /**
+ * Connect to the given object, or "null" to disconnect.
+ *
+ * Raises an exception if we are already connected.
+ */
+ public void connectTo(Connect wrappedObject) {
+ if (mWrapped != null && wrappedObject != null)
+ throw new IllegalStateException();
+
+ mWrapped = wrappedObject;
+
+ if (mWrapped != null) {
+ // Set the task up with the new activity.
+ if (getStatus() == Status.RUNNING)
+ onPreExecute();
+
+ // If we were unable to do the full post processing because of
+ // no object being available, do so now.
+ else if (getStatus() == Status.FINISHED && !mPostProcessingDone) {
+ mPostProcessingDone = true;
+ processPostExecute(mResult);
+ mResult = null; // Be sure to free reference now.
+ }
+ }
+ }
+
+ /**
+ * Return whether post processing has been completed.
+ */
+ public boolean postProcessingDone() {
+ return mPostProcessingDone;
+ }
+
+ @Override
+ protected void onPostExecute(Result result) {
+ super.onPostExecute(result);
+
+ // We need to make sure we only go on if an activity is
+ // attached. Since it's possible that, say, an orientation
+ // change happens while we are running, it can happen that
+ // there isn't one. If so, processPostExecute() will be
+ // run the next time one is attached.
+ if (mWrapped != null) {
+ mPostProcessingDone = true;
+ processPostExecute(result);
+ }
+ else
+ // Remember result for the next connect.
+ mResult = result;
+ }
+
+ /**
+ * You should override this rather than onPostExecute()
+ * to ensure your handler will be called even if at the
+ * time of a finish the task is not connected.
+ */
+ protected abstract void processPostExecute(Result result);
+}
@@ -0,0 +1,84 @@
+/*
+Copyright (c) 2009 nullwire aps
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Contributors:
+Mads Kristiansen, mads.kristiansen@nullwire.com
+Glen Humphrey
+Evan Charlton
+Peter Hewitt
+Jon Vlachoyiannis, jon@sfalma.com
+ */
+
+package com.sfalma.trace;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.util.Random;
+
+import android.util.Log;
+
+public class DefaultExceptionHandler implements UncaughtExceptionHandler {
+
+ private UncaughtExceptionHandler defaultExceptionHandler;
+
+ // constructor
+ public DefaultExceptionHandler(UncaughtExceptionHandler pDefaultExceptionHandler)
+ {
+ defaultExceptionHandler = pDefaultExceptionHandler;
+ }
+
+ // Default exception handler
+ public void uncaughtException(Thread t, Throwable e) {
+ // Here you should have a more robust, permanent record of problems
+ final Writer result = new StringWriter();
+ final PrintWriter printWriter = new PrintWriter(result);
+ e.printStackTrace(printWriter);
+ try {
+ // Random number to avoid duplicate files
+ Random generator = new Random();
+ int random = generator.nextInt(99999);
+ // Embed version in stacktrace filename
+ String filename = G.APP_VERSION+"-"+Integer.toString(random);
+ Log.d(G.TAG, "Writing unhandled exception to: " + G.FILES_PATH+"/"+filename+".stacktrace");
+ // Write the stacktrace to disk
+ BufferedWriter bos = new BufferedWriter(new FileWriter(G.FILES_PATH+"/"+filename+".stacktrace"));
+ bos.write(G.ANDROID_VERSION + "\n");
+ bos.write(G.PHONE_MODEL + "\n");
+ bos.write(result.toString());
+ bos.flush();
+ // Close up everything
+ bos.close();
+ } catch (Exception ebos) {
+ // Nothing much we can do about this - the game is over
+ Log.e(G.TAG, "Error saving exception stacktrace", e);
+ }
+ Log.d(G.TAG, result.toString());
+ //call original handler
+ defaultExceptionHandler.uncaughtException(t, e);
+ }
+}
@@ -0,0 +1,47 @@
+/*
+Copyright (c) 2009 nullwire aps
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Contributors:
+Mads Kristiansen, mads.kristiansen@nullwire.com
+Glen Humphrey
+Evan Charlton
+Peter Hewitt
+*/
+
+package com.sfalma.trace;
+
+public class G {
+ // Since the exception handler doesn't have access to the context,
+ // or anything really, the library prepares these values for when
+ // the handler needs them.
+ public static String FILES_PATH = null;
+ public static String APP_VERSION = "unknown";
+ public static String APP_PACKAGE = "unknown";
+ public static String URL = "http://10.39.255.101:8080/api/send";
+ public static String TAG = "SfalmaHandler";
+ public static String ANDROID_VERSION = null;
+ public static String PHONE_MODEL = null;
+
+ public static String TraceVersion = "0.6.0";
+}
@@ -43,5 +43,5 @@ public class G {
public static String ANDROID_VERSION = null;
public static String PHONE_MODEL = null;
- public static String TraceVersion = "@__TRACEVERSION__@";
+ public static String TraceVersion = "0.3.0";
}
@@ -0,0 +1,47 @@
+/*
+Copyright (c) 2009 nullwire aps
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Contributors:
+Mads Kristiansen, mads.kristiansen@nullwire.com
+Glen Humphrey
+Evan Charlton
+Peter Hewitt
+*/
+
+package com.sfalma.trace;
+
+public class G {
+ // Since the exception handler doesn't have access to the context,
+ // or anything really, the library prepares these values for when
+ // the handler needs them.
+ public static String FILES_PATH = null;
+ public static String APP_VERSION = "unknown";
+ public static String APP_PACKAGE = "unknown";
+ public static String URL = "http://10.39.255.101:8080/api/send";
+ public static String TAG = "SfalmaHandler";
+ public static String ANDROID_VERSION = null;
+ public static String PHONE_MODEL = null;
+
+ public static String TraceVersion = "@__TRACEVERSION__@";
+}
@@ -0,0 +1,47 @@
+/*
+Copyright (c) 2009 nullwire aps
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Contributors:
+Mads Kristiansen, mads.kristiansen@nullwire.com
+Glen Humphrey
+Evan Charlton
+Peter Hewitt
+*/
+
+package com.nullwire.trace;
+
+public class G {
+ // Since the exception handler doesn't have access to the context,
+ // or anything really, the library prepares these values for when
+ // the handler needs them.
+ public static String FILES_PATH = null;
+ public static String APP_VERSION = "unknown";
+ public static String APP_PACKAGE = "unknown";
+ public static String URL = "http://10.39.255.101:8080/api/send";
+ public static String TAG = "SfalmaHandler";
+ public static String ANDROID_VERSION = null;
+ public static String PHONE_MODEL = null;
+
+ public static String TraceVersion = "@__TRACEVERSION__@";
+}
@@ -26,7 +26,7 @@
Jon Vlachoyiannis
*/
-package com.nullwire.trace;
+package com.sfalma.trace;
import java.io.IOException;
Oops, something went wrong.

0 comments on commit 849b0cc

Please sign in to comment.