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 @@
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,33 +84,13 @@ 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;
};
}
......@@ -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;
......
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