Adding more call log filter buttons.

Adding missed, outgoing, incoming buttons to complement existing
voicemail button.

Change-Id: I43c2a5675783b8a32e4db45b39c64b5496f09e53
diff --git a/res/menu/call_log_options.xml b/res/menu/call_log_options.xml
index c41f9da..d393a9e 100644
--- a/res/menu/call_log_options.xml
+++ b/res/menu/call_log_options.xml
@@ -16,20 +16,44 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item
-        android:id="@+id/show_voicemails_only"
-        android:title="@string/menu_show_voicemails_only"
-        android:showAsAction="withText"
-        android:orderInCategory="1" />
+            android:id="@+id/show_all_calls"
+            android:title="@string/menu_show_all_calls"
+            android:icon="@drawable/quickcon_background_texture"
+            android:showAsAction="ifRoom"
+            android:orderInCategory="1"/>
 
     <item
-        android:id="@+id/show_all_calls"
-        android:title="@string/menu_show_all_calls"
-        android:showAsAction="withText"
-        android:orderInCategory="1" />
+            android:id="@+id/show_voicemails_only"
+            android:title="@string/menu_show_voicemails_only"
+            android:icon="@drawable/ic_call_voicemail_holo_dark"
+            android:showAsAction="ifRoom"
+            android:orderInCategory="1"/>
 
     <item
-        android:id="@+id/delete_all"
-        android:title="@string/recentCalls_deleteAll"
-        android:showAsAction="withText"
-        android:orderInCategory="1" />
+            android:id="@+id/show_missed_only"
+            android:title="@string/menu_show_missed_only"
+            android:icon="@drawable/ic_call_missed_holo_dark"
+            android:showAsAction="ifRoom"
+            android:orderInCategory="1"/>
+
+    <item
+            android:id="@+id/show_outgoing_only"
+            android:title="@string/menu_show_outgoing_only"
+            android:icon="@drawable/ic_call_outgoing_holo_dark"
+            android:showAsAction="ifRoom"
+            android:orderInCategory="1"/>
+
+    <item
+            android:id="@+id/show_incoming_only"
+            android:title="@string/menu_show_incoming_only"
+            android:icon="@drawable/ic_call_incoming_holo_dark"
+            android:showAsAction="ifRoom"
+            android:orderInCategory="1"/>
+
+
+    <item
+            android:id="@+id/delete_all"
+            android:title="@string/recentCalls_deleteAll"
+            android:showAsAction="withText"
+            android:orderInCategory="1"/>
 </menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a924648..3b5ccd1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1651,6 +1651,15 @@
     <!-- The "file name" displayed for vCards received directly via NFC [CHAR LIMIT=16] -->
     <string name="nfc_vcard_file_name">Contact received over NFC</string>
 
+    <!-- Menu item used to show only outgoing in the call log. [CHAR LIMIT=30] -->
+    <string name="menu_show_outgoing_only">Show outgoing only</string>
+
+    <!-- Menu item used to show only incoming in the call log. [CHAR LIMIT=30] -->
+    <string name="menu_show_incoming_only">Show incoming only</string>
+
+    <!-- Menu item used to show only missed in the call log. [CHAR LIMIT=30] -->
+    <string name="menu_show_missed_only">Show missed only</string>
+
     <!-- Menu item used to show only voicemails in the call log. [CHAR LIMIT=30] -->
     <string name="menu_show_voicemails_only">Show voicemails only</string>
 
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index b71f15a..2e35213 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -1017,7 +1017,7 @@
             // When there is a permanent menu key, there is no overflow icon on the right of
             // the action bar which would force the search menu item (if it is visible) to the
             // left.  This is the purpose of showing the emptyRightMenuItem.
-            emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
+            emptyRightMenuItem.setVisible(false);
         } 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.
@@ -1038,11 +1038,11 @@
         final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);
 
         // prepare the menu items
-        searchMenuItem.setVisible(true);
+        searchMenuItem.setVisible(false);
         filterOptionMenuItem.setVisible(false);
         addContactOptionMenuItem.setVisible(false);
         callSettingsMenuItem.setVisible(true);
