mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 03:07:32 +01: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() {
|
this.actuallySendData = function() {
|
||||||
GBjs.sendAppMessage(self.configurationValues);
|
GBjs.sendAppMessage(self.configurationValues);
|
||||||
|
showStep("step1");
|
||||||
GBActivity.closeActivity();
|
GBActivity.closeActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +210,7 @@ if (jsConfigFile != null) {
|
|||||||
Pebble.evaluate('showConfiguration');
|
Pebble.evaluate('showConfiguration');
|
||||||
} else {
|
} else {
|
||||||
window.onfocus = function () {
|
window.onfocus = function () {
|
||||||
|
showStep("step1");
|
||||||
GBjs.gbLog("window focused!!!");
|
GBjs.gbLog("window focused!!!");
|
||||||
Pebble.evaluate('showConfiguration');
|
Pebble.evaluate('showConfiguration');
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,7 @@ 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;
|
||||||
@ -70,6 +71,12 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
public void onViewDetachedFromWindow(View v) {
|
public void onViewDetachedFromWindow(View v) {
|
||||||
myWebView.removeJavascriptInterface("GBActivity");
|
myWebView.removeJavascriptInterface("GBActivity");
|
||||||
myWebView.setWillNotDraw(true);
|
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);
|
FrameLayout fl = (FrameLayout) findViewById(R.id.webview_placeholder);
|
||||||
fl.removeAllViews();
|
fl.removeAllViews();
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,15 @@ import android.Manifest;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.MutableContextWrapper;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.location.Criteria;
|
import android.location.Criteria;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
@ -58,7 +61,8 @@ public class WebViewSingleton {
|
|||||||
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
|
||||||
|
|
||||||
private static WebView instance = null;
|
private static WebView instance = null;
|
||||||
private Activity contextWrapper;
|
private MutableContextWrapper contextWrapper;
|
||||||
|
private Looper mainLooper;
|
||||||
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
|
private static WebViewSingleton webViewSingleton = new WebViewSingleton();
|
||||||
private static UUID currentRunningUUID;
|
private static UUID currentRunningUUID;
|
||||||
|
|
||||||
@ -67,8 +71,9 @@ public class WebViewSingleton {
|
|||||||
|
|
||||||
public static synchronized WebView createWebView(Activity context) {
|
public static synchronized WebView createWebView(Activity context) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
webViewSingleton.contextWrapper = context;
|
webViewSingleton.contextWrapper = new MutableContextWrapper(context);
|
||||||
instance = new WebView(context);
|
webViewSingleton.mainLooper = context.getMainLooper();
|
||||||
|
instance = new WebView(webViewSingleton.contextWrapper);
|
||||||
instance.setWillNotDraw(true);
|
instance.setWillNotDraw(true);
|
||||||
instance.clearCache(true);
|
instance.clearCache(true);
|
||||||
instance.setWebViewClient(new GBWebClient());
|
instance.setWebViewClient(new GBWebClient());
|
||||||
@ -86,7 +91,7 @@ public class WebViewSingleton {
|
|||||||
|
|
||||||
public static void updateActivityContext(Activity context) {
|
public static void updateActivityContext(Activity context) {
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
webViewSingleton.contextWrapper = context;
|
webViewSingleton.contextWrapper.setBaseContext(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +109,7 @@ public class WebViewSingleton {
|
|||||||
} else {
|
} else {
|
||||||
LOG.debug("WEBVIEW uuid changed, restarting");
|
LOG.debug("WEBVIEW uuid changed, restarting");
|
||||||
currentRunningUUID = uuid;
|
currentRunningUUID = uuid;
|
||||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
instance.removeJavascriptInterface("GBjs");
|
instance.removeJavascriptInterface("GBjs");
|
||||||
@ -125,8 +130,7 @@ public class WebViewSingleton {
|
|||||||
|
|
||||||
final String appMessage = parseIncomingAppMessage(message.message, message.appUUID);
|
final String appMessage = parseIncomingAppMessage(message.message, message.appUUID);
|
||||||
LOG.debug("to WEBVIEW: " + appMessage);
|
LOG.debug("to WEBVIEW: " + appMessage);
|
||||||
|
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
instance.evaluateJavascript("Pebble.evaluate('appmessage',[" + appMessage + "]);", new ValueCallback<String>() {
|
instance.evaluateJavascript("Pebble.evaluate('appmessage',[" + appMessage + "]);", new ValueCallback<String>() {
|
||||||
@ -141,7 +145,7 @@ public class WebViewSingleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void disposeWebView() {
|
public static void disposeWebView() {
|
||||||
webViewSingleton.contextWrapper.runOnUiThread(new Runnable() {
|
new Handler(webViewSingleton.mainLooper).post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user