Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Tasker Plugin #1435

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<uses-permission android:name="cyanogenmod.permission.ACCESS_WEATHER_MANAGER" />
<uses-permission android:name="cyanogenmod.permission.READ_WEATHER" />
<uses-permission android:name="org.omnirom.omnijaws.READ_WEATHER" />
<uses-permission android:name="net.dinglisch.android.tasker.PERMISSION_RUN_TASKS" />

<uses-feature
android:name="android.hardware.bluetooth"
Expand All @@ -41,8 +42,8 @@
android:allowBackup="false"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/GadgetbridgeTheme">
<activity
android:name=".activities.ControlCenterv2"
Expand All @@ -67,9 +68,9 @@
android:label="@string/activity_summaries"
android:parentActivityName=".activities.ControlCenterv2" />
<activity
android:launchMode="singleTop"
android:name=".activities.appmanager.AppManagerActivity"
android:label="@string/title_activity_appmanager"
android:launchMode="singleTop"
android:parentActivityName=".activities.ControlCenterv2" />
<activity
android:name=".activities.AppBlacklistActivity"
Expand Down Expand Up @@ -320,11 +321,12 @@

<activity android:name=".externalevents.WeatherNotificationConfig">
<intent-filter>
<action android:name="ru.gelin.android.weather.notification.ACTION_WEATHER_SKIN_PREFERENCES"/>
<action android:name="ru.gelin.android.weather.notification.ACTION_WEATHER_SKIN_PREFERENCES" />
</intent-filter>
</activity>

<receiver android:name=".externalevents.AutoStartReceiver"
<receiver
android:name=".externalevents.AutoStartReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
Expand Down Expand Up @@ -354,8 +356,8 @@
</intent-filter>
</receiver>
<receiver
android:enabled="true"
android:name="nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter"
android:enabled="true"
android:exported="false">

</receiver>
Expand Down Expand Up @@ -391,10 +393,10 @@
android:label="@string/title_activity_pebble_pairing" />
<activity
android:name=".devices.watch9.Watch9PairingActivity"
android:label="@string/title_activity_watch9_pairing" />
android:label="@string/title_activity_watch9_pairing" />
<activity
android:name=".devices.watch9.Watch9CalibrationActivity"
android:label="@string/title_activity_watch9_calibration" />
android:label="@string/title_activity_watch9_calibration" />
<activity
android:name=".activities.charts.ChartsActivity"
android:label="@string/title_activity_charts"
Expand All @@ -420,6 +422,17 @@
<activity
android:name=".activities.FindPhoneActivity"
android:label="Find Phone" />
<activity
android:name=".tasker.settings.activities.TaskerActivity"
android:label="@string/tasker" />
<activity
android:name=".tasker.settings.activities.TaskerEventActivity"
android:label="@string/tasker"
android:parentActivityName=".tasker.settings.activities.TaskerEventsActivity" />
<activity
android:name=".tasker.settings.activities.TaskerEventsActivity"
android:label="@string/tasker"
android:parentActivityName=".tasker.settings.activities.TaskerActivity" />

<provider
android:name=".contentprovider.PebbleContentProvider"
Expand Down Expand Up @@ -448,19 +461,21 @@
</receiver>

<activity
android:launchMode="singleTask"
android:name=".activities.ExternalPebbleJSActivity"
android:allowTaskReparenting="true"
android:clearTaskOnLaunch="true"
android:name=".activities.ExternalPebbleJSActivity"
android:label="@string/app_configure"
android:launchMode="singleTask"
android:parentActivityName=".activities.appmanager.AppManagerActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2" />
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="gadgetbridge" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerConstants;
import nodomain.freeyourgadget.gadgetbridge.tasker.settings.activities.TaskerActivity;
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
Expand Down Expand Up @@ -292,16 +294,16 @@ public boolean onPreferenceClick(Preference preference) {

pref = findPreference("weather_city");
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
// reset city id and force a new lookup
GBApplication.getPrefs().getPreferences().edit().putString("weather_cityid", null).apply();
preference.setSummary(newVal.toString());
Intent intent = new Intent("GB_UPDATE_WEATHER");
intent.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intent);
return true;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
// reset city id and force a new lookup
GBApplication.getPrefs().getPreferences().edit().putString("weather_cityid", null).apply();
preference.setSummary(newVal.toString());
Intent intent = new Intent("GB_UPDATE_WEATHER");
intent.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intent);
return true;
}
});

pref = findPreference(GBPrefs.AUTO_EXPORT_LOCATION);
Expand Down Expand Up @@ -557,6 +559,16 @@ public void run() {
}
});

findPreference(TaskerConstants.ACTIVITY_TASKER).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent enableIntent = new Intent(SettingsActivity.this, TaskerActivity.class);
startActivity(enableIntent);
return true;
}
});


// Get all receivers of Media Buttons
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

