From b2f9d68d09902b78544083896803dc549c41eb2b Mon Sep 17 00:00:00 2001 From: slymax Date: Mon, 21 Jan 2019 20:36:40 +0100 Subject: [PATCH] minor fixes --- app/src/main/java/com/example/app/MainActivity.java | 6 +++--- app/src/main/java/com/example/app/MyWebViewClient.java | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/app/MainActivity.java b/app/src/main/java/com/example/app/MainActivity.java index 10cc58a..264c404 100755 --- a/app/src/main/java/com/example/app/MainActivity.java +++ b/app/src/main/java/com/example/app/MainActivity.java @@ -1,9 +1,8 @@ package com.example.app; +import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -12,12 +11,13 @@ public class MainActivity extends Activity { private WebView mWebView; + @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - mWebView = (WebView) findViewById(R.id.activity_main_webview); + mWebView = findViewById(R.id.activity_main_webview); // Force links and redirects to open in the WebView instead of in a browser mWebView.setWebViewClient(new WebViewClient()); diff --git a/app/src/main/java/com/example/app/MyWebViewClient.java b/app/src/main/java/com/example/app/MyWebViewClient.java index 2087cf1..dc10ce9 100755 --- a/app/src/main/java/com/example/app/MyWebViewClient.java +++ b/app/src/main/java/com/example/app/MyWebViewClient.java @@ -5,11 +5,13 @@ import android.net.Uri; import android.webkit.WebView; import android.webkit.WebViewClient; -public class MyWebViewClient extends WebViewClient { +import java.util.Objects; + +class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Uri.parse(url).getHost().endsWith("example.com")) { + if (Objects.requireNonNull(Uri.parse(url).getHost()).endsWith("example.com")) { return false; }