1/* 2 * Copyright (C) 2006 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 android.content; 18 19import android.view.KeyEvent; 20 21/** 22 * 23 */ 24public interface DialogInterface { 25 /** 26 * The identifier for the positive button. 27 */ 28 public static final int BUTTON_POSITIVE = -1; 29 30 /** 31 * The identifier for the negative button. 32 */ 33 public static final int BUTTON_NEGATIVE = -2; 34 35 /** 36 * The identifier for the neutral button. 37 */ 38 public static final int BUTTON_NEUTRAL = -3; 39 40 /** 41 * @deprecated Use {@link #BUTTON_POSITIVE} 42 */ 43 @Deprecated 44 public static final int BUTTON1 = BUTTON_POSITIVE; 45 46 /** 47 * @deprecated Use {@link #BUTTON_NEGATIVE} 48 */ 49 @Deprecated 50 public static final int BUTTON2 = BUTTON_NEGATIVE; 51 52 /** 53 * @deprecated Use {@link #BUTTON_NEUTRAL} 54 */ 55 @Deprecated 56 public static final int BUTTON3 = BUTTON_NEUTRAL; 57 58 public void cancel(); 59 60 public void dismiss(); 61 62 /** 63 * Interface used to allow the creator of a dialog to run some code when the 64 * dialog is canceled. 65 * <p> 66 * This will only be called when the dialog is canceled, if the creator 67 * needs to know when it is dismissed in general, use 68 * {@link DialogInterface.OnDismissListener}. 69 */ 70 interface OnCancelListener { 71 /** 72 * This method will be invoked when the dialog is canceled. 73 * 74 * @param dialog The dialog that was canceled will be passed into the 75 * method. 76 */ 77 public void onCancel(DialogInterface dialog); 78 } 79 80 /** 81 * Interface used to allow the creator of a dialog to run some code when the 82 * dialog is dismissed. 83 */ 84 interface OnDismissListener { 85 /** 86 * This method will be invoked when the dialog is dismissed. 87 * 88 * @param dialog The dialog that was dismissed will be passed into the 89 * method. 90 */ 91 public void onDismiss(DialogInterface dialog); 92 } 93 94 /** 95 * Interface used to allow the creator of a dialog to run some code when the 96 * dialog is shown. 97 */ 98 interface OnShowListener { 99 /** 100 * This method will be invoked when the dialog is shown. 101 * 102 * @param dialog The dialog that was shown will be passed into the 103 * method. 104 */ 105 public void onShow(DialogInterface dialog); 106 } 107 108 /** 109 * Interface used to allow the creator of a dialog to run some code when an 110 * item on the dialog is clicked.. 111 */ 112 interface OnClickListener { 113 /** 114 * This method will be invoked when a button in the dialog is clicked. 115 * 116 * @param dialog The dialog that received the click. 117 * @param which The button that was clicked (e.g. 118 * {@link DialogInterface#BUTTON1}) or the position 119 * of the item clicked. 120 */ 121 /* TODO: Change to use BUTTON_POSITIVE after API council */ 122 public void onClick(DialogInterface dialog, int which); 123 } 124 125 /** 126 * Interface used to allow the creator of a dialog to run some code when an 127 * item in a multi-choice dialog is clicked. 128 */ 129 interface OnMultiChoiceClickListener { 130 /** 131 * This method will be invoked when an item in the dialog is clicked. 132 * 133 * @param dialog The dialog where the selection was made. 134 * @param which The position of the item in the list that was clicked. 135 * @param isChecked True if the click checked the item, else false. 136 */ 137 public void onClick(DialogInterface dialog, int which, boolean isChecked); 138 } 139 140 /** 141 * Interface definition for a callback to be invoked when a key event is 142 * dispatched to this dialog. The callback will be invoked before the key 143 * event is given to the dialog. 144 */ 145 interface OnKeyListener { 146 /** 147 * Called when a key is dispatched to a dialog. This allows listeners to 148 * get a chance to respond before the dialog. 149 * 150 * @param dialog The dialog the key has been dispatched to. 151 * @param keyCode The code for the physical key that was pressed 152 * @param event The KeyEvent object containing full information about 153 * the event. 154 * @return True if the listener has consumed the event, false otherwise. 155 */ 156 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event); 157 } 158} 159