Add a proxy activity that loads the right UI base on screen properties.

Change-Id: If6ae100f02a024006a541f02dabaf98ade89ab5d
diff --git a/src/com/android/contacts/DialtactsActivity.java b/src/com/android/contacts/DialtactsActivity.java
index afb8606..758a3b5 100644
--- a/src/com/android/contacts/DialtactsActivity.java
+++ b/src/com/android/contacts/DialtactsActivity.java
@@ -16,6 +16,7 @@
 
 package com.android.contacts;
 
+import com.android.contacts.activities.ContactsFrontDoor;
 import com.android.internal.telephony.ITelephony;
 
 import android.app.Activity;
@@ -228,25 +229,24 @@
         final int savedTabIndex = mLastManuallySelectedTab;
 
         // Choose the tab based on the inbound intent
-        String componentName = intent.getComponent().getClassName();
-        if (getClass().getName().equals(componentName)) {
-            if (recentCallsRequest) {
-                mTabHost.setCurrentTab(TAB_INDEX_CALL_LOG);
-            } else {
-                mTabHost.setCurrentTab(TAB_INDEX_DIALER);
-            }
-        } else if (FAVORITES_ENTRY_COMPONENT.equals(componentName)) {
-            mTabHost.setCurrentTab(TAB_INDEX_FAVORITES);
-        } else if (CONTACTS_LAUNCH_ACTIVITY.equals(componentName)) {
-            mTabHost.setCurrentTab(mLastManuallySelectedTab);
+        if (intent.getBooleanExtra(ContactsFrontDoor.EXTRA_FRONT_DOOR, false)) {
+            // Launched through the contacts front door, set the proper contacts tab
+            setContactsTab();
         } else {
-            SharedPreferences prefs = getSharedPreferences(PREFS_DIALTACTS, MODE_PRIVATE);
-            boolean favoritesAsContacts = prefs.getBoolean(PREF_FAVORITES_AS_CONTACTS,
-                    PREF_FAVORITES_AS_CONTACTS_DEFAULT);
-            if (favoritesAsContacts) {
+            // Not launched through the front door, look at the component to determine the tab
+            String componentName = intent.getComponent().getClassName();
+            if (getClass().getName().equals(componentName)) {
+                if (recentCallsRequest) {
+                    mTabHost.setCurrentTab(TAB_INDEX_CALL_LOG);
+                } else {
+                    mTabHost.setCurrentTab(TAB_INDEX_DIALER);
+                }
+            } else if (FAVORITES_ENTRY_COMPONENT.equals(componentName)) {
                 mTabHost.setCurrentTab(TAB_INDEX_FAVORITES);
+            } else if (CONTACTS_LAUNCH_ACTIVITY.equals(componentName)) {
+                mTabHost.setCurrentTab(mLastManuallySelectedTab);
             } else {
-                mTabHost.setCurrentTab(TAB_INDEX_CONTACTS);
+                setContactsTab();
             }
         }
 
@@ -258,6 +258,17 @@
         intent.putExtra(EXTRA_IGNORE_STATE, false);
     }
 
+    private void setContactsTab() {
+        SharedPreferences prefs = getSharedPreferences(PREFS_DIALTACTS, MODE_PRIVATE);
+        boolean favoritesAsContacts = prefs.getBoolean(PREF_FAVORITES_AS_CONTACTS,
+                PREF_FAVORITES_AS_CONTACTS_DEFAULT);
+        if (favoritesAsContacts) {
+            mTabHost.setCurrentTab(TAB_INDEX_FAVORITES);
+        } else {
+            mTabHost.setCurrentTab(TAB_INDEX_CONTACTS);
+        }
+    }
+
     @Override
     public void onNewIntent(Intent newIntent) {
         setIntent(newIntent);
diff --git a/src/com/android/contacts/activities/ContactsFrontDoor.java b/src/com/android/contacts/activities/ContactsFrontDoor.java
new file mode 100644
index 0000000..773e135
--- /dev/null
+++ b/src/com/android/contacts/activities/ContactsFrontDoor.java
@@ -0,0 +1,52 @@
+/*
+ * 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.activities;
+
+import com.android.contacts.DialtactsActivity;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+
+public class ContactsFrontDoor extends Activity {
+    public static final String EXTRA_FRONT_DOOR = "front_door";
+
+    @Override
+    public void onCreate(Bundle savedState) {
+        super.onCreate(savedState);
+
+        Intent intent = new Intent();
+        intent.setFlags(
+                Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+        intent.putExtra(EXTRA_FRONT_DOOR, true);
+
+        // The user launched the config based front door, pick the right activity to go to
+        Configuration config = getResources().getConfiguration();
+        int screenLayoutSize = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
+        if (screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
+            // XL screen, use two pane UI
+            intent.setClass(this, TwoPaneActivity.class);
+        } else {
+            // Default to the normal dialtacts layout
+            intent.setClass(this, DialtactsActivity.class);
+        }
+
+        startActivity(intent);
+        finish();
+    }
+}