mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-23 16:01:13 +01:00
Refactoring: get rid of ServiceCommand, use new CallSpec and MusicSpec to pass Call and Music info
This commit is contained in:
parent
3e3cf462a6
commit
a15b327ff1
@ -29,9 +29,10 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
@ -118,20 +119,20 @@ public class DebugActivity extends Activity {
|
||||
incomingCallButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onSetCallState(
|
||||
editContent.getText().toString(),
|
||||
null,
|
||||
ServiceCommand.CALL_INCOMING);
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = CallSpec.CALL_INCOMING;
|
||||
callSpec.number = editContent.getText().toString();
|
||||
GBApplication.deviceService().onSetCallState(callSpec);
|
||||
}
|
||||
});
|
||||
outgoingCallButton = (Button) findViewById(R.id.outgoingCallButton);
|
||||
outgoingCallButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onSetCallState(
|
||||
editContent.getText().toString(),
|
||||
null,
|
||||
ServiceCommand.CALL_OUTGOING);
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = CallSpec.CALL_OUTGOING;
|
||||
callSpec.number = editContent.getText().toString();
|
||||
GBApplication.deviceService().onSetCallState(callSpec);
|
||||
}
|
||||
});
|
||||
|
||||
@ -139,20 +140,18 @@ public class DebugActivity extends Activity {
|
||||
startCallButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onSetCallState(
|
||||
null,
|
||||
null,
|
||||
ServiceCommand.CALL_START);
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = CallSpec.CALL_START;
|
||||
GBApplication.deviceService().onSetCallState(callSpec);
|
||||
}
|
||||
});
|
||||
endCallButton = (Button) findViewById(R.id.endCallButton);
|
||||
endCallButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onSetCallState(
|
||||
null,
|
||||
null,
|
||||
ServiceCommand.CALL_END);
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = CallSpec.CALL_END;
|
||||
GBApplication.deviceService().onSetCallState(callSpec);
|
||||
}
|
||||
});
|
||||
|
||||
@ -199,10 +198,15 @@ public class DebugActivity extends Activity {
|
||||
setMusicInfoButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onSetMusicInfo(
|
||||
editContent.getText().toString() + "(artist)",
|
||||
editContent.getText().toString() + "(album)",
|
||||
editContent.getText().toString() + "(track)", 20, 10, 2);
|
||||
MusicSpec musicSpec = new MusicSpec();
|
||||
musicSpec.artist = editContent.getText().toString() + "(artist)";
|
||||
musicSpec.album = editContent.getText().toString() + "(album)";
|
||||
musicSpec.track = editContent.getText().toString() + "(track)";
|
||||
musicSpec.duration = 10;
|
||||
musicSpec.trackCount = 5;
|
||||
musicSpec.trackNr = 2;
|
||||
|
||||
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -9,6 +9,7 @@ public class GBDeviceEventDisplayMessage {
|
||||
* An event for displaying a message to the user. How the message is displayed
|
||||
* is a detail of the current activity, which needs to listen to the Intent
|
||||
* GB.ACTION_DISPLAY_MESSAGE.
|
||||
*
|
||||
* @param message
|
||||
* @param duration
|
||||
* @param severity
|
||||
|
@ -1,14 +1,14 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
|
||||
/**
|
||||
* Specifies all events that GadgetBridge intends to send to the gadget device.
|
||||
@ -22,9 +22,9 @@ public interface EventHandler {
|
||||
|
||||
void onSetAlarms(ArrayList<? extends Alarm> alarms);
|
||||
|
||||
void onSetCallState(@Nullable String number, @Nullable String name, ServiceCommand command);
|
||||
void onSetCallState(CallSpec callSpec);
|
||||
|
||||
void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr);
|
||||
void onSetMusicInfo(MusicSpec musicSpec);
|
||||
|
||||
void onEnableRealtimeSteps(boolean enable);
|
||||
|
||||
|
@ -18,7 +18,6 @@ public final class MiBandConst {
|
||||
public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection";
|
||||
|
||||
|
||||
|
||||
public static final String ORIGIN_SMS = "sms";
|
||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||
public static final String ORIGIN_K9MAIL = "k9mail";
|
||||
|
@ -8,12 +8,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
|
||||
public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MusicPlaybackReceiver.class);
|
||||
|
||||
private static String mLastSource;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String artist = intent.getStringExtra("artist");
|
||||
@ -24,11 +23,16 @@ public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
for (String key : bundle.keySet()) {
|
||||
Object value = bundle.get(key);
|
||||
LOG.info(String.format("%s %s (%s)", key,
|
||||
value.toString(), value.getClass().getName()));
|
||||
value != null ? value.toString() : "null", value != null ? value.getClass().getName() : "no class"));
|
||||
}
|
||||
*/
|
||||
LOG.info("Current track: " + artist + ", " + album + ", " + track);
|
||||
|
||||
GBApplication.deviceService().onSetMusicInfo(artist, album, track, 0, 0, 0);
|
||||
MusicSpec musicSpec = new MusicSpec();
|
||||
musicSpec.artist = artist;
|
||||
musicSpec.artist = album;
|
||||
musicSpec.artist = track;
|
||||
|
||||
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
|
@ -8,7 +8,7 @@ import android.preference.PreferenceManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
|
||||
|
||||
public class PhoneCallReceiver extends BroadcastReceiver {
|
||||
@ -40,35 +40,38 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
ServiceCommand callCommand = null;
|
||||
int callCommand = CallSpec.CALL_UNDEFINED;
|
||||
switch (state) {
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
mSavedNumber = number;
|
||||
callCommand = ServiceCommand.CALL_INCOMING;
|
||||
callCommand = CallSpec.CALL_INCOMING;
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
|
||||
callCommand = ServiceCommand.CALL_START;
|
||||
callCommand = CallSpec.CALL_START;
|
||||
} else {
|
||||
callCommand = ServiceCommand.CALL_OUTGOING;
|
||||
callCommand = CallSpec.CALL_OUTGOING;
|
||||
mSavedNumber = number;
|
||||
}
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
|
||||
//missed call would be correct here
|
||||
callCommand = ServiceCommand.CALL_END;
|
||||
callCommand = CallSpec.CALL_END;
|
||||
} else {
|
||||
callCommand = ServiceCommand.CALL_END;
|
||||
callCommand = CallSpec.CALL_END;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (callCommand != null) {
|
||||
if (callCommand != CallSpec.CALL_UNDEFINED) {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if ("never".equals(sharedPrefs.getString("notification_mode_calls", "always"))) {
|
||||
return;
|
||||
}
|
||||
GBApplication.deviceService().onSetCallState(mSavedNumber, null, callCommand);
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.number = mSavedNumber;
|
||||
callSpec.command = callCommand;
|
||||
GBApplication.deviceService().onSetCallState(callSpec);
|
||||
}
|
||||
mLastState = state;
|
||||
}
|
||||
|
@ -10,9 +10,10 @@ import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
|
||||
public class GBDeviceService implements DeviceService {
|
||||
@ -115,23 +116,23 @@ public class GBDeviceService implements DeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(String number, String name, ServiceCommand command) {
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
// name is actually ignored and provided by the service itself...
|
||||
Intent intent = createIntent().setAction(ACTION_CALLSTATE)
|
||||
.putExtra(EXTRA_CALL_PHONENUMBER, number)
|
||||
.putExtra(EXTRA_CALL_COMMAND, command);
|
||||
.putExtra(EXTRA_CALL_PHONENUMBER, callSpec.number)
|
||||
.putExtra(EXTRA_CALL_COMMAND, callSpec.command);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
Intent intent = createIntent().setAction(ACTION_SETMUSICINFO)
|
||||
.putExtra(EXTRA_MUSIC_ARTIST, artist)
|
||||
.putExtra(EXTRA_MUSIC_ALBUM, album)
|
||||
.putExtra(EXTRA_MUSIC_TRACK, track)
|
||||
.putExtra(EXTRA_MUSIC_DURATION, duration)
|
||||
.putExtra(EXTRA_MUSIC_TRACKCOUNT, trackCount)
|
||||
.putExtra(EXTRA_MUSIC_TRACKNR, trackNr);
|
||||
.putExtra(EXTRA_MUSIC_ARTIST, musicSpec.artist)
|
||||
.putExtra(EXTRA_MUSIC_ALBUM, musicSpec.album)
|
||||
.putExtra(EXTRA_MUSIC_TRACK, musicSpec.track)
|
||||
.putExtra(EXTRA_MUSIC_DURATION, musicSpec.duration)
|
||||
.putExtra(EXTRA_MUSIC_TRACKCOUNT, musicSpec.trackCount)
|
||||
.putExtra(EXTRA_MUSIC_TRACKNR, musicSpec.trackNr);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
public class CallSpec {
|
||||
public static final int CALL_UNDEFINED = 1;
|
||||
public static final int CALL_ACCEPT = 1;
|
||||
public static final int CALL_INCOMING = 2;
|
||||
public static final int CALL_OUTGOING = 3;
|
||||
public static final int CALL_REJECT = 4;
|
||||
public static final int CALL_START = 5;
|
||||
public static final int CALL_END = 6;
|
||||
|
||||
public String number;
|
||||
public String name;
|
||||
public int command;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
public class MusicSpec {
|
||||
public static final int MUSIC_UNDEFINED = 0;
|
||||
public static final int MUSIC_PLAY = 1;
|
||||
public static final int MUSIC_PAUSE = 2;
|
||||
public static final int MUSIC_PLAYPAUSE = 3;
|
||||
public static final int MUSIC_NEXT = 4;
|
||||
public static final int MUSIC_PREVIOUS = 5;
|
||||
|
||||
public String artist;
|
||||
public String album;
|
||||
public String track;
|
||||
public int duration;
|
||||
public int trackCount;
|
||||
public int trackNr;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
public enum ServiceCommand {
|
||||
|
||||
UNDEFINED,
|
||||
|
||||
CALL_ACCEPT,
|
||||
CALL_END,
|
||||
CALL_INCOMING,
|
||||
CALL_OUTGOING,
|
||||
CALL_REJECT,
|
||||
CALL_START,
|
||||
|
||||
MUSIC_PLAY,
|
||||
MUSIC_PAUSE,
|
||||
MUSIC_PLAYPAUSE,
|
||||
MUSIC_NEXT,
|
||||
MUSIC_PREVIOUS,
|
||||
|
||||
APP_INFO_NAME,
|
||||
VERSION_FIRMWARE
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -33,9 +33,10 @@ import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
@ -64,10 +65,10 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALA
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_CONFIG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_START;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_UUID;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_BOOLEAN_ENABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_PHONENUMBER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_DEVICE_ADDRESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_BOOLEAN_ENABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_FIND_START;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ALBUM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ARTIST;
|
||||
@ -278,26 +279,32 @@ public class DeviceCommunicationService extends Service {
|
||||
break;
|
||||
}
|
||||
case ACTION_CALLSTATE:
|
||||
ServiceCommand command = (ServiceCommand) intent.getSerializableExtra(EXTRA_CALL_COMMAND);
|
||||
int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
|
||||
|
||||
String phoneNumber = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
|
||||
String callerName = null;
|
||||
if (phoneNumber != null) {
|
||||
callerName = getContactDisplayNameByNumber(phoneNumber);
|
||||
}
|
||||
mDeviceSupport.onSetCallState(phoneNumber, callerName, command);
|
||||
|
||||
CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = command;
|
||||
callSpec.number = phoneNumber;
|
||||
callSpec.name = callerName;
|
||||
mDeviceSupport.onSetCallState(callSpec);
|
||||
break;
|
||||
case ACTION_SETTIME:
|
||||
mDeviceSupport.onSetTime();
|
||||
break;
|
||||
case ACTION_SETMUSICINFO:
|
||||
String artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
|
||||
String album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
|
||||
String track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
|
||||
int duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
|
||||
int trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
|
||||
int trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
|
||||
mDeviceSupport.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr);
|
||||
MusicSpec musicSpec = new MusicSpec();
|
||||
musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
|
||||
musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
|
||||
musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
|
||||
musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
|
||||
musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
|
||||
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
|
||||
mDeviceSupport.onSetMusicInfo(musicSpec);
|
||||
break;
|
||||
case ACTION_REQUEST_APPINFO:
|
||||
mDeviceSupport.onAppInfoReq();
|
||||
@ -424,7 +431,10 @@ public class DeviceCommunicationService extends Service {
|
||||
}
|
||||
if (mMusicPlaybackReceiver == null) {
|
||||
mMusicPlaybackReceiver = new MusicPlaybackReceiver();
|
||||
registerReceiver(mMusicPlaybackReceiver, new IntentFilter("com.android.music.metachanged"));
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.android.music.metachanged");
|
||||
//filter.addAction("com.android.music.playstatechanged");
|
||||
registerReceiver(mMusicPlaybackReceiver, filter);
|
||||
}
|
||||
if (mTimeChangeReceiver == null) {
|
||||
mTimeChangeReceiver = new TimeChangeReceiver();
|
||||
|
@ -13,8 +13,9 @@ import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
|
||||
/**
|
||||
* Wraps another device support instance and supports busy-checking and throttling of events.
|
||||
@ -131,19 +132,19 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
||||
// No throttling for the other events
|
||||
|
||||
@Override
|
||||
public void onSetCallState(String number, String name, ServiceCommand command) {
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
if (checkBusy("set call state")) {
|
||||
return;
|
||||
}
|
||||
delegate.onSetCallState(number, name, command);
|
||||
delegate.onSetCallState(callSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
if (checkBusy("set music info")) {
|
||||
return;
|
||||
}
|
||||
delegate.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr);
|
||||
delegate.onSetMusicInfo(musicSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,9 +20,10 @@ public abstract class ConditionalWriteAction extends WriteAction {
|
||||
/**
|
||||
* Checks the condition whether the write shall happen or not.
|
||||
* Returns the actual value to be written or null in case nothing shall be written.
|
||||
*
|
||||
* <p/>
|
||||
* Note that returning null will not cause run() to return false, in other words,
|
||||
* the rest of the queue will still be executed.
|
||||
*
|
||||
* @return the value to be written or null to not write anything
|
||||
*/
|
||||
protected abstract byte[] checkCondition();
|
||||
|
@ -34,10 +34,11 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
|
||||
@ -383,6 +384,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
/**
|
||||
* Part of device initialization process. Do not call manually.
|
||||
*
|
||||
* @param builder
|
||||
*/
|
||||
private MiBandSupport setHeartrateSleepSupport(TransactionBuilder builder) {
|
||||
@ -558,8 +560,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(String number, String name, ServiceCommand command) {
|
||||
if (ServiceCommand.CALL_INCOMING.equals(command)) {
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
if (callSpec.command == CallSpec.CALL_INCOMING) {
|
||||
telephoneRinging = true;
|
||||
AbortTransactionAction abortAction = new AbortTransactionAction() {
|
||||
@Override
|
||||
@ -568,7 +570,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
};
|
||||
performPreferredNotification("incoming call", MiBandConst.ORIGIN_INCOMING_CALL, abortAction);
|
||||
} else if (ServiceCommand.CALL_START.equals(command) || ServiceCommand.CALL_END.equals(command)) {
|
||||
} else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) {
|
||||
telephoneRinging = false;
|
||||
}
|
||||
}
|
||||
@ -579,7 +581,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleColor;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleIconID;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
||||
|
||||
public class PebbleProtocol extends GBDeviceProtocol {
|
||||
@ -495,7 +495,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
|
||||
@Override
|
||||
public byte[] encodeFindDevice(boolean start) {
|
||||
return encodeSetCallState("Where are you?", "Gadgetbridge", start ? ServiceCommand.CALL_INCOMING : ServiceCommand.CALL_END);
|
||||
return encodeSetCallState("Where are you?", "Gadgetbridge", start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END);
|
||||
}
|
||||
|
||||
private static byte[] encodeExtensibleNotification(int id, int timestamp, String title, String subtitle, String body, String sourceName, boolean hasHandle, String[] cannedReplies) {
|
||||
@ -1044,20 +1044,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetCallState(String number, String name, ServiceCommand command) {
|
||||
public byte[] encodeSetCallState(String number, String name, int command) {
|
||||
String[] parts = {number, name};
|
||||
byte pebbleCmd;
|
||||
switch (command) {
|
||||
case CALL_START:
|
||||
case CallSpec.CALL_START:
|
||||
pebbleCmd = PHONECONTROL_START;
|
||||
break;
|
||||
case CALL_END:
|
||||
case CallSpec.CALL_END:
|
||||
pebbleCmd = PHONECONTROL_END;
|
||||
break;
|
||||
case CALL_INCOMING:
|
||||
case CallSpec.CALL_INCOMING:
|
||||
pebbleCmd = PHONECONTROL_INCOMINGCALL;
|
||||
break;
|
||||
case CALL_OUTGOING:
|
||||
case CallSpec.CALL_OUTGOING:
|
||||
// pebbleCmd = PHONECONTROL_OUTGOINGCALL;
|
||||
/*
|
||||
* HACK/WORKAROUND for non-working outgoing call display.
|
||||
|
@ -12,8 +12,9 @@ import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.AbstractSerialDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceIoThread;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
||||
@ -99,16 +100,16 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(String number, String name, ServiceCommand command) {
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
if (reconnect()) {
|
||||
super.onSetCallState(number, name, command);
|
||||
super.onSetCallState(callSpec);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
if (reconnect()) {
|
||||
super.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr);
|
||||
super.onSetMusicInfo(musicSpec);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,9 @@ import java.util.UUID;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.EventHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport;
|
||||
|
||||
/**
|
||||
@ -120,14 +121,14 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(String number, String name, ServiceCommand command) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetCallState(number, name, command);
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetCallState(callSpec.number, callSpec.name, callSpec.command);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(artist, album, track, duration, trackCount, trackNr);
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(musicSpec.artist, musicSpec.album, musicSpec.track, musicSpec.duration, musicSpec.trackCount, musicSpec.trackNr);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
|
||||
public abstract class GBDeviceProtocol {
|
||||
|
||||
@ -16,7 +15,7 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeSetCallState(String number, String name, ServiceCommand command) {
|
||||
public byte[] encodeSetCallState(String number, String name, int command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -60,7 +59,9 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeEnableHeartRateSleepSupport(boolean enable) { return null; }
|
||||
public byte[] encodeEnableHeartRateSleepSupport(boolean enable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
|
||||
return null;
|
||||
|
@ -3,15 +3,15 @@ package nodomain.freeyourgadget.gadgetbridge.service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
|
||||
public class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
|
||||
@ -61,12 +61,12 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(@Nullable String number, @Nullable String name, ServiceCommand command) {
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user