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 17 package android.view.cts; 18 19 import java.util.ArrayList; 20 21 import android.app.cts.CTSResult; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.res.XmlResourceParser; 25 import android.graphics.Bitmap; 26 import android.graphics.Canvas; 27 import android.graphics.Point; 28 import android.graphics.Rect; 29 import android.graphics.Region; 30 import android.graphics.Bitmap.Config; 31 import android.graphics.drawable.BitmapDrawable; 32 import android.os.Parcelable; 33 import android.os.SystemClock; 34 import android.test.InstrumentationTestCase; 35 import android.util.AttributeSet; 36 import android.util.DisplayMetrics; 37 import android.util.SparseArray; 38 import android.view.Display; 39 import android.view.KeyEvent; 40 import android.view.MotionEvent; 41 import android.view.View; 42 import android.view.ViewGroup; 43 import android.view.WindowManager; 44 import android.view.View.BaseSavedState; 45 import android.view.View.MeasureSpec; 46 import android.view.View.OnTouchListener; 47 import android.view.ViewGroup.LayoutParams; 48 import android.view.ViewGroup.OnHierarchyChangeListener; 49 import android.view.animation.AlphaAnimation; 50 import android.view.animation.Animation; 51 import android.view.animation.LayoutAnimationController; 52 import android.view.animation.RotateAnimation; 53 import android.view.animation.Transformation; 54 import android.view.animation.Animation.AnimationListener; 55 import android.widget.TextView; 56 import android.widget.cts.ViewGroupStubActivity; 57 58 import com.android.internal.util.XmlUtils; 59 60 import dalvik.annotation.TestTargets; 61 import dalvik.annotation.TestLevel; 62 import dalvik.annotation.TestTargetNew; 63 import dalvik.annotation.TestTargetClass; 64 import dalvik.annotation.ToBeFixed; 65 66 @TestTargetClass(ViewGroup.class) 67 public class ViewGroupTest extends InstrumentationTestCase implements CTSResult{ 68 69 private Context mContext; 70 private MotionEvent mMotionEvent; 71 private int mResultCode; 72 73 private Sync mSync = new Sync(); 74 private static class Sync { 75 boolean mHasNotify; 76 } 77 78 @Override setUp()79 protected void setUp() throws Exception { 80 super.setUp(); 81 mContext = getInstrumentation().getTargetContext(); 82 } 83 84 @TestTargets({ 85 @TestTargetNew( 86 level = TestLevel.COMPLETE, 87 method = "ViewGroup", 88 args = {android.content.Context.class} 89 ), 90 @TestTargetNew( 91 level = TestLevel.COMPLETE, 92 method = "ViewGroup", 93 args = {android.content.Context.class, android.util.AttributeSet.class} 94 ), 95 @TestTargetNew( 96 level = TestLevel.COMPLETE, 97 method = "ViewGroup", 98 args = {android.content.Context.class, android.util.AttributeSet.class, int.class} 99 ) 100 }) testConstructor()101 public void testConstructor() { 102 new MockViewGroup(mContext); 103 new MockViewGroup(mContext, null); 104 new MockViewGroup(mContext, null, 0); 105 } 106 107 @TestTargetNew( 108 level = TestLevel.COMPLETE, 109 method = "addFocusables", 110 args = {java.util.ArrayList.class, int.class} 111 ) testAddFocusables()112 public void testAddFocusables() { 113 MockViewGroup vg = new MockViewGroup(mContext); 114 vg.setFocusable(true); 115 116 ArrayList<View> list = new ArrayList<View>(); 117 TextView textView = new TextView(mContext); 118 list.add(textView); 119 vg.addView(textView); 120 vg.addFocusables(list, 0); 121 122 assertEquals(2, list.size()); 123 124 list = new ArrayList<View>(); 125 list.add(textView); 126 vg.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 127 vg.setFocusable(false); 128 vg.addFocusables(list, 0); 129 assertEquals(1, list.size()); 130 } 131 132 @TestTargets({ 133 @TestTargetNew( 134 level = TestLevel.COMPLETE, 135 method = "addStatesFromChildren", 136 args = {} 137 ), 138 @TestTargetNew( 139 level = TestLevel.COMPLETE, 140 method = "setAddStatesFromChildren", 141 args = {boolean.class} 142 ) 143 }) testAddStatesFromChildren()144 public void testAddStatesFromChildren() { 145 MockViewGroup vg = new MockViewGroup(mContext); 146 TextView textView = new TextView(mContext); 147 vg.addView(textView); 148 assertFalse(vg.addStatesFromChildren()); 149 150 vg.setAddStatesFromChildren(true); 151 textView.performClick(); 152 assertTrue(vg.addStatesFromChildren()); 153 assertTrue(vg.isDrawableStateChangedCalled); 154 } 155 156 @TestTargets({ 157 @TestTargetNew( 158 level = TestLevel.COMPLETE, 159 method = "addTouchables", 160 args = {java.util.ArrayList.class} 161 ), 162 @TestTargetNew( 163 level = TestLevel.COMPLETE, 164 method = "getChildAt", 165 args = {int.class} 166 ) 167 }) testAddTouchables()168 public void testAddTouchables() { 169 MockViewGroup vg = new MockViewGroup(mContext); 170 vg.setFocusable(true); 171 172 ArrayList<View> list = new ArrayList<View>(); 173 TextView textView = new TextView(mContext); 174 textView.setVisibility(View.VISIBLE); 175 textView.setClickable(true); 176 textView.setEnabled(true); 177 178 list.add(textView); 179 vg.addView(textView); 180 vg.addTouchables(list); 181 182 assertEquals(2, list.size()); 183 184 View v = vg.getChildAt(0); 185 assertSame(textView, v); 186 187 v = vg.getChildAt(-1); 188 assertNull(v); 189 190 v = vg.getChildAt(1); 191 assertNull(v); 192 193 v = vg.getChildAt(100); 194 assertNull(v); 195 196 v = vg.getChildAt(-100); 197 assertNull(v); 198 } 199 200 @TestTargetNew( 201 level = TestLevel.COMPLETE, 202 method = "addView", 203 args = {android.view.View.class} 204 ) testAddView()205 public void testAddView() { 206 MockViewGroup vg = new MockViewGroup(mContext); 207 TextView textView = new TextView(mContext); 208 209 assertEquals(0, vg.getChildCount()); 210 211 vg.addView(textView); 212 assertEquals(1, vg.getChildCount()); 213 } 214 215 @TestTargetNew( 216 level = TestLevel.COMPLETE, 217 method = "addView", 218 args = {android.view.View.class, int.class} 219 ) testAddViewWithParaViewInt()220 public void testAddViewWithParaViewInt() { 221 MockViewGroup vg = new MockViewGroup(mContext); 222 TextView textView = new TextView(mContext); 223 224 assertEquals(0, vg.getChildCount()); 225 226 vg.addView(textView, -1); 227 assertEquals(1, vg.getChildCount()); 228 } 229 230 @TestTargetNew( 231 level = TestLevel.COMPLETE, 232 method = "addView", 233 args = {android.view.View.class, android.view.ViewGroup.LayoutParams.class} 234 ) testAddViewWithParaViewLayoutPara()235 public void testAddViewWithParaViewLayoutPara() { 236 MockViewGroup vg = new MockViewGroup(mContext); 237 TextView textView = new TextView(mContext); 238 239 assertEquals(0, vg.getChildCount()); 240 241 vg.addView(textView, new ViewGroup.LayoutParams(100, 200)); 242 243 assertEquals(1, vg.getChildCount()); 244 } 245 246 @TestTargetNew( 247 level = TestLevel.COMPLETE, 248 method = "addView", 249 args = {android.view.View.class, int.class, int.class} 250 ) testAddViewWithParaViewIntInt()251 public void testAddViewWithParaViewIntInt() { 252 final int width = 100; 253 final int height = 200; 254 MockViewGroup vg = new MockViewGroup(mContext); 255 TextView textView = new TextView(mContext); 256 257 assertEquals(0, vg.getChildCount()); 258 259 vg.addView(textView, width, height); 260 assertEquals(width, textView.getLayoutParams().width); 261 assertEquals(height, textView.getLayoutParams().height); 262 263 assertEquals(1, vg.getChildCount()); 264 } 265 266 @TestTargetNew( 267 level = TestLevel.COMPLETE, 268 method = "addView", 269 args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class} 270 ) testAddViewWidthParaViewIntLayoutParam()271 public void testAddViewWidthParaViewIntLayoutParam() { 272 MockViewGroup vg = new MockViewGroup(mContext); 273 TextView textView = new TextView(mContext); 274 275 assertEquals(0, vg.getChildCount()); 276 277 vg.addView(textView, -1, new ViewGroup.LayoutParams(100, 200)); 278 279 assertEquals(1, vg.getChildCount()); 280 } 281 282 @TestTargetNew( 283 level = TestLevel.COMPLETE, 284 method = "addViewInLayout", 285 args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class} 286 ) testAddViewInLayout()287 public void testAddViewInLayout() { 288 MockViewGroup vg = new MockViewGroup(mContext); 289 TextView textView = new TextView(mContext); 290 291 assertEquals(0, vg.getChildCount()); 292 293 assertTrue(vg.isRequestLayoutCalled); 294 vg.isRequestLayoutCalled = false; 295 assertTrue(vg.addViewInLayout(textView, -1, new ViewGroup.LayoutParams(100, 200))); 296 assertEquals(1, vg.getChildCount()); 297 // check that calling addViewInLayout() does not trigger a 298 // requestLayout() on this ViewGroup 299 assertFalse(vg.isRequestLayoutCalled); 300 } 301 302 @TestTargetNew( 303 level = TestLevel.COMPLETE, 304 method = "attachLayoutAnimationParameters", 305 args = {android.view.View.class, android.view.ViewGroup.LayoutParams.class, int.class, 306 int.class} 307 ) testAttachLayoutAnimationParameters()308 public void testAttachLayoutAnimationParameters() { 309 MockViewGroup vg = new MockViewGroup(mContext); 310 ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(10, 10); 311 312 vg.attachLayoutAnimationParameters(null, param, 1, 2); 313 assertEquals(2, param.layoutAnimationParameters.count); 314 assertEquals(1, param.layoutAnimationParameters.index); 315 } 316 317 @TestTargetNew( 318 level = TestLevel.COMPLETE, 319 method = "attachViewToParent", 320 args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class} 321 ) testAttachViewToParent()322 public void testAttachViewToParent() { 323 MockViewGroup vg = new MockViewGroup(mContext); 324 vg.setFocusable(true); 325 assertEquals(0, vg.getChildCount()); 326 327 ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(10, 10); 328 329 TextView child = new TextView(mContext); 330 child.setFocusable(true); 331 vg.attachViewToParent(child, -1, param); 332 assertSame(vg, child.getParent()); 333 assertEquals(1, vg.getChildCount()); 334 assertSame(child, vg.getChildAt(0)); 335 } 336 337 @TestTargetNew( 338 level = TestLevel.COMPLETE, 339 method = "addViewInLayout", 340 args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class, 341 boolean.class} 342 ) testAddViewInLayoutWithParamViewIntLayB()343 public void testAddViewInLayoutWithParamViewIntLayB() { 344 MockViewGroup vg = new MockViewGroup(mContext); 345 TextView textView = new TextView(mContext); 346 347 assertEquals(0, vg.getChildCount()); 348 349 assertTrue(vg.isRequestLayoutCalled); 350 vg.isRequestLayoutCalled = false; 351 assertTrue(vg.addViewInLayout(textView, -1, new ViewGroup.LayoutParams(100, 200), true)); 352 353 assertEquals(1, vg.getChildCount()); 354 // check that calling addViewInLayout() does not trigger a 355 // requestLayout() on this ViewGroup 356 assertFalse(vg.isRequestLayoutCalled); 357 } 358 359 @TestTargetNew( 360 level = TestLevel.COMPLETE, 361 method = "bringChildToFront", 362 args = {android.view.View.class} 363 ) testBringChildToFront()364 public void testBringChildToFront() { 365 MockViewGroup vg = new MockViewGroup(mContext); 366 TextView textView1 = new TextView(mContext); 367 TextView textView2 = new TextView(mContext); 368 369 assertEquals(0, vg.getChildCount()); 370 371 vg.addView(textView1); 372 vg.addView(textView2); 373 assertEquals(2, vg.getChildCount()); 374 375 vg.bringChildToFront(textView1); 376 assertEquals(vg, textView1.getParent()); 377 assertEquals(2, vg.getChildCount()); 378 assertNotNull(vg.getChildAt(0)); 379 assertSame(textView2, vg.getChildAt(0)); 380 381 vg.bringChildToFront(textView2); 382 assertEquals(vg, textView2.getParent()); 383 assertEquals(2, vg.getChildCount()); 384 assertNotNull(vg.getChildAt(0)); 385 assertSame(textView1, vg.getChildAt(0)); 386 } 387 388 @TestTargetNew( 389 level = TestLevel.COMPLETE, 390 method = "canAnimate", 391 args = {} 392 ) testCanAnimate()393 public void testCanAnimate() { 394 MockViewGroup vg = new MockViewGroup(mContext); 395 396 assertFalse(vg.canAnimate()); 397 398 RotateAnimation animation = new RotateAnimation(0.1f, 0.1f); 399 LayoutAnimationController la = new LayoutAnimationController(animation); 400 vg.setLayoutAnimation(la); 401 assertTrue(vg.canAnimate()); 402 } 403 404 @TestTargetNew( 405 level = TestLevel.COMPLETE, 406 method = "checkLayoutParams", 407 args = {android.view.ViewGroup.LayoutParams.class} 408 ) testCheckLayoutParams()409 public void testCheckLayoutParams() { 410 MockViewGroup view = new MockViewGroup(mContext); 411 assertFalse(view.checkLayoutParams(null)); 412 413 assertTrue(view.checkLayoutParams(new ViewGroup.LayoutParams(100, 200))); 414 } 415 416 @TestTargetNew( 417 level = TestLevel.COMPLETE, 418 method = "childDrawableStateChanged", 419 args = {android.view.View.class} 420 ) testChildDrawableStateChanged()421 public void testChildDrawableStateChanged() { 422 MockViewGroup vg = new MockViewGroup(mContext); 423 vg.setAddStatesFromChildren(true); 424 425 vg.childDrawableStateChanged(null); 426 assertTrue(vg.isRefreshDrawableStateCalled); 427 } 428 429 @TestTargetNew( 430 level = TestLevel.COMPLETE, 431 method = "cleanupLayoutState", 432 args = {android.view.View.class} 433 ) testCleanupLayoutState()434 public void testCleanupLayoutState() { 435 MockViewGroup vg = new MockViewGroup(mContext); 436 TextView textView = new TextView(mContext); 437 438 assertTrue(textView.isLayoutRequested()); 439 440 vg.cleanupLayoutState(textView); 441 assertFalse(textView.isLayoutRequested()); 442 } 443 444 @TestTargets({ 445 @TestTargetNew( 446 level = TestLevel.COMPLETE, 447 method = "clearChildFocus", 448 args = {android.view.View.class} 449 ), 450 @TestTargetNew( 451 level = TestLevel.COMPLETE, 452 method = "getFocusedChild", 453 args = {} 454 ) 455 }) testClearChildFocus()456 public void testClearChildFocus() { 457 MockViewGroup vg = new MockViewGroup(mContext); 458 TextView textView = new TextView(mContext); 459 460 vg.addView(textView); 461 vg.requestChildFocus(textView, null); 462 463 View focusedView = vg.getFocusedChild(); 464 assertSame(textView, focusedView); 465 466 vg.clearChildFocus(textView); 467 assertNull(vg.getFocusedChild()); 468 } 469 470 @TestTargetNew( 471 level = TestLevel.COMPLETE, 472 method = "clearDisappearingChildren", 473 args = {} 474 ) testClearDisappearingChildren()475 public void testClearDisappearingChildren() { 476 477 Canvas canvas = new Canvas(); 478 MockViewGroup vg = new MockViewGroup(mContext); 479 MockViewGroup son = new MockViewGroup(mContext); 480 son.setAnimation(new MockAnimation()); 481 vg.addView(son); 482 assertEquals(1, vg.getChildCount()); 483 484 assertNotNull(son.getAnimation()); 485 vg.dispatchDraw(canvas); 486 assertEquals(1, vg.drawChildCalledTime); 487 488 son.setAnimation(new MockAnimation()); 489 vg.removeAllViewsInLayout(); 490 491 vg.drawChildCalledTime = 0; 492 vg.dispatchDraw(canvas); 493 assertEquals(1, vg.drawChildCalledTime); 494 495 son.setAnimation(new MockAnimation()); 496 vg.clearDisappearingChildren(); 497 498 vg.drawChildCalledTime = 0; 499 vg.dispatchDraw(canvas); 500 assertEquals(0, vg.drawChildCalledTime); 501 } 502 503 @TestTargetNew( 504 level = TestLevel.COMPLETE, 505 method = "clearFocus", 506 args = {} 507 ) testClearFocus()508 public void testClearFocus() { 509 MockViewGroup vg = new MockViewGroup(mContext); 510 MockTextView textView = new MockTextView(mContext); 511 512 vg.addView(textView); 513 vg.requestChildFocus(textView, null); 514 vg.clearFocus(); 515 assertTrue(textView.isClearFocusCalled); 516 } 517 518 @TestTargetNew( 519 level = TestLevel.COMPLETE, 520 method = "detachAllViewsFromParent", 521 args = {} 522 ) testDetachAllViewsFromParent()523 public void testDetachAllViewsFromParent() { 524 MockViewGroup vg = new MockViewGroup(mContext); 525 TextView textView = new TextView(mContext); 526 527 vg.addView(textView); 528 assertEquals(1, vg.getChildCount()); 529 assertSame(vg, textView.getParent()); 530 vg.detachAllViewsFromParent(); 531 assertEquals(0, vg.getChildCount()); 532 assertNull(textView.getParent()); 533 } 534 535 @TestTargetNew( 536 level = TestLevel.COMPLETE, 537 method = "detachViewFromParent", 538 args = {int.class} 539 ) testDetachViewFromParent()540 public void testDetachViewFromParent() { 541 MockViewGroup vg = new MockViewGroup(mContext); 542 TextView textView = new TextView(mContext); 543 544 vg.addView(textView); 545 assertEquals(1, vg.getChildCount()); 546 547 vg.detachViewFromParent(0); 548 549 assertEquals(0, vg.getChildCount()); 550 assertNull(textView.getParent()); 551 } 552 553 @TestTargetNew( 554 level = TestLevel.COMPLETE, 555 method = "detachViewFromParent", 556 args = {android.view.View.class} 557 ) testDetachViewFromParentWithParamView()558 public void testDetachViewFromParentWithParamView() { 559 MockViewGroup vg = new MockViewGroup(mContext); 560 TextView textView = new TextView(mContext); 561 562 vg.addView(textView); 563 assertEquals(1, vg.getChildCount()); 564 assertSame(vg, textView.getParent()); 565 566 vg.detachViewFromParent(textView); 567 568 assertEquals(0, vg.getChildCount()); 569 assertNull(vg.getParent()); 570 } 571 572 @TestTargetNew( 573 level = TestLevel.COMPLETE, 574 method = "detachViewsFromParent", 575 args = {int.class, int.class} 576 ) testDetachViewsFromParent()577 public void testDetachViewsFromParent() { 578 MockViewGroup vg = new MockViewGroup(mContext); 579 TextView textView1 = new TextView(mContext); 580 TextView textView2 = new TextView(mContext); 581 TextView textView3 = new TextView(mContext); 582 583 vg.addView(textView1); 584 vg.addView(textView2); 585 vg.addView(textView3); 586 assertEquals(3, vg.getChildCount()); 587 588 vg.detachViewsFromParent(0, 2); 589 590 assertEquals(1, vg.getChildCount()); 591 assertNull(textView1.getParent()); 592 assertNull(textView2.getParent()); 593 } 594 595 @TestTargetNew( 596 level = TestLevel.COMPLETE, 597 method = "dispatchDraw", 598 args = {android.graphics.Canvas.class} 599 ) testDispatchDraw()600 public void testDispatchDraw() { 601 MockViewGroup vg = new MockViewGroup(mContext); 602 Canvas canvas = new Canvas(); 603 604 vg.draw(canvas); 605 assertTrue(vg.isDispatchDrawCalled); 606 assertSame(canvas, vg.canvas); 607 } 608 609 @TestTargetNew( 610 level = TestLevel.COMPLETE, 611 method = "dispatchFreezeSelfOnly", 612 args = {android.util.SparseArray.class} 613 ) 614 @SuppressWarnings("unchecked") testDispatchFreezeSelfOnly()615 public void testDispatchFreezeSelfOnly() { 616 MockViewGroup vg = new MockViewGroup(mContext); 617 vg.setId(1); 618 vg.setSaveEnabled(true); 619 620 SparseArray container = new SparseArray(); 621 assertEquals(0, container.size()); 622 vg.dispatchFreezeSelfOnly(container); 623 assertEquals(1, container.size()); 624 } 625 626 @TestTargetNew( 627 level = TestLevel.COMPLETE, 628 method = "dispatchKeyEvent", 629 args = {android.view.KeyEvent.class} 630 ) testDispatchKeyEvent()631 public void testDispatchKeyEvent() { 632 MockViewGroup vg = new MockViewGroup(mContext); 633 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER); 634 assertFalse(vg.dispatchKeyEvent(event)); 635 636 MockTextView textView = new MockTextView(mContext); 637 vg.addView(textView); 638 vg.requestChildFocus(textView, null); 639 textView.setFrame(1, 1, 100, 100); 640 641 assertTrue(vg.dispatchKeyEvent(event)); 642 } 643 644 @TestTargets({ 645 @TestTargetNew( 646 level = TestLevel.COMPLETE, 647 method = "dispatchRestoreInstanceState", 648 args = {android.util.SparseArray.class} 649 ), 650 @TestTargetNew( 651 level = TestLevel.COMPLETE, 652 method = "dispatchSaveInstanceState", 653 args = {android.util.SparseArray.class} 654 ) 655 }) 656 @SuppressWarnings("unchecked") testDispatchSaveInstanceState()657 public void testDispatchSaveInstanceState() { 658 MockViewGroup vg = new MockViewGroup(mContext); 659 vg.setId(2); 660 vg.setSaveEnabled(true); 661 MockTextView textView = new MockTextView(mContext); 662 textView.setSaveEnabled(true); 663 textView.setId(1); 664 vg.addView(textView); 665 666 SparseArray array = new SparseArray(); 667 vg.dispatchSaveInstanceState(array); 668 669 assertTrue(array.size() > 0); 670 assertNotNull(array.get(2)); 671 672 array = new SparseArray(); 673 vg.dispatchRestoreInstanceState(array); 674 assertTrue(textView.isDispatchRestoreInstanceStateCalled); 675 } 676 677 @TestTargetNew( 678 level = TestLevel.COMPLETE, 679 method = "dispatchSetPressed", 680 args = {boolean.class} 681 ) testDispatchSetPressed()682 public void testDispatchSetPressed() { 683 MockViewGroup vg = new MockViewGroup(mContext); 684 MockTextView textView = new MockTextView(mContext); 685 vg.addView(textView); 686 687 vg.dispatchSetPressed(true); 688 assertTrue(textView.isPressed()); 689 690 vg.dispatchSetPressed(false); 691 assertFalse(textView.isPressed()); 692 } 693 694 @TestTargetNew( 695 level = TestLevel.COMPLETE, 696 method = "dispatchSetSelected", 697 args = {boolean.class} 698 ) testDispatchSetSelected()699 public void testDispatchSetSelected() { 700 MockViewGroup vg = new MockViewGroup(mContext); 701 MockTextView textView = new MockTextView(mContext); 702 vg.addView(textView); 703 704 vg.dispatchSetSelected(true); 705 assertTrue(textView.isSelected()); 706 707 vg.dispatchSetSelected(false); 708 assertFalse(textView.isSelected()); 709 } 710 711 @TestTargetNew( 712 level = TestLevel.COMPLETE, 713 method = "dispatchThawSelfOnly", 714 args = {android.util.SparseArray.class} 715 ) 716 @SuppressWarnings("unchecked") testDispatchThawSelfOnly()717 public void testDispatchThawSelfOnly() { 718 MockViewGroup vg = new MockViewGroup(mContext); 719 vg.setId(1); 720 SparseArray array = new SparseArray(); 721 array.put(1, BaseSavedState.EMPTY_STATE); 722 723 vg.dispatchThawSelfOnly(array); 724 assertTrue(vg.isOnRestoreInstanceStateCalled); 725 726 } 727 728 @TestTargetNew( 729 level = TestLevel.COMPLETE, 730 method = "dispatchTouchEvent", 731 args = {android.view.MotionEvent.class} 732 ) testDispatchTouchEvent()733 public void testDispatchTouchEvent() { 734 MockViewGroup vg = new MockViewGroup(mContext); 735 736 DisplayMetrics metrics = new DisplayMetrics(); 737 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 738 Display d = wm.getDefaultDisplay(); 739 d.getMetrics(metrics); 740 int screenWidth = metrics.widthPixels; 741 int screenHeight = metrics.heightPixels; 742 vg.setFrame(0, 0, screenWidth, screenHeight); 743 vg.setLayoutParams(new ViewGroup.LayoutParams(screenWidth, screenHeight)); 744 745 MockTextView textView = new MockTextView(mContext); 746 mMotionEvent = null; 747 textView.setOnTouchListener(new OnTouchListener() { 748 public boolean onTouch(View v, MotionEvent event) { 749 mMotionEvent = event; 750 return true; 751 } 752 }); 753 754 textView.setVisibility(View.VISIBLE); 755 textView.setEnabled(true); 756 757 vg.addView(textView, new LayoutParams(screenWidth, screenHeight)); 758 759 vg.requestDisallowInterceptTouchEvent(true); 760 MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), 761 SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 762 screenWidth / 2, screenHeight / 2, 0); 763 764 assertFalse(vg.dispatchTouchEvent(me)); 765 assertNull(mMotionEvent); 766 767 textView.setFrame(0, 0, screenWidth, screenHeight); 768 assertTrue(vg.dispatchTouchEvent(me)); 769 assertSame(me, mMotionEvent); 770 } 771 772 @TestTargetNew( 773 level = TestLevel.COMPLETE, 774 method = "dispatchTrackballEvent", 775 args = {android.view.MotionEvent.class} 776 ) testDispatchTrackballEvent()777 public void testDispatchTrackballEvent() { 778 MockViewGroup vg = new MockViewGroup(mContext); 779 MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), 780 SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 100, 100, 781 0); 782 assertFalse(vg.dispatchTrackballEvent(me)); 783 784 MockTextView textView = new MockTextView(mContext); 785 vg.addView(textView); 786 textView.setFrame(1, 1, 100, 100); 787 vg.requestChildFocus(textView, null); 788 assertTrue(vg.dispatchTrackballEvent(me)); 789 } 790 791 @TestTargetNew( 792 level = TestLevel.COMPLETE, 793 method = "dispatchUnhandledMove", 794 args = {android.view.View.class, int.class} 795 ) testDispatchUnhandledMove()796 public void testDispatchUnhandledMove() { 797 MockViewGroup vg = new MockViewGroup(mContext); 798 MockTextView textView = new MockTextView(mContext); 799 assertFalse(vg.dispatchUnhandledMove(textView, View.FOCUS_DOWN)); 800 801 vg.addView(textView); 802 textView.setFrame(1, 1, 100, 100); 803 vg.requestChildFocus(textView, null); 804 assertTrue(vg.dispatchUnhandledMove(textView, View.FOCUS_DOWN)); 805 } 806 807 @TestTargetNew( 808 level = TestLevel.COMPLETE, 809 method = "dispatchWindowFocusChanged", 810 args = {boolean.class} 811 ) testDispatchWindowFocusChanged()812 public void testDispatchWindowFocusChanged() { 813 MockViewGroup vg = new MockViewGroup(mContext); 814 MockTextView textView = new MockTextView(mContext); 815 816 vg.addView(textView); 817 textView.setPressed(true); 818 assertTrue(textView.isPressed()); 819 820 vg.dispatchWindowFocusChanged(false); 821 assertFalse(textView.isPressed()); 822 } 823 824 @TestTargetNew( 825 level = TestLevel.COMPLETE, 826 method = "dispatchWindowVisibilityChanged", 827 args = {int.class} 828 ) testDispatchWindowVisibilityChanged()829 public void testDispatchWindowVisibilityChanged() { 830 int expected = 10; 831 MockViewGroup vg = new MockViewGroup(mContext); 832 MockTextView textView = new MockTextView(mContext); 833 834 vg.addView(textView); 835 vg.dispatchWindowVisibilityChanged(expected); 836 assertEquals(expected, textView.visibility); 837 } 838 839 @TestTargetNew( 840 level = TestLevel.COMPLETE, 841 method = "drawableStateChanged", 842 args = {} 843 ) testDrawableStateChanged()844 public void testDrawableStateChanged() { 845 MockViewGroup vg = new MockViewGroup(mContext); 846 MockTextView textView = new MockTextView(mContext); 847 textView.setDuplicateParentStateEnabled(true); 848 849 vg.addView(textView); 850 vg.setAddStatesFromChildren(false); 851 vg.drawableStateChanged(); 852 assertTrue(textView.mIsRefreshDrawableStateCalled); 853 } 854 855 @TestTargetNew( 856 level = TestLevel.COMPLETE, 857 method = "drawChild", 858 args = {android.graphics.Canvas.class, android.view.View.class, long.class} 859 ) testDrawChild()860 public void testDrawChild() { 861 MockViewGroup vg = new MockViewGroup(mContext); 862 MockTextView textView = new MockTextView(mContext); 863 vg.addView(textView); 864 865 MockCanvas canvas = new MockCanvas(); 866 textView.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(100, 100, 867 Config.ALPHA_8))); 868 assertFalse(vg.drawChild(canvas, textView, 100)); 869 // test whether child's draw method is called. 870 assertTrue(textView.isDrawCalled); 871 } 872 873 @TestTargetNew( 874 level = TestLevel.COMPLETE, 875 method = "findFocus", 876 args = {} 877 ) testFindFocus()878 public void testFindFocus() { 879 MockViewGroup vg = new MockViewGroup(mContext); 880 881 assertNull(vg.findFocus()); 882 vg.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 883 vg.setFocusable(true); 884 vg.setVisibility(View.VISIBLE); 885 vg.setFocusableInTouchMode(true); 886 assertTrue(vg.requestFocus(1, new Rect())); 887 888 assertSame(vg, vg.findFocus()); 889 } 890 891 @TestTargetNew( 892 level = TestLevel.COMPLETE, 893 method = "fitSystemWindows", 894 args = {android.graphics.Rect.class} 895 ) testFitSystemWindows()896 public void testFitSystemWindows() { 897 Rect rect = new Rect(1, 1, 100, 100); 898 MockViewGroup vg = new MockViewGroup(mContext); 899 assertFalse(vg.fitSystemWindows(rect)); 900 901 vg = new MockViewGroup(mContext, null, 0); 902 MockView mv = new MockView(mContext); 903 vg.addView(mv); 904 assertTrue(vg.fitSystemWindows(rect)); 905 } 906 907 static class MockView extends ViewGroup { 908 909 public int mWidthMeasureSpec; 910 public int mHeightMeasureSpec; 911 MockView(Context context)912 public MockView(Context context) { 913 super(context); 914 } 915 916 @Override onLayout(boolean changed, int l, int t, int r, int b)917 public void onLayout(boolean changed, int l, int t, int r, int b) { 918 } 919 920 @Override fitSystemWindows(Rect insets)921 public boolean fitSystemWindows(Rect insets) { 922 return true; 923 } 924 925 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)926 public void onMeasure(int widthMeasureSpec, 927 int heightMeasureSpec) { 928 mWidthMeasureSpec = widthMeasureSpec; 929 mHeightMeasureSpec = heightMeasureSpec; 930 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 931 } 932 } 933 934 @TestTargetNew( 935 level = TestLevel.COMPLETE, 936 method = "focusableViewAvailable", 937 args = {android.view.View.class} 938 ) testFocusableViewAvailable()939 public void testFocusableViewAvailable() { 940 MockViewGroup vg = new MockViewGroup(mContext); 941 MockView son = new MockView(mContext); 942 vg.addView(son); 943 944 son.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 945 son.focusableViewAvailable(vg); 946 947 assertTrue(vg.isFocusableViewAvailable); 948 } 949 950 @TestTargetNew( 951 level = TestLevel.COMPLETE, 952 method = "focusSearch", 953 args = {android.view.View.class, int.class} 954 ) testFocusSearch()955 public void testFocusSearch() { 956 MockViewGroup vg = new MockViewGroup(mContext); 957 MockTextView textView = new MockTextView(mContext); 958 MockView son = new MockView(mContext); 959 vg.addView(son); 960 son.addView(textView); 961 assertNotNull(son.focusSearch(textView, 1)); 962 assertSame(textView, son.focusSearch(textView, 1)); 963 } 964 965 @TestTargetNew( 966 level = TestLevel.COMPLETE, 967 method = "gatherTransparentRegion", 968 args = {android.graphics.Region.class} 969 ) 970 @ToBeFixed(bug = "1391284", explanation = "Currently this function always return true") testGatherTransparentRegion()971 public void testGatherTransparentRegion() { 972 Region region = new Region(); 973 MockViewGroup vg = new MockViewGroup(mContext); 974 MockTextView textView = new MockTextView(mContext); 975 textView.setAnimation(new AlphaAnimation(mContext, null)); 976 textView.setVisibility(100); 977 vg.addView(textView); 978 assertEquals(1, vg.getChildCount()); 979 980 assertTrue(vg.gatherTransparentRegion(region)); 981 assertTrue(vg.gatherTransparentRegion(null)); 982 } 983 984 @TestTargetNew( 985 level = TestLevel.COMPLETE, 986 method = "generateDefaultLayoutParams", 987 args = {} 988 ) testGenerateDefaultLayoutParams()989 public void testGenerateDefaultLayoutParams(){ 990 MockViewGroup vg = new MockViewGroup(mContext); 991 LayoutParams lp = vg.generateDefaultLayoutParams(); 992 993 assertEquals(LayoutParams.WRAP_CONTENT, lp.width); 994 assertEquals(LayoutParams.WRAP_CONTENT, lp.height); 995 } 996 997 @TestTargetNew( 998 level = TestLevel.COMPLETE, 999 method = "generateLayoutParams", 1000 args = {android.util.AttributeSet.class} 1001 ) testGenerateLayoutParamsWithParaAttributeSet()1002 public void testGenerateLayoutParamsWithParaAttributeSet() throws Exception{ 1003 MockViewGroup vg = new MockViewGroup(mContext); 1004 XmlResourceParser set = mContext.getResources().getLayout( 1005 com.android.cts.stub.R.layout.abslistview_layout); 1006 XmlUtils.beginDocument(set, "ViewGroup_Layout"); 1007 LayoutParams lp = vg.generateLayoutParams(set); 1008 assertNotNull(lp); 1009 assertEquals(25, lp.height); 1010 assertEquals(25, lp.width); 1011 } 1012 1013 @TestTargetNew( 1014 level = TestLevel.COMPLETE, 1015 method = "generateLayoutParams", 1016 args = {android.view.ViewGroup.LayoutParams.class} 1017 ) testGenerateLayoutParams()1018 public void testGenerateLayoutParams() { 1019 MockViewGroup vg = new MockViewGroup(mContext); 1020 LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT, 1021 LayoutParams.FILL_PARENT); 1022 assertSame(p, vg.generateLayoutParams(p)); 1023 } 1024 1025 @TestTargetNew( 1026 level = TestLevel.COMPLETE, 1027 method = "getChildDrawingOrder", 1028 args = {int.class, int.class} 1029 ) testGetChildDrawingOrder()1030 public void testGetChildDrawingOrder() { 1031 MockViewGroup vg = new MockViewGroup(mContext); 1032 assertEquals(1, vg.getChildDrawingOrder(0, 1)); 1033 assertEquals(2, vg.getChildDrawingOrder(0, 2)); 1034 } 1035 1036 @TestTargetNew( 1037 level = TestLevel.COMPLETE, 1038 method = "getChildMeasureSpec", 1039 args = {int.class, int.class, int.class} 1040 ) testGetChildMeasureSpec()1041 public void testGetChildMeasureSpec() { 1042 int spec = 1; 1043 int padding = 1; 1044 int childDimension = 1; 1045 assertEquals(MeasureSpec.makeMeasureSpec(childDimension, MeasureSpec.EXACTLY), 1046 ViewGroup.getChildMeasureSpec(spec, padding, childDimension)); 1047 spec = 4; 1048 padding = 6; 1049 childDimension = 9; 1050 assertEquals(MeasureSpec.makeMeasureSpec(childDimension, MeasureSpec.EXACTLY), 1051 ViewGroup.getChildMeasureSpec(spec, padding, childDimension)); 1052 } 1053 1054 @TestTargetNew( 1055 level = TestLevel.COMPLETE, 1056 method = "getChildStaticTransformation", 1057 args = {android.view.View.class, android.view.animation.Transformation.class} 1058 ) testGetChildStaticTransformation()1059 public void testGetChildStaticTransformation() { 1060 MockViewGroup vg = new MockViewGroup(mContext); 1061 assertFalse(vg.getChildStaticTransformation(null, null)); 1062 } 1063 1064 @TestTargetNew( 1065 level = TestLevel.COMPLETE, 1066 method = "getChildVisibleRect", 1067 args = {android.view.View.class, android.graphics.Rect.class, android.graphics.Point.class} 1068 ) testGetChildVisibleRect()1069 public void testGetChildVisibleRect() { 1070 MockViewGroup vg = new MockViewGroup(mContext); 1071 MockTextView textView = new MockTextView(mContext); 1072 1073 textView.setFrame(1, 1, 100, 100); 1074 Rect rect = new Rect(1, 1, 50, 50); 1075 Point p = new Point(); 1076 assertFalse(vg.getChildVisibleRect(textView, rect, p)); 1077 1078 textView.setFrame(0, 0, 0, 0); 1079 vg.setFrame(20, 20, 60, 60); 1080 rect = new Rect(10, 10, 40, 40); 1081 p = new Point(); 1082 assertTrue(vg.getChildVisibleRect(textView, rect, p)); 1083 } 1084 1085 @TestTargetNew( 1086 level = TestLevel.COMPLETE, 1087 method = "getDescendantFocusability", 1088 args = {} 1089 ) testGetDescendantFocusability()1090 public void testGetDescendantFocusability() { 1091 MockViewGroup vg = new MockViewGroup(mContext); 1092 final int FLAG_MASK_FOCUSABILITY = 0x60000; 1093 assertFalse((vg.getDescendantFocusability() & FLAG_MASK_FOCUSABILITY) == 0); 1094 1095 vg.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 1096 assertFalse((vg.getDescendantFocusability() & FLAG_MASK_FOCUSABILITY) == 0); 1097 } 1098 1099 @TestTargetNew( 1100 level = TestLevel.COMPLETE, 1101 method = "getLayoutAnimation", 1102 args = {} 1103 ) testGetLayoutAnimation()1104 public void testGetLayoutAnimation() { 1105 MockViewGroup vg = new MockViewGroup(mContext); 1106 1107 assertNull(vg.getLayoutAnimation()); 1108 RotateAnimation animation = new RotateAnimation(0.1f, 0.1f); 1109 LayoutAnimationController la = new LayoutAnimationController(animation); 1110 vg.setLayoutAnimation(la); 1111 assertTrue(vg.canAnimate()); 1112 assertSame(la, vg.getLayoutAnimation()); 1113 } 1114 1115 @TestTargets({ 1116 @TestTargetNew( 1117 level = TestLevel.COMPLETE, 1118 method = "getLayoutAnimationListener", 1119 args = {} 1120 ), 1121 @TestTargetNew( 1122 level = TestLevel.COMPLETE, 1123 method = "setLayoutAnimationListener", 1124 args = {android.view.animation.Animation.AnimationListener.class} 1125 ) 1126 }) testGetLayoutAnimationListener()1127 public void testGetLayoutAnimationListener() { 1128 MockViewGroup vg = new MockViewGroup(mContext); 1129 1130 assertNull(vg.getLayoutAnimationListener()); 1131 1132 AnimationListener al = new AnimationListener() { 1133 1134 public void onAnimationEnd(Animation animation) { 1135 } 1136 1137 public void onAnimationRepeat(Animation animation) { 1138 } 1139 1140 public void onAnimationStart(Animation animation) { 1141 } 1142 }; 1143 vg.setLayoutAnimationListener(al); 1144 assertSame(al, vg.getLayoutAnimationListener()); 1145 } 1146 1147 @TestTargetNew( 1148 level = TestLevel.COMPLETE, 1149 method = "getPersistentDrawingCache", 1150 args = {} 1151 ) testGetPersistentDrawingCache()1152 public void testGetPersistentDrawingCache() { 1153 MockViewGroup vg = new MockViewGroup(mContext); 1154 final int mPersistentDrawingCache1 = 2; 1155 final int mPersistentDrawingCache2 = 3; 1156 assertEquals(mPersistentDrawingCache1, vg.getPersistentDrawingCache()); 1157 1158 vg.setPersistentDrawingCache(mPersistentDrawingCache2); 1159 assertEquals(mPersistentDrawingCache2, vg.getPersistentDrawingCache()); 1160 } 1161 1162 @TestTargetNew( 1163 level = TestLevel.COMPLETE, 1164 method = "hasFocus", 1165 args = {} 1166 ) testHasFocus()1167 public void testHasFocus() { 1168 MockViewGroup vg = new MockViewGroup(mContext); 1169 assertFalse(vg.hasFocus()); 1170 1171 TextView textView = new TextView(mContext); 1172 1173 vg.addView(textView); 1174 vg.requestChildFocus(textView, null); 1175 1176 assertTrue(vg.hasFocus()); 1177 } 1178 1179 @TestTargetNew( 1180 level = TestLevel.COMPLETE, 1181 method = "hasFocusable", 1182 args = {} 1183 ) testHasFocusable()1184 public void testHasFocusable() { 1185 MockViewGroup vg = new MockViewGroup(mContext); 1186 assertFalse(vg.hasFocusable()); 1187 1188 vg.setVisibility(View.VISIBLE); 1189 vg.setFocusable(true); 1190 assertTrue(vg.hasFocusable()); 1191 } 1192 1193 @TestTargetNew( 1194 level = TestLevel.COMPLETE, 1195 method = "indexOfChild", 1196 args = {android.view.View.class} 1197 ) testIndexOfChild()1198 public void testIndexOfChild() { 1199 MockViewGroup vg = new MockViewGroup(mContext); 1200 TextView textView = new TextView(mContext); 1201 1202 assertEquals(-1, vg.indexOfChild(textView)); 1203 1204 vg.addView(textView); 1205 assertEquals(0, vg.indexOfChild(textView)); 1206 } 1207 setupActivity(String action)1208 private void setupActivity(String action) { 1209 1210 Intent intent = new Intent(getInstrumentation().getTargetContext(), 1211 ViewGroupStubActivity.class); 1212 intent.setAction(action); 1213 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 1214 getInstrumentation().getTargetContext().startActivity(intent); 1215 } 1216 1217 @TestTargets({ 1218 @TestTargetNew( 1219 level = TestLevel.COMPLETE, 1220 method = "invalidateChild", 1221 args = {android.view.View.class, android.graphics.Rect.class} 1222 ), 1223 @TestTargetNew( 1224 level = TestLevel.COMPLETE, 1225 method = "invalidateChildInParent", 1226 args = {int[].class, android.graphics.Rect.class} 1227 ) 1228 }) testInvalidateChild()1229 public void testInvalidateChild() { 1230 ViewGroupStubActivity.setResult(this); 1231 setupActivity(ViewGroupStubActivity.ACTION_INVALIDATE_CHILD); 1232 waitForResult(); 1233 assertEquals(CTSResult.RESULT_OK, mResultCode); 1234 } 1235 waitForResult()1236 private void waitForResult() { 1237 synchronized (mSync) { 1238 while(!mSync.mHasNotify) { 1239 try { 1240 mSync.wait(); 1241 } catch (InterruptedException e) { 1242 } 1243 } 1244 } 1245 } 1246 1247 @TestTargets({ 1248 @TestTargetNew( 1249 level = TestLevel.COMPLETE, 1250 method = "isAlwaysDrawnWithCacheEnabled", 1251 args = {} 1252 ), 1253 @TestTargetNew( 1254 level = TestLevel.COMPLETE, 1255 method = "setAlwaysDrawnWithCacheEnabled", 1256 args = {boolean.class} 1257 ) 1258 }) testIsAlwaysDrawnWithCacheEnabled()1259 public void testIsAlwaysDrawnWithCacheEnabled() { 1260 MockViewGroup vg = new MockViewGroup(mContext); 1261 1262 assertTrue(vg.isAlwaysDrawnWithCacheEnabled()); 1263 1264 vg.setAlwaysDrawnWithCacheEnabled(false); 1265 assertFalse(vg.isAlwaysDrawnWithCacheEnabled()); 1266 vg.setAlwaysDrawnWithCacheEnabled(true); 1267 assertTrue(vg.isAlwaysDrawnWithCacheEnabled()); 1268 } 1269 1270 @TestTargets({ 1271 @TestTargetNew( 1272 level = TestLevel.COMPLETE, 1273 method = "isAnimationCacheEnabled", 1274 args = {} 1275 ), 1276 @TestTargetNew( 1277 level = TestLevel.COMPLETE, 1278 method = "setAnimationCacheEnabled", 1279 args = {boolean.class} 1280 ) 1281 }) testIsAnimationCacheEnabled()1282 public void testIsAnimationCacheEnabled() { 1283 MockViewGroup vg = new MockViewGroup(mContext); 1284 1285 assertTrue(vg.isAnimationCacheEnabled()); 1286 1287 vg.setAnimationCacheEnabled(false); 1288 assertFalse(vg.isAnimationCacheEnabled()); 1289 vg.setAnimationCacheEnabled(true); 1290 assertTrue(vg.isAnimationCacheEnabled()); 1291 } 1292 1293 @TestTargetNew( 1294 level = TestLevel.COMPLETE, 1295 method = "isChildrenDrawnWithCacheEnabled", 1296 args = {} 1297 ) testIsChildrenDrawnWithCacheEnabled()1298 public void testIsChildrenDrawnWithCacheEnabled() { 1299 MockViewGroup vg = new MockViewGroup(mContext); 1300 1301 assertFalse(vg.isChildrenDrawnWithCacheEnabled()); 1302 1303 vg.setChildrenDrawnWithCacheEnabled(true); 1304 assertTrue(vg.isChildrenDrawnWithCacheEnabled()); 1305 } 1306 1307 @TestTargetNew( 1308 level = TestLevel.COMPLETE, 1309 method = "measureChild", 1310 args = {android.view.View.class, int.class, int.class} 1311 ) testMeasureChild()1312 public void testMeasureChild() { 1313 final int width = 100; 1314 final int height = 200; 1315 MockViewGroup vg = new MockViewGroup(mContext); 1316 MockView son = new MockView(mContext); 1317 son.setLayoutParams(new LayoutParams(width, height)); 1318 son.forceLayout(); 1319 vg.addView(son); 1320 1321 final int parentWidthMeasureSpec = 1; 1322 final int parentHeightMeasureSpec = 2; 1323 vg.measureChild(son, parentWidthMeasureSpec, parentHeightMeasureSpec); 1324 assertEquals(ViewGroup.getChildMeasureSpec(parentWidthMeasureSpec, 0, width), 1325 son.mWidthMeasureSpec); 1326 assertEquals(ViewGroup.getChildMeasureSpec(parentHeightMeasureSpec, 0, height), 1327 son.mHeightMeasureSpec); 1328 } 1329 1330 @TestTargetNew( 1331 level = TestLevel.COMPLETE, 1332 method = "measureChildren", 1333 args = {int.class, int.class} 1334 ) testMeasureChildren()1335 public void testMeasureChildren() { 1336 final int widthMeasureSpec = 100; 1337 final int heightMeasureSpec = 200; 1338 MockViewGroup vg = new MockViewGroup(mContext); 1339 MockTextView textView1 = new MockTextView(mContext); 1340 1341 vg.addView(textView1); 1342 vg.measureChildCalledTime = 0; 1343 vg.measureChildren(widthMeasureSpec, heightMeasureSpec); 1344 assertEquals(1, vg.measureChildCalledTime); 1345 1346 MockTextView textView2 = new MockTextView(mContext); 1347 textView2.setVisibility(View.GONE); 1348 vg.addView(textView2); 1349 1350 vg.measureChildCalledTime = 0; 1351 vg.measureChildren(widthMeasureSpec, heightMeasureSpec); 1352 assertEquals(1, vg.measureChildCalledTime); 1353 } 1354 1355 @TestTargetNew( 1356 level = TestLevel.COMPLETE, 1357 method = "measureChildWithMargins", 1358 args = {android.view.View.class, int.class, int.class, int.class, int.class} 1359 ) testMeasureChildWithMargins()1360 public void testMeasureChildWithMargins() { 1361 final int width = 10; 1362 final int height = 20; 1363 final int parentWidthMeasureSpec = 1; 1364 final int widthUsed = 2; 1365 final int parentHeightMeasureSpec = 3; 1366 final int heightUsed = 4; 1367 MockViewGroup vg = new MockViewGroup(mContext); 1368 MockView son = new MockView(mContext); 1369 1370 vg.addView(son); 1371 son.setLayoutParams(new ViewGroup.LayoutParams(width, height)); 1372 try { 1373 vg.measureChildWithMargins(son, parentWidthMeasureSpec, widthUsed, 1374 parentHeightMeasureSpec, heightUsed); 1375 fail("measureChildWithMargins should throw out class cast exception"); 1376 } catch (RuntimeException e) { 1377 } 1378 son.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height)); 1379 1380 vg.measureChildWithMargins(son, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, 1381 heightUsed); 1382 assertEquals(ViewGroup.getChildMeasureSpec(parentWidthMeasureSpec, parentHeightMeasureSpec, 1383 width), son.mWidthMeasureSpec); 1384 assertEquals(ViewGroup.getChildMeasureSpec(widthUsed, heightUsed, height), 1385 son.mHeightMeasureSpec); 1386 } 1387 1388 @TestTargetNew( 1389 level = TestLevel.COMPLETE, 1390 method = "offsetDescendantRectToMyCoords", 1391 args = {android.view.View.class, android.graphics.Rect.class} 1392 ) testOffsetDescendantRectToMyCoords()1393 public void testOffsetDescendantRectToMyCoords() { 1394 MockViewGroup vg = new MockViewGroup(mContext); 1395 MockTextView textView = new MockTextView(mContext); 1396 1397 try { 1398 vg.offsetDescendantRectToMyCoords(textView, new Rect()); 1399 fail("offsetDescendantRectToMyCoords should throw out " 1400 + "IllegalArgumentException"); 1401 } catch (RuntimeException e) { 1402 // expected 1403 } 1404 vg.addView(textView); 1405 textView.setFrame(1, 2, 3, 4); 1406 Rect rect = new Rect(); 1407 vg.offsetDescendantRectToMyCoords(textView, rect); 1408 assertEquals(2, rect.bottom); 1409 assertEquals(2, rect.top); 1410 assertEquals(1, rect.left); 1411 assertEquals(1, rect.right); 1412 } 1413 1414 @TestTargetNew( 1415 level = TestLevel.COMPLETE, 1416 method = "offsetRectIntoDescendantCoords", 1417 args = {android.view.View.class, android.graphics.Rect.class} 1418 ) testOffsetRectIntoDescendantCoords()1419 public void testOffsetRectIntoDescendantCoords() { 1420 MockViewGroup vg = new MockViewGroup(mContext); 1421 vg.setFrame(10, 20, 30, 40); 1422 MockTextView textView = new MockTextView(mContext); 1423 1424 try { 1425 vg.offsetRectIntoDescendantCoords(textView, new Rect()); 1426 fail("offsetRectIntoDescendantCoords should throw out " 1427 + "IllegalArgumentException"); 1428 } catch (RuntimeException e) { 1429 // expected 1430 } 1431 textView.setFrame(1, 2, 3, 4); 1432 vg.addView(textView); 1433 1434 Rect rect = new Rect(5, 6, 7, 8); 1435 vg.offsetRectIntoDescendantCoords(textView, rect); 1436 assertEquals(6, rect.bottom); 1437 assertEquals(4, rect.top); 1438 assertEquals(4, rect.left); 1439 assertEquals(6, rect.right); 1440 } 1441 1442 @TestTargetNew( 1443 level = TestLevel.COMPLETE, 1444 method = "onAnimationEnd", 1445 args = {} 1446 ) testOnAnimationEnd()1447 public void testOnAnimationEnd() { 1448 // this function is a call back function it should be tested in ViewGroup#drawChild. 1449 MockViewGroup father = new MockViewGroup(mContext); 1450 MockViewGroup son = new MockViewGroup(mContext); 1451 son.setAnimation(new MockAnimation()); 1452 // this call will make mPrivateFlags |= ANIMATION_STARTED; 1453 son.onAnimationStart(); 1454 father.addView(son); 1455 1456 MockCanvas canvas = new MockCanvas(); 1457 assertFalse(father.drawChild(canvas, son, 100)); 1458 assertTrue(son.isOnAnimationEndCalled); 1459 } 1460 1461 private class MockAnimation extends Animation { MockAnimation()1462 public MockAnimation() { 1463 super(); 1464 } 1465 MockAnimation(Context context, AttributeSet attrs)1466 public MockAnimation(Context context, AttributeSet attrs) { 1467 super(context, attrs); 1468 } 1469 1470 @Override getTransformation(long currentTime, Transformation outTransformation)1471 public boolean getTransformation(long currentTime, Transformation outTransformation) { 1472 super.getTransformation(currentTime, outTransformation); 1473 return false; 1474 } 1475 } 1476 1477 @TestTargetNew( 1478 level = TestLevel.COMPLETE, 1479 method = "onAnimationStart", 1480 args = {} 1481 ) testOnAnimationStart()1482 public void testOnAnimationStart() { 1483 // This is a call back method. It should be tested in ViewGroup#drawChild. 1484 MockViewGroup father = new MockViewGroup(mContext); 1485 MockViewGroup son = new MockViewGroup(mContext); 1486 1487 father.addView(son); 1488 1489 MockCanvas canvas = new MockCanvas(); 1490 try { 1491 assertFalse(father.drawChild(canvas, son, 100)); 1492 assertFalse(son.isOnAnimationStartCalled); 1493 } catch (Exception e) { 1494 // expected 1495 } 1496 1497 son.setAnimation(new MockAnimation()); 1498 assertFalse(father.drawChild(canvas, son, 100)); 1499 assertTrue(son.isOnAnimationStartCalled); 1500 } 1501 1502 @TestTargetNew( 1503 level = TestLevel.COMPLETE, 1504 method = "onCreateDrawableState", 1505 args = {int.class} 1506 ) testOnCreateDrawableState()1507 public void testOnCreateDrawableState() { 1508 MockViewGroup vg = new MockViewGroup(mContext); 1509 // Call back function. Called in View#getDrawableState() 1510 int[] data = vg.getDrawableState(); 1511 assertTrue(vg.isOnCreateDrawableStateCalled); 1512 assertEquals(1, data.length); 1513 } 1514 1515 @TestTargetNew( 1516 level = TestLevel.COMPLETE, 1517 method = "onInterceptTouchEvent", 1518 args = {android.view.MotionEvent.class} 1519 ) testOnInterceptTouchEvent()1520 public void testOnInterceptTouchEvent() { 1521 MockViewGroup vg = new MockViewGroup(mContext); 1522 MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), 1523 SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 100, 100, 1524 0); 1525 1526 assertFalse(vg.dispatchTouchEvent(me)); 1527 assertTrue(vg.isOnInterceptTouchEventCalled); 1528 } 1529 1530 @TestTargetNew( 1531 level = TestLevel.COMPLETE, 1532 method = "onLayout", 1533 args = {boolean.class, int.class, int.class, int.class, int.class} 1534 ) testOnLayout()1535 public void testOnLayout() { 1536 final int left = 1; 1537 final int top = 2; 1538 final int right = 100; 1539 final int bottom = 200; 1540 MockViewGroup mv = new MockViewGroup(mContext); 1541 mv.layout(left, top, right, bottom); 1542 assertEquals(left, mv.left); 1543 assertEquals(top, mv.top); 1544 assertEquals(right, mv.right); 1545 assertEquals(bottom, mv.bottom); 1546 } 1547 1548 @TestTargetNew( 1549 level = TestLevel.COMPLETE, 1550 method = "onRequestFocusInDescendants", 1551 args = {int.class, android.graphics.Rect.class} 1552 ) testOnRequestFocusInDescendants()1553 public void testOnRequestFocusInDescendants() { 1554 MockViewGroup vg = new MockViewGroup(mContext); 1555 1556 vg.requestFocus(View.FOCUS_DOWN, new Rect()); 1557 assertTrue(vg.isOnRequestFocusInDescendantsCalled); 1558 } 1559 1560 @TestTargetNew( 1561 level = TestLevel.COMPLETE, 1562 method = "recomputeViewAttributes", 1563 args = {android.view.View.class} 1564 ) testRecomputeViewAttributes()1565 public void testRecomputeViewAttributes() { 1566 MockViewGroup father = new MockViewGroup(mContext); 1567 MockViewGroup son = new MockViewGroup(mContext); 1568 father.addView(son); 1569 1570 son.recomputeViewAttributes(null); 1571 assertTrue(father.isRecomputeViewAttributesCalled); 1572 } 1573 1574 @TestTargets({ 1575 @TestTargetNew( 1576 level = TestLevel.COMPLETE, 1577 method = "removeAllViews", 1578 args = {} 1579 ), 1580 @TestTargetNew( 1581 level = TestLevel.COMPLETE, 1582 method = "getChildCount", 1583 args = {} 1584 ) 1585 }) testRemoveAllViews()1586 public void testRemoveAllViews() { 1587 MockViewGroup vg = new MockViewGroup(mContext); 1588 MockTextView textView = new MockTextView(mContext); 1589 assertEquals(0, vg.getChildCount()); 1590 1591 vg.addView(textView); 1592 assertEquals(1, vg.getChildCount()); 1593 1594 vg.removeAllViews(); 1595 assertEquals(0, vg.getChildCount()); 1596 assertNull(textView.getParent()); 1597 } 1598 1599 @TestTargetNew( 1600 level = TestLevel.COMPLETE, 1601 method = "removeAllViewsInLayout", 1602 args = {} 1603 ) testRemoveAllViewsInLayout()1604 public void testRemoveAllViewsInLayout() { 1605 MockViewGroup father = new MockViewGroup(mContext); 1606 MockViewGroup son = new MockViewGroup(mContext); 1607 MockTextView textView = new MockTextView(mContext); 1608 1609 assertEquals(0, father.getChildCount()); 1610 1611 son.addView(textView); 1612 father.addView(son); 1613 assertEquals(1, father.getChildCount()); 1614 1615 father.removeAllViewsInLayout(); 1616 assertEquals(0, father.getChildCount()); 1617 assertEquals(1, son.getChildCount()); 1618 assertNull(son.getParent()); 1619 assertSame(son, textView.getParent()); 1620 } 1621 1622 @TestTargetNew( 1623 level = TestLevel.COMPLETE, 1624 method = "removeDetachedView", 1625 args = {android.view.View.class, boolean.class} 1626 ) testRemoveDetachedView()1627 public void testRemoveDetachedView() { 1628 MockViewGroup father = new MockViewGroup(mContext); 1629 MockViewGroup son1 = new MockViewGroup(mContext); 1630 MockViewGroup son2 = new MockViewGroup(mContext); 1631 MockOnHierarchyChangeListener listener = new MockOnHierarchyChangeListener(); 1632 father.setOnHierarchyChangeListener(listener); 1633 father.addView(son1); 1634 father.addView(son2); 1635 1636 father.removeDetachedView(son1, false); 1637 assertSame(father, listener.sParent); 1638 assertSame(son1, listener.sChild); 1639 } 1640 1641 static class MockOnHierarchyChangeListener implements OnHierarchyChangeListener { 1642 1643 public View sParent; 1644 public View sChild; 1645 onChildViewAdded(View parent, View child)1646 public void onChildViewAdded(View parent, View child) { 1647 } 1648 onChildViewRemoved(View parent, View child)1649 public void onChildViewRemoved(View parent, View child) { 1650 sParent = parent; 1651 sChild = child; 1652 } 1653 } 1654 1655 @TestTargetNew( 1656 level = TestLevel.COMPLETE, 1657 method = "removeView", 1658 args = {android.view.View.class} 1659 ) testRemoveView()1660 public void testRemoveView() { 1661 MockViewGroup father = new MockViewGroup(mContext); 1662 MockViewGroup son = new MockViewGroup(mContext); 1663 1664 assertEquals(0, father.getChildCount()); 1665 1666 father.addView(son); 1667 assertEquals(1, father.getChildCount()); 1668 1669 father.removeView(son); 1670 assertEquals(0, father.getChildCount()); 1671 assertNull(son.getParent()); 1672 } 1673 1674 @TestTargetNew( 1675 level = TestLevel.COMPLETE, 1676 method = "removeViewAt", 1677 args = {int.class} 1678 ) testRemoveViewAt()1679 public void testRemoveViewAt() { 1680 MockViewGroup father = new MockViewGroup(mContext); 1681 MockViewGroup son = new MockViewGroup(mContext); 1682 1683 assertEquals(0, father.getChildCount()); 1684 1685 father.addView(son); 1686 assertEquals(1, father.getChildCount()); 1687 1688 try { 1689 father.removeViewAt(2); 1690 fail("should throw out null pointer exception"); 1691 } catch (RuntimeException e) { 1692 // expected 1693 } 1694 assertEquals(1, father.getChildCount()); 1695 1696 father.removeViewAt(0); 1697 assertEquals(0, father.getChildCount()); 1698 assertNull(son.getParent()); 1699 } 1700 1701 @TestTargetNew( 1702 level = TestLevel.COMPLETE, 1703 method = "removeViewInLayout", 1704 args = {android.view.View.class} 1705 ) testRemoveViewInLayout()1706 public void testRemoveViewInLayout() { 1707 MockViewGroup father = new MockViewGroup(mContext); 1708 MockViewGroup son = new MockViewGroup(mContext); 1709 1710 assertEquals(0, father.getChildCount()); 1711 1712 father.addView(son); 1713 assertEquals(1, father.getChildCount()); 1714 1715 father.removeViewInLayout(son); 1716 assertEquals(0, father.getChildCount()); 1717 assertNull(son.getParent()); 1718 } 1719 1720 @TestTargetNew( 1721 level = TestLevel.COMPLETE, 1722 method = "removeViews", 1723 args = {int.class, int.class} 1724 ) testRemoveViews()1725 public void testRemoveViews() { 1726 MockViewGroup father = new MockViewGroup(mContext); 1727 MockViewGroup son1 = new MockViewGroup(mContext); 1728 MockViewGroup son2 = new MockViewGroup(mContext); 1729 1730 assertEquals(0, father.getChildCount()); 1731 1732 father.addView(son1); 1733 father.addView(son2); 1734 assertEquals(2, father.getChildCount()); 1735 1736 father.removeViews(0, 1); 1737 assertEquals(1, father.getChildCount()); 1738 assertNull(son1.getParent()); 1739 1740 father.removeViews(0, 1); 1741 assertEquals(0, father.getChildCount()); 1742 assertNull(son2.getParent()); 1743 } 1744 1745 @TestTargetNew( 1746 level = TestLevel.COMPLETE, 1747 method = "removeViewsInLayout", 1748 args = {int.class, int.class} 1749 ) testRemoveViewsInLayout()1750 public void testRemoveViewsInLayout() { 1751 MockViewGroup father = new MockViewGroup(mContext); 1752 MockViewGroup son1 = new MockViewGroup(mContext); 1753 MockViewGroup son2 = new MockViewGroup(mContext); 1754 1755 assertEquals(0, father.getChildCount()); 1756 1757 father.addView(son1); 1758 father.addView(son2); 1759 assertEquals(2, father.getChildCount()); 1760 1761 father.removeViewsInLayout(0, 1); 1762 assertEquals(1, father.getChildCount()); 1763 assertNull(son1.getParent()); 1764 1765 father.removeViewsInLayout(0, 1); 1766 assertEquals(0, father.getChildCount()); 1767 assertNull(son2.getParent()); 1768 } 1769 1770 @TestTargetNew( 1771 level = TestLevel.COMPLETE, 1772 method = "requestChildFocus", 1773 args = {android.view.View.class, android.view.View.class} 1774 ) testRequestChildFocus()1775 public void testRequestChildFocus() { 1776 MockViewGroup vg = new MockViewGroup(mContext); 1777 TextView textView = new TextView(mContext); 1778 1779 vg.addView(textView); 1780 vg.requestChildFocus(textView, null); 1781 1782 assertNotNull(vg.getFocusedChild()); 1783 1784 vg.clearChildFocus(textView); 1785 assertNull(vg.getFocusedChild()); 1786 } 1787 1788 @TestTargetNew( 1789 level = TestLevel.COMPLETE, 1790 method = "requestChildRectangleOnScreen", 1791 args = {android.view.View.class, android.graphics.Rect.class, boolean.class} 1792 ) testRequestChildRectangleOnScreen()1793 public void testRequestChildRectangleOnScreen() { 1794 MockViewGroup vg = new MockViewGroup(mContext); 1795 assertFalse(vg.requestChildRectangleOnScreen(null, null, false)); 1796 } 1797 1798 @TestTargetNew( 1799 level = TestLevel.COMPLETE, 1800 method = "requestDisallowInterceptTouchEvent", 1801 args = {boolean.class} 1802 ) testRequestDisallowInterceptTouchEvent()1803 public void testRequestDisallowInterceptTouchEvent() { 1804 MockViewGroup father = new MockViewGroup(mContext); 1805 MockView son = new MockView(mContext); 1806 1807 father.addView(son); 1808 son.requestDisallowInterceptTouchEvent(true); 1809 son.requestDisallowInterceptTouchEvent(false); 1810 assertTrue(father.isRequestDisallowInterceptTouchEventCalled); 1811 } 1812 1813 @TestTargetNew( 1814 level = TestLevel.COMPLETE, 1815 method = "requestFocus", 1816 args = {int.class, android.graphics.Rect.class} 1817 ) testRequestFocus()1818 public void testRequestFocus() { 1819 MockViewGroup vg = new MockViewGroup(mContext); 1820 1821 vg.requestFocus(View.FOCUS_DOWN, new Rect()); 1822 assertTrue(vg.isOnRequestFocusInDescendantsCalled); 1823 } 1824 1825 @TestTargetNew( 1826 level = TestLevel.COMPLETE, 1827 method = "requestTransparentRegion", 1828 args = {android.view.View.class} 1829 ) testRequestTransparentRegion()1830 public void testRequestTransparentRegion() { 1831 MockViewGroup father = new MockViewGroup(mContext); 1832 MockView son1 = new MockView(mContext); 1833 MockView son2 = new MockView(mContext); 1834 son1.addView(son2); 1835 father.addView(son1); 1836 son1.requestTransparentRegion(son2); 1837 assertTrue(father.isRequestTransparentRegionCalled); 1838 } 1839 1840 @TestTargetNew( 1841 level = TestLevel.COMPLETE, 1842 method = "scheduleLayoutAnimation", 1843 args = {} 1844 ) testScheduleLayoutAnimation()1845 public void testScheduleLayoutAnimation() { 1846 MockViewGroup vg = new MockViewGroup(mContext); 1847 Animation animation = new AlphaAnimation(mContext, null); 1848 1849 MockLayoutAnimationController al = new MockLayoutAnimationController(animation); 1850 vg.setLayoutAnimation(al); 1851 vg.scheduleLayoutAnimation(); 1852 vg.dispatchDraw(new Canvas()); 1853 assertTrue(al.mIsStartCalled); 1854 } 1855 1856 static class MockLayoutAnimationController extends LayoutAnimationController { 1857 1858 public boolean mIsStartCalled; 1859 MockLayoutAnimationController(Animation animation)1860 public MockLayoutAnimationController(Animation animation) { 1861 super(animation); 1862 } 1863 1864 @Override start()1865 public void start() { 1866 mIsStartCalled = true; 1867 super.start(); 1868 } 1869 } 1870 1871 @TestTargetNew( 1872 level = TestLevel.COMPLETE, 1873 method = "setAddStatesFromChildren", 1874 args = {boolean.class} 1875 ) testSetAddStatesFromChildren()1876 public void testSetAddStatesFromChildren() { 1877 MockViewGroup vg = new MockViewGroup(mContext); 1878 vg.setAddStatesFromChildren(true); 1879 assertTrue(vg.addStatesFromChildren()); 1880 1881 vg.setAddStatesFromChildren(false); 1882 assertFalse(vg.addStatesFromChildren()); 1883 } 1884 1885 @TestTargetNew( 1886 level = TestLevel.COMPLETE, 1887 method = "setChildrenDrawingCacheEnabled", 1888 args = {boolean.class} 1889 ) testSetChildrenDrawingCacheEnabled()1890 public void testSetChildrenDrawingCacheEnabled() { 1891 MockViewGroup vg = new MockViewGroup(mContext); 1892 1893 assertTrue(vg.isAnimationCacheEnabled()); 1894 1895 vg.setAnimationCacheEnabled(false); 1896 assertFalse(vg.isAnimationCacheEnabled()); 1897 1898 vg.setAnimationCacheEnabled(true); 1899 assertTrue(vg.isAnimationCacheEnabled()); 1900 } 1901 1902 @TestTargetNew( 1903 level = TestLevel.COMPLETE, 1904 method = "setChildrenDrawnWithCacheEnabled", 1905 args = {boolean.class} 1906 ) testSetChildrenDrawnWithCacheEnabled()1907 public void testSetChildrenDrawnWithCacheEnabled() { 1908 MockViewGroup vg = new MockViewGroup(mContext); 1909 1910 assertFalse(vg.isChildrenDrawnWithCacheEnabled()); 1911 1912 vg.setChildrenDrawnWithCacheEnabled(true); 1913 assertTrue(vg.isChildrenDrawnWithCacheEnabled()); 1914 1915 vg.setChildrenDrawnWithCacheEnabled(false); 1916 assertFalse(vg.isChildrenDrawnWithCacheEnabled()); 1917 } 1918 1919 @TestTargetNew( 1920 level = TestLevel.COMPLETE, 1921 method = "setClipChildren", 1922 args = {boolean.class} 1923 ) testSetClipChildren()1924 public void testSetClipChildren() { 1925 Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); 1926 1927 MockViewGroup vg = new MockViewGroup(mContext); 1928 MockTextView textView = new MockTextView(mContext); 1929 textView.setFrame(1, 2, 30, 40); 1930 vg.setFrame(1, 1, 100, 200); 1931 vg.setClipChildren(true); 1932 1933 MockCanvas canvas = new MockCanvas(bitmap); 1934 vg.drawChild(canvas, textView, 100); 1935 Rect rect = canvas.getClipBounds(); 1936 assertEquals(0, rect.top); 1937 assertEquals(100, rect.bottom); 1938 assertEquals(0, rect.left); 1939 assertEquals(100, rect.right); 1940 } 1941 1942 class MockCanvas extends Canvas { 1943 1944 public boolean mIsSaveCalled; 1945 public int mLeft; 1946 public int mTop; 1947 public int mRight; 1948 public int mBottom; 1949 MockCanvas()1950 public MockCanvas() { 1951 } 1952 MockCanvas(Bitmap bitmap)1953 public MockCanvas(Bitmap bitmap) { 1954 super(bitmap); 1955 } 1956 1957 @Override quickReject(float left, float top, float right, float bottom, EdgeType type)1958 public boolean quickReject(float left, float top, float right, 1959 float bottom, EdgeType type) { 1960 super.quickReject(left, top, right, bottom, type); 1961 return false; 1962 } 1963 1964 @Override save()1965 public int save() { 1966 mIsSaveCalled = true; 1967 return super.save(); 1968 } 1969 1970 @Override clipRect(int left, int top, int right, int bottom)1971 public boolean clipRect(int left, int top, int right, int bottom) { 1972 mLeft = left; 1973 mTop = top; 1974 mRight = right; 1975 mBottom = bottom; 1976 return super.clipRect(left, top, right, bottom); 1977 } 1978 } 1979 1980 @TestTargetNew( 1981 level = TestLevel.COMPLETE, 1982 method = "setClipToPadding", 1983 args = {boolean.class} 1984 ) testSetClipToPadding()1985 public void testSetClipToPadding() { 1986 final int frameLeft = 1; 1987 final int frameTop = 2; 1988 final int frameRight = 100; 1989 final int frameBottom = 200; 1990 MockViewGroup vg = new MockViewGroup(mContext); 1991 vg.setFrame(frameLeft, frameTop, frameRight, frameBottom); 1992 1993 vg.setClipToPadding(true); 1994 MockCanvas canvas = new MockCanvas(); 1995 final int paddingLeft = 10; 1996 final int paddingTop = 20; 1997 final int paddingRight = 100; 1998 final int paddingBottom = 200; 1999 vg.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); 2000 vg.dispatchDraw(canvas); 2001 //check that the clip region does not contain the padding area 2002 assertTrue(canvas.mIsSaveCalled); 2003 assertEquals(10, canvas.mLeft); 2004 assertEquals(20, canvas.mTop); 2005 assertEquals(-frameLeft, canvas.mRight); 2006 assertEquals(-frameTop, canvas.mBottom); 2007 2008 vg.setClipToPadding(false); 2009 canvas = new MockCanvas(); 2010 vg.dispatchDraw(canvas); 2011 assertFalse(canvas.mIsSaveCalled); 2012 assertEquals(0, canvas.mLeft); 2013 assertEquals(0, canvas.mTop); 2014 assertEquals(0, canvas.mRight); 2015 assertEquals(0, canvas.mBottom); 2016 } 2017 2018 @TestTargetNew( 2019 level = TestLevel.COMPLETE, 2020 method = "setDescendantFocusability", 2021 args = {int.class} 2022 ) testSetDescendantFocusability()2023 public void testSetDescendantFocusability() { 2024 MockViewGroup vg = new MockViewGroup(mContext); 2025 final int FLAG_MASK_FOCUSABILITY = 0x60000; 2026 assertFalse((vg.getDescendantFocusability() & FLAG_MASK_FOCUSABILITY) == 0); 2027 2028 vg.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 2029 assertFalse((vg.getDescendantFocusability() & FLAG_MASK_FOCUSABILITY) == 0); 2030 2031 vg.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 2032 assertFalse((vg.getDescendantFocusability() & FLAG_MASK_FOCUSABILITY) == 0); 2033 assertFalse((vg.getDescendantFocusability() & 2034 ViewGroup.FOCUS_BEFORE_DESCENDANTS) == 0); 2035 } 2036 2037 @TestTargetNew( 2038 level = TestLevel.COMPLETE, 2039 method = "setOnHierarchyChangeListener", 2040 args = {android.view.ViewGroup.OnHierarchyChangeListener.class} 2041 ) testSetOnHierarchyChangeListener()2042 public void testSetOnHierarchyChangeListener() { 2043 MockViewGroup father = new MockViewGroup(mContext); 2044 MockViewGroup son = new MockViewGroup(mContext); 2045 MockOnHierarchyChangeListener listener = new MockOnHierarchyChangeListener(); 2046 father.setOnHierarchyChangeListener(listener); 2047 father.addView(son); 2048 2049 father.removeDetachedView(son, false); 2050 assertSame(father, listener.sParent); 2051 assertSame(son, listener.sChild); 2052 } 2053 2054 @TestTargetNew( 2055 level = TestLevel.COMPLETE, 2056 method = "setPadding", 2057 args = {int.class, int.class, int.class, int.class} 2058 ) testSetPadding()2059 public void testSetPadding() { 2060 final int left = 1; 2061 final int top = 2; 2062 final int right = 3; 2063 final int bottom = 4; 2064 MockViewGroup vg = new MockViewGroup(mContext); 2065 assertEquals(0, vg.getPaddingBottom()); 2066 assertEquals(0, vg.getPaddingTop()); 2067 assertEquals(0, vg.getPaddingLeft()); 2068 assertEquals(0, vg.getPaddingRight()); 2069 2070 vg.setPadding(left, top, right, bottom); 2071 assertEquals(bottom, vg.getPaddingBottom()); 2072 assertEquals(top, vg.getPaddingTop()); 2073 assertEquals(left, vg.getPaddingLeft()); 2074 assertEquals(right, vg.getPaddingRight()); 2075 } 2076 2077 @TestTargetNew( 2078 level = TestLevel.COMPLETE, 2079 method = "setPersistentDrawingCache", 2080 args = {int.class} 2081 ) testSetPersistentDrawingCache()2082 public void testSetPersistentDrawingCache() { 2083 MockViewGroup vg = new MockViewGroup(mContext); 2084 vg.setPersistentDrawingCache(1); 2085 assertEquals(1 & ViewGroup.PERSISTENT_ALL_CACHES, vg 2086 .getPersistentDrawingCache()); 2087 } 2088 2089 @TestTargetNew( 2090 level = TestLevel.COMPLETE, 2091 method = "showContextMenuForChild", 2092 args = {android.view.View.class} 2093 ) testShowContextMenuForChild()2094 public void testShowContextMenuForChild() { 2095 MockViewGroup father = new MockViewGroup(mContext); 2096 MockViewGroup son = new MockViewGroup(mContext); 2097 father.addView(son); 2098 2099 son.showContextMenuForChild(null); 2100 assertTrue(father.isShowContextMenuForChildCalled); 2101 } 2102 2103 @TestTargets({ 2104 @TestTargetNew( 2105 level = TestLevel.COMPLETE, 2106 method = "startLayoutAnimation", 2107 args = {} 2108 ), 2109 @TestTargetNew( 2110 level = TestLevel.COMPLETE, 2111 method = "setLayoutAnimation", 2112 args = {android.view.animation.LayoutAnimationController.class} 2113 ) 2114 }) testStartLayoutAnimation()2115 public void testStartLayoutAnimation() { 2116 MockViewGroup vg = new MockViewGroup(mContext); 2117 RotateAnimation animation = new RotateAnimation(0.1f, 0.1f); 2118 LayoutAnimationController la = new LayoutAnimationController(animation); 2119 vg.setLayoutAnimation(la); 2120 2121 vg.layout(1, 1, 100, 100); 2122 assertFalse(vg.isLayoutRequested()); 2123 vg.startLayoutAnimation(); 2124 assertTrue(vg.isLayoutRequested()); 2125 } 2126 2127 @TestTargetNew( 2128 level = TestLevel.COMPLETE, 2129 method = "updateViewLayout", 2130 args = {android.view.View.class, android.view.ViewGroup.LayoutParams.class} 2131 ) testUpdateViewLayout()2132 public void testUpdateViewLayout() { 2133 MockViewGroup father = new MockViewGroup(mContext); 2134 MockViewGroup son = new MockViewGroup(mContext); 2135 2136 father.addView(son); 2137 LayoutParams param = new LayoutParams(100, 200); 2138 father.updateViewLayout(son, param); 2139 assertEquals(param.width, son.getLayoutParams().width); 2140 assertEquals(param.height, son.getLayoutParams().height); 2141 } 2142 2143 @TestTargetNew( 2144 level = TestLevel.COMPLETE, 2145 method = "debug", 2146 args = {int.class} 2147 ) testDebug()2148 public void testDebug() { 2149 final int EXPECTED = 100; 2150 MockViewGroup father = new MockViewGroup(mContext); 2151 MockViewGroup son = new MockViewGroup(mContext); 2152 father.addView(son); 2153 2154 father.debug(EXPECTED); 2155 assertEquals(EXPECTED + 1, son.debugDepth); 2156 } 2157 2158 @TestTargets({ 2159 @TestTargetNew( 2160 level = TestLevel.COMPLETE, 2161 method = "dispatchKeyEventPreIme", 2162 args = {KeyEvent.class} 2163 ), 2164 @TestTargetNew( 2165 level = TestLevel.COMPLETE, 2166 method = "dispatchKeyShortcutEvent", 2167 args = {KeyEvent.class} 2168 ), 2169 @TestTargetNew( 2170 level = TestLevel.COMPLETE, 2171 method = "setStaticTransformationsEnabled", 2172 args = {boolean.class} 2173 ) 2174 }) testDispatchKeyEventPreIme()2175 public void testDispatchKeyEventPreIme() { 2176 MockViewGroup vg = new MockViewGroup(mContext); 2177 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER); 2178 assertFalse(vg.dispatchKeyEventPreIme(event)); 2179 assertFalse(vg.dispatchKeyShortcutEvent(event)); 2180 MockTextView textView = new MockTextView(mContext); 2181 2182 vg.addView(textView); 2183 vg.requestChildFocus(textView, null); 2184 vg.layout(0, 0, 100, 200); 2185 assertFalse(vg.dispatchKeyEventPreIme(event)); 2186 assertFalse(vg.dispatchKeyShortcutEvent(event)); 2187 2188 vg.requestChildFocus(textView, null); 2189 textView.layout(0, 0, 50, 50); 2190 assertTrue(vg.dispatchKeyEventPreIme(event)); 2191 assertTrue(vg.dispatchKeyShortcutEvent(event)); 2192 2193 vg.setStaticTransformationsEnabled(true); 2194 Canvas canvas = new Canvas(); 2195 vg.drawChild(canvas, textView, 100); 2196 assertTrue(vg.isGetChildStaticTransformationCalled); 2197 vg.isGetChildStaticTransformationCalled = false; 2198 vg.setStaticTransformationsEnabled(false); 2199 vg.drawChild(canvas, textView, 100); 2200 assertFalse(vg.isGetChildStaticTransformationCalled); 2201 } 2202 2203 static class MockTextView extends TextView { 2204 2205 public boolean isClearFocusCalled; 2206 public boolean isDispatchRestoreInstanceStateCalled; 2207 public int visibility; 2208 public boolean mIsRefreshDrawableStateCalled; 2209 public boolean isDrawCalled; 2210 MockTextView(Context context)2211 public MockTextView(Context context) { 2212 super(context); 2213 } 2214 2215 @Override draw(Canvas canvas)2216 public void draw(Canvas canvas) { 2217 super.draw(canvas); 2218 isDrawCalled = true; 2219 } 2220 2221 @Override clearFocus()2222 public void clearFocus() { 2223 isClearFocusCalled = true; 2224 super.clearFocus(); 2225 } 2226 2227 @Override dispatchKeyEvent(KeyEvent event)2228 public boolean dispatchKeyEvent(KeyEvent event) { 2229 return true; 2230 } 2231 2232 @Override setFrame(int l, int t, int r, int b)2233 public boolean setFrame(int l, int t, int r, int b) { 2234 return super.setFrame(l, t, r, b); 2235 } 2236 2237 @Override dispatchRestoreInstanceState( SparseArray<Parcelable> container)2238 public void dispatchRestoreInstanceState( 2239 SparseArray<Parcelable> container) { 2240 isDispatchRestoreInstanceStateCalled = true; 2241 super.dispatchRestoreInstanceState(container); 2242 } 2243 2244 @Override onTrackballEvent(MotionEvent event)2245 public boolean onTrackballEvent(MotionEvent event) { 2246 return true; 2247 } 2248 2249 @Override dispatchUnhandledMove(View focused, int direction)2250 public boolean dispatchUnhandledMove(View focused, int direction) { 2251 return true; 2252 } 2253 2254 @Override onWindowVisibilityChanged(int visibility)2255 public void onWindowVisibilityChanged(int visibility) { 2256 this.visibility = visibility; 2257 super.onWindowVisibilityChanged(visibility); 2258 } 2259 2260 @Override refreshDrawableState()2261 public void refreshDrawableState() { 2262 mIsRefreshDrawableStateCalled = true; 2263 super.refreshDrawableState(); 2264 } 2265 2266 @Override gatherTransparentRegion(Region region)2267 public boolean gatherTransparentRegion(Region region) { 2268 return false; 2269 } 2270 2271 @Override dispatchTouchEvent(MotionEvent event)2272 public boolean dispatchTouchEvent(MotionEvent event) { 2273 super.dispatchTouchEvent(event); 2274 return true; 2275 } 2276 2277 @Override dispatchKeyEventPreIme(KeyEvent event)2278 public boolean dispatchKeyEventPreIme(KeyEvent event) { 2279 return true; 2280 } 2281 2282 @Override dispatchKeyShortcutEvent(KeyEvent event)2283 public boolean dispatchKeyShortcutEvent(KeyEvent event) { 2284 return true; 2285 } 2286 } 2287 2288 static class MockViewGroup extends ViewGroup { 2289 2290 public boolean isRecomputeViewAttributesCalled; 2291 public boolean isShowContextMenuForChildCalled; 2292 public boolean isRefreshDrawableStateCalled; 2293 public boolean isOnRestoreInstanceStateCalled; 2294 public boolean isOnCreateDrawableStateCalled; 2295 public boolean isOnInterceptTouchEventCalled; 2296 public boolean isOnRequestFocusInDescendantsCalled; 2297 public boolean isFocusableViewAvailable; 2298 public boolean isDispatchDrawCalled; 2299 public boolean isRequestDisallowInterceptTouchEventCalled; 2300 public boolean isRequestTransparentRegionCalled; 2301 public boolean isGetChildStaticTransformationCalled; 2302 public int[] location; 2303 public int measureChildCalledTime; 2304 public boolean isOnAnimationEndCalled; 2305 public boolean isOnAnimationStartCalled; 2306 public int debugDepth; 2307 public int drawChildCalledTime; 2308 public Canvas canvas; 2309 public boolean isInvalidateChildInParentCalled; 2310 public boolean isDrawableStateChangedCalled; 2311 public boolean isRequestLayoutCalled; 2312 public boolean isOnLayoutCalled; 2313 public int left; 2314 public int top; 2315 public int right; 2316 public int bottom; 2317 MockViewGroup(Context context, AttributeSet attrs, int defStyle)2318 public MockViewGroup(Context context, AttributeSet attrs, int defStyle) { 2319 super(context, attrs, defStyle); 2320 } 2321 MockViewGroup(Context context, AttributeSet attrs)2322 public MockViewGroup(Context context, AttributeSet attrs) { 2323 super(context, attrs); 2324 } 2325 MockViewGroup(Context context)2326 public MockViewGroup(Context context) { 2327 super(context); 2328 } 2329 2330 @Override onLayout(boolean changed, int l, int t, int r, int b)2331 public void onLayout(boolean changed, int l, int t, int r, int b) { 2332 isOnLayoutCalled = true; 2333 left = l; 2334 top = t; 2335 right = r; 2336 bottom = b; 2337 } 2338 2339 @Override addViewInLayout(View child, int index, ViewGroup.LayoutParams params)2340 public boolean addViewInLayout(View child, int index, 2341 ViewGroup.LayoutParams params) { 2342 return super.addViewInLayout(child, index, params); 2343 } 2344 2345 @Override addViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout)2346 public boolean addViewInLayout(View child, int index, 2347 ViewGroup.LayoutParams params, boolean preventRequestLayout) { 2348 return super.addViewInLayout(child, index, params, preventRequestLayout); 2349 } 2350 2351 @Override attachLayoutAnimationParameters(View child, ViewGroup.LayoutParams params, int index, int count)2352 public void attachLayoutAnimationParameters(View child, 2353 ViewGroup.LayoutParams params, int index, int count) { 2354 super.attachLayoutAnimationParameters(child, params, index, count); 2355 } 2356 2357 @Override attachViewToParent(View child, int index, LayoutParams params)2358 public void attachViewToParent(View child, int index, 2359 LayoutParams params) { 2360 super.attachViewToParent(child, index, params); 2361 } 2362 2363 @Override canAnimate()2364 public boolean canAnimate() { 2365 return super.canAnimate(); 2366 } 2367 2368 @Override checkLayoutParams(LayoutParams p)2369 public boolean checkLayoutParams(LayoutParams p) { 2370 return super.checkLayoutParams(p); 2371 } 2372 2373 @Override refreshDrawableState()2374 public void refreshDrawableState() { 2375 isRefreshDrawableStateCalled = true; 2376 super.refreshDrawableState(); 2377 } 2378 2379 @Override cleanupLayoutState(View child)2380 public void cleanupLayoutState(View child) { 2381 super.cleanupLayoutState(child); 2382 } 2383 2384 @Override detachAllViewsFromParent()2385 public void detachAllViewsFromParent() { 2386 super.detachAllViewsFromParent(); 2387 } 2388 2389 @Override detachViewFromParent(int index)2390 public void detachViewFromParent(int index) { 2391 super.detachViewFromParent(index); 2392 } 2393 2394 @Override detachViewFromParent(View child)2395 public void detachViewFromParent(View child) { 2396 super.detachViewFromParent(child); 2397 } 2398 @Override 2399 detachViewsFromParent(int start, int count)2400 public void detachViewsFromParent(int start, int count) { 2401 super.detachViewsFromParent(start, count); 2402 } 2403 2404 @Override dispatchDraw(Canvas canvas)2405 public void dispatchDraw(Canvas canvas) { 2406 isDispatchDrawCalled = true; 2407 super.dispatchDraw(canvas); 2408 this.canvas = canvas; 2409 } 2410 2411 @Override dispatchFreezeSelfOnly(SparseArray<Parcelable> container)2412 public void dispatchFreezeSelfOnly(SparseArray<Parcelable> container) { 2413 super.dispatchFreezeSelfOnly(container); 2414 } 2415 2416 @Override dispatchRestoreInstanceState( SparseArray<Parcelable> container)2417 public void dispatchRestoreInstanceState( 2418 SparseArray<Parcelable> container) { 2419 super.dispatchRestoreInstanceState(container); 2420 } 2421 2422 @Override dispatchSaveInstanceState( SparseArray<Parcelable> container)2423 public void dispatchSaveInstanceState( 2424 SparseArray<Parcelable> container) { 2425 super.dispatchSaveInstanceState(container); 2426 } 2427 2428 @Override dispatchSetPressed(boolean pressed)2429 public void dispatchSetPressed(boolean pressed) { 2430 super.dispatchSetPressed(pressed); 2431 } 2432 2433 @Override dispatchThawSelfOnly(SparseArray<Parcelable> container)2434 public void dispatchThawSelfOnly(SparseArray<Parcelable> container) { 2435 super.dispatchThawSelfOnly(container); 2436 } 2437 2438 @Override onRestoreInstanceState(Parcelable state)2439 public void onRestoreInstanceState(Parcelable state) { 2440 isOnRestoreInstanceStateCalled = true; 2441 super.onRestoreInstanceState(state); 2442 } 2443 2444 @Override drawableStateChanged()2445 public void drawableStateChanged() { 2446 isDrawableStateChangedCalled = true; 2447 super.drawableStateChanged(); 2448 } 2449 2450 @Override drawChild(Canvas canvas, View child, long drawingTime)2451 public boolean drawChild(Canvas canvas, View child, long drawingTime) { 2452 drawChildCalledTime++; 2453 return super.drawChild(canvas, child, drawingTime); 2454 } 2455 2456 @Override fitSystemWindows(Rect insets)2457 public boolean fitSystemWindows(Rect insets) { 2458 return super.fitSystemWindows(insets); 2459 } 2460 2461 @Override generateDefaultLayoutParams()2462 public LayoutParams generateDefaultLayoutParams() { 2463 return super.generateDefaultLayoutParams(); 2464 } 2465 2466 @Override generateLayoutParams(LayoutParams p)2467 public LayoutParams generateLayoutParams(LayoutParams p) { 2468 return super.generateLayoutParams(p); 2469 } 2470 2471 @Override getChildDrawingOrder(int childCount, int i)2472 public int getChildDrawingOrder(int childCount, int i) { 2473 return super.getChildDrawingOrder(childCount, i); 2474 } 2475 2476 @Override getChildStaticTransformation(View child, Transformation t)2477 public boolean getChildStaticTransformation(View child, 2478 Transformation t) { 2479 isGetChildStaticTransformationCalled = true; 2480 return super.getChildStaticTransformation(child, t); 2481 } 2482 2483 @Override setFrame(int left, int top, int right, int bottom)2484 public boolean setFrame(int left, int top, int right, int bottom) { 2485 return super.setFrame(left, top, right, bottom); 2486 } 2487 2488 @Override isChildrenDrawnWithCacheEnabled()2489 public boolean isChildrenDrawnWithCacheEnabled() { 2490 return super.isChildrenDrawnWithCacheEnabled(); 2491 } 2492 2493 @Override setChildrenDrawnWithCacheEnabled(boolean enabled)2494 public void setChildrenDrawnWithCacheEnabled(boolean enabled) { 2495 super.setChildrenDrawnWithCacheEnabled(enabled); 2496 } 2497 2498 @Override measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec)2499 public void measureChild(View child, int parentWidthMeasureSpec, 2500 int parentHeightMeasureSpec) { 2501 measureChildCalledTime++; 2502 super.measureChild(child, parentWidthMeasureSpec, parentHeightMeasureSpec); 2503 } 2504 2505 @Override measureChildren(int widthMeasureSpec, int heightMeasureSpec)2506 public void measureChildren(int widthMeasureSpec, 2507 int heightMeasureSpec) { 2508 super.measureChildren(widthMeasureSpec, heightMeasureSpec); 2509 } 2510 2511 @Override measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)2512 public void measureChildWithMargins(View child, 2513 int parentWidthMeasureSpec, int widthUsed, 2514 int parentHeightMeasureSpec, int heightUsed) { 2515 super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, 2516 parentHeightMeasureSpec, heightUsed); 2517 } 2518 2519 @Override onAnimationEnd()2520 public void onAnimationEnd() { 2521 isOnAnimationEndCalled = true; 2522 super.onAnimationEnd(); 2523 } 2524 2525 @Override onAnimationStart()2526 public void onAnimationStart() { 2527 super.onAnimationStart(); 2528 isOnAnimationStartCalled = true; 2529 } 2530 2531 @Override onCreateDrawableState(int extraSpace)2532 public int[] onCreateDrawableState(int extraSpace) { 2533 isOnCreateDrawableStateCalled = true; 2534 return super.onCreateDrawableState(extraSpace); 2535 } 2536 2537 @Override onInterceptTouchEvent(MotionEvent ev)2538 public boolean onInterceptTouchEvent(MotionEvent ev) { 2539 isOnInterceptTouchEventCalled = true; 2540 return super.onInterceptTouchEvent(ev); 2541 } 2542 2543 @Override onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)2544 public boolean onRequestFocusInDescendants(int direction, 2545 Rect previouslyFocusedRect) { 2546 isOnRequestFocusInDescendantsCalled = true; 2547 return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); 2548 } 2549 2550 @Override recomputeViewAttributes(View child)2551 public void recomputeViewAttributes(View child) { 2552 isRecomputeViewAttributesCalled = true; 2553 super.recomputeViewAttributes(child); 2554 } 2555 2556 @Override removeDetachedView(View child, boolean animate)2557 public void removeDetachedView(View child, boolean animate) { 2558 super.removeDetachedView(child, animate); 2559 } 2560 2561 @Override showContextMenuForChild(View originalView)2562 public boolean showContextMenuForChild(View originalView) { 2563 isShowContextMenuForChildCalled = true; 2564 return super.showContextMenuForChild(originalView); 2565 } 2566 2567 @Override isInTouchMode()2568 public boolean isInTouchMode() { 2569 super.isInTouchMode(); 2570 return false; 2571 } 2572 2573 @Override focusableViewAvailable(View v)2574 public void focusableViewAvailable(View v) { 2575 isFocusableViewAvailable = true; 2576 super.focusableViewAvailable(v); 2577 } 2578 2579 @Override focusSearch(View focused, int direction)2580 public View focusSearch(View focused, int direction) { 2581 super.focusSearch(focused, direction); 2582 return focused; 2583 } 2584 2585 @Override requestDisallowInterceptTouchEvent(boolean disallowIntercept)2586 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 2587 isRequestDisallowInterceptTouchEventCalled = true; 2588 super.requestDisallowInterceptTouchEvent(disallowIntercept); 2589 } 2590 2591 @Override requestTransparentRegion(View child)2592 public void requestTransparentRegion(View child) { 2593 isRequestTransparentRegionCalled = true; 2594 super.requestTransparentRegion(child); 2595 } 2596 2597 @Override debug(int depth)2598 public void debug(int depth) { 2599 debugDepth = depth; 2600 super.debug(depth); 2601 } 2602 2603 @Override requestLayout()2604 public void requestLayout() { 2605 isRequestLayoutCalled = true; 2606 super.requestLayout(); 2607 } 2608 2609 @Override setStaticTransformationsEnabled(boolean enabled)2610 public void setStaticTransformationsEnabled(boolean enabled) { 2611 super.setStaticTransformationsEnabled(enabled); 2612 } 2613 } 2614 setResult(int resultCode)2615 public void setResult(int resultCode) { 2616 synchronized (mSync) { 2617 mSync.mHasNotify = true; 2618 mSync.notify(); 2619 mResultCode = resultCode; 2620 } 2621 } 2622 } 2623