From 0f2d240402877ff53597830f56e0c7fa0b830e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Wed, 22 Jan 2025 21:37:16 +0000 Subject: [PATCH] SuperCars: Adopt device card custom action --- .../supercars/SuperCarsCoordinator.java | 110 +++++------------- .../main/res/drawable/ic_steering_wheel.xml | 16 +++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 45 insertions(+), 82 deletions(-) create mode 100644 app/src/main/res/drawable/ic_steering_wheel.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java index 5a53dabbb..1400b67d8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/supercars/SuperCarsCoordinator.java @@ -17,38 +17,28 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.supercars; -import android.app.Activity; import android.content.Context; -import android.net.Uri; +import android.content.Intent; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Collections; +import java.util.List; import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; -import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; +import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCardAction; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; -import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; -import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.supercars.SuperCarsSupport; public class SuperCarsCoordinator extends AbstractDeviceCoordinator { - private static final Logger LOG = LoggerFactory.getLogger(SuperCarsCoordinator.class); - @Override protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { - } @Override @@ -61,90 +51,22 @@ public class SuperCarsCoordinator extends AbstractDeviceCoordinator { return BONDING_STYLE_NONE; } - @Override - public int getBatteryCount(final GBDevice device) { - return 1; - } - @NonNull @Override public Class getDeviceSupportClass() { return SuperCarsSupport.class; } - @Override - public Class getAppsManagementActivity() { - return ControlActivity.class; - } - - @Nullable - @Override - public Class getPairingActivity() { - return null; - } - - @Override - public boolean supportsActivityDataFetching() { - return false; - } - - @Override - public boolean supportsActivityTracking() { - return false; - } - - @Override - public SampleProvider getSampleProvider(GBDevice device, DaoSession session) { - return null; - } - - @Override - public InstallHandler findInstallHandler(Uri uri, Context context) { - return null; - } - - @Override - public boolean supportsScreenshots(final GBDevice device) { - return false; - } - - @Override - public int getAlarmSlotCount(GBDevice device) { - return 0; - } - @Override public String getManufacturer() { return "Brand Base"; } - @Override - public boolean supportsAppsManagement(final GBDevice device) { - return true; - } - - @Override - public boolean supportsCalendarEvents() { - return false; - } - - @Override - public boolean supportsRealtimeData() { - return false; - } - - @Override - public boolean supportsFindDevice() { - return false; - } - - @Override public int getDeviceNameResource() { return R.string.devicetype_super_cars; } - @Override public int getDefaultIconResource() { return R.drawable.ic_device_supercars; @@ -154,4 +76,28 @@ public class SuperCarsCoordinator extends AbstractDeviceCoordinator { public int getDisabledIconResource() { return R.drawable.ic_device_supercars_disabled; } + + @Override + public List getCustomActions() { + return Collections.singletonList(new ControlDeviceCardAction()); + } + + private static final class ControlDeviceCardAction implements DeviceCardAction { + @Override + public int getIcon(GBDevice device) { + return R.drawable.ic_steering_wheel; + } + + @Override + public String getDescription(final GBDevice device, final Context context) { + return context.getString(R.string.remote_control); + } + + @Override + public void onClick(final GBDevice device, final Context context) { + final Intent startIntent = new Intent(context, ControlActivity.class); + startIntent.putExtra(GBDevice.EXTRA_DEVICE, device); + context.startActivity(startIntent); + } + } } diff --git a/app/src/main/res/drawable/ic_steering_wheel.xml b/app/src/main/res/drawable/ic_steering_wheel.xml new file mode 100644 index 000000000..91a476132 --- /dev/null +++ b/app/src/main/res/drawable/ic_steering_wheel.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4003616a..ddd6a5396 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -565,6 +565,7 @@ Pending Current Error + Remote control Camera Remote Allows the watch to trigger the phone\'s camera Morning Updates