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
android:minSdkVersion="8"
android:targetSdkVersion="15" />
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />

View File

@@ -30,15 +30,17 @@ import android.util.Log;
import anroid.v4.compat.NotificationCompat;
/**
* This is Twenty Codes, LLC Exception Handler of Awesomeness!
* This class will be used to generate reports that will be emailed to us via the users email client after the users approval
* This is Twenty Codes, LLC Exception Handler of Awesomeness! This class will
* be used to generate reports that will be emailed to us via the users email
* client after the users approval
*
* @author ricky barrette
*/
public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
private static final String MSG_SUBJECT_TAG = "Exception Report";
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).";
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).";
protected static final int SIMPLE_NOTFICATION_ID = 45684645;
private final Thread.UncaughtExceptionHandler mDefaultUEH;
private Activity mApp = null;
@@ -54,6 +56,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/**
* Creates a new ExceptionHandler
*
* @param app
* @author ricky barrette
*/
@@ -66,6 +69,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/**
* Creates a new ExceptionHandler
*
* @param broadcastReceiver
* @author ricky barrette
*/
@@ -78,6 +82,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/**
* Creates a new ExceptionHandler
*
* @param service
* @author ricky barrette
*/
@@ -90,6 +95,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
/**
* Generates an email from the report
*
* @author ricky barrette
*/
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
*/
private void displayNotification(final Intent generatedReportIntent) {
@@ -125,19 +133,16 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
final Context context = mContext.getApplicationContext();
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 NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.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)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentIntent(intent);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).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)
.setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentIntent(intent);
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
*/
private void parseProperties() {
@@ -167,9 +172,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
}
/**
* Called when there is an uncaught exception.
* (non-Javadoc)
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable)
* Called when there is an uncaught exception. (non-Javadoc)
*
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread,
* java.lang.Throwable)
* @author ricky barrette
*/
@Override
@@ -207,13 +213,13 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
}
// 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)
if (mApp != null)
mApp.runOnUiThread(this);
if (mService != null)
if (mEmail == null)
displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport));

View File

@@ -16,7 +16,9 @@ import android.widget.EditText;
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
*/
public class ExceptionReportActivity extends Activity implements OnClickListener {
@@ -26,6 +28,7 @@ public class ExceptionReportActivity extends Activity implements OnClickListener
/**
* (non-Javadoc)
*
* @see android.view.View.OnClickListener#onClick(android.view.View)
* @author ricky barrette
*/
@@ -40,6 +43,7 @@ public class ExceptionReportActivity extends Activity implements OnClickListener
/**
* (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle)
* @author ricky barrette
*/

View File

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

View File

@@ -18,7 +18,9 @@ import android.widget.BaseAdapter;
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
*/
public class ReportAdapter extends BaseAdapter {
@@ -27,12 +29,14 @@ public class ReportAdapter extends BaseAdapter {
TextView title;
TextView body;
}
private final ArrayList<NameValuePair> mReport;
private final LayoutInflater mInflater;
/**
* Creates a new ReportAdapter
*
* @author ricky barrette
*/
public ReportAdapter(final Context context, final ArrayList<NameValuePair> report) {
@@ -44,6 +48,7 @@ public class ReportAdapter extends BaseAdapter {
/**
* (non-Javadoc)
*
* @see android.widget.Adapter#getCount()
* @author ricky barrette
*/
@@ -54,6 +59,7 @@ public class ReportAdapter extends BaseAdapter {
/**
* (non-Javadoc)
*
* @see android.widget.Adapter#getItem(int)
* @author ricky barrette
*/
@@ -64,6 +70,7 @@ public class ReportAdapter extends BaseAdapter {
/**
* (non-Javadoc)
*
* @see android.widget.Adapter#getItemId(int)
* @author ricky barrette
*/
@@ -78,16 +85,20 @@ public class ReportAdapter extends BaseAdapter {
@Override
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;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// When convertView is not null, we can reuse it directly, there is no
// need
// to reinflate it. We only inflate a new View when the convertView
// supplied
// by ListView is null.
if (convertView == 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.
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.exception_title);

View File

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

View File

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

View File

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