FileDocCategorySizeDatePackage
ExceptionBrowser.javaAPI DocAndroid 1.5 API5613Wed May 06 22:41:08 BST 2009com.android.development

ExceptionBrowser

public class ExceptionBrowser extends android.app.ListActivity

Fields Summary
private static final String
TAG
Logging identifier.
private static final int
UPLOAD_ID
private static final int
CLEAR_ID
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);

        Cursor cursor = getContentResolver().query(
                Checkin.Crashes.CONTENT_URI,
                new String[] { Checkin.Crashes._ID, Checkin.Crashes.DATA },
                null, null, null);

        if (cursor != null) {
            startManagingCursor(cursor);

            setListAdapter(new CursorAdapter(this, cursor, true) {
                public View newView(Context context, Cursor c, ViewGroup v) {
                    return new CrashListItem(context);
                }

                public void bindView(View view, Context c, Cursor cursor) {
                    CrashListItem item = (CrashListItem) view;
                    try {
                        String data = cursor.getString(1);
                        CrashData crash = new CrashData(
                            new DataInputStream(
                                new ByteArrayInputStream(
                                    Base64.decodeBase64(data.getBytes()))));

                        ThrowableData exc = crash.getThrowableData();
                        item.setText(exc.getType() + ": " + exc.getMessage());
                        item.setCrashData(crash);
                    } catch (IOException e) {
                        item.setText("Invalid crash: " + e);
                        Log.e(TAG, "Invalid crash", e);
                    }
                }
            });
        } else {
            // No database, no exceptions, empty list.
            setListAdapter(new BaseAdapter() {
                public int getCount() {
                    return 0;
                }

                public Object getItem(int position) {
                    throw new AssertionError();
                }

                public long getItemId(int position) {
                    throw new AssertionError();
                }

                public View getView(int position, View convertView,
                        ViewGroup parent) {
                    throw new AssertionError();
                }
            });
        }
    
public booleanonCreateOptionsMenu(android.view.Menu menu)


        
        super.onCreateOptionsMenu(menu);

        menu.add(0, UPLOAD_ID, 0, R.string.menu_upload_exceptions);
        menu.add(0, CLEAR_ID, 0, R.string.menu_clear_exceptions);

        return true;
    
protected voidonListItemClick(ListView l, android.view.View view, int pos, long id)

        // TODO: Use a generic VIEW action on the crash's content URI.
        CrashData crash = ((CrashListItem) view).getCrashData();
        if (crash != null) {
            Intent intent = new Intent();
            intent.setClass(this, StacktraceViewer.class);
            intent.putExtra(
                    CrashData.class.getName(),
                    crash.getThrowableData().toString());
            startActivity(intent);
        }
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        // Handle all of the possible menu actions.
        switch (item.getItemId()) {
            case UPLOAD_ID:
                sendBroadcast(new Intent(Checkin.TriggerIntent.ACTION));
                break;
            case CLEAR_ID:
                getContentResolver().delete(
                        Checkin.Crashes.CONTENT_URI, null, null);
                break;
        }
        return super.onOptionsItemSelected(item);