Cleaned up code

This commit is contained in:
2012-07-22 09:36:07 -04:00
parent 5e6e6c4dd9
commit 4de767f753
8 changed files with 172 additions and 132 deletions

View File

@@ -6,7 +6,7 @@
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="8"
android:targetSdkVersion="15" /> android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />

View File

@@ -30,15 +30,17 @@ import android.util.Log;
import anroid.v4.compat.NotificationCompat; import anroid.v4.compat.NotificationCompat;
/** /**
* This is Twenty Codes, LLC Exception Handler of Awesomeness! * This is Twenty Codes, LLC Exception Handler of Awesomeness! This class will
* This class will be used to generate reports that will be emailed to us via the users email client after the users approval * be used to generate reports that will be emailed to us via the users email
* client after the users approval
*
* @author ricky barrette * @author ricky barrette
*/ */
public class ExceptionHandler implements UncaughtExceptionHandler, Runnable { public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
private static final String MSG_SUBJECT_TAG = "Exception Report"; private static final String MSG_SUBJECT_TAG = "Exception Report";
private static final String MSG_BODY = "Just click send to help make this application better. "+ private static final String MSG_BODY = "Just click send to help make this application better. "
"No personal information is being sent (you can check by reading the rest of the email)."; + "No personal information is being sent (you can check by reading the rest of the email).";
protected static final int SIMPLE_NOTFICATION_ID = 45684645; protected static final int SIMPLE_NOTFICATION_ID = 45684645;
private final Thread.UncaughtExceptionHandler mDefaultUEH; private final Thread.UncaughtExceptionHandler mDefaultUEH;
private Activity mApp = null; private Activity mApp = null;
@@ -54,6 +56,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/** /**
* Creates a new ExceptionHandler * Creates a new ExceptionHandler
*
* @param app * @param app
* @author ricky barrette * @author ricky barrette
*/ */
@@ -66,6 +69,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/** /**
* Creates a new ExceptionHandler * Creates a new ExceptionHandler
*
* @param broadcastReceiver * @param broadcastReceiver
* @author ricky barrette * @author ricky barrette
*/ */
@@ -78,6 +82,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/** /**
* Creates a new ExceptionHandler * Creates a new ExceptionHandler
*
* @param service * @param service
* @author ricky barrette * @author ricky barrette
*/ */
@@ -90,6 +95,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/** /**
* Generates an email from the report * Generates an email from the report
*
* @author ricky barrette * @author ricky barrette
*/ */
private void displayEmailNotification() { private void displayEmailNotification() {
@@ -117,7 +123,9 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
} }
/** /**
* displays an notification in the status bar, letting the user know that there was an issue * displays an notification in the status bar, letting the user know that
* there was an issue
*
* @param generatedReportIntent * @param generatedReportIntent
*/ */
private void displayNotification(final Intent generatedReportIntent) { private void displayNotification(final Intent generatedReportIntent) {
@@ -125,19 +133,16 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
final Context context = mContext.getApplicationContext(); final Context context = mContext.getApplicationContext();
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final PendingIntent intent = PendingIntent.getActivity(context, 0, generatedReportIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent intent = PendingIntent.getActivity(context, 0, generatedReportIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(context.getString(R.string.crash))
.setContentTitle(context.getString(R.string.crash)) .setContentText(context.getString(R.string.sorry)).setTicker(context.getString(R.string.crash)).setSmallIcon(android.R.drawable.stat_notify_error)
.setContentText(context.getString(R.string.sorry)) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentIntent(intent);
.setTicker(context.getString(R.string.crash))
.setSmallIcon(android.R.drawable.stat_notify_error)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentIntent(intent);
notificationManager.notify(SIMPLE_NOTFICATION_ID, builder.getNotification()); notificationManager.notify(SIMPLE_NOTFICATION_ID, builder.getNotification());
} }
/** /**
* parses in the exception handler options from the client application's assets folder. /assets/exceptionhandler.properties * parses in the exception handler options from the client application's
* assets folder. /assets/exceptionhandler.properties
*
* @author ricky barrette * @author ricky barrette
*/ */
private void parseProperties() { private void parseProperties() {
@@ -167,9 +172,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
} }
/** /**
* Called when there is an uncaught exception. * Called when there is an uncaught exception. (non-Javadoc)
* (non-Javadoc) *
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable) * @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread,
* java.lang.Throwable)
* @author ricky barrette * @author ricky barrette
*/ */
@Override @Override
@@ -207,13 +213,13 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
} }
// generate the report // generate the report
mReport = new Report(mURL).generateReport(e.toString(), report.toString(), causereport.toString(), sdf.format(theDate), Build.FINGERPRINT, pi.versionName+"b"+pi.versionCode, mAppName != null ? mAppName : mContext.getPackageName(), mTracker, mContext.getPackageName()); mReport = new Report(mURL).generateReport(e.toString(), report.toString(), causereport.toString(), sdf.format(theDate), Build.FINGERPRINT, pi.versionName + "b"
+ pi.versionCode, mAppName != null ? mAppName : mContext.getPackageName(), mTracker, mContext.getPackageName());
// try to send file contents via email (need to do so via the UI thread) // try to send file contents via email (need to do so via the UI thread)
if (mApp != null) if (mApp != null)
mApp.runOnUiThread(this); mApp.runOnUiThread(this);
if (mService != null) if (mService != null)
if (mEmail == null) if (mEmail == null)
displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport)); displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport));

