Skip to content

Commit

Permalink
cleanup: use constants to check on Build.VERSION.SDK_INT
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0mas committed Oct 28, 2021
1 parent 4e85560 commit 9414e69
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/android/nl/xservices/plugins/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 9414e69

Please sign in to comment.