Example #1
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 = 360f / (float) 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 ShareArImageView child = (ShareArImageView) getChildAt(i);
      if (child.getVisibility() == GONE) {
        continue;
      }
      left =
          Math.round(
              (float)
                  (((sharearWidth / 2f) - childWidth / 2f)
                      + radius * Math.cos(Math.toRadians(angle))));
      top =
          Math.round(
              (float)
                  (((sharearHeight / 2f) - childHeight / 2f)
                      + radius * Math.sin(Math.toRadians(angle))));

      child.setAngle(angle);

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

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

      child.layout(left, top, left + childWidth, top + childHeight);
      angle += angleDelay;
    }
  }
Example #2
0
    @Override
    public boolean onSingleTapUp(MotionEvent e) {
      if (getChildCount() == 0) return false;

      mTappedViewsPostition = pointToPosition(e.getX(), e.getY());
      if (mTappedViewsPostition >= 0) {
        mTappedView = getChildAt(mTappedViewsPostition);
        mTappedView.setPressed(true);
      } else {
        float centerX = sharearWidth / 2f;
        float centerY = sharearHeight / 2f;

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

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

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

          if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(
                mTappedView,
                mTappedViewsPostition,
                mTappedView.getId(),
                view.getRid(),
                view.getName());
          }
        }
        return true;
      }
      return super.onSingleTapUp(e);
    }