mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 18:45:49 +01:00
Huami: Send media volume to device
This commit is contained in:
parent
37ba8c291e
commit
682b215985
@ -60,6 +60,13 @@ public interface EventHandler {
|
||||
|
||||
void onSetMusicInfo(MusicSpec musicSpec);
|
||||
|
||||
/**
|
||||
* Sets the current phone media volume.
|
||||
*
|
||||
* @param volume the volume percentage (0 to 100).
|
||||
*/
|
||||
void onSetPhoneVolume(final float volume);
|
||||
|
||||
void onEnableRealtimeSteps(boolean enable);
|
||||
|
||||
void onInstallApp(Uri uri);
|
||||
|
@ -224,6 +224,13 @@ public class GBDeviceService implements DeviceService {
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(final float volume) {
|
||||
Intent intent = createIntent().setAction(ACTION_SET_PHONE_VOLUME)
|
||||
.putExtra(EXTRA_PHONE_VOLUME, volume);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetReminders(ArrayList<? extends Reminder> reminders) {
|
||||
Intent intent = createIntent().setAction(ACTION_SET_REMINDERS)
|
||||
|
@ -39,6 +39,7 @@ public interface DeviceService extends EventHandler {
|
||||
String ACTION_SETTIME = PREFIX + ".action.settime";
|
||||
String ACTION_SETMUSICINFO = PREFIX + ".action.setmusicinfo";
|
||||
String ACTION_SETMUSICSTATE = PREFIX + ".action.setmusicstate";
|
||||
String ACTION_SET_PHONE_VOLUME = PREFIX + ".action.set_phone_volume";
|
||||
String ACTION_REQUEST_DEVICEINFO = PREFIX + ".action.request_deviceinfo";
|
||||
String ACTION_REQUEST_APPINFO = PREFIX + ".action.request_appinfo";
|
||||
String ACTION_REQUEST_SCREENSHOT = PREFIX + ".action.request_screenshot";
|
||||
@ -103,6 +104,7 @@ public interface DeviceService extends EventHandler {
|
||||
String EXTRA_MUSIC_REPEAT = "music_repeat";
|
||||
String EXTRA_MUSIC_POSITION = "music_position";
|
||||
String EXTRA_MUSIC_RATE = "music_rate";
|
||||
String EXTRA_PHONE_VOLUME = "phone_volume";
|
||||
String EXTRA_APP_UUID = "app_uuid";
|
||||
String EXTRA_APP_START = "app_start";
|
||||
String EXTRA_APP_CONFIG = "app_config";
|
||||
|
@ -120,6 +120,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SE
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_FM_FREQUENCY;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_HEARTRATE_MEASUREMENT_INTERVAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_LED_COLOR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_PHONE_VOLUME;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_REMINDERS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_WORLD_CLOCKS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START;
|
||||
@ -174,6 +175,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOT
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_SUBJECT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TITLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_PHONE_VOLUME;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_RECORDED_DATA_TYPES;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_REMINDERS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_RESET_FLAGS;
|
||||
@ -533,6 +535,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
|
||||
mDeviceSupport.onSetMusicInfo(musicSpec);
|
||||
break;
|
||||
case ACTION_SET_PHONE_VOLUME:
|
||||
float phoneVolume = intent.getFloatExtra(EXTRA_PHONE_VOLUME, 0);
|
||||
mDeviceSupport.onSetPhoneVolume(phoneVolume);
|
||||
break;
|
||||
case ACTION_SETMUSICSTATE:
|
||||
MusicStateSpec stateSpec = new MusicStateSpec();
|
||||
stateSpec.shuffle = intent.getByteExtra(EXTRA_MUSIC_SHUFFLE, (byte) 0);
|
||||
|
@ -207,6 +207,14 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
||||
delegate.onSetMusicInfo(musicSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(float volume) {
|
||||
if (checkBusy("set phone volume")) {
|
||||
return;
|
||||
}
|
||||
delegate.onSetPhoneVolume(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstallApp(Uri uri) {
|
||||
if (checkBusy("install app")) {
|
||||
|
@ -374,6 +374,11 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(final float volume) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetReminders(ArrayList<? extends Reminder> reminders) {
|
||||
|
||||
|
@ -26,6 +26,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -1230,11 +1231,40 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendMusicStateToDevice() {
|
||||
sendMusicStateToDevice(bufferMusicSpec, bufferMusicStateSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(final float volume) {
|
||||
if (characteristicChunked == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final byte[] volumeCommand = new byte[]{0x40, (byte) Math.round(volume)};
|
||||
|
||||
try {
|
||||
final TransactionBuilder builder = performInitialized("send volume");
|
||||
writeToChunked(builder, 3, volumeCommand);
|
||||
|
||||
builder.queue(getQueue());
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Unable to send volume", e);
|
||||
}
|
||||
|
||||
LOG.info("sendVolumeStateToDevice: {}", volume);
|
||||
}
|
||||
|
||||
private void sendVolumeStateToDevice() {
|
||||
final AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
final int volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
final int volumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
final int volumePercentage = (byte) Math.round(100 * (volumeLevel / (float) volumeMax));
|
||||
|
||||
onSetPhoneVolume(volumePercentage);
|
||||
}
|
||||
|
||||
protected void sendMusicStateToDevice(MusicSpec musicSpec, MusicStateSpec musicStateSpec) {
|
||||
if (characteristicChunked == null) {
|
||||
return;
|
||||
@ -1712,6 +1742,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
LOG.info("Music app started");
|
||||
isMusicAppStarted = true;
|
||||
sendMusicStateToDevice();
|
||||
sendVolumeStateToDevice();
|
||||
break;
|
||||
case (byte) 225:
|
||||
LOG.info("Music app terminated");
|
||||
|
@ -76,6 +76,12 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
case VOLUMEDOWN:
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, volumeAdjust, 0);
|
||||
|
||||
final int volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
final int volumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
final int volumePercentage = (byte) Math.round(100 * (volumeLevel / (float) volumeMax));
|
||||
|
||||
GBApplication.deviceService().onSetPhoneVolume(volumePercentage);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
@ -158,6 +158,12 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(final float volume) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeVolume(volume);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppInfoReq() {
|
||||
byte[] bytes = gbDeviceProtocol.encodeAppInfoReq();
|
||||
|
@ -64,6 +64,10 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeVolume(float volume) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeSetMusicState(byte state, int position, int playRate, byte shuffle, byte repeat) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user