diff options
| author | Yi-an Chen <theianchen@google.com> | 2022-06-01 11:24:06 -0700 |
|---|---|---|
| committer | Yi-an Chen <theianchen@google.com> | 2022-07-19 13:52:13 -0700 |
| commit | edfc44079c1cfc424e8266d0cf89d8e588cdcb5d (patch) | |
| tree | bf9deed41235e7aa6a27dfa1115104ce7ec7eb63 /core/java/android/widget/Toast.java | |
| parent | e9ff71ec1b1079ca2f718e48dbb4395bf1ad4852 (diff) | |
Add PbA branding to clipboard
Bug: 213357911
Test: Manually on Raven
Change-Id: If9944393fe64c7f94a5be139a538833d91ae98fe
Diffstat (limited to 'core/java/android/widget/Toast.java')
| -rw-r--r-- | core/java/android/widget/Toast.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index dbf3570b1d24..ca57c84a1631 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -32,6 +32,7 @@ import android.compat.annotation.EnabledAfter; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.Resources; +import android.graphics.drawable.Drawable; import android.os.Binder; import android.os.Build; import android.os.Handler; @@ -494,19 +495,39 @@ public class Toast { */ public static Toast makeText(@NonNull Context context, @Nullable Looper looper, @NonNull CharSequence text, @Duration int duration) { + Toast result = new Toast(context, looper); + if (Compatibility.isChangeEnabled(CHANGE_TEXT_TOASTS_IN_THE_SYSTEM)) { - Toast result = new Toast(context, looper); result.mText = text; - result.mDuration = duration; - return result; } else { - Toast result = new Toast(context, looper); - View v = ToastPresenter.getTextToastView(context, text); - result.mNextView = v; - result.mDuration = duration; + result.mNextView = ToastPresenter.getTextToastView(context, text); + } + + result.mDuration = duration; + return result; + } - return result; + /** + * Make a standard toast with an icon to display using the specified looper. + * If looper is null, Looper.myLooper() is used. + * + * The toast will be a custom view that's rendered by the app (instead of by SystemUI). + * In Android version R and above, non-system apps can only render the toast + * when it's in the foreground. + * + * @hide + */ + public static Toast makeCustomToastWithIcon(@NonNull Context context, @Nullable Looper looper, + @NonNull CharSequence text, @Duration int duration, @NonNull Drawable icon) { + if (icon == null) { + throw new IllegalArgumentException("Drawable icon should not be null " + + "for makeCustomToastWithIcon"); } + + Toast result = new Toast(context, looper); + result.mNextView = ToastPresenter.getTextToastViewWithIcon(context, text, icon); + result.mDuration = duration; + return result; } /** |
