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

Bug: 5566469
Change-Id: I080bd22b3983409e6432e1d78cb693135af9503c
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 996bc78..babd439 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -121,7 +121,7 @@
             android:launchMode="singleTask"
             android:clearTaskOnLaunch="true"
             android:icon="@mipmap/ic_launcher_phone"
-            android:screenOrientation="portrait"
+            android:screenOrientation="nosensor"
             android:enabled="@*android:bool/config_voice_capable"
             android:taskAffinity="android.task.contacts.phone"
             android:windowSoftInputMode="stateAlwaysHidden|adjustNothing">
@@ -464,7 +464,7 @@
         <activity android:name="CallDetailActivity"
             android:label="@string/callDetailTitle"
             android:theme="@style/CallDetailActivityTheme"
-            android:screenOrientation="nosensor"
+            android:screenOrientation="portrait"
             android:icon="@mipmap/ic_launcher_phone"
             android:taskAffinity="android.task.contacts.phone"
         >
diff --git a/res/layout-land/dialpad_fragment.xml b/res/layout-land/dialpad_fragment.xml
index c5f3056..63dd369 100644
--- a/res/layout-land/dialpad_fragment.xml
+++ b/res/layout-land/dialpad_fragment.xml
@@ -17,41 +17,81 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/top"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
->
+    android:layout_height="match_parent" >
 
-    <!-- Text field above the keypad where the digits are displayed.
-         It's type is set to PHONE (to put the keyboard in the right
-         config) in the java code.
-    -->
-    <!-- TODO: Use a textAppearance to control the display of the number -->
-    <EditText android:id="@+id/digits"
-        android:layout_width="match_parent"
-        android:layout_height="@dimen/dialpad_digits_height"
-        android:layout_marginBottom="@dimen/dialpad_digits_margin_bottom"
-        android:layout_marginTop="1dip"
-        android:gravity="center"
-        android:maxLines="1"
-        android:scrollHorizontally="true"
-        android:textSize="@dimen/dialpad_digits_text_size"
-        android:freezesText="true"
-        android:background="@drawable/dialpad_background"
-        android:textColor="@color/dialer_button_text"
-        android:hint="@string/dialerKeyboardHintText"
-     />
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="3"
+        android:orientation="vertical" >
 
-    <!-- Horizontal row of buttons (Voicemail + DialButton + Delete.) -->
-    <include layout="@layout/dialpad_additional_buttons" />
+        <LinearLayout
+            android:id="@+id/digits_container"
+            android:layout_width="match_parent"
+            android:layout_height="0px"
+            android:layout_weight="@integer/dialpad_layout_weight_digits"
+            android:layout_marginTop="@dimen/dialpad_vertical_margin"
+            android:background="@drawable/dialpad_background"
+            android:gravity="center">
 
-    <!-- "Dialpad chooser" UI, shown only when the user brings up the
+            <com.android.contacts.dialpad.DigitsEditText
+                android:id="@+id/digits"
+                android:layout_width="0dip"
+                android:layout_weight="1"
+                android:layout_height="match_parent"
+                android:gravity="center"
+                android:textAppearance="@style/DialtactsDigitsTextAppearance"
+                android:textColor="?android:attr/textColorPrimary"
+                android:nextFocusRight="@+id/overflow_menu"
+                android:background="@android:color/transparent" />
+
+            <ImageButton
+                android:id="@+id/deleteButton"
+                android:layout_width="56dip"
+                android:layout_height="match_parent"
+                android:layout_gravity="center_vertical"
+                android:gravity="center"
+                android:state_enabled="false"
+                android:background="?android:attr/selectableItemBackground"
+                android:contentDescription="@string/description_delete_button"
+                android:src="@drawable/ic_dial_action_delete" />
+
+
+        </LinearLayout>
+        <!-- "Dialpad chooser" UI, shown only when the user brings up the
          Dialer while a call is already in progress.
          When this UI is visible, the other Dialer elements
          (the textfield and button) are hidden. -->
-    <ListView android:id="@+id/dialpadChooser"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:footerDividersEnabled="true"
-    />
+        <ListView android:id="@+id/dialpadChooser"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:footerDividersEnabled="true" />
 
+        <!-- Keypad section -->
+        <include layout="@layout/dialpad" />
+    </LinearLayout>
+    <View
+       android:layout_width="@dimen/dialpad_center_margin"
+       android:layout_height="match_parent"
+       android:background="#66000000"/>
+    <RelativeLayout
+        android:id="@+id/dialButtonContainer"
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="2"
+        android:background="@drawable/dialpad_background">
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/dialpad_button_margin"
+            android:layout_above="@id/dialButton"
+            android:background="#33000000" />
+        <ImageButton android:id="@+id/dialButton"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/call_button_height"
+            android:layout_alignParentBottom="true"
+            android:state_enabled="false"
+            android:background="@drawable/btn_call"
+            android:contentDescription="@string/description_dial_button"
+            android:src="@drawable/ic_dial_action_call" />
+    </RelativeLayout>
 </LinearLayout>
