Пример #1
0
  private void doScroll(MotionEvent event) {
    int xe = (int) event.getX();
    int ye = (int) event.getY();
    int txtHeight = textView.getLineHeight() * (textView.getLineCount() - 2);
    int xt = tvPos1.x + tvPos0.x - xe;
    int yt = tvPos1.y + tvPos0.y - ye;
    // if (xt < -textView.getRight()) {
    // xt = -textView.getRight() + 20;
    // } else if (xt > scrWidth) {
    xt = 0; // scrWidth - 20;
    // }
    if (yt < -textView.getBottom()) {
      yt = -textView.getBottom() + textView.getLineHeight();
    } else if (yt > (txtHeight - scrHeight)) {
      yt = txtHeight - scrHeight;
    } else if (yt < 0) {
      yt = 0;
    }

    if (yt < 0) {
      yt = 0;
    }

    textView.scrollTo(xt, yt);
    tvPosSave.set(xt, yt);
  }
Пример #2
0
  @MediumTest
  public void testGainFocusAsScrolledOntoScreen() {
    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

    assertTrue(
        "button should have scrolled onto screen",
        mBottomButton.getBottom() >= mScrollView.getBottom());
    assertTrue(
        "button should have gained focus as it was scrolled completely " + "into view",
        mBottomButton.isFocused());

    sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    assertTrue(
        "scroll view should have focus, but "
            + getActivity().getScrollView().findFocus()
            + " does instead",
        getActivity().getScrollView().isFocused());
  }
Пример #3
0
  public void setPosition(int position, float positionOffset, int positionOffsetPixels) {
    mTouchZonesAccurate = false;
    int width = getWidth();
    int center = width / 2;

    // Move the view at position. This will be the label for the left
    // of the two fragments that may be on the screen
    if (position >= 0 && position < getChildCount()) {
      TextView view = (TextView) getChildAt(position);
      int viewWidth = view.getWidth();
      int leftMin = 0;
      if (position + 1 < getChildCount()) {
        int nextViewWidth = getChildAt(position + 1).getWidth();
        leftMin = Math.min(0, center - (nextViewWidth / 2) - mPaddingPush - viewWidth);
      }
      int leftMax = center - (viewWidth / 2);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mInactiveTextColor.red, mActiveTextColor.red),
              map(positionOffset, 1, 0, mInactiveTextColor.green, mActiveTextColor.green),
              map(positionOffset, 1, 0, mInactiveTextColor.blue, mActiveTextColor.blue)));
    }

    // Move the view at position + 1. This will be the label for the
    // right of the two fragments that may be visible on screen
    if ((position + 1) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 1);
      int viewWidth = view.getWidth();
      int prevViewWidth = getChildAt(position).getWidth();
      int leftMin = center - (viewWidth / 2);
      int leftMax = Math.max(width - viewWidth, center + (prevViewWidth / 2) + mPaddingPush);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mActiveTextColor.red, mInactiveTextColor.red),
              map(positionOffset, 1, 0, mActiveTextColor.green, mInactiveTextColor.green),
              map(positionOffset, 1, 0, mActiveTextColor.blue, mInactiveTextColor.blue)));
    }

    // Move the view at position - 1. This will be the label for the
    // fragment that is off the screen to the left, if it exists
    if (position > 0) {
      TextView view = (TextView) getChildAt(position - 1);
      int plusOneLeft = getChildAt(position).getLeft();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (plusOneLeft < newLeft + viewWidth + mPaddingPush || newLeft < 0) {
        newLeft = Math.min(0, plusOneLeft - viewWidth - mPaddingPush);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 1, 0, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Move the view at position + 2. This will be the label for the
    // fragment that is off the screen to the right, if it exists
    if ((position + 2) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 2);
      int minusOneRight = getChildAt(position + 1).getRight();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (minusOneRight > (newLeft - mPaddingPush) || newLeft + viewWidth > width) {
        newLeft = Math.max(minusOneRight + mPaddingPush, width - viewWidth);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 0, 1, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Draw the tab under the active or oncoming TextView based on the
    // positionOffset
    View view = getChildAt(positionOffset < 0.5f ? position : position + 1);
    int viewLeft = view.getLeft();
    int viewRight = view.getRight();
    float percent = (Math.abs(positionOffset - 0.5f) / 0.5f);
    int tabHeight = (int) (mTabHeight * percent);
    int alpha = (int) (255 * percent);
    mTabDrawable.setBounds(
        viewLeft - mTabPadding, getHeight() - tabHeight, viewRight + mTabPadding, getHeight());
    mTabDrawable.setAlpha(alpha);
  }