Exemplo n.º 1
0
 protected void updateBackground() {
   if (items.size() * (_myItemHeight + spacing) < _myOriginalBackgroundHeight) {
     _myBackgroundHeight = items.size() * (_myItemHeight + spacing);
   }
   if (buttons.size() < items.size()) {
     _myScrollbar.setHeight(_myBackgroundHeight - spacing);
     _myScrollbar.show();
   } else {
     _myScrollbar.hide();
   }
   updateButtonWidth();
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    final float x = event.getX();
    final float y = event.getY();

    if (mAnimating) {
      return false;
    }

    View leftHandle = mLeftSlider.tab;
    leftHandle.getHitRect(mTmpRect);
    boolean leftHit = mTmpRect.contains((int) x, (int) y);

    View rightHandle = mRightSlider.tab;
    rightHandle.getHitRect(mTmpRect);
    boolean rightHit = mTmpRect.contains((int) x, (int) y);

    if (!mTracking && !(leftHit || rightHit)) {
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mTracking = true;
          mTriggered = false;
          vibrate(VIBRATE_SHORT);
          if (leftHit) {
            mCurrentSlider = mLeftSlider;
            mOtherSlider = mRightSlider;
            mThreshold = isHorizontal() ? THRESHOLD : 1.0f - THRESHOLD;
            setGrabbedState(OnTriggerListener.LEFT_HANDLE);
          } else {
            mCurrentSlider = mRightSlider;
            mOtherSlider = mLeftSlider;
            mThreshold = isHorizontal() ? 1.0f - THRESHOLD : THRESHOLD;
            setGrabbedState(OnTriggerListener.RIGHT_HANDLE);
          }
          mCurrentSlider.setState(Slider.STATE_PRESSED);
          mCurrentSlider.showTarget();
          mOtherSlider.hide();
          break;
        }
    }

    return true;
  }
Exemplo n.º 3
0
  protected ListBox(
      ControlP5 theControlP5,
      ControllerGroup<?> theGroup,
      String theName,
      int theX,
      int theY,
      int theW,
      int theH) {
    super(theControlP5, theGroup, theName, theX, theY, theW, 9);

    items = new ArrayList<ListBoxItem>();

    buttons = new ArrayList<Button>();

    _myWidth = theW;

    _myName = theName;

    // workaround fix see code.goode.com/p/controlp5 issue 7
    _myBackgroundHeight = theH < 10 ? 10 : theH;

    _myScrollbar =
        new Slider(
            cp5,
            _myParent,
            theName + "Scroller",
            0,
            1,
            1,
            _myWidth - _myScrollbarWidth,
            0,
            _myScrollbarWidth,
            _myBackgroundHeight);
    _myScrollbar.setBroadcast(false);
    _myScrollbar.setSliderMode(Slider.FLEXIBLE);
    _myScrollbar.setMoveable(false);
    _myScrollbar.setLabelVisible(false);
    _myScrollbar.setParent(this);
    _myScrollbar.addListener(this);
    _myScrollbar.setVisible(false);
    _myScrollbar.hide();
    _myScrollbar.updateDisplayMode(DEFAULT);
    add(_myScrollbar);
    setHeight(_myBackgroundHeight);
  }
Exemplo n.º 4
0
 protected void scroll() {
   itemOffset = 0;
   if (buttons.size() < items.size() && isScrollbarVisible) {
     _myScrollbar.show();
     itemOffset = (int) Math.abs(_myScrollValue * (items.size() - buttons.size()));
   } else {
     _myScrollbar.hide();
   }
   if (!bulkadding) {
     for (int i = 0; i < buttons.size(); i++) {
       ListBoxItem item = items.get(itemOffset + i);
       Button b = buttons.get(i);
       b.getCaptionLabel().toUpperCase(isToUpperCase);
       b.setColor(item.getColor());
       b.getCaptionLabel().set(item.getText());
       b._myValue = item.getValue();
     }
   }
 }
Exemplo n.º 5
0
 public ListBox hideScrollbar() {
   isScrollbarVisible = false;
   _myScrollbar.hide();
   return this;
 }