Add initial support for saved vs non-saved tags.

Get rid of the third "MyTag" column.  This isn't currently
being used.

Change-Id: Id35074d939e1373f0998e5502eb9cfc9c86ecca5
This commit is contained in:
Nick Kralevich
2010-10-11 17:52:43 -07:00
parent dbb9a2fd92
commit 21995b1888
3 changed files with 14 additions and 17 deletions

View File

@@ -39,11 +39,12 @@ public class TagDBHelper extends SQLiteOpenHelper {
+ "_id INTEGER NOT NULL, "
+ "bytes BLOB NOT NULL, "
+ "date TEXT NOT NULL, "
+ "saved TEXT NOT NULL default 0," // boolean
+ "PRIMARY KEY(_id)"
+ ")";
private static final String INSERT =
"INSERT INTO NdefMessage (bytes, date) values (?, ?)";
"INSERT INTO NdefMessage (bytes, date, saved) values (?, ?, ?)";
private static final byte[] REAL_NFC_MSG = new byte[] {
(byte) 0xd1,
@@ -120,22 +121,24 @@ public class TagDBHelper extends SQLiteOpenHelper {
NdefUtil.toUriRecord(URI.create("http://www.android.com"))
});
insert(db, msg1);
insert(db, msg2);
insert(db, msg1, false);
insert(db, msg2, true);
try {
// A real message obtained from an NFC Forum Type 4 tag.
NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG);
insert(db, msg3);
insert(db, msg3, false);
} catch (NfcException e) {
throw new RuntimeException(e);
}
}
private void insert(SQLiteDatabase db, NdefMessage msg) {
private void insert(SQLiteDatabase db, NdefMessage msg, boolean isSaved) {
SQLiteStatement stmt = db.compileStatement(INSERT);
stmt.bindString(1, new String(msg.toByteArray())); // TODO: This should be a blob
stmt.bindString(2, new Date().toString());
String isSavedStr = isSaved ? "1" : "0";
stmt.bindString(3, isSavedStr);
stmt.executeInsert();
stmt.close();
}

View File

@@ -27,7 +27,6 @@ import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
/**
* @author nnk@google.com (Nick Kralevich)
@@ -36,13 +35,16 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
private SQLiteDatabase db;
private Cursor cursor;
static final String SHOW_SAVED_ONLY = "show_saved_only";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(getBaseContext(), "entered method", Toast.LENGTH_SHORT).show();
boolean showSavedOnly = getIntent().getBooleanExtra(SHOW_SAVED_ONLY, false);
db = new TagDBHelper(getBaseContext()).getReadableDatabase();
cursor = db.query("NdefMessage", new String[] { "_id", "bytes", "date" }, null, null, null, null, null);
String selection = showSavedOnly ? "saved=1" : null;
cursor = db.query("NdefMessage", new String[] { "_id", "bytes", "date" }, selection, null, null, null, null);
SimpleCursorAdapter sca =
new SimpleCursorAdapter(this,
android.R.layout.two_line_list_item,
@@ -52,7 +54,6 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
setListAdapter(sca);
registerForContextMenu(getListView());
Toast.makeText(getBaseContext(), "exit method", Toast.LENGTH_SHORT).show();
}
@Override

View File

@@ -42,9 +42,8 @@ public class Tags extends TabActivity {
TabHost tabHost = getTabHost();
Intent i = new Intent().setClass(this, TagList.class);
Intent iSavedList = new Intent().setClass(this, TagList.class);
Intent iSavedList = new Intent().setClass(this, TagList.class).putExtra(TagList.SHOW_SAVED_ONLY, true);
Intent iRecentList = new Intent().setClass(this, TagList.class);
Intent iMyTagList = new Intent().setClass(this, TagList.class);
TabHost.TabSpec spec1 = tabHost.newTabSpec("1")
@@ -56,12 +55,6 @@ public class Tags extends TabActivity {
.setIndicator("Recent", res.getDrawable(R.drawable.ic_tab_artists))
.setContent(iRecentList);
tabHost.addTab(spec2);
TabHost.TabSpec spec3 = tabHost.newTabSpec("3")
.setIndicator("My Tag", res.getDrawable(R.drawable.ic_tab_artists))
.setContent(iMyTagList);
tabHost.addTab(spec3);
}
}