Skip to content

Commit

Permalink
Remove show toast method call from cancel timer to ensure that toast …
Browse files Browse the repository at this point in the history
…show is called only once. #118
  • Loading branch information
EddyVerbruggen committed Aug 22, 2018
1 parent e4e18f1 commit 8869b81
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ The Android code was entirely created by me.
For iOS most credits go to this excellent [Toast for iOS project by Charles Scalesse] (https://github.com/scalessec/Toast).

## 6. CHANGELOG
- 2.7.0: [Android P compatibility.](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/116)
- 2.6.2: [iOS view hierarchy fix.](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/pull/112)
- 2.6.0: Windows support!
- 2.5.2: Multi-line wrapping Toasts are now center aligned.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-x-toast",
"version": "2.6.2",
"version": "2.7.0",
"description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.",
"cordova": {
"id": "cordova-plugin-x-toast",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-x-toast"
version="2.6.2">
version="2.7.0">

<name>Toast</name>

Expand Down
10 changes: 8 additions & 2 deletions src/android/nl/xservices/plugins/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Toast extends CordovaPlugin {
private ViewGroup viewGroup;

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;

// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
private boolean isPaused;
Expand Down Expand Up @@ -192,7 +193,12 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
}
// trigger show every 2500 ms for as long as the requested duration
_timer = new CountDownTimer(hideAfterMs, 2500) {
public void onTick(long millisUntilFinished) { }
public void onTick(long millisUntilFinished) {
// see https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/116
if (!IS_AT_LEAST_PIE) {
toast.show();
}
}
public void onFinish() {
returnTapEvent("hide", msg, data, callbackContext);
toast.cancel();
Expand Down Expand Up @@ -257,4 +263,4 @@ public void onPause(boolean multitasking) {
public void onResume(boolean multitasking) {
this.isPaused = false;
}
}
}

0 comments on commit 8869b81

Please sign in to comment.