Attempt to plug some odd recent force closes

git-svn-id: https://zxing.googlecode.com/svn/trunk@1640 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-11-11 07:33:25 +00:00
parent 754e8d3910
commit 20cac4ff82
5 changed files with 56 additions and 33 deletions

View file

@ -51,8 +51,8 @@ public final class ViewfinderView extends View {
private final int laserColor; private final int laserColor;
private final int resultPointColor; private final int resultPointColor;
private int scannerAlpha; private int scannerAlpha;
private Collection<ResultPoint> possibleResultPoints; private volatile Collection<ResultPoint> possibleResultPoints;
private Collection<ResultPoint> lastPossibleResultPoints; private volatile Collection<ResultPoint> lastPossibleResultPoints;
// This constructor is used when the class is built from an XML resource. // This constructor is used when the class is built from an XML resource.
public ViewfinderView(Context context, AttributeSet attrs) { public ViewfinderView(Context context, AttributeSet attrs) {

View file

@ -25,7 +25,7 @@ import android.content.Context;
*/ */
final class DBHelper extends SQLiteOpenHelper { final class DBHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 2; private static final int DB_VERSION = 3;
private static final String DB_NAME = "barcode_scanner_history.db"; private static final String DB_NAME = "barcode_scanner_history.db";
static final String TABLE_NAME = "history"; static final String TABLE_NAME = "history";
static final String ID_COL = "id"; static final String ID_COL = "id";

View file

@ -22,6 +22,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -33,6 +34,7 @@ import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
@ -80,7 +82,13 @@ public final class HistoryManager {
List<Result> getHistoryItems() { List<Result> getHistoryItems() {
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
List<Result> items = new ArrayList<Result>(); List<Result> items = new ArrayList<Result>();
SQLiteDatabase db = helper.getReadableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return Collections.emptyList();
}
Cursor cursor = null; Cursor cursor = null;
try { try {
cursor = db.query(DBHelper.TABLE_NAME, cursor = db.query(DBHelper.TABLE_NAME,
@ -135,7 +143,13 @@ public final class HistoryManager {
} }
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = helper.getWritableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return;
}
try { try {
// Insert // Insert
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -151,7 +165,13 @@ public final class HistoryManager {
private void deletePrevious(String text) { private void deletePrevious(String text) {
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = helper.getWritableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return;
}
try { try {
db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "=?", new String[] { text }); db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "=?", new String[] { text });
} finally { } finally {
@ -161,7 +181,13 @@ public final class HistoryManager {
public void trimHistory() { public void trimHistory() {
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = helper.getWritableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return;
}
Cursor cursor = null; Cursor cursor = null;
try { try {
cursor = db.query(DBHelper.TABLE_NAME, cursor = db.query(DBHelper.TABLE_NAME,
@ -200,7 +226,13 @@ public final class HistoryManager {
CharSequence buildHistory() { CharSequence buildHistory() {
StringBuilder historyText = new StringBuilder(1000); StringBuilder historyText = new StringBuilder(1000);
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = helper.getReadableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return "";
}
Cursor cursor = null; Cursor cursor = null;
try { try {
cursor = db.query(DBHelper.TABLE_NAME, cursor = db.query(DBHelper.TABLE_NAME,
@ -258,7 +290,13 @@ public final class HistoryManager {
void clearHistory() { void clearHistory() {
SQLiteOpenHelper helper = new DBHelper(activity); SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = helper.getWritableDatabase(); SQLiteDatabase db;
try {
db = helper.getWritableDatabase();
} catch (SQLiteException sqle) {
Log.w(TAG, "Error while opening database", sqle);
return;
}
try { try {
db.delete(DBHelper.TABLE_NAME, null, null); db.delete(DBHelper.TABLE_NAME, null, null);
} finally { } finally {

View file

@ -50,25 +50,11 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<Str
private final AppPickerActivity activity; private final AppPickerActivity activity;
private DialogInterface dialog;
LoadPackagesAsyncTask(AppPickerActivity activity) { LoadPackagesAsyncTask(AppPickerActivity activity) {
this.activity = activity; this.activity = activity;
} }
@Override
protected synchronized void onPreExecute() {
dialog = ProgressDialog.show(activity, "", activity.getString(R.string.msg_loading_apps), true, true);
}
@Override
protected synchronized void onCancelled() {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
}
@Override @Override
protected List<String[]> doInBackground(List<String[]>... objects) { protected List<String[]> doInBackground(List<String[]>... objects) {
List<String[]> labelsPackages = objects[0]; List<String[]> labelsPackages = objects[0];
@ -110,13 +96,8 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<Str
for (String[] result : results) { for (String[] result : results) {
labels.add(result[0]); labels.add(result[0]);
} }
ListAdapter listAdapter = new ArrayAdapter<String>( ListAdapter listAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, labels);
activity, android.R.layout.simple_list_item_1, labels);
activity.setListAdapter(listAdapter); activity.setListAdapter(listAdapter);
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
} }
private static class ByFirstStringComparator implements Comparator<String[]>, Serializable { private static class ByFirstStringComparator implements Comparator<String[]>, Serializable {

View file

@ -179,12 +179,16 @@ public final class ShareActivity extends Activity {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (contactCursor != null && contactCursor.moveToFirst()) { if (contactCursor != null && contactCursor.moveToFirst()) {
int nameColumn = contactCursor.getColumnIndex(Contacts.PeopleColumns.NAME); int nameColumn = contactCursor.getColumnIndex(Contacts.PeopleColumns.NAME);
if (nameColumn >= 0) {
String name = contactCursor.getString(nameColumn); String name = contactCursor.getString(nameColumn);
// Don't require a name to be present, this contact might be just a phone number. // Don't require a name to be present, this contact might be just a phone number.
if (name != null && name.length() > 0) { if (name != null && name.length() > 0) {
bundle.putString(Contacts.Intents.Insert.NAME, massageContactData(name)); bundle.putString(Contacts.Intents.Insert.NAME, massageContactData(name));
} }
} else {
Log.w(TAG, "Unable to find column? " + Contacts.PeopleColumns.NAME);
}
contactCursor.close(); contactCursor.close();
Uri phonesUri = Uri.withAppendedPath(contactUri, Contacts.People.Phones.CONTENT_DIRECTORY); Uri phonesUri = Uri.withAppendedPath(contactUri, Contacts.People.Phones.CONTENT_DIRECTORY);