/** * Returns a dark theme SuperCardToast with a supplied animation. <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 * @param animations Should use SuperToast.Animations * @return SuperCardToast */ public static SuperCardToast createSuperCardToast( Context context, CharSequence textCharSequence, int durationInteger, Animations animations) { SuperCardToast superCardToast = new SuperCardToast(context); superCardToast.setText(textCharSequence); superCardToast.setDuration(durationInteger); superCardToast.setAnimations(animations); return superCardToast; }
/** * Returns a light theme SuperCardToast with a supplied animation. <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 * @param animations Should use SuperToast.Animations * @return SuperCardToast */ public static SuperCardToast createLightSuperCardToast( Context context, CharSequence textCharSequence, int durationInteger, Animations animations) { SuperCardToast SuperCardToast = new SuperCardToast(context); SuperCardToast.setText(textCharSequence); SuperCardToast.setDuration(durationInteger); SuperCardToast.setBackgroundResource(SuperToast.Background.WHITE); SuperCardToast.setTextColor(Color.BLACK); SuperCardToast.setAnimations(animations); return SuperCardToast; }
/** 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(); }