Add landscape dialer for Contacts (Phone) app when in car dock.

Bug: 5566469
Change-Id: I080bd22b3983409e6432e1d78cb693135af9503c
diff --git a/src/com/android/contacts/ContactsUtils.java b/src/com/android/contacts/ContactsUtils.java
index e8aa1ae..15b33ab 100644
--- a/src/com/android/contacts/ContactsUtils.java
+++ b/src/com/android/contacts/ContactsUtils.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Rect;
 import android.location.CountryDetector;
@@ -331,4 +332,12 @@
         }
         return sThumbnailSize;
     }
+
+    /**
+     * @return if the context is in landscape orientation.
+     */
+    public static boolean isLandscape(Context context) {
+        return context.getResources().getConfiguration().orientation
+                == Configuration.ORIENTATION_LANDSCAPE;
+    }
 }
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index b71f15a..ea68407 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -1021,7 +1021,8 @@
         } else {
             // This is when the user is looking at the dialer pad.  In this case, the real
             // ActionBar is hidden and fake menu items are shown.
-            searchMenuItem.setVisible(false);
+            // Except in landscape, in which case the real search menu item is shown.
+            searchMenuItem.setVisible(ContactsUtils.isLandscape(this));
             // If a permanent menu key is available, then we need to show the call settings item
             // so that the call settings item can be invoked by the permanent menu key.
             callSettingsMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
@@ -1224,6 +1225,7 @@
      * @param visible True when visible.
      */
     private void updateFakeMenuButtonsVisibility(boolean visible) {
+        // Note: Landscape mode does not have the fake menu and search buttons.
         if (DEBUG) {
             Log.d(TAG, "updateFakeMenuButtonVisibility(" + visible + ")");
         }
diff --git a/src/com/android/contacts/dialpad/DialpadFragment.java b/src/com/android/contacts/dialpad/DialpadFragment.java
index a853711..6ba4178 100644
--- a/src/com/android/contacts/dialpad/DialpadFragment.java
+++ b/src/com/android/contacts/dialpad/DialpadFragment.java
@@ -288,7 +288,9 @@
         int cellCount = dm.widthPixels / minCellSize;
         int fakeMenuItemWidth = dm.widthPixels / cellCount;
         mDialButtonContainer = fragmentView.findViewById(R.id.dialButtonContainer);
-        if (mDialButtonContainer != null) {
+        // If in portrait, add padding to the dial button since we need space for the
+        // search and menu/overflow buttons.
+        if (mDialButtonContainer != null && !ContactsUtils.isLandscape(this.getActivity())) {
             mDialButtonContainer.setPadding(
                     fakeMenuItemWidth, mDialButtonContainer.getPaddingTop(),
                     fakeMenuItemWidth, mDialButtonContainer.getPaddingBottom());
@@ -621,7 +623,10 @@
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         super.onCreateOptionsMenu(menu, inflater);
-        if (ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
+        // Landscape dialer uses the real actionbar menu, whereas portrait uses a fake one
+        // that is created using constructPopupMenu()
+        if (ContactsUtils.isLandscape(this.getActivity()) ||
+                ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
                 isLayoutReady() && mDialpadChooser != null) {
             inflater.inflate(R.menu.dialpad_options, menu);
         }
@@ -630,9 +635,10 @@
     @Override
     public void onPrepareOptionsMenu(Menu menu) {
         // Hardware menu key should be available and Views should already be ready.
-        if (ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
+        if (ContactsUtils.isLandscape(this.getActivity()) ||
+                ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
                 isLayoutReady() && mDialpadChooser != null) {
-             setupMenuItems(menu);
+            setupMenuItems(menu);
         }
     }