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.widget.cts; 18 19 import com.android.cts.widget.R; 20 21 22 import org.xmlpull.v1.XmlPullParser; 23 24 import android.app.Activity; 25 import android.content.Context; 26 import android.cts.util.PollingCheck; 27 import android.cts.util.WidgetTestUtils; 28 import android.graphics.Rect; 29 import android.test.ActivityInstrumentationTestCase2; 30 import android.test.UiThreadTest; 31 import android.util.AttributeSet; 32 import android.util.Xml; 33 import android.view.KeyEvent; 34 import android.view.MotionEvent; 35 import android.view.View; 36 import android.view.ViewGroup; 37 import android.view.View.MeasureSpec; 38 import android.view.ViewGroup.LayoutParams; 39 import android.widget.HorizontalScrollView; 40 import android.widget.TextView; 41 42 /** 43 * Test {@link HorizontalScrollView}. 44 */ 45 public class HorizontalScrollViewTest 46 extends ActivityInstrumentationTestCase2<HorizontalScrollViewCtsActivity> { 47 private static final int ITEM_WIDTH = 250; 48 private static final int ITEM_HEIGHT = 100; 49 private static final int ITEM_COUNT = 15; 50 private static final int PAGE_WIDTH = 100; 51 private static final int PAGE_HEIGHT = 100; 52 private static final int SCROLL_RIGHT = ITEM_WIDTH * ITEM_COUNT - PAGE_WIDTH; 53 private MyHorizontalScrollView mScrollView; 54 private Activity mActivity; 55 HorizontalScrollViewTest()56 public HorizontalScrollViewTest() { 57 super("com.android.cts.widget", HorizontalScrollViewCtsActivity.class); 58 } 59 60 @Override setUp()61 protected void setUp() throws Exception { 62 super.setUp(); 63 mActivity = getActivity(); 64 mScrollView = (MyHorizontalScrollView) mActivity.findViewById(R.id.horizontal_scroll_view); 65 } 66 testConstructor()67 public void testConstructor() { 68 XmlPullParser parser = mActivity.getResources().getLayout(R.layout.horizontal_scrollview); 69 AttributeSet attrs = Xml.asAttributeSet(parser); 70 new HorizontalScrollView(mActivity); 71 72 new HorizontalScrollView(mActivity, attrs); 73 74 new HorizontalScrollView(mActivity, attrs, 0); 75 } 76 testGetMaxScrollAmount()77 public void testGetMaxScrollAmount() { 78 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 79 scrollView.layout(0, 0, 100, 200); 80 assertEquals((100 - 0) / 2, scrollView.getMaxScrollAmount()); 81 82 scrollView.layout(0, 0, 150, 100); 83 assertEquals((150 - 0) / 2, scrollView.getMaxScrollAmount()); 84 } 85 testAddView()86 public void testAddView() { 87 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 88 TextView child0 = new TextView(mActivity); 89 scrollView.addView(child0); 90 assertSame(child0, scrollView.getChildAt(0)); 91 92 assertEquals(1, scrollView.getChildCount()); 93 TextView child1 = new TextView(mActivity); 94 try { 95 scrollView.addView(child1); 96 fail("did not throw IllegalStateException when add more than one child"); 97 } catch (IllegalStateException e) { 98 // expected 99 } 100 assertEquals(1, scrollView.getChildCount()); 101 } 102 testAddViewWithIndex()103 public void testAddViewWithIndex() { 104 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 105 TextView child0 = new TextView(mActivity); 106 scrollView.addView(child0, 0); 107 assertSame(child0, scrollView.getChildAt(0)); 108 109 assertEquals(1, scrollView.getChildCount()); 110 TextView child1 = new TextView(mActivity); 111 try { 112 scrollView.addView(child1, 1); 113 fail("did not throw IllegalStateException when add more than one child"); 114 } catch (IllegalStateException e) { 115 // expected 116 } 117 assertEquals(1, scrollView.getChildCount()); 118 119 scrollView.removeAllViews(); 120 scrollView = new HorizontalScrollView(mActivity); 121 scrollView.addView(child0, -1); 122 assertSame(child0, scrollView.getChildAt(0)); 123 124 assertEquals(1, scrollView.getChildCount()); 125 child1 = new TextView(mActivity); 126 try { 127 scrollView.addView(child1, -1); 128 fail("did not throw IllegalStateException when add more than one child"); 129 } catch (IllegalStateException e) { 130 // expected 131 } 132 assertEquals(1, scrollView.getChildCount()); 133 134 scrollView.removeAllViews(); 135 scrollView = new HorizontalScrollView(mActivity); 136 try { 137 scrollView.addView(child0, 1); 138 fail("did not throw IndexOutOfBoundsException when index is larger than 0"); 139 } catch (IndexOutOfBoundsException e) { 140 // expected 141 } 142 } 143 testAddViewWithLayoutParams()144 public void testAddViewWithLayoutParams() { 145 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 146 TextView child0 = new TextView(mActivity); 147 scrollView.addView(child0, new ViewGroup.LayoutParams(200, 100)); 148 assertSame(child0, scrollView.getChildAt(0)); 149 assertEquals(200, child0.getLayoutParams().width); 150 assertEquals(100, child0.getLayoutParams().height); 151 152 assertEquals(1, scrollView.getChildCount()); 153 TextView child1 = new TextView(mActivity); 154 try { 155 scrollView.addView(child1, new ViewGroup.LayoutParams(200, 100)); 156 fail("did not throw IllegalStateException when add more than one child"); 157 } catch (IllegalStateException e) { 158 // expected 159 } 160 assertEquals(1, scrollView.getChildCount()); 161 162 scrollView.removeAllViews(); 163 scrollView = new HorizontalScrollView(mActivity); 164 child0 = new TextView(mActivity); 165 try { 166 scrollView.addView(child0, null); 167 fail("did not throw NullPointerException when LayoutParams is null."); 168 } catch (NullPointerException e) { 169 // expected 170 } 171 } 172 testAddViewWithIndexAndLayoutParams()173 public void testAddViewWithIndexAndLayoutParams() { 174 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 175 TextView child0 = new TextView(mActivity); 176 scrollView.addView(child0, 0, new ViewGroup.LayoutParams(200, 100)); 177 assertSame(child0, scrollView.getChildAt(0)); 178 assertEquals(200, child0.getLayoutParams().width); 179 assertEquals(100, child0.getLayoutParams().height); 180 181 assertEquals(1, scrollView.getChildCount()); 182 TextView child1 = new TextView(mActivity); 183 try { 184 scrollView.addView(child1, 0, new ViewGroup.LayoutParams(200, 100)); 185 fail("did not throw IllegalStateException when add more than one child"); 186 } catch (IllegalStateException e) { 187 // expected 188 } 189 assertEquals(1, scrollView.getChildCount()); 190 191 scrollView.removeAllViews(); 192 scrollView = new HorizontalScrollView(mActivity); 193 child0 = new TextView(mActivity); 194 try { 195 scrollView.addView(child0, null); 196 fail("did not throw NullPointerException when LayoutParams is null."); 197 } catch (NullPointerException e) { 198 // expected 199 } 200 201 scrollView.removeAllViews(); 202 scrollView = new HorizontalScrollView(mActivity); 203 scrollView.addView(child0, -1, new ViewGroup.LayoutParams(300, 150)); 204 assertSame(child0, scrollView.getChildAt(0)); 205 assertEquals(300, child0.getLayoutParams().width); 206 assertEquals(150, child0.getLayoutParams().height); 207 208 assertEquals(1, scrollView.getChildCount()); 209 child1 = new TextView(mActivity); 210 try { 211 scrollView.addView(child1, -1, new ViewGroup.LayoutParams(200, 100)); 212 fail("did not throw IllegalStateException when add more than one child"); 213 } catch (IllegalStateException e) { 214 // expected 215 } 216 assertEquals(1, scrollView.getChildCount()); 217 218 scrollView.removeAllViews(); 219 scrollView = new HorizontalScrollView(mActivity); 220 try { 221 scrollView.addView(child0, 1, new ViewGroup.LayoutParams(200, 100)); 222 fail("did not throw IndexOutOfBoundsException when index is larger than 0"); 223 } catch (IndexOutOfBoundsException e) { 224 // expected 225 } 226 } 227 testAccessFillViewport()228 public void testAccessFillViewport() { 229 HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); 230 assertFalse(scrollView.isFillViewport()); 231 scrollView.layout(0, 0, 100, 100); 232 assertFalse(scrollView.isLayoutRequested()); 233 234 scrollView.setFillViewport(false); 235 assertFalse(scrollView.isFillViewport()); 236 assertFalse(scrollView.isLayoutRequested()); 237 238 scrollView.setFillViewport(true); 239 assertTrue(scrollView.isFillViewport()); 240 assertTrue(scrollView.isLayoutRequested()); 241 242 scrollView.layout(0, 0, 100, 100); 243 assertFalse(mScrollView.isLayoutRequested()); 244 245 scrollView.setFillViewport(false); 246 assertFalse(scrollView.isFillViewport()); 247 assertTrue(scrollView.isLayoutRequested()); 248 } 249 testAccessSmoothScrollingEnabled()250 public void testAccessSmoothScrollingEnabled() throws Throwable { 251 assertTrue(mScrollView.isSmoothScrollingEnabled()); 252 253 // scroll immediately 254 mScrollView.setSmoothScrollingEnabled(false); 255 assertFalse(mScrollView.isSmoothScrollingEnabled()); 256 257 runTestOnUiThread(new Runnable() { 258 public void run() { 259 mScrollView.fullScroll(View.FOCUS_RIGHT); 260 } 261 }); 262 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 263 264 runTestOnUiThread(new Runnable() { 265 public void run() { 266 mScrollView.fullScroll(View.FOCUS_LEFT); 267 } 268 }); 269 assertEquals(0, mScrollView.getScrollX()); 270 271 // smooth scroll 272 mScrollView.setSmoothScrollingEnabled(true); 273 assertTrue(mScrollView.isSmoothScrollingEnabled()); 274 275 runTestOnUiThread(new Runnable() { 276 public void run() { 277 mScrollView.fullScroll(View.FOCUS_RIGHT); 278 } 279 }); 280 pollingCheckSmoothScrolling(0, SCROLL_RIGHT, 0, 0); 281 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 282 283 runTestOnUiThread(new Runnable() { 284 public void run() { 285 mScrollView.fullScroll(View.FOCUS_LEFT); 286 } 287 }); 288 pollingCheckSmoothScrolling(SCROLL_RIGHT, 0, 0, 0); 289 assertEquals(0, mScrollView.getScrollX()); 290 } 291 testMeasureChild()292 public void testMeasureChild() { 293 MyHorizontalScrollView scrollView = new MyHorizontalScrollView(mActivity); 294 295 MyView child = new MyView(mActivity); 296 child.setBackgroundDrawable(null); 297 child.setPadding(0, 0, 0, 0); 298 child.setMinimumWidth(30); 299 child.setLayoutParams(new ViewGroup.LayoutParams(100, 100)); 300 child.measure(MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), 301 MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY)); 302 303 assertEquals(100, child.getMeasuredHeight()); 304 assertEquals(100, child.getMeasuredWidth()); 305 306 scrollView.measureChild(child, MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), 307 MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY)); 308 309 assertEquals(100, child.getMeasuredHeight()); 310 assertEquals(30, child.getMeasuredWidth()); 311 } 312 testMeasureChildWithMargins()313 public void testMeasureChildWithMargins() { 314 MyHorizontalScrollView scrollView = new MyHorizontalScrollView(mActivity); 315 316 MyView child = new MyView(mActivity); 317 child.setBackgroundDrawable(null); 318 child.setPadding(0, 0, 0, 0); 319 child.setMinimumWidth(30); 320 child.setLayoutParams(new ViewGroup.MarginLayoutParams(100, 100)); 321 child.measure(MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), 322 MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY)); 323 324 assertEquals(100, child.getMeasuredHeight()); 325 assertEquals(100, child.getMeasuredWidth()); 326 327 scrollView.measureChildWithMargins(child, 328 MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), 5, 329 MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), 5); 330 331 assertEquals(100, child.getMeasuredHeight()); 332 assertEquals(30, child.getMeasuredWidth()); 333 } 334 335 @UiThreadTest testPageScroll()336 public void testPageScroll() { 337 mScrollView.setSmoothScrollingEnabled(false); 338 assertEquals(0, mScrollView.getScrollX()); 339 340 assertTrue(mScrollView.pageScroll(View.FOCUS_RIGHT)); 341 assertEquals(PAGE_WIDTH, mScrollView.getScrollX()); 342 343 mScrollView.scrollTo(SCROLL_RIGHT, PAGE_HEIGHT); 344 assertFalse(mScrollView.pageScroll(View.FOCUS_RIGHT)); 345 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 346 347 assertTrue(mScrollView.pageScroll(View.FOCUS_LEFT)); 348 assertEquals(SCROLL_RIGHT - PAGE_WIDTH, mScrollView.getScrollX()); 349 350 mScrollView.scrollTo(0, PAGE_HEIGHT); 351 assertFalse(mScrollView.pageScroll(View.FOCUS_LEFT)); 352 assertEquals(0, mScrollView.getScrollX()); 353 } 354 355 @UiThreadTest testFullScroll()356 public void testFullScroll() { 357 mScrollView.setSmoothScrollingEnabled(false); 358 assertEquals(0, mScrollView.getScrollX()); 359 360 assertTrue(mScrollView.fullScroll(View.FOCUS_RIGHT)); 361 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 362 363 assertFalse(mScrollView.fullScroll(View.FOCUS_RIGHT)); 364 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 365 366 assertTrue(mScrollView.fullScroll(View.FOCUS_LEFT)); 367 assertEquals(0, mScrollView.getScrollX()); 368 369 assertFalse(mScrollView.fullScroll(View.FOCUS_LEFT)); 370 assertEquals(0, mScrollView.getScrollX()); 371 } 372 373 @UiThreadTest testArrowScroll()374 public void testArrowScroll() { 375 mScrollView.setSmoothScrollingEnabled(false); 376 assertEquals(0, mScrollView.getScrollX()); 377 378 int x = mScrollView.getScrollX(); 379 while (SCROLL_RIGHT != x) { 380 assertTrue(mScrollView.arrowScroll(View.FOCUS_RIGHT)); 381 assertTrue(x <= mScrollView.getScrollX()); 382 x = mScrollView.getScrollX(); 383 } 384 385 assertFalse(mScrollView.arrowScroll(View.FOCUS_RIGHT)); 386 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 387 388 x = mScrollView.getScrollX(); 389 while (0 != x) { 390 assertTrue(mScrollView.arrowScroll(View.FOCUS_LEFT)); 391 assertTrue(x >= mScrollView.getScrollX()); 392 x = mScrollView.getScrollX(); 393 } 394 395 assertFalse(mScrollView.arrowScroll(View.FOCUS_LEFT)); 396 assertEquals(0, mScrollView.getScrollX()); 397 } 398 testSmoothScrollBy()399 public void testSmoothScrollBy() throws Throwable { 400 assertEquals(0, mScrollView.getScrollX()); 401 assertEquals(0, mScrollView.getScrollY()); 402 403 runTestOnUiThread(new Runnable() { 404 public void run() { 405 mScrollView.smoothScrollBy(SCROLL_RIGHT, 0); 406 } 407 }); 408 pollingCheckSmoothScrolling(0, SCROLL_RIGHT, 0, 0); 409 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 410 assertEquals(0, mScrollView.getScrollY()); 411 412 runTestOnUiThread(new Runnable() { 413 public void run() { 414 mScrollView.smoothScrollBy(-SCROLL_RIGHT, 0); 415 } 416 }); 417 pollingCheckSmoothScrolling(SCROLL_RIGHT, 0, 0, 0); 418 assertEquals(0, mScrollView.getScrollX()); 419 assertEquals(0, mScrollView.getScrollY()); 420 } 421 testSmoothScrollTo()422 public void testSmoothScrollTo() throws Throwable { 423 assertEquals(0, mScrollView.getScrollX()); 424 assertEquals(0, mScrollView.getScrollY()); 425 426 runTestOnUiThread(new Runnable() { 427 public void run() { 428 mScrollView.smoothScrollTo(SCROLL_RIGHT, 0); 429 } 430 }); 431 pollingCheckSmoothScrolling(0, SCROLL_RIGHT, 0, 0); 432 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 433 assertEquals(0, mScrollView.getScrollY()); 434 435 runTestOnUiThread(new Runnable() { 436 public void run() { 437 mScrollView.smoothScrollTo(0, 0); 438 } 439 }); 440 pollingCheckSmoothScrolling(SCROLL_RIGHT, 0, 0, 0); 441 assertEquals(0, mScrollView.getScrollX()); 442 assertEquals(0, mScrollView.getScrollY()); 443 } 444 testComputeScrollDeltaToGetChildRectOnScreen()445 public void testComputeScrollDeltaToGetChildRectOnScreen() { 446 mScrollView.setSmoothScrollingEnabled(false); 447 int edge = mScrollView.getHorizontalFadingEdgeLength(); 448 449 // Rect's width is smaller than scroll view 450 Rect rect = new Rect(0, 0, 0, 0); 451 assertEquals(0, mScrollView.computeScrollDeltaToGetChildRectOnScreen(rect)); 452 453 rect = new Rect(edge, 0, PAGE_WIDTH, 0); 454 assertEquals(0, mScrollView.computeScrollDeltaToGetChildRectOnScreen(rect)); 455 456 mScrollView.scrollTo(0, 0); 457 rect = new Rect(edge + 1, 0, PAGE_WIDTH, 0); 458 assertEquals(edge, mScrollView.computeScrollDeltaToGetChildRectOnScreen(rect)); 459 } 460 testComputeHorizontalScrollRange()461 public void testComputeHorizontalScrollRange() { 462 assertTrue(mScrollView.getChildCount() > 0); 463 assertEquals(ITEM_WIDTH * ITEM_COUNT, mScrollView.computeHorizontalScrollRange()); 464 465 MyScrollView myScrollView = new MyScrollView(mActivity); 466 assertEquals(0, myScrollView.getChildCount()); 467 assertEquals(0, myScrollView.computeVerticalScrollRange()); 468 } 469 470 @UiThreadTest testRequestChildFocus()471 public void testRequestChildFocus() { 472 mScrollView.setSmoothScrollingEnabled(false); 473 474 View firstChild = mScrollView.findViewById(R.id.first_horizontal_child); 475 View lastChild = mScrollView.findViewById(R.id.last_horizontal_child); 476 firstChild.requestFocus(); 477 478 int scrollX = mScrollView.getScrollX(); 479 mScrollView.requestChildFocus(lastChild, lastChild); 480 // check scrolling to the child which wants focus 481 assertTrue(mScrollView.getScrollX() > scrollX); 482 483 scrollX = mScrollView.getScrollX(); 484 mScrollView.requestChildFocus(firstChild, firstChild); 485 // check scrolling to the child which wants focus 486 assertTrue(mScrollView.getScrollX() < scrollX); 487 } 488 489 @UiThreadTest 490 public void testRequestChildRectangleOnScreen() { 491 mScrollView.setSmoothScrollingEnabled(false); 492 int edge = mScrollView.getHorizontalFadingEdgeLength(); 493 494 View child = mScrollView.findViewById(R.id.first_horizontal_child); 495 final Rect originalRect = new Rect(0, 0, 10, 10); 496 final Rect newRect = new Rect(ITEM_WIDTH - 10, ITEM_HEIGHT - 10, ITEM_WIDTH, ITEM_HEIGHT); 497 498 assertFalse(mScrollView.requestChildRectangleOnScreen(child, originalRect, true)); 499 assertEquals(0, mScrollView.getScrollX()); 500 assertEquals(0, mScrollView.getScrollY()); 501 502 assertTrue(mScrollView.requestChildRectangleOnScreen(child, newRect, true)); 503 assertEquals(ITEM_WIDTH - mScrollView.getWidth() + edge, mScrollView.getScrollX()); 504 assertEquals(0, mScrollView.getScrollY()); 505 } 506 507 @UiThreadTest 508 public void testRequestLayout() { 509 mScrollView.requestLayout(); 510 511 assertTrue(mScrollView.isLayoutRequested()); 512 } 513 514 public void testFling() throws Throwable { 515 mScrollView.setSmoothScrollingEnabled(true); 516 assertEquals(0, mScrollView.getScrollX()); 517 518 final int velocityX = WidgetTestUtils.convertDipToPixels(getActivity(), 2000); 519 520 // fling towards right 521 runTestOnUiThread(new Runnable() { 522 public void run() { 523 mScrollView.fling(velocityX); 524 } 525 }); 526 pollingCheckFling(0, true); 527 528 final int currentX = mScrollView.getScrollX(); 529 // fling towards left 530 runTestOnUiThread(new Runnable() { 531 public void run() { 532 mScrollView.fling(-velocityX); 533 } 534 }); 535 pollingCheckFling(currentX, false); 536 } 537 538 @UiThreadTest 539 public void testScrollTo() { 540 mScrollView.setSmoothScrollingEnabled(false); 541 542 mScrollView.scrollTo(10, 10); 543 assertEquals(0, mScrollView.getScrollY()); 544 assertEquals(10, mScrollView.getScrollX()); 545 546 mScrollView.scrollTo(PAGE_WIDTH, PAGE_HEIGHT); 547 assertEquals(0, mScrollView.getScrollY()); 548 assertEquals(PAGE_WIDTH, mScrollView.getScrollX()); 549 550 mScrollView.scrollTo(SCROLL_RIGHT, 0); 551 assertEquals(0, mScrollView.getScrollY()); 552 assertEquals(SCROLL_RIGHT, mScrollView.getScrollX()); 553 554 // reach the top and left 555 mScrollView.scrollTo(-10, -10); 556 assertEquals(0, mScrollView.getScrollY()); 557 assertEquals(0, mScrollView.getScrollX()); 558 } 559 560 public void testGetHorizontalFadingEdgeStrengths() { 561 assertTrue(mScrollView.getChildCount() > 0); 562 assertTrue(mScrollView.getLeftFadingEdgeStrength() <= 1.0f); 563 assertTrue(mScrollView.getLeftFadingEdgeStrength() >= 0.0f); 564 assertTrue(mScrollView.getRightFadingEdgeStrength() <= 1.0f); 565 assertTrue(mScrollView.getRightFadingEdgeStrength() >= 0.0f); 566 567 MyScrollView myScrollView = new MyScrollView(mActivity); 568 assertEquals(0, myScrollView.getChildCount()); 569 assertTrue(mScrollView.getLeftFadingEdgeStrength() <= 1.0f); 570 assertTrue(mScrollView.getLeftFadingEdgeStrength() >= 0.0f); 571 assertTrue(mScrollView.getRightFadingEdgeStrength() <= 1.0f); 572 assertTrue(mScrollView.getRightFadingEdgeStrength() >= 0.0f); 573 } 574 testOnLayout()575 public void testOnLayout() { 576 // onLayout() is implementation details, do NOT test 577 } 578 testOnMeasure()579 public void testOnMeasure() { 580 // onMeasure() is implementation details, do NOT test 581 } 582 testExecuteKeyEvent()583 public void testExecuteKeyEvent() { 584 // executeKeyEvent() is implementation details, do NOT test 585 } 586 testOnRequestFocusInDescendants()587 public void testOnRequestFocusInDescendants() { 588 // onRequestFocusInDescendants() is implementation details, do NOT test 589 } 590 testOnSizeChanged()591 public void testOnSizeChanged() { 592 // onSizeChanged() is implementation details, do NOT test 593 } 594 testDispatchKeyEvent()595 public void testDispatchKeyEvent() { 596 // dispatchKeyEvent() is implementation details, do NOT test 597 } 598 testOnInterceptTouchEvent()599 public void testOnInterceptTouchEvent() { 600 // onInterceptTouchEvent() is implementation details, do NOT test 601 } 602 testOnTouchEvent()603 public void testOnTouchEvent() { 604 // onTouchEvent() is implementation details, do NOT test 605 } 606 testComputeScroll()607 public void testComputeScroll() { 608 // computeScroll() is implementation details, do NOT test 609 } 610 isInRange(int current, int from, int to)611 private boolean isInRange(int current, int from, int to) { 612 if (from < to) { 613 return current >= from && current <= to; 614 } 615 return current <= from && current >= to; 616 } 617 pollingCheckSmoothScrolling(final int fromX, final int toX, final int fromY, final int toY)618 private void pollingCheckSmoothScrolling(final int fromX, final int toX, 619 final int fromY, final int toY) { 620 621 if (fromX == toX && fromY == toY) { 622 return; 623 } 624 625 if (fromY != toY) { 626 new PollingCheck() { 627 @Override 628 protected boolean check() { 629 return isInRange(mScrollView.getScrollY(), fromY, toY); 630 } 631 }.run(); 632 } 633 634 if (fromX != toX) { 635 new PollingCheck() { 636 @Override 637 protected boolean check() { 638 return isInRange(mScrollView.getScrollX(), fromX, toX); 639 } 640 }.run(); 641 } 642 643 new PollingCheck() { 644 @Override 645 protected boolean check() { 646 return toX == mScrollView.getScrollX() && toY == mScrollView.getScrollY(); 647 } 648 }.run(); 649 } 650 pollingCheckFling(final int startPosition, final boolean movingRight)651 private void pollingCheckFling(final int startPosition, final boolean movingRight) { 652 new PollingCheck() { 653 @Override 654 protected boolean check() { 655 if (movingRight) { 656 return mScrollView.getScrollX() > startPosition; 657 } 658 return mScrollView.getScrollX() < startPosition; 659 } 660 }.run(); 661 662 new PollingCheck() { 663 private int mPreviousScrollX = mScrollView.getScrollX(); 664 665 @Override 666 protected boolean check() { 667 if (mScrollView.getScrollX() == mPreviousScrollX) { 668 return true; 669 } else { 670 mPreviousScrollX = mScrollView.getScrollX(); 671 return false; 672 } 673 } 674 }.run(); 675 } 676 677 private static class MyView extends View { MyView(Context context)678 public MyView(Context context) { 679 super(context); 680 } 681 } 682 } 683