Add view call history at bottom of recents

Bug: 13936108

Change-Id: Ic688d65240dada75b014b6684d4bebed208551bd
diff --git a/res/layout/recents_list_footer.xml b/res/layout/recents_list_footer.xml
new file mode 100644
index 0000000..48c0f36
--- /dev/null
+++ b/res/layout/recents_list_footer.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<!-- Text field and possibly soft menu button above the keypad where
+     the digits are displayed. -->
+
+<TextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/recents_list_footer"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingTop="20dp"
+    android:paddingBottom="20dp"
+    android:gravity="center"
+    android:textColor="@color/dialtacts_primary_text_color"
+    android:textSize="14sp"
+    android:text="@string/recents_footer_text"
+    android:background="?android:attr/selectableItemBackground" />
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index cbd116d..53ff534 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -15,9 +15,9 @@
 -->
 
 <resources>
-
-    <!-- Secondary text color in the Phone app -->
+    <!--  Primary text color in the Dialer -->
     <color name="dialtacts_primary_text_color">#000000</color>
+    <!-- Secondary text color in the Dialer -->
     <color name="dialtacts_secondary_text_color">#888888</color>
 
     <!-- Background color of dialpad -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 07dfd81..bd9aefb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -725,6 +725,9 @@
     <!-- Shortcut item used to add a number directly from search -->
     <string name="search_shortcut_add_to_contacts">Add to contacts</string>
 
+    <!-- Title for the recent calls footer that brings users to the full call history when clicked -->
+    <string name="recents_footer_text">View full call history</string>
+
     <!-- Number of missed calls shown on call card [CHAR LIMIT=40] -->
     <string name="num_missed_calls"><xliff:g id="number">%s</xliff:g> new missed calls</string>
 
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 2d5df2b..c449e09 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -94,6 +94,7 @@
         DialpadFragment.OnDialpadQueryChangedListener,
         OnListFragmentScrolledListener,
         DialpadFragment.HostInterface,
+        ListsFragment.HostInterface,
         PhoneFavoriteFragment.HostInterface,
         OnDragDropListener, View.OnLongClickListener,
         OnPhoneNumberPickerActionListener {
@@ -427,10 +428,7 @@
                 showDialpadFragment(true);
                 break;
             case R.id.call_history_button:
-                // Use explicit CallLogActivity intent instead of ACTION_VIEW +
-                // CONTENT_TYPE, so that we always open our call log from our dialer
-                final Intent intent = new Intent(this, CallLogActivity.class);
-                startActivity(intent);
+                showCallHistory();
                 break;
             case R.id.dial_button:
                 // Dial button was pressed; tell the Dialpad fragment
@@ -463,10 +461,7 @@
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.menu_history:
-                // Use explicit CallLogActivity intent instead of ACTION_VIEW +
-                // CONTENT_TYPE, so that we always open our call log from our dialer
-                final Intent intent = new Intent(this, CallLogActivity.class);
-                startActivity(intent);
+                showCallHistory();
                 break;
             case R.id.menu_add_contact:
                 try {
@@ -912,6 +907,14 @@
         return resolveInfo != null && resolveInfo.size() > 0;
     }
 
+    @Override
+    public void showCallHistory() {
+        // Use explicit CallLogActivity intent instead of ACTION_VIEW +
+        // CONTENT_TYPE, so that we always open our call log from our dialer
+        final Intent intent = new Intent(this, CallLogActivity.class);
+        startActivity(intent);
+    }
+
     /**
      * Called when the user has long-pressed a contact tile to start a drag operation.
      */
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 84d55d1..2ab6136 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -30,7 +30,6 @@
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract;
 import android.provider.VoicemailContract.Status;
-import android.telephony.TelephonyManager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -75,6 +74,7 @@
     private TextView mStatusMessageText;
     private TextView mStatusMessageAction;
     private KeyguardManager mKeyguardManager;
+    private View mFooterView;
 
     private boolean mEmptyLoaderRunning;
     private boolean mCallLogFetched;
@@ -252,6 +252,7 @@
         mStatusMessageView = view.findViewById(R.id.voicemail_status);
         mStatusMessageText = (TextView) view.findViewById(R.id.voicemail_status_message);
         mStatusMessageAction = (TextView) view.findViewById(R.id.voicemail_status_action);
+
         return view;
     }
 
