• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.contacts.list;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.app.DialogFragment;
22 import android.content.DialogInterface;
23 import android.os.Bundle;
24 
25 import com.android.contacts.R;
26 
27 /**
28  * Confirmation dialog for turning global auto-sync setting on.
29  */
30 public 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          */
onEnableAutoSync(ContactListFilter filter)45         void onEnableAutoSync(ContactListFilter filter);
46     }
47 
show(DefaultContactBrowseListFragment fragment, ContactListFilter filter)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
onCreate(Bundle savedInstanceState)60     public void onCreate(Bundle savedInstanceState) {
61         super.onCreate(savedInstanceState);
62         mFilter = getArguments().getParcelable(ARG_FILTER);
63     }
64 
65     @Override
onCreateDialog(Bundle savedInstanceState)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 }
85