Cleaned Up code

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-07-01 11:21:18 -04:00
parent c4980a8295
commit 42cb0b9f0e
9 changed files with 297 additions and 308 deletions

View File

@@ -1,11 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -5,8 +5,8 @@
android:versionName="1.0" > android:versionName="1.0" >
<uses-sdk <uses-sdk
android:minSdkVersion="1" android:minSdkVersion="8"
android:targetSdkVersion="11" /> android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />

View File

@@ -40,11 +40,11 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
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 Thread.UncaughtExceptionHandler mDefaultUEH; private final Thread.UncaughtExceptionHandler mDefaultUEH;
private Activity mApp= null; private Activity mApp= null;
private Service mService = null; private Service mService = null;
private BroadcastReceiver mBroadcastReceiver = null; private BroadcastReceiver mBroadcastReceiver = null;
private Context mContext; private final Context mContext;
private Report mReport; private Report mReport;
private static final String TAG = "ExceptionHandler"; private static final String TAG = "ExceptionHandler";
private String mURL = null; private String mURL = null;
@@ -57,10 +57,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @param app * @param app
* @author ricky barrette * @author ricky barrette
*/ */
public ExceptionHandler(Activity app) { public ExceptionHandler(final Activity app) {
this.mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler(); mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
this.mApp = app; mApp = app;
this.mContext = app; mContext = app;
parseProperties(); parseProperties();
} }
@@ -69,10 +69,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @param broadcastReceiver * @param broadcastReceiver
* @author ricky barrette * @author ricky barrette
*/ */
public ExceptionHandler(BroadcastReceiver broadcastReceiver, Context context){ public ExceptionHandler(final BroadcastReceiver broadcastReceiver, final Context context){
this.mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler(); mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
this.mBroadcastReceiver = broadcastReceiver; mBroadcastReceiver = broadcastReceiver;
this.mContext = context; mContext = context;
parseProperties(); parseProperties();
} }
@@ -81,10 +81,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @param service * @param service
* @author ricky barrette * @author ricky barrette
*/ */
public ExceptionHandler(Service service){ public ExceptionHandler(final Service service){
this.mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler(); mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
this.mService = service; mService = service;
this.mContext = service; mContext = service;
parseProperties(); parseProperties();
} }
@@ -105,10 +105,10 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
if(mBroadcastReceiver != null) if(mBroadcastReceiver != null)
title = mBroadcastReceiver.getClass().getName(); title = mBroadcastReceiver.getClass().getName();
Intent intent = new Intent(Intent.ACTION_SEND); final Intent intent = new Intent(Intent.ACTION_SEND);
String theSubject = title + " " + MSG_SUBJECT_TAG; final String theSubject = title + " " + MSG_SUBJECT_TAG;
String theBody = "\n\n"+MSG_BODY+this.mReport.toString(); final String theBody = "\n\n"+MSG_BODY+mReport.toString();
intent.putExtra(Intent.EXTRA_EMAIL,new String[] {this.mEmail}); intent.putExtra(Intent.EXTRA_EMAIL,new String[] {mEmail});
intent.putExtra(Intent.EXTRA_TEXT, theBody); intent.putExtra(Intent.EXTRA_TEXT, theBody);
intent.putExtra(Intent.EXTRA_SUBJECT, theSubject); intent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
intent.setType("message/rfc822"); intent.setType("message/rfc822");
@@ -121,12 +121,12 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @param generatedReportIntent * @param generatedReportIntent
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void displayNotification(Intent generatedReportIntent) { private void displayNotification(final Intent generatedReportIntent) {
Log.i(TAG, "displayNotification"); Log.i(TAG, "displayNotification");
Context context = mContext.getApplicationContext(); final Context context = mContext.getApplicationContext();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notifyDetails = new Notification(android.R.drawable.stat_notify_error, context.getString(R.string.sorry), System.currentTimeMillis()); final Notification notifyDetails = new Notification(android.R.drawable.stat_notify_error, context.getString(R.string.sorry), System.currentTimeMillis());
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);
notifyDetails.setLatestEventInfo(context, context.getString(R.string.crash), context.getString(R.string.sorry), intent); notifyDetails.setLatestEventInfo(context, context.getString(R.string.crash), context.getString(R.string.sorry), intent);
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); notificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
@@ -137,26 +137,27 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @author ricky barrette * @author ricky barrette
*/ */
private void parseProperties() { private void parseProperties() {
Resources resources = this.mContext.getResources(); final Resources resources = mContext.getResources();
AssetManager assetManager = resources.getAssets(); final AssetManager assetManager = resources.getAssets();
// Read from the /assets directory // Read from the /assets directory
try { try {
InputStream inputStream = assetManager.open("exceptionhandler.properties"); final InputStream inputStream = assetManager.open("exceptionhandler.properties");
Properties properties = new Properties(); final Properties properties = new Properties();
properties.load(inputStream); properties.load(inputStream);
this.mURL = properties.getProperty("server"); mURL = properties.getProperty("server");
this.mEmail = properties.getProperty("email"); mEmail = properties.getProperty("email");
this.mAppName = properties.getProperty("app"); mAppName = properties.getProperty("app");
this.mTracker = properties.getProperty("tracker"); mTracker = properties.getProperty("tracker");
} catch (IOException e) { } catch (final IOException e) {
Log.e(TAG, "Failed to open exceptionhandler.properties"); Log.e(TAG, "Failed to open exceptionhandler.properties");
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override
public void run() { public void run() {
if(this.mEmail == null) if(mEmail == null)
displayNotification(new Intent(this.mContext, ExceptionReportActivity.class).putExtra("report", this.mReport)); displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport));
else else
displayEmailNotification(); displayEmailNotification();
} }
@@ -168,61 +169,58 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* @author ricky barrette * @author ricky barrette
*/ */
@Override @Override
public void uncaughtException(Thread t, Throwable e) { public void uncaughtException(final Thread t, final Throwable e) {
Log.d(TAG, "uncaughtException()"); Log.d(TAG, "uncaughtException()");
// Log.d(TAG,"mURL = "+ this.mURL); // Log.d(TAG,"mURL = "+ this.mURL);
// Log.d(TAG,"mEmail = "+ this.mEmail); // Log.d(TAG,"mEmail = "+ this.mEmail);
Date theDate = new Date(); final Date theDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz"); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz");
PackageManager pm = mContext.getPackageManager(); final PackageManager pm = mContext.getPackageManager();
//app environment; //app environment;
PackageInfo pi; PackageInfo pi;
try { try {
pi = pm.getPackageInfo(mContext.getPackageName(), 0); pi = pm.getPackageInfo(mContext.getPackageName(), 0);
} catch (NameNotFoundException eNnf) { } catch (final NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package //doubt this will ever run since we want info about our own package
pi = new PackageInfo(); pi = new PackageInfo();
pi.versionName = "unknown"; pi.versionName = "unknown";
pi.versionCode = 69; pi.versionCode = 69;
} }
StringBuffer report = new StringBuffer(); final StringBuffer report = new StringBuffer();
for (StackTraceElement item : e.getStackTrace()) for (final StackTraceElement item : e.getStackTrace())
report.append("at "+item.toString() + "\n"); report.append("at "+item.toString() + "\n");
StringBuffer causereport = new StringBuffer(); final StringBuffer causereport = new StringBuffer();
Throwable cause = e.getCause(); final Throwable cause = e.getCause();
if (cause != null) { if (cause != null) {
causereport.append(cause.toString() + "\n \n"); causereport.append(cause.toString() + "\n \n");
for (StackTraceElement item : cause.getStackTrace()) for (final StackTraceElement item : cause.getStackTrace())
causereport.append("at "+item.toString() + "\n"); causereport.append("at "+item.toString() + "\n");
} }
//generate the report //generate the report
this.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(), this.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(this.mApp != null){ if(mApp != null)
this.mApp.runOnUiThread(this); mApp.runOnUiThread(this);
}
if(this.mService != null){ if(mService != null)
if(this.mEmail == null) if(mEmail == null)
displayNotification(new Intent(this.mContext, ExceptionReportActivity.class).putExtra("report", this.mReport)); displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport));
else else
displayEmailNotification(); displayEmailNotification();
}
if(this.mBroadcastReceiver != null){ if(mBroadcastReceiver != null)
if(this.mEmail == null) if(mEmail == null)
displayNotification(new Intent(this.mContext, ExceptionReportActivity.class).putExtra("report", this.mReport)); displayNotification(new Intent(mContext, ExceptionReportActivity.class).putExtra("report", mReport));
else else
displayEmailNotification(); displayEmailNotification();
}
//do not forget to pass this exception through up the chain //do not forget to pass this exception through up the chain
mDefaultUEH.uncaughtException(t,e); mDefaultUEH.uncaughtException(t,e);

View File

@@ -24,39 +24,39 @@ public class ExceptionReportActivity extends Activity implements OnClickListener
private static final String TAG = "ExceptionActivity"; private static final String TAG = "ExceptionActivity";
private Report mReport; private Report mReport;
/**
* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
* @author ricky barrette
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
this.mReport = (Report) this.getIntent().getParcelableExtra("report");
if(this.getIntent().hasExtra("display"))
this.setContentView(R.layout.list);
else {
this.setContentView(R.layout.exception_activity);
this.findViewById(R.id.send).setOnClickListener(this);
}
ListView list = (ListView) this.findViewById(android.R.id.list);
list.setAdapter(new ReportAdapter(this, this.mReport.getReport()));
list.setClickable(false);
}
/** /**
* (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
*/ */
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
EditText description = (EditText) findViewById(R.id.description); final EditText description = (EditText) findViewById(R.id.description);
this.mReport.setDescription(description.getText().toString()); mReport.setDescription(description.getText().toString());
v.setEnabled(false); v.setEnabled(false);
this.startService(new Intent(this, ReportPostingService.class).putExtra("report", this.mReport)); startService(new Intent(this, ReportPostingService.class).putExtra("report", mReport));
this.finish(); finish();
}
/**
* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
* @author ricky barrette
*/
@Override
protected void onCreate(final Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
mReport = (Report) getIntent().getParcelableExtra("report");
if(getIntent().hasExtra("display"))
this.setContentView(R.layout.list);
else {
this.setContentView(R.layout.exception_activity);
findViewById(R.id.send).setOnClickListener(this);
}
final ListView list = (ListView) findViewById(android.R.id.list);
list.setAdapter(new ReportAdapter(this, mReport.getReport()));
list.setClickable(false);
} }
} }

