mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
changed parameter from byte to enum
This commit is contained in:
parent
b7277f02a6
commit
a2060470f8
@ -9,11 +9,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Pla
|
||||
public class PackageConfig implements Serializable {
|
||||
private short min, hour;
|
||||
private String packageName, appName;
|
||||
private int vibration;
|
||||
private PlayNotificationRequest.VibrationType vibration;
|
||||
private boolean respectSilentMode;
|
||||
private long id = -1;
|
||||
|
||||
PackageConfig(short min, short hour, String packageName, String appName, boolean respectSilentMode, int vibration) {
|
||||
PackageConfig(short min, short hour, String packageName, String appName, boolean respectSilentMode, PlayNotificationRequest.VibrationType vibration) {
|
||||
this.min = min;
|
||||
this.hour = hour;
|
||||
this.packageName = packageName;
|
||||
@ -22,7 +22,7 @@ public class PackageConfig implements Serializable {
|
||||
this.vibration = vibration;
|
||||
}
|
||||
|
||||
PackageConfig(short min, short hour, String packageName, String appName, boolean respectSilentMode, int vibration, long id) {
|
||||
PackageConfig(short min, short hour, String packageName, String appName, boolean respectSilentMode, PlayNotificationRequest.VibrationType vibration, long id) {
|
||||
this.min = min;
|
||||
this.hour = hour;
|
||||
this.packageName = packageName;
|
||||
@ -37,15 +37,15 @@ public class PackageConfig implements Serializable {
|
||||
this.packageName = packageName;
|
||||
this.appName = appName;
|
||||
this.respectSilentMode = false;
|
||||
this.vibration = PlayNotificationRequest.VibrationType.SINGLE_NORMAL.getValue();
|
||||
this.vibration = PlayNotificationRequest.VibrationType.SINGLE_NORMAL;
|
||||
this.id = -1;
|
||||
}
|
||||
|
||||
public int getVibration() {
|
||||
public PlayNotificationRequest.VibrationType getVibration() {
|
||||
return vibration;
|
||||
}
|
||||
|
||||
public void setVibration(int vibration) {
|
||||
public void setVibration(PlayNotificationRequest.VibrationType vibration) {
|
||||
this.vibration = vibration;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import android.util.Log;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.PlayNotificationRequest;
|
||||
|
||||
public class PackageConfigHelper extends DBOpenHelper {
|
||||
public static final String DB_NAME = "qhybridNotifications.db";
|
||||
@ -36,7 +37,7 @@ public class PackageConfigHelper extends DBOpenHelper {
|
||||
values.put(DB_APPNAME, settings.getAppName());
|
||||
values.put(DB_HOUR, settings.getHour());
|
||||
values.put(DB_MINUTE, settings.getMin());
|
||||
values.put(DB_VIBRATION, settings.getVibration());
|
||||
values.put(DB_VIBRATION, settings.getVibration().getValue());
|
||||
values.put(DB_RESPECT_SILENT, settings.getRespectSilentMode());
|
||||
|
||||
if(settings.getId() == -1) {
|
||||
@ -67,7 +68,7 @@ public class PackageConfigHelper extends DBOpenHelper {
|
||||
cursor.getString(packageNamePos),
|
||||
cursor.getString(appNamePos),
|
||||
cursor.getInt(silentPos) == 1,
|
||||
cursor.getInt(vibrationPos),
|
||||
PlayNotificationRequest.VibrationType.fromValue((byte)cursor.getInt(vibrationPos)),
|
||||
cursor.getInt(idPos)
|
||||
));
|
||||
Log.d("Settings", "setting #" + cursor.getPosition() + ": " + cursor.getInt(silentPos));
|
||||
@ -91,7 +92,7 @@ public class PackageConfigHelper extends DBOpenHelper {
|
||||
c.getString(c.getColumnIndex(DB_PACKAGE)),
|
||||
c.getString(c.getColumnIndex(DB_APPNAME)),
|
||||
c.getInt(c.getColumnIndex(DB_RESPECT_SILENT)) == 1,
|
||||
c.getInt(c.getColumnIndex(DB_VIBRATION)),
|
||||
PlayNotificationRequest.VibrationType.fromValue((byte)c.getInt(c.getColumnIndex(DB_VIBRATION))),
|
||||
c.getInt(c.getColumnIndex(DB_ID))
|
||||
);
|
||||
c.close();
|
||||
|
@ -29,7 +29,7 @@ public class TaskerPluginActivity extends AbstractPluginActivity {
|
||||
group = findViewById(R.id.qhybrid_tasker_vibration);
|
||||
for(PlayNotificationRequest.VibrationType type : PlayNotificationRequest.VibrationType.values()){
|
||||
RadioButton button = new RadioButton(this);
|
||||
button.setText(type.name() + " (" + type.getValue() + ")");
|
||||
button.setText(type.name() + " (" + type.name() + ")");
|
||||
button.setId(type.getValue());
|
||||
group.addView(button);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.PlayNotificationRequest;
|
||||
|
||||
public class TaskerPluginReceiver extends BroadcastReceiver {
|
||||
|
||||
@ -18,7 +19,14 @@ public class TaskerPluginReceiver extends BroadcastReceiver {
|
||||
int minDegrees = (int)Float.parseFloat(min);
|
||||
int hourDegrees = (int)Float.parseFloat(hour);
|
||||
|
||||
PackageConfig config = new PackageConfig((short)minDegrees, (short)hourDegrees, null, null, false, Integer.parseInt(vibration));
|
||||
PackageConfig config = new PackageConfig(
|
||||
(short)minDegrees,
|
||||
(short)hourDegrees,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
PlayNotificationRequest.VibrationType.fromValue(Byte.parseByte(vibration))
|
||||
);
|
||||
|
||||
Intent send = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
|
||||
send.putExtra("CONFIG", config);
|
||||
|
@ -99,11 +99,11 @@ public class TimePicker extends AlertDialog.Builder {
|
||||
group.addView(button);
|
||||
}
|
||||
|
||||
group.check(settings.getVibration());
|
||||
group.check(settings.getVibration().getValue());
|
||||
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup radioGroup, int i) {
|
||||
settings.setVibration(i);
|
||||
settings.setVibration(PlayNotificationRequest.VibrationType.fromValue((byte)i));
|
||||
if(TimePicker.this.vibrationListener != null) TimePicker.this.vibrationListener.onVibrationSet(settings);
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class PlayNotificationRequest extends Request {
|
||||
|
||||
@ -14,23 +15,31 @@ public class PlayNotificationRequest extends Request {
|
||||
SINGLE_LONG(8),
|
||||
NO_VIBE(9);
|
||||
|
||||
public byte value;
|
||||
private byte value;
|
||||
|
||||
VibrationType(int value) {
|
||||
this.value = (byte)value;
|
||||
}
|
||||
|
||||
public static VibrationType fromValue(byte value){
|
||||
for(VibrationType type : values()){
|
||||
if(type.getValue() == value) return type;
|
||||
}
|
||||
throw new InvalidParameterException("vibration Type not supported");
|
||||
}
|
||||
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public PlayNotificationRequest(int vibrationType, int degreesHour, int degreesMins){
|
||||
public PlayNotificationRequest(VibrationType vibrationType, int degreesHour, int degreesMins, int degreesActivityHand){
|
||||
int length = 0;
|
||||
if(degreesHour > -1) length++;
|
||||
if(degreesMins > -1) length++;
|
||||
if(degreesActivityHand > -1) length++;
|
||||
ByteBuffer buffer = createBuffer(length * 2 + 10);
|
||||
buffer.put((byte)vibrationType);
|
||||
buffer.put(vibrationType.getValue());
|
||||
buffer.put((byte)5);
|
||||
buffer.put((byte)(length * 2 + 2));
|
||||
buffer.putShort((short)0);
|
||||
@ -40,9 +49,18 @@ public class PlayNotificationRequest extends Request {
|
||||
if(degreesMins > -1){
|
||||
buffer.putShort((short)((degreesMins % 360) | (2 << 12)));
|
||||
}
|
||||
if(degreesActivityHand > -1) {
|
||||
buffer.putShort((short)((degreesActivityHand % 360) | (3 << 12)));
|
||||
}
|
||||
this.data = buffer.array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public PlayNotificationRequest(VibrationType vibrationType, int degreesHour, int degreesMins){
|
||||
this(vibrationType, degreesHour, degreesMins, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getStartSequence() {
|
||||
return new byte[]{2, 7, 15, 10, 1};
|
||||
|
Loading…
Reference in New Issue
Block a user