コード例 #1
0
    @Override
    public boolean onSingleTapUp(MotionEvent e) {
      mTappedViewsPostition = pointToPosition(e.getX(), e.getY());
      if (mTappedViewsPostition >= 0) {
        mTappedView = getChildAt(mTappedViewsPostition);
        mTappedView.setPressed(true);
      } else {
        float centerX = circleWidth / 2;
        float centerY = circleHeight / 2;

        if (e.getX() < centerX + (childWidth / 2)
            && e.getX() > centerX - childWidth / 2
            && e.getY() < centerY + (childHeight / 2)
            && e.getY() > centerY - (childHeight / 2)) {
          if (mOnCenterClickListener != null) {
            mOnCenterClickListener.onCenterClick();
            return true;
          }
        }
      }

      if (mTappedView != null) {
        CircleImageView view = (CircleImageView) (mTappedView);
        if (selected != mTappedViewsPostition) {
          rotateViewToCenter(view, false);
          if (!rotateToCenter) {
            if (mOnItemSelectedListener != null) {
              mOnItemSelectedListener.onItemSelected(
                  mTappedView, mTappedViewsPostition, mTappedView.getId(), view.getName());
            }

            if (mOnItemClickListener != null) {
              mOnItemClickListener.onItemClick(
                  mTappedView, mTappedViewsPostition, mTappedView.getId(), view.getName());
            }
          }
        } else {
          rotateViewToCenter(view, false);

          if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(
                mTappedView, mTappedViewsPostition, mTappedView.getId(), view.getName());
          }
        }
        return true;
      }
      return super.onSingleTapUp(e);
    }
コード例 #2
0
  /**
   * Rotate the buttons.
   *
   * @param degrees The degrees, the menu items should get rotated.
   */
  private void rotateButtons(float degrees) {
    int left, top, childCount = getChildCount();
    float angleDelay = 360 / childCount;
    angle += degrees;

    if (angle > 360) {
      angle -= 360;
    } else {
      if (angle < 0) {
        angle += 360;
      }
    }

    for (int i = 0; i < childCount; i++) {
      if (angle > 360) {
        angle -= 360;
      } else {
        if (angle < 0) {
          angle += 360;
        }
      }

      final CircleImageView child = (CircleImageView) getChildAt(i);
      if (child.getVisibility() == GONE) {
        continue;
      }
      left =
          Math.round(
              (float)
                  (((circleWidth / 2) - childWidth / 2)
                      + radius * Math.cos(Math.toRadians(angle))));
      top =
          Math.round(
              (float)
                  (((circleHeight / 2) - childHeight / 2)
                      + radius * Math.sin(Math.toRadians(angle))));

      child.setAngle(angle);

      if (Math.abs(angle - firstChildPos) < (angleDelay / 2) && selected != child.getPosition()) {
        selected = child.getPosition();

        if (mOnItemSelectedListener != null && rotateToCenter) {
          mOnItemSelectedListener.onItemSelected(child, selected, child.getId(), child.getName());
        }
      }

      child.layout(left, top, left + childWidth, top + childHeight);
      angle += angleDelay;
    }
  }