ebook img

Rapid Android Development: Build Rich, Sensor-Based Applications with Processing PDF

384 Pages·2016·43.89 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Rapid Android Development: Build Rich, Sensor-Based Applications with Processing

Prepared exclusively for ricardo palmieri Under Construction: The book you’re reading is still under development. As part of our Beta book program, we’re releasing ß this copy well before a normal book would be released. That way you’re able to get this content a couple of months before it’s available in finished form, and we’ll get feedback to make the book even better. The idea is that everyone wins! Be warned: The book has not had a full technical edit, so it will contain errors. It has not been copyedited, so it will be full of typos, spelling mistakes, and the occasional creative piece of grammar. And there’s been no effort spent doing layout, so you’ll find bad page breaks, over-long code lines, incorrect hyphen- ation, and all the other ugly things that you wouldn’t expect to see in a finished book. It also doesn't have an index. We can’t be held liable if you use this book to try to create a spiffy application and you somehow end up with a strangely shaped farm implement instead. Despite all this, we think you’ll enjoy it! Download Updates: Throughout this process you’ll be able to get updated ebooks from your account at pragprog.com/my_account. When the book is com- plete, you’ll get the final version (and subsequent updates) from the same ad- dress. Send us your feedback: In the meantime, we’d appreciate you sending us your feedback on this book at pragprog.com/titles/dsproc/errata, or by using the links at the bottom of each page. Thank you for being part of the Pragmatic community! Andy & Dave Prepared exclusively for ricardo palmieri Rapid Android Development Build Rich, Sensor-Based Applications with Processing Daniel Sauter The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Prepared exclusively for ricardo palmieri Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com. Copyright © 2012 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-93778-506-2 Encoded using the finest acid-free high-entropy binary digits. Book version: B4.0—November 12, 2012 Prepared exclusively for ricardo palmieri Contents Change History . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . xi Preface . . . . . . . . . . . . . . xiii Part I — Getting Started with the Touch Screen and Android Sensors 1. Getting Started . . . . . . . . . . . . 3 1.1 Install the Required Software 4 1.2 Write Your First Android Sketch 6 1.3 Run a Sketch in the Android Emulator 13 1.4 Run a Sketch on an Android Device 15 1.5 Wrapping Up 16 2. Working With The Touch Screen Display . . . . . . 17 2.1 Work with the Android Touch Screen 18 2.2 Control Grayscale Values Using motionPressure 21 2.3 Using Colors 24 2.4 Use Touch Screen Pressure to Control Color Hues 28 2.5 Introducing the Ketai Library 31 2.6 Install the Ketai library 33 2.7 Working With the KetaiGestureClass 34 2.8 Detect Multi-Touch Gestures 35 2.9 Wrapping Up 42 3. Using Motion and Position Sensors . . . . . . . 43 3.1 Introducing the Device Hardware and Software Layers 44 3.2 Introducing Common Android Sensors 45 3.3 Working With the KetaiSensor Class 47 3.4 List the Built-in Sensors on an Android Device 47 3.5 Display Values from the Accelerometer 50 Prepared exclusively for ricardo palmieri Contents • iv 3.6 Display Values from Multiple Sensors 53 3.7 Build a Motion-based Color Mixer and Palette 57 3.8 Save a Color 61 3.9 Build a Palette of Colors 64 3.10 Erase a Palette with a Shake 68 3.11 Wrapping Up 72 Part II — Working with Camera and Location Devices 4. Using Geolocation and Compass . . . . . . . . 77 4.1 Introducing the Location Manager 78 4.2 Working With the KetaiLocation Class 80 4.3 Determine Your Location 81 4.4 Setting Sketch Permissions 83 4.5 Working With the Location Class 86 4.6 Determine the Distance Between Two Locations 87 4.7 Determine the Speed and Bearing of a Moving Device 90 4.8 Find Your Way to a Destination 92 4.9 Find a Significant Other (Device) 96 4.10 Wrapping Up 100 5. Using Android Cameras . . . . . . . . . 103 5.1 Introducing the Android Camera and APIs 104 5.2 Working With the KetaiCamera Class 105 5.3 Display a Back-Facing Camera Full-Screen Preview 106 5.4 Toggle Between the Front- and Back-Facing Cameras 110 5.5 Snap and Save Pictures 114 5.6 Superimpose and Combine Images 119 5.7 Detect and Trace the Motion of Colored Objects 125 5.8 Detect Faces 131 5.9 Wrapping Up 135 Part III — Using Peer-To-Peer Networking 6. Networking Devices with WiFi . . . . . . . . 139 6.1 Working with WiFi on Android Devices 140 6.2 Working with Networking Classes 141 6.3 Using the Open Sound Control Networking Format 143 6.4 Network an Android with a Desktop PC 144 6.5 Share Real Time Data 153 Prepared exclusively for ricardo palmieri Contents • v 6.6 Network a Pair of Androids for a Multiplayer Game 158 6.7 Wrapping Up 164 7. Peer-To-Peer Networking Using Bluetooth and WiFi Direct . 165 7.1 Introducing Short-Range Networking and UI Classes 166 7.2 Working with the KetaiBluetooth Class 167 7.3 Introducing Bluetooth 168 7.4 Working with the Android Activity Lifecycle 168 7.5 Connect Two Android Devices Via Bluetooth 170 7.6 Create A Survey App Using Bluetooth 181 7.7 Working with WiFi Direct 197 7.8 Use WiFi Direct To Control Remote Cursors 198 7.9 Wrapping Up 204 8. Using Near Field Communication (NFC) . . . . . . 205 8.1 Introducing NFC 206 8.2 Working with the KetaiNFC Class and NDEF Messages 209 8.3 Share a Camera Preview Using NFC and Bluetooth 210 8.4 Read a URL from an NFC Tag 220 8.5 Write a URL to an NFC Tag 225 8.6 Wrapping Up 228 Part IV — Working with Data 9. Working With Data . . . . . . . . . . . 233 9.1 Introducing Databases 234 9.2 Working with the Table Class and the File System 235 9.3 Working with the Android Storage 236 9.4 Read A Tab-separated Grocery List 237 9.5 Read Comma-separated Web Color Data 241 9.6 Save User Data in a TSV File 245 9.7 Write Data to the External Storage 250 9.8 Visualize Real-Time Earthquake Data 252 9.9 Add Vibes to the Earthquake App 260 9.10 Wrapping Up 265 10. Using SQLiteDatabases . . . . . . . . . . 267 10.1 Working with SQLite Databases 268 10.2 Working With the KetaiSQLite Class 268 10.3 Implement A Data Table in SQLite 269 10.4 Record Sensor Data Into a SQLite Database 274 Prepared exclusively for ricardo palmieri Contents • vi 10.5 Refine SQLite Results using WHERE Clauses 280 10.6 Wrapping Up 284 Part V — Creating 3D Graphics and Cross-platform Apps 11. Introducing 3D Graphics With OpenGL . . . . . . 287 11.1 Introducing 3D Graphics and OpenGL 288 11.2 Work With 3D Primitives And Lights 289 11.3 Apply An Image Texture 293 11.4 Use the Camera Preview as 3D Texture 295 11.5 Work With Spot And Point Lights 297 11.6 Use Custom Fonts and Large Amounts of Text 301 11.7 Wrapping Up 309 12. Working With Shapes and 3D Objects . . . . . . 311 12.1 Working With the PShape Class 312 12.2 Working with SVG Graphics and Maps 313 12.3 Map the United States 314 12.4 Display an Architectural Model Loaded From an Object File 319 12.5 Create a Moebius Shape And Control It Using the Gyroscope 323 12.6 Use GPU Memory to Improve Frame Rate 330 12.7 Control a Virtual Camera With Your Gaze 332 12.8 Wrapping Up 337 13. Sharing and Publishing Applications . . . . . . 339 13.1 Sharing Your Code 339 13.2 Export a Project to Eclipse 340 13.3 Branding Your App 341 13.4 Moving Your App to Eclipse for Further Development 342 13.5 Publishing Your App to Google Play 346 13.6 Packaging Your App to Run in HTML5-Ready Browsers 354 13.7 Wrapping Up 363 A1. Appendix . . . . . . . . . . . . . 365 A1.1 Android Version History 365 A1.2 Introducing Ketai Library Classes 365 A1.3 Find Vendors 367 Prepared exclusively for ricardo palmieri Contents • vii A1.4 Writing to a Text File on a Web Server 367 A1.5 Troubleshooting 370 Bibliography . . . . . . . . . . . . 375 Prepared exclusively for ricardo palmieri Change History The book you’re reading is in beta. This means that we update it frequently. This chapter lists the major changes that have been made at each beta release of the book, with the most recent change first. Beta 4.0 November 12, 2012 • We’ve added the last chapter, Chapter 13, "Sharing and Publishing Applications" • We’ve tested and updated the code examples to work with the latest version of Processing: Version 2, Beta 6. This has allowed us, for example, to remove calls to onPause() and onResume() • In Chapter 1, "Getting Started," we’ve added links to instructions for Windows and Linux on how to install a USB driver and set up an Android device to use it • We’ve changed references to the "Standard" mode to "Java" mode to match the change on terminology in the Processing 2 • We’ve added links to the chapter by chapter overview in the "Preface" so ebook readers can to jump directly to a chapter from its description • We’ve added support to the Ketai Library Version 8 for loading an existing SQLite database and included a code snippet that shows how to use the feature in Chapter 10, "Using SQLiteDatabases". • In the "WiFiDirectCursors" example, we’ve replaced the connectToDevice(selec- tion) method with the connect() method to reflect changes to the Ketai library • We’ve changed the Android SDK Manager screenshot in "Appendix" to reflect changes in what’s required to use the Android SDK that have occurred since the release of Processing 2 Prepared exclusively for ricardo palmieri report erratum • discuss

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.