Beispiel #1
0
  /**
   * Rotates the given view to the center of the menu.
   *
   * @param view the view to be rotated to the center
   * @param fromRunnable if the method is called from the runnable which animates the rotation then
   *     it should be true, otherwise false
   */
  private void rotateViewToCenter(ShareArImageView view, boolean fromRunnable) {
    if (view == null) return;
    if (rotateToCenter) {
      float velocityTemp = 1;
      float destAngle = (float) (firstChildPos - view.getAngle());
      float startAngle = 0;
      int reverser = 1;

      if (destAngle < 0) {
        destAngle += 360;
      }

      if (destAngle > 180) {
        reverser = -1;
        destAngle = 360 - destAngle;
      }

      while (startAngle < destAngle) {
        startAngle += velocityTemp / 75f;
        velocityTemp *= 1.0666f;
      }

      ShareArLayout.this.post(new FlingRunnable(reverser * velocityTemp, !fromRunnable));
    }
  }
Beispiel #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 = 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;
    }
  }
Beispiel #3
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;
    }
  }
Beispiel #4
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);
    }