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 final OrientationTestUtils.Observer onSaveInstanceStateObserver = 54 new OrientationTestUtils.Observer(); 55 public final static OrientationTestUtils.Observer onRestoreInstanceStateObserver = 56 new OrientationTestUtils.Observer(); 57 public boolean isOnWindowAttributesChangedCalled; 58 public boolean isOnCreatePanelMenuCalled; 59 public boolean isOnCreatePanelViewCalled; 60 public boolean isOnPreparePanelCalled; 61 public boolean isOnMenuOpenedCalled; 62 public boolean isOnMenuItemSelectedCalled; 63 public boolean isOnPanelClosedCalled; 64 public boolean isOnCreateOptionsMenuCalled; 65 public boolean isOnPrepareOptionsMenuCalled; 66 public boolean isOnOptionsItemSelectedCalled; 67 public boolean isOnOptionsMenuClosedCalled; 68 public boolean isOnContextItemSelectedCalled; 69 public boolean isOnContextMenuClosedCalled; 70 public boolean isOnCreateContextMenuCalled; 71 public boolean isOnSearchRequestedCalled; 72 public boolean onKeyDownReturn; 73 public boolean onKeyMultipleReturn; 74 public boolean dispatchTouchEventResult; 75 public boolean dispatchKeyEventResult; 76 public int keyDownCode = -1; 77 public Bundle saveInstanceState; 78 public Bundle savedInstanceState; 79 public KeyEvent keyEvent; 80 public MotionEvent touchEvent; 81 public MotionEvent trackballEvent; 82 public MotionEvent onTrackballEvent; 83 public MotionEvent onTouchEvent; 84 public KeyEvent keyMultipleEvent; 85 TestDialog(Context context)86 public TestDialog(Context context) { 87 super(context); 88 } 89 TestDialog(Context context, int theme)90 public TestDialog(Context context, int theme) { 91 super(context, theme); 92 } 93 TestDialog(Context context, boolean cancelable, OnCancelListener cancelListener)94 public TestDialog(Context context, boolean cancelable, OnCancelListener cancelListener) { 95 super(context, cancelable, cancelListener); 96 } 97 98 @Override onStart()99 protected void onStart() { 100 super.onStart(); 101 isOnStartCalled = true; 102 } 103 104 @Override onStop()105 protected void onStop() { 106 super.onStop(); 107 isOnStopCalled = true; 108 } 109 110 @Override onCreate(Bundle savedInstanceState)111 protected void onCreate(Bundle savedInstanceState) { 112 isRequestWindowFeature = requestWindowFeature(Window.FEATURE_LEFT_ICON); 113 super.onCreate(savedInstanceState); 114 isOnCreateCalled = true; 115 } 116 117 @Override onContentChanged()118 public void onContentChanged() { 119 super.onContentChanged(); 120 121 isOnContentChangedCalled = true; 122 } 123 124 @Override onWindowFocusChanged(boolean hasFocus)125 public void onWindowFocusChanged(boolean hasFocus) { 126 super.onWindowFocusChanged(hasFocus); 127 128 isOnWindowFocusChangedCalled = true; 129 } 130 131 @Override onTouchEvent(MotionEvent event)132 public boolean onTouchEvent(MotionEvent event) { 133 isOnTouchEventCalled = true; 134 onTouchEvent = event; 135 return super.onTouchEvent(event); 136 } 137 138 @Override onTrackballEvent(MotionEvent event)139 public boolean onTrackballEvent(MotionEvent event) { 140 isOnTrackballEventCalled = true; 141 onTrackballEvent = event; 142 return super.onTrackballEvent(event); 143 } 144 145 @Override onKeyDown(int keyCode, KeyEvent event)146 public boolean onKeyDown(int keyCode, KeyEvent event) { 147 isOnKeyDownCalled = true; 148 keyDownCode = keyCode; 149 onKeyDownReturn = super.onKeyDown(keyCode, event); 150 151 return onKeyDownReturn; 152 } 153 154 @Override onKeyUp(int keyCode, KeyEvent event)155 public boolean onKeyUp(int keyCode, KeyEvent event) { 156 isOnKeyUpCalled = true; 157 158 return super.onKeyUp(keyCode, event); 159 } 160 161 @Override onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)162 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { 163 isOnKeyMultipleCalled = true; 164 onKeyMultipleReturn = super.onKeyMultiple(keyCode, repeatCount, event); 165 keyMultipleEvent = event; 166 return onKeyMultipleReturn; 167 } 168 169 @Override onSaveInstanceState()170 public Bundle onSaveInstanceState() { 171 saveInstanceState = super.onSaveInstanceState(); 172 onSaveInstanceStateObserver.onObserved(); 173 return saveInstanceState; 174 } 175 176 @Override onRestoreInstanceState(Bundle savedInstanceState)177 public void onRestoreInstanceState(Bundle savedInstanceState) { 178 this.savedInstanceState = savedInstanceState; 179 onRestoreInstanceStateObserver.onObserved(); 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