Merge branch 'gingerbread' into gingerbread-release

This commit is contained in:
The Android Automerger
2010-10-13 18:49:54 -07:00
14 changed files with 158 additions and 60 deletions

View 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>

View File

@@ -22,8 +22,8 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.trustedlogic.trustednfc.android.NdefMessage; import android.nfc.NdefMessage;
import com.trustedlogic.trustednfc.android.NdefRecord; import android.nfc.NdefRecord;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
@@ -105,8 +105,8 @@ public class NdefUtil {
*/ */
byte[] payload = Bytes.concat(new byte[] { 0x00 }, uriBytes); byte[] payload = Bytes.concat(new byte[] { 0x00 }, uriBytes);
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN_TYPE, return new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
NdefRecord.TYPE_URI, EMPTY, payload); NdefRecord.RTD_URI, EMPTY, payload);
} }
/** /**
@@ -122,8 +122,8 @@ public class NdefUtil {
* record containing a URI. * record containing a URI.
*/ */
public static URI toURI(NdefRecord record) throws URISyntaxException { public static URI toURI(NdefRecord record) throws URISyntaxException {
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE); Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_URI)); Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
byte[] payload = record.getPayload(); byte[] payload = record.getPayload();
@@ -161,8 +161,8 @@ public class NdefUtil {
* @return text payload. * @return text payload.
*/ */
public static String toText(NdefRecord record) { public static String toText(NdefRecord record) {
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE); Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_TEXT)); Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_TEXT));
try { try {
byte[] payload = record.getPayload(); byte[] payload = record.getPayload();

View File

@@ -16,13 +16,13 @@
package com.android.apps.tag; package com.android.apps.tag;
import com.trustedlogic.trustednfc.android.NdefMessage;
import com.trustedlogic.trustednfc.android.NfcManager;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.nfc.NdefMessage;
import android.nfc.NdefTag;
import android.nfc.NfcAdapter;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.WindowManager; import android.view.WindowManager;
@@ -32,6 +32,7 @@ import android.widget.Toast;
* An {@code Activity} which handles a broadcast of a new tag that the device just discovered. * An {@code Activity} which handles a broadcast of a new tag that the device just discovered.
*/ */
public class SaveTag extends Activity implements DialogInterface.OnClickListener { public class SaveTag extends Activity implements DialogInterface.OnClickListener {
private static final String TAG = "SaveTag";
@Override @Override
protected void onStart() { protected void onStart() {
@@ -46,9 +47,17 @@ public class SaveTag extends Activity implements DialogInterface.OnClickListener
); );
showDialog(1); showDialog(1);
NdefMessage msg = getIntent().getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA); NdefTag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefMessage[] msgs = tag.getNdefMessages();
String s = toHexString(msg.toByteArray()); if (msgs.length == 0) {
Log.d(TAG, "No NDEF messages");
return;
}
if (msgs.length > 1) {
Log.d(TAG, "Multiple NDEF messages, only saving first");
}
String s = toHexString(msgs[0].toByteArray());
Log.d("SaveTag", s); Log.d("SaveTag", s);
Toast.makeText(this.getBaseContext(), "SaveTag: " + s, Toast.LENGTH_SHORT).show(); Toast.makeText(this.getBaseContext(), "SaveTag: " + s, Toast.LENGTH_SHORT).show();
} }

View File

@@ -18,9 +18,9 @@ package com.android.apps.tag;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.trustedlogic.trustednfc.android.NdefMessage; import android.nfc.NdefMessage;
import com.trustedlogic.trustednfc.android.NdefRecord; import android.nfc.NdefRecord;
import com.trustedlogic.trustednfc.android.NfcException; import android.nfc.FormatException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.net.URI; import java.net.URI;
@@ -67,8 +67,8 @@ public class SmartPoster {
} }
public static SmartPoster from(NdefRecord record) { public static SmartPoster from(NdefRecord record) {
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE); Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_SMART_POSTER)); Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_SMART_POSTER));
try { try {
NdefMessage subRecords = new NdefMessage(record.getPayload()); NdefMessage subRecords = new NdefMessage(record.getPayload());
URI uri = Iterables.getOnlyElement(NdefUtil.getURIs(subRecords)); URI uri = Iterables.getOnlyElement(NdefUtil.getURIs(subRecords));
@@ -79,7 +79,7 @@ public class SmartPoster {
} }
return new SmartPoster(uri, title); return new SmartPoster(uri, title);
} catch (NfcException e) { } catch (FormatException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
} }

View File