View File

@@ -16,7 +16,9 @@ import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
/** /**
* This activity will be used to present the user with the exception report, and allows them to send it, or not * This activity will be used to present the user with the exception report, and
* allows them to send it, or not
*
* @author ricky barrette * @author ricky barrette
*/ */
public class ExceptionReportActivity extends Activity implements OnClickListener { public class ExceptionReportActivity extends Activity implements OnClickListener {
@@ -26,6 +28,7 @@ public class ExceptionReportActivity extends Activity implements OnClickListener
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.view.View.OnClickListener#onClick(android.view.View) * @see android.view.View.OnClickListener#onClick(android.view.View)
* @author ricky barrette * @author ricky barrette
*/ */
@@ -40,6 +43,7 @@ public class ExceptionReportActivity extends Activity implements OnClickListener
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle) * @see android.app.Activity#onCreate(android.os.Bundle)
* @author ricky barrette * @author ricky barrette
*/ */

View File

@@ -29,7 +29,9 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
/** /**
* This class will be used to generate a report, and insert it into our exception report database * This class will be used to generate a report, and insert it into our
* exception report database
*
* @author ricky barrette * @author ricky barrette
*/ */
public class Report implements Parcelable { public class Report implements Parcelable {
@@ -51,6 +53,7 @@ public class Report implements Parcelable{
/** /**
* Creates a new Report * Creates a new Report
*
* @param in * @param in
* @author ricky barrette * @author ricky barrette
*/ */
@@ -62,6 +65,7 @@ public class Report implements Parcelable{
/** /**
* Creates a new Report * Creates a new Report
*
* @author ricky barrette * @author ricky barrette
*/ */
public Report(final String url) { public Report(final String url) {
@@ -76,6 +80,7 @@ public class Report implements Parcelable{
/** /**
* Files the report with the remote database * Files the report with the remote database
*
* @author ricky barrette * @author ricky barrette
* @throws IOException * @throws IOException
* @throws ClientProtocolException * @throws ClientProtocolException
@@ -103,6 +108,7 @@ public class Report implements Parcelable{
/** /**
* Generates a report to be displayed form a downloaded JSON object * Generates a report to be displayed form a downloaded JSON object
*
* @param report * @param report
* @return * @return
* @author ricky barrette * @author ricky barrette
@@ -121,6 +127,7 @@ public class Report implements Parcelable{
/** /**
* Generates a report to be sent. * Generates a report to be sent.
*
* @param msg * @param msg
* @param stackTrace * @param stackTrace
* @param cause * @param cause
@@ -130,7 +137,8 @@ public class Report implements Parcelable{
* @return this * @return this
* @author ricky barrette * @author ricky barrette
*/ */
public Report generateReport(final String msg, final String stackTrace, final String cause, final String date, final String device, final String appVersion, final String app, final String tracker, final String packageName){ public Report generateReport(final String msg, final String stackTrace, final String cause, final String date, final String device, final String appVersion,
final String app, final String tracker, final String packageName) {
mReport = new ArrayList<ReportItem>(); mReport = new ArrayList<ReportItem>();
mReport.add(new ReportItem("app", app)); mReport.add(new ReportItem("app", app));
mReport.add(new ReportItem("version", appVersion)); mReport.add(new ReportItem("version", appVersion));
@@ -146,6 +154,7 @@ public class Report implements Parcelable{
/** /**
* Extracts the name value pairs from the report bundle * Extracts the name value pairs from the report bundle
*
* @return * @return
* @author ricky barrette * @author ricky barrette
*/ */
@@ -166,6 +175,7 @@ public class Report implements Parcelable{
/** /**
* Sets the optional users description of what happened * Sets the optional users description of what happened
*
* @param string * @param string
* @author ricky barrette * @author ricky barrette
*/ */

View File

@@ -18,7 +18,9 @@ import android.widget.BaseAdapter;
import android.widget.TextView; import android.widget.TextView;
/** /**
* This class will be used to populate a custom Listview used to display the Generated exception report * This class will be used to populate a custom Listview used to display the
* Generated exception report
*
* @author ricky barrette * @author ricky barrette
*/ */
public class ReportAdapter extends BaseAdapter { public class ReportAdapter extends BaseAdapter {
@@ -27,12 +29,14 @@ public class ReportAdapter extends BaseAdapter {
TextView title; TextView title;
TextView body; TextView body;
} }
private final ArrayList<NameValuePair> mReport; private final ArrayList<NameValuePair> mReport;
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
/** /**
* Creates a new ReportAdapter * Creates a new ReportAdapter
*
* @author ricky barrette * @author ricky barrette
*/ */
public ReportAdapter(final Context context, final ArrayList<NameValuePair> report) { public ReportAdapter(final Context context, final ArrayList<NameValuePair> report) {
@@ -44,6 +48,7 @@ public class ReportAdapter extends BaseAdapter {
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.widget.Adapter#getCount() * @see android.widget.Adapter#getCount()
* @author ricky barrette * @author ricky barrette
*/ */
@@ -54,6 +59,7 @@ public class ReportAdapter extends BaseAdapter {
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.widget.Adapter#getItem(int) * @see android.widget.Adapter#getItem(int)
* @author ricky barrette * @author ricky barrette
*/ */
@@ -64,6 +70,7 @@ public class ReportAdapter extends BaseAdapter {
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.widget.Adapter#getItemId(int) * @see android.widget.Adapter#getItemId(int)
* @author ricky barrette * @author ricky barrette
*/ */
@@ -78,16 +85,20 @@ public class ReportAdapter extends BaseAdapter {
@Override @Override
public View getView(final int position, View convertView, final ViewGroup parent) { public View getView(final int position, View convertView, final ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unnecessary calls to findViewById() on each row. // A ViewHolder keeps references to children views to avoid unnecessary
// calls to findViewById() on each row.
ViewHolder holder; ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need // When convertView is not null, we can reuse it directly, there is no
// to reinflate it. We only inflate a new View when the convertView supplied // need
// to reinflate it. We only inflate a new View when the convertView
// supplied
// by ListView is null. // by ListView is null.
if (convertView == null) { if (convertView == null) {
convertView = mInflater.inflate(R.layout.exception_list_item, null); convertView = mInflater.inflate(R.layout.exception_list_item, null);
// Creates a ViewHolder and store references to the two children views // Creates a ViewHolder and store references to the two children
// views
// we want to bind data to. // we want to bind data to.
holder = new ViewHolder(); holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.exception_title); holder.title = (TextView) convertView.findViewById(R.id.exception_title);

View File

@@ -10,8 +10,10 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
/** /**
* This class will represent an individual report item. The ReportItems will be used in an array list that will be passed via intent. * This class will represent an individual report item. The ReportItems will be
* This will allow for our report items to stay in the proper order. * used in an array list that will be passed via intent. This will allow for our
* report items to stay in the proper order.
*
* @author ricky * @author ricky
*/ */
public final class ReportItem implements Parcelable { public final class ReportItem implements Parcelable {
@@ -33,6 +35,7 @@ public final class ReportItem implements Parcelable {
/** /**
* Creates a new ReportItem from a parcel * Creates a new ReportItem from a parcel
*
* @param in * @param in
*/ */
public ReportItem(final Parcel in) { public ReportItem(final Parcel in) {
@@ -42,6 +45,7 @@ public final class ReportItem implements Parcelable {
/** /**
* Creates a new ReportItem * Creates a new ReportItem
*
* @author ricky barrette * @author ricky barrette
*/ */
public ReportItem(final String key, final String value) { public ReportItem(final String key, final String value) {
@@ -49,7 +53,9 @@ public final class ReportItem implements Parcelable {
mValue = value; mValue = value;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see android.os.Parcelable#describeContents() * @see android.os.Parcelable#describeContents()
*/ */
@Override @Override
@@ -72,7 +78,9 @@ public final class ReportItem implements Parcelable {
return mValue; return mValue;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int) * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/ */
@Override @Override

View File

@@ -21,8 +21,9 @@ import android.util.Log;
import anroid.v4.compat.NotificationCompat; import anroid.v4.compat.NotificationCompat;
/** /**
* This service will allow the exception handler to post reports in the backgound, * This service will allow the exception handler to post reports in the
* allowing the user to do what ever they want * backgound, allowing the user to do what ever they want
*
* @author ricky barrette * @author ricky barrette
*/ */
public class ReportPostingService extends Service { public class ReportPostingService extends Service {
@@ -38,6 +39,7 @@ public class ReportPostingService extends Service {
/** /**
* Fires of a notification based upon api level * Fires of a notification based upon api level
*
* @param title * @param title
* @param contentText * @param contentText
* @param ticker * @param ticker
@@ -51,12 +53,8 @@ public class ReportPostingService extends Service {
if (intent != null) if (intent != null)
pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()).setContentTitle(title).setContentText(contentText)
.setContentTitle(title) .setTicker(ticker).setSmallIcon(icon).setWhen(System.currentTimeMillis());
.setContentText(contentText)
.setTicker(ticker)
.setSmallIcon(icon)
.setWhen(System.currentTimeMillis());
if (isOngoing) if (isOngoing)
builder.setOngoing(true); builder.setOngoing(true);
@@ -70,6 +68,7 @@ public class ReportPostingService extends Service {
/** /**
* Extracts the report object from the intent * Extracts the report object from the intent
*
* @param intent * @param intent
* @author ricky barrette * @author ricky barrette
*/ */
@@ -79,32 +78,26 @@ public class ReportPostingService extends Service {
/** /**
* notifiys the user that we are sending a report * notifiys the user that we are sending a report
*
* @author ricky barrette * @author ricky barrette
*/ */
private void notifyError() { private void notifyError() {
fireNotification(getString(R.string.reporting_error), fireNotification(getString(R.string.reporting_error), getString(R.string.reporting_error_msg), getString(R.string.reporting_error_msg),
getString(R.string.reporting_error_msg), android.R.drawable.stat_notify_error, new Intent(getApplicationContext(), ReportPostingService.class).putExtras(mIntent), false);
getString(R.string.reporting_error_msg),
android.R.drawable.stat_notify_error,
new Intent(getApplicationContext(), ReportPostingService.class).putExtras(mIntent),
false);
} }
/** /**
* notifiys the user that we are sending a report * notifiys the user that we are sending a report
*
* @author ricky barrette * @author ricky barrette
*/ */
private void notifySending() { private void notifySending() {
fireNotification(getString(R.string.sending), fireNotification(getString(R.string.sending), getString(R.string.sending_report), getString(R.string.sending), android.R.drawable.stat_sys_upload, null, true);
getString(R.string.sending_report),
getString(R.string.sending),
android.R.drawable.stat_sys_upload,
null,
true);
} }
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.app.Service#onBind(android.content.Intent) * @see android.app.Service#onBind(android.content.Intent)
*/ */
@Override @Override
@@ -114,10 +107,9 @@ public class ReportPostingService extends Service {
} }
/** /**
* Called when the service is being created * Called when the service is being created Here we want to display a
* Here we want to display a notifcation, * notifcation, to inform the user what we are doing. (non-Javadoc)
* to inform the user what we are doing. *
* (non-Javadoc)
* @see android.app.Service#onCreate() * @see android.app.Service#onCreate()
*/ */
@Override @Override
@@ -128,10 +120,11 @@ public class ReportPostingService extends Service {
notifySending(); notifySending();
super.onCreate(); super.onCreate();
} }
/** /**
* Called when the service is being destroyed * Called when the service is being destroyed Here we want to dismiss the
* Here we want to dismiss the notifications * notifications (non-Javadoc)
* (non-Javadoc) *
* @see android.app.Service#onDestroy() * @see android.app.Service#onDestroy()
*/ */
@Override @Override
@@ -144,6 +137,7 @@ public class ReportPostingService extends Service {
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.app.Service#onStart(android.content.Intent, int) * @see android.app.Service#onStart(android.content.Intent, int)
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -158,6 +152,7 @@ public class ReportPostingService extends Service {
/** /**
* (non-Javadoc) * (non-Javadoc)
*
* @see android.app.Service#onStartCommand(android.content.Intent, int, int) * @see android.app.Service#onStartCommand(android.content.Intent, int, int)
*/ */
@TargetApi(5) @TargetApi(5)
@@ -172,6 +167,7 @@ public class ReportPostingService extends Service {
/** /**
* Posts a copy of the report to the report handing server * Posts a copy of the report to the report handing server
*
* @author ricky barrette * @author ricky barrette
*/ */
private void postReport() { private void postReport() {

View File

@@ -20,7 +20,9 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
* this class will be a simple preference that contains only a text view that will display the application build information * this class will be a simple preference that contains only a text view that
* will display the application build information
*
* @author ricky barrette * @author ricky barrette
*/ */
public class VersionInformationPreference extends Preference { public class VersionInformationPreference extends Preference {
@@ -29,6 +31,7 @@ public class VersionInformationPreference extends Preference {
/** /**
* creates a preference that is nothing but a text view * creates a preference that is nothing but a text view
*
* @param context * @param context
*/ */
public VersionInformationPreference(final Context context) { public VersionInformationPreference(final Context context) {
@@ -38,6 +41,7 @@ public class VersionInformationPreference extends Preference {
/** /**
* creates a preference that is nothing but a text view * creates a preference that is nothing but a text view
*
* @param context * @param context
* @param attrs * @param attrs
*/ */
@@ -48,6 +52,7 @@ public class VersionInformationPreference extends Preference {
/** /**
* creates a preference that is nothing but a text view * creates a preference that is nothing but a text view
*
* @param context * @param context
* @param attrs * @param attrs
* @param defStyle * @param defStyle
@@ -57,10 +62,9 @@ public class VersionInformationPreference extends Preference {
mContext = context; mContext = context;
} }
/** /**
* creates a linear layout the contains only a textview. * creates a linear layout the contains only a textview. (non-Javadoc)
* (non-Javadoc) *
* @see android.preference.Preference#onCreateView(android.view.ViewGroup) * @see android.preference.Preference#onCreateView(android.view.ViewGroup)
* @param parent * @param parent
* @return * @return
@@ -84,7 +88,8 @@ public class VersionInformationPreference extends Preference {
} }
/* /*
* create a vertical linear layout that width and height that wraps content * create a vertical linear layout that width and height that wraps
* content
*/ */
final LinearLayout layout = new LinearLayout(getContext()); final LinearLayout layout = new LinearLayout(getContext());
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
@@ -95,8 +100,8 @@ public class VersionInformationPreference extends Preference {
layout.removeAllViews(); layout.removeAllViews();
/* /*
* create a textview that will be used to display the application's name and build information * create a textview that will be used to display the application's name
* and add it to the layout * and build information and add it to the layout
*/ */
final TextView title = new TextView(getContext()); final TextView title = new TextView(getContext());
title.setText(mContext.getString(R.string.version) + " " + pi.versionName + " bulid " + pi.versionCode); title.setText(mContext.getString(R.string.version) + " " + pi.versionName + " bulid " + pi.versionCode);