diff options
author | Jeff Hamilton <jham@android.com> | 2011-07-27 17:14:01 -0500 |
---|---|---|
committer | Jeff Hamilton <jham@android.com> | 2011-07-27 17:14:01 -0500 |
commit | 59395354a8a09752dae68f2fef44d6ad011c38db (patch) | |
tree | f6d115f121cfeb1f467dcaada4f21e82960556d0 /src | |
parent | dee4bf7b3b5dbdbaf0cf68766c087658b26bc21b (diff) | |
download | android_packages_apps_Tag-59395354a8a09752dae68f2fef44d6ad011c38db.tar.gz android_packages_apps_Tag-59395354a8a09752dae68f2fef44d6ad011c38db.tar.bz2 android_packages_apps_Tag-59395354a8a09752dae68f2fef44d6ad011c38db.zip |
Update the Tags app to the holo theme and fix some bugs.
Change-Id: I217cf3f5b2e228df50ff1bed050448bf72140a3b
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/apps/tag/TagViewer.java | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/src/com/android/apps/tag/TagViewer.java b/src/com/android/apps/tag/TagViewer.java index 14e58f8..b4e9474 100644 --- a/src/com/android/apps/tag/TagViewer.java +++ b/src/com/android/apps/tag/TagViewer.java @@ -22,7 +22,6 @@ import com.android.apps.tag.record.ParsedNdefRecord; import android.app.Activity; import android.content.Intent; -import android.net.Uri; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; @@ -32,8 +31,8 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; -import android.widget.Button; import android.widget.LinearLayout; +import android.widget.TextView; import java.util.List; @@ -52,7 +51,6 @@ public class TagViewer extends Activity implements OnClickListener { setContentView(R.layout.tag_viewer); mTagContent = (LinearLayout) findViewById(R.id.list); - findViewById(R.id.button_done).setOnClickListener(this); resolveIntent(getIntent()); } @@ -62,25 +60,13 @@ public class TagViewer extends Activity implements OnClickListener { String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { - // When a tag is discovered we send it to the service to be save. We - // include a PendingIntent for the service to call back onto. This - // will cause this activity to be restarted with onNewIntent(). At - // that time we read it from the database and view it. Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); - NdefMessage[] msgs; + NdefMessage msg = null; if (rawMsgs != null && rawMsgs.length > 0) { - // stupid java, need to cast one-by-one - msgs = new NdefMessage[rawMsgs.length]; - for (int i = 0; i < rawMsgs.length; i++) { - msgs[i] = (NdefMessage) rawMsgs[i]; - } - } else { - // Unknown tag type - byte[] empty = new byte[] {}; - NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); - NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); - msgs = new NdefMessage[] { msg }; + msg = (NdefMessage) rawMsgs[0]; } + + buildTagViews(msg); } else { Log.e(TAG, "Unknown intent " + intent); finish(); @@ -89,28 +75,35 @@ public class TagViewer extends Activity implements OnClickListener { } void buildTagViews(NdefMessage msg) { - if (msg == null) { - return; - } - LayoutInflater inflater = LayoutInflater.from(this); LinearLayout content = mTagContent; // Clear out any old views in the content area, for example if you scan two tags in a row. content.removeAllViews(); - // Parse the first message in the list - //TODO figure out what to do when/if we support multiple messages per tag - ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg); - // Build views for all of the sub records - List<ParsedNdefRecord> records = parsedMsg.getRecords(); - final int size = records.size(); - - for (int i = 0; i < size; i++) { - ParsedNdefRecord record = records.get(i); - content.addView(record.getView(this, inflater, content, i)); - inflater.inflate(R.layout.tag_divider, content, true); + if (msg == null) { + TextView empty = (TextView) inflater.inflate(R.layout.tag_text, content, false); + empty.setText(R.string.tag_empty); + content.addView(empty); + } else { + // Parse the first message in the list + //TODO figure out what to do when/if we support multiple messages per tag + ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg); + + List<ParsedNdefRecord> records = parsedMsg.getRecords(); + final int size = records.size(); + if (size == 0) { + TextView empty = (TextView) inflater.inflate(R.layout.tag_text, content, false); + empty.setText(R.string.tag_empty); + content.addView(empty); + } else { + for (int i = 0; i < size; i++) { + ParsedNdefRecord record = records.get(i); + content.addView(record.getView(this, inflater, content, i)); + inflater.inflate(R.layout.tag_divider, content, true); + } + } } } |