コード例 #1
0
  /**
   * Method that converts the resize frame to a dispostion reference
   *
   * @return Disposition The disposition reference
   */
  private Disposition resizerToDisposition() {
    int w = getMeasuredWidth() - (getPaddingLeft() + getPaddingRight());
    int h = getMeasuredHeight() - (getPaddingTop() + getPaddingBottom());
    int cw = w / mCols;
    int ch = h / mRows;

    // Remove overlapped areas
    Disposition resizer = new Disposition();
    resizer.x = Math.round(mResizeFrame.getX() / cw);
    resizer.y = Math.round(mResizeFrame.getY() / ch);
    resizer.w = Math.round(mResizeFrame.getWidth() / cw);
    resizer.h = Math.round(mResizeFrame.getHeight() / ch);

    // Fix disposition (limits)
    resizer.x = Math.max(resizer.x, 0);
    resizer.y = Math.max(resizer.y, 0);
    resizer.w = Math.min(resizer.w, mCols - resizer.x);
    resizer.h = Math.min(resizer.h, mRows - resizer.y);

    return resizer;
  }
コード例 #2
0
  /** Method that request the deletion of the current selected frame */
  @SuppressWarnings("boxing")
  public void deleteCurrentFrame() {
    if (mTarget == null) return;
    if (mResizeFrame == null) return;

    final Disposition targetDisposition = resizerToDisposition();

    // Get valid dispositions to move
    final List<Disposition> adjacents = findAdjacentsDispositions(targetDisposition);
    if (adjacents == null) {
      // Nothing to do
      Toast.makeText(
              getContext(), R.string.pref_disposition_unable_delete_advise, Toast.LENGTH_SHORT)
          .show();
      return;
    }

    // Hide resizer
    mResizeFrame.setVisibility(View.GONE);

    // Animate adjacents views
    List<Animator> animators = new ArrayList<Animator>();
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleX", 1.0f, 0.0f));
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleY", 1.0f, 0.0f));

    Disposition first = null;
    for (Disposition adjacent : adjacents) {
      // Extract the view and remove from dispositions
      View v = findViewFromRect(getLocationFromDisposition(adjacent));
      mDispositions.remove(adjacent);

      // Clone first disposition
      if (first == null) {
        first = new Disposition();
        first.x = adjacent.x;
        first.y = adjacent.y;
        first.w = adjacent.w;
        first.h = adjacent.h;
      }

      // Add animators and fix the adjacent
      if (v != null) {
        if (first.x < targetDisposition.x) {
          // From Left to Right
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));

          // Update the adjacent
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.x > targetDisposition.x) {
          // From Right to Left
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));
          animators.add(ObjectAnimator.ofFloat(v, "x", v.getX(), mTarget.getX()));

          // Update the adjacent
          adjacent.x = targetDisposition.x;
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.y < targetDisposition.y) {
          // From Top to Bottom
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));

          // Update the adjacent
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);

        } else if (first.y > targetDisposition.y) {
          // From Bottom to Top
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));
          animators.add(ObjectAnimator.ofFloat(v, "y", v.getY(), mTarget.getY()));

          // Update the adjacent
          adjacent.y = targetDisposition.y;
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);
        }
      }
    }
    if (animators.size() > 0) {
      AnimatorSet animSet = new AnimatorSet();
      animSet.playTogether(animators);
      animSet.setDuration(getResources().getInteger(R.integer.disposition_hide_anim));
      animSet.setInterpolator(new AccelerateInterpolator());
      animSet.addListener(
          new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              // Ignore
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
              // Ignore
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              finishDeleteAnimation(targetDisposition);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
              finishDeleteAnimation(targetDisposition);
            }
          });
      animSet.start();
    }
  }