diff --git a/res/layout-land/dialtacts_activity.xml b/res/layout-land/dialtacts_activity.xml
new file mode 100644
index 0000000..f43fe5f
--- /dev/null
+++ b/res/layout-land/dialtacts_activity.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_marginTop="?android:attr/actionBarSize"
+    android:id="@+id/dialtacts_frame"
+    >
+    <android.support.v4.view.ViewPager
+        android:id="@+id/pager"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+</FrameLayout>
diff --git a/res/layout/call_log_fragment.xml b/res/layout/call_log_fragment.xml
index 5e7061c..34b4b7f 100644
--- a/res/layout/call_log_fragment.xml
+++ b/res/layout/call_log_fragment.xml
@@ -16,10 +16,10 @@
 
 <!-- Layout parameters are set programmatically. -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/FragmentActionBarPadding"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
-    android:paddingBottom="?android:attr/actionBarSize"
     android:divider="?android:attr/dividerHorizontal"
     android:showDividers="end">
 
@@ -27,8 +27,6 @@
         android:id="@+id/voicemail_status"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentBottom="true"
         android:visibility="gone">
         <include layout="@layout/call_log_voicemail_status"
     />
diff --git a/res/layout/dialpad_additional_buttons.xml b/res/layout/dialpad_additional_buttons.xml
deleted file mode 100644
index 392f97a..0000000
--- a/res/layout/dialpad_additional_buttons.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<!-- Horizontal row of buttons (Voicemail + DialButton + Delete.) -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/dialpadAdditionalButtons"
-    android:layout_width="match_parent"
-    android:layout_height="0px"
-    android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"
-    android:layout_gravity="center_horizontal"
-    android:background="@drawable/dialpad_background"
-    android:orientation="horizontal">
-
-    <!-- Onscreen "All contacts" button.
-         TODO: rename this id. -->
-    <ImageButton android:id="@+id/searchButton"
-        android:layout_width="0px"
-        android:layout_weight="0.30"
-        android:layout_height="match_parent"
-        android:layout_gravity="center_vertical"
-        android:state_enabled="false"
-        android:background="?android:attr/selectableItemBackground"
-        android:contentDescription="@string/description_search_button"
-        android:src="@drawable/ic_dial_action_search"/>
-
-    <View
-        android:layout_width="1dip"
-        android:layout_height="24dip"
-        android:layout_gravity="center_vertical"
-        android:background="?android:attr/dividerVertical" />
-
-    <!-- Onscreen "Dial" button, diused on all platforms by
-         default. Its usage can be disabled using resources (see
-         config.xml.) -->
-    <ImageButton android:id="@+id/dialButton"
-        android:layout_width="0px"
-        android:layout_weight="0.40"
-        android:layout_height="match_parent"
-        android:layout_gravity="center_vertical"
-        android:state_enabled="false"
-        android:background="@drawable/btn_call"
-        android:contentDescription="@string/description_dial_button"
-        android:src="@drawable/ic_dial_action_call" />
-
-    <View
-        android:layout_width="1dip"
-        android:layout_height="24dip"
-        android:layout_gravity="center_vertical"
-        android:background="?android:attr/dividerVertical" />
-
-    <!-- Onscreen "Backspace/Delete" button -->
-    <ImageButton android:id="@+id/deleteButton"
-        android:layout_width="0px"
-        android:layout_weight="0.30"
-        android:layout_height="match_parent"
-        android:layout_gravity="center_vertical"
-        android:state_enabled="false"
-        android:background="?android:attr/selectableItemBackground"
-        android:contentDescription="@string/description_delete_button"
-        android:src="@drawable/ic_dial_action_delete" />
-</LinearLayout>
-
diff --git a/res/layout/phone_contact_tile_list.xml b/res/layout/phone_contact_tile_list.xml
index 57dd66c..8931cf6 100644
--- a/res/layout/phone_contact_tile_list.xml
+++ b/res/layout/phone_contact_tile_list.xml
@@ -17,10 +17,10 @@
 <!-- Use LinearLayout + FrameLayout, just to rely on android:divider and android:showDividers -->
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/FragmentActionBarPadding"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
-    android:paddingBottom="?android:attr/actionBarSize"
     android:divider="?android:attr/dividerHorizontal"
     android:showDividers="end">
     <FrameLayout
diff --git a/res/values-land/styles.xml b/res/values-land/styles.xml
index dab7802..e1d8a49 100644
--- a/res/values-land/styles.xml
+++ b/res/values-land/styles.xml
@@ -24,4 +24,8 @@
         <item name="android:layout_height">0dip</item>
         <item name="android:layout_weight">1</item>
     </style>
+
+    <style name="FragmentActionBarPadding">
+        <item name="android:paddingBottom">0dp</item>
+    </style>
 </resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 5037279..94faf49 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -168,6 +168,10 @@
     <!-- Just used in landscape mode -->
     <dimen name="dialpad_digits_height">0px</dimen>
     <dimen name="dialpad_digits_margin_bottom">0px</dimen>
+    <dimen name="dialpad_center_margin">3dp</dimen>
+    <dimen name="dialpad_button_margin">2dp</dimen>
+    <!-- Match call_button_height to Phone's dimens/in_call_end_button_height -->
+    <dimen name="call_button_height">74dp</dimen>
 
     <!-- Width of search view in action bar.  Use 0dip for MATCH_PARENT -->
     <dimen name="search_view_width">0dip</dimen>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6a7bd6f..ad8d07b 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -356,4 +356,8 @@
         <item name="android:textColor">#cdffffff</item>
         <item name="android:textSize">18sp</item>
     </style>
+
+    <style name="FragmentActionBarPadding">
+        <item name="android:paddingBottom">?android:attr/actionBarSize</item>
+    </style>
 </resources>
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);
         }
     }