@SuppressLint("NewApi")
  private void scroll(final float height) {
    if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE) {
      float move = height - (mScrollIndicator.getHeight() / 2);

      if (move < 0) move = 0;
      else if (move > getHeight() - mScrollIndicator.getHeight())
        move = getHeight() - mScrollIndicator.getHeight();

      if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        mScrollIndicator.startAnimation(moveCompat(move));
      else mScrollIndicator.setTranslationY(move);
    }

    if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE) {
      mHandlebar.setSelected(true);
      moveHandlebar(height - (mHandlebar.getHeight() / 2));
    }

    int postition = (int) ((height / getHeight()) * mItemCount);
    if (mList instanceof ExpandableListView) {
      final int grouppos =
          ExpandableListView.getPackedPositionGroup(
              ((ExpandableListView) mList).getExpandableListPosition(postition));
      if (grouppos != -1) mGroupPosition = grouppos;
    }

    if (postition < 0) postition = 0;
    else if (postition >= mItemCount) postition = mItemCount - 1;
    mScrollIndicatorText.setText(mScrollable.getIndicatorForPosition(postition, mGroupPosition));
    mList.setSelection(mScrollable.getScrollPosition(postition, mGroupPosition));
  }
Example #2
0
 void scrollContent() {
   if (content instanceof Scrollable) {
     Scrollable scrollable = (Scrollable) content;
     scrollable.setScrollPosition(scrollbarH.getValue(), scrollbarV.getValue());
   } else {
     content.setPosition(
         contentArea.getX() - scrollbarH.getValue(), contentArea.getY() - scrollbarV.getValue());
   }
 }
Example #3
0
  @Override
  public void update(float delta) {
    // Call the update method in the superclass (Scrollable)
    super.update(delta);

    // The set() method allows you to set the top left corner's x, y
    // coordinates,
    // along with the width and height of the rectangle

    barUp.set(position.x, position.y, width, height);
    barDown.set(
        position.x,
        position.y + height + VERTICAL_GAP,
        width,
        groundY - (position.y + height + VERTICAL_GAP));

    // Our skull width is 24. The bar is only 22 pixels wide. So the skull
    // must be shifted by 1 pixel to the left (so that the skull is centered
    // with respect to its bar).

    // This shift is equivalent to: (SKULL_WIDTH - width) / 2
    skullUp.set(
        position.x - (SKULL_WIDTH - width) / 2,
        position.y + height - SKULL_HEIGHT,
        SKULL_WIDTH,
        SKULL_HEIGHT);
    skullDown.set(position.x - (SKULL_WIDTH - width) / 2, barDown.y, SKULL_WIDTH, SKULL_HEIGHT);
  }
Example #4
0
 @Override
 public void reset(float newX) {
   // Call the reset method in the superclass (Scrollable)
   super.reset(newX);
   // Change the height to a random number
   height = r.nextInt(90) + 15;
   isScored = false;
 }
Example #5
0
  /**
   * Called by the AWT when the specified container needs to be laid out.
   *
   * @param parent the container to lay out
   * @exception AWTError if the target isn't the container specified to the <code>BoxLayout</code>
   *     constructor
   */
  public void layoutContainer(Container parent) {
    JViewport vp = (JViewport) parent;
    Component view = vp.getView();
    Scrollable scrollableView = null;

    if (view == null) {
      return;
    } else if (view instanceof Scrollable) {
      scrollableView = (Scrollable) view;
    }

    /* All of the dimensions below are in view coordinates, except
     * vpSize which we're converting.
     */

    Insets insets = vp.getInsets();
    Dimension viewPrefSize = view.getPreferredSize();
    Dimension vpSize = vp.getSize();
    Dimension extentSize = vp.toViewCoordinates(vpSize);
    Dimension viewSize = new Dimension(viewPrefSize);

    if (scrollableView != null) {
      if (scrollableView.getScrollableTracksViewportWidth()) {
        viewSize.width = vpSize.width;
      }
      if (scrollableView.getScrollableTracksViewportHeight()) {
        viewSize.height = vpSize.height;
      }
    }

    Point viewPosition = vp.getViewPosition();

    /* If the new viewport size would leave empty space to the
     * right of the view, right justify the view or left justify
     * the view when the width of the view is smaller than the
     * container.
     */
    if (scrollableView == null
        || vp.getParent() == null
        || vp.getParent().getComponentOrientation().isLeftToRight()) {
      if ((viewPosition.x + extentSize.width) > viewSize.width) {
        viewPosition.x = Math.max(0, viewSize.width - extentSize.width);
      }
    } else {
      if (extentSize.width > viewSize.width) {
        viewPosition.x = viewSize.width - extentSize.width;
      } else {
        viewPosition.x = Math.max(0, Math.min(viewSize.width - extentSize.width, viewPosition.x));
      }
    }

    /* If the new viewport size would leave empty space below the
     * view, bottom justify the view or top justify the view when
     * the height of the view is smaller than the container.
     */
    if ((viewPosition.y + extentSize.height) > viewSize.height) {
      viewPosition.y = Math.max(0, viewSize.height - extentSize.height);
    }

    /* If we haven't been advised about how the viewports size
     * should change wrt to the viewport, i.e. if the view isn't
     * an instance of Scrollable, then adjust the views size as follows.
     *
     * If the origin of the view is showing and the viewport is
     * bigger than the views preferred size, then make the view
     * the same size as the viewport.
     */
    if (scrollableView == null) {
      if ((viewPosition.x == 0) && (vpSize.width > viewPrefSize.width)) {
        viewSize.width = vpSize.width;
      }
      if ((viewPosition.y == 0) && (vpSize.height > viewPrefSize.height)) {
        viewSize.height = vpSize.height;
      }
    }
    vp.setViewPosition(viewPosition);
    vp.setViewSize(viewSize);
  }