diff --git a/apps/Tag/src/com/android/apps/tag/NdefUtil.java b/apps/Tag/src/com/android/apps/tag/NdefUtil.java index eec7c1918..55d52f37b 100644 --- a/apps/Tag/src/com/android/apps/tag/NdefUtil.java +++ b/apps/Tag/src/com/android/apps/tag/NdefUtil.java @@ -16,20 +16,12 @@ package com.android.apps.tag; -import com.android.apps.tag.record.ParsedNdefRecord; -import com.android.apps.tag.record.SmartPoster; -import com.android.apps.tag.record.TextRecord; -import com.android.apps.tag.record.UriRecord; -import com.google.common.collect.Iterables; -import com.google.common.primitives.Bytes; - import android.net.Uri; -import android.nfc.NdefMessage; import android.nfc.NdefRecord; +import com.google.common.primitives.Bytes; + import java.nio.charset.Charsets; -import java.util.ArrayList; -import java.util.List; /** * Utilities for dealing with conversions to and from NdefRecords. @@ -60,34 +52,4 @@ public class NdefUtil { return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, EMPTY, payload); } - - public static Iterable getTextFields(NdefMessage message) { - return Iterables.filter(getObjects(message), TextRecord.class); - } - - public static Iterable getUris(NdefMessage message) { - return Iterables.filter(getObjects(message), UriRecord.class); - } - - /** - * Parse the provided {@code NdefMessage}, extracting all known - * objects from the message. Typically this list will consist of - * {@link String}s corresponding to NDEF text records, or {@link Uri}s - * corresponding to NDEF URI records. - *

- * TODO: Is this API too generic? Should we keep it? - */ - public static Iterable getObjects(NdefMessage message) { - List retval = new ArrayList(); - for (NdefRecord record : message.getRecords()) { - if (UriRecord.isUri(record)) { - retval.add(UriRecord.parse(record)); - } else if (TextRecord.isText(record)) { - retval.add(TextRecord.parse(record)); - } else if (SmartPoster.isPoster(record)) { - retval.add(SmartPoster.parse(record)); - } - } - return retval; - } } diff --git a/apps/Tag/src/com/android/apps/tag/TagAdapter.java b/apps/Tag/src/com/android/apps/tag/TagAdapter.java index 04bc46aa4..44757c455 100644 --- a/apps/Tag/src/com/android/apps/tag/TagAdapter.java +++ b/apps/Tag/src/com/android/apps/tag/TagAdapter.java @@ -16,14 +16,10 @@ package com.android.apps.tag; -import com.android.apps.tag.TagDBHelper.NdefMessagesTable; - import android.content.Context; import android.database.Cursor; -import android.net.Uri; import android.nfc.FormatException; import android.nfc.NdefMessage; -import android.nfc.NdefRecord; import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; @@ -32,9 +28,12 @@ import android.view.ViewGroup; import android.widget.Adapter; import android.widget.CursorAdapter; import android.widget.TextView; -import com.android.apps.tag.record.SmartPoster; -import com.android.apps.tag.record.TextRecord; -import com.android.apps.tag.record.UriRecord; + +import com.android.apps.tag.TagDBHelper.NdefMessagesTable; +import com.android.apps.tag.message.NdefMessageParser; +import com.android.apps.tag.message.ParsedNdefMessage; + +import java.util.Locale; /** * A custom {@link Adapter} that renders tag entries for a list. @@ -63,23 +62,8 @@ public class TagAdapter extends CursorAdapter { if (msg == null) { mainLine.setText("Invalid tag"); } else { - try { - SmartPoster poster = SmartPoster.parse(msg.getRecords()[0]); - TextRecord title = poster.getTitle(); - if (title != null) { - mainLine.setText(title.getText()); - } - } catch (IllegalArgumentException e) { - // Not a smart poster - NdefRecord record = msg.getRecords()[0]; - Uri uri = null; - try { - uri = UriRecord.parse(record).getUri(); - mainLine.setText(uri.toString()); - } catch (IllegalArgumentException e2) { - mainLine.setText("Not a smart poster or URL"); - } - } + ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg); + mainLine.setText(parsedMsg.getSnippet(Locale.getDefault())); } dateLine.setText(DateUtils.getRelativeTimeSpanString( context, cursor.getLong(cursor.getColumnIndex(NdefMessagesTable.DATE)))); diff --git a/apps/Tag/src/com/android/apps/tag/TagDBHelper.java b/apps/Tag/src/com/android/apps/tag/TagDBHelper.java index 3cb7844c1..dd11d9431 100644 --- a/apps/Tag/src/com/android/apps/tag/TagDBHelper.java +++ b/apps/Tag/src/com/android/apps/tag/TagDBHelper.java @@ -16,8 +16,6 @@ package com.android.apps.tag; -import com.google.common.annotations.VisibleForTesting; - import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -27,6 +25,8 @@ import android.nfc.FormatException; import android.nfc.NdefMessage; import android.nfc.NdefRecord; +import com.google.common.annotations.VisibleForTesting; + /** * Database utilities for the saved tags. */ diff --git a/apps/Tag/src/com/android/apps/tag/TagList.java b/apps/Tag/src/com/android/apps/tag/TagList.java index 45f6f6577..7d09baed1 100644 --- a/apps/Tag/src/com/android/apps/tag/TagList.java +++ b/apps/Tag/src/com/android/apps/tag/TagList.java @@ -16,8 +16,6 @@ package com.android.apps.tag; -import com.android.apps.tag.TagDBHelper.NdefMessagesTable; - import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -35,6 +33,8 @@ import android.view.Menu; import android.view.View; import android.widget.ListView; +import com.android.apps.tag.TagDBHelper.NdefMessagesTable; + /** * An {@link Activity} that displays a flat list of tags that can be "opened". */ diff --git a/apps/Tag/src/com/android/apps/tag/TagViewer.java b/apps/Tag/src/com/android/apps/tag/TagViewer.java index aac93c6d1..a1d890020 100644 --- a/apps/Tag/src/com/android/apps/tag/TagViewer.java +++ b/apps/Tag/src/com/android/apps/tag/TagViewer.java @@ -30,10 +30,11 @@ import android.view.LayoutInflater; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.TextView; -import com.android.apps.tag.record.ParsedNdefRecord; -import com.android.apps.tag.record.SmartPoster; -import com.android.apps.tag.record.TextRecord; -import com.android.apps.tag.record.UriRecord; + +import com.android.apps.tag.message.NdefMessageParser; +import com.android.apps.tag.message.ParsedNdefMessage; + +import java.util.Locale; /** * An {@link Activity} which handles a broadcast of a new tag that the device just discovered. @@ -93,35 +94,11 @@ public class TagViewer extends Activity { // The body of the dialog should use the light theme // Build the views from the logical records in the messages - boolean first = true; for (NdefMessage msg : msgs) { - Iterable objects = NdefUtil.getObjects(msg); - for (ParsedNdefRecord object : objects) { - if (!first) { - list.addView(inflater.inflate(R.layout.tag_divider, list, false)); - first = false; - } - - if (object instanceof TextRecord) { - TextRecord textRecord = (TextRecord) object; - TextView text = (TextView) inflater.inflate(R.layout.tag_text, list, false); - text.setText(textRecord.getText()); - list.addView(text); - } else if (object instanceof UriRecord) { - UriRecord uriRecord = (UriRecord) object; - TextView text = (TextView) inflater.inflate(R.layout.tag_text, list, false); - text.setText(uriRecord.getUri().toString()); - list.addView(text); - } else if (object instanceof SmartPoster) { - TextView text = (TextView) inflater.inflate(R.layout.tag_text, list, false); - SmartPoster poster = (SmartPoster) object; - TextRecord title = poster.getTitle(); - if (title != null) { - text.setText(title.getText()); - } - list.addView(text); - } - } + ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg); + TextView text = (TextView) inflater.inflate(R.layout.tag_text, list, false); + text.setText(parsedMsg.getSnippet(Locale.getDefault())); + list.addView(text); } } diff --git a/apps/Tag/src/com/android/apps/tag/message/EmptyMessage.java b/apps/Tag/src/com/android/apps/tag/message/EmptyMessage.java new file mode 100644 index 000000000..48f9e9f85 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/EmptyMessage.java @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import java.util.Locale; + +/** + * A parsed message containing no elements. + */ +class EmptyMessage implements ParsedNdefMessage { + + /* package private */ EmptyMessage() { } + + @Override + public String getSnippet(Locale locale) { + return "Empty Tag"; // TODO: localize + } + + @Override + public boolean isStarred() { + return false; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/message/NdefMessageParser.java b/apps/Tag/src/com/android/apps/tag/message/NdefMessageParser.java new file mode 100644 index 000000000..1823f9847 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/NdefMessageParser.java @@ -0,0 +1,76 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import android.nfc.NdefMessage; +import android.nfc.NdefRecord; + +import com.android.apps.tag.record.ParsedNdefRecord; +import com.android.apps.tag.record.SmartPoster; +import com.android.apps.tag.record.TextRecord; +import com.android.apps.tag.record.UriRecord; + +import java.util.ArrayList; +import java.util.List; + +/** + * Utility class for creating {@link ParsedNdefMessage}s. + */ +public class NdefMessageParser { + + // Utility class + private NdefMessageParser() { } + + /** Parse an NdefMessage */ + public static ParsedNdefMessage parse(NdefMessage message) { + List elements = getRecords(message); + + if (elements.isEmpty()) { + return new EmptyMessage(); + } + + ParsedNdefRecord first = elements.get(0); + + if (elements.size() == 1) { + if (first instanceof SmartPoster) { + return new SmartPosterMessage((SmartPoster) first); + } + if (first instanceof TextRecord) { + return new TextMessage((TextRecord) first); + } + if (first instanceof UriRecord) { + return new UriMessage((UriRecord) first); + } + } + + return new UnknownMessage(elements); + } + + public static List getRecords(NdefMessage message) { + List elements = new ArrayList(); + for (NdefRecord record : message.getRecords()) { + if (UriRecord.isUri(record)) { + elements.add(UriRecord.parse(record)); + } else if (TextRecord.isText(record)) { + elements.add(TextRecord.parse(record)); + } else if (SmartPoster.isPoster(record)) { + elements.add(SmartPoster.parse(record)); + } + } + return elements; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/message/ParsedNdefMessage.java b/apps/Tag/src/com/android/apps/tag/message/ParsedNdefMessage.java new file mode 100644 index 000000000..427aae4c9 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/ParsedNdefMessage.java @@ -0,0 +1,35 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import java.util.Locale; + +/** + * A parsed version of an {@link android.nfc.NdefMessage} + */ +public interface ParsedNdefMessage { + + /** + * Returns the snippet information associated with the NdefMessage + * most appropriate for the given {@code locale}. + */ + public String getSnippet(Locale locale); + + // TODO: Determine if this is the best place for holding whether + // the user has starred this parsed message. + public boolean isStarred(); +} diff --git a/apps/Tag/src/com/android/apps/tag/message/SmartPosterMessage.java b/apps/Tag/src/com/android/apps/tag/message/SmartPosterMessage.java new file mode 100644 index 000000000..28cd7b3c1 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/SmartPosterMessage.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import com.android.apps.tag.record.SmartPoster; +import com.android.apps.tag.record.TextRecord; +import com.google.common.base.Preconditions; + +import java.util.Locale; + +/** + * A message consisting of one {@link SmartPoster} object. + */ +class SmartPosterMessage implements ParsedNdefMessage { + private final SmartPoster mPoster; + + SmartPosterMessage(SmartPoster poster) { + mPoster = Preconditions.checkNotNull(poster); + } + + @Override + public String getSnippet(Locale locale) { + TextRecord title = mPoster.getTitle(); + if (title == null) { + return mPoster.getUriRecord().getUri().toString(); + } + return title.getText(); + } + + @Override + public boolean isStarred() { + return false; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/message/TextMessage.java b/apps/Tag/src/com/android/apps/tag/message/TextMessage.java new file mode 100644 index 000000000..3494331cf --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/TextMessage.java @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import com.android.apps.tag.record.TextRecord; +import com.google.common.base.Preconditions; + +import java.util.Locale; + +/** + * A message containing one text element + */ +class TextMessage implements ParsedNdefMessage { + private final TextRecord mRecord; + + TextMessage(TextRecord record) { + mRecord = Preconditions.checkNotNull(record); + } + + @Override + public String getSnippet(Locale locale) { + return mRecord.getText(); + } + + @Override + public boolean isStarred() { + return false; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/message/UnknownMessage.java b/apps/Tag/src/com/android/apps/tag/message/UnknownMessage.java new file mode 100644 index 000000000..a30445fc3 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/UnknownMessage.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import com.android.apps.tag.record.ParsedNdefRecord; +import com.google.common.collect.ImmutableList; + +import java.util.Locale; + +/** + * The catchall parsed message format for when nothing else better applies. + */ +class UnknownMessage implements ParsedNdefMessage { + + private final ImmutableList mRecords; + + UnknownMessage(Iterable records) { + mRecords = ImmutableList.copyOf(records); + } + + @Override + public String getSnippet(Locale locale) { + // TODO: localize + return "Unknown record type with " + mRecords.size() + " elements."; + } + + @Override + public boolean isStarred() { + return false; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/message/UriMessage.java b/apps/Tag/src/com/android/apps/tag/message/UriMessage.java new file mode 100644 index 000000000..85bfa41f1 --- /dev/null +++ b/apps/Tag/src/com/android/apps/tag/message/UriMessage.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package com.android.apps.tag.message; + +import com.android.apps.tag.record.UriRecord; +import com.google.common.base.Preconditions; + +import java.util.Locale; + +/** + * A {@link ParsedNdefMessage} consisting of one {@link UriRecord}. + */ +class UriMessage implements ParsedNdefMessage { + + private final UriRecord mRecord; + + UriMessage(UriRecord record) { + mRecord = Preconditions.checkNotNull(record); + } + + @Override + public String getSnippet(Locale locale) { + // URIs cannot be localized + return mRecord.getUri().toString(); + } + + @Override + public boolean isStarred() { + return false; + } +} diff --git a/apps/Tag/src/com/android/apps/tag/record/SmartPoster.java b/apps/Tag/src/com/android/apps/tag/record/SmartPoster.java index 54ac42405..935b23498 100644 --- a/apps/Tag/src/com/android/apps/tag/record/SmartPoster.java +++ b/apps/Tag/src/com/android/apps/tag/record/SmartPoster.java @@ -16,16 +16,16 @@ package com.android.apps.tag.record; -import com.android.apps.tag.NdefUtil; -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; - import android.nfc.FormatException; import android.nfc.NdefMessage; import android.nfc.NdefRecord; -import java.util.Arrays; +import com.android.apps.tag.message.NdefMessageParser; +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +import java.util.Arrays; +import java.util.NoSuchElementException; import javax.annotation.Nullable; /** @@ -73,8 +73,12 @@ public class SmartPoster implements ParsedNdefRecord { Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_SMART_POSTER)); try { NdefMessage subRecords = new NdefMessage(record.getPayload()); - UriRecord uri = Iterables.getOnlyElement(NdefUtil.getUris(subRecords)); - Iterable textFields = NdefUtil.getTextFields(subRecords); + + Iterable records = NdefMessageParser.getRecords(subRecords); + + UriRecord uri = Iterables.getOnlyElement(Iterables.filter(records, UriRecord.class)); + Iterable textFields = Iterables.filter(records, TextRecord.class); + TextRecord title = null; if (!Iterables.isEmpty(textFields)) { title = Iterables.get(textFields, 0); @@ -83,6 +87,8 @@ public class SmartPoster implements ParsedNdefRecord { return new SmartPoster(uri, title); } catch (FormatException e) { throw new IllegalArgumentException(e); + } catch (NoSuchElementException e) { + throw new IllegalArgumentException(e); } } diff --git a/apps/Tag/src/com/android/apps/tag/record/TextRecord.java b/apps/Tag/src/com/android/apps/tag/record/TextRecord.java index 29d380d85..716e5afb7 100644 --- a/apps/Tag/src/com/android/apps/tag/record/TextRecord.java +++ b/apps/Tag/src/com/android/apps/tag/record/TextRecord.java @@ -17,6 +17,7 @@ package com.android.apps.tag.record; import android.nfc.NdefRecord; + import com.google.common.base.Preconditions; import java.io.UnsupportedEncodingException; @@ -27,6 +28,7 @@ import java.util.Arrays; */ public class TextRecord implements ParsedNdefRecord { + /** ISO/IANA language code */ private final String mLanguageCode; private final String mText; @@ -44,6 +46,11 @@ public class TextRecord implements ParsedNdefRecord { return mText; } + /** + * Returns the ISO/IANA language code associated with this text element. + * + * TODO: this should return a {@link java.util.Locale} + */ public String getLanguageCode() { return mLanguageCode; } diff --git a/apps/Tag/src/com/android/apps/tag/record/UriRecord.java b/apps/Tag/src/com/android/apps/tag/record/UriRecord.java index eeba30bd8..7d5e9bc6f 100644 --- a/apps/Tag/src/com/android/apps/tag/record/UriRecord.java +++ b/apps/Tag/src/com/android/apps/tag/record/UriRecord.java @@ -18,6 +18,7 @@ package com.android.apps.tag.record; import android.net.Uri; import android.nfc.NdefRecord; + import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; diff --git a/apps/Tag/tests/src/com/android/apps/tag/NdefUtilTest.java b/apps/Tag/tests/src/com/android/apps/tag/NdefUtilTest.java index 24070ae12..297e754fc 100644 --- a/apps/Tag/tests/src/com/android/apps/tag/NdefUtilTest.java +++ b/apps/Tag/tests/src/com/android/apps/tag/NdefUtilTest.java @@ -16,10 +16,11 @@ package com.android.apps.tag; +import android.nfc.NdefRecord; import android.test.AndroidTestCase; + import com.android.apps.tag.record.TextRecord; import com.google.common.primitives.Bytes; -import android.nfc.NdefRecord; import java.io.UnsupportedEncodingException; diff --git a/apps/Tag/tests/src/com/android/apps/tag/SmartPosterTest.java b/apps/Tag/tests/src/com/android/apps/tag/SmartPosterTest.java index 8225197ce..9a5e644a8 100644 --- a/apps/Tag/tests/src/com/android/apps/tag/SmartPosterTest.java +++ b/apps/Tag/tests/src/com/android/apps/tag/SmartPosterTest.java @@ -16,8 +16,9 @@ package com.android.apps.tag; -import android.test.AndroidTestCase; import android.nfc.NdefMessage; +import android.test.AndroidTestCase; + import com.android.apps.tag.record.SmartPoster; /** diff --git a/ndk/platforms/android-9/samples/native-activity/src/Dummy.java b/ndk/platforms/android-9/samples/native-activity/src/Dummy.java deleted file mode 100644 index 596215a48..000000000 --- a/ndk/platforms/android-9/samples/native-activity/src/Dummy.java +++ /dev/null @@ -1,4 +0,0 @@ -// Temporary until the NDK build system can deal with there being no Java source. -class Dummy { - -} diff --git a/samples/ApiDemos/res/layout/device_admin_sample.xml b/samples/ApiDemos/res/layout/device_admin_sample.xml index 2827c010b..16b08ce5d 100644 --- a/samples/ApiDemos/res/layout/device_admin_sample.xml +++ b/samples/ApiDemos/res/layout/device_admin_sample.xml @@ -99,21 +99,27 @@ + + - - + + Password Attempts Wipe Data Force Lock Wipe Data + Wipe All Data Max screen timeout Set Timeout diff --git a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java index f7ee2d73c..b3fc2f98a 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java @@ -128,6 +128,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { Button mForceLockButton; Button mWipeDataButton; + Button mWipeAllDataButton; private Button mTimeoutButton; @@ -208,6 +209,8 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mForceLockButton.setOnClickListener(mForceLockListener); mWipeDataButton = (Button)findViewById(R.id.wipe_data); mWipeDataButton.setOnClickListener(mWipeDataListener); + mWipeAllDataButton = (Button)findViewById(R.id.wipe_all_data); + mWipeAllDataButton.setOnClickListener(mWipeDataListener); mTimeout = (EditText) findViewById(R.id.timeout); mTimeoutButton = (Button) findViewById(R.id.set_timeout); @@ -226,6 +229,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mResetPasswordButton.setEnabled(true); mForceLockButton.setEnabled(true); mWipeDataButton.setEnabled(true); + mWipeAllDataButton.setEnabled(true); } else { mEnableButton.setEnabled(true); mDisableButton.setEnabled(false); @@ -236,6 +240,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mResetPasswordButton.setEnabled(false); mForceLockButton.setEnabled(false); mWipeDataButton.setEnabled(false); + mWipeAllDataButton.setEnabled(false); } } @@ -372,7 +377,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { }; private OnClickListener mWipeDataListener = new OnClickListener() { - public void onClick(View v) { + public void onClick(final View v) { if (mAM.isUserAMonkey()) { // Don't trust monkeys to do the right thing! AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this); @@ -386,14 +391,22 @@ public class DeviceAdminSample extends DeviceAdminReceiver { builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this); - builder.setMessage("This is not a test. " - + "This WILL erase all of your data! " - + "Are you really absolutely sure?"); + if (v == mWipeAllDataButton) { + builder.setMessage("This is not a test. " + + "This WILL erase all of your data, " + + "including external storage! " + + "Are you really absolutely sure?"); + } else { + builder.setMessage("This is not a test. " + + "This WILL erase all of your data! " + + "Are you really absolutely sure?"); + } builder.setPositiveButton("BOOM!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean active = mDPM.isAdminActive(mDeviceAdminSample); if (active) { - mDPM.wipeData(0); + mDPM.wipeData(v == mWipeAllDataButton + ? DevicePolicyManager.WIPE_EXTERNAL_STORAGE : 0); } } }); diff --git a/samples/source.properties b/samples/source.properties index 96c520a22..69d50d381 100644 --- a/samples/source.properties +++ b/samples/source.properties @@ -1,5 +1,5 @@ Pkg.UserSrc=false Pkg.Revision=1 AndroidVersion.ApiLevel=8 -#AndroidVersion.CodeName= +AndroidVersion.CodeName=gingerbread