1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-18 22:57:48 +01:00

Add some style, intercept and display toast in case of JS errors

This commit is contained in:
Daniele Gobbetti 2016-03-18 17:50:24 +01:00
parent e69fac9704
commit 538961fd2c
2 changed files with 46 additions and 6 deletions

View File

@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'> <meta charset="utf-8" />
<meta name='viewport' content='initial-scale=1.0, maximum-scale=1.0'>
<script type="text/javascript" src="js/Uri.js"> <script type="text/javascript" src="js/Uri.js">
</script> </script>
<script type="text/javascript" src="js/gadgetbridge_boilerplate.js"> <script type="text/javascript" src="js/gadgetbridge_boilerplate.js">
@ -8,19 +9,48 @@
<script type="text/javascript"> <script type="text/javascript">
</script> </script>
<style> <style>
body {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-touch-callout: none;
}
#config_url,#jsondata {
word-wrap: break-word;
margin: 20px;
}
.btn {
display: inline-block;
position: relative;
height: 32px;
line-height: 32px;
border-radius: 2px;
font-size: 0.9em;
background-color: #eee;
color: #646464;
text-align: center;
border-style: none;
}
.btn:active {
border-style: none;
box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2)inset;
transition-delay: 0s;
}
<!-- TODO --> <!-- TODO -->
</style> </style>
</head> </head>
<body onload="" style="width: 100%;"> <body onload="" style="width: 100%;">
<div id="step1"> <div id="step1">
<h2>Url of the configuration:</h2> <h2>Url of the configuration:</h2>
<div id="config_url" style="height: 100px; width: 100%;"></div> <div id="config_url"></div>
<button name="show config" value="show config" onclick="Pebble.showConfiguration()" >1) showConfig</button> <button class="btn" name="show config" value="show config" onclick="Pebble.showConfiguration()" >Show config / URL</button>
<button name="open config" value="open config" onclick="Pebble.actuallyOpenURL()" >2) Open configuration website</button> <button class="btn" name="open config" value="open config" onclick="Pebble.actuallyOpenURL()" >Open configuration website</button>
</div> </div>
<div id="step2"> <div id="step2">
<h2>Incoming configuration data:</h2> <h2>Incoming configuration data:</h2>
<div id="jsondata" style="height: 100px; width: 100%;"></div> <div id="jsondata"></div>
<button name="send config" value="send config" onclick="Pebble.actuallySendData()" >Send data to pebble</button> <button class="btn" name="send config" value="send config" onclick="Pebble.actuallySendData()" >Send data to pebble</button>
</div> </div>
</body> </body>

View File

@ -7,7 +7,9 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
@ -64,6 +66,7 @@ public class ExternalPebbleJSActivity extends Activity {
WebView myWebView = (WebView) findViewById(R.id.configureWebview); WebView myWebView = (WebView) findViewById(R.id.configureWebview);
myWebView.clearCache(true); myWebView.clearCache(true);
myWebView.setWebViewClient(new GBWebClient()); myWebView.setWebViewClient(new GBWebClient());
myWebView.setWebChromeClient(new GBChromeClient());
WebSettings webSettings = myWebView.getSettings(); WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptEnabled(true);
//needed to access the DOM //needed to access the DOM
@ -90,6 +93,13 @@ public class ExternalPebbleJSActivity extends Activity {
return null; return null;
} }
private class GBChromeClient extends WebChromeClient {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
GB.toast(consoleMessage.message(), Toast.LENGTH_LONG, GB.ERROR);
return super.onConsoleMessage(consoleMessage);
}
}
private class GBWebClient extends WebViewClient { private class GBWebClient extends WebViewClient {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {