From 7e736a449c2a4193036bad4ab5edf9009864dfd9 Mon Sep 17 00:00:00 2001 From: nightoftune Date: Sun, 3 Mar 2019 17:41:39 +0100 Subject: [PATCH] Changed to GB.toast, fixed equals and added constructors to TaskerEventType. --- .../service/devices/xwatch/XWatchSupport.java | 2 + .../tasker/event/TaskerEventType.java | 41 +++++++++---------- .../tasker/service/TaskerUtil.java | 9 ++-- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java index 828c44f59..4c396c18f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java @@ -194,10 +194,12 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport { @Override public void onSetAlarms(ArrayList alarms) { //TODO: Implement + System.out.println("A"); } @Override public void onNotification(NotificationSpec notificationSpec) { + System.out.println("YO"); //TODO: Implement } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/event/TaskerEventType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/event/TaskerEventType.java index 390699d6b..26bbcceb2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/event/TaskerEventType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/event/TaskerEventType.java @@ -10,42 +10,41 @@ import nodomain.freeyourgadget.gadgetbridge.R; /** * Default set of tasker events. *

- * Extend here if you want to add more events. Use {@link TaskerEventType#create(String)} - * and configure {@link TaskerEventType#withLocalization(int)} for {@link nodomain.freeyourgadget.gadgetbridge.tasker.settings.activities.TaskerEventsActivity} + * Extend here if you want to add more events. Use {@link TaskerEventType#(String, int)} if you want to use the event together with + * {@link nodomain.freeyourgadget.gadgetbridge.tasker.settings.activities.TaskerEventsActivity}. *

* Don't forget to add the new event to {@link #getTypes()} method. */ public class TaskerEventType implements Serializable { - public static TaskerEventType BUTTON = TaskerEventType.create("button").withLocalization(R.string.tasker_event_button); - public static TaskerEventType CONNECTION = TaskerEventType.create("connection").withLocalization(R.string.tasker_event_connection); - public static TaskerEventType DATA = TaskerEventType.create("data").withLocalization(R.string.tasker_event_data); - public static TaskerEventType NO_OP = TaskerEventType.create("no-op"); + public static TaskerEventType BUTTON = new TaskerEventType("button", R.string.tasker_event_button); + public static TaskerEventType CONNECTION = new TaskerEventType("connection", R.string.tasker_event_connection); + public static TaskerEventType DATA = new TaskerEventType("data", R.string.tasker_event_data); + public static TaskerEventType NO_OP = new TaskerEventType("no-op"); private String type; private int index; private int localization; - private TaskerEventType() { + public TaskerEventType(String type) { + this.type = type; + this.index = 1; } - public TaskerEventType withLocalization(int localization) { + public TaskerEventType(String type, int localization) { + this(type); this.localization = localization; - return this; - } - - public static TaskerEventType create(String type) { - TaskerEventType taskerEventType = new TaskerEventType(); - taskerEventType.index = 1; - taskerEventType.type = type; - return taskerEventType; } + /** + * Scopes the event with an index. I.e. for two buttons. + * + * @param index Event index + * @return Scoped {@link TaskerEventType} + */ public TaskerEventType withIndex(int index) { - TaskerEventType taskerEventType = new TaskerEventType(); - taskerEventType.type = this.type; - taskerEventType.index = index; - taskerEventType.localization = this.localization; + TaskerEventType taskerEventType = new TaskerEventType(type, localization); + taskerEventType.index = this.index; return taskerEventType; } @@ -68,7 +67,7 @@ public class TaskerEventType implements Serializable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !getClass().isAssignableFrom(o.getClass())) return false; TaskerEventType that = (TaskerEventType) o; return index == that.index && Objects.equals(type, that.type); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/service/TaskerUtil.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/service/TaskerUtil.java index c98adf12e..5b7e7d087 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/service/TaskerUtil.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/tasker/service/TaskerUtil.java @@ -1,5 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.tasker.service; +import android.content.res.Resources; import android.os.Handler; import android.os.Looper; import android.widget.Toast; @@ -7,6 +8,7 @@ import android.widget.Toast; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerIntent; +import nodomain.freeyourgadget.gadgetbridge.util.GB; /** * Tasker convenience methods for direct access to tasker without {@link TaskerService}. @@ -37,12 +39,7 @@ public class TaskerUtil { * Creates a {@link android.widget.Toast} for the user to show that Tasker is enabled but no task is defined. */ public static void noTaskDefinedInformation() { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - Toast.makeText(GBApplication.getContext(), R.string.tasker_no_task_defined, Toast.LENGTH_LONG).show(); - } - }); + GB.toast(Resources.getSystem().getString(R.string.tasker_no_task_defined), Toast.LENGTH_LONG, GB.INFO); } }