| OLD | NEW |
| (Empty) |
| 1 #!mojo sky_viewer.mojo | |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 // Use of this source code is governed by a BSD-style license that can be | |
| 4 // found in the LICENSE file. | |
| 5 | |
| 6 // To run: mojo/devtools/common/mojo_run --sky \ | |
| 7 // examples/dart/camera_roll/camera_roll.dart --android | |
| 8 // This example makes use of mojo:camera_roll which is available only when | |
| 9 // running on Android. | |
| 10 | |
| 11 import 'dart:async'; | |
| 12 import 'dart:sky'; | |
| 13 | |
| 14 import 'package:mojom/mojo/camera_roll.mojom.dart'; | |
| 15 import 'package:sky/mojo/embedder.dart'; | |
| 16 | |
| 17 final CameraRollServiceProxy cameraRoll = new CameraRollServiceProxy.unbound(); | |
| 18 int photoIndex = 0; | |
| 19 | |
| 20 Picture draw(Image image) { | |
| 21 PictureRecorder canvas = new PictureRecorder(view.width, view.height); | |
| 22 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0); | |
| 23 canvas.scale(view.width / image.width, view.height / image.height); | |
| 24 canvas.drawImage(image, 0.0, 0.0, paint); | |
| 25 return canvas.endRecording(); | |
| 26 } | |
| 27 | |
| 28 void drawNextPhoto() { | |
| 29 var future = cameraRoll.ptr.getPhoto(photoIndex); | |
| 30 future.then((response) { | |
| 31 if (response.photo == null) { | |
| 32 cameraRoll.ptr.update(); | |
| 33 photoIndex = 0; | |
| 34 drawNextPhoto(); | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 new ImageDecoder(response.photo.content.handle.h, (image) { | |
| 39 if (image != null) { | |
| 40 view.picture = draw(image); | |
| 41 view.scheduleFrame(); | |
| 42 } | |
| 43 }); | |
| 44 }); | |
| 45 } | |
| 46 | |
| 47 bool handleEvent(Event event) { | |
| 48 if (event.type == "pointerdown") { | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 if (event.type == "pointerup") { | |
| 53 photoIndex++; | |
| 54 drawNextPhoto(); | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 void main() { | |
| 62 embedder.connectToService("mojo:camera_roll", cameraRoll); | |
| 63 view.setEventCallback(handleEvent); | |
| 64 drawNextPhoto(); | |
| 65 } | |
| OLD | NEW |