AllIntents - a test application for contact list.
Bug: 2601157
Change-Id: Iff4b45f89d4d09405b0ca991b941722370ae3424
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 533888f..47f47b7 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -721,23 +721,21 @@
setTitle(R.string.shortcutActivityTitle);
}
} else if (Intent.ACTION_GET_CONTENT.equals(action)) {
- // TODO : Does it work in mSearchMode?
- final String resolvedType = intent.resolveType(this);
- if (Contacts.CONTENT_ITEM_TYPE.equals(resolvedType)) {
+ if (Contacts.CONTENT_ITEM_TYPE.equals(type)) {
if (mSearchMode) {
mMode = MODE_PICK_CONTACT;
} else {
mMode = MODE_PICK_OR_CREATE_CONTACT;
}
- } else if (Phone.CONTENT_ITEM_TYPE.equals(resolvedType)) {
+ } else if (Phone.CONTENT_ITEM_TYPE.equals(type)) {
mMode = MODE_PICK_PHONE;
- } else if (Phones.CONTENT_ITEM_TYPE.equals(resolvedType)) {
+ } else if (Phones.CONTENT_ITEM_TYPE.equals(type)) {
mMode = MODE_LEGACY_PICK_PHONE;
- } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(resolvedType)) {
+ } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(type)) {
mMode = MODE_PICK_POSTAL;
- } else if (ContactMethods.CONTENT_POSTAL_ITEM_TYPE.equals(resolvedType)) {
+ } else if (ContactMethods.CONTENT_POSTAL_ITEM_TYPE.equals(type)) {
mMode = MODE_LEGACY_PICK_POSTAL;
- } else if (People.CONTENT_ITEM_TYPE.equals(resolvedType)) {
+ } else if (People.CONTENT_ITEM_TYPE.equals(type)) {
if (mSearchMode) {
mMode = MODE_LEGACY_PICK_PERSON;
} else {
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 7af1a54..53334a8 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -4,9 +4,9 @@
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.
@@ -17,16 +17,40 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.contacts.tests">
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+
<application>
<uses-library android:name="android.test.runner" />
<meta-data android:name="com.android.contacts.iconset" android:resource="@xml/iconset" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+
+ <activity android:name=".allintents.AllIntentsActivity"
+ android:label="@string/contactsIntents"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".allintents.ResultActivity"
+ android:label="@string/result"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.contacts"
android:label="Contacts app tests">
</instrumentation>
-
+
<instrumentation android:name="com.android.contacts.ContactsLaunchPerformance"
android:targetPackage="com.android.contacts"
android:label="Contacts launch performance">
@@ -38,4 +62,4 @@
android:label="Dialer launch performance">
</instrumentation>
-</manifest>
+</manifest>
diff --git a/tests/res/layout/intent_list_item.xml b/tests/res/layout/intent_list_item.xml
new file mode 100644
index 0000000..4749224
--- /dev/null
+++ b/tests/res/layout/intent_list_item.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+/>
diff --git a/tests/res/layout/result.xml b/tests/res/layout/result.xml
new file mode 100644
index 0000000..0ab32c6
--- /dev/null
+++ b/tests/res/layout/result.xml
@@ -0,0 +1,32 @@
+<?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.
+-->
+
+<ScrollView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fillViewport="true"
+>
+
+ <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/table"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:shrinkColumns="1"
+ android:stretchColumns="*">
+ </TableLayout>
+</ScrollView>
+
diff --git a/tests/res/values/donottranslate_strings.xml b/tests/res/values/donottranslate_strings.xml
new file mode 100644
index 0000000..a4d29e1
--- /dev/null
+++ b/tests/res/values/donottranslate_strings.xml
@@ -0,0 +1,65 @@
+<?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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <string name="contactsIntents">Contacts Intents</string>
+ <string name="result">Result returned by activity</string>
+
+ <string-array name="allIntents">
+ <item>LIST_DEFAULT</item>
+ <item>LIST_ALL_CONTACTS_ACTION</item>
+ <item>LIST_CONTACTS_WITH_PHONES_ACTION</item>
+ <item>LIST_STARRED_ACTION</item>
+ <item>LIST_STARRED_ACTION (filter)</item>
+ <item>LIST_FREQUENT_ACTION</item>
+ <item>LIST_FREQUENT_ACTION (filter)</item>
+ <item>LIST_STREQUENT_ACTION</item>
+ <item>LIST_STREQUENT_ACTION (filter)</item>
+ <item>ACTION_PICK: contact</item>
+ <item>ACTION_PICK: contact (legacy)</item>
+ <item>ACTION_PICK: phone</item>
+ <item>ACTION_PICK: phone (legacy)</item>
+ <item>ACTION_PICK: postal</item>
+ <item>ACTION_PICK: postal (legacy)</item>
+ <item>ACTION_CREATE_SHORTCUT: contact</item>
+ <item>ACTION_CREATE_SHORTCUT: contact (filter)</item>
+ <item>ACTION_CREATE_SHORTCUT: dial</item>
+ <item>ACTION_CREATE_SHORTCUT: dial (filter)</item>
+ <item>ACTION_CREATE_SHORTCUT: message</item>
+ <item>ACTION_CREATE_SHORTCUT: message (filter)</item>
+ <item>ACTION_GET_CONTENT: contact</item>
+ <item>ACTION_GET_CONTENT: contact (filter)</item>
+ <item>ACTION_GET_CONTENT: contact (legacy)</item>
+ <item>ACTION_GET_CONTENT: contact (filter, legacy)</item>
+ <item>ACTION_GET_CONTENT: phone</item>
+ <item>ACTION_GET_CONTENT: phone (filter)</item>
+ <item>ACTION_GET_CONTENT: phone (legacy)</item>
+ <item>ACTION_GET_CONTENT: postal</item>
+ <item>ACTION_GET_CONTENT: postal (filter)</item>
+ <item>ACTION_GET_CONTENT: postal (legacy)</item>
+ <item>ACTION_INSERT_OR_EDIT</item>
+ <item>ACTION_SEARCH (call button)</item>
+ <item>ACTION_SEARCH: contact</item>
+ <item>ACTION_SEARCH: email</item>
+ <item>ACTION_SEARCH: phone</item>
+ <item>SEARCH_SUGGESTION_CLICKED (call button)</item>
+ <item>SEARCH_SUGGESTION_CLICKED: contact</item>
+ <item>SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED</item>
+ <item>SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED</item>
+ <item>TODO: JOIN_CONTACT</item>
+ <item>ACTION_GET_MULTIPLE_PHONES</item>
+ </string-array>
+</resources>
diff --git a/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java b/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java
new file mode 100644
index 0000000..7f4919d
--- /dev/null
+++ b/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java
@@ -0,0 +1,420 @@
+/*
+ * 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.contacts.tests.allintents;
+
+import com.android.contacts.ContactsSearchManager;
+import com.android.contacts.tests.R;
+
+import android.app.ListActivity;
+import android.app.SearchManager;
+import android.content.ComponentName;
+import android.content.ContentUris;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.Contacts.ContactMethods;
+import android.provider.Contacts.People;
+import android.provider.Contacts.Phones;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.Intents;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
+import android.provider.ContactsContract.Intents.Insert;
+import android.provider.ContactsContract.Intents.UI;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+/**
+ * An activity that provides access to various modes of the contacts application.
+ * Useful for manual and scripted tests.
+ */
+@SuppressWarnings("deprecation")
+public class AllIntentsActivity extends ListActivity {
+
+ private static final String ANDROID_CONTACTS_PACKAGE = "com.android.contacts";
+
+ private static final String CONTACTS_LIST_ACTIVITY_CLASS_NAME =
+ "com.android.contacts.ContactsListActivity";
+ private static final String SEARCH_RESULTS_ACTIVITY_CLASS_NAME =
+ "com.android.contacts.SearchResultsActivity";
+
+ private static final int LIST_DEFAULT = 0;
+ private static final int LIST_ALL_CONTACTS_ACTION = 1;
+ private static final int LIST_CONTACTS_WITH_PHONES_ACTION = 2;
+ private static final int LIST_STARRED_ACTION = 3;
+ private static final int LIST_STARRED_ACTION_WITH_FILTER = 4;
+ private static final int LIST_FREQUENT_ACTION = 5;
+ private static final int LIST_FREQUENT_ACTION_WITH_FILTER = 6;
+ private static final int LIST_STREQUENT_ACTION = 7;
+ private static final int LIST_STREQUENT_ACTION_WITH_FILTER = 8;
+ private static final int ACTION_PICK_CONTACT = 9;
+ private static final int ACTION_PICK_CONTACT_LEGACY = 10;
+ private static final int ACTION_PICK_PHONE = 11;
+ private static final int ACTION_PICK_PHONE_LEGACY = 12;
+ private static final int ACTION_PICK_POSTAL = 13;
+ private static final int ACTION_PICK_POSTAL_LEGACY = 14;
+ private static final int ACTION_CREATE_SHORTCUT_CONTACT = 15;
+ private static final int ACTION_CREATE_SHORTCUT_CONTACT_FILTER = 16;
+ private static final int ACTION_CREATE_SHORTCUT_DIAL = 17;
+ private static final int ACTION_CREATE_SHORTCUT_DIAL_FILTER = 18;
+ private static final int ACTION_CREATE_SHORTCUT_MESSAGE = 19;
+ private static final int ACTION_CREATE_SHORTCUT_MESSAGE_FILTER = 20;
+ private static final int ACTION_GET_CONTENT_CONTACT = 21;
+ private static final int ACTION_GET_CONTENT_CONTACT_FILTER = 22;
+ private static final int ACTION_GET_CONTENT_CONTACT_LEGACY = 23;
+ private static final int ACTION_GET_CONTENT_CONTACT_FILTER_LEGACY = 24;
+ private static final int ACTION_GET_CONTENT_PHONE = 25;
+ private static final int ACTION_GET_CONTENT_PHONE_FILTER = 26;
+ private static final int ACTION_GET_CONTENT_PHONE_LEGACY = 27;
+ private static final int ACTION_GET_CONTENT_POSTAL = 28;
+ private static final int ACTION_GET_CONTENT_POSTAL_FILTER = 29;
+ private static final int ACTION_GET_CONTENT_POSTAL_LEGACY = 30;
+ private static final int ACTION_INSERT_OR_EDIT = 31;
+ private static final int ACTION_SEARCH_CALL = 32;
+ private static final int ACTION_SEARCH_CONTACT = 33;
+ private static final int ACTION_SEARCH_EMAIL = 34;
+ private static final int ACTION_SEARCH_PHONE = 35;
+ private static final int SEARCH_SUGGESTION_CLICKED_CALL_BUTTON = 36;
+ private static final int SEARCH_SUGGESTION_CLICKED_CONTACT = 37;
+ private static final int SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED = 38;
+ private static final int SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED = 39;
+ private static final int JOIN_CONTACT = 40;
+ private static final int ACTION_GET_MULTIPLE_PHONES = 41;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setListAdapter(new ArrayAdapter<String>(this, R.layout.intent_list_item,
+ getResources().getStringArray(R.array.allIntents)));
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ super.onListItemClick(l, v, position, id);
+
+ switch (position) {
+ case LIST_DEFAULT: {
+ startContactsListActivity(
+ new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_ALL_CONTACTS_ACTION: {
+ startContactsListActivity(
+ new Intent(UI.LIST_ALL_CONTACTS_ACTION, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_CONTACTS_WITH_PHONES_ACTION: {
+ startContactsListActivity(
+ new Intent(UI.LIST_CONTACTS_WITH_PHONES_ACTION, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_STARRED_ACTION: {
+ startContactsListActivity(
+ new Intent(UI.LIST_STARRED_ACTION, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_STARRED_ACTION_WITH_FILTER: {
+ startContactsListActivity(
+ buildFilterIntent(UI.LIST_STARRED_ACTION, null, null));
+ break;
+ }
+ case LIST_FREQUENT_ACTION: {
+ startContactsListActivity(
+ new Intent(UI.LIST_FREQUENT_ACTION, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_FREQUENT_ACTION_WITH_FILTER: {
+ startContactsListActivity(
+ buildFilterIntent(UI.LIST_FREQUENT_ACTION, null, null));
+ break;
+ }
+ case LIST_STREQUENT_ACTION: {
+ startContactsListActivity(
+ new Intent(UI.LIST_STREQUENT_ACTION, Contacts.CONTENT_URI));
+ break;
+ }
+ case LIST_STREQUENT_ACTION_WITH_FILTER: {
+ startContactsListActivity(
+ buildFilterIntent(UI.LIST_STREQUENT_ACTION, null, null));
+ break;
+ }
+ case ACTION_PICK_CONTACT: {
+ startContactsListActivityForResult(
+ new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI));
+ break;
+ }
+ case ACTION_PICK_CONTACT_LEGACY: {
+ startContactsListActivityForResult(
+ new Intent(Intent.ACTION_PICK, People.CONTENT_URI));
+ break;
+ }
+ case ACTION_PICK_PHONE: {
+ startContactsListActivityForResult(
+ new Intent(Intent.ACTION_PICK, Phone.CONTENT_URI));
+ break;
+ }
+ case ACTION_PICK_PHONE_LEGACY: {
+ startContactsListActivityForResult(
+ new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI));
+ break;
+ }
+ case ACTION_PICK_POSTAL: {
+ startContactsListActivityForResult(
+ new Intent(Intent.ACTION_PICK, StructuredPostal.CONTENT_URI));
+ break;
+ }
+ case ACTION_PICK_POSTAL_LEGACY: {
+ Intent intent = new Intent(Intent.ACTION_PICK);
+ intent.setType(ContactMethods.CONTENT_POSTAL_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_CONTACT: {
+ Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_CONTACT_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_CREATE_SHORTCUT,
+ CONTACTS_LIST_ACTIVITY_CLASS_NAME, null));
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_DIAL: {
+ Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
+ intent.setComponent(
+ new ComponentName(ANDROID_CONTACTS_PACKAGE, "alias.DialShortcut"));
+ startActivityForResult(intent, 0);
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_DIAL_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_CREATE_SHORTCUT,
+ "alias.DialShortcut", null));
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_MESSAGE: {
+ Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
+ intent.setComponent(
+ new ComponentName(ANDROID_CONTACTS_PACKAGE, "alias.MessageShortcut"));
+ startActivityForResult(intent, 0);
+ break;
+ }
+ case ACTION_CREATE_SHORTCUT_MESSAGE_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_CREATE_SHORTCUT,
+ "alias.MessageShortcut", null));
+ break;
+ }
+ case ACTION_GET_CONTENT_CONTACT: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(Contacts.CONTENT_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_GET_CONTENT_CONTACT_LEGACY: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(People.CONTENT_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_GET_CONTENT_CONTACT_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_GET_CONTENT,
+ CONTACTS_LIST_ACTIVITY_CLASS_NAME,
+ Contacts.CONTENT_ITEM_TYPE));
+ break;
+ }
+ case ACTION_GET_CONTENT_CONTACT_FILTER_LEGACY: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_GET_CONTENT,
+ CONTACTS_LIST_ACTIVITY_CLASS_NAME,
+ People.CONTENT_ITEM_TYPE));
+ break;
+ }
+ case ACTION_GET_CONTENT_PHONE: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(Phone.CONTENT_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_GET_CONTENT_PHONE_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_GET_CONTENT,
+ CONTACTS_LIST_ACTIVITY_CLASS_NAME,
+ Phone.CONTENT_ITEM_TYPE));
+ break;
+ }
+ case ACTION_GET_CONTENT_PHONE_LEGACY: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(Phones.CONTENT_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_GET_CONTENT_POSTAL: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(StructuredPostal.CONTENT_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_GET_CONTENT_POSTAL_FILTER: {
+ startContactsListActivityForResult(
+ buildFilterIntent(Intent.ACTION_GET_CONTENT,
+ CONTACTS_LIST_ACTIVITY_CLASS_NAME,
+ StructuredPostal.CONTENT_ITEM_TYPE));
+ break;
+ }
+ case ACTION_GET_CONTENT_POSTAL_LEGACY: {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType(ContactMethods.CONTENT_POSTAL_ITEM_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ case ACTION_INSERT_OR_EDIT: {
+ Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
+ startContactsListActivity(intent);
+ break;
+ }
+ case ACTION_SEARCH_CALL: {
+ Intent intent = new Intent(Intent.ACTION_SEARCH);
+ intent.putExtra(SearchManager.ACTION_MSG, "call");
+ intent.putExtra(SearchManager.QUERY, "800-4664-411");
+ startSearchResultActivity(intent);
+ break;
+ }
+ case ACTION_SEARCH_CONTACT: {
+ Intent intent = new Intent(Intent.ACTION_SEARCH);
+ intent.putExtra(SearchManager.QUERY, "a");
+ startSearchResultActivity(intent);
+ break;
+ }
+ case ACTION_SEARCH_EMAIL: {
+ Intent intent = new Intent(Intent.ACTION_SEARCH);
+ intent.putExtra(Insert.EMAIL, "a");
+ startSearchResultActivity(intent);
+ break;
+ }
+ case ACTION_SEARCH_PHONE: {
+ Intent intent = new Intent(Intent.ACTION_SEARCH);
+ intent.putExtra(Insert.PHONE, "800");
+ startSearchResultActivity(intent);
+ break;
+ }
+ case SEARCH_SUGGESTION_CLICKED_CALL_BUTTON: {
+ long contactId = findArbitraryContactWithPhoneNumber();
+ if (contactId != -1) {
+ Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
+ Intent intent = new Intent(Intents.SEARCH_SUGGESTION_CLICKED);
+ intent.setData(contactUri);
+ intent.putExtra(SearchManager.ACTION_MSG, "call");
+ startContactsListActivity(intent);
+ }
+ break;
+ }
+ case SEARCH_SUGGESTION_CLICKED_CONTACT: {
+ long contactId = findArbitraryContactWithPhoneNumber();
+ if (contactId != -1) {
+ Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
+ Intent intent = new Intent(Intents.SEARCH_SUGGESTION_CLICKED);
+ intent.setData(contactUri);
+ startContactsListActivity(intent);
+ }
+ break;
+ }
+ case SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED: {
+ Intent intent = new Intent(Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED);
+ intent.setData(Uri.parse("tel:800-4664411"));
+ startContactsListActivity(intent);
+ break;
+ }
+ case SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED: {
+ Intent intent = new Intent(Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED);
+ intent.setData(Uri.parse("tel:800-4664411"));
+ startContactsListActivity(intent);
+ break;
+ }
+ case JOIN_CONTACT: {
+ // TODO
+ break;
+ }
+ case ACTION_GET_MULTIPLE_PHONES: {
+ Intent intent = new Intent(Intents.ACTION_GET_MULTIPLE_PHONES);
+ intent.setType(Phone.CONTENT_TYPE);
+ startContactsListActivityForResult(intent);
+ break;
+ }
+ }
+ }
+
+ private Intent buildFilterIntent(String action, String component, String type) {
+ Intent intent = new Intent(UI.FILTER_CONTACTS_ACTION);
+ intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, "A");
+ intent.putExtra(ContactsSearchManager.ORIGINAL_ACTION_EXTRA_KEY, action);
+ if (component != null) {
+ intent.putExtra(ContactsSearchManager.ORIGINAL_COMPONENT_EXTRA_KEY, component);
+ }
+ if (type != null) {
+ intent.putExtra(ContactsSearchManager.ORIGINAL_TYPE_EXTRA_KEY, type);
+ }
+ return intent;
+ }
+
+ private void startContactsListActivity(Intent intent) {
+ intent.setComponent(
+ new ComponentName(ANDROID_CONTACTS_PACKAGE, CONTACTS_LIST_ACTIVITY_CLASS_NAME));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ }
+
+ private void startContactsListActivityForResult(Intent intent) {
+ intent.setComponent(
+ new ComponentName(ANDROID_CONTACTS_PACKAGE, CONTACTS_LIST_ACTIVITY_CLASS_NAME));
+ startActivityForResult(intent, 12);
+ }
+
+ private void startSearchResultActivity(Intent intent) {
+ intent.setComponent(
+ new ComponentName(ANDROID_CONTACTS_PACKAGE, SEARCH_RESULTS_ACTIVITY_CLASS_NAME));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ Intent intent = new Intent(this, ResultActivity.class);
+ intent.putExtra("resultCode", resultCode);
+ intent.putExtra("data", data);
+ startActivity(intent);
+ }
+
+ private long findArbitraryContactWithPhoneNumber() {
+ Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI,
+ new String[]{Contacts._ID},
+ Contacts.HAS_PHONE_NUMBER + "!=0", null, Contacts._ID + " LIMIT 1");
+ try {
+ if (cursor.moveToFirst()) {
+ return cursor.getLong(0);
+ }
+ } finally {
+ cursor.close();
+ }
+
+ return -1;
+ }
+}
diff --git a/tests/src/com/android/contacts/tests/allintents/ResultActivity.java b/tests/src/com/android/contacts/tests/allintents/ResultActivity.java
new file mode 100644
index 0000000..562f2ba
--- /dev/null
+++ b/tests/src/com/android/contacts/tests/allintents/ResultActivity.java
@@ -0,0 +1,196 @@
+/*
+ * 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.contacts.tests.allintents;
+
+import com.android.contacts.tests.R;
+
+import android.app.Activity;
+import android.content.ContentUris;
+import android.content.Intent;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.Data;
+import android.provider.ContactsContract.CommonDataKinds.Photo;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TableLayout;
+import android.widget.TableRow;
+import android.widget.TextView;
+import android.widget.ImageView.ScaleType;
+
+import java.util.Arrays;
+
+/**
+ * An activity that shows the result of a contacts activity invocation.
+ */
+public class ResultActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.result);
+
+ Intent intent = getIntent();
+ addRowsForIntent((Intent)intent.getExtras().get("data"));
+ }
+
+ private void addRowsForIntent(Intent intent) {
+ if (intent == null) {
+ addRow("", "No data intent returned");
+ } else {
+ addRow("INTENT", intent.toString());
+ addSeparator(3);
+
+ Bundle extras = intent.getExtras();
+ if (extras != null && !extras.isEmpty()) {
+ for (String key : extras.keySet()) {
+ Object value = extras.get(key);
+ addRow("EXTRA", key);
+ addRowForValue("", value);
+ }
+
+ addSeparator(3);
+ }
+
+ String dataUri = intent.getDataString();
+ if (dataUri != null) {
+ addRowsForQuery(Uri.parse(dataUri));
+ }
+ }
+ }
+
+ private void addRowForValue(String label, Object value) {
+ if (value == null) {
+ addRow(label, "null");
+ } else if (value instanceof Bitmap) {
+ addRowWithBitmap(label, (Bitmap)value);
+ } else if (value instanceof Intent) {
+ addRow(label, "INTENT");
+ addRowsForIntent((Intent)value);
+ } else if (value instanceof Uri) {
+ addRow(label, "DATA");
+ addRowsForQuery((Uri)value);
+ } else if (value.getClass().isArray()) {
+ addRow(label, "ARRAY");
+ Parcelable[] array = (Parcelable[])value;
+ for (int i = 0; i < array.length; i++) {
+ addRowForValue("[" + i + "]", String.valueOf(array[i]));
+ }
+ } else {
+ addRow(label, String.valueOf(value));
+ }
+ }
+
+ private void addRowsForQuery(Uri dataUri) {
+ Cursor cursor = getContentResolver().query(dataUri, null, null, null, null);
+ if (cursor == null) {
+ addRow("", "No data for this URI");
+ } else {
+ try {
+ while (cursor.moveToNext()) {
+ addRow("", "DATA");
+ String[] columnNames = cursor.getColumnNames();
+ String[] names = new String[columnNames.length];
+ System.arraycopy(columnNames, 0, names, 0, columnNames.length);
+ Arrays.sort(names);
+ for (int i = 0; i < names.length; i++) {
+ int index = cursor.getColumnIndex(names[i]);
+ String value = cursor.getString(index);
+ addRow(names[i], value);
+
+ if (names[i].equals(Contacts.PHOTO_ID) && !TextUtils.isEmpty(value)) {
+ addRowWithPhoto(Long.parseLong(value));
+ }
+ }
+ }
+ } finally {
+ cursor.close();
+ }
+ }
+ }
+
+ private void addRow(String column0, String column1) {
+ TextView label = new TextView(this);
+ label.setPadding(4, 4, 4, 4);
+ label.setText(column0);
+ TextView value = new TextView(this);
+ value.setPadding(4, 4, 4, 4);
+ value.setText(column1);
+ addRow(label, value);
+ }
+
+ private void addRowWithPhoto(long photoId) {
+ byte[] data = null;
+ Cursor cursor = getContentResolver().query(
+ ContentUris.withAppendedId(Data.CONTENT_URI, photoId),
+ new String[]{Photo.PHOTO}, null, null, null);
+ try {
+ if (cursor.moveToNext()) {
+ data = cursor.getBlob(0);
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+
+ if (data == null) {
+ return;
+ }
+
+ addRowWithBitmap("Photo", BitmapFactory.decodeByteArray(data, 0, data.length));
+ }
+
+ private void addRowWithBitmap(String label, Bitmap bitmap) {
+ TextView labelView = new TextView(this);
+ labelView.setPadding(4, 4, 4, 4);
+ labelView.setText(label);
+
+ ImageView imageView = new ImageView(this);
+ imageView.setImageBitmap(bitmap);
+ imageView.setPadding(4, 4, 4, 4);
+ imageView.setScaleType(ScaleType.FIT_START);
+ addRow(labelView, imageView);
+ }
+
+ private void addRow(View column0, View column1) {
+ TableLayout table = (TableLayout)findViewById(R.id.table);
+ TableRow row = new TableRow(this);
+ row.addView(column0);
+ row.addView(column1);
+ table.addView(row);
+
+ addSeparator(1);
+ }
+
+ private void addSeparator(int height) {
+ TableLayout table = (TableLayout)findViewById(R.id.table);
+ View separator = new View(this);
+ TableLayout.LayoutParams params = new TableLayout.LayoutParams();
+ params.height = height;
+ separator.setLayoutParams(params);
+ separator.setBackgroundColor(Color.rgb(33, 66, 33));
+ table.addView(separator);
+ }
+}