am feb2b3d9: Change date storage in DB to be a ms timestamp integral value. Add a basic CursorAdapter to add more flexibility to views in list. Create custom listview item that is pretty much the same, except with a relative time string.
Merge commit 'feb2b3d9b02d7fd008bea09d14f175d848a62226' into gingerbread-plus-aosp * commit 'feb2b3d9b02d7fd008bea09d14f175d848a62226': Change date storage in DB to be a ms timestamp integral value.
This commit is contained in:
40
apps/Tag/res/layout/tag_list_item.xml
Normal file
40
apps/Tag/res/layout/tag_list_item.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="4dip"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:padding="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
android:padding="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
43
apps/Tag/src/com/android/apps/tag/TagCursorAdapter.java
Normal file
43
apps/Tag/src/com/android/apps/tag/TagCursorAdapter.java
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
|
||||
package com.android.apps.tag;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A custom {@link Adapter} that renders tag entries for a list.
|
||||
*/
|
||||
public class TagCursorAdapter extends CursorAdapter {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public TagCursorAdapter(Context context, Cursor c) {
|
||||
super(context, c);
|
||||
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
TextView mainLine = (TextView) view.findViewById(R.id.title);
|
||||
TextView dateLine = (TextView) view.findViewById(R.id.date);
|
||||
|
||||
// TODO(benkomalo): either write a cursor abstraction, or use constants for column indices.
|
||||
mainLine.setText(cursor.getString(cursor.getColumnIndex("bytes")));
|
||||
dateLine.setText(DateUtils.getRelativeTimeSpanString(
|
||||
context, cursor.getLong(cursor.getColumnIndex("date"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return mInflater.inflate(R.layout.tag_list_item, null);
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,14 @@
|
||||
package com.android.apps.tag;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
import android.nfc.FormatException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
import android.nfc.FormatException;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
@@ -39,7 +39,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
|
||||
private static final String NDEF_MSG = "create table NdefMessage ("
|
||||
+ "_id INTEGER NOT NULL, "
|
||||
+ "bytes BLOB NOT NULL, "
|
||||
+ "date TEXT NOT NULL, "
|
||||
+ "date INTEGER NOT NULL, "
|
||||
+ "saved TEXT NOT NULL default 0," // boolean
|
||||
+ "PRIMARY KEY(_id)"
|
||||
+ ")";
|
||||
@@ -154,7 +154,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
|
||||
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());
|
||||
stmt.bindLong(2, System.currentTimeMillis());
|
||||
String isSavedStr = isSaved ? "1" : "0";
|
||||
stmt.bindString(3, isSavedStr);
|
||||
stmt.executeInsert();
|
||||
|
||||
@@ -43,19 +43,15 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
|
||||
boolean showSavedOnly = getIntent().getBooleanExtra(SHOW_SAVED_ONLY, false);
|
||||
db = new TagDBHelper(getBaseContext()).getReadableDatabase();
|
||||
String selection = showSavedOnly ? "saved=1" : null;
|
||||
|
||||
// TODO: Use an AsyncQueryHandler so that DB queries are not done on UI thread.
|
||||
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,
|
||||
cursor,
|
||||
new String[] { "bytes", "date" },
|
||||
new int[] { android.R.id.text1, android.R.id.text2 });
|
||||
|
||||
setListAdapter(sca);
|
||||
setListAdapter(new TagCursorAdapter(this, cursor));
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user