mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-11 00:36:32 +02:00
- model package contains mostly shared interfaces (UI+service), not named GB* - impl package contains implementations of those interfaces, named GB* the impl classes should not be used by the service (not completely done) - the service classes should mostly use classes inside the service and deviceevents packages (tbd) Every device now has two packages: - devices/[device name] for UI related functionality - service[device name] for lowlevel communication
68 lines
2.6 KiB
Java
68 lines
2.6 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.service.receivers;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.media.AudioManager;
|
|
import android.os.SystemClock;
|
|
import android.view.KeyEvent;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
|
|
|
public class GBMusicControlReceiver extends BroadcastReceiver {
|
|
private static final Logger LOG = LoggerFactory.getLogger(GBMusicControlReceiver.class);
|
|
|
|
public static final String ACTION_MUSICCONTROL = "nodomain.freeyourgadget.gadgetbridge.musiccontrol";
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
GBDeviceEventMusicControl.Event musicCmd = GBDeviceEventMusicControl.Event.values()[intent.getIntExtra("event", 0)];
|
|
int keyCode = -1;
|
|
int volumeAdjust = AudioManager.ADJUST_LOWER;
|
|
|
|
switch (musicCmd) {
|
|
case NEXT:
|
|
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
|
|
break;
|
|
case PREVIOUS:
|
|
keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
|
|
break;
|
|
case PLAY:
|
|
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY;
|
|
break;
|
|
case PAUSE:
|
|
keyCode = KeyEvent.KEYCODE_MEDIA_PAUSE;
|
|
break;
|
|
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);
|
|
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);
|
|
}
|
|
}
|
|
}
|