From 9414e6915da9a4cad1ef30aff69e8d27187490d1 Mon Sep 17 00:00:00 2001 From: Alexis THOMAS Date: Thu, 28 Oct 2021 01:56:18 +0200 Subject: [PATCH 1/2] cleanup: use constants to check on Build.VERSION.SDK_INT --- src/android/nl/xservices/plugins/Toast.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index de6b510..03242bf 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -35,6 +35,7 @@ public class Toast extends CordovaPlugin { private android.widget.Toast mostRecentToast; private ViewGroup viewGroup; + private static final boolean IS_AT_LEAST_JELLY_BEAN = Build.VERSION.SDK_INT >= 16; private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21; private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28; @@ -105,7 +106,7 @@ public void run() { } // if one of the custom layout options have been passed in, draw our own shape - if (styling != null && Build.VERSION.SDK_INT >= 16) { + if (styling != null && IS_AT_LEAST_JELLY_BEAN) { // the defaults mimic the default toast as close as possible final String backgroundColor = styling.optString("backgroundColor", "#333333"); @@ -132,7 +133,7 @@ public void run() { toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); // this gives the toast a very subtle shadow on newer devices - if (Build.VERSION.SDK_INT >= 21) { + if (IS_AT_LEAST_LOLLIPOP) { toast.getView().setElevation(6); } } From a4aca43b5221bd4de80d370ac6551cbfbf732ed0 Mon Sep 17 00:00:00 2001 From: Alexis THOMAS Date: Thu, 28 Oct 2021 02:09:23 +0200 Subject: [PATCH 2/2] fix: sdk 30 no styling nor touchListener --- src/android/nl/xservices/plugins/Toast.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 03242bf..8ce0959 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -38,6 +38,7 @@ public class Toast extends CordovaPlugin { private static final boolean IS_AT_LEAST_JELLY_BEAN = Build.VERSION.SDK_INT >= 16; private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21; private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28; + private static final boolean IS_AT_LEAST_R = Build.VERSION.SDK_INT >= 30; // note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style private boolean isPaused; @@ -106,7 +107,8 @@ public void run() { } // if one of the custom layout options have been passed in, draw our own shape - if (styling != null && IS_AT_LEAST_JELLY_BEAN) { + // (but disabled on Android >= 11 since custom toast views are deprecated) + if (styling != null && IS_AT_LEAST_JELLY_BEAN && !IS_AT_LEAST_R) { // the defaults mimic the default toast as close as possible final String backgroundColor = styling.optString("backgroundColor", "#333333"); @@ -138,9 +140,13 @@ public void run() { } } - // On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener', - // so created something funky that compares the Toast position to the tap coordinates. - if (IS_AT_LEAST_LOLLIPOP) { + if (IS_AT_LEAST_R) { + // On Android >= 11 the 'toast.getView()' will always return null + // so no touchListener can be used or mocked + // DO NOTHING + } else if (IS_AT_LEAST_LOLLIPOP) { + // On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener', + // so created something funky that compares the Toast position to the tap coordinates. getViewGroup().setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) {