blob: 7591de3ff7811cdb84bb0b0dd2793b0284fc4950 [file] [log] [blame]
Chiao Chenga6b4c792012-10-31 15:18:29 -07001/*
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
Gary Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.dialog;
Chiao Chenga6b4c792012-10-31 15:18:29 -070018
19import android.app.AlertDialog;
20import android.app.Dialog;
Brian Attwellc2e912c2014-10-27 12:29:44 -070021import android.app.DialogFragment;
Chiao Chenga6b4c792012-10-31 15:18:29 -070022import android.app.FragmentManager;
23import android.content.ContentResolver;
Yorke Lee3a52e632015-05-21 11:04:14 -070024import android.content.Context;
Chiao Chenga6b4c792012-10-31 15:18:29 -070025import android.content.DialogInterface;
26import android.content.DialogInterface.OnClickListener;
27import android.os.AsyncTask;
28import android.os.Bundle;
29import android.provider.ContactsContract;
30
Arthur Wang3f6a2442016-12-05 14:51:59 -080031import com.android.contacts.R;
Gary Mai69c182a2016-12-05 13:07:03 -080032import com.android.contacts.util.PermissionsUtil;
Chiao Chenga6b4c792012-10-31 15:18:29 -070033
34/**
35 * Dialog that clears the frequently contacted list after confirming with the user.
36 */
Brian Attwellc2e912c2014-10-27 12:29:44 -070037public class ClearFrequentsDialog extends DialogFragment {
Chiao Chenga6b4c792012-10-31 15:18:29 -070038 /** Preferred way to show this dialog */
39 public static void show(FragmentManager fragmentManager) {
40 ClearFrequentsDialog dialog = new ClearFrequentsDialog();
41 dialog.show(fragmentManager, "clearFrequents");
42 }
43
44 @Override
45 public Dialog onCreateDialog(Bundle savedInstanceState) {
Yorke Lee3a52e632015-05-21 11:04:14 -070046 final Context context = getActivity().getApplicationContext();
Chiao Chenga6b4c792012-10-31 15:18:29 -070047 final ContentResolver resolver = getActivity().getContentResolver();
48 final OnClickListener okListener = new OnClickListener() {
49 @Override
50 public void onClick(DialogInterface dialog, int which) {
Yorke Lee3a52e632015-05-21 11:04:14 -070051 if (!PermissionsUtil.hasContactsPermissions(context)) {
52 return;
53 }
Chiao Chenga6b4c792012-10-31 15:18:29 -070054 final IndeterminateProgressDialog progressDialog = IndeterminateProgressDialog.show(
55 getFragmentManager(), getString(R.string.clearFrequentsProgress_title),
56 null, 500);
57 final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
58 @Override
59 protected Void doInBackground(Void... params) {
60 resolver.delete(ContactsContract.DataUsageFeedback.DELETE_USAGE_URI,
61 null, null);
62 return null;
63 }
64
65 @Override
66 protected void onPostExecute(Void result) {
67 progressDialog.dismiss();
68 }
69 };
70 task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
71 }
72 };
73 return new AlertDialog.Builder(getActivity())
74 .setTitle(R.string.clearFrequentsConfirmation_title)
75 .setMessage(R.string.clearFrequentsConfirmation)
76 .setNegativeButton(android.R.string.cancel, null)
77 .setPositiveButton(android.R.string.ok, okListener)
78 .setCancelable(true)
79 .create();
80 }
81}