Move delete and edit number to overflow menu.

Bug: 5035685
Bug: 5036100
Change-Id: I503d0bcf978b34aa559d517ff8d693b597121703
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index 324ab20..68c9f61 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -45,6 +45,8 @@
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
@@ -99,6 +101,11 @@
     private TextView mStatusMessageText;
     private TextView mStatusMessageAction;
 
+    /** Whether we should show "remove from call log" in the options menu. */
+    private boolean mHasRemoveFromCallLog;
+    /** Whether we should show "edit number before call" in the options menu. */
+    private boolean mHasEditNumberBeforeCall;
+
     static final String[] CALL_LOG_PROJECTION = new String[] {
         CallLog.Calls.DATE,
         CallLog.Calls.DURATION,
@@ -356,37 +363,17 @@
 
         // This action deletes all elements in the group from the call log.
         // We don't have this action for voicemails, because you can just use the trash button.
-        if (!hasVoicemail()) {
-            actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
-                    getString(R.string.recentCalls_removeFromRecentList),
-                    new View.OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            StringBuilder callIds = new StringBuilder();
-                            for (Uri callUri : callUris) {
-                                if (callIds.length() != 0) {
-                                    callIds.append(",");
-                                }
-                                callIds.append(ContentUris.parseId(callUri));
-                            }
+        mHasRemoveFromCallLog = !hasVoicemail();
+        mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
 
-                            getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
-                                    Calls._ID + " IN (" + callIds + ")", null);
-                            finish();
-                        }
-                    }));
+        if (actions.size() != 0) {
+            // Set the actions for this phone number.
+            setListAdapter(new ViewAdapter(this, actions));
+            getListView().setVisibility(View.VISIBLE);
+        } else {
+            getListView().setVisibility(View.GONE);
         }
 
-        if (canPlaceCallsTo && !isSipNumber && !isVoicemailNumber) {
-            // "Edit the number before calling" is only available for PSTN numbers.
-            actions.add(new ViewEntry(android.R.drawable.sym_action_call,
-                    getString(R.string.recentCalls_editNumberBeforeCall),
-                    new Intent(Intent.ACTION_DIAL, numberCallUri)));
-        }
-
-        // Set the actions for this phone number.
-        setListAdapter(new ViewAdapter(this, actions));
-
         ListView historyList = (ListView) findViewById(R.id.history);
         historyList.setAdapter(
                 new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details));
@@ -631,4 +618,48 @@
         }
         return messages.get(0);
     }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.call_details_options, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onPrepareOptionsMenu(Menu menu) {
+        // This action deletes all elements in the group from the call log.
+        // We don't have this action for voicemails, because you can just use the trash button.
+        menu.findItem(R.id.remove_from_call_log).setVisible(mHasRemoveFromCallLog);
+        menu.findItem(R.id.edit_number_before_call).setVisible(mHasEditNumberBeforeCall);
+        return mHasRemoveFromCallLog || mHasEditNumberBeforeCall;
+    }
+
+    @Override
+    public boolean onMenuItemSelected(int featureId, MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.remove_from_call_log: {
+                StringBuilder callIds = new StringBuilder();
+                for (Uri callUri : getCallLogEntryUris()) {
+                    if (callIds.length() != 0) {
+                        callIds.append(",");
+                    }
+                    callIds.append(ContentUris.parseId(callUri));
+                }
+
+                getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
+                        Calls._ID + " IN (" + callIds + ")", null);
+                // Also close the activity.
+                finish();
+                return true;
+            }
+
+            case R.id.edit_number_before_call:
+                startActivity(
+                        new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber)));
+                return true;
+
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
 }