Added confirmation message to clear call log
Bug: 1447515

Change-Id: If8b591c070e164ca3aa0c0bcf7d0bce09befa01f
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d4b093a..377e932 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -374,6 +374,12 @@
     <!-- Text displayed when the call log is empty -->
     <string name="recentCalls_empty">Call log is empty.</string>
 
+    <!-- Title of the confirmation dialog for clearing the call log  -->
+    <string name="clearCallLogConfirmation_title">Clear call log</string>
+
+    <!-- Confirmation dialog for clearing the call log  -->
+    <string name="clearCallLogConfirmation">Are you sure you want to clear the call log?</string>
+
     <!-- The title of a dialog that displays the IMEI of the phone -->
     <string name="imei">IMEI</string>
 
diff --git a/src/com/android/contacts/RecentCallsListActivity.java b/src/com/android/contacts/RecentCallsListActivity.java
index dedc531..d12f9dd 100644
--- a/src/com/android/contacts/RecentCallsListActivity.java
+++ b/src/com/android/contacts/RecentCallsListActivity.java
@@ -19,13 +19,17 @@
 import com.android.internal.telephony.CallerInfo;
 import com.android.internal.telephony.ITelephony;
 
+import android.app.AlertDialog;
+import android.app.Dialog;
 import android.app.ListActivity;
 import android.content.ActivityNotFoundException;
 import android.content.AsyncQueryHandler;
 import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.DialogInterface.OnClickListener;
 import android.database.CharArrayBuffer;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabaseCorruptException;
@@ -123,6 +127,8 @@
     private static final int QUERY_TOKEN = 53;
     private static final int UPDATE_TOKEN = 54;
 
+    private static final int DIALOG_CONFIRM_DELETE_ALL = 1;
+
     RecentCallsAdapter mAdapter;
     private QueryHandler mQueryHandler;
     String mVoiceMailNumber;
@@ -903,13 +909,34 @@
     }
 
     @Override
+    protected Dialog onCreateDialog(int id, Bundle args) {
+        switch (id) {
+            case DIALOG_CONFIRM_DELETE_ALL:
+                return new AlertDialog.Builder(this)
+                    .setTitle(R.string.clearCallLogConfirmation_title)
+                    .setIcon(android.R.drawable.ic_dialog_alert)
+                    .setMessage(R.string.clearCallLogConfirmation)
+                    .setNegativeButton(android.R.string.cancel, null)
+                    .setPositiveButton(android.R.string.ok, new OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            getContentResolver().delete(Calls.CONTENT_URI, null, null);
+                            // TODO The change notification should do this automatically, but it
+                            // isn't working right now. Remove this when the change notification
+                            // is working properly.
+                            startQuery();
+                        }
+                    })
+                    .setCancelable(false)
+                    .create();
+        }
+        return null;
+    }
+
+    @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case MENU_ITEM_DELETE_ALL: {
-                getContentResolver().delete(Calls.CONTENT_URI, null, null);
-                //TODO The change notification should do this automatically, but it isn't working
-                // right now. Remove this when the change notification is working properly.
-                startQuery();
+                showDialog(DIALOG_CONFIRM_DELETE_ALL);
                 return true;
             }