@@ -19,8 +19,10 @@ package com.android.apps.tag;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.trustedlogic.trustednfc.android.NdefMessage; import android.nfc.NdefTag;
import com.trustedlogic.trustednfc.android.NfcManager;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
/** /**
* When we receive a new NDEF tag, start the activity to * When we receive a new NDEF tag, start the activity to
@@ -30,10 +32,10 @@ public class TagBroadcastReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) { if (intent.getAction().equals(NfcAdapter.ACTION_NDEF_TAG_DISCOVERED)) {
NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA); NdefTag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Intent i = new Intent(context, SaveTag.class) Intent i = new Intent(context, SaveTag.class)
.putExtra(NfcManager.NDEF_MESSAGE_EXTRA, msg) .putExtra(NfcAdapter.EXTRA_TAG, tag)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i); context.startActivity(i);
} }

View 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);
}
}

View File

@@ -17,14 +17,14 @@
package com.android.apps.tag; package com.android.apps.tag;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.trustedlogic.trustednfc.android.NdefMessage;
import com.trustedlogic.trustednfc.android.NdefRecord;
import com.trustedlogic.trustednfc.android.NfcException;
import android.content.Context; import android.content.Context;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import java.net.URI; import java.net.URI;
import java.util.Date; import java.util.Date;
@@ -39,7 +39,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
private static final String NDEF_MSG = "create table NdefMessage (" private static final String NDEF_MSG = "create table NdefMessage ("
+ "_id INTEGER NOT NULL, " + "_id INTEGER NOT NULL, "
+ "bytes BLOB NOT NULL, " + "bytes BLOB NOT NULL, "
+ "date TEXT NOT NULL, " + "date INTEGER NOT NULL, "
+ "saved TEXT NOT NULL default 0," // boolean + "saved TEXT NOT NULL default 0," // boolean
+ "PRIMARY KEY(_id)" + "PRIMARY KEY(_id)"
+ ")"; + ")";
@@ -146,7 +146,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
// A real message obtained from an NFC Forum Type 4 tag. // A real message obtained from an NFC Forum Type 4 tag.
NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG); NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG);
insert(db, msg3, false); insert(db, msg3, false);
} catch (NfcException e) { } catch (FormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -154,7 +154,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
private void insert(SQLiteDatabase db, NdefMessage msg, boolean isSaved) { private void insert(SQLiteDatabase db, NdefMessage msg, boolean isSaved) {
SQLiteStatement stmt = db.compileStatement(INSERT); SQLiteStatement stmt = db.compileStatement(INSERT);
stmt.bindString(1, new String(msg.toByteArray())); // TODO: This should be a blob 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"; String isSavedStr = isSaved ? "1" : "0";
stmt.bindString(3, isSavedStr); stmt.bindString(3, isSavedStr);
stmt.executeInsert(); stmt.executeInsert();

View File

@@ -43,19 +43,15 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
boolean showSavedOnly = getIntent().getBooleanExtra(SHOW_SAVED_ONLY, false); boolean showSavedOnly = getIntent().getBooleanExtra(SHOW_SAVED_ONLY, false);
db = new TagDBHelper(getBaseContext()).getReadableDatabase(); db = new TagDBHelper(getBaseContext()).getReadableDatabase();
String selection = showSavedOnly ? "saved=1" : null; String selection = showSavedOnly ? "saved=1" : null;
// TODO: Use an AsyncQueryHandler so that DB queries are not done on UI thread.
cursor = db.query( cursor = db.query(
"NdefMessage", "NdefMessage",
new String[] { "_id", "bytes", "date" }, new String[] { "_id", "bytes", "date" },
selection, selection,
null, null, null, null); 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()); registerForContextMenu(getListView());
} }

View File

@@ -18,7 +18,7 @@ package com.android.apps.tag;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.trustedlogic.trustednfc.android.NdefRecord; import android.nfc.NdefRecord;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@@ -45,7 +45,7 @@ public class NdefUtilTest extends AndroidTestCase {
text text
); );
NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN_TYPE, NdefRecord.TYPE_TEXT, new byte[0], data); NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);
assertEquals(word, NdefUtil.toText(record)); assertEquals(word, NdefUtil.toText(record));
} }
} }

View File

@@ -17,7 +17,7 @@
package com.android.apps.tag; package com.android.apps.tag;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import com.trustedlogic.trustednfc.android.NdefMessage; import android.nfc.NdefMessage;
/** /**
* Tests for {@link SmartPoster}. * Tests for {@link SmartPoster}.

View File

@@ -140,33 +140,36 @@ frameworks/base/docs/docs-samples-redirect.html docs/samples/index.html
# #
# the list here should match the list of samples that we generate docs for, # the list here should match the list of samples that we generate docs for,
# (see web_docs_sample_code_flags in frameworks/base/Android.mk) # (see web_docs_sample_code_flags in frameworks/base/Android.mk)
development/samples/source.properties samples/${PLATFORM_NAME}/source.properties
development/apps/GestureBuilder samples/${PLATFORM_NAME}/GestureBuilder development/apps/GestureBuilder samples/${PLATFORM_NAME}/GestureBuilder
development/samples/source.properties samples/${PLATFORM_NAME}/source.properties
#
# PLEASE KEEP THE SAMPLES IN ALPHABETICAL ORDER.
#
development/samples/AccessibilityService samples/${PLATFORM_NAME}/AccessibilityService development/samples/AccessibilityService samples/${PLATFORM_NAME}/AccessibilityService
development/samples/BluetoothChat samples/${PLATFORM_NAME}/BluetoothChat
development/samples/Home samples/${PLATFORM_NAME}/Home
development/samples/LunarLander samples/${PLATFORM_NAME}/LunarLander
development/samples/NotePad samples/${PLATFORM_NAME}/NotePad
development/samples/ApiDemos samples/${PLATFORM_NAME}/ApiDemos development/samples/ApiDemos samples/${PLATFORM_NAME}/ApiDemos
development/samples/BackupRestore samples/${PLATFORM_NAME}/BackupRestore development/samples/BackupRestore samples/${PLATFORM_NAME}/BackupRestore
development/samples/BluetoothChat samples/${PLATFORM_NAME}/BluetoothChat
development/samples/ContactManager samples/${PLATFORM_NAME}/ContactManager
development/samples/CrossCompatibility samples/${PLATFORM_NAME}/CrossCompatibility
development/samples/CubeLiveWallpaper samples/${PLATFORM_NAME}/CubeLiveWallpaper
development/samples/HeavyWeight samples/${PLATFORM_NAME}/HeavyWeight development/samples/HeavyWeight samples/${PLATFORM_NAME}/HeavyWeight
development/samples/Home samples/${PLATFORM_NAME}/Home
development/samples/JetBoy samples/${PLATFORM_NAME}/JetBoy
development/samples/LunarLander samples/${PLATFORM_NAME}/LunarLander
development/samples/MultiResolution samples/${PLATFORM_NAME}/MultiResolution
development/samples/NotePad samples/${PLATFORM_NAME}/NotePad
development/samples/SampleSyncAdapter samples/${PLATFORM_NAME}/SampleSyncAdapter development/samples/SampleSyncAdapter samples/${PLATFORM_NAME}/SampleSyncAdapter
development/samples/SearchableDictionary samples/${PLATFORM_NAME}/SearchableDictionary
development/samples/SkeletonApp samples/${PLATFORM_NAME}/SkeletonApp development/samples/SkeletonApp samples/${PLATFORM_NAME}/SkeletonApp
development/samples/Snake samples/${PLATFORM_NAME}/Snake development/samples/Snake samples/${PLATFORM_NAME}/Snake
development/samples/SoftKeyboard samples/${PLATFORM_NAME}/SoftKeyboard development/samples/SoftKeyboard samples/${PLATFORM_NAME}/SoftKeyboard
development/samples/JetBoy samples/${PLATFORM_NAME}/JetBoy
development/samples/SearchableDictionary samples/${PLATFORM_NAME}/SearchableDictionary
development/samples/Spinner samples/${PLATFORM_NAME}/Spinner development/samples/Spinner samples/${PLATFORM_NAME}/Spinner
development/samples/SpinnerTest samples/${PLATFORM_NAME}/SpinnerTest development/samples/SpinnerTest samples/${PLATFORM_NAME}/SpinnerTest
development/samples/ContactManager samples/${PLATFORM_NAME}/ContactManager
development/samples/MultiResolution samples/${PLATFORM_NAME}/MultiResolution
development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary
development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple
development/samples/CubeLiveWallpaper samples/${PLATFORM_NAME}/CubeLiveWallpaper
development/samples/VoiceRecognitionService samples/${PLATFORM_NAME}/VoiceRecognitionService
development/samples/TicTacToeLib samples/${PLATFORM_NAME}/TicTacToeLib development/samples/TicTacToeLib samples/${PLATFORM_NAME}/TicTacToeLib
development/samples/TicTacToeMain samples/${PLATFORM_NAME}/TicTacToeMain development/samples/TicTacToeMain samples/${PLATFORM_NAME}/TicTacToeMain
development/samples/CrossCompatibility samples/${PLATFORM_NAME}/CrossCompatibility development/samples/VoiceRecognitionService samples/${PLATFORM_NAME}/VoiceRecognitionService
development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary
development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple
# NOTICE files are copied by build/core/Makefile from sdk.git # NOTICE files are copied by build/core/Makefile from sdk.git
sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt

5
samples/README Normal file
View File

@@ -0,0 +1,5 @@
Adding a new folder in development/samples is not enough to have it
be packaged with the SDK.
Make sure to edit development/build/sdk.atree to add the sample to the SDK
build.

View File

@@ -1,5 +1,5 @@
Pkg.UserSrc=false Pkg.UserSrc=false
Pkg.Revision=1 Pkg.Revision=1
AndroidVersion.ApiLevel=8 AndroidVersion.ApiLevel=9
AndroidVersion.CodeName=gingerbread #AndroidVersion.CodeName=

View File

@@ -1,6 +1,6 @@
Pkg.Desc=Android SDK Platform 2.x_r1 Pkg.Desc=Android SDK Platform 2.3_r1
Pkg.UserSrc=false Pkg.UserSrc=false
Platform.Version=2.x Platform.Version=2.3
Pkg.Revision=1 Pkg.Revision=1
AndroidVersion.ApiLevel=8 AndroidVersion.ApiLevel=9
AndroidVersion.CodeName=gingerbread #AndroidVersion.CodeName=