blob: 46df4ae7fc09a51c1b602ab63bc3966439498b46 [file] [log] [blame]
yaolu491cca52016-09-30 14:04:40 -07001/*
2 * Copyright (C) 2016 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
17package com.android.contacts.list;
18
19import android.app.AlertDialog;
20import android.app.Dialog;
21import android.app.DialogFragment;
22import android.content.DialogInterface;
23import android.os.Bundle;
24
25import com.android.contacts.R;
26import com.android.contacts.common.list.ContactListFilter;
27
28/**
29 * Confirmation dialog for turning global auto-sync setting on.
30 */
31public class EnableGlobalSyncDialogFragment extends DialogFragment{
32
33 private static final String ARG_FILTER = "filter";
34 private ContactListFilter mFilter;
35
36 /**
37 * Callbacks for the dialog host.
38 */
39 public interface Listener {
40
41 /**
42 * Invoked after the user has confirmed that they want to turn on sync.
43 *
44 * @param filter the filter of current contacts list.
45 */
46 void onEnableAutoSync(ContactListFilter filter);
47 }
48
49 public static void show(DefaultContactBrowseListFragment fragment, ContactListFilter filter) {
50 final Bundle args = new Bundle();
51 args.putParcelable(ARG_FILTER, filter);
52
53 final EnableGlobalSyncDialogFragment dialog = new
54 EnableGlobalSyncDialogFragment();
55 dialog.setTargetFragment(fragment, 0);
56 dialog.setArguments(args);
57 dialog.show(fragment.getFragmentManager(), "globalSync");
58 }
59
60 @Override
61 public void onCreate(Bundle savedInstanceState) {
62 super.onCreate(savedInstanceState);
63 mFilter = getArguments().getParcelable(ARG_FILTER);
64 }
65
66 @Override
67 public Dialog onCreateDialog(Bundle savedInstanceState) {
68 final Listener targetListener = (Listener) getTargetFragment();
69 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
70 builder.setTitle(R.string.turn_auto_sync_on_dialog_title)
71 .setMessage(R.string.turn_auto_sync_on_dialog_body)
72 .setPositiveButton(R.string.turn_auto_sync_on_dialog_confirm_btn,
73 new DialogInterface.OnClickListener() {
74 @Override
75 public void onClick(DialogInterface dialog, int which) {
76 if (targetListener != null) {
77 targetListener.onEnableAutoSync(mFilter);
78 }
79 }
80 });
81 builder.setNegativeButton(android.R.string.cancel, null);
82 builder.setCancelable(false);
83 return builder.create();
84 }
85}