Merge branch 'gingerbread' into gingerbread-release
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>
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NdefRecord;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
@@ -105,8 +105,8 @@ public class NdefUtil {
|
||||
*/
|
||||
byte[] payload = Bytes.concat(new byte[] { 0x00 }, uriBytes);
|
||||
|
||||
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN_TYPE,
|
||||
NdefRecord.TYPE_URI, EMPTY, payload);
|
||||
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
|
||||
NdefRecord.RTD_URI, EMPTY, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,8 +122,8 @@ public class NdefUtil {
|
||||
* record containing a URI.
|
||||
*/
|
||||
public static URI toURI(NdefRecord record) throws URISyntaxException {
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_URI));
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
|
||||
|
||||
byte[] payload = record.getPayload();
|
||||
|
||||
@@ -161,8 +161,8 @@ public class NdefUtil {
|
||||
* @return text payload.
|
||||
*/
|
||||
public static String toText(NdefRecord record) {
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_TEXT));
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_TEXT));
|
||||
try {
|
||||
|
||||
byte[] payload = record.getPayload();
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.android.apps.tag;
|
||||
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefTag;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
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.
|
||||
*/
|
||||
public class SaveTag extends Activity implements DialogInterface.OnClickListener {
|
||||
private static final String TAG = "SaveTag";
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
@@ -46,9 +47,17 @@ public class SaveTag extends Activity implements DialogInterface.OnClickListener
|
||||
);
|
||||
|
||||
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);
|
||||
Toast.makeText(this.getBaseContext(), "SaveTag: " + s, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ package com.android.apps.tag;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NdefRecord;
|
||||
import com.trustedlogic.trustednfc.android.NfcException;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
import android.nfc.FormatException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.URI;
|
||||
@@ -67,8 +67,8 @@ public class SmartPoster {
|
||||
}
|
||||
|
||||
public static SmartPoster from(NdefRecord record) {
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_SMART_POSTER));
|
||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_SMART_POSTER));
|
||||
try {
|
||||
NdefMessage subRecords = new NdefMessage(record.getPayload());
|
||||
URI uri = Iterables.getOnlyElement(NdefUtil.getURIs(subRecords));
|
||||
@@ -79,7 +79,7 @@ public class SmartPoster {
|
||||
}
|
||||
|
||||
return new SmartPoster(uri, title);
|
||||
} catch (NfcException e) {
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ package com.android.apps.tag;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
||||
import android.nfc.NdefTag;
|
||||
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NfcAdapter;
|
||||
|
||||
/**
|
||||
* When we receive a new NDEF tag, start the activity to
|
||||
@@ -30,10 +32,10 @@ public class TagBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
|
||||
NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
|
||||
if (intent.getAction().equals(NfcAdapter.ACTION_NDEF_TAG_DISCOVERED)) {
|
||||
NdefTag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
||||
Intent i = new Intent(context, SaveTag.class)
|
||||
.putExtra(NfcManager.NDEF_MESSAGE_EXTRA, msg)
|
||||
.putExtra(NfcAdapter.EXTRA_TAG, tag)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
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 com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NdefRecord;
|
||||
import com.trustedlogic.trustednfc.android.NfcException;
|
||||
|
||||
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)"
|
||||
+ ")";
|
||||
@@ -146,7 +146,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
|
||||
// A real message obtained from an NFC Forum Type 4 tag.
|
||||
NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG);
|
||||
insert(db, msg3, false);
|
||||
} catch (NfcException e) {
|
||||
} catch (FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.android.apps.tag;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.trustedlogic.trustednfc.android.NdefRecord;
|
||||
import android.nfc.NdefRecord;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class NdefUtilTest extends AndroidTestCase {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.android.apps.tag;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import android.nfc.NdefMessage;
|
||||
|
||||
/**
|
||||
* Tests for {@link SmartPoster}.
|
||||
|
||||
@@ -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,
|
||||
# (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/samples/source.properties samples/${PLATFORM_NAME}/source.properties
|
||||
#
|
||||
# PLEASE KEEP THE SAMPLES IN ALPHABETICAL ORDER.
|
||||
#
|
||||
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/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/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/SearchableDictionary samples/${PLATFORM_NAME}/SearchableDictionary
|
||||
development/samples/SkeletonApp samples/${PLATFORM_NAME}/SkeletonApp
|
||||
development/samples/Snake samples/${PLATFORM_NAME}/Snake
|
||||
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/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/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
|
||||
sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt
|
||||
|
||||
5
samples/README
Normal file
5
samples/README
Normal 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.
|
||||
@@ -1,5 +1,5 @@
|
||||
Pkg.UserSrc=false
|
||||
Pkg.Revision=1
|
||||
AndroidVersion.ApiLevel=8
|
||||
AndroidVersion.CodeName=gingerbread
|
||||
AndroidVersion.ApiLevel=9
|
||||
#AndroidVersion.CodeName=
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pkg.Desc=Android SDK Platform 2.x_r1
|
||||
Pkg.Desc=Android SDK Platform 2.3_r1
|
||||
Pkg.UserSrc=false
|
||||
Platform.Version=2.x
|
||||
Platform.Version=2.3
|
||||
Pkg.Revision=1
|
||||
AndroidVersion.ApiLevel=8
|
||||
AndroidVersion.CodeName=gingerbread
|
||||
AndroidVersion.ApiLevel=9
|
||||
#AndroidVersion.CodeName=
|
||||
|
||||
Reference in New Issue
Block a user