mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-09 19:49:30 +01:00
Prepare code for more music metadata (duration, track count, current track number)
Oh and format code
This commit is contained in:
parent
bfcfe82f17
commit
adfef3db42
@ -202,7 +202,7 @@ public class DebugActivity extends Activity {
|
||||
GBApplication.deviceService().onSetMusicInfo(
|
||||
editContent.getText().toString() + "(artist)",
|
||||
editContent.getText().toString() + "(album)",
|
||||
editContent.getText().toString() + "(tracl)");
|
||||
editContent.getText().toString() + "(track)", 90, 10, 2);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,6 @@ import android.widget.Toast;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
|
@ -24,7 +24,7 @@ public interface EventHandler {
|
||||
|
||||
void onSetCallState(@Nullable String number, @Nullable String name, ServiceCommand command);
|
||||
|
||||
void onSetMusicInfo(String artist, String album, String track);
|
||||
void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr);
|
||||
|
||||
void onEnableRealtimeSteps(boolean enable);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -19,9 +19,16 @@ public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
String artist = intent.getStringExtra("artist");
|
||||
String album = intent.getStringExtra("album");
|
||||
String track = intent.getStringExtra("track");
|
||||
|
||||
/*
|
||||
Bundle bundle = intent.getExtras();
|
||||
for (String key : bundle.keySet()) {
|
||||
Object value = bundle.get(key);
|
||||
LOG.info(String.format("%s %s (%s)", key,
|
||||
value.toString(), value.getClass().getName()));
|
||||
}
|
||||
*/
|
||||
LOG.info("Current track: " + artist + ", " + album + ", " + track);
|
||||
|
||||
GBApplication.deviceService().onSetMusicInfo(artist, album, track);
|
||||
GBApplication.deviceService().onSetMusicInfo(artist, album, track, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -124,10 +124,14 @@ public class GBDeviceService implements DeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track) {
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
Intent intent = createIntent().setAction(ACTION_SETMUSICINFO)
|
||||
.putExtra(EXTRA_MUSIC_ARTIST, artist)
|
||||
.putExtra(EXTRA_MUSIC_TRACK, track);
|
||||
.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);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,9 @@ public interface DeviceService extends EventHandler {
|
||||
String EXTRA_MUSIC_ARTIST = "music_artist";
|
||||
String EXTRA_MUSIC_ALBUM = "music_album";
|
||||
String EXTRA_MUSIC_TRACK = "music_track";
|
||||
String EXTRA_MUSIC_DURATION = "music_duration";
|
||||
String EXTRA_MUSIC_TRACKNR = "music_tracknr";
|
||||
String EXTRA_MUSIC_TRACKCOUNT = "music_trackcount";
|
||||
String EXTRA_APP_UUID = "app_uuid";
|
||||
String EXTRA_APP_START = "app_start";
|
||||
String EXTRA_APP_CONFIG = "app_config";
|
||||
|
@ -70,7 +70,10 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ENA
|
||||
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;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACK;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKCOUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKNR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_FLAGS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ID;
|
||||
@ -290,7 +293,10 @@ public class DeviceCommunicationService extends Service {
|
||||
String artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
|
||||
String album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
|
||||
String track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
|
||||
mDeviceSupport.onSetMusicInfo(artist, album, 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);
|
||||
break;
|
||||
case ACTION_REQUEST_APPINFO:
|
||||
mDeviceSupport.onAppInfoReq();
|
||||
|
@ -139,11 +139,11 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track) {
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
if (checkBusy("set music info")) {
|
||||
return;
|
||||
}
|
||||
delegate.onSetMusicInfo(artist, album, track);
|
||||
delegate.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,15 +13,15 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||
public abstract class AbstractMi1FirmwareInfo extends AbstractMiFirmwareInfo {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractMi1FirmwareInfo.class);
|
||||
|
||||
private static final byte[] SINGLE_FW_HEADER = new byte[] {
|
||||
private static final byte[] SINGLE_FW_HEADER = new byte[]{
|
||||
0,
|
||||
(byte)0x98,
|
||||
(byte) 0x98,
|
||||
0,
|
||||
(byte)0x20,
|
||||
(byte)0x89,
|
||||
(byte) 0x20,
|
||||
(byte) 0x89,
|
||||
4,
|
||||
0,
|
||||
(byte)0x20
|
||||
(byte) 0x20
|
||||
};
|
||||
private static final int SINGLE_FW_HEADER_OFFSET = 0;
|
||||
|
||||
|
@ -2,11 +2,9 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||
|
||||
public abstract class AbstractMiFirmwareInfo {
|
||||
|
||||
@ -32,7 +30,7 @@ public abstract class AbstractMiFirmwareInfo {
|
||||
if (MiBandSupport.MI_1A_HR_FW_UPDATE_TEST_MODE_ENABLED) {
|
||||
TestMi1AFirmwareInfo info = TestMi1AFirmwareInfo.getInstance(wholeFirmwareBytes);
|
||||
if (info != null) {
|
||||
return new AbstractMiFirmwareInfo[] { info };
|
||||
return new AbstractMiFirmwareInfo[]{info};
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,11 +80,13 @@ public abstract class AbstractMiFirmwareInfo {
|
||||
/**
|
||||
* Checks whether this instance, with the provided firmware data is compatible with the
|
||||
* given device. Must be called to avoid installing Mi1 firmware on Mi1A, for example.
|
||||
*
|
||||
* @param device
|
||||
*/
|
||||
public abstract boolean isGenerallyCompatibleWith(GBDevice device);
|
||||
|
||||
public @NonNull byte[] getFirmwareBytes() {
|
||||
@NonNull
|
||||
public byte[] getFirmwareBytes() {
|
||||
return Arrays.copyOfRange(wholeFirmwareBytes, getFirmwareOffset(), getFirmwareOffset() + getFirmwareLength());
|
||||
}
|
||||
|
||||
@ -103,6 +103,7 @@ public abstract class AbstractMiFirmwareInfo {
|
||||
/**
|
||||
* Performs a thorough sanity check of the firmware data and throws IllegalArgumentException
|
||||
* if there's any problem with it.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public void checkValid() throws IllegalArgumentException {
|
||||
|
@ -16,11 +16,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||
public class Mi1SFirmwareInfo extends CompositeMiFirmwareInfo {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfo.class);
|
||||
|
||||
private static final byte[] DOUBLE_FW_HEADER = new byte[] {
|
||||
(byte)0x78,
|
||||
(byte)0x75,
|
||||
(byte)0x63,
|
||||
(byte)0x6b
|
||||
private static final byte[] DOUBLE_FW_HEADER = new byte[]{
|
||||
(byte) 0x78,
|
||||
(byte) 0x75,
|
||||
(byte) 0x63,
|
||||
(byte) 0x6b
|
||||
};
|
||||
private static final int DOUBLE_FW_HEADER_OFFSET = 0;
|
||||
|
||||
|
@ -540,7 +540,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track) {
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
* This is a class just for testing the dual fw firmware update procedure.
|
||||
* It uses two instances of the known-to-be-working Mi1A firmware update instances
|
||||
* and combines them in a CompositeMiFirmwareInfo.
|
||||
*
|
||||
* <p/>
|
||||
* Most methods simply delegate to one of the child instances (FW1).
|
||||
*
|
||||
* <p/>
|
||||
* FW1 is the default Mi 1A Band firmware
|
||||
* FW2 is the same default Mi 1A Band firmware
|
||||
*/
|
||||
|
@ -15,7 +15,6 @@ import java.util.UUID;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.PlainAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
|
||||
|
@ -1083,9 +1083,51 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetMusicInfo(String artist, String album, String track) {
|
||||
public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
String[] parts = {artist, album, track};
|
||||
return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
|
||||
if (duration == 0) {
|
||||
return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
|
||||
} else {
|
||||
// Calculate length first
|
||||
int length = LENGTH_PREFIX + 13;
|
||||
if (parts != null) {
|
||||
for (String s : parts) {
|
||||
if (s == null || s.equals("")) {
|
||||
length++; // encode null or empty strings as 0x00 later
|
||||
continue;
|
||||
}
|
||||
length += (1 + s.getBytes().length);
|
||||
}
|
||||
}
|
||||
|
||||
// Encode Prefix
|
||||
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
buf.putShort((short) (length - LENGTH_PREFIX));
|
||||
buf.putShort(ENDPOINT_MUSICCONTROL);
|
||||
buf.put(MUSICCONTROL_SETMUSICINFO);
|
||||
|
||||
// Encode Pascal-Style Strings
|
||||
for (String s : parts) {
|
||||
if (s == null || s.equals("")) {
|
||||
buf.put((byte) 0x00);
|
||||
continue;
|
||||
}
|
||||
|
||||
int partlength = s.getBytes().length;
|
||||
if (partlength > 255) partlength = 255;
|
||||
buf.put((byte) partlength);
|
||||
buf.put(s.getBytes(), 0, partlength);
|
||||
}
|
||||
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.putInt(duration*1000);
|
||||
buf.putInt(trackCount);
|
||||
buf.putInt(trackNr);
|
||||
|
||||
return buf.array();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,8 +126,8 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(artist, album, track);
|
||||
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);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeSetMusicInfo(String artist, String album, String track) {
|
||||
public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,11 @@ public class ArrayUtils {
|
||||
/**
|
||||
* Checks the two given arrays for equality, but comparing only a subset of the second
|
||||
* array with the whole first array.
|
||||
* @param first the whole array to compare against
|
||||
* @param second the array, of which a subset shall be compared against the whole first array
|
||||
*
|
||||
* @param first the whole array to compare against
|
||||
* @param second the array, of which a subset shall be compared against the whole first array
|
||||
* @param secondStartIndex the start index (inclusive) of the second array from which to start the comparison
|
||||
* @param secondEndIndex the end index (exclusive) of the second array until which to compare
|
||||
* @param secondEndIndex the end index (exclusive) of the second array until which to compare
|
||||
* @return whether the first byte array is equal to the specified subset of the second byte array
|
||||
* @throws IllegalArgumentException when one of the arrays is null or start and end index are wrong
|
||||
*/
|
||||
|
@ -66,7 +66,7 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(String artist, String album, String track) {
|
||||
public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user