mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
Implement volume control for Pebble
I didn't know how to access this on the pebble until I did a long press on play/pause ;)
This commit is contained in:
parent
40438ebe0e
commit
0cec658c3a
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.os.SystemClock;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
@ -16,7 +17,9 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
GBDeviceCommandMusicControl.Command musicCmd = GBDeviceCommandMusicControl.Command.values()[intent.getIntExtra("command", 0)];
|
||||
int keyCode;
|
||||
int keyCode = -1;
|
||||
int volumeAdjust = AudioManager.ADJUST_LOWER;
|
||||
|
||||
switch (musicCmd) {
|
||||
case NEXT:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
|
||||
@ -33,10 +36,19 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
case PLAYPAUSE:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
||||
break;
|
||||
case VOLUMEUP:
|
||||
// change default and fall through, :P
|
||||
volumeAdjust = AudioManager.ADJUST_RAISE;
|
||||
case VOLUMEDOWN:
|
||||
AudioManager audioManager =
|
||||
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, volumeAdjust, 0);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyCode != -1) {
|
||||
long eventtime = SystemClock.uptimeMillis();
|
||||
|
||||
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||
@ -50,3 +62,4 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
context.sendOrderedBroadcast(upIntent, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class PBWReader {
|
||||
try {
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
String fileName = ze.getName();
|
||||
if (fileName.equals("pebble-app.bin") || fileName.equals("pebble-worker.bin") || fileName.equals("app_resources.pbpack")) {
|
||||
if (fileName.equals("pebble-app.bin") || fileName.equals("pebble-worker.bin") || fileName.equals("app_resources.pbpack") || fileName.equals("")) {
|
||||
filesToInstall.add(fileName); // FIXME: do not hardcode filenames above
|
||||
} else if (fileName.equals("appinfo.json")) {
|
||||
long bytes = ze.getSize();
|
||||
|
@ -15,5 +15,7 @@ public class GBDeviceCommandMusicControl extends GBDeviceCommand {
|
||||
PLAYPAUSE,
|
||||
NEXT,
|
||||
PREVIOUS,
|
||||
VOLUMEUP,
|
||||
VOLUMEDOWN,
|
||||
}
|
||||
}
|
||||
|
@ -390,6 +390,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
case MUSICCONTROL_PLAYPAUSE:
|
||||
musicCmd.command = GBDeviceCommandMusicControl.Command.PLAYPAUSE;
|
||||
break;
|
||||
case MUSICCONTROL_VOLUMEUP:
|
||||
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEUP;
|
||||
break;
|
||||
case MUSICCONTROL_VOLUMEDOWN:
|
||||
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEDOWN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user