• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.content;
18 
19 import android.view.KeyEvent;
20 
21 /**
22  *
23  */
24 public 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 
cancel()58     public void cancel();
59 
dismiss()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          */
onCancel(DialogInterface dialog)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          */
onDismiss(DialogInterface dialog)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      * @hide Pending API council approval
98      */
99     interface OnShowListener {
100         /**
101          * This method will be invoked when the dialog is shown.
102          *
103          * @param dialog The dialog that was shown will be passed into the
104          *            method.
105          */
onShow(DialogInterface dialog)106         public void onShow(DialogInterface dialog);
107     }
108 
109     /**
110      * Interface used to allow the creator of a dialog to run some code when an
111      * item on the dialog is clicked..
112      */
113     interface OnClickListener {
114         /**
115          * This method will be invoked when a button in the dialog is clicked.
116          *
117          * @param dialog The dialog that received the click.
118          * @param which The button that was clicked (e.g.
119          *            {@link DialogInterface#BUTTON1}) or the position
120          *            of the item clicked.
121          */
122         /* TODO: Change to use BUTTON_POSITIVE after API council */
onClick(DialogInterface dialog, int which)123         public void onClick(DialogInterface dialog, int which);
124     }
125 
126     /**
127      * Interface used to allow the creator of a dialog to run some code when an
128      * item in a multi-choice dialog is clicked.
129      */
130     interface OnMultiChoiceClickListener {
131         /**
132          * This method will be invoked when an item in the dialog is clicked.
133          *
134          * @param dialog The dialog where the selection was made.
135          * @param which The position of the item in the list that was clicked.
136          * @param isChecked True if the click checked the item, else false.
137          */
onClick(DialogInterface dialog, int which, boolean isChecked)138         public void onClick(DialogInterface dialog, int which, boolean isChecked);
139     }
140 
141     /**
142      * Interface definition for a callback to be invoked when a key event is
143      * dispatched to this dialog. The callback will be invoked before the key
144      * event is given to the dialog.
145      */
146     interface OnKeyListener {
147         /**
148          * Called when a key is dispatched to a dialog. This allows listeners to
149          * get a chance to respond before the dialog.
150          *
151          * @param dialog The dialog the key has been dispatched to.
152          * @param keyCode The code for the physical key that was pressed
153          * @param event The KeyEvent object containing full information about
154          *            the event.
155          * @return True if the listener has consumed the event, false otherwise.
156          */
onKey(DialogInterface dialog, int keyCode, KeyEvent event)157         public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event);
158     }
159 }
160