View File

@@ -38,11 +38,13 @@ public class Report implements Parcelable{
private ArrayList<ReportItem> mReport; private ArrayList<ReportItem> mReport;
public static final Parcelable.Creator<Report> CREATOR = new Parcelable.Creator<Report>() { public static final Parcelable.Creator<Report> CREATOR = new Parcelable.Creator<Report>() {
public Report createFromParcel(Parcel in) { @Override
public Report createFromParcel(final Parcel in) {
return new Report(in); return new Report(in);
} }
public Report[] newArray(int size) { @Override
public Report[] newArray(final int size) {
return new Report[size]; return new Report[size];
} }
}; };
@@ -52,19 +54,19 @@ public class Report implements Parcelable{
* @param in * @param in
* @author ricky barrette * @author ricky barrette
*/ */
public Report(Parcel in){ public Report(final Parcel in){
this.mUrl = in.readString(); mUrl = in.readString();
this.mReport = new ArrayList<ReportItem>(); mReport = new ArrayList<ReportItem>();
in.readTypedList(this.mReport, ReportItem.CREATOR); in.readTypedList(mReport, ReportItem.CREATOR);
} }
/** /**
* Creates a new Report * Creates a new Report
* @author ricky barrette * @author ricky barrette
*/ */
public Report(String url) { public Report(final String url) {
// Log.d(TAG, url); // Log.d(TAG, url);
this.mUrl = url; mUrl = url;
} }
@Override @Override
@@ -80,16 +82,16 @@ public class Report implements Parcelable{
* @return String result * @return String result
*/ */
public String file() throws ClientProtocolException, IOException{ public String file() throws ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient(); final HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(mUrl); final HttpPost httppost = new HttpPost(mUrl);
httppost.setEntity(new UrlEncodedFormEntity(getNameValuePairs())); httppost.setEntity(new UrlEncodedFormEntity(getNameValuePairs()));
//return the results //return the results
HttpResponse response = httpclient.execute(httppost); final HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity(); final HttpEntity entity = response.getEntity();
InputStream is = entity.getContent(); final InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); final BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n"); sb.append(reader.readLine() + "\n");
String line="0"; String line="0";
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null)
@@ -107,12 +109,12 @@ public class Report implements Parcelable{
* @throws JSONException * @throws JSONException
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Report generateReport(JSONObject report) throws JSONException{ public Report generateReport(final JSONObject report) throws JSONException{
this.mReport = new ArrayList<ReportItem>(); mReport = new ArrayList<ReportItem>();
Iterator iter = report.keys(); final Iterator iter = report.keys();
while(iter.hasNext()){ while(iter.hasNext()){
String key = (String)iter.next(); final String key = (String)iter.next();
this.mReport.add(new ReportItem(key , report.getString(key))); mReport.add(new ReportItem(key , report.getString(key)));
} }
return this; return this;
} }
@@ -128,17 +130,17 @@ public class Report implements Parcelable{
* @return this * @return this
* @author ricky barrette * @author ricky barrette
*/ */
public Report generateReport(String msg, String stackTrace, String cause, String date, String device, String appVersion, String app, String tracker, 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){
this.mReport = new ArrayList<ReportItem>(); mReport = new ArrayList<ReportItem>();
this.mReport.add(new ReportItem("app",app)); mReport.add(new ReportItem("app",app));
this.mReport.add(new ReportItem("version",appVersion)); mReport.add(new ReportItem("version",appVersion));
this.mReport.add(new ReportItem("date",date)); mReport.add(new ReportItem("date",date));
this.mReport.add(new ReportItem("msg",msg)); mReport.add(new ReportItem("msg",msg));
this.mReport.add(new ReportItem("stackTrace",stackTrace)); mReport.add(new ReportItem("stackTrace",stackTrace));
this.mReport.add(new ReportItem("cause",cause)); mReport.add(new ReportItem("cause",cause));
this.mReport.add(new ReportItem("device",device)); mReport.add(new ReportItem("device",device));
this.mReport.add(new ReportItem("tracker",tracker)); mReport.add(new ReportItem("tracker",tracker));
this.mReport.add(new ReportItem("package",packageName)); mReport.add(new ReportItem("package",packageName));
return this; return this;
} }
@@ -148,9 +150,9 @@ public class Report implements Parcelable{
* @author ricky barrette * @author ricky barrette
*/ */
private ArrayList<NameValuePair> getNameValuePairs() { private ArrayList<NameValuePair> getNameValuePairs() {
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); final ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
for(ReportItem entry : this.mReport) for(final ReportItem entry : mReport)
list.add(new BasicNameValuePair(entry.getKey(), (String) entry.getValue())); list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
return list; return list;
} }
@@ -167,8 +169,8 @@ public class Report implements Parcelable{
* @param string * @param string
* @author ricky barrette * @author ricky barrette
*/ */
public Report setDescription(String description) { public Report setDescription(final String description) {
this.mReport.add(new ReportItem("description", description)); mReport.add(new ReportItem("description", description));
return this; return this;
} }
@@ -178,8 +180,8 @@ public class Report implements Parcelable{
*/ */
@Override @Override
public String toString(){ public String toString(){
StringBuilder s = new StringBuilder(); final StringBuilder s = new StringBuilder();
for(ReportItem item : this.mReport){ for(final ReportItem item : mReport){
s.append("\n\n-----"+ item.getKey()+"-----"); s.append("\n\n-----"+ item.getKey()+"-----");
s.append("\n"+item.getValue()); s.append("\n"+item.getValue());
} }
@@ -187,8 +189,8 @@ public class Report implements Parcelable{
} }
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(final Parcel out, final int flags) {
out.writeString(this.mUrl); out.writeString(mUrl);
out.writeTypedList(this.mReport); out.writeTypedList(mReport);
} }
} }

View File

@@ -17,26 +17,29 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.TextView; import android.widget.TextView;
import com.TwentyCodes.android.exception.R;
/** /**
* 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 {
private ArrayList<NameValuePair> mReport; class ViewHolder {
private LayoutInflater mInflater; TextView title;
TextView body;
}
private final ArrayList<NameValuePair> mReport;
private final LayoutInflater mInflater;
/** /**
* Creates a new ReportAdapter * Creates a new ReportAdapter
* @author ricky barrette * @author ricky barrette
*/ */
public ReportAdapter(Context context, ArrayList<NameValuePair> report) { public ReportAdapter(final Context context, final ArrayList<NameValuePair> report) {
super(); super();
// Cache the LayoutInflate to avoid asking for a new one each time. // Cache the LayoutInflate to avoid asking for a new one each time.
this.mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
this.mReport = report; mReport = report;
} }
/** /**
@@ -46,7 +49,7 @@ public class ReportAdapter extends BaseAdapter {
*/ */
@Override @Override
public int getCount() { public int getCount() {
return this.mReport.size(); return mReport.size();
} }
/** /**
@@ -55,8 +58,8 @@ public class ReportAdapter extends BaseAdapter {
* @author ricky barrette * @author ricky barrette
*/ */
@Override @Override
public NameValuePair getItem(int index) { public NameValuePair getItem(final int index) {
return this.mReport.get(index); return mReport.get(index);
} }
/** /**
@@ -65,7 +68,7 @@ public class ReportAdapter extends BaseAdapter {
* @author ricky barrette * @author ricky barrette
*/ */
@Override @Override
public long getItemId(int index) { public long getItemId(final int index) {
return index; return index;
} }
@@ -73,7 +76,7 @@ public class ReportAdapter extends BaseAdapter {
* *
*/ */
@Override @Override
public View getView(final int position, View convertView, 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;
@@ -91,9 +94,8 @@ public class ReportAdapter extends BaseAdapter {
holder.body = (TextView) convertView.findViewById(R.id.exception_text); holder.body = (TextView) convertView.findViewById(R.id.exception_text);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else
holder = (ViewHolder) convertView.getTag(); holder = (ViewHolder) convertView.getTag();
}
/* /*
* Bind the data efficiently with the holder. * Bind the data efficiently with the holder.
@@ -104,9 +106,4 @@ public class ReportAdapter extends BaseAdapter {
return convertView; return convertView;
} }
class ViewHolder {
TextView title;
TextView body;
}
} }

View File

@@ -17,11 +17,13 @@ import android.os.Parcelable;
public final class ReportItem implements Parcelable { public final class ReportItem implements Parcelable {
public static final Parcelable.Creator<ReportItem> CREATOR = new Parcelable.Creator<ReportItem>() { public static final Parcelable.Creator<ReportItem> CREATOR = new Parcelable.Creator<ReportItem>() {
public ReportItem createFromParcel(Parcel in) { @Override
public ReportItem createFromParcel(final Parcel in) {
return new ReportItem(in); return new ReportItem(in);
} }
public ReportItem[] newArray(int size) { @Override
public ReportItem[] newArray(final int size) {
return new ReportItem[size]; return new ReportItem[size];
} }
}; };
@@ -29,22 +31,22 @@ public final class ReportItem implements Parcelable {
private final String mKey; private final String mKey;
private final String mValue; private final String mValue;
/**
* Creates a new ReportItem
* @author ricky barrette
*/
public ReportItem(String key, String value) {
this.mKey = key;
this.mValue = value;
}
/** /**
* Creates a new ReportItem from a parcel * Creates a new ReportItem from a parcel
* @param in * @param in
*/ */
public ReportItem(Parcel in){ public ReportItem(final Parcel in){
this.mKey = in.readString(); mKey = in.readString();
this.mValue = in.readString(); mValue = in.readString();
}
/**
* Creates a new ReportItem
* @author ricky barrette
*/
public ReportItem(final String key, final String value) {
mKey = key;
mValue = value;
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -56,27 +58,27 @@ public final class ReportItem implements Parcelable {
return 0; return 0;
} }
/* (non-Javadoc)
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.mKey);
dest.writeString(this.mValue);
}
/** /**
* @return the key * @return the key
*/ */
public String getKey() { public String getKey() {
return this.mKey; return mKey;
} }
/** /**
* @return the value * @return the value
*/ */
public String getValue() { public String getValue() {
return this.mValue; return mValue;
}
/* (non-Javadoc)
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/
@Override
public void writeToParcel(final Parcel dest, final int flags) {
dest.writeString(mKey);
dest.writeString(mValue);
} }
} }

View File

@@ -50,15 +50,15 @@ public class ReportPostingService extends Service {
*/ */
@SuppressLint("NewApi") @SuppressLint("NewApi")
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void fireNotification(String title, String contentText, String ticker, int icon, Intent intent, boolean isOngoing) { private void fireNotification(final String title, final String contentText, final String ticker, final int icon, final Intent intent, final boolean isOngoing) {
PendingIntent pendingIntent = null; PendingIntent pendingIntent = null;
if(intent != null) if(intent != null)
pendingIntent = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0); pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
/* /*
* Use the appropriate notificafation methods * Use the appropriate notificafation methods
*/ */
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){ if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){
Builder builder = new Notification.Builder(this.getApplicationContext()) final Builder builder = new Notification.Builder(getApplicationContext())
.setContentTitle(title) .setContentTitle(title)
.setContentText(contentText) .setContentText(contentText)
.setTicker(ticker) .setTicker(ticker)
@@ -72,12 +72,12 @@ public class ReportPostingService extends Service {
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
} else { } else {
Notification notification = new Notification(icon, title , System.currentTimeMillis()); final Notification notification = new Notification(icon, title , System.currentTimeMillis());
if(isOngoing) if(isOngoing)
notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_ONGOING_EVENT;
else else
notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(), title, contentText, pendingIntent); notification.setLatestEventInfo(getApplicationContext(), title, contentText, pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification); mNotificationManager.notify(NOTIFICATION_ID, notification);
} }
} }
@@ -87,7 +87,7 @@ public class ReportPostingService extends Service {
* @param intent * @param intent
* @author ricky barrette * @author ricky barrette
*/ */
private void getReport(Intent intent) { private void getReport(final Intent intent) {
mReport = (Report) intent.getParcelableExtra("report"); mReport = (Report) intent.getParcelableExtra("report");
} }
@@ -100,7 +100,7 @@ public class ReportPostingService extends Service {
getString(R.string.reporting_error_msg), getString(R.string.reporting_error_msg),
getString(R.string.reporting_error_msg), getString(R.string.reporting_error_msg),
android.R.drawable.stat_notify_error, android.R.drawable.stat_notify_error,
new Intent(this.getApplicationContext(), ReportPostingService.class).putExtras(mIntent), new Intent(getApplicationContext(), ReportPostingService.class).putExtras(mIntent),
false); false);
} }
@@ -123,7 +123,7 @@ public class ReportPostingService extends Service {
* @see android.app.Service#onBind(android.content.Intent) * @see android.app.Service#onBind(android.content.Intent)
*/ */
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(final Intent intent) {
// Unused // Unused
return null; return null;
} }
@@ -137,7 +137,7 @@ public class ReportPostingService extends Service {
*/ */
@Override @Override
public void onCreate() { public void onCreate() {
Context context = this.getApplicationContext(); final Context context = getApplicationContext();
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifySending(); notifySending();
@@ -163,7 +163,7 @@ public class ReportPostingService extends Service {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(final Intent intent, final int startId) {
mStartId = startId; mStartId = startId;
getReport(intent); getReport(intent);
postReport(); postReport();
@@ -177,7 +177,7 @@ public class ReportPostingService extends Service {
*/ */
@TargetApi(5) @TargetApi(5)
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(final Intent intent, final int flags, final int startId) {
mStartId = startId; mStartId = startId;
getReport(intent); getReport(intent);
postReport(); postReport();
@@ -197,10 +197,10 @@ public class ReportPostingService extends Service {
public void run(){ public void run(){
try { try {
Log.d(TAG, mReport.file()); Log.d(TAG, mReport.file());
} catch (ClientProtocolException e) { } catch (final ClientProtocolException e) {
e.printStackTrace(); e.printStackTrace();
hasErrored = true; hasErrored = true;
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
hasErrored = true; hasErrored = true;
} finally { } finally {

View File

@@ -15,6 +15,7 @@ import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@@ -24,14 +25,14 @@ import android.widget.TextView;
*/ */
public class VersionInformationPreference extends Preference { public class VersionInformationPreference extends Preference {
private Context mContext; private final Context mContext;
/** /**
* 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(Context context) { public VersionInformationPreference(final Context context) {
super(context); super(context);
mContext = context; mContext = context;
} }
@@ -41,7 +42,7 @@ public class VersionInformationPreference extends Preference {
* @param context * @param context
* @param attrs * @param attrs
*/ */
public VersionInformationPreference(Context context, AttributeSet attrs) { public VersionInformationPreference(final Context context, final AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mContext = context; mContext = context;
} }
@@ -52,7 +53,7 @@ public class VersionInformationPreference extends Preference {
* @param attrs * @param attrs
* @param defStyle * @param defStyle
*/ */
public VersionInformationPreference(Context context, AttributeSet attrs, int defStyle) { public VersionInformationPreference(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mContext = context; mContext = context;
} }
@@ -67,16 +68,16 @@ public class VersionInformationPreference extends Preference {
* @author ricky barrette * @author ricky barrette
*/ */
@Override @Override
protected View onCreateView(ViewGroup parent){ protected View onCreateView(final ViewGroup parent){
/* /*
* get the build information, and build the string * get the build information, and build the string
*/ */
PackageManager pm = mContext.getPackageManager(); final PackageManager pm = mContext.getPackageManager();
PackageInfo pi; PackageInfo pi;
try { try {
pi = pm.getPackageInfo(mContext.getPackageName(), 0); pi = pm.getPackageInfo(mContext.getPackageName(), 0);
} catch (NameNotFoundException eNnf) { } catch (final NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package //doubt this will ever run since we want info about our own package
pi = new PackageInfo(); pi = new PackageInfo();
pi.versionName = "unknown"; pi.versionName = "unknown";
@@ -86,9 +87,9 @@ 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
*/ */
LinearLayout layout = new LinearLayout(getContext()); final LinearLayout layout = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// params.gravity = Gravity.CENTER; // params.gravity = Gravity.CENTER;
layout.setPadding(15, 5, 10, 5); layout.setPadding(15, 5, 10, 5);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
@@ -98,7 +99,7 @@ public class VersionInformationPreference extends Preference {
* 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 build information
* and add it to the layout * and add it to the layout
*/ */
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);
title.setTextSize(16); title.setTextSize(16);
title.setTypeface(Typeface.SANS_SERIF); title.setTypeface(Typeface.SANS_SERIF);