mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
AsteroidOS: Add volume control
This pull request adds volume control to the AsteroidOS implementation. It's not quite what I wanted from it, but it's probably good enough. Hopefully it's good enough for other people too
This commit is contained in:
parent
9edbf160c7
commit
fbd4cb810a
@ -16,6 +16,9 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,12 +32,18 @@ public class AsteroidOSMediaCommand {
|
|||||||
public static final byte COMMAND_VOLUME = 0x4;
|
public static final byte COMMAND_VOLUME = 0x4;
|
||||||
|
|
||||||
public byte command;
|
public byte command;
|
||||||
public AsteroidOSMediaCommand(byte value) {
|
public byte[] raw_values;
|
||||||
command = value;
|
public Context context;
|
||||||
|
|
||||||
|
public AsteroidOSMediaCommand(byte[] values, Context device_context) {
|
||||||
|
command = values[0];
|
||||||
|
raw_values = values;
|
||||||
|
context = device_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the MediaCommand to a music control event
|
* Convert the MediaCommand to a music control event
|
||||||
|
*
|
||||||
* @return the matching music control event
|
* @return the matching music control event
|
||||||
*/
|
*/
|
||||||
public GBDeviceEventMusicControl toMusicControlEvent() {
|
public GBDeviceEventMusicControl toMusicControlEvent() {
|
||||||
@ -53,9 +62,21 @@ public class AsteroidOSMediaCommand {
|
|||||||
event.event = GBDeviceEventMusicControl.Event.PAUSE;
|
event.event = GBDeviceEventMusicControl.Event.PAUSE;
|
||||||
break;
|
break;
|
||||||
case COMMAND_VOLUME:
|
case COMMAND_VOLUME:
|
||||||
|
setVolume(raw_values[1]);
|
||||||
|
event = null;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
event.event = GBDeviceEventMusicControl.Event.UNKNOWN;
|
event.event = GBDeviceEventMusicControl.Event.UNKNOWN;
|
||||||
}
|
}
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setVolume(byte volume) {
|
||||||
|
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
|
||||||
|
final int volumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||||
|
final int finalVol = (int) Math.round((volume * volumeMax) / 100f);
|
||||||
|
if (audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) != finalVol)
|
||||||
|
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) Math.round((volume * volumeMax) / 100f), AudioManager.FLAG_SHOW_UI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@ -274,8 +275,9 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
*/
|
*/
|
||||||
public void handleMediaCommand (BluetoothGattCharacteristic characteristic) {
|
public void handleMediaCommand (BluetoothGattCharacteristic characteristic) {
|
||||||
LOG.info("handle media command");
|
LOG.info("handle media command");
|
||||||
AsteroidOSMediaCommand command = new AsteroidOSMediaCommand(characteristic.getValue()[0]);
|
AsteroidOSMediaCommand command = new AsteroidOSMediaCommand(characteristic.getValue(), getContext());
|
||||||
GBDeviceEventMusicControl event = command.toMusicControlEvent();
|
GBDeviceEventMusicControl event = command.toMusicControlEvent();
|
||||||
|
if (event != null)
|
||||||
evaluateGBDeviceEvent(event);
|
evaluateGBDeviceEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user