mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
Some fixes for the background webview
This commit is contained in:
parent
711800f3d0
commit
234beace29
@ -283,8 +283,7 @@
|
|||||||
android:parentActivityName=".activities.ControlCenter" />
|
android:parentActivityName=".activities.ControlCenter" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.BackgroundWebViewActivity"
|
android:name=".activities.BackgroundWebViewActivity"
|
||||||
android:label="@string/activity_web_view"
|
android:label="@string/activity_web_view"/>
|
||||||
android:parentActivityName=".activities.ControlCenter" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.AndroidPairingActivity"
|
android:name=".activities.AndroidPairingActivity"
|
||||||
android:label="@string/title_activity_android_pairing" />
|
android:label="@string/title_activity_android_pairing" />
|
||||||
|
@ -136,7 +136,9 @@ public class GBApplication extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createWebViewActivity() {
|
private void createWebViewActivity() {
|
||||||
startActivity(new Intent(getContext(), BackgroundWebViewActivity.class));
|
Intent intent = new Intent(getContext(), BackgroundWebViewActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,15 +2,19 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.WebViewSingleton;
|
import nodomain.freeyourgadget.gadgetbridge.util.WebViewSingleton;
|
||||||
|
|
||||||
public class BackgroundWebViewActivity extends Activity {
|
public class BackgroundWebViewActivity extends Activity {
|
||||||
|
private static Logger LOG = LoggerFactory.getLogger(BackgroundWebViewActivity.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState, persistentState);
|
super.onCreate(savedInstanceState);
|
||||||
WebViewSingleton.createWebView(this);
|
WebViewSingleton.createWebView(this);
|
||||||
setVisible(false);
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,8 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
|
|
||||||
WebViewSingleton.updateActivityContext(this);
|
WebViewSingleton.updateActivityContext(this);
|
||||||
myWebView = WebViewSingleton.getWebView();
|
myWebView = WebViewSingleton.getWebView();
|
||||||
|
myWebView.setWillNotDraw(false);
|
||||||
|
myWebView.removeJavascriptInterface("GBActivity");
|
||||||
myWebView.addJavascriptInterface(new ActivityJSInterface(ExternalPebbleJSActivity.this), "GBActivity");
|
myWebView.addJavascriptInterface(new ActivityJSInterface(ExternalPebbleJSActivity.this), "GBActivity");
|
||||||
FrameLayout fl = (FrameLayout) findViewById(R.id.webview_placeholder);
|
FrameLayout fl = (FrameLayout) findViewById(R.id.webview_placeholder);
|
||||||
fl.addView(myWebView);
|
fl.addView(myWebView);
|
||||||
@ -104,7 +106,6 @@ public class ExternalPebbleJSActivity extends GBActivity {
|
|||||||
fl.removeAllViews();
|
fl.removeAllViews();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,7 +48,7 @@ import java.util.UUID;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
public class WebViewSingleton extends Activity {
|
public class WebViewSingleton {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public class WebViewSingleton extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||||
if (ConsoleMessage.MessageLevel.ERROR.equals(consoleMessage.messageLevel())) {
|
if (ConsoleMessage.MessageLevel.ERROR.equals(consoleMessage.messageLevel())) {
|
||||||
GB.toast(consoleMessage.message(), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(formatConsoleMessage(consoleMessage), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
//TODO: show error page
|
//TODO: show error page
|
||||||
}
|
}
|
||||||
return super.onConsoleMessage(consoleMessage);
|
return super.onConsoleMessage(consoleMessage);
|
||||||
@ -162,6 +162,14 @@ public class WebViewSingleton extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String formatConsoleMessage(ConsoleMessage message) {
|
||||||
|
String sourceId = message.sourceId();
|
||||||
|
if (sourceId == null || sourceId.length() == 0) {
|
||||||
|
sourceId = "unknown";
|
||||||
|
}
|
||||||
|
return String.format("%s (at %s: %d)", message.message(), sourceId, message.lineNumber());
|
||||||
|
}
|
||||||
|
|
||||||
private static class GBWebClient extends WebViewClient {
|
private static class GBWebClient extends WebViewClient {
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user