Make LIST_XXX intents open corresponding tab

Also, make Contacts Intents send the correct intent for LIST_DEFAULT.

Bug 5071627
Bug 5073681

Change-Id: Id28f85c0adef085417472c2211c29bcd5193aa58
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 579c833..b1b7e5e 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -104,7 +104,6 @@
         ContactListFilterController.ContactListFilterListener, ProviderStatusListener {
 
     private static final String TAG = "PeopleActivity";
-    private static final Boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE
 
     private static final int SUBACTIVITY_NEW_GROUP = 2;
     private static final int SUBACTIVITY_EDIT_GROUP = 3;
@@ -284,7 +283,7 @@
     private boolean processIntent(boolean forNewIntent) {
         // Extract relevant information from the intent
         mRequest = mIntentResolver.resolveIntent(getIntent());
-        if (DEBUG) {
+        if (Log.isLoggable(TAG, Log.DEBUG)) {
             Log.d(TAG, this + " processIntent: forNewIntent=" + forNewIntent
                     + " intent=" + getIntent() + " request=" + mRequest);
         }
@@ -485,14 +484,17 @@
             ContactListFilter filter = null;
             int actionCode = mRequest.getActionCode();
             boolean searchMode = mRequest.isSearchMode();
+            TabState tabToOpen = null;
             switch (actionCode) {
                 case ContactsRequest.ACTION_ALL_CONTACTS:
                     filter = ContactListFilter.createFilterWithType(
                             ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS);
+                    tabToOpen = TabState.ALL;
                     break;
                 case ContactsRequest.ACTION_CONTACTS_WITH_PHONES:
                     filter = ContactListFilter.createFilterWithType(
                             ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY);
+                    tabToOpen = TabState.ALL;
                     break;
 
                 // TODO: handle FREQUENT and STREQUENT according to the spec
@@ -502,11 +504,20 @@
                 case ContactsRequest.ACTION_STARRED:
                     filter = ContactListFilter.createFilterWithType(
                             ContactListFilter.FILTER_TYPE_STARRED);
+                    tabToOpen = TabState.FAVORITES;
                     break;
                 case ContactsRequest.ACTION_VIEW_CONTACT:
-                    if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
-                        mActionBarAdapter.setCurrentTab(TabState.ALL);
-                    }
+                    // We redirect this intent to the detail activity on 1-pane, so we don't get
+                    // here.  It's only for 2-pane.
+                    tabToOpen = TabState.ALL;
+                    break;
+                case ContactsRequest.ACTION_GROUP:
+                    tabToOpen = TabState.GROUPS;
+                    // TODO Select the specified group?  See the TODO in ContactsIntentResolver too.
+                    break;
+            }
+            if (tabToOpen != null) {
+                mActionBarAdapter.setCurrentTab(tabToOpen);
             }
 
             if (filter != null) {
diff --git a/src/com/android/contacts/list/ContactsIntentResolver.java b/src/com/android/contacts/list/ContactsIntentResolver.java
index 3ef68d8..63cadf1 100644
--- a/src/com/android/contacts/list/ContactsIntentResolver.java
+++ b/src/com/android/contacts/list/ContactsIntentResolver.java
@@ -72,6 +72,9 @@
             request.setActionCode(ContactsRequest.ACTION_STREQUENT);
         } else if (UI.LIST_GROUP_ACTION.equals(action)) {
             request.setActionCode(ContactsRequest.ACTION_GROUP);
+
+            // TODO Selecting a group is not implemented, but it doesn't seem to be used anywhere.
+            // Can we remove this?
             String groupName = intent.getStringExtra(UI.GROUP_NAME_EXTRA_KEY);
             if (!TextUtils.isEmpty(groupName)) {
                 request.setGroupName(groupName);
@@ -195,7 +198,6 @@
         if (title != null) {
             request.setActivityTitle(title);
         }
-
         return request;
     }
 }
diff --git a/tests/res/values/donottranslate_strings.xml b/tests/res/values/donottranslate_strings.xml
index 4d4d10b..528b129 100644
--- a/tests/res/values/donottranslate_strings.xml
+++ b/tests/res/values/donottranslate_strings.xml
@@ -27,6 +27,7 @@
         <item>LIST_STARRED_ACTION</item>
         <item>LIST_FREQUENT_ACTION</item>
         <item>LIST_STREQUENT_ACTION</item>
+        <item>LIST_GROUP_ACTION</item>
         <item>ACTION_PICK: contact</item>
         <item>ACTION_PICK: contact (legacy)</item>
         <item>ACTION_PICK: phone</item>
diff --git a/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java b/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java
index 8c37a02..e5e6a1c 100644
--- a/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java
+++ b/tests/src/com/android/contacts/tests/allintents/AllIntentsActivity.java
@@ -69,6 +69,7 @@
         LIST_STARRED_ACTION,
         LIST_FREQUENT_ACTION,
         LIST_STREQUENT_ACTION,
+        LIST_GROUP_ACTION,
         ACTION_PICK_CONTACT,
         ACTION_PICK_CONTACT_LEGACY,
         ACTION_PICK_PHONE,
@@ -142,7 +143,7 @@
         switch (ContactsIntent.get(position)) {
             case LIST_DEFAULT: {
                 startContactListActivity(
-                        new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));
+                        new Intent(UI.LIST_DEFAULT, Contacts.CONTENT_URI));
                 break;
             }
             case LIST_ALL_CONTACTS_ACTION: {
@@ -170,6 +171,11 @@
                         new Intent(UI.LIST_STREQUENT_ACTION, Contacts.CONTENT_URI));
                 break;
             }
+            case LIST_GROUP_ACTION: {
+                startContactListActivity(
+                        new Intent(UI.LIST_GROUP_ACTION, Contacts.CONTENT_URI));
+                break;
+            }
             case ACTION_PICK_CONTACT: {
                 startContactSelectionActivityForResult(
                         new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI));