@Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } });
/** * Send a message at a later time. This is used to dismiss a SuperToast. */ private void sendDelayedMessage(SuperToast superToast, int messageId, long delay) { Message message = obtainMessage(messageId); message.obj = superToast; sendMessageDelayed(message, delay); }
/** * Returns the dismiss Parcelable token of the SuperActivityToast. * * @return The dismiss Parcelable token */ @Override public Parcelable getDismissToken() { return super.getDismissToken(); }
/** * 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); }
/** * Default material red transparent style for SuperToasts. * @return A new Style */ public static Style red() { final Style style = new Style(); style.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_RED); return style; }
@Override public void onAnimationEnd(Animator animation) { if (superToast.getOnDismissListener() != null) { superToast.getOnDismissListener().onDismiss(superToast.getView(), superToast.getStyle().dismissToken); } ((SuperActivityToast) superToast).getViewGroup().removeView(superToast.getView()); // Show the next SuperToast if any exist Toaster.this.showNextSuperToast(); }
/** * Shows the SuperToast. If any SuperToast is already showing, this SuperToast * will be enqueued until the others have finished (depending on priority level). */ public void show() { this.onPrepareShow(); Toaster.getInstance().add(this); AccessibilityUtils.sendAccessibilityEvent(this.mView); }
@Override public void onClick(View view) { getRandomSuperToast().show(); } });
/** * Show the next SuperToast in the current queue. If a SuperToast is currently showing, * do nothing. The currently showing SuperToast will call this method when it dismisses. */ private void showNextSuperToast() { // Do nothing if the queue is empty if (superToastPriorityQueue.isEmpty()) return; // Get next SuperToast in the queue final SuperToast superToast = superToastPriorityQueue.peek(); if (!superToast.isShowing()) { final Message message = obtainMessage(Messages.DISPLAY_SUPERTOAST); message.obj = superToast; sendMessage(message); } }
@Override public int compare(SuperToast x, SuperToast y) { // Do not shuffle around any showing SuperToasts if (x.isShowing()) return -1; if (x.getStyle().priorityLevel < y.getStyle().priorityLevel) return -1; else if (x.getStyle().priorityLevel > y.getStyle().priorityLevel) return 1; // PriorityQueue uses a heap, we want to maintain insertion order else return x.getStyle().timestamp <= y.getStyle().timestamp ? -1 : 1; } }
/** * Dismissed the SuperToast if it is showing. */ public void dismiss() { Toaster.getInstance().removeSuperToast(this); }
/** * Dismisses every SuperToast and SuperActivityToast that is showing and * cancels everything in the queue. */ public static void cancelAllSuperToasts() { Toaster.getInstance().cancelAllSuperToasts(); }
public Style createFromParcel(Parcel parcel) { return new Style(parcel); }
/** * 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); }
/** * Returns the dismiss tag of the SuperActivityToast. * * @return The dismiss tag */ @Override public String getDismissTag() { return super.getDismissTag(); }
/** * Gets the current instance of the Toaster. If there is no extant instance, * a new one will be created. * * @return The current Toaster instance */ static synchronized Toaster getInstance() { if (mToaster != null) return mToaster; else { mToaster = new Toaster(); return mToaster; } }
/** * 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); }
/** * Default material purple transparent style for SuperToasts. * @return A new Style */ public static Style purple() { final Style style = new Style(); style.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_PURPLE); return style; }
/** * Default material light blue transparent style for SuperToasts. * @return A new Style */ public static Style lightBlue() { final Style style = new Style(); style.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_LIGHT_BLUE); return style; }
/** * Default material grey transparent style for SuperToasts. * @return A new Style */ public static Style grey() { final Style style = new Style(); style.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_GREY); return style; }