Commit 6efbcdc9 authored by Adam Barth's avatar Adam Barth

Add haptic and aural feedback service

And use the service in mine_digger to notify the user when they flag a bomb.
parent d291fcae
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'dart:math'; import 'dart:math';
import 'package:sky/mojo/activity.dart' as activity;
import 'package:sky/painting/text_style.dart'; import 'package:sky/painting/text_style.dart';
import 'package:sky/rendering/flex.dart'; import 'package:sky/rendering/flex.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
...@@ -83,33 +84,13 @@ class MineDiggerApp extends App { ...@@ -83,33 +84,13 @@ class MineDiggerApp extends App {
assert(false); assert(false);
} }
Stopwatch longPressStopwatch;
PointerEventListener _pointerDownHandlerFor(int posX, int posY) { PointerEventListener _pointerDownHandlerFor(int posX, int posY) {
return (sky.PointerEvent event) { return (sky.PointerEvent event) {
if (event.buttons == 1) { if (event.buttons == 1) {
probe(posX, posY); probe(posX, posY);
} else if (event.buttons == 2) { } else if (event.buttons == 2) {
flag(posX, posY); 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;
}; };
} }
...@@ -128,7 +109,13 @@ class MineDiggerApp extends App { ...@@ -128,7 +109,13 @@ class MineDiggerApp extends App {
if (state == CellState.covered) { if (state == CellState.covered) {
row.add(new Listener( row.add(new Listener(
onPointerDown: _pointerDownHandlerFor(ix, iy), 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( child: new CoveredMineNode(
flagged: false, flagged: false,
posX: ix, posX: ix,
......
...@@ -8,7 +8,7 @@ import 'dart:async'; ...@@ -8,7 +8,7 @@ import 'dart:async';
import 'package:sky/mojo/shell.dart' as shell; import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky_services/activity/activity.mojom.dart'; 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. /// Dart wrapper around Activity mojo service available in Sky on Android.
/// ///
...@@ -27,6 +27,15 @@ ActivityProxy _initActivity() { ...@@ -27,6 +27,15 @@ ActivityProxy _initActivity() {
final ActivityProxy _activity = _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; Color _cachedPrimaryColor;
String _cachedLabel; String _cachedLabel;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment