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