public void animateSubjectOut(final SubjectCard materia) {
    final List<View> toBeAnimated = new ArrayList<View>();
    boolean after = false;
    for (SubjectCard mtr : mSubjectCards) {
      if (after) toBeAnimated.add(mtr);
      if (mtr == materia) after = true;
    }
    toBeAnimated.add(mAddButton);
    final int numberToBeAnimated = toBeAnimated.size();

    int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(),
        materiaHeight = materia.getHeight();
    final int initScroll = mScrollView.getScrollY(),
        scrollBy =
            ((maxScroll < initScroll + materiaHeight)
                    ? Math.max(maxScroll - materiaHeight, 0)
                    : initScroll)
                - initScroll;
    ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight);
    listAnimator.setInterpolator(new DecelerateInterpolator(3.2f));
    listAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            for (int i = 0; i < numberToBeAnimated; i++)
              ViewHelper.setTranslationY(toBeAnimated.get(i), value);
            ViewHelper.setScrollY(
                mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction()));
          }
        });
    listAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mSubjectCards.remove(materia);
            mSubjectsLayout.removeView(materia);
            mSqlHelper.remove(materia.getData().getSqlID());
            updateTotal();
            mScrollView.setVerticalScrollBarEnabled(true);
            mScrollView.setOnTouchListener(null);
            for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0);
          }
        });
    listAnimator.setDuration(700);
    mScrollView.setVerticalScrollBarEnabled(false);
    mScrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        }); // disable user scrolling during the animation

    if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0);
    listAnimator.setStartDelay(500);
    listAnimator.start();
  }
예제 #2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    boolean hit = event.getY() > content.getTop() && getParent() != null;
    if (tapOutsideToDismiss && !hit) {
      hide();
      return false;
    }

    if (hit && swipeToDismiss) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        swipe = 0;
        handler.removeCallbacks(hideRunnable);
        if (animator != null) {
          animator.cancel();
          animator = null;
          swipe = ViewHelper.getTranslationX(content);
        }
        super.onTouchEvent(event);
        return true;
      } else if ((event.getAction() == MotionEvent.ACTION_UP
              || event.getAction() == MotionEvent.ACTION_CANCEL)
          && animator == null) {
        animator = ObjectAnimator.ofFloat(swipe, 0);
        animator.setDuration(200);
        animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                float s = (Float) animation.getAnimatedValue();
                ViewHelper.setTranslationX(content, s);
                ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(s) / content.getWidth()));
                postInvalidate();
              }
            });
        animator.start();
        animator.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                animator.cancel();
                animator = null;
                if (duration != INFINITE) handler.postDelayed(hideRunnable, duration);
              }
            });
        super.onTouchEvent(event);
        return true;
      }
    }

    return super.onTouchEvent(event);
  }
예제 #3
0
 private void logState(View v, String title) {
   Log.v(
       TAG,
       title
           + ": ROT ("
           + ViewHelper.getRotation(v)
           + ", "
           + ViewHelper.getRotationX(v)
           + ", "
           + ViewHelper.getRotationY(v)
           + "), TRANS ("
           + ViewHelper.getTranslationX(v)
           + ", "
           + ViewHelper.getTranslationY(v)
           + "), SCALE ("
           + ViewHelper.getScaleX(v)
           + ", "
           + ViewHelper.getScaleY(v)
           + "), ALPHA "
           + ViewHelper.getAlpha(v));
 }