mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-10-31 06:32:54 +01:00
Pebble background webview: config page should be shown reliably now.
This commit is contained in:
parent
21b90d1e6e
commit
f84c651c38
@ -99,6 +99,7 @@ function gbPebble() {
|
|||||||
for (var i = 0; i < l; i++) {
|
for (var i = 0; i < l; i++) {
|
||||||
evs[i].apply(null, args);
|
evs[i].apply(null, args);
|
||||||
}
|
}
|
||||||
|
GBjs.eventFinished(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actuallyOpenURL = function() {
|
this.actuallyOpenURL = function() {
|
||||||
@ -204,6 +205,14 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
if (jsConfigFile != null) {
|
if (jsConfigFile != null) {
|
||||||
loadScript(jsConfigFile, function() {
|
loadScript(jsConfigFile, function() {
|
||||||
Pebble.evaluate('ready');
|
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') {
|
if (getURLVariable('config') == 'true') {
|
||||||
showStep("step2");
|
showStep("step2");
|
||||||
var json_string = getURLVariable('json');
|
var json_string = getURLVariable('json');
|
||||||
|
@ -8,7 +8,6 @@ import android.support.v4.app.NavUtils;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.JavascriptInterface;
|
import android.webkit.JavascriptInterface;
|
||||||
import android.webkit.ValueCallback;
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -28,9 +27,7 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ExternalPebbleJSActivity.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ExternalPebbleJSActivity.class);
|
||||||
|
|
||||||
private UUID appUuid;
|
|
||||||
private Uri confUri;
|
private Uri confUri;
|
||||||
private GBDevice mGBDevice = null;
|
|
||||||
private WebView myWebView;
|
private WebView myWebView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,8 +36,7 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
|
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
WebViewSingleton.runJavascriptInterface((GBDevice) extras.getParcelable(GBDevice.EXTRA_DEVICE), (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID));
|
||||||
appUuid = (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID);
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
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) {
|
public void onViewAttachedToWindow(View v) {
|
||||||
|
|
||||||
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||||
//show configuration
|
//show configuration - moved to JS
|
||||||
myWebView.evaluateJavascript("Pebble.evaluate('showConfiguration');", new ValueCallback<String>() {
|
// myWebView.evaluateJavascript("Pebble.evaluate('showConfiguration');", new ValueCallback<String>() {
|
||||||
@Override
|
// @Override
|
||||||
public void onReceiveValue(String s) {
|
// public void onReceiveValue(String s) {
|
||||||
LOG.debug("Callback from showConfiguration: " + s);
|
// LOG.debug("Callback from showConfiguration: " + s);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,7 +84,6 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
//getting back with configuration data
|
//getting back with configuration data
|
||||||
LOG.debug("WEBVIEW returned config: " + confUri.toString());
|
LOG.debug("WEBVIEW returned config: " + confUri.toString());
|
||||||
try {
|
try {
|
||||||
appUuid = UUID.fromString(confUri.getHost());
|
|
||||||
queryString = confUri.getEncodedQuery();
|
queryString = confUri.getEncodedQuery();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
GB.toast("returned uri: " + confUri.toString(), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast("returned uri: " + confUri.toString(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
@ -60,6 +60,7 @@ public class WebViewSingleton {
|
|||||||
private static WebView instance = null;
|
private static WebView instance = null;
|
||||||
private Activity contextWrapper;
|
private Activity contextWrapper;
|
||||||
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
|
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
|
||||||
|
private static UUID currentRunningUUID;
|
||||||
|
|
||||||
private WebViewSingleton() {
|
private WebViewSingleton() {
|
||||||
}
|
}
|
||||||
@ -98,14 +99,21 @@ public class WebViewSingleton {
|
|||||||
|
|
||||||
final JSInterface jsInterface = new JSInterface(device, uuid);
|
final JSInterface jsInterface = new JSInterface(device, uuid);
|
||||||
|
|
||||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
if (uuid.equals(currentRunningUUID)) {
|
||||||
@Override
|
LOG.debug("WEBVIEW uuid not changed keeping the old context");
|
||||||
public void run() {
|
} else {
|
||||||
instance.removeJavascriptInterface("GBjs");
|
LOG.debug("WEBVIEW uuid changed, restarting");
|
||||||
instance.addJavascriptInterface(jsInterface, "GBjs");
|
currentRunningUUID = uuid;
|
||||||
instance.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
|
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) {
|
public static void appMessage(GBDeviceEventAppMessage message) {
|
||||||
@ -390,7 +398,7 @@ public class WebViewSingleton {
|
|||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void gbLog(String msg) {
|
public void gbLog(String msg) {
|
||||||
LOG.debug("WEBVIEW webpage log", msg);
|
LOG.debug("WEBVIEW webpage log: " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
@ -562,6 +570,10 @@ public class WebViewSingleton {
|
|||||||
return geoPosition.toString();
|
return geoPosition.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public void eventFinished(String event) {
|
||||||
|
LOG.debug("WEBVIEW event finished: " + event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user