rapid android development - the pragmatic programmermedia.pragprog.com/titles/dsproc/toc.pdf ·...

8
Extracted from: Rapid Android Development Build Rich, Sensor-Based Applications with Processing This PDF file contains pages extracted from Rapid Android Development, published by the Pragmatic Bookshelf. For more information or to purchase a paperback or PDF copy, please visit http://www.pragprog.com. Note: This extract contains some colored text (particularly in code listing). This is available only in online versions of the books. The printed versions are black and white. Pagination might vary between the online and printed versions; the content is otherwise identical. Copyright © 2013 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. The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina

Upload: buidat

Post on 24-May-2018

221 views

Category:

Documents


2 download

TRANSCRIPT

Extracted from:

Rapid Android DevelopmentBuild Rich, Sensor-Based Applications with Processing

This PDF file contains pages extracted from Rapid Android Development, publishedby the Pragmatic Bookshelf. For more information or to purchase a paperback or

PDF copy, please visit http://www.pragprog.com.

Note: This extract contains some colored text (particularly in code listing). Thisis available only in online versions of the books. The printed versions are blackand white. Pagination might vary between the online and printed versions; the

content is otherwise identical.

Copyright © 2013 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.

The Pragmatic BookshelfDallas, Texas • Raleigh, North Carolina

Rapid Android DevelopmentBuild Rich, Sensor-Based Applications with Processing

Daniel Sauter

The Pragmatic BookshelfDallas, Texas • Raleigh, North Carolina

Many of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks. Where those designations appear in this book, and The PragmaticProgrammers, LLC was aware of a trademark claim, the designations have been printed ininitial 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 assumesno responsibility for errors or omissions, or for damages that may result from the use ofinformation (including program listings) contained herein.

Our Pragmatic courses, workshops, and other products can help you and your team createbetter software and have more fun. For more information, as well as the latest Pragmatictitles, please visit us at https://pragprog.com.

The Android robot is reproduced from work created and shared by Google and is usedaccording to terms described in the Creative Commons 3.0 Attribution License (http://cre-ativecommons.org/licenses/by/3.0/us/legalcode).

The team that produced this book includes:

John Osborn (editor)Potomac Indexing, LLC (indexer)Molly McBeath (copyeditor)David J Kelly (typesetter)Janet Furlow (producer)Ellie Callahan (support)

For international rights, please contact [email protected].

Copyright © 2013 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-2Encoded using the finest acid-free high-entropy binary digits.Book version: P3.0—May 2015

Contents

Foreword . . . . . . . . . . . . . . ?Acknowledgments . . . . . . . . . . . ?Preface . . . . . . . . . . . . . . ?

Part I — Getting Started withthe Touch Screen and Android Sensors

1. Getting Started . . . . . . . . . . . . ?Install the Required Software ?Write Your First Android Sketch ?Run a Sketch in the Android Emulator ?Run a Sketch on an Android Device ?Wrapping Up ?

2. Working with the Touch Screen Display . . . . . . ?Introducing the Android Touch Screen ?Using Colors ?Use Mouse Speed to Control Hues ?Introducing the Ketai Library ?Install the Ketai Library ?Working with the KetaiGesture Class ?Detect Multitouch Gestures ?Wrapping Up ?

3. Using Motion and Position Sensors . . . . . . . ?Introducing the Device Hardware and Software Layers ?Introducing Common Android Sensors ?Working with the KetaiSensor Class ?List the Built-In Sensors on an Android Device ?Display Values from the Accelerometer ?

Display Values from Multiple Sensors ?Build a Motion-Based Color Mixer and Palette ?Save a Color ?Build a Palette of Colors ?Erase a Palette with a Shake ?Wrapping Up ?

Part II — Working with Camera and Location Devices

4. Using Geolocation and Compass . . . . . . . . ?Introducing the Location Manager ?Working with the KetaiLocation Class ?Setting Sketch Permissions ?Determine Your Location ?Working with the Location Class ?Determine the Distance Between Two Locations ?Determine the Speed and Bearing of a Moving Device ?Find Your Way to a Destination ?Find a Significant Other (Device) ?Wrapping Up ?

5. Using Android Cameras . . . . . . . . . . ?Introducing the Android Camera and APIs ?Working with the KetaiCamera Class ?Display a Back-Facing Camera Full-Screen Preview ?Toggle Between the Front- and Back-Facing Cameras ?Snap and Save Pictures ?Superimpose and Combine Images ?Detect and Trace the Motion of Colored Objects ?Detect Faces ?Wrapping Up ?

Part III — Using Peer-to-Peer Networking

6. Networking Devices with Wi-Fi . . . . . . . . ?Working with Wi-Fi on Android Devices ?Working with Networking Classes ?Using the Open Sound Control Networking Format ?Network an Android with a Desktop PC ?Share Real-Time Data ?

Contents • vi

Network a Pair of Androids for a Multiplayer Game ?Wrapping Up ?

7. Peer-to-Peer Networking Using Bluetooth and Wi-Fi Direct . . ?Introducing Short-Range Networking and UI Classes ?Working with the KetaiBluetooth Class ?Introducing Bluetooth ?Working with the Android Activity Life Cycle ?Connect Two Android Devices via Bluetooth ?Create a Survey App Using Bluetooth ?Working with Wi-Fi Direct ?Use Wi-Fi Direct to Control Remote Cursors ?Wrapping Up ?

8. Using Near Field Communication (NFC) . . . . . . ?Introducing NFC ?Working with the KetaiNFC Class and NDEF Messages ?Share a Camera Preview Using NFC and Bluetooth ?Read a URL from an NFC Tag ?Write a URL to an NFC Tag ?Wrapping Up ?

Part IV — Working with Data

9. Working with Data . . . . . . . . . . . ?Introducing Databases ?Working with the Table Class and the File System ?Working with Android Storage ?Read a Tab-Separated Grocery List ?Read Comma-Separated Web Color Data ?Save User Data in a TSV File ?Write Data to External Storage ?Visualize Real-Time Earthquake Data ?Add Vibes to the Earthquake App ?Wrapping Up ?

10. Using SQLite Databases . . . . . . . . . . ?Working with SQLite Databases ?Working with the KetaiSQLite Class ?Implement a Data Table in SQLite ?Record Sensor Data into a SQLite Database ?

Contents • vii

Refine SQLite Results Using WHERE Clauses ?Wrapping Up ?

Part V — Creating 3D Graphics and Cross-Platform Apps

11. Introducing 3D Graphics with OpenGL . . . . . . ?Introducing 3D Graphics and OpenGL ?Work with 3D Primitives and Lights ?Apply an Image Texture ?Use the Camera Preview as 3D Texture ?Work with Spot and Point Lights ?Use Custom Fonts and Large Amounts of Text ?Wrapping Up ?

12. Working with Shapes and 3D Objects . . . . . . . ?Working with the PShape Class ?Working with SVG Graphics and Maps ?Map the United States ?An Architectural Model Loaded from an Object File ?Create a Möbius Shape and Control It Using the Gyroscope ?Use GPU Memory to Improve Frame Rate ?Control a Virtual Camera with Your Gaze ?Wrapping Up ?

13. Sharing and Publishing Applications . . . . . . . ?Share Your Code ?Brand Your App ?Move Your App to Eclipse ?Publish Your App to Google Play ?Package Your App to Run in HTML5-Ready Browsers ?Wrapping Up ?

A1. Miscellaneous Notes . . . . . . . . . . . ?Android Version History ?The Ketai Library Classes ?Writing to a Text File on a Web Server ?Troubleshooting ?

Bibliography . . . . . . . . . . . . . ?Index . . . . . . . . . . . . . . . ?

Contents • viii