mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-02-24 10:12:53 +08:00
Merge pull request #142 from tomburger/fix/api-30-crashing
fix the crash for API 30
This commit is contained in:
commit
28cc48357c
@ -35,8 +35,10 @@ public class Toast extends CordovaPlugin {
|
|||||||
private android.widget.Toast mostRecentToast;
|
private android.widget.Toast mostRecentToast;
|
||||||
private ViewGroup viewGroup;
|
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_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_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
|
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
|
||||||
private boolean isPaused;
|
private boolean isPaused;
|
||||||
@ -105,7 +107,8 @@ public class Toast extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if one of the custom layout options have been passed in, draw our own shape
|
// if one of the custom layout options have been passed in, draw our own shape
|
||||||
if (styling != null && Build.VERSION.SDK_INT >= 16) {
|
// (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
|
// the defaults mimic the default toast as close as possible
|
||||||
final String backgroundColor = styling.optString("backgroundColor", "#333333");
|
final String backgroundColor = styling.optString("backgroundColor", "#333333");
|
||||||
@ -132,14 +135,18 @@ public class Toast extends CordovaPlugin {
|
|||||||
toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
|
toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
|
||||||
|
|
||||||
// this gives the toast a very subtle shadow on newer devices
|
// 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);
|
toast.getView().setElevation(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener',
|
if (IS_AT_LEAST_R) {
|
||||||
// so created something funky that compares the Toast position to the tap coordinates.
|
// On Android >= 11 the 'toast.getView()' will always return null
|
||||||
if (IS_AT_LEAST_LOLLIPOP) {
|
// 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() {
|
getViewGroup().setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user