1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 01:09:47 +01:00

Some fixes for the background webview

This commit is contained in:
cpfeiffer 2017-02-25 21:50:05 +01:00
parent 711800f3d0
commit 234beace29
5 changed files with 24 additions and 10 deletions

View File

@ -283,8 +283,7 @@
android:parentActivityName=".activities.ControlCenter" />
<activity
android:name=".activities.BackgroundWebViewActivity"
android:label="@string/activity_web_view"
android:parentActivityName=".activities.ControlCenter" />
android:label="@string/activity_web_view"/>
<activity
android:name=".activities.AndroidPairingActivity"
android:label="@string/title_activity_android_pairing" />

View File

@ -136,7 +136,9 @@ public class GBApplication extends Application {
}
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

View File

@ -2,15 +2,19 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
import android.app.Activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.util.WebViewSingleton;
public class BackgroundWebViewActivity extends Activity {
private static Logger LOG = LoggerFactory.getLogger(BackgroundWebViewActivity.class);
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebViewSingleton.createWebView(this);
setVisible(false);
finish();
}
}

View File

@ -50,6 +50,8 @@ public class ExternalPebbleJSActivity extends GBActivity {
WebViewSingleton.updateActivityContext(this);
myWebView = WebViewSingleton.getWebView();
myWebView.setWillNotDraw(false);
myWebView.removeJavascriptInterface("GBActivity");
myWebView.addJavascriptInterface(new ActivityJSInterface(ExternalPebbleJSActivity.this), "GBActivity");
FrameLayout fl = (FrameLayout) findViewById(R.id.webview_placeholder);
fl.addView(myWebView);
@ -104,7 +106,6 @@ public class ExternalPebbleJSActivity extends GBActivity {
fl.removeAllViews();
}
});
}
@Override

View File

@ -48,7 +48,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class WebViewSingleton extends Activity {
public class WebViewSingleton {
private static final Logger LOG = LoggerFactory.getLogger(WebViewSingleton.class);
@ -154,7 +154,7 @@ public class WebViewSingleton extends Activity {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
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
}
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 {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {