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