Add haptic and aural feedback service
And use the service in mine_digger to notify the user when they flag a bomb.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import 'dart:sky' as sky;
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:sky/mojo/activity.dart' as activity;
|
||||
import 'package:sky/painting/text_style.dart';
|
||||
import 'package:sky/rendering/flex.dart';
|
||||
import 'package:sky/theme/colors.dart' as colors;
|
||||
@@ -83,36 +84,16 @@ class MineDiggerApp extends App {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
Stopwatch longPressStopwatch;
|
||||
|
||||
PointerEventListener _pointerDownHandlerFor(int posX, int posY) {
|
||||
return (sky.PointerEvent event) {
|
||||
if (event.buttons == 1) {
|
||||
probe(posX, posY);
|
||||
} else if (event.buttons == 2) {
|
||||
flag(posX, posY);
|
||||
} else {
|
||||
// Touch event.
|
||||
longPressStopwatch = new Stopwatch()..start();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
PointerEventListener _pointerUpHandlerFor(int posX, int posY) {
|
||||
return (sky.PointerEvent event) {
|
||||
if (longPressStopwatch == null)
|
||||
return;
|
||||
// Pointer down was a touch event.
|
||||
if (longPressStopwatch.elapsedMilliseconds < 250) {
|
||||
probe(posX, posY);
|
||||
} else {
|
||||
// Long press flags.
|
||||
flag(posX, posY);
|
||||
}
|
||||
longPressStopwatch = null;
|
||||
};
|
||||
}
|
||||
|
||||
Widget buildBoard() {
|
||||
bool hasCoveredCell = false;
|
||||
List<Flex> flexRows = <Flex>[];
|
||||
@@ -128,7 +109,13 @@ class MineDiggerApp extends App {
|
||||
if (state == CellState.covered) {
|
||||
row.add(new Listener(
|
||||
onPointerDown: _pointerDownHandlerFor(ix, iy),
|
||||
onPointerUp: _pointerUpHandlerFor(ix, iy),
|
||||
onGestureTap: (_) {
|
||||
probe(ix, iy);
|
||||
},
|
||||
onGestureLongPress: (_) {
|
||||
activity.userFeedback.performHapticFeedback(activity.HapticFeedbackType_LONG_PRESS);
|
||||
flag(ix, iy);
|
||||
},
|
||||
child: new CoveredMineNode(
|
||||
flagged: false,
|
||||
posX: ix,
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'dart:async';
|
||||
import 'package:sky/mojo/shell.dart' as shell;
|
||||
import 'package:sky_services/activity/activity.mojom.dart';
|
||||
|
||||
export 'package:sky_services/activity/activity.mojom.dart' show Intent, ComponentName, StringExtra, SystemUIVisibility_STANDARD, SystemUIVisibility_FULLSCREEN, SystemUIVisibility_IMMERSIVE;
|
||||
export 'package:sky_services/activity/activity.mojom.dart';
|
||||
|
||||
/// Dart wrapper around Activity mojo service available in Sky on Android.
|
||||
///
|
||||
@@ -27,6 +27,15 @@ ActivityProxy _initActivity() {
|
||||
|
||||
final ActivityProxy _activity = _initActivity();
|
||||
|
||||
UserFeedbackProxy _initUserFeedbackProxy() {
|
||||
UserFeedbackProxy proxy = new UserFeedbackProxy.unbound();
|
||||
_activity.ptr.getUserFeedback(proxy);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
final UserFeedbackProxy _userFeedbackProxy = _initUserFeedbackProxy();
|
||||
final UserFeedback userFeedback = _userFeedbackProxy.ptr;
|
||||
|
||||
Color _cachedPrimaryColor;
|
||||
String _cachedLabel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user