diff options
| author | Beverly <beverlyt@google.com> | 2020-09-29 09:44:09 -0400 |
|---|---|---|
| committer | Beverly <beverlyt@google.com> | 2020-09-30 20:48:29 -0400 |
| commit | b7ef5de9e06f2efcb57612ab099028b427a5604e (patch) | |
| tree | 22954a7f972f87688fe664e71df908e8955d9d22 /core/java/android/widget/ToastPresenter.java | |
| parent | 8862617d5f80b50185d1a8092a70309a8fc52ee4 (diff) | |
Add Plugin interface for Toasts
Allows Toasts that route through SystemUI to be implemented by a
ToastPlugin. This CL also adds the ability for plugins to create a
custom animation for when the toast shows and hides.
Also adds logging for Toasts that get routed through SystemUI. By
default, these logs aren't logged to logcat but can be enabled via adb (see
LogBuffer.kt).
To dump ToastLog:
adb shell dumpsys activity service com.android.systemui/.SystemUIService ToastLog
Bug: 169587378
Test: manually add CustomToastPlugin
Test: atest ToastUITest
Change-Id: I0a0b16fdc2a5ba1908054197f6dc6728f10a0d2e
Diffstat (limited to 'core/java/android/widget/ToastPresenter.java')
| -rw-r--r-- | core/java/android/widget/ToastPresenter.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/core/java/android/widget/ToastPresenter.java b/core/java/android/widget/ToastPresenter.java index fb5d55dd2141..b484dfacbf6c 100644 --- a/core/java/android/widget/ToastPresenter.java +++ b/core/java/android/widget/ToastPresenter.java @@ -48,6 +48,8 @@ import com.android.internal.util.ArrayUtils; public class ToastPresenter { private static final String TAG = "ToastPresenter"; private static final String WINDOW_TITLE = "Toast"; + + // exclusively used to guarantee window timeouts private static final long SHORT_DURATION_TIMEOUT = 4000; private static final long LONG_DURATION_TIMEOUT = 7000; @@ -145,7 +147,7 @@ public class ToastPresenter { */ private void adjustLayoutParams(WindowManager.LayoutParams params, IBinder windowToken, int duration, int gravity, int xOffset, int yOffset, float horizontalMargin, - float verticalMargin) { + float verticalMargin, boolean removeWindowAnimations) { Configuration config = mResources.getConfiguration(); int absGravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection()); params.gravity = absGravity; @@ -163,6 +165,10 @@ public class ToastPresenter { params.hideTimeoutMilliseconds = (duration == Toast.LENGTH_LONG) ? LONG_DURATION_TIMEOUT : SHORT_DURATION_TIMEOUT; params.token = windowToken; + + if (removeWindowAnimations && params.windowAnimations == R.style.Animation_Toast) { + params.windowAnimations = 0; + } } /** @@ -193,16 +199,28 @@ public class ToastPresenter { /** * Shows the toast in {@code view} with the parameters passed and callback {@code callback}. + * Uses window animations to animate the toast. */ public void show(View view, IBinder token, IBinder windowToken, int duration, int gravity, int xOffset, int yOffset, float horizontalMargin, float verticalMargin, @Nullable ITransientNotificationCallback callback) { + show(view, token, windowToken, duration, gravity, xOffset, yOffset, horizontalMargin, + verticalMargin, callback, false /* removeWindowAnimations */); + } + + /** + * Shows the toast in {@code view} with the parameters passed and callback {@code callback}. + * Can optionally remove window animations from the toast window. + */ + public void show(View view, IBinder token, IBinder windowToken, int duration, int gravity, + int xOffset, int yOffset, float horizontalMargin, float verticalMargin, + @Nullable ITransientNotificationCallback callback, boolean removeWindowAnimations) { checkState(mView == null, "Only one toast at a time is allowed, call hide() first."); mView = view; mToken = token; adjustLayoutParams(mParams, windowToken, duration, gravity, xOffset, yOffset, - horizontalMargin, verticalMargin); + horizontalMargin, verticalMargin, removeWindowAnimations); if (mView.getParent() != null) { mWindowManager.removeView(mView); } @@ -247,7 +265,8 @@ public class ToastPresenter { try { callback.onToastHidden(); } catch (RemoteException e) { - Log.w(TAG, "Error calling back " + mPackageName + " to notify onToastHide()", e); + Log.w(TAG, "Error calling back " + mPackageName + " to notify onToastHide()", + e); } } mView = null; |
