Programming Google Glass
The Mirror API
by Eric Redmond
Version: P1.0 (December 2013)
Copyright 2013 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
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 and the linking g device are trademarks 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.
Table of Contents
Copyright 2013, The Pragmatic Bookshelf.
Early praise for Programming Google Glass
Erics writing captures the spirit of Glassware development with honesty, wit, and charmpeppered with a healthy dose of insider tricks and techniques for quickly building effective wearable computing services that coders of all levels will appreciate.
Jason Salas |
Coauthor, Think for Glass: Discover, Design, Develop |
This insightful book opened my eyes to the potential of Google Glass in a big way. Glassware is going to be huge, and this book gives you the tools to make it.
Jim Wilson |
Author, Node.js the Right Way |
A great read and learning resource. You start with a small project and build it into a full-fledged Glassware application, learning all about the Mirror API along the way.
Steven Mitchell |
Glass Explorer |
I really enjoyed your book; you successfully convinced me to buy Glass and start learning as much about it as I can. Its not like the tech is going to disappear if I ignore it!
Marissa Anderson |
Principal Developer, Electrozoic |
This is a great introduction to the Google Glass Mirror API. Any serious Google Glass developer will want to get a copy of this book.
Mark Billinghurt |
Director, HIT Lab NZ, University of Canterbury |
Acknowledgements
All books, even short ones like this, require efforts that extend far beyond a single author. Although I get to put my name on the cover, I want to thank everyone who helped turn a collection of drafts and ideas into a book we all hope youll enjoy.
Thanks first go to my indefatigable editor, Jackie Carter. Thanks, too, to Susannah, Andy, Dave, and the rest of the crew at Pragmatic for keeping this ship sailing straight.
Im thrilled to thank my eagle-eyed friend Jim Wilson, and the piles of notes from a cadre of talented Glass Explorers: Jason Salas, Steven Mitchell, Marissa Anderson, Mark Billinghurst, Elmer Thomas, and Rahul Ravikumar.
Finally, thanks to my patient wife Noelle for enduring another book, and a preemptive thanks to Miss Wiggles for tolerating the next one.
Copyright 2013, The Pragmatic Bookshelf.
Preface
Google Glass is the new wearable computer that everyone is talking about. Not only does Glass offer a head-mounted optical display and touch interface, but its also programmable in two ways: by creating native applications using the Glass Development Kit (GDK), and by programming Glassware (Glass applications) using the HTTP-based Mirror API. This book is about the latter.
Youll get a glimpse of what Glass is and what it is not, and how users can interface with Glass. Then youll learn how to develop a Glass application fast, by using the Mirror API to manipulate timeline cards and menus, track a Glasss geolocation, create rich interactions by responding to user inputs, and capture or serve user images and videos. Youll see how to properly design new Glassware or update existing applications to become Glassware. This is the book to read if you want a shortcut to this brave new world.
Whats the Big Deal with Glass?
The first future-facing movie that I can recall containing consumer HUD (heads-up display) goggles was Back to the Future 2 . This HUD was worn in the future year 2015 (I know, right?), not by a military commander or an airship pilot, but by young Marty McFly, Jr., as he sat with his family around the kitchen table. This was a consumer device capable of, at least, displaying text and accepting phone calls. Google Glass has beaten that mark by a year.
Although Glass is sometimes wrongly considered to be an augmented-reality device, its better thought of as an ever-present optical interface for a mobile device. Its a self-contained computer, yes, but it is also reliant on an external paired smartphone for some actions, such as geolocation or continuous Internet access. Internet access is a necessary component for using Glassware with the Mirror API, in the same way that Twitter is usable only if you have online access.
This is a powerful requirement, since it means your Glassware can connect users and allow them to share assets. You can store and retrieve each of your Glass users information in the cloud, and easily connect the same data through Glass, smartphones, and the Web.
Is This Book for You?
This book is designed to help experienced developers quickly start writing Google Glass applications with the Mirror API. Although this book covers using the interface with Googles Java Mirror Client code, the Mirror API itself is an HTTP interface with support for many languages. This means that many of the lessons about the Mirror API itself can apply to languages beyond the simple Java client.
The pertinent code is covered in the book, and the rest can be downloaded along with the book (or from GitHub.) You neednt be a Java expert to use this book, but it can help to know your way around the syntax and Eclipse editor. You may also get more out of this book if youre familiar with Google App Engine, although you can use any Platform as a Service (PaaS) or host your own Glassware applications.
Whats in This Book?
This book is about programming Google Glass by using the Mirror API, but theres more information to know beyond the technicals of one API. We start with an overview of the Glass environment in Chapter 1, .
The middle of the book digs into the actual Mirror API, starting with Chapter 4, .
We wrap up the book with an eye on design in Chapter 7, .
This book is intended to be read linearly, from the first to last chapter. It does cover most of the Mirror API, but its not designed to be a reference book. However, there is a reference in Appendix 1, .
Online Resources
You can download the code and other resources used in this book from the Pragmatic Bookshelf website or my GitHub repository. You are free to use this source code for anything you wish.