forked from github/Toast-PhoneGap-Plugin
#80 Receiving a callback when a Toast is tapped not trigger in Android
This commit is contained in:
parent
52e4072ce6
commit
b5adb0da91
@ -35,6 +35,8 @@ public class Toast extends CordovaPlugin {
|
||||
private android.widget.Toast mostRecentToast;
|
||||
private ViewGroup viewGroup;
|
||||
|
||||
private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21;
|
||||
|
||||
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
|
||||
private boolean isPaused;
|
||||
|
||||
@ -79,7 +81,7 @@ public class Toast extends CordovaPlugin {
|
||||
hideAfterMs = Integer.parseInt(duration);
|
||||
}
|
||||
final android.widget.Toast toast = android.widget.Toast.makeText(
|
||||
Build.VERSION.SDK_INT >= 21 ? cordova.getActivity().getWindow().getContext() : cordova.getActivity().getApplicationContext(),
|
||||
IS_AT_LEAST_LOLLIPOP ? cordova.getActivity().getWindow().getContext() : cordova.getActivity().getApplicationContext(),
|
||||
message,
|
||||
android.widget.Toast.LENGTH_LONG // actually controlled by a timer further down
|
||||
);
|
||||
@ -128,8 +130,9 @@ public class Toast extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// On newer Android devices you can no longer rely on the 'toast.getView().setOnTouchListener',
|
||||
// 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) {
|
||||
getViewGroup().setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
@ -173,6 +176,14 @@ public class Toast extends CordovaPlugin {
|
||||
return tapped && returnTapEvent(msg, data, callbackContext);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast.getView().setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return motionEvent.getAction() == MotionEvent.ACTION_DOWN && returnTapEvent(msg, data, callbackContext);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// trigger show every 2500 ms for as long as the requested duration
|
||||
_timer = new CountDownTimer(hideAfterMs, 2500) {
|
||||
|
Loading…
Reference in New Issue
Block a user