1 /* 2 * Copyright (C) 2009 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.app.cts; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 import android.app.Activity; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.view.KeyEvent; 26 import android.view.Menu; 27 import android.view.MenuInflater; 28 import android.view.MenuItem; 29 import android.view.MotionEvent; 30 import android.view.View; 31 import android.widget.TextView; 32 import com.android.cts.app.stub.R; 33 34 public class InstrumentationTestActivity extends Activity { 35 36 private boolean mOnCreateCalled; 37 private boolean mOnDestroyCalled ; 38 private boolean mOnNewIntentCalled; 39 private boolean mOnPauseCalled; 40 private boolean mOnPostCreate; 41 private boolean mOnRestart; 42 private boolean mOnRestoreInstanceState; 43 private boolean mOnResume; 44 private boolean mOnSaveInstanceState; 45 private boolean mOnStart; 46 private boolean mOnStop; 47 private boolean mOnMenuOpened; 48 private boolean mOnLeave; 49 private int mMenuID; 50 private boolean mOnTouchEventCalled; 51 private int mKeyDownCode; 52 private int mKeyUpCode; 53 private MotionEvent mMotionEvent; 54 private Bundle mBundle; 55 private MockTextView mTextView; 56 private List<KeyEvent> mKeyDownList = new ArrayList<KeyEvent>(); 57 private List<KeyEvent> mKeyUpList = new ArrayList<KeyEvent>(); 58 59 @Override onCreate(Bundle savedInstanceState)60 public void onCreate(Bundle savedInstanceState) { 61 super.onCreate(savedInstanceState); 62 mTextView = new MockTextView(this); 63 setContentView(mTextView); 64 mOnCreateCalled = true; 65 } 66 67 class MockTextView extends TextView { 68 MockTextView(Context context)69 public MockTextView(Context context) { 70 super(context); 71 } 72 73 @Override onTouchEvent(MotionEvent event)74 public boolean onTouchEvent(MotionEvent event) { 75 return super.onTouchEvent(event); 76 } 77 78 @Override onTrackballEvent(MotionEvent event)79 public boolean onTrackballEvent(MotionEvent event) { 80 return super.onTrackballEvent(event); 81 } 82 83 @Override getLocationOnScreen(int[] location)84 public void getLocationOnScreen(int[] location) { 85 super.getLocationOnScreen(location); 86 location[0] = location[1] = 10; 87 } 88 } 89 90 @Override onDestroy()91 protected void onDestroy() { 92 super.onDestroy(); 93 mOnDestroyCalled = true; 94 } 95 96 @Override onNewIntent(Intent intent)97 protected void onNewIntent(Intent intent) { 98 super.onNewIntent(intent); 99 mOnNewIntentCalled = true; 100 } 101 102 @Override onPause()103 protected void onPause() { 104 super.onPause(); 105 mOnPauseCalled = true; 106 } 107 108 @Override onPostCreate(Bundle savedInstanceState)109 protected void onPostCreate(Bundle savedInstanceState) { 110 super.onPostCreate(savedInstanceState); 111 mOnPostCreate = true; 112 } 113 114 @Override onRestart()115 protected void onRestart() { 116 super.onRestart(); 117 mOnRestart = true; 118 } 119 120 @Override onRestoreInstanceState(Bundle savedInstanceState)121 protected void onRestoreInstanceState(Bundle savedInstanceState) { 122 super.onRestoreInstanceState(savedInstanceState); 123 mOnRestoreInstanceState = true; 124 } 125 126 @Override onTouchEvent(MotionEvent event)127 public boolean onTouchEvent(MotionEvent event) { 128 mOnTouchEventCalled = true; 129 mMotionEvent = event; 130 return super.onTouchEvent(event); 131 } 132 133 @Override onResume()134 protected void onResume() { 135 super.onResume(); 136 mOnResume = true; 137 } 138 139 @Override onSaveInstanceState(Bundle outState)140 protected void onSaveInstanceState(Bundle outState) { 141 super.onSaveInstanceState(outState); 142 mOnSaveInstanceState = true; 143 mBundle = outState; 144 } 145 146 @Override onStart()147 protected void onStart() { 148 super.onStart(); 149 mOnStart = true; 150 } 151 152 @Override onStop()153 protected void onStop() { 154 super.onStop(); 155 mOnStop = true; 156 } 157 158 @Override onUserLeaveHint()159 protected void onUserLeaveHint() { 160 super.onUserLeaveHint(); 161 mOnLeave = true; 162 } 163 164 @Override onMenuOpened(int featureId, Menu menu)165 public boolean onMenuOpened(int featureId, Menu menu) { 166 mOnMenuOpened = true; 167 return super.onMenuOpened(featureId, menu); 168 } 169 170 @Override onCreateOptionsMenu(Menu menu)171 public boolean onCreateOptionsMenu(Menu menu) { 172 super.onCreateOptionsMenu(menu); 173 MenuInflater inflater = getMenuInflater(); 174 inflater.inflate(R.menu.browser, menu); 175 176 menu.add("title"); 177 mOnMenuOpened = true; 178 return true; 179 } 180 181 @Override onCreatePanelMenu(int featureId, Menu menu)182 public boolean onCreatePanelMenu(int featureId, Menu menu) { 183 return super.onCreatePanelMenu(featureId, menu); 184 } 185 186 @Override onMenuItemSelected(int featureId, MenuItem item)187 public boolean onMenuItemSelected(int featureId, MenuItem item) { 188 mMenuID = item.getItemId(); 189 return super.onMenuItemSelected(featureId, item); 190 } 191 192 @Override openContextMenu(View view)193 public void openContextMenu(View view) { 194 super.openContextMenu(view); 195 } 196 197 @Override openOptionsMenu()198 public void openOptionsMenu() { 199 super.openOptionsMenu(); 200 } 201 202 @Override onOptionsItemSelected(MenuItem item)203 public boolean onOptionsItemSelected(MenuItem item) { 204 return super.onOptionsItemSelected(item); 205 } 206 207 @Override onKeyDown(int keyCode, KeyEvent event)208 public boolean onKeyDown(int keyCode, KeyEvent event) { 209 mKeyDownList.add(event); 210 mKeyDownCode = keyCode; 211 return super.onKeyDown(keyCode, event); 212 } 213 214 @Override onTrackballEvent(MotionEvent event)215 public boolean onTrackballEvent(MotionEvent event) { 216 mMotionEvent = event; 217 return super.onTrackballEvent(event); 218 } 219 220 @Override onKeyUp(int keyCode, KeyEvent event)221 public boolean onKeyUp(int keyCode, KeyEvent event) { 222 mKeyUpList.add(event); 223 mKeyUpCode = keyCode; 224 return super.onKeyUp(keyCode, event); 225 } 226 isOnCreateCalled()227 public boolean isOnCreateCalled() { 228 return mOnCreateCalled; 229 } 230 setOnCreateCalled(boolean onCreateCalled)231 public void setOnCreateCalled(boolean onCreateCalled) { 232 mOnCreateCalled = onCreateCalled; 233 } 234 isOnDestroyCalled()235 public boolean isOnDestroyCalled() { 236 return mOnDestroyCalled; 237 } 238 setOnDestroyCalled(boolean onDestroyCalled)239 public void setOnDestroyCalled(boolean onDestroyCalled) { 240 mOnDestroyCalled = onDestroyCalled; 241 } 242 isOnNewIntentCalled()243 public boolean isOnNewIntentCalled() { 244 return mOnNewIntentCalled; 245 } 246 setOnNewIntentCalled(boolean onNewIntentCalled)247 public void setOnNewIntentCalled(boolean onNewIntentCalled) { 248 mOnNewIntentCalled = onNewIntentCalled; 249 } 250 isOnPauseCalled()251 public boolean isOnPauseCalled() { 252 return mOnPauseCalled; 253 } 254 setOnPauseCalled(boolean onPauseCalled)255 public void setOnPauseCalled(boolean onPauseCalled) { 256 mOnPauseCalled = onPauseCalled; 257 } 258 isOnPostCreate()259 public boolean isOnPostCreate() { 260 return mOnPostCreate; 261 } 262 setOnPostCreate(boolean onPostCreate)263 public void setOnPostCreate(boolean onPostCreate) { 264 mOnPostCreate = onPostCreate; 265 } 266 isOnRestart()267 public boolean isOnRestart() { 268 return mOnRestart; 269 } 270 setOnRestart(boolean onRestart)271 public void setOnRestart(boolean onRestart) { 272 mOnRestart = onRestart; 273 } 274 isOnRestoreInstanceState()275 public boolean isOnRestoreInstanceState() { 276 return mOnRestoreInstanceState; 277 } 278 setOnRestoreInstanceState(boolean onRestoreInstanceState)279 public void setOnRestoreInstanceState(boolean onRestoreInstanceState) { 280 mOnRestoreInstanceState = onRestoreInstanceState; 281 } 282 isOnResume()283 public boolean isOnResume() { 284 return mOnResume; 285 } 286 setOnResume(boolean onResume)287 public void setOnResume(boolean onResume) { 288 mOnResume = onResume; 289 } 290 isOnSaveInstanceState()291 public boolean isOnSaveInstanceState() { 292 return mOnSaveInstanceState; 293 } 294 setOnSaveInstanceState(boolean onSaveInstanceState)295 public void setOnSaveInstanceState(boolean onSaveInstanceState) { 296 mOnSaveInstanceState = onSaveInstanceState; 297 } 298 isOnStart()299 public boolean isOnStart() { 300 return mOnStart; 301 } 302 setOnStart(boolean onStart)303 public void setOnStart(boolean onStart) { 304 mOnStart = onStart; 305 } 306 isOnStop()307 public boolean isOnStop() { 308 return mOnStop; 309 } 310 isOnLeave()311 public boolean isOnLeave() { 312 return mOnLeave; 313 } 314 setOnStop(boolean onStop)315 public void setOnStop(boolean onStop) { 316 mOnStop = onStop; 317 } 318 isMOnMenuOpened()319 public boolean isMOnMenuOpened() { 320 return mOnMenuOpened; 321 } 322 setOnMenuOpened(boolean onMenuOpened)323 public void setOnMenuOpened(boolean onMenuOpened) { 324 mOnMenuOpened = onMenuOpened; 325 } 326 getMenuID()327 public int getMenuID() { 328 return mMenuID; 329 } 330 setMenuID(int menuID)331 public void setMenuID(int menuID) { 332 mMenuID = menuID; 333 } 334 getMotionEvent()335 public MotionEvent getMotionEvent() { 336 return mMotionEvent; 337 } 338 getBundle()339 public Bundle getBundle() { 340 return mBundle; 341 } 342 isOnTouchEventCalled()343 public boolean isOnTouchEventCalled() { 344 return mOnTouchEventCalled; 345 } 346 setOnTouchEventCalled(boolean onTouchEventCalled)347 public void setOnTouchEventCalled(boolean onTouchEventCalled) { 348 mOnTouchEventCalled = onTouchEventCalled; 349 } 350 getKeyUpCode()351 public int getKeyUpCode() { 352 return mKeyUpCode; 353 } 354 getKeyDownCode()355 public int getKeyDownCode() { 356 return mKeyDownCode; 357 } 358 getKeyUpList()359 public List<KeyEvent> getKeyUpList() { 360 return mKeyUpList; 361 } 362 getKeyDownList()363 public List<KeyEvent> getKeyDownList() { 364 return mKeyDownList; 365 } 366 } 367