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(android.R.string.ok, new DialogInterface.OnClickListener() {
     50                             @Override
     51                             public void onClick(DialogInterface dialogInterface, int which) {
     52                                 final Listener targetListener = (Listener) getTargetFragment();
     53                                 targetListener.onCancelEditConfirmed();
     54                             }
     55                         }
     56                 )
     57                 .setNegativeButton(android.R.string.cancel, null)
     58                 .create();
     59     }
     60 
     61     /**
     62      * Callbacks for {@link CancelEditDialogFragment} hosts.
     63      */
     64     public interface Listener {
     65 
     66         /**
     67          * Invoked when the user confirms that they want to cancel editing the contact.
     68          */
     69         void onCancelEditConfirmed();
     70     }
     71 }