Closed eleybourn closed 13 years ago
isbn_scan.patch
diff --git a/res/layout/isbn_scan.xml b/res/layout/isbn_scan.xml
index 6f6849e..630413c 100644
--- a/res/layout/isbn_scan.xml
+++ b/res/layout/isbn_scan.xml
@@ -19,6 +19,17 @@
android:digits="0123456789Xx"
android:padding="10sp"
android:textAppearance="?android:attr/textAppearanceLarge"
- />
+ />
+ <Button android:layout_width="fill_parent" android:text="Start Scan" android:id="@+id/startscan" android:layout_height="wrap_content"></Button>
+ <RadioGroup android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_width="fill_parent" android:baselineAligned="false">
+ <RadioButton android:text="Add Books" android:layout_width="wrap_content" android:id="@+id/addbook" android:layout_height="wrap_content" android:checked="true"></RadioButton>
+ <CheckBox android:layout_width="wrap_content" android:id="@+id/notfound" android:text="Include not founds" android:layout_height="wrap_content" android:layout_marginLeft="10dip"></CheckBox>
+ <RadioButton android:text="Search Books" android:layout_width="wrap_content" android:id="@+id/searchbook" android:layout_height="wrap_content"></RadioButton>
+ <CheckBox android:layout_width="wrap_content" android:id="@+id/editbook" android:text="Edit Book" android:layout_height="wrap_content" android:layout_marginLeft="10dip"></CheckBox>
+ <RadioButton android:text="Set Locations" android:layout_width="wrap_content" android:id="@+id/setlocation" android:layout_height="wrap_content"></RadioButton>
+ <EditText android:layout_width="fill_parent" android:id="@+id/location" android:layout_height="wrap_content" android:text="Location" android:layout_marginLeft="10dip"></EditText>
+ <RadioButton android:text="Set Lenders" android:layout_width="wrap_content" android:id="@+id/setlender" android:layout_height="wrap_content"></RadioButton>
+ <EditText android:id="@+id/lender" android:layout_height="wrap_content" android:text="Lender" android:layout_marginLeft="10dip" android:layout_width="fill_parent"></EditText>
+ </RadioGroup>
</LinearLayout>
</ScrollView>
\ No newline at end of file
0001-Add-Barcode2-ISBN2.patch
From eb7621900a2043c1fa6c85da8d7c94ec47e980b0 Mon Sep 17 00:00:00 2001
From: Jam <jam@jam.org>
Date: Sat, 12 Mar 2011 20:26:33 +0200
Subject: [PATCH 1/4] Add Barcode2 (ISBN2)
Adds field for barcode, which is also used ISBN search.
Note that Scan-button is fully visible only in landscape.
Signed-off-by: Jam <jam@jam.org>
---
AndroidManifest.xml | 2 +-
res/layout/edit_book.xml | 15 +++
res/values/strings.xml | 2 +
.../eleybourn/bookcatalogue/BookBarcodeSearch.java | 129 ++++++++++++++++++++
.../eleybourn/bookcatalogue/BookEditFields.java | 26 ++++-
.../bookcatalogue/CatalogueDBAdapter.java | 24 +++-
src/com/eleybourn/bookcatalogue/ExportThread.java | 2 +
.../eleybourn/bookcatalogue/FieldVisibility.java | 6 +-
8 files changed, 197 insertions(+), 9 deletions(-)
create mode 100644 src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 138e0a8..e93547c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eleybourn.bookcatalogue"
- android:versionName="3.3" android:versionCode="47">
+ android:versionName="3.4.1" android:versionCode="54">
<application android:label="@string/app_name" android:icon="@drawable/logo_bc" android:debuggable="true">
<provider android:name=".SearchSuggestionProvider" android:authorities="com.eleybourn.bookcatalogue.SearchSuggestionProvider" />
<activity android:name=".BookCatalogue"
diff --git a/res/layout/edit_book.xml b/res/layout/edit_book.xml
index 1df861b..1007ba0 100644
--- a/res/layout/edit_book.xml
+++ b/res/layout/edit_book.xml
@@ -43,6 +43,15 @@
android:layout_weight="1"
android:hint="@string/isbn"
android:inputType="text"
+ android:nextFocusDown="@+id/isbn2"
+ />
+
+ <EditText android:id="@+id/isbn2"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:hint="@string/isbn2"
+ android:inputType="numberDecimal"
android:nextFocusDown="@+id/series"
/>
@@ -163,5 +172,11 @@
android:width="150sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
+
+ <Button android:id="@+id/scan"
+ android:text="@string/scan"
+ android:width="150sp"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6c315a7..e31a434 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6,6 +6,7 @@
<string name="author">Author</string>
<string name="title">Title</string>
<string name="isbn">ISBN</string>
+<string name="isbn2">Barcode2</string>
<string name="publisher">Publisher</string>
<string name="date_published">Date Published</string>
<string name="rating">Rating</string>
@@ -25,6 +26,7 @@
<string name="menu_insert_barcode">Add by Barcode</string>
<string name="search">Search</string>
<string name="cancel">Cancel</string>
+<string name="scan">Scan Barcode2</string>
<string name="confirm_save">Save Book</string>
<string name="nobookshelves">You have not created any bookshelves yet. Please add some using the menu at the bottom of this screen.</string>
<string name="menu_insert_bs">Create Bookshelf</string>
diff --git a/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
new file mode 100644
index 0000000..c484ede
--- /dev/null
+++ b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
@@ -0,0 +1,129 @@
+/*
+ * @copyright 2011 ++Jam
+ * @license GNU General Public License
+ *
+ * This file is part of Book Catalogue.
+ *
+ * Book Catalogue is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Book Catalogue is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Book Catalogue. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.eleybourn.bookcatalogue;
+
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.widget.Toast;
+
+public class BookBarcodeSearch extends Activity {
+ public static final String BY = "by";
+
+ private static final int ACTIVITY_SCAN=4;
+ private static final int ACTIVITY_BARCODE2 = 42;
+
+ private CatalogueDBAdapter mDbHelper;
+
+ public String barcode;
+
+ // Flag to indicate the Activity should not 'finish()' because
+ // an alert is being displayed. The Alter will call finish().
+ private boolean mDisplayingAlert = false;
+
+ // The intent used to start the scanner.
+ private Intent mScannerIntent = null;
+ // The last Intent returned as a result of creating a book.
+ private Intent mLastBookIntent = null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Bundle extras = getIntent().getExtras();
+ mDbHelper = new CatalogueDBAdapter(this);
+ mDbHelper.open();
+
+ barcode = extras.getString("barcode");
+ String by = extras.getString(BY);
+ int mode = ACTIVITY_SCAN;
+ if (by.equals("barcode2")) {
+ mode = ACTIVITY_BARCODE2;
+ }
+ /**
+ * Use the zxing barcode scanner to search for a isbn
+ * Prompt users to install the application if they do not have it installed.
+ */
+ try {
+ // Start the scanner IF this is a real 'first time' call.
+ if (savedInstanceState == null)
+ startScannerActivity(mode);
+ } catch (ActivityNotFoundException e) {
+ // Verify - this can be a dangerous operation
+ BookBarcodeSearch pthis = this;
+ AlertDialog alertDialog = new AlertDialog.Builder(pthis).setMessage(R.string.install_scan).create();
+ alertDialog.setTitle(R.string.install_scan_title);
+ alertDialog.setIcon(android.R.drawable.ic_menu_info_details);
+ alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.zxing.client.android"));
+ startActivity(marketIntent);
+ finish();
+ }
+ });
+ alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ //do nothing
+ finish();
+ }
+ });
+ // Prevent the activity result from closing this activity.
+ mDisplayingAlert = true;
+ alertDialog.show();
+ return;
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mDbHelper.close();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ super.onActivityResult(requestCode, resultCode, intent);
+ switch(requestCode) {
+ case ACTIVITY_BARCODE2:
+ String contents = intent.getStringExtra("SCAN_RESULT");
+ Toast.makeText(this, contents, Toast.LENGTH_LONG).show();
+ this.setResult(RESULT_OK, intent);
+ finish();
+ break;
+ }
+ }
+
+ /*
+ * Start scanner activity.
+ */
+ private void startScannerActivity(int mode) {
+ if (mScannerIntent == null)
+ mScannerIntent = new Intent("com.google.zxing.client.android.SCAN");
+ //intent.putExtra("SCAN_MODE", "EAN_13");
+ startActivityForResult(mScannerIntent, mode);
+ }
+
+}
diff --git a/src/com/eleybourn/bookcatalogue/BookEditFields.java b/src/com/eleybourn/bookcatalogue/BookEditFields.java
index d19d0c7..7167787 100644
--- a/src/com/eleybourn/bookcatalogue/BookEditFields.java
+++ b/src/com/eleybourn/bookcatalogue/BookEditFields.java
@@ -73,6 +73,7 @@ public class BookEditFields extends Activity {
private Button mConfirmButton;
private Button mCancelButton;
+ private Button mScanButton;
private Long mRowId;
private CatalogueDBAdapter mDbHelper;
private Integer mThumbEditSize;
@@ -108,7 +109,9 @@ public class BookEditFields extends Activity {
private static final int ZOOM_THUMB_DIALOG_ID = 2;
public static final String BOOKSHELF_SEPERATOR = ", ";
-
+
+ private static final int ACTIVITY_BARCODE2 = 42;
+
private ArrayList<Author> mAuthorList = null;
private ArrayList<Series> mSeriesList = null;
CoverBrowser mCoverBrowser = null;
@@ -196,6 +199,7 @@ public class BookEditFields extends Activity {
mFields.add(R.id.title, CatalogueDBAdapter.KEY_TITLE, nonBlankValidator);
mFields.add(R.id.isbn, CatalogueDBAdapter.KEY_ISBN, null);
+ mFields.add(R.id.isbn2, CatalogueDBAdapter.KEY_ISBN2, null);
mFields.add(R.id.publisher, CatalogueDBAdapter.KEY_PUBLISHER, null);
mFields.add(R.id.date_published_button, "", CatalogueDBAdapter.KEY_DATE_PUBLISHED, null);
mFields.add(R.id.date_published, CatalogueDBAdapter.KEY_DATE_PUBLISHED, CatalogueDBAdapter.KEY_DATE_PUBLISHED,
@@ -286,6 +290,7 @@ public class BookEditFields extends Activity {
mConfirmButton = (Button) findViewById(R.id.confirm);
mCancelButton = (Button) findViewById(R.id.cancel);
+ mScanButton = (Button) findViewById(R.id.scan);
bookshelfButtonFe.view.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -458,13 +463,26 @@ public class BookEditFields extends Activity {
finish();
}
});
+
+ // Start scan for Barcode2 (ISBN2)
+ mScanButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View view) {
+ createBarcodeScan();
+ }
+ });
} catch (IndexOutOfBoundsException e) {
Logger.logError(e);
} catch (SQLException e) {
Logger.logError(e);
}
}
-
+
+ private void createBarcodeScan() {
+ Intent i = new Intent(this, BookBarcodeSearch.class);
+ i.putExtra(BookBarcodeSearch.BY, "barcode2");
+ startActivityForResult(i, ACTIVITY_BARCODE2);
+ }
+
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog;
@@ -1015,6 +1033,10 @@ public class BookEditFields extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch(requestCode) {
+ case ACTIVITY_BARCODE2:
+ String contents = intent.getStringExtra("SCAN_RESULT");
+ mFields.getField(R.id.isbn2).setValue(contents);
+ return;
case ADD_PHOTO:
if (resultCode == Activity.RESULT_OK){
String filename = CatalogueDBAdapter.fetchThumbnailFilename(mRowId, true);
diff --git a/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java b/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
index cc3cbb0..81d91cb 100644
--- a/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
+++ b/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
@@ -64,6 +64,7 @@ public class CatalogueDBAdapter {
public static final String KEY_TITLE = "title";
public static final String KEY_THUMBNAIL = "thumbnail";
public static final String KEY_ISBN = "isbn";
+ public static final String KEY_ISBN2 = "isbn2";
public static final String KEY_PUBLISHER = "publisher";
public static final String KEY_DATE_PUBLISHED = "date_published";
public static final String KEY_RATING = "rating";
@@ -154,6 +155,7 @@ public class CatalogueDBAdapter {
/* KEY_AUTHOR + " integer not null REFERENCES " + DB_TB_AUTHORS + ", " + */
KEY_TITLE + " text not null, " +
KEY_ISBN + " text, " +
+ KEY_ISBN2 + " text, " +
KEY_PUBLISHER + " text, " +
KEY_DATE_PUBLISHED + " date, " +
KEY_RATING + " float not null default 0, " +
@@ -229,6 +231,7 @@ public class CatalogueDBAdapter {
"CREATE INDEX IF NOT EXISTS books_title ON "+DB_TB_BOOKS+" ("+KEY_TITLE+");" +
"CREATE INDEX IF NOT EXISTS books_title_ci ON "+DB_TB_BOOKS+" ("+KEY_TITLE+" " + COLLATION + ");" +
"CREATE INDEX IF NOT EXISTS books_isbn ON "+DB_TB_BOOKS+" ("+KEY_ISBN+");" +
+ "CREATE INDEX IF NOT EXISTS books_isbn2 ON "+DB_TB_BOOKS+" ("+KEY_ISBN2+");" +
/* "CREATE INDEX IF NOT EXISTS books_series ON "+DB_TB_BOOKS+" ("+KEY_SERIES+");" + */
"CREATE INDEX IF NOT EXISTS books_publisher ON "+DB_TB_BOOKS+" ("+KEY_PUBLISHER+");" +
"CREATE INDEX IF NOT EXISTS anthology_book ON "+DB_TB_ANTHOLOGY+" ("+KEY_BOOK+");" +
@@ -305,6 +308,7 @@ public class CatalogueDBAdapter {
"(Select Count(*) from " + DB_TB_BOOK_AUTHOR + " ba Where ba." + KEY_BOOK + " = " + alias + "." + KEY_ROWID + ") as _num_authors," +
alias + "." + KEY_ISBN + " as " + KEY_ISBN + ", " +
+ alias + "." + KEY_ISBN2 + " as " + KEY_ISBN2 + ", " +
alias + "." + KEY_PUBLISHER + " as " + KEY_PUBLISHER + ", " +
alias + "." + KEY_DATE_PUBLISHED + " as " + KEY_DATE_PUBLISHED + ", " +
alias + "." + KEY_RATING + " as " + KEY_RATING + ", " +
@@ -882,7 +886,15 @@ public class CatalogueDBAdapter {
} catch (Exception e) {
Logger.logError(e);
}
- }
+ }
+ if (curVersion == 54) {
+ curVersion++;
+ message += "New in v3.4.1\n\n";
+ message += "* Barcode2\n* Search own books with barcode\n\n";
+
+ db.execSQL("ALTER TABLE " + DB_TB_BOOKS + " ADD " + KEY_ISBN2 + " text");
+ createIndices(db);
+ }
}
}
}
@@ -1868,9 +1880,11 @@ public class CatalogueDBAdapter {
*/
public boolean checkIsbnExists(String isbn) {
if (mCheckIsbnExistsStmt == null) {
- mCheckIsbnExistsStmt = compileStatement("Select Count(*) From " + DB_TB_BOOKS + " Where Upper(" + KEY_ISBN + ") = Upper(?)");
+ mCheckIsbnExistsStmt = compileStatement("Select Count(*) From " + DB_TB_BOOKS +
+ " Where Upper(" + KEY_ISBN + ") = Upper(?) OR Upper(" + KEY_ISBN2 + ") = Upper(?)");
}
mCheckIsbnExistsStmt.bindString(1, isbn);
+ mCheckIsbnExistsStmt.bindString(2, isbn);
return mCheckIsbnExistsStmt.simpleQueryForLong() > 0;
}
@@ -2030,6 +2044,10 @@ public class CatalogueDBAdapter {
" SELECT \"BK\" || b." + KEY_ROWID + " as " + BaseColumns._ID + ", b." + KEY_ISBN + " as " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ", b." + KEY_ISBN + " as " + SearchManager.SUGGEST_COLUMN_INTENT_DATA +
" FROM " + DB_TB_BOOKS + " b" +
" WHERE b." + KEY_ISBN + " LIKE '"+query+"%'" +
+ " UNION " +
+ " SELECT \"BK\" || b." + KEY_ROWID + " as " + BaseColumns._ID + ", b." + KEY_ISBN2 + " as " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ", b." + KEY_ISBN2 + " as " + SearchManager.SUGGEST_COLUMN_INTENT_DATA +
+ " FROM " + DB_TB_BOOKS + " b" +
+ " WHERE b." + KEY_ISBN2 + " LIKE '"+query+"%'" +
" ORDER BY Upper(b." + KEY_TITLE + ") " + COLLATION;
;
Cursor results = mDb.rawQuery(sql, null);
@@ -2119,7 +2137,7 @@ public class CatalogueDBAdapter {
StringBuilder result = new StringBuilder("(");
// Just do a simple search of a bunch of fields.
- String[] keys = new String[] {KEY_TITLE, KEY_ISBN, KEY_PUBLISHER, KEY_NOTES, KEY_LOCATION};
+ String[] keys = new String[] {KEY_TITLE, KEY_ISBN, KEY_ISBN2, KEY_PUBLISHER, KEY_NOTES, KEY_LOCATION};
for(String k : keys)
result.append(makeSearchTerm(k, search_term) + " OR ");
diff --git a/src/com/eleybourn/bookcatalogue/ExportThread.java b/src/com/eleybourn/bookcatalogue/ExportThread.java
index 1d2639e..92cad56 100644
--- a/src/com/eleybourn/bookcatalogue/ExportThread.java
+++ b/src/com/eleybourn/bookcatalogue/ExportThread.java
@@ -84,6 +84,7 @@ public class ExportThread extends ManagedTask {
'"' + "anthology_titles" + "\"," + //24
'"' + CatalogueDBAdapter.KEY_DESCRIPTION+ "\"," + //25
'"' + CatalogueDBAdapter.KEY_GENRE+ "\"," + //26
+ '"' + CatalogueDBAdapter.KEY_ISBN2 + "\"," + //27
"\n");
long lastUpdate = 0;
@@ -184,6 +185,7 @@ public class ExportThread extends ManagedTask {
row.append("\"" + formatCell(anthology_titles) + "\",");
row.append("\"" + formatCell(books.getString(books.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_DESCRIPTION))) + "\",");
row.append("\"" + formatCell(books.getString(books.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_GENRE))) + "\",");
+ row.append("\"" + formatCell(books.getString(books.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_ISBN2))) + "\",");
row.append("\n");
export.append(row);
diff --git a/src/com/eleybourn/bookcatalogue/FieldVisibility.java b/src/com/eleybourn/bookcatalogue/FieldVisibility.java
index 3ac05c7..08003bc 100644
--- a/src/com/eleybourn/bookcatalogue/FieldVisibility.java
+++ b/src/com/eleybourn/bookcatalogue/FieldVisibility.java
@@ -61,19 +61,19 @@ public class FieldVisibility extends Activity {
public void setupFields() {
// The fields to show/hide
String[] fields = {CatalogueDBAdapter.KEY_AUTHOR_ID, CatalogueDBAdapter.KEY_TITLE, "thumbnail",
- CatalogueDBAdapter.KEY_ISBN, CatalogueDBAdapter.KEY_SERIES_NAME, CatalogueDBAdapter.KEY_SERIES_NUM,
+ CatalogueDBAdapter.KEY_ISBN, CatalogueDBAdapter.KEY_ISBN2, CatalogueDBAdapter.KEY_SERIES_NAME, CatalogueDBAdapter.KEY_SERIES_NUM,
CatalogueDBAdapter.KEY_PUBLISHER, CatalogueDBAdapter.KEY_DATE_PUBLISHED, CatalogueDBAdapter.KEY_BOOKSHELF,
CatalogueDBAdapter.KEY_PAGES, CatalogueDBAdapter.KEY_LIST_PRICE, CatalogueDBAdapter.KEY_READ,
CatalogueDBAdapter.KEY_RATING, CatalogueDBAdapter.KEY_NOTES, CatalogueDBAdapter.KEY_ANTHOLOGY,
CatalogueDBAdapter.KEY_LOCATION, CatalogueDBAdapter.KEY_READ_START, CatalogueDBAdapter.KEY_READ_END,
CatalogueDBAdapter.KEY_FORMAT, CatalogueDBAdapter.KEY_SIGNED, CatalogueDBAdapter.KEY_DESCRIPTION,
CatalogueDBAdapter.KEY_GENRE};
- int[] fieldRs = {R.string.author, R.string.title, R.string.thumbnail, R.string.isbn, R.string.series, R.string.series_num,
+ int[] fieldRs = {R.string.author, R.string.title, R.string.thumbnail, R.string.isbn, R.string.isbn2, R.string.series, R.string.series_num,
R.string.publisher, R.string.date_published, R.string.bookshelf, R.string.pages, R.string.list_price,
R.string.read, R.string.rating, R.string.notes, R.string.anthology, R.string.location,
R.string.read_start, R.string.read_end, R.string.format, R.string.signed, R.string.description,
R.string.genre};
- boolean[] compulsory = {true, true, false, false, false, false, false, false,
+ boolean[] compulsory = {true, true, false, false, false, false, false, false, false,
true, false, false, false, false, false, false, false, false, false, false, false, false, false};
SharedPreferences mPrefs = getSharedPreferences("bookCatalogue", MODE_PRIVATE);
--
1.7.0.4
0002-Search-own-books-with-Barcode.patch
From 379e73c2b481d92a434fb9fddccfa3bd387aa828 Mon Sep 17 00:00:00 2001
From: Jam <jam@jam.org>
Date: Sat, 12 Mar 2011 20:28:58 +0200
Subject: [PATCH 2/4] Search (own books) with Barcode
Simple way to check if you already have that book/magazine/...
Signed-off-by: Jam <jam@jam.org>
---
AndroidManifest.xml | 1 +
res/values/strings.xml | 2 +
.../eleybourn/bookcatalogue/BookBarcodeSearch.java | 74 ++++++++++++++++++++
src/com/eleybourn/bookcatalogue/BookCatalogue.java | 31 ++++++--
4 files changed, 101 insertions(+), 7 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e93547c..13819ec 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -18,6 +18,7 @@
</activity>
<activity android:name=".BookEdit"></activity>
<activity android:name=".BookISBNSearch" android:label="@string/title_isbn_search"></activity>
+ <activity android:name=".BookBarcodeSearch" android:label="@string/title_barcode_search"></activity>
<activity android:name=".Bookshelf" android:label="@string/title_manage_bs"></activity>
<activity android:name=".BookshelfEdit" android:label="@string/title_edit_bs"></activity>
<activity android:name=".Administration" android:label="@string/administration_title"></activity>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e31a434..fde45bc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -39,6 +39,7 @@
<string name="all_books">All Books</string>
<string name="isbn_found">ISBN Scanned. Searching Internet.</string>
<string name="title_isbn_search">Book Catalogue: ISBN Search</string>
+<string name="title_barcode_search">Book Catalogue: Barcode Search</string>
<string name="title_manage_bs">Book Catalogue: Manage Bookshelves</string>
<string name="title_edit_bs">Book Catalogue: Edit Bookshelf</string>
<string name="book_exists">The book you are trying to add already exists. .</string>
@@ -153,6 +154,7 @@
<string name="auto_update">Would you like to automatically update the following fields now \n* Genre \n* Description \n* Thumbnails\n\n If you select Cancel you can always run this again from the Administration page</string>
<string name="notset">Not Set</string>
<string name="menu_search">Search Books</string>
+<string name="menu_search_barcode">Search with Barcode</string>
<string name="menu_insert_name">Add by Name</string>
<string name="isbn_name_search_help">Adding books by ISBN is much more accurate than adding by author and title and is generally preferred. Please remember you can sometimes find the correct barcode on the inside front cover. \n\n</string>
<string name="help_click_here">Please click here to access the online help pages</string>
diff --git a/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
index c484ede..4367807 100644
--- a/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
+++ b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
@@ -107,6 +107,25 @@ public class BookBarcodeSearch extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch(requestCode) {
+ case ACTIVITY_SCAN:
+ try {
+ if (resultCode == RESULT_OK) {
+ // Scanner returned an Barcode...process it.
+ String contents = intent.getStringExtra("SCAN_RESULT");
+ go(contents);
+ } else {
+ // Scanner Cancelled/failed. Exit if no dialog present.
+ if (mLastBookIntent != null)
+ this.setResult(RESULT_OK, mLastBookIntent);
+ else
+ this.setResult(RESULT_CANCELED, mLastBookIntent);
+ if (!mDisplayingAlert)
+ finish();
+ }
+ } catch (NullPointerException e) {
+ finish();
+ }
+ break;
case ACTIVITY_BARCODE2:
String contents = intent.getStringExtra("SCAN_RESULT");
Toast.makeText(this, contents, Toast.LENGTH_LONG).show();
@@ -115,6 +134,61 @@ public class BookBarcodeSearch extends Activity {
break;
}
}
+
+ protected ArrayList<String> getInfo(Cursor info_cur) {
+ ArrayList<String> info_list = new ArrayList<String>();
+ startManagingCursor(info_cur);
+ while (info_cur.moveToNext()) {
+ String author = info_cur.getString(info_cur.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_AUTHOR_FORMATTED));
+ String title = info_cur.getString(info_cur.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_TITLE));
+ String series = info_cur.getString(info_cur.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_SERIES_FORMATTED));
+ String publisher = info_cur.getString(info_cur.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_PUBLISHER));
+ String info = "";
+ if (author.length() > 3)
+ info += author;
+ if (title.length() > 2) {
+ if (info.length() > 3)
+ info += ": ";
+ info += title;
+ }
+ if (info.length() < 40 && series.length() > 1)
+ info += " (" + series + ")";
+ if (info.length() < 40 && publisher.length() > 1)
+ info += " (" + publisher + ")";
+ info_list.add(info);
+ }
+ info_cur.close();
+ return info_list;
+ }
+
+ protected void go(String isbn) {
+ try {
+ if (!isbn.equals("")) {
+ /*Cursor book = mDbHelper.fetchBookByISBN(isbn);
+ int rows = book.getCount();
+
+ if (rows != 0) {
+ String info = isbn + ":\n";
+ for(String f: getInfo(book)) {
+ info += f;
+ }
+ Toast.makeText(this, info, Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(this, R.string.book_not_found, Toast.LENGTH_LONG).show();
+ }*/
+
+ if (mDbHelper.checkIsbnExists(isbn))
+ Toast.makeText(this, "Book Found!", Toast.LENGTH_LONG).show();
+ else
+ Toast.makeText(this, R.string.book_not_found, Toast.LENGTH_LONG).show();
+
+ startScannerActivity(ACTIVITY_SCAN);
+ //book.close(); //close the cursor
+ }
+ } catch (Exception e) {
+ //do nothing
+ }
+ }
/*
* Start scanner activity.
diff --git a/src/com/eleybourn/bookcatalogue/BookCatalogue.java b/src/com/eleybourn/bookcatalogue/BookCatalogue.java
index 23c818e..786f329 100644
--- a/src/com/eleybourn/bookcatalogue/BookCatalogue.java
+++ b/src/com/eleybourn/bookcatalogue/BookCatalogue.java
@@ -79,8 +79,9 @@ public class BookCatalogue extends ExpandableListActivity {
private static final int ACTIVITY_SORT=2;
private static final int ACTIVITY_ISBN=3;
private static final int ACTIVITY_SCAN=4;
- private static final int ACTIVITY_ADMIN=5;
- private static final int ACTIVITY_ADMIN_FINISH=6;
+ private static final int ACTIVITY_BARCODE=5;
+ private static final int ACTIVITY_ADMIN=6;
+ private static final int ACTIVITY_ADMIN_FINISH=7;
private CatalogueDBAdapter mDbHelper;
private int mGroupIdColumnIndex;
@@ -96,11 +97,12 @@ public class BookCatalogue extends ExpandableListActivity {
private static final int EDIT_BOOK_NOTES = Menu.FIRST + 11;
private static final int EDIT_BOOK_FRIENDS = Menu.FIRST + 12;
private static final int SEARCH = Menu.FIRST + 13;
- private static final int INSERT_NAME_ID = Menu.FIRST + 14;
+ private static final int SEARCH_BARCODE = Menu.FIRST + 14;
+ private static final int INSERT_NAME_ID = Menu.FIRST + 15;
- private static final int DELETE_SERIES_ID = Menu.FIRST + 15;
- private static final int EDIT_AUTHOR_ID = Menu.FIRST + 16;
- private static final int EDIT_SERIES_ID = Menu.FIRST + 17;
+ private static final int DELETE_SERIES_ID = Menu.FIRST + 16;
+ private static final int EDIT_AUTHOR_ID = Menu.FIRST + 17;
+ private static final int EDIT_SERIES_ID = Menu.FIRST + 18;
public static String bookshelf = "All Books";
private ArrayAdapter<String> spinnerAdapter;
@@ -446,7 +448,7 @@ public class BookCatalogue extends ExpandableListActivity {
protected String[] mFrom = null; // Source fields for top level resource
protected String[] mChildFrom = null; // Source fields for child
protected int[] mTo = null; // Dest field resource IDs for top level
- protected int[] mChildTo = null; // Dest field resourrce IDs for child
+ protected int[] mChildTo = null; // Dest field resource IDs for child
// Methods to 'get' list/view related items
public int getLayout() { return mLayout; };
public int getLayoutChild() { return mChildLayout; };
@@ -868,6 +870,9 @@ public class BookCatalogue extends ExpandableListActivity {
MenuItem search = menu.add(0, SEARCH, 4, R.string.menu_search);
search.setIcon(android.R.drawable.ic_menu_search);
+ MenuItem searchBC = menu.add(0, SEARCH_BARCODE, 4, R.string.menu_search_barcode);
+ search.setIcon(android.R.drawable.ic_menu_search);
+
return super.onPrepareOptionsMenu(menu);
}
@@ -902,6 +907,9 @@ public class BookCatalogue extends ExpandableListActivity {
case SEARCH:
onSearchRequested();
return true;
+ case SEARCH_BARCODE:
+ createBarcodeScan();
+ return true;
case INSERT_NAME_ID:
createBookISBN("name");
return true;
@@ -1309,6 +1317,15 @@ public class BookCatalogue extends ExpandableListActivity {
startActivityForResult(i, ACTIVITY_ISBN);
}
+ /**
+ * Load the Search local books (by ISBN) Activity to begin scanning.
+ */
+ private void createBarcodeScan() {
+ Intent i = new Intent(this, BookBarcodeSearch.class);
+ i.putExtra(BookBarcodeSearch.BY, "scan");
+ startActivityForResult(i, ACTIVITY_BARCODE);
+ }
+
@Override
public boolean onChildClick(ExpandableListView l, View v, int position, int childPosition, long id) {
boolean result = super.onChildClick(l, v, position, childPosition, id);
--
1.7.0.4
0003-make-fetchBookByISBN.patch
From 94e7815d6bf70fbcd03dd98b70c328c46234c7b6 Mon Sep 17 00:00:00 2001
From: Jam <jam@jam.org>
Date: Wed, 9 Mar 2011 23:50:56 +0200
Subject: [PATCH 3/4] make fetchBookByISBN
Signed-off-by: Jam <jam@jam.org>
---
.../eleybourn/bookcatalogue/BookBarcodeSearch.java | 8 ++++----
.../bookcatalogue/CatalogueDBAdapter.java | 8 +++++++-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
index 4367807..8df7a39 100644
--- a/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
+++ b/src/com/eleybourn/bookcatalogue/BookBarcodeSearch.java
@@ -164,7 +164,7 @@ public class BookBarcodeSearch extends Activity {
protected void go(String isbn) {
try {
if (!isbn.equals("")) {
- /*Cursor book = mDbHelper.fetchBookByISBN(isbn);
+ Cursor book = mDbHelper.fetchBookByISBN(isbn);
int rows = book.getCount();
if (rows != 0) {
@@ -175,12 +175,12 @@ public class BookBarcodeSearch extends Activity {
Toast.makeText(this, info, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, R.string.book_not_found, Toast.LENGTH_LONG).show();
- }*/
+ }
- if (mDbHelper.checkIsbnExists(isbn))
+ /*if (mDbHelper.checkIsbnExists(isbn))
Toast.makeText(this, "Book Found!", Toast.LENGTH_LONG).show();
else
- Toast.makeText(this, R.string.book_not_found, Toast.LENGTH_LONG).show();
+ Toast.makeText(this, R.string.book_not_found, Toast.LENGTH_LONG).show();*/
startScannerActivity(ACTIVITY_SCAN);
//book.close(); //close the cursor
diff --git a/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java b/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
index 81d91cb..e9a6900 100644
--- a/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
+++ b/src/com/eleybourn/bookcatalogue/CatalogueDBAdapter.java
@@ -1887,7 +1887,13 @@ public class CatalogueDBAdapter {
mCheckIsbnExistsStmt.bindString(2, isbn);
return mCheckIsbnExistsStmt.simpleQueryForLong() > 0;
}
-
+
+ public Cursor fetchBookByISBN(String isbn) {
+ String bookWhere = makeTextTerm("b." + KEY_ISBN, "=", isbn) +
+ " OR " + makeTextTerm("b." + KEY_ISBN2, "=", isbn);
+ return fetchAllBooks("", "All Books", "", bookWhere, "", "", "" );
+ }
+
/**
*
* @param family Family name of author
--
1.7.0.4
0004-Allow-Book-Add-Without-Match.patch
From 23baa4b8b75596e7061c48fedd76b737adc2772e Mon Sep 17 00:00:00 2001
From: Jam <jam@jam.org>
Date: Thu, 10 Mar 2011 00:21:06 +0200
Subject: [PATCH 4/4] Allow book-add without match
Signed-off-by: Jam <jam@jam.org>
---
.../eleybourn/bookcatalogue/BookEditFields.java | 4 ++++
src/com/eleybourn/bookcatalogue/SearchManager.java | 3 ++-
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/com/eleybourn/bookcatalogue/BookEditFields.java b/src/com/eleybourn/bookcatalogue/BookEditFields.java
index 7167787..3897b89 100644
--- a/src/com/eleybourn/bookcatalogue/BookEditFields.java
+++ b/src/com/eleybourn/bookcatalogue/BookEditFields.java
@@ -732,6 +732,10 @@ public class BookEditFields extends Activity {
mAuthorList = values.getParcelableArrayList(CatalogueDBAdapter.KEY_AUTHOR_ARRAY);
mSeriesList = values.getParcelableArrayList(CatalogueDBAdapter.KEY_SERIES_ARRAY);
+ if (mAuthorList == null)
+ mAuthorList = new ArrayList<Author>();
+ if (mSeriesList == null)
+ mSeriesList = new ArrayList<Series>();
}
diff --git a/src/com/eleybourn/bookcatalogue/SearchManager.java b/src/com/eleybourn/bookcatalogue/SearchManager.java
index 8004e21..6bfd138 100644
--- a/src/com/eleybourn/bookcatalogue/SearchManager.java
+++ b/src/com/eleybourn/bookcatalogue/SearchManager.java
@@ -190,6 +190,7 @@ public class SearchManager implements OnTaskEndedListener {
mIsbn = isbn;
mFetchThumbnail = fetchThumbnail;
+ mBookData.putString(CatalogueDBAdapter.KEY_ISBN, isbn);
if (mTaskManager.runningInUiThread()) {
doSearch();
} else {
@@ -289,7 +290,7 @@ public class SearchManager implements OnTaskEndedListener {
if (authors == null || authors.length() == 0 || title == null || title.length() == 0) {
mTaskManager.doToast(mTaskManager.getString(R.string.book_not_found));
- mBookData = null;
+ //mBookData = null;
if (mSearchHandler != null)
mSearchHandler.onSearchFinished(mBookData, mCancelledFlg);
--
1.7.0.4
Just a first reaction, nothing reallly concrete, but I'm not sure I understand what ISBN2 is; if it is an ASIN we should not really use it because ASIN varies by site (from what I read, Amazon.uk can have different ASINs for the same ISBN). If it is an ISBN10/ISBN13, then we just need a generator for each of these so we can use them interchangeably (for the 978 based ISBN13's, there is a transformation, 979s may not have one). If it is some other code, we need to understand what it is then decide what to do about it.
In terms of detecting duplicate books, we effectively already have this (though it would benefit from ISBN10<->ISBN13 translation). If you scan an an existing ISBN, you get an immediate warning.
If this is a means to support some other user-defined (or local) barcode (eg. the Dana numbers), we should look at a more generic approach... perhaps part of the user-defined additional fields.
Closed due to lack of activity
Via email from Jam
I have added couple things to your book catalogue-program. I don't want to do account to github, so I decided to email those to you.
There is 2 main things; add additional field (for barcode/isbn) and searching with barcode. Currently scanning functionality is in own file, but I should be merged with existing scan (bookisbnsearch). Some books I have, have different number is it's barcode than what actually is it's ISBN-number. Also some books have also second barcode (product-code?).
Searching with barcode is quite simple addition, but it could be combined (and also expand functionality) with "Add by Barcode". I added a small patch to isbn scan layout to show what I was thinking.
I don't have much free time, so I don't know when/if I do more to BC, so I decided to send (atleast) this version to you. Have fun and thanks doing this fine application.