コード例 #1
0
  /** Shows the SuperCardToast. */
  public void show() {

    ManagerSuperCardToast.getInstance().add(this);

    if (!isIndeterminate) {

      mHandler = new Handler();
      mHandler.postDelayed(mHideRunnable, mDuration);
    }

    mViewGroup.addView(mToastView);

    if (!showImmediate) {

      final Animation animation = this.getShowAnimation();

      /** Invalidate the ViewGroup after the show animation completes * */
      animation.setAnimationListener(
          new Animation.AnimationListener() {

            @Override
            public void onAnimationEnd(Animation arg0) {

              /** Must use Handler to modify ViewGroup in onAnimationEnd() * */
              Handler mHandler = new Handler();
              mHandler.post(mInvalidateRunnable);
            }

            @Override
            public void onAnimationRepeat(Animation arg0) {

              // Do nothing

            }

            @Override
            public void onAnimationStart(Animation arg0) {

              // Do nothing

            }
          });

      mToastView.startAnimation(animation);
    }
  }
コード例 #2
0
  @SuppressLint("NewApi")
  @SuppressWarnings("deprecation")
  private void dismissWithAnimation() {

    Animation animation = this.getDismissAnimation();

    animation.setAnimationListener(
        new Animation.AnimationListener() {

          @Override
          public void onAnimationEnd(Animation animation) {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

              /** Must use Handler to modify ViewGroup in onAnimationEnd() * */
              Handler handler = new Handler();
              handler.post(mHideWithAnimationRunnable);

            } else {

              /** Must use Handler to modify ViewGroup in onAnimationEnd() * */
              Handler handler = new Handler();
              handler.post(mHideImmediateRunnable);
            }
          }

          @Override
          public void onAnimationRepeat(Animation animation) {

            // Not used

          }

          @Override
          public void onAnimationStart(Animation animation) {

            // Not used

          }
        });

    if (mToastView != null) {

      mToastView.startAnimation(animation);
    }
  }
コード例 #3
0
  private Animation getShowAnimation() {

    if (this.getAnimation() == SuperToast.Animations.FLYIN) {

      TranslateAnimation translateAnimation =
          new TranslateAnimation(
              Animation.RELATIVE_TO_SELF,
              0.75f,
              Animation.RELATIVE_TO_SELF,
              0.0f,
              Animation.RELATIVE_TO_SELF,
              0.0f,
              Animation.RELATIVE_TO_SELF,
              0.0f);

      AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);

      AnimationSet animationSet = new AnimationSet(true);
      animationSet.addAnimation(translateAnimation);
      animationSet.addAnimation(alphaAnimation);
      animationSet.setInterpolator(new DecelerateInterpolator());
      animationSet.setDuration(250);

      return animationSet;

    } else if (this.getAnimation() == SuperToast.Animations.SCALE) {

      ScaleAnimation scaleAnimation =
          new ScaleAnimation(
              0.9f,
              1.0f,
              0.9f,
              1.0f,
              Animation.RELATIVE_TO_SELF,
              0.5f,
              Animation.RELATIVE_TO_SELF,
              0.5f);

      AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);

      AnimationSet animationSet = new AnimationSet(true);
      animationSet.addAnimation(scaleAnimation);
      animationSet.addAnimation(alphaAnimation);
      animationSet.setInterpolator(new DecelerateInterpolator());
      animationSet.setDuration(250);

      return animationSet;

    } else if (this.getAnimation() == SuperToast.Animations.POPUP) {

      TranslateAnimation translateAnimation =
          new TranslateAnimation(
              Animation.RELATIVE_TO_SELF,
              0.0f,
              Animation.RELATIVE_TO_SELF,
              0.0f,
              Animation.RELATIVE_TO_SELF,
              0.1f,
              Animation.RELATIVE_TO_SELF,
              0.0f);

      AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);

      AnimationSet animationSet = new AnimationSet(true);
      animationSet.addAnimation(translateAnimation);
      animationSet.addAnimation(alphaAnimation);
      animationSet.setInterpolator(new DecelerateInterpolator());
      animationSet.setDuration(250);

      return animationSet;

    } else {

      Animation animation = new AlphaAnimation(0f, 1f);
      animation.setDuration(500);
      animation.setInterpolator(new DecelerateInterpolator());

      return animation;
    }
  }
コード例 #4
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tweenlistener);

    mLinear = (LinearLayout) findViewById(R.id.linear);

    mBtn = (Button) findViewById(R.id.start);
    mBtn.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            // * 리스너로 연결하기
            mBtn.startAnimation(mAni1);
            // */
            /* 오프셋으로 연결하기
            mBtn.startAnimation(AnimationUtils.loadAnimation(
            		TweenListener.this, R.anim.offset));
            //*/
          }
        });

    mAni1 = AnimationUtils.loadAnimation(this, R.anim.rotate2);
    mAni2 = AnimationUtils.loadAnimation(this, R.anim.alpha2);
    mAni3 = AnimationUtils.loadAnimation(this, R.anim.scale2);

    mAni1.setAnimationListener(
        new AnimationListener() {
          public void onAnimationEnd(Animation animation) {
            mBtn.startAnimation(mAni2);
          }

          public void onAnimationRepeat(Animation animation) {
            ;
          }

          public void onAnimationStart(Animation animation) {
            ;
          }
        });

    mAni2.setAnimationListener(
        new AnimationListener() {
          public void onAnimationEnd(Animation animation) {
            mBtn.startAnimation(mAni3);
          }

          public void onAnimationRepeat(Animation animation) {
            ;
          }

          public void onAnimationStart(Animation animation) {
            ;
          }
        });

    mAni3.setAnimationListener(
        new AnimationListener() {
          public void onAnimationEnd(Animation animation) {
            Toast.makeText(TweenListener.this, "Animation End", 0).show();
          }

          public void onAnimationRepeat(Animation animation) {
            ;
          }

          public void onAnimationStart(Animation animation) {
            ;
          }
        });
  }