mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 00:30:37 +02:00
Pebble background webview: bring back the mutableContextWrapper, otherwise inputs aren't working.
Reliably go back to first step of the configuration page when closing (this causes a Toast when closing the activity while in the clay settings page)
This commit is contained in:
parent
f84c651c38
commit
75d4abc9dc
@ -109,6 +109,7 @@ function gbPebble() {
|
||||
|
||||
this.actuallySendData = function() {
|
||||
GBjs.sendAppMessage(self.configurationValues);
|
||||
showStep("step1");
|
||||
GBActivity.closeActivity();
|
||||
}
|
||||
|
||||
@ -209,6 +210,7 @@ if (jsConfigFile != null) {
|
||||
Pebble.evaluate('showConfiguration');
|
||||
} else {
|
||||
window.onfocus = function () {
|
||||
showStep("step1");
|
||||
GBjs.gbLog("window focused!!!");
|
||||
Pebble.evaluate('showConfiguration');
|
||||
};
|
||||
|
@ -8,6 +8,7 @@ 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;
|
||||
@ -70,6 +71,12 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
||||
public void onViewDetachedFromWindow(View v) {
|
||||
myWebView.removeJavascriptInterface("GBActivity");
|
||||
myWebView.setWillNotDraw(true);
|
||||
myWebView.evaluateJavascript("showStep('step1')", new ValueCallback<String>() {
|
||||
@Override
|
||||
public void onReceiveValue(String s) {
|
||||
LOG.debug("Callback from window detach: " + s);
|
||||
}
|
||||
});
|
||||
FrameLayout fl = (FrameLayout) findViewById(R.id.webview_placeholder);
|
||||
fl.removeAllViews();
|
||||
}
|
||||
|
@ -4,12 +4,15 @@ import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.MutableContextWrapper;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.webkit.ConsoleMessage;
|
||||
@ -58,7 +61,8 @@ public class WebViewSingleton {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
|
||||
|
||||
private static WebView instance = null;
|
||||
private Activity contextWrapper;
|
||||
private MutableContextWrapper contextWrapper;
|
||||
private Looper mainLooper;
|
||||
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
|
||||
private static UUID currentRunningUUID;
|
||||
|
||||
@ -67,8 +71,9 @@ public class WebViewSingleton {
|
||||
|
||||
public static synchronized WebView createWebView(Activity context) {
|
||||
if (instance == null) {
|
||||
webViewSingleton.contextWrapper = context;
|
||||
instance = new WebView(context);
|
||||
webViewSingleton.contextWrapper = new MutableContextWrapper(context);
|
||||
webViewSingleton.mainLooper = context.getMainLooper();
|
||||
instance = new WebView(webViewSingleton.contextWrapper);
|
||||
instance.setWillNotDraw(true);
|
||||
instance.clearCache(true);
|
||||
instance.setWebViewClient(new GBWebClient());
|
||||
@ -86,7 +91,7 @@ public class WebViewSingleton {
|
||||
|
||||
public static void updateActivityContext(Activity context) {
|
||||
if (context instanceof Activity) {
|
||||
webViewSingleton.contextWrapper = context;
|
||||
webViewSingleton.contextWrapper.setBaseContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +109,7 @@ public class WebViewSingleton {
|
||||
} else {
|
||||
LOG.debug("WEBVIEW uuid changed, restarting");
|
||||
currentRunningUUID = uuid;
|
||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
||||
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.removeJavascriptInterface("GBjs");
|
||||
@ -125,8 +130,7 @@ public class WebViewSingleton {
|
||||
|
||||
final String appMessage = parseIncomingAppMessage(message.message, message.appUUID);
|
||||
LOG.debug("to WEBVIEW: " + appMessage);
|
||||
|
||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
||||
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.evaluateJavascript("Pebble.evaluate('appmessage',[" + appMessage + "]);", new ValueCallback<String>() {
|
||||
@ -141,7 +145,7 @@ public class WebViewSingleton {
|
||||
}
|
||||
|
||||
public static void disposeWebView() {
|
||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
||||
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (instance != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user