@@ -260,6 +261,7 @@
         super.onViewCreated(view, savedInstanceState);
         updateEmptyMessage(mCallTypeFilter);
         getListView().setItemsCanFocus(true);
+        assignFooterViewToListView();
     }
 
     /**
@@ -479,4 +481,27 @@
             CallLogNotificationsHelper.updateVoicemailNotifications(getActivity());
         }
     }
+
+    /**
+     * Assigns a view to be used as a footer view in the call log.
+     *
+     * @param view View to be used as the footer view.
+     */
+    public void setFooterView(View view) {
+        mFooterView = view;
+        // Content view not created yet, defer addition of the footerview to onCreate
+        if (getView() == null) {
+            return;
+        }
+        assignFooterViewToListView();
+    }
+
+    private void assignFooterViewToListView() {
+        if (mFooterView == null) {
+            return;
+        }
+        final ListView listView = getListView();
+        listView.removeFooterView(mFooterView);
+        listView.addFooterView(mFooterView);
+    }
 }
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java
index 3144b86..b91f09a 100644
--- a/src/com/android/dialer/list/ListsFragment.java
+++ b/src/com/android/dialer/list/ListsFragment.java
@@ -22,6 +22,8 @@
 
 import com.android.contacts.common.GeoUtil;
 import com.android.dialer.DialtactsActivity;
+import android.view.View.OnClickListener;
+
 import com.android.dialer.R;
 import com.android.dialer.calllog.CallLogAdapter;
 import com.android.dialer.calllog.CallLogFragment;
@@ -47,8 +49,9 @@
 
     private static final int TAB_INDEX_COUNT = 3;
 
-    // TODO: Replace with a date limit (e.g. 2 weeks)
-    private static final int MAX_ENTRIES = 20;
+    private static final int MAX_RECENTS_ENTRIES = 20;
+    // Oldest recents entry to display is 2 weeks old.
+    private static final long OLDEST_RECENTS_DATE = 1000L * 60 * 60 * 24 * 14;
 
     private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE =
             "key_last_dismissed_call_shortcut_date";
@@ -56,6 +59,10 @@
     // Used with LoaderManager
     private static int MISSED_CALL_LOADER = 1;
 
+    public interface HostInterface {
+        public void showCallHistory();
+    }
+
     private ViewPager mViewPager;
     private ViewPagerAdapter mViewPagerAdapter;
     private PhoneFavoriteFragment mSpeedDialFragment;
@@ -113,7 +120,25 @@
                     return mSpeedDialFragment;
                 case TAB_INDEX_RECENTS:
                     mRecentsFragment = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL,
-                            MAX_ENTRIES);
+                            MAX_RECENTS_ENTRIES, System.currentTimeMillis() - OLDEST_RECENTS_DATE);
+
+                    /*
+                     * Provide mViewPager as a parent viewgroup for the inflation of the footer,
+                     * to ensure that the footer view is inflated with the correct LayoutParams.
+                     * If root is null in
+                     * inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot),
+                     * the layout parameters specified in R.layout.recents_list_footer are not
+                     * correctly applied. The footer view is ultimately not attached to mViewPager.
+                     */
+                    final View viewFullHistoryFooter = getActivity().getLayoutInflater().inflate(
+                            R.layout.recents_list_footer, mViewPager, false);
+                    viewFullHistoryFooter.setOnClickListener(new OnClickListener() {
+                        @Override
+                        public void onClick(View v) {
+                            ((HostInterface) getActivity()).showCallHistory();
+                        }
+                    });
+                    mRecentsFragment.setFooterView(viewFullHistoryFooter);
                     return mRecentsFragment;
                 case TAB_INDEX_ALL_CONTACTS:
                     mAllContactsFragment = new AllContactsFragment();