~tetron/astrid/RTM-list-support

« back to all changes in this revision

Viewing changes to src/com/timsu/astrid/utilities/AstridUtilities.java

  • Committer: Tim Su
  • Date: 2009-06-13 21:25:34 UTC
  • mfrom: (215.1.16 2.8.5)
  • Revision ID: tim@todoroo.com-20090613212534-r01v4v7qu2w4og1c
Merged from 2.8.5 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import java.io.PrintWriter;
4
4
import java.io.StringWriter;
 
5
import java.lang.Thread.UncaughtExceptionHandler;
 
6
 
 
7
import android.database.sqlite.SQLiteException;
 
8
 
 
9
import com.flurry.android.FlurryAgent;
5
10
 
6
11
/**
7
12
 * General purpose utilities for the Astrid project. Grab-bag of stuff.
17
22
     * @param input
18
23
     * @return
19
24
     */
20
 
    public static String throwableToString(Throwable input) {
 
25
    public static void reportFlurryError(String name, Throwable error) {
 
26
        String message = error.toString();
 
27
 
21
28
        StringWriter writer = new StringWriter();
22
29
        PrintWriter writerPrinter = new PrintWriter(writer);
23
 
        input.printStackTrace(writerPrinter);
 
30
        error.printStackTrace(writerPrinter);
24
31
        writerPrinter.flush();
25
32
        writerPrinter.close();
26
33
 
27
 
        return writer.toString();
28
 
    }
29
 
 
 
34
        String trace = writer.toString();
 
35
 
 
36
        // shorten the string
 
37
        trace = trace.substring(message.length());
 
38
        trace.replaceAll("android", "A");
 
39
        trace.replaceAll("database", "db");
 
40
        trace.replaceAll(IllegalStateException.class.getName(), "IlStEx");
 
41
        trace.replaceAll(ClassCastException.class.getName(), "ClCaEx");
 
42
        trace.replaceAll(NullPointerException.class.getName(), "NPE");
 
43
        trace.replaceAll(SQLiteException.class.getName(), "SqLiEx");
 
44
        trace.replaceAll("com.timsu.", "");
 
45
 
 
46
        FlurryAgent.onError(name, message, trace);
 
47
    }
 
48
 
 
49
 
 
50
    /**
 
51
     * For reporting uncaught exceptions
 
52
     *
 
53
     * @author timsu
 
54
     *
 
55
     */
 
56
    public static class AstridUncaughtExceptionHandler implements UncaughtExceptionHandler {
 
57
        private UncaughtExceptionHandler defaultUEH;
 
58
 
 
59
        public AstridUncaughtExceptionHandler() {
 
60
            defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
 
61
        }
 
62
 
 
63
        @Override
 
64
        public void uncaughtException(Thread thread, Throwable ex) {
 
65
            AstridUtilities.reportFlurryError("uncaught", ex);
 
66
            defaultUEH.uncaughtException(thread, ex);
 
67
        }
 
68
    }
30
69
}
 
70