mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-08 07:28:32 +02:00
Only start the webview when needed
This commit is contained in:
parent
0038ddabdb
commit
53dbc54041
@ -37,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
@ -136,9 +137,11 @@ public class GBApplication extends Application {
|
||||
}
|
||||
|
||||
private void createWebViewActivity() {
|
||||
Intent intent = new Intent(getContext(), BackgroundWebViewActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
if (DeviceHelper.getInstance().needsBackgroundWebView(this)) {
|
||||
Intent intent = new Intent(getContext(), BackgroundWebViewActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,14 +3,9 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -103,4 +103,9 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsBackgroundWebView(GBDevice device) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -186,4 +186,12 @@ public interface DeviceCoordinator {
|
||||
* @return
|
||||
*/
|
||||
Class<? extends Activity> getAppsManagementActivity();
|
||||
|
||||
/**
|
||||
* Returns true if the given device needs a background webview for
|
||||
* executing javascript or configuration, for example.
|
||||
*
|
||||
* @param device
|
||||
*/
|
||||
boolean needsBackgroundWebView(GBDevice device);
|
||||
}
|
||||
|
@ -137,4 +137,9 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||
public Class<? extends Activity> getAppsManagementActivity() {
|
||||
return AppManagerActivity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsBackgroundWebView(GBDevice device) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -255,4 +255,20 @@ public class DeviceHelper {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the background webview for executing javascript is needed
|
||||
* for any of the known/available devices.
|
||||
* @param context
|
||||
*/
|
||||
public boolean needsBackgroundWebView(Context context) {
|
||||
Set<GBDevice> availableDevices = getAvailableDevices(context);
|
||||
for (GBDevice device : availableDevices) {
|
||||
DeviceCoordinator coordinator = getCoordinator(device);
|
||||
if (coordinator.needsBackgroundWebView(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user