Home | History | Annotate | Download | only in calllog
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.contacts.calllog;
     18 
     19 import android.app.AlertDialog;
     20 import android.app.Dialog;
     21 import android.app.DialogFragment;
     22 import android.app.FragmentManager;
     23 import android.app.ProgressDialog;
     24 import android.content.ContentResolver;
     25 import android.content.DialogInterface;
     26 import android.content.DialogInterface.OnClickListener;
     27 import android.os.AsyncTask;
     28 import android.os.Bundle;
     29 import android.provider.CallLog.Calls;
     30 
     31 import com.android.contacts.R;
     32 
     33 /**
     34  * Dialog that clears the call log after confirming with the user
     35  */
     36 public class ClearCallLogDialog extends DialogFragment {
     37     /** Preferred way to show this dialog */
     38     public static void show(FragmentManager fragmentManager) {
     39         ClearCallLogDialog dialog = new ClearCallLogDialog();
     40         dialog.show(fragmentManager, "deleteCallLog");
     41     }
     42 
     43     @Override
     44     public Dialog onCreateDialog(Bundle savedInstanceState) {
     45         final ContentResolver resolver = getActivity().getContentResolver();
     46         final OnClickListener okListener = new OnClickListener() {
     47             @Override
     48             public void onClick(DialogInterface dialog, int which) {
     49                 final ProgressDialog progressDialog = ProgressDialog.show(getActivity(),
     50                         getString(R.string.clearCallLogProgress_title),
     51                         "", true, false);
     52                 final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
     53                     @Override
     54                     protected Void doInBackground(Void... params) {
     55                         resolver.delete(Calls.CONTENT_URI, null, null);
     56                         return null;
     57                     }
     58                     @Override
     59                     protected void onPostExecute(Void result) {
     60                         progressDialog.dismiss();
     61                     }
     62                 };
     63                 // TODO: Once we have the API, we should configure this ProgressDialog
     64                 // to only show up after a certain time (e.g. 150ms)
     65                 progressDialog.show();
     66                 task.execute();
     67             }
     68         };
     69         return new AlertDialog.Builder(getActivity())
     70             .setTitle(R.string.clearCallLogConfirmation_title)
     71             .setIconAttribute(android.R.attr.alertDialogIcon)
     72             .setMessage(R.string.clearCallLogConfirmation)
     73             .setNegativeButton(android.R.string.cancel, null)
     74             .setPositiveButton(android.R.string.ok, okListener)
     75             .setCancelable(true)
     76             .create();
     77     }
     78 }
     79