1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-01 09:16:24 +02:00

Pebble background webview: config page should be shown reliably now.

This commit is contained in:
Daniele Gobbetti 2017-03-04 19:46:18 +01:00
parent 21b90d1e6e
commit f84c651c38
3 changed files with 38 additions and 22 deletions

View File

@ -99,6 +99,7 @@ function gbPebble() {
for (var i = 0; i < l; i++) {
evs[i].apply(null, args);
}
GBjs.eventFinished(name);
}
this.actuallyOpenURL = function() {
@ -204,6 +205,14 @@ document.addEventListener('DOMContentLoaded', function(){
if (jsConfigFile != null) {
loadScript(jsConfigFile, function() {
Pebble.evaluate('ready');
if(document.hasFocus() && !(getURLVariable('config') == 'true')) {
Pebble.evaluate('showConfiguration');
} else {
window.onfocus = function () {
GBjs.gbLog("window focused!!!");
Pebble.evaluate('showConfiguration');
};
}
if (getURLVariable('config') == 'true') {
showStep("step2");
var json_string = getURLVariable('json');

View File

@ -8,7 +8,6 @@ import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.Toast;
@ -28,9 +27,7 @@ public class ExternalPebbleJSActivity extends GBActivity {
private static final Logger LOG = LoggerFactory.getLogger(ExternalPebbleJSActivity.class);
private UUID appUuid;
private Uri confUri;
private GBDevice mGBDevice = null;
private WebView myWebView;
@Override
@ -39,8 +36,7 @@ public class ExternalPebbleJSActivity extends GBActivity {
Bundle extras = getIntent().getExtras();
if (extras != null) {
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
appUuid = (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID);
WebViewSingleton.runJavascriptInterface((GBDevice) extras.getParcelable(GBDevice.EXTRA_DEVICE), (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID));
} else {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
@ -61,13 +57,13 @@ public class ExternalPebbleJSActivity extends GBActivity {
public void onViewAttachedToWindow(View v) {
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
//show configuration
myWebView.evaluateJavascript("Pebble.evaluate('showConfiguration');", new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
LOG.debug("Callback from showConfiguration: " + s);
}
});
//show configuration - moved to JS
// myWebView.evaluateJavascript("Pebble.evaluate('showConfiguration');", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String s) {
// LOG.debug("Callback from showConfiguration: " + s);
// }
// });
}
@Override
@ -88,7 +84,6 @@ public class ExternalPebbleJSActivity extends GBActivity {
//getting back with configuration data
LOG.debug("WEBVIEW returned config: " + confUri.toString());
try {
appUuid = UUID.fromString(confUri.getHost());
queryString = confUri.getEncodedQuery();
} catch (IllegalArgumentException e) {
GB.toast("returned uri: " + confUri.toString(), Toast.LENGTH_LONG, GB.ERROR);

View File

@ -60,6 +60,7 @@ public class WebViewSingleton {
private static WebView instance = null;
private Activity contextWrapper;
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
private static UUID currentRunningUUID;
private WebViewSingleton() {
}
@ -98,14 +99,21 @@ public class WebViewSingleton {
final JSInterface jsInterface = new JSInterface(device, uuid);
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
@Override
public void run() {
instance.removeJavascriptInterface("GBjs");
instance.addJavascriptInterface(jsInterface, "GBjs");
instance.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
}
});
if (uuid.equals(currentRunningUUID)) {
LOG.debug("WEBVIEW uuid not changed keeping the old context");
} else {
LOG.debug("WEBVIEW uuid changed, restarting");
currentRunningUUID = uuid;
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
@Override
public void run() {
instance.removeJavascriptInterface("GBjs");
instance.addJavascriptInterface(jsInterface, "GBjs");
instance.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
}
});
}
}
public static void appMessage(GBDeviceEventAppMessage message) {
@ -390,7 +398,7 @@ public class WebViewSingleton {
@JavascriptInterface
public void gbLog(String msg) {
LOG.debug("WEBVIEW webpage log", msg);
LOG.debug("WEBVIEW webpage log: " + msg);
}
@JavascriptInterface
@ -562,6 +570,10 @@ public class WebViewSingleton {
return geoPosition.toString();
}
@JavascriptInterface
public void eventFinished(String event) {
LOG.debug("WEBVIEW event finished: " + event);
}
}
}