Home | History | Annotate | Download | only in editor
      1 /*
      2  * Copyright (C) 2015 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.editor;
     18 
     19 import com.android.contacts.R;
     20 
     21 import android.app.AlertDialog;
     22 import android.app.Dialog;
     23 import android.app.DialogFragment;
     24 import android.content.DialogInterface;
     25 import android.os.Bundle;
     26 
     27 /**
     28  * Asks the user whether to cancel editing the contact.
     29  */
     30 public class CancelEditDialogFragment extends DialogFragment {
     31 
     32     private static final String TAG = "cancelEditor";
     33 
     34     /**
     35      * Shows a {@link CancelEditDialogFragment} after setting the given Fragment as the
     36      * target of the dialog.
     37      */
     38     public static void show(ContactEditorBaseFragment fragment) {
     39         final CancelEditDialogFragment dialog = new CancelEditDialogFragment();
     40         dialog.setTargetFragment(fragment, 0);
     41         dialog.show(fragment.getFragmentManager(), TAG);
     42     }
     43 
     44     @Override
     45     public Dialog onCreateDialog(Bundle savedInstanceState) {
     46         return new AlertDialog.Builder(getActivity())
     47                 .setIconAttribute(android.R.attr.alertDialogIcon)
     48                 .setMessage(R.string.cancel_confirmation_dialog_message)
     49                 .setPositiveButton(R.string.cancel_confirmation_dialog_cancel_editing_button,
     50                         new DialogInterface.OnClickListener() {
     51                             @Override
     52                             public void onClick(DialogInterface dialogInterface, int which) {
     53                                 final Listener targetListener = (Listener) getTargetFragment();
     54                                 targetListener.onCancelEditConfirmed();
     55                             }
     56                         }
     57                 )
     58                 .setNegativeButton(R.string.cancel_confirmation_dialog_keep_editing_button, null)
     59                 .create();
     60     }
     61 
     62     /**
     63      * Callbacks for {@link CancelEditDialogFragment} hosts.
     64      */
     65     public interface Listener {
     66 
     67         /**
     68          * Invoked when the user confirms that they want to cancel editing the contact.
     69          */
     70         void onCancelEditConfirmed();
     71     }
     72 }