Esempio n. 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;
    }
  }
Esempio n. 2
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int layoutWidth = r - l;
    int layoutHeight = b - t;

    // Laying out the child views
    final int childCount = getChildCount();
    int left, top;
    radius = (layoutWidth <= layoutHeight) ? layoutWidth / 3 : layoutHeight / 3;

    childWidth = (int) (radius / 1.5f);
    childHeight = (int) (radius / 1.5f);

    float angleDelay = 360 / (float) getChildCount();

    for (int i = 0; i < childCount; i++) {
      final ShareArImageView child = (ShareArImageView) getChildAt(i);
      if (child.getVisibility() == GONE) {
        continue;
      }

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

      child.setAngle(angle);
      child.setPosition(i);

      left =
          Math.round(
              (float)
                  (((layoutWidth / 2f) - childWidth / 2f)
                      + radius * Math.cos(Math.toRadians(angle))));
      top =
          Math.round(
              (float)
                  (((layoutHeight / 2f) - childHeight / 2f)
                      + radius * Math.sin(Math.toRadians(angle))));

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