mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-23 16:00:41 +00:00
e001c153fb
* [Android] wip * implemented `VolumeEventsService` * implemented `VolumeKeysListener` (wip) * Added screenshots links * [Android] nullable typo * implemented `VolumeKeysNotifier` * deinitialize camera when on Settings screen * disable volume handling when on Settings screen * used "platform" package to mock `isAndroid` * init/deinit camera on settings open * allow volume action override only on metering screen * lints * cleanup * await dispose * tests * reduced `SwitchListTile.contentPadding` * fixed tests * removed `VolumeAction.zoom` * added social preview * typo * fixed `CameraContainerBloc` tests * added `Stream.empty()` tests
40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:platform/platform.dart';
|
|
|
|
class VolumeEventsService {
|
|
final LocalPlatform localPlatform;
|
|
|
|
@visibleForTesting
|
|
static const volumeHandlingChannel = MethodChannel("com.vodemn.lightmeter/volumeHandling");
|
|
|
|
@visibleForTesting
|
|
static const volumeEventsChannel = EventChannel("com.vodemn.lightmeter/volumeEvents");
|
|
|
|
const VolumeEventsService(this.localPlatform);
|
|
|
|
/// If set to `false` we allow system to handle key events.
|
|
/// Returns current status of volume handling.
|
|
Future<bool> setVolumeHandling(bool enableHandling) async {
|
|
if (!localPlatform.isAndroid) {
|
|
return false;
|
|
}
|
|
return volumeHandlingChannel
|
|
.invokeMethod<bool>("setVolumeHandling", enableHandling)
|
|
.then((value) => value!);
|
|
}
|
|
|
|
/// Emits new events on
|
|
/// KEYCODE_VOLUME_UP = 24;
|
|
/// KEYCODE_VOLUME_DOWN = 25;
|
|
/// pressed
|
|
Stream<int> volumeButtonsEventStream() {
|
|
if (!localPlatform.isAndroid) {
|
|
return const Stream.empty();
|
|
}
|
|
return volumeEventsChannel
|
|
.receiveBroadcastStream()
|
|
.cast<int>()
|
|
.where((event) => event == 24 || event == 25);
|
|
}
|
|
}
|