1 /* 2 * Copyright (C) 2008 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 package android.app.stubs; 17 18 import android.app.Dialog; 19 import android.content.Context; 20 import android.os.Bundle; 21 import android.view.ContextMenu; 22 import android.view.KeyEvent; 23 import android.view.Menu; 24 import android.view.MenuItem; 25 import android.view.MotionEvent; 26 import android.view.View; 27 import android.view.Window; 28 import android.view.ContextMenu.ContextMenuInfo; 29 import android.view.WindowManager.LayoutParams; 30 31 public class TestDialog extends Dialog { 32 private static final int OPTIONS_MENU_ITEM_0 = Menu.FIRST; 33 private static final int OPTIONS_MENU_ITEM_1 = Menu.FIRST + 1; 34 private static final int OPTIONS_MENU_ITEM_2 = Menu.FIRST + 2; 35 private static final int OPTIONS_MENU_ITEM_3 = Menu.FIRST + 3; 36 private static final int OPTIONS_MENU_ITEM_4 = Menu.FIRST + 4; 37 private static final int OPTIONS_MENU_ITEM_5 = Menu.FIRST + 5; 38 private static final int OPTIONS_MENU_ITEM_6 = Menu.FIRST + 6; 39 private static final int CONTEXT_MENU_ITEM_0 = Menu.FIRST + 7; 40 private static final int CONTEXT_MENU_ITEM_1 = Menu.FIRST + 8; 41 private static final int CONTEXT_MENU_ITEM_2 = Menu.FIRST + 9; 42 public boolean isOnStartCalled; 43 public boolean isOnStopCalled; 44 public boolean isOnCreateCalled; 45 public boolean isRequestWindowFeature; 46 public boolean isOnContentChangedCalled; 47 public boolean isOnWindowFocusChangedCalled; 48 public boolean isOnTouchEventCalled; 49 public boolean isOnTrackballEventCalled; 50 public boolean isOnKeyDownCalled; 51 public boolean isOnKeyUpCalled; 52 public boolean isOnKeyMultipleCalled; 53 public boolean isOnSaveInstanceStateCalled; 54 public static boolean isOnRestoreInstanceStateCalled; 55 public boolean isOnWindowAttributesChangedCalled; 56 public boolean isOnCreatePanelMenuCalled; 57 public boolean isOnCreatePanelViewCalled; 58 public boolean isOnPreparePanelCalled; 59 public boolean isOnMenuOpenedCalled; 60 public boolean isOnMenuItemSelectedCalled; 61 public boolean isOnPanelClosedCalled; 62 public boolean isOnCreateOptionsMenuCalled; 63 public boolean isOnPrepareOptionsMenuCalled; 64 public boolean isOnOptionsItemSelectedCalled; 65 public boolean isOnOptionsMenuClosedCalled; 66 public boolean isOnContextItemSelectedCalled; 67 public boolean isOnContextMenuClosedCalled; 68 public boolean isOnCreateContextMenuCalled; 69 public boolean isOnSearchRequestedCalled; 70 public boolean onKeyDownReturn; 71 public boolean onKeyMultipleReturn; 72 public boolean dispatchTouchEventResult; 73 public boolean dispatchKeyEventResult; 74 public int keyDownCode = -1; 75 public Window window; 76 public Bundle saveInstanceState; 77 public Bundle savedInstanceState; 78 public KeyEvent keyEvent; 79 public MotionEvent touchEvent; 80 public MotionEvent trackballEvent; 81 public MotionEvent onTrackballEvent; 82 public MotionEvent onTouchEvent; 83 public KeyEvent keyMultipleEvent; 84 TestDialog(Context context)85 public TestDialog(Context context) { 86 super(context); 87 } 88 TestDialog(Context context, int theme)89 public TestDialog(Context context, int theme) { 90 super(context, theme); 91 } 92 TestDialog(Context context, boolean cancelable, OnCancelListener cancelListener)93 public TestDialog(Context context, boolean cancelable, OnCancelListener cancelListener) { 94 super(context, cancelable, cancelListener); 95 } 96 97 @Override onStart()98 protected void onStart() { 99 super.onStart(); 100 isOnStartCalled = true; 101 } 102 103 @Override onStop()104 protected void onStop() { 105 super.onStop(); 106 isOnStopCalled = true; 107 } 108 109 @Override onCreate(Bundle savedInstanceState)110 protected void onCreate(Bundle savedInstanceState) { 111 isRequestWindowFeature = requestWindowFeature(Window.FEATURE_LEFT_ICON); 112 super.onCreate(savedInstanceState); 113 isOnCreateCalled = true; 114 } 115 116 @Override onContentChanged()117 public void onContentChanged() { 118 super.onContentChanged(); 119 120 isOnContentChangedCalled = true; 121 } 122 123 @Override onWindowFocusChanged(boolean hasFocus)124 public void onWindowFocusChanged(boolean hasFocus) { 125 super.onWindowFocusChanged(hasFocus); 126 127 isOnWindowFocusChangedCalled = true; 128 } 129 130 @Override onTouchEvent(MotionEvent event)131 public boolean onTouchEvent(MotionEvent event) { 132 isOnTouchEventCalled = true; 133 onTouchEvent = event; 134 return super.onTouchEvent(event); 135 } 136 137 @Override onTrackballEvent(MotionEvent event)138 public boolean onTrackballEvent(MotionEvent event) { 139 isOnTrackballEventCalled = true; 140 onTrackballEvent = event; 141 return super.onTrackballEvent(event); 142 } 143 144 @Override onKeyDown(int keyCode, KeyEvent event)145 public boolean onKeyDown(int keyCode, KeyEvent event) { 146 isOnKeyDownCalled = true; 147 keyDownCode = keyCode; 148 onKeyDownReturn = super.onKeyDown(keyCode, event); 149 150 return onKeyDownReturn; 151 } 152 153 @Override onKeyUp(int keyCode, KeyEvent event)154 public boolean onKeyUp(int keyCode, KeyEvent event) { 155 isOnKeyUpCalled = true; 156 157 return super.onKeyUp(keyCode, event); 158 } 159 160 @Override onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)161 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { 162 isOnKeyMultipleCalled = true; 163 onKeyMultipleReturn = super.onKeyMultiple(keyCode, repeatCount, event); 164 keyMultipleEvent = event; 165 return onKeyMultipleReturn; 166 } 167 168 @Override onSaveInstanceState()169 public Bundle onSaveInstanceState() { 170 isOnSaveInstanceStateCalled = true; 171 saveInstanceState = super.onSaveInstanceState(); 172 return saveInstanceState; 173 } 174 175 @Override onRestoreInstanceState(Bundle savedInstanceState)176 public void onRestoreInstanceState(Bundle savedInstanceState) { 177 isOnRestoreInstanceStateCalled = true; 178 this.savedInstanceState = savedInstanceState; 179 180 super.onRestoreInstanceState(savedInstanceState); 181 } 182 183 @Override onWindowAttributesChanged(LayoutParams params)184 public void onWindowAttributesChanged(LayoutParams params) { 185 isOnWindowAttributesChangedCalled = true; 186 super.onWindowAttributesChanged(params); 187 } 188 189 @Override onCreatePanelMenu(int featureId, Menu menu)190 public boolean onCreatePanelMenu(int featureId, Menu menu) { 191 isOnCreatePanelMenuCalled = true; 192 return super.onCreatePanelMenu(featureId, menu); 193 } 194 195 @Override onCreatePanelView(int featureId)196 public View onCreatePanelView(int featureId) { 197 isOnCreatePanelViewCalled = true; 198 return super.onCreatePanelView(featureId); 199 } 200 201 @Override onPreparePanel(int featureId, View view, Menu menu)202 public boolean onPreparePanel(int featureId, View view, Menu menu) { 203 isOnPreparePanelCalled = true; 204 return super.onPreparePanel(featureId, view, menu); 205 } 206 207 @Override onMenuItemSelected(int featureId, MenuItem item)208 public boolean onMenuItemSelected(int featureId, MenuItem item) { 209 isOnMenuItemSelectedCalled = true; 210 return super.onMenuItemSelected(featureId, item); 211 } 212 213 @Override onMenuOpened(int featureId, Menu menu)214 public boolean onMenuOpened(int featureId, Menu menu) { 215 isOnMenuOpenedCalled = true; 216 return super.onMenuOpened(featureId, menu); 217 } 218 219 @Override onPanelClosed(int featureId, Menu menu)220 public void onPanelClosed(int featureId, Menu menu) { 221 isOnPanelClosedCalled = true; 222 super.onPanelClosed(featureId, menu); 223 } 224 225 @Override onPrepareOptionsMenu(Menu menu)226 public boolean onPrepareOptionsMenu(Menu menu) { 227 isOnPrepareOptionsMenuCalled = true; 228 return super.onPrepareOptionsMenu(menu); 229 } 230 231 @Override onCreateOptionsMenu(Menu menu)232 public boolean onCreateOptionsMenu(Menu menu) { 233 super.onCreateOptionsMenu(menu); 234 menu.add(0, OPTIONS_MENU_ITEM_0, 0, "OptionsMenuItem0"); 235 menu.add(0, OPTIONS_MENU_ITEM_1, 0, "OptionsMenuItem1"); 236 menu.add(0, OPTIONS_MENU_ITEM_2, 0, "OptionsMenuItem2"); 237 menu.add(0, OPTIONS_MENU_ITEM_3, 0, "OptionsMenuItem3"); 238 menu.add(0, OPTIONS_MENU_ITEM_4, 0, "OptionsMenuItem4"); 239 menu.add(0, OPTIONS_MENU_ITEM_5, 0, "OptionsMenuItem5"); 240 menu.add(0, OPTIONS_MENU_ITEM_6, 0, "OptionsMenuItem6"); 241 isOnCreateOptionsMenuCalled = true; 242 return true; 243 } 244 245 @Override onOptionsItemSelected(MenuItem item)246 public boolean onOptionsItemSelected(MenuItem item) { 247 isOnOptionsItemSelectedCalled = true; 248 switch (item.getItemId()) { 249 case OPTIONS_MENU_ITEM_0: 250 case OPTIONS_MENU_ITEM_1: 251 case OPTIONS_MENU_ITEM_2: 252 case OPTIONS_MENU_ITEM_3: 253 case OPTIONS_MENU_ITEM_4: 254 case OPTIONS_MENU_ITEM_5: 255 case OPTIONS_MENU_ITEM_6: 256 return true; 257 default: 258 return super.onOptionsItemSelected(item); 259 } 260 } 261 262 @Override onOptionsMenuClosed(Menu menu)263 public void onOptionsMenuClosed(Menu menu) { 264 isOnOptionsMenuClosedCalled = true; 265 super.onOptionsMenuClosed(menu); 266 } 267 268 @Override onContextItemSelected(MenuItem item)269 public boolean onContextItemSelected(MenuItem item) { 270 isOnContextItemSelectedCalled = true; 271 switch (item.getItemId()) { 272 case CONTEXT_MENU_ITEM_0: 273 case CONTEXT_MENU_ITEM_1: 274 case CONTEXT_MENU_ITEM_2: 275 return true; 276 default: 277 return super.onContextItemSelected(item); 278 } 279 } 280 281 @Override onContextMenuClosed(Menu menu)282 public void onContextMenuClosed(Menu menu) { 283 isOnContextMenuClosedCalled = true; 284 super.onContextMenuClosed(menu); 285 } 286 287 @Override onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)288 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 289 menu.add(0, CONTEXT_MENU_ITEM_0, 0, "ContextMenuItem0"); 290 menu.add(0, CONTEXT_MENU_ITEM_1, 0, "ContextMenuItem1"); 291 menu.add(0, CONTEXT_MENU_ITEM_2, 0, "ContextMenuItem2"); 292 isOnCreateContextMenuCalled = true; 293 } 294 295 @Override onSearchRequested()296 public boolean onSearchRequested() { 297 isOnSearchRequestedCalled = true; 298 return super.onSearchRequested(); 299 } 300 301 @Override dispatchKeyEvent(KeyEvent event)302 public boolean dispatchKeyEvent(KeyEvent event) { 303 keyEvent = event; 304 dispatchKeyEventResult = super.dispatchKeyEvent(event); 305 return dispatchKeyEventResult; 306 } 307 308 @Override dispatchTrackballEvent(MotionEvent ev)309 public boolean dispatchTrackballEvent(MotionEvent ev) { 310 trackballEvent = ev; 311 return super.dispatchTrackballEvent(ev); 312 } 313 314 @Override dispatchTouchEvent(MotionEvent ev)315 public boolean dispatchTouchEvent(MotionEvent ev) { 316 touchEvent = ev; 317 dispatchTouchEventResult = super.dispatchTouchEvent(ev); 318 return dispatchTouchEventResult; 319 } 320 } 321