-        emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
+        emptyRightMenuItem.setVisible(false);
     }
 
     private void prepareOptionsMenuForFavoritesTab(Menu menu) {
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index f04a2f3..739cf35 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -331,10 +331,7 @@
         // menu items are ready if the first item is non-null.
         if (itemDeleteAll != null) {
             itemDeleteAll.setEnabled(mAdapter != null && !mAdapter.isEmpty());
-            menu.findItem(R.id.show_voicemails_only).setVisible(
-                    mVoicemailSourcesAvailable && !mShowingVoicemailOnly);
-            menu.findItem(R.id.show_all_calls).setVisible(
-                    mVoicemailSourcesAvailable && mShowingVoicemailOnly);
+            menu.findItem(R.id.show_voicemails_only).setVisible(mVoicemailSourcesAvailable);
         }
     }
 
@@ -345,6 +342,21 @@
                 ClearCallLogDialog.show(getFragmentManager());
                 return true;
 
+            case R.id.show_outgoing_only:
+                mCallLogQueryHandler.fetchOutgoing();
+
+                return true;
+
+            case R.id.show_incoming_only:
+                mCallLogQueryHandler.fetchIncoming();
+
+                return true;
+
+            case R.id.show_missed_only:
+                mCallLogQueryHandler.fetchMissed();
+
+                return true;
+
             case R.id.show_voicemails_only:
                 mCallLogQueryHandler.fetchVoicemailOnly();
                 mShowingVoicemailOnly = true;
diff --git a/src/com/android/contacts/calllog/CallLogQueryHandler.java b/src/com/android/contacts/calllog/CallLogQueryHandler.java
index ba604cd..3ef2f7d 100644
--- a/src/com/android/contacts/calllog/CallLogQueryHandler.java
+++ b/src/com/android/contacts/calllog/CallLogQueryHandler.java
@@ -29,6 +29,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
+import android.provider.CallLog;
 import android.provider.CallLog.Calls;
 import android.provider.VoicemailContract.Status;
 import android.util.Log;
@@ -159,8 +160,8 @@
     public void fetchAllCalls() {
         cancelFetch();
         int requestId = newCallsRequest();
-        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, false /*voicemailOnly*/);
-        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, false /*voicemailOnly*/);
+        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, -1 /*callType*/);
+        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, -1 /*callType*/);
     }
 
     /**
@@ -171,10 +172,30 @@
     public void fetchVoicemailOnly() {
         cancelFetch();
         int requestId = newCallsRequest();
-        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, true /*voicemailOnly*/);
-        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, true /*voicemailOnly*/);
+        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, Calls.VOICEMAIL_TYPE);
+        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, Calls.VOICEMAIL_TYPE);
     }
 
+    public void fetchOutgoing() {
+        cancelFetch();
+        int requestId = newCallsRequest();
+        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, Calls.OUTGOING_TYPE);
+        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, Calls.OUTGOING_TYPE);
+    }
+
+    public void fetchIncoming() {
+        cancelFetch();
+        int requestId = newCallsRequest();
+        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, Calls.INCOMING_TYPE);
+        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, Calls.INCOMING_TYPE);
+    }
+
+    public void fetchMissed() {
+        cancelFetch();
+        int requestId = newCallsRequest();
+        fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, Calls.MISSED_TYPE);
+        fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, Calls.MISSED_TYPE);
+    }
 
     public void fetchVoicemailStatus() {
         startQuery(QUERY_VOICEMAIL_STATUS_TOKEN, null, Status.CONTENT_URI,
@@ -182,7 +203,7 @@
     }
 
     /** Fetches the list of calls in the call log, either the new one or the old ones. */
-    private void fetchCalls(int token, int requestId, boolean isNew, boolean voicemailOnly) {
+    private void fetchCalls(int token, int requestId, boolean isNew, int callType) {
         // We need to check for NULL explicitly otherwise entries with where READ is NULL
         // may not match either the query or its negation.
         // We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new".
@@ -194,10 +215,10 @@
             // Negate the query.
             selection = String.format("NOT (%s)", selection);
         }
-        if (voicemailOnly) {
+        if (callType > 0) {
             // Add a clause to fetch only items of type voicemail.
             selection = String.format("(%s) AND (%s = ?)", selection, Calls.TYPE);
-            selectionArgs.add(Integer.toString(Calls.VOICEMAIL_TYPE));
+            selectionArgs.add(Integer.toString(callType));
         }
         startQuery(token, requestId, Calls.CONTENT_URI_WITH_VOICEMAIL,
                 CallLogQuery._PROJECTION, selection, selectionArgs.toArray(EMPTY_STRING_ARRAY),