2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.content;
19 import android.view.KeyEvent;
22 * Interface that defines a dialog-type class that can be shown, dismissed, or
23 * canceled, and may have buttons that can be clicked.
25 public interface DialogInterface {
26 /** The identifier for the positive button. */
27 int BUTTON_POSITIVE = -1;
29 /** The identifier for the negative button. */
30 int BUTTON_NEGATIVE = -2;
32 /** The identifier for the neutral button. */
33 int BUTTON_NEUTRAL = -3;
35 /** @deprecated Use {@link #BUTTON_POSITIVE} */
37 int BUTTON1 = BUTTON_POSITIVE;
39 /** @deprecated Use {@link #BUTTON_NEGATIVE} */
41 int BUTTON2 = BUTTON_NEGATIVE;
43 /** @deprecated Use {@link #BUTTON_NEUTRAL} */
45 int BUTTON3 = BUTTON_NEUTRAL;
48 * Cancels the dialog, invoking the {@link OnCancelListener}.
50 * The {@link OnDismissListener} may also be called if cancellation
51 * dismisses the dialog.
56 * Dismisses the dialog, invoking the {@link OnDismissListener}.
61 * Interface used to allow the creator of a dialog to run some code when the
64 * This will only be called when the dialog is canceled, if the creator
65 * needs to know when it is dismissed in general, use
66 * {@link DialogInterface.OnDismissListener}.
68 interface OnCancelListener {
70 * This method will be invoked when the dialog is canceled.
72 * @param dialog the dialog that was canceled will be passed into the
75 void onCancel(DialogInterface dialog);
79 * Interface used to allow the creator of a dialog to run some code when the
80 * dialog is dismissed.
82 interface OnDismissListener {
84 * This method will be invoked when the dialog is dismissed.
86 * @param dialog the dialog that was dismissed will be passed into the
89 void onDismiss(DialogInterface dialog);
93 * Interface used to allow the creator of a dialog to run some code when the
96 interface OnShowListener {
98 * This method will be invoked when the dialog is shown.
100 * @param dialog the dialog that was shown will be passed into the
103 void onShow(DialogInterface dialog);
107 * Interface used to allow the creator of a dialog to run some code when an
108 * item on the dialog is clicked.
110 interface OnClickListener {
112 * This method will be invoked when a button in the dialog is clicked.
114 * @param dialog the dialog that received the click
115 * @param which the button that was clicked (ex.
116 * {@link DialogInterface#BUTTON_POSITIVE}) or the position
117 * of the item clicked
119 void onClick(DialogInterface dialog, int which);
123 * Interface used to allow the creator of a dialog to run some code when an
124 * item in a multi-choice dialog is clicked.
126 interface OnMultiChoiceClickListener {
128 * This method will be invoked when an item in the dialog is clicked.
130 * @param dialog the dialog where the selection was made
131 * @param which the position of the item in the list that was clicked
132 * @param isChecked {@code true} if the click checked the item, else
135 void onClick(DialogInterface dialog, int which, boolean isChecked);
139 * Interface definition for a callback to be invoked when a key event is
140 * dispatched to this dialog. The callback will be invoked before the key
141 * event is given to the dialog.
143 interface OnKeyListener {
145 * Called when a key is dispatched to a dialog. This allows listeners to
146 * get a chance to respond before the dialog.
148 * @param dialog the dialog the key has been dispatched to
149 * @param keyCode the code for the physical key that was pressed
150 * @param event the KeyEvent object containing full information about
152 * @return {@code true} if the listener has consumed the event,
153 * {@code false} otherwise
155 boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event);