1 /* 2 * Copyright (C) 2012 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.common.dialog; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.DialogFragment; 22 import android.app.FragmentManager; 23 import android.content.ContentResolver; 24 import android.content.DialogInterface; 25 import android.content.DialogInterface.OnClickListener; 26 import android.os.AsyncTask; 27 import android.os.Bundle; 28 import android.provider.ContactsContract; 29 30 import com.android.contacts.common.R; 31 32 /** 33 * Dialog that clears the frequently contacted list after confirming with the user. 34 */ 35 public class ClearFrequentsDialog extends DialogFragment { 36 /** Preferred way to show this dialog */ 37 public static void show(FragmentManager fragmentManager) { 38 ClearFrequentsDialog dialog = new ClearFrequentsDialog(); 39 dialog.show(fragmentManager, "clearFrequents"); 40 } 41 42 @Override 43 public Dialog onCreateDialog(Bundle savedInstanceState) { 44 final ContentResolver resolver = getActivity().getContentResolver(); 45 final OnClickListener okListener = new OnClickListener() { 46 @Override 47 public void onClick(DialogInterface dialog, int which) { 48 final IndeterminateProgressDialog progressDialog = IndeterminateProgressDialog.show( 49 getFragmentManager(), getString(R.string.clearFrequentsProgress_title), 50 null, 500); 51 final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { 52 @Override 53 protected Void doInBackground(Void... params) { 54 resolver.delete(ContactsContract.DataUsageFeedback.DELETE_USAGE_URI, 55 null, null); 56 return null; 57 } 58 59 @Override 60 protected void onPostExecute(Void result) { 61 progressDialog.dismiss(); 62 } 63 }; 64 task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 65 } 66 }; 67 return new AlertDialog.Builder(getActivity()) 68 .setTitle(R.string.clearFrequentsConfirmation_title) 69 .setMessage(R.string.clearFrequentsConfirmation) 70 .setNegativeButton(android.R.string.cancel, null) 71 .setPositiveButton(android.R.string.ok, okListener) 72 .setCancelable(true) 73 .create(); 74 } 75 } 76