Expand Down Expand Up @@ -702,4 +714,4 @@ private void setLocationPreferences(Location location) {
pref_latitude.setSummary(latitude);
pref_longitude.setSummary(longitude);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nodomain.freeyourgadget.gadgetbridge.devices.xwatch;

public class XWatchConstants {

public static class Tasker {
public static final String TASKER_ACTIVE = "tasker_active";
public static final String TASKER_TASK_SINGLE = "tasker_task_single";
public static final String TASKER_TASK_DOUBLE = "tasker_task_double";
public static final String TASKER_TASK_TRIPLE = "tasker_task_triple";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public static String lookup(UUID uuid, String fallback) {
}
return name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package nodomain.freeyourgadget.gadgetbridge.devices.xwatch;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;

import java.util.Arrays;
import java.util.List;

import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.tasker.event.TaskerEventType;
import nodomain.freeyourgadget.gadgetbridge.tasker.spec.AbstractTaskerSpec;

public class XWatchTaskerSpec extends AbstractTaskerSpec {

public XWatchTaskerSpec(DeviceType device) {
super(device);
}

@Override
public TaskerEventType getEventType(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
if (XWatchService.UUID_NOTIFY.equals(characteristic.getUuid())) {
byte[] data = characteristic.getValue();
if (data[0] == XWatchService.COMMAND_ACTIVITY_DATA) {
return TaskerEventType.DATA;
}
if (data[0] == XWatchService.COMMAND_ACTION_BUTTON) {
return TaskerEventType.BUTTON;
}
if (data[0] == XWatchService.COMMAND_CONNECTED) {
return TaskerEventType.CONNECTION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that such events would rather be handled generically via GBDevice#getState() changes (see GBDevice#sendDeviceUpdateEvent()).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AbstractDeviceSupport#handleGBDeviceEvent() methods are probably also good candidates for a generic implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me more info on that.

}
}
return TaskerEventType.NO_OP;
}

@Override
public List<TaskerEventType> getSupportedTypes() {
return Arrays.asList(TaskerEventType.BUTTON, TaskerEventType.DATA, TaskerEventType.CONNECTION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.media.AudioManager;
import android.net.Uri;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

Expand Down Expand Up @@ -58,6 +59,9 @@
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerBleProfile;
import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerConstants;
import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerDevice;
import nodomain.freeyourgadget.gadgetbridge.util.GB;

public class XWatchSupport extends AbstractBTLEDeviceSupport {
Expand All @@ -71,10 +75,10 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {

public XWatchSupport() {
super(LOG);

addSupportedService(XWatchService.UUID_SERVICE);
addSupportedService(XWatchService.UUID_WRITE);
addSupportedService(XWatchService.UUID_NOTIFY);
addSupportedProfile(new TaskerBleProfile<>(this, TaskerDevice.XWATCH));
}

public static byte[] crcChecksum(byte[] data) {
Expand Down Expand Up @@ -190,10 +194,12 @@ public void onDeleteCalendarEvent(byte type, long id) {
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
//TODO: Implement
System.out.println("A");
}

@Override
public void onNotification(NotificationSpec notificationSpec) {
System.out.println("YO");
//TODO: Implement
}

Expand Down Expand Up @@ -260,7 +266,7 @@ public void onSetConstantVibration(int intensity) {
@Override
public void onFetchRecordedData(int dataTypes) {
try {
if(builder == null) {
if (builder == null) {
builder = performInitialized("fetchActivityData");
}
requestSummarizedData(builder);
Expand Down Expand Up @@ -309,7 +315,7 @@ public void onScreenshotReq() {
public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);

Log.d("BLE", "V: " + characteristic.getValue().toString());
UUID characteristicUUID = characteristic.getUuid();
if (XWatchService.UUID_NOTIFY.equals(characteristicUUID)) {
byte[] data = characteristic.getValue();
Expand Down Expand Up @@ -451,7 +457,7 @@ private void handleDetailedData(byte[] value) {

if (value[5] == 95) {
dayToFetch++;
if(dayToFetch <= maxDayToFetch) {
if (dayToFetch <= maxDayToFetch) {
try {
builder = performInitialized("fetchActivityData");
requestDetailedData(builder);
Expand All @@ -469,9 +475,10 @@ private void handleDetailedData(byte[] value) {

private void handleButtonPressed(byte[] value) {
long currentTimestamp = System.currentTimeMillis();
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager.isWiredHeadsetOn())

AudioManager audioManager = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
if(audioManager.isWiredHeadsetOn()) {
{
if (currentTimestamp - lastButtonTimestamp < 1000) {
if (audioManager.isMusicActive()) {
audioManager.dispatchMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
Expand All @@ -487,7 +494,6 @@ private void handleButtonPressed(byte[] value) {
audioManager.dispatchMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
}
}

lastButtonTimestamp = currentTimestamp;
}

Expand Down Expand Up @@ -565,7 +571,7 @@ private int getTimestampFromData(byte year, byte month, byte day, byte hoursminu
minutes
);

timestamp = (int)(cal.getTimeInMillis() / 1000);
timestamp = (int) (cal.getTimeInMillis() / 1000);

return timestamp;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package nodomain.freeyourgadget.gadgetbridge.tasker.event;

import nodomain.freeyourgadget.gadgetbridge.tasker.settings.TaskerSettings;

/**
* Tasker event that gets thrown if its corresponding {@link TaskerSettings#isEnabled()} is true.
* <p>
* Provides {@link TaskerEventType} and a count.
* <p>
* Count resets itself after {@link TaskerSettings#getThreshold()} is expired.
*/
public class TaskerEvent {

private TaskerEventType type;
private int count;

public TaskerEvent(TaskerEventType type, int count) {
this.type = type;
this.count = count;
}

/**
* Tasker event type of this event.
*
* @return
*/
public TaskerEventType getType() {
return type;
}

public void setType(TaskerEventType type) {
this.type = type;
}

/**
* Count how often this event is thrown in the {@link TaskerSettings#getThreshold()}
*
* @return Fired times
*/
public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}
Loading