1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 01:55: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:
Andreas Shimokawa 2015-04-13 22:25:23 +02:00
parent 40438ebe0e
commit 0cec658c3a
4 changed files with 32 additions and 11 deletions

View File

@ -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,20 +36,30 @@ 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;
}
long eventtime = SystemClock.uptimeMillis();
if (keyCode != -1) {
long eventtime = SystemClock.uptimeMillis();
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
context.sendOrderedBroadcast(downIntent, null);
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
context.sendOrderedBroadcast(downIntent, null);
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
context.sendOrderedBroadcast(upIntent, null);
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
context.sendOrderedBroadcast(upIntent, null);
}
}
}

View File

@ -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();

View File

@ -15,5 +15,7 @@ public class GBDeviceCommandMusicControl extends GBDeviceCommand {
PLAYPAUSE,
NEXT,
PREVIOUS,
VOLUMEUP,
VOLUMEDOWN,
}
}

View File

@ -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;
}