/**
   * Instantiates a new SuperCardToast. <br>
   *
   * @param context should be Activity
   */
  public SuperCardToast(Context context) {

    if (context instanceof Activity) {

      this.mContext = context;

      this.mType = Type.STANDARD;

      final Activity activity = (Activity) context;

      mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      if (activity.findViewById(R.id.card_container) != null) {

        mViewGroup = (LinearLayout) activity.findViewById(R.id.card_container);

        mToastView = mLayoutInflater.inflate(R.layout.supercardtoast, mViewGroup, false);

        mMessageTextView = (TextView) mToastView.findViewById(R.id.message_textView);

        mRootLayout = (LinearLayout) mToastView.findViewById(R.id.root_layout);

      } else {

        throw new IllegalArgumentException(TAG + ERROR_CONTAINERNULL);
      }

    } else {

      throw new IllegalArgumentException(TAG + ERROR_CONTEXTNOTACTIVITY);
    }
  }
  /**
   * Instantiates a new SuperCardToast with a type. <br>
   *
   * @param context should be Activity
   * @param type choose from SuperToast.Type <br>
   */
  public SuperCardToast(Context context, Type type) {

    if (context instanceof Activity) {

      this.mContext = context;

      final Activity activity = (Activity) context;

      mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      this.mType = type;

      if (activity.findViewById(R.id.card_container) != null) {

        mViewGroup = (LinearLayout) activity.findViewById(R.id.card_container);

        if (type == Type.BUTTON) {

          mToastView = mLayoutInflater.inflate(R.layout.supercardtoast_button, mViewGroup, false);

          mToastButton = (Button) mToastView.findViewById(R.id.button);

          mDividerView = mToastView.findViewById(R.id.divider);

          mToastButton.setOnTouchListener(mTouchDismissListener);

        } else if (type == Type.PROGRESS) {

          mToastView =
              mLayoutInflater.inflate(R.layout.supercardtoast_progresscircle, mViewGroup, false);

          mProgressBar = (ProgressBar) mToastView.findViewById(R.id.progressBar);

        } else if (type == Type.PROGRESS_HORIZONTAL) {

          mToastView =
              mLayoutInflater.inflate(
                  R.layout.supercardtoast_progresshorizontal, mViewGroup, false);

          mProgressBar = (ProgressBar) mToastView.findViewById(R.id.progressBar);

        } else {

          mToastView = mLayoutInflater.inflate(R.layout.supercardtoast, mViewGroup, false);
        }

        mMessageTextView = (TextView) mToastView.findViewById(R.id.message_textView);

        mRootLayout = (LinearLayout) mToastView.findViewById(R.id.root_layout);

      } else {

        throw new IllegalArgumentException(TAG + ERROR_CONTAINERNULL);
      }

    } else {

      throw new IllegalArgumentException(TAG + ERROR_CONTEXTNOTACTIVITY);
    }
  }
  /**
   * Sets a private OnTouchListener to the SuperCardToast that will dismiss the SuperCardToast when
   * swiped. <br>
   *
   * @param swipeDismiss
   */
  public void setSwipeToDismiss(boolean swipeDismiss) {

    this.isSwipeDismissable = swipeDismiss;

    if (swipeDismiss) {

      if (Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {

        final SwipeDismissListener swipeDismissListener =
            new SwipeDismissListener(
                mToastView,
                new SwipeDismissListener.OnDismissCallback() {

                  @Override
                  public void onDismiss(View view) {

                    dismissImmediately();
                  }
                });

        mToastView.setOnTouchListener(swipeDismissListener);

      } else {

        Log.w(TAG, WARNING_PREHONEYCOMB);
      }

    } else {

      mToastView.setOnTouchListener(null);
    }
  }
  /**
   * Sets a private OnTouchListener to the SuperCardToast View that will dismiss it when touched.
   * <br>
   *
   * @param touchDismiss If true will dismiss when touched
   */
  public void setTouchToDismiss(boolean touchDismiss) {

    this.isTouchDismissable = touchDismiss;

    if (touchDismiss) {

      mToastView.setOnTouchListener(mTouchDismissListener);

    } else {

      mToastView.setOnTouchListener(null);
    }
  }
  /** Hide the SuperCardToast and animate the Layout. Post Honeycomb only. * */
  @SuppressLint("NewApi")
  private void dismissWithLayoutAnimation() {

    if (mToastView != null) {

      mToastView.setVisibility(View.INVISIBLE);

      final ViewGroup.LayoutParams layoutParams = mToastView.getLayoutParams();
      final int originalHeight = mToastView.getHeight();

      ValueAnimator animator =
          ValueAnimator.ofInt(originalHeight, 1)
              .setDuration(
                  mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));

      animator.addListener(
          new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {

              Handler mHandler = new Handler();
              mHandler.post(mHideImmediateRunnable);
            }
          });

      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {

              if (mToastView != null) {

                layoutParams.height = (Integer) valueAnimator.getAnimatedValue();
                mToastView.setLayoutParams(layoutParams);
              }
            }
          });

      animator.start();

    } else {

      dismissImmediately();
    }
  }
  /**
   * Sets the background resource of the Button divider in a BUTTON Type SuperCardToast. <br>
   *
   * @param dividerResource Use color resources to maintain design consistncy
   */
  public void setButtonDividerResource(int dividerResource) {

    this.mButtonDividerResource = dividerResource;

    if (mDividerView != null) {

      mDividerView.setBackgroundResource(dividerResource);
    }
  }
  @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);
    }
  }
  /** 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);
    }
  }
Beispiel #9
0
 public void onDropButtonClick(View view) {
   TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 1000);
   animation.setDuration(1000);
   view.startAnimation(animation);
 }
  /**
   * Returns true if the SuperCardToast is showing. <br>
   *
   * @return boolean <br>
   */
  public boolean isShowing() {

    return mToastView != null && mToastView.isShown();
  }
Beispiel #11
0
 /**
  * Returns a textual representation of the appearance of the object.
  *
  * @param view the view to visualize
  */
 public static String visualize(View view) {
   Canvas canvas = new Canvas();
   view.draw(canvas);
   return shadowOf(canvas).getDescription();
 }