diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index edf7b965e..92c682e79 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -467,6 +467,11 @@ + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java new file mode 100644 index 000000000..0b4cbd00b --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java @@ -0,0 +1,96 @@ +package nodomain.freeyourgadget.gadgetbridge.devices.banglejs; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.PopupMenu; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + +import org.json.JSONArray; + +import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; +import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; +import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; +import nodomain.freeyourgadget.gadgetbridge.util.GB; + +public class AppsManagementActivity extends AbstractGBActivity { + private WebView webView; + private GBDevice mGBDevice; + private DeviceCoordinator mCoordinator; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_banglejs_apps_management); + + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + mGBDevice = bundle.getParcelable(GBDevice.EXTRA_DEVICE); + } else { + throw new IllegalArgumentException("Must provide a device when invoking this activity"); + } + mCoordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice); + + initViews(); + } + + private void toast(String data) { + GB.toast(data, Toast.LENGTH_LONG, GB.INFO); + } + + @Override + protected void onPause() { + super.onPause(); + LocalBroadcastManager.getInstance(this).unregisterReceiver(deviceUpdateReceiver); + finish(); + } + + @Override + protected void onResume() { + super.onResume(); + LocalBroadcastManager.getInstance(this).registerReceiver(deviceUpdateReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED)); + } + + BroadcastReceiver deviceUpdateReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + + } + }; + + private void initViews() { + //https://stackoverflow.com/questions/4325639/android-calling-javascript-functions-in-webview + webView = findViewById(R.id.webview); + webView.setWebViewClient(new WebViewClient()); + webView.getSettings().setJavaScriptEnabled(true); + webView.loadUrl("https://banglejs.com/apps/"); + + webView.setWebViewClient(new WebViewClient(){ + public void onPageFinished(WebView view, String weburl){ + webView.loadUrl("javascript:showToast('WebView in Espruino')"); + } + }); + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java index ad052bf1e..38a1a4b0b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSCoordinator.java @@ -31,6 +31,7 @@ import java.util.Collection; import java.util.Collections; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; @@ -132,21 +133,18 @@ public class BangleJSCoordinator extends AbstractDeviceCoordinator { return true; } - @Override - public boolean supportsAppsManagement() { - return false; - } - @Override public int getAlarmSlotCount() { return 10; } @Override - public Class getAppsManagementActivity() { - return null; - } + public boolean supportsAppsManagement() { return true; } + @Override + public Class getAppsManagementActivity() { + return AppsManagementActivity.class; + } @Override protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) { diff --git a/app/src/main/res/layout/activity_banglejs_apps_management.xml b/app/src/main/res/layout/activity_banglejs_apps_management.xml new file mode 100644 index 000000000..08188a975 --- /dev/null +++ b/app/src/main/res/layout/activity_banglejs_apps_management.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file