mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +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.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.AudioManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
@ -16,7 +17,9 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
GBDeviceCommandMusicControl.Command musicCmd = GBDeviceCommandMusicControl.Command.values()[intent.getIntExtra("command", 0)];
|
GBDeviceCommandMusicControl.Command musicCmd = GBDeviceCommandMusicControl.Command.values()[intent.getIntExtra("command", 0)];
|
||||||
int keyCode;
|
int keyCode = -1;
|
||||||
|
int volumeAdjust = AudioManager.ADJUST_LOWER;
|
||||||
|
|
||||||
switch (musicCmd) {
|
switch (musicCmd) {
|
||||||
case NEXT:
|
case NEXT:
|
||||||
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
|
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
|
||||||
@ -33,10 +36,19 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
|||||||
case PLAYPAUSE:
|
case PLAYPAUSE:
|
||||||
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
||||||
break;
|
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:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (keyCode != -1) {
|
||||||
long eventtime = SystemClock.uptimeMillis();
|
long eventtime = SystemClock.uptimeMillis();
|
||||||
|
|
||||||
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||||
@ -50,3 +62,4 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
|||||||
context.sendOrderedBroadcast(upIntent, null);
|
context.sendOrderedBroadcast(upIntent, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class PBWReader {
|
|||||||
try {
|
try {
|
||||||
while ((ze = zis.getNextEntry()) != null) {
|
while ((ze = zis.getNextEntry()) != null) {
|
||||||
String fileName = ze.getName();
|
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
|
filesToInstall.add(fileName); // FIXME: do not hardcode filenames above
|
||||||
} else if (fileName.equals("appinfo.json")) {
|
} else if (fileName.equals("appinfo.json")) {
|
||||||
long bytes = ze.getSize();
|
long bytes = ze.getSize();
|
||||||
|
@ -15,5 +15,7 @@ public class GBDeviceCommandMusicControl extends GBDeviceCommand {
|
|||||||
PLAYPAUSE,
|
PLAYPAUSE,
|
||||||
NEXT,
|
NEXT,
|
||||||
PREVIOUS,
|
PREVIOUS,
|
||||||
|
VOLUMEUP,
|
||||||
|
VOLUMEDOWN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,6 +390,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
case MUSICCONTROL_PLAYPAUSE:
|
case MUSICCONTROL_PLAYPAUSE:
|
||||||
musicCmd.command = GBDeviceCommandMusicControl.Command.PLAYPAUSE;
|
musicCmd.command = GBDeviceCommandMusicControl.Command.PLAYPAUSE;
|
||||||
break;
|
break;
|
||||||
|
case MUSICCONTROL_VOLUMEUP:
|
||||||
|
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEUP;
|
||||||
|
break;
|
||||||
|
case MUSICCONTROL_VOLUMEDOWN:
|
||||||
|
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEDOWN;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user