Esempio n. 1
0
  /**
   * Returns a dark theme SuperCardToast. <br>
   * IMPORTANT: Activity layout should contain a linear layout with the id card_container <br>
   *
   * @param context Should be Activity
   * @param textCharSequence Message text
   * @param durationInteger Should use SuperToast.Duration constants
   * @return SuperCardToast
   */
  public static SuperCardToast createSuperCardToast(
      Context context, CharSequence textCharSequence, int durationInteger) {

    SuperCardToast superCardToast = new SuperCardToast(context);
    superCardToast.setText(textCharSequence);
    superCardToast.setDuration(durationInteger);

    return superCardToast;
  }
Esempio n. 2
0
  /**
   * Returns a light theme SuperCardToast. <br>
   * IMPORTANT: Activity layout should contain a linear layout with the id card_container <br>
   *
   * @param context Should be Activity
   * @param textCharSequence Message text
   * @param durationInteger Should use SuperToast.Duration constants
   * @return SuperCardToast
   */
  public static SuperCardToast createLightSuperCardToast(
      Context context, CharSequence textCharSequence, int durationInteger) {

    SuperCardToast SuperCardToast = new SuperCardToast(context);
    SuperCardToast.setText(textCharSequence);
    SuperCardToast.setDuration(durationInteger);
    SuperCardToast.setBackgroundResource(SuperToast.Background.WHITE);
    SuperCardToast.setTextColor(Color.BLACK);

    return SuperCardToast;
  }
Esempio n. 3
0
  /**
   * Saves pending/shown SuperCardToasts to a bundle. <br>
   *
   * @param bundle Use onSaveInstanceState() bundle
   */
  public static void onSaveState(Bundle bundle) {

    Style[] list = new Style[ManagerSuperCardToast.getInstance().getList().size()];

    LinkedList<SuperCardToast> lister = ManagerSuperCardToast.getInstance().getList();

    for (int i = 0; i < list.length; i++) {

      list[i] = new Style(lister.get(i));
    }

    bundle.putParcelableArray(BUNDLE_TAG, list);

    SuperCardToast.cancelAllSuperCardToasts();
  }
Esempio n. 4
0
    public Style(SuperCardToast superCardToast) {

      mType = superCardToast.getType();

      if (mType == Type.BUTTON) {

        mButtonText = superCardToast.getButtonText().toString();
        mButtonTextSize = superCardToast.getButtonTextSize();
        mButtonTextColor = superCardToast.getButtonTextColor();
        mButtonResource = superCardToast.getButtonResource();
        mButtonDividerResource = superCardToast.getButtonDividerResource();
        mClickListenerTag = superCardToast.getClickListenerTag();
        mButtonTypeface = superCardToast.getButtonTypeface();
      }

      if (superCardToast.getIconResource() != 0 && superCardToast.getIconPosition() != null) {

        mIconResource = superCardToast.getIconResource();
        mIconPosition = superCardToast.getIconPosition();
      }

      mDismissListenerTag = superCardToast.getDismissListenerTag();
      mAnimations = superCardToast.getAnimation();
      mText = superCardToast.getText().toString();
      mTypeface = superCardToast.getTypeface();
      mDuration = superCardToast.getDuration();
      mTextColor = superCardToast.getTextColor();
      mTextSize = superCardToast.getTextSize();
      isIndeterminate = superCardToast.isIndeterminate();
      mBackgroundResource = superCardToast.getBackgroundResource();
      isTouchDismissable = superCardToast.isTouchDismissable();
      isSwipeDismissable = superCardToast.isSwipeDismissable();
    }
Esempio n. 5
0
  /** Method used to recreate SuperCardToasts after orientation change */
  private SuperCardToast(
      Activity activity,
      Style style,
      List<OnToastButtonClickListenerHolder> onToastButtonClickListeners,
      List<OnToastDismissListenerHolder> onToastDismissListeners,
      int position) {

    SuperCardToast superCardToast;

    if (style.mType == Type.BUTTON) {

      superCardToast = new SuperCardToast(activity, Type.BUTTON);
      superCardToast.setButtonText(style.mButtonText);
      superCardToast.setButtonTextSizeFloat(style.mButtonTextSize);
      superCardToast.setButtonTextColor(style.mButtonTextColor);
      superCardToast.setButtonResource(style.mButtonResource);
      superCardToast.setButtonDividerResource(style.mButtonDividerResource);
      superCardToast.setButtonTypeface(style.mButtonTypeface);

      /** Reattach any OnToastButtonClickListeners via retained Fragment */
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        FragmentRetainer fragmentRetainer =
            (FragmentRetainer) activity.getFragmentManager().findFragmentByTag(FRAGMENTRETAINER_ID);

        if (fragmentRetainer != null && fragmentRetainer.getClickListeners() != null) {

          for (OnToastButtonClickListenerHolder onToastButtonClickListenerHolder :
              fragmentRetainer.getClickListeners()) {

            if (onToastButtonClickListenerHolder.getTag().equals(style.mClickListenerTag)) {

              superCardToast.setOnToastButtonClickListener(onToastButtonClickListenerHolder);
            }
          }
        }

        /** Reattach any OnToastButtonClickListeners via provided List */
      } else {

        if (onToastButtonClickListeners != null) {

          for (OnToastButtonClickListenerHolder onToastButtonClickListenerHolder :
              onToastButtonClickListeners) {

            if (onToastButtonClickListenerHolder
                .getTag()
                .equalsIgnoreCase(style.mClickListenerTag)) {

              superCardToast.setOnToastButtonClickListener(onToastButtonClickListenerHolder);
            }
          }
        }
      }

    } else if (style.mType == Type.PROGRESS) {

      /** PROGRESS style SuperCardToasts should be managed by the developer */
      return;

    } else if (style.mType == Type.PROGRESS_HORIZONTAL) {

      /** PROGRESS_HORIZONTAL style SuperCardToasts should be managed by the developer */
      return;

    } else {

      superCardToast = new SuperCardToast(activity);
    }

    /** Reattach any OnToastBDismissListeners via retained Fragment */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

      FragmentRetainer fragmentRetainer =
          (FragmentRetainer) activity.getFragmentManager().findFragmentByTag(FRAGMENTRETAINER_ID);

      if (fragmentRetainer != null && fragmentRetainer.getDismissListeners() != null) {

        for (OnToastDismissListenerHolder onToastDismissListenerHolder :
            fragmentRetainer.getDismissListeners()) {

          if (onToastDismissListenerHolder.getTag().equals(style.mDismissListenerTag)) {

            superCardToast.setOnToastDismissListener(onToastDismissListenerHolder);
          }
        }
      }

      /** Reattach any OnToastBDismissListeners via provided List */
    } else {

      if (onToastDismissListeners != null) {

        for (OnToastDismissListenerHolder onToastDismissListenerHolder : onToastDismissListeners) {

          if (onToastDismissListenerHolder.getTag().equalsIgnoreCase(style.mDismissListenerTag)) {

            superCardToast.setOnToastDismissListener(onToastDismissListenerHolder);
          }
        }
      }
    }

    superCardToast.setAnimations(style.mAnimations);
    superCardToast.setText(style.mText);
    superCardToast.setTypeface(style.mTypeface);
    superCardToast.setDuration(style.mDuration);
    superCardToast.setTextColor(style.mTextColor);
    superCardToast.setTextSizeFloat(style.mTextSize);
    superCardToast.setIndeterminate(style.isIndeterminate);
    superCardToast.setIcon(style.mIconResource, style.mIconPosition);
    superCardToast.setBackgroundResource(style.mBackgroundResource);

    /** Must use if else statements here to prevent erratic behavior */
    if (style.isTouchDismissable) {

      superCardToast.setTouchToDismiss(true);

    } else if (style.isSwipeDismissable) {

      superCardToast.setSwipeToDismiss(true);
    }

    superCardToast.setShowImmediate(true);
    superCardToast.show();
  }