/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param text The desired text to be shown * @param duration The desired duration of the SuperActivityToast * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull String text, @Style.Duration int duration) { return (SuperActivityToast) new SuperActivityToast(context) .setText(text) .setDuration(duration); }
@Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } });
/** * Public constructor for a SuperActivityToast. * * @param context An Activity Context */ public SuperActivityToast(@NonNull Context context) { super(context); if (!(context instanceof Activity)) { throw new IllegalArgumentException("SuperActivityToast Context must be an Activity."); } this.mContext = context; this.mStyle = this.getStyle(); // Style is created in the super(context) call // Set the default ViewGroup as the Activity's content this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content); }
final int typeArbiter = random.nextInt(5); switch (typeArbiter) { case 1: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_BUTTON); break; case 2: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_PROGRESS_BAR); break; case 3: superActivityToast = new SuperActivityToast(Playground.this, Style.TYPE_PROGRESS_CIRCLE); break; default: superActivityToast = new SuperActivityToast(Playground.this); break; superActivityToast.setText("SuperActivityToast"); superActivityToast.setTouchToDismiss(true); case 1: superActivityToast.setTypefaceStyle(Typeface.BOLD); break; case 2: superActivityToast.setTypefaceStyle(Typeface.BOLD_ITALIC); break; case 3: superActivityToast.setTypefaceStyle(Typeface.ITALIC); break; default: superActivityToast.setTypefaceStyle(Typeface.NORMAL); case 1: superActivityToast.setAnimations(Style.ANIMATIONS_FADE); break; case 2: superActivityToast.setAnimations(Style.ANIMATIONS_FLY); break; case 3: superActivityToast.setAnimations(Style.ANIMATIONS_POP); break; default: superActivityToast.setAnimations(Style.ANIMATIONS_SCALE); int blue = random.nextInt(255); int green = random.nextInt(255); superActivityToast.setColor(Color.argb(255, red, blue, green)); case 1: superActivityToast.setFrame(Style.FRAME_KITKAT); break; case 2: superActivityToast.setFrame(Style.FRAME_LOLLIPOP); break; default: superActivityToast.setFrame(Style.FRAME_STANDARD); break; blue = random.nextInt(255);
@Override @SuppressWarnings("ResourceType") public void onClick(View view) { final int containerId = AttributeUtils.getFrame(getActivity()) == Style.FRAME_LOLLIPOP || AttributeUtils.getType(getActivity()) == Style.TYPE_BUTTON ? R.id.toast_container : 0; SuperActivityToast.create(getActivity(), new Style(), AttributeUtils.getType(getActivity()), containerId) .setButtonText("UNDO") .setButtonIconResource(R.drawable.ic_undo) .setOnButtonClickListener("good_tag_name", null, onButtonClickListener) .setProgressBarColor(Color.WHITE) .setText("SuperActivityToast") .setDuration(AttributeUtils.getDuration(getActivity())) .setFrame(AttributeUtils.getFrame(getActivity())) .setColor(AttributeUtils.getColor(getActivity())) .setAnimations(AttributeUtils.getAnimations(getActivity())).show(); } });
if (!style.isSuperActivityToast) new SuperToast(context, style).show(); else { final SuperActivityToast superActivityToast = new SuperActivityToast(context, style); if (firstInList) superActivityToast.fromOrientationChange(); superActivityToast.setOnDismissListener(style.dismissTag, style.dismissToken, onDismissListener); superActivityToast.setOnButtonClickListener(style.buttonTag, style.buttonToken, onButtonClickListener); superActivityToast.show();
new SuperActivityToast(context, style).fromOrientationChange().show(); else new SuperActivityToast(context, style).show();
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context) { return (SuperActivityToast) new SuperActivityToast(context); }
switch (superActivityToast.getAnimations()) { case Style.ANIMATIONS_FADE: return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderAlpha) .setDuration(SHOW_DURATION); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderX, propertyValuesHolderAlpha).setDuration(SHOW_DURATION); final PropertyValuesHolder propertyValuesHolderScaleX = PropertyValuesHolder.ofFloat(SCALE_X, 1f, 0f); final PropertyValuesHolder propertyValuesHolderScaleY = PropertyValuesHolder.ofFloat(SCALE_Y, 1f, 0f); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderScaleX, propertyValuesHolderScaleY, propertyValuesHolderAlpha).setDuration(SHOW_DURATION); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderY, propertyValuesHolderAlpha).setDuration(SHOW_DURATION); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderAlpha) .setDuration(SHOW_DURATION);
@Override public boolean onTouch(View v, MotionEvent motionEvent) { // Prevent repetitive touch events if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN) dismiss(); timesTouched++; return false; // Do not consume the event in case a Button listener is set } });
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param type The desired type of the SuperActivityToast * * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @Style.Type int type) { return (SuperActivityToast) new SuperActivityToast(context, type); }
switch (superActivityToast.getAnimations()) { case Style.ANIMATIONS_FADE: return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderAlpha) .setDuration(SHOW_DURATION); final PropertyValuesHolder propertyValuesHolderX = PropertyValuesHolder. ofFloat(TRANSLATION_X, -500f, 0f); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderX, propertyValuesHolderAlpha).setDuration(SHOW_DURATION); final PropertyValuesHolder propertyValuesHolderScaleY = PropertyValuesHolder .ofFloat(SCALE_Y, 0f, 1f); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderScaleX, propertyValuesHolderScaleY, propertyValuesHolderAlpha) final PropertyValuesHolder propertyValuesHolderY = PropertyValuesHolder .ofFloat(TRANSLATION_Y, 250f, 0f); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderY, propertyValuesHolderAlpha).setDuration(SHOW_DURATION); return ObjectAnimator.ofPropertyValuesHolder(superActivityToast.getView(), propertyValuesHolderAlpha) .setDuration(SHOW_DURATION);
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param text The desired text to be shown * @param duration The desired duration of the SuperActivityToast * @param style The desired Style of the SuperToast * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull String text, @Style.Duration int duration, @NonNull Style style) { return (SuperActivityToast) new SuperActivityToast(context, style) .setText(text) .setDuration(duration); }
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param style The desired Style of the SuperActivityToast * @param type The desired type of the SuperActivityToast * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull Style style, @Style.Type int type) { return (SuperActivityToast) new SuperActivityToast(context, style, type); }
/** * Public constructor for a SuperActivityToast. * * @param context An Activity Context * @param type The desired SuperActivityToast type */ public SuperActivityToast(@NonNull Context context, @Style.Type int type) { super(context, type); if (!(context instanceof Activity)) { throw new IllegalArgumentException("SuperActivityToast Context must be an Activity."); } this.mContext = context; this.mStyle = this.getStyle(); // Style is created in the super(context) call // Set the default ViewGroup as the Activity's content this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content); }
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param text The desired text to be shown * @param duration The desired duration of the SuperActivityToast * @param style The desired Style of the SuperToast * @param viewGroup The ViewGroup to attach the SuperActivityToast to * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull String text, @Style.Duration int duration, @NonNull Style style, @IdRes int viewGroup) { return (SuperActivityToast) new SuperActivityToast(context, style, Style.TYPE_STANDARD, viewGroup) .setText(text) .setDuration(duration); } }
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param style The desired Style of the SuperActivityToast * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull Style style) { return (SuperActivityToast) new SuperActivityToast(context, style); }
/** * Public constructor for a SuperActivityToast. * * @param context An Activity Context * @param style The desired Style * @param type The desired SuperActivityToast type */ public SuperActivityToast(@NonNull Context context, @NonNull Style style, @Style.Type int type) { super(context, style, type); if (!(context instanceof Activity)) { throw new IllegalArgumentException("SuperActivityToast Context must be an Activity."); } this.mContext = context; this.mStyle = this.getStyle(); // Style is created in the super(context) call // Set the default ViewGroup as the Activity's content this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content); }
/** * Creates a simple SuperActivityToast. Don't forget to call {@link SuperToast#show()}. * * @param context An Activity Context * @param style The desired Style of the SuperActivityToast * @param type The desired type of the SuperActivityToast/ * @param viewGroup the id of a ViewGroup to add the SuperActivityToast to * @return The newly created SuperActivityToast */ public static SuperActivityToast create(@NonNull Context context, @NonNull Style style, @Style.Type int type, @IdRes int viewGroup) { return (SuperActivityToast) new SuperActivityToast(context, style, type, viewGroup); }
/** * Public constructor for a SuperActivityToast. * * @param context An Activity Context * @param style The desired Style * @param type The desired SuperActivityToast type * @param viewGroupId The id of the ViewGroup to attach the SuperActivityToast to */ public SuperActivityToast(@NonNull Context context, @NonNull Style style, @Style.Type int type, @IdRes int viewGroupId) { super(context, style, type, viewGroupId); if (!(context instanceof Activity)) { throw new IllegalArgumentException("SuperActivityToast Context must be an Activity."); } this.mContext = context; this.mStyle = this.getStyle(); // Style is created in the super(context) call // Try to find the ViewGroup id in the layout this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(viewGroupId); if (this.mViewGroup == null) { Log.e(getClass().getName(), "Could not find a ViewGroup with id " + String.valueOf(viewGroupId)); this.mViewGroup = (ViewGroup) ((Activity) context).findViewById(android.R.id.content); } }