Skip to content
Permalink
Browse files

Fixed a time out error when multiple request are being send

  • Loading branch information...
Miggets7 committed Jul 10, 2019
1 parent aa81a4a commit 120795fceb3c3e52e76c77a0dcf230f59de35902
Showing with 22 additions and 3 deletions.
  1. +22 −3 console/android/src/main/java/org/openremote/android/MainActivity.java
@@ -65,6 +65,7 @@
import java.util.logging.Logger;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

@@ -82,6 +83,8 @@

protected final ConnectivityChangeReceiver connectivityChangeReceiver = new ConnectivityChangeReceiver();
protected WebView webView;
protected Handler timeOutHandler;
protected Runnable timeOutRunnable;
protected ProgressBar progressBar;
protected int webViewTimeout = WEBVIEW_LOAD_TIMEOUT_DEFAULT;
protected boolean webViewLoaded;
@@ -374,24 +377,40 @@ public void onPageStarted(WebView view, final String url, Bitmap favicon) {

progressBar.setVisibility(View.VISIBLE);

Runnable run = new Runnable() {
timeOutRunnable = new Runnable() {
public void run() {
if (!webViewLoaded) {
handleError(ERROR_TIMEOUT, "Connection timed out", url, true);
}
}
};
Handler myHandler = new Handler(Looper.myLooper());
myHandler.postDelayed(run, 5000);
timeOutHandler = new Handler(Looper.myLooper());
timeOutHandler.postDelayed(timeOutRunnable, 5000);
}

@Override
public void onPageFinished(WebView view, String url) {
webViewLoaded = true;
progressBar.setVisibility(View.GONE);
timeOutHandler.removeCallbacks(timeOutRunnable);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if (uri.getScheme().equalsIgnoreCase("webbrowser")) {
String newUrl = uri.buildUpon().scheme("https").build().toString();
Intent i = new Intent(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(newUrl));
startActivity(i);
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}

@Override
@RequiresApi(Build.VERSION_CODES.N)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().getScheme().equalsIgnoreCase("webbrowser")) {
String newUrl = request.getUrl().buildUpon().scheme("https").build().toString();

0 comments on commit 120795f

Please sign in to comment.
You can’t perform that action at this time.