Improve D-Pad accessiblity of the call details.

We are doing something fancy with the layout, to scroll the header when
the list view is scrolled: a list view is shown under the controls, with
a first header item which is invisible as it is behind the controls; the
controls are then scrolled up when the list is scrolled. This is similar
to what is done in the tab carousel in the contact details/updates.

Unfortunately, this broke the accessibility of the call details.

In this commit I have a partial fix: whenever the hidden header is
focused, focus is transfered to the controls. This makes the history
items not accessible, but makes the more crucial controls accessible
again.

Bug: 5323306
Change-Id: I342e58b9052e2aba3d5d8c8ea1b178108741de91
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index b7ccffc..8d7561a 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -507,7 +507,8 @@
                 ListView historyList = (ListView) findViewById(R.id.history);
                 historyList.setAdapter(
                         new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
-                                mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo));
+                                mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
+                                findViewById(R.id.controls)));
                 BackScrollManager.bind(
                         new ScrollableHeader() {
                             private View controls = findViewById(R.id.controls);
diff --git a/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java b/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
index ed9c2e0..22b85d7 100644
--- a/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
+++ b/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
@@ -45,16 +45,30 @@
     private final boolean mShowVoicemail;
     /** Whether the call and SMS controls are shown. */
     private final boolean mShowCallAndSms;
+    /** The controls that are shown on top of the history list. */
+    private final View mControls;
+    /** The listener to changes of focus of the header. */
+    private View.OnFocusChangeListener mHeaderFocusChangeListener =
+            new View.OnFocusChangeListener() {
+        @Override
+        public void onFocusChange(View v, boolean hasFocus) {
+            // When the header is focused, focus the controls above it instead.
+            if (hasFocus) {
+                mControls.requestFocus();
+            }
+        }
+    };
 
     public CallDetailHistoryAdapter(Context context, LayoutInflater layoutInflater,
             CallTypeHelper callTypeHelper, PhoneCallDetails[] phoneCallDetails,
-            boolean showVoicemail, boolean showCallAndSms) {
+            boolean showVoicemail, boolean showCallAndSms, View controls) {
         mContext = context;
         mLayoutInflater = layoutInflater;
         mCallTypeHelper = callTypeHelper;
         mPhoneCallDetails = phoneCallDetails;
         mShowVoicemail = showVoicemail;
         mShowCallAndSms = showCallAndSms;
+        mControls = controls;
     }
 
     @Override
@@ -103,6 +117,8 @@
             // Call and SMS controls are only shown in the main UI if there is a known number.
             View callAndSmsContainer = header.findViewById(R.id.header_call_and_sms_container);
             callAndSmsContainer.setVisibility(mShowCallAndSms ? View.VISIBLE : View.GONE);
+            header.setFocusable(true);
+            header.setOnFocusChangeListener(mHeaderFocusChangeListener);
             return header;
         }