Skip to content

Commit 11b1347

Browse files
authored
breaking(android): replace magic numbers with android.os.Build constants (apache#821)
1 parent 85acc2a commit 11b1347

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/android/InAppBrowser.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ else if (action.equals("loadAfterBeforeload")) {
269269
@SuppressLint("NewApi")
270270
@Override
271271
public void run() {
272-
currentClient.waitForBeforeload = false;
273-
inAppWebView.setWebViewClient(currentClient);
272+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
273+
currentClient.waitForBeforeload = false;
274+
inAppWebView.setWebViewClient(currentClient);
275+
} else {
276+
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
277+
}
274278
inAppWebView.loadUrl(url);
275279
}
276280
});
@@ -410,7 +414,7 @@ private void injectDeferredObject(String source, String jsWrapper) {
410414
@SuppressLint("NewApi")
411415
@Override
412416
public void run() {
413-
if (Build.VERSION.SDK_INT < 19) {
417+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
414418
// This action will have the side-effect of blurring the currently focused element
415419
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
416420
} else {
@@ -1002,7 +1006,7 @@ public void postMessage(String data) {
10021006
}
10031007
}
10041008

1005-
if(android.os.Build.VERSION.SDK_INT >= 17) {
1009+
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
10061010
settings.setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
10071011
inAppWebView.addJavascriptInterface(new JsObject(), "cordova_iab");
10081012
}
@@ -1034,7 +1038,7 @@ public void postMessage(String data) {
10341038
}
10351039

10361040
// Enable Thirdparty Cookies on >=Android 5.0 device
1037-
if (android.os.Build.VERSION.SDK_INT >= 21) {
1041+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
10381042
CookieManager.getInstance().setAcceptThirdPartyCookies(inAppWebView,true);
10391043
}
10401044

@@ -1128,7 +1132,7 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu
11281132
*/
11291133
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
11301134
// For Android >= 5.0
1131-
if(Build.VERSION.SDK_INT >= 21) {
1135+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
11321136
LOG.d(LOG_TAG, "onActivityResult (For Android >= 5.0)");
11331137
// If RequestCode or Callback is Invalid
11341138
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
@@ -1201,7 +1205,7 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) {
12011205
* @param webView
12021206
* @param request
12031207
*/
1204-
@TargetApi(24)
1208+
@TargetApi(Build.VERSION_CODES.N)
12051209
@Override
12061210
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request) {
12071211
return shouldOverrideUrlLoading(request.getUrl().toString(), request.getMethod());
@@ -1373,7 +1377,7 @@ public WebResourceResponse shouldInterceptRequest (final WebView view, String ur
13731377
* @param webView
13741378
* @param request
13751379
*/
1376-
@TargetApi(21)
1380+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
13771381
@Override
13781382
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
13791383
return shouldInterceptRequest(request.getUrl().toString(), super.shouldInterceptRequest(view, request), request.getMethod());
@@ -1424,12 +1428,12 @@ public void onPageFinished(WebView view, String url) {
14241428
super.onPageFinished(view, url);
14251429

14261430
// Set the namespace for postMessage()
1427-
if (Build.VERSION.SDK_INT >= 17) {
1431+
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
14281432
injectDeferredObject("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}", null);
14291433
}
14301434

14311435
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
1432-
if (android.os.Build.VERSION.SDK_INT >= 21) {
1436+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
14331437
CookieManager.getInstance().flush();
14341438
} else {
14351439
CookieSyncManager.getInstance().sync();

0 commit comments

Comments
 (0)