Chrome’s file browser handler

During the day 2 keynote of Google I/O, I was excited to see Box’s integration with the Chromebook’s file browser handler getting demoed on the big stage. The integration makes local files and files you encounter on the web easily accessible to cloud services inside Chrome OS.

Chrome’s file browser handler utilizes the new HTML5 file system API, designed to enable web applications to interact with local files. This API lets web applications read files, edit files, and create new files within a designated local space on a user’s machine. This includes creating binary files for application data, and in Box’s case, accessing user-created files to let people easily move their content to the cloud.

As mentioned during the Google I/O keynote, the integration between Box and the Chrome OS file browser handler only took our team a weekend to build. We were able to build the integration quickly because of the simplicity of both Chrome’s file browser platform and Box’s API, both of which were designed to make content integrations like this easy for developers to implement.

In this case, the Quick Importer tool from the Box API made the entire development process just a few steps:

1. We created a Chrome extension manifest to work with Box.

{
 "name”: "Box Uploader",
 ...
 "file_browser_handlers": [
     {
      "id”: "upload",
      "default_title": "Save to Gallery", // What the button will display
      "file_filters": [
       ]
     }
   ],

2. In the Chrome manifest, we specified the relevant file types to which the service applies. In our case, that’s most file types, as seen below. Specialized services may just want certain types, such as images for Picasa.

"file_browser_handlers": [
     {
      "id": "upload",
      "default_title": "Save to Box",
      "file_filters": [
       "filesystem:*.*"
       ]
     }
   ],

3. With some JavaScript code connecting to the file browser handler, we set up a way to upload files through Box’s Quick Importer.

<strong>var</strong> fm = <strong>new</strong> FileManager<strong>()</strong>;
fm.uploadServer = 'https://www.box.net/&lt;...&gt;';

<strong>if</strong> <strong>(</strong>bgPage <strong>&amp;&amp;</strong> bgPage.filesToUpload.length<strong>)</strong> <strong>{</strong>
 <strong>var</strong> entry;
 <strong>while(</strong>entry = bgPage.filesToUpload.pop<strong>())</strong> <strong>{</strong>
   entry.file<strong>(function(</strong>file<strong>)</strong> <strong>{</strong>
     fm.uploadFile<strong>(</strong>file<strong>)</strong>;
   <strong>})</strong>;
 <strong>}</strong>
<strong>}</strong>

That’s actually all there was to the integration.

Once the file is uploaded to the Box API’s Quick Import URL, our page is displayed to authenticate the user, to let the user select a Box folder to save the file, and then to upload the file.

While such an integration can be customized through our API, our Quick Import provided an easy and fast means to connect the platforms. Developers can customize the integration by using direct calls to our API, and take advantage of additional features such as automatic sharing, if they prefer.

Thanks to the simplicity of Chrome’s file browser handler and some extra tools in the Box API, our development time was very short (just a weekend), but it could have actually been even quicker. We had a couple of unusual complications that weekend:

1. The Google Chrome team was still experimenting with the file browser, so development from both sides was happening in parallel, which can be a bit tricky. Now that the file browser has been thoroughly tested, you should have an even easier time.

2. I took my girlfriend out a couple times, since her final exams were coming up soon afterward. I love you, Hayley!

Once the content has been uploaded to Box, it’s accessible to many Google services, including Gmail, Google Docs, and Google Calendar, through additional integrations on our site with Google Apps. Ah, the wonders of open platforms.

Watching the Lunar Eclipse

We’re always fascinated by the unique wonders of space and the world—what can we say, it’s the geek in us! Naturally, when we learned that part of the world will be treated to a rare 100-minute long total lunar eclipse starting at 11:20am PDT today, we were both excited and disappointed that this rare occasion wouldn’t be visible from our Mountain View campus like last year’s eclipse. We suspect we aren’t alone, so you’ll be glad to know that we’ve worked with Slooh Space Camera to let you experience the spectacle wherever you are in the world, in real time.


Slooh will host a live mission interface using Google App Engine that lets anyone not lucky enough to live in certain areas (South America, Europe, Africa, Asia and Australia) take part in this rare astronomical event. It’s equipped with audio narrations from real-life astronomers so you can hear a firsthand, expert account of the event. You can also watch the live stream on the Google YouTube Channel or from the Sky layer in Google Earth (download this kml), while exploring the fascinating world that exists in our galaxy. Finally, those of you on the go can download the Slooh Space Camera Android app to view the images right on your phone.

If you’re fortunate enough to be able to view this event in the sky, we hope you’ll get the chance to step outside and indulge in the spectacle. For everyone else, we hope our moon madness helps brighten your day.

WebGL experience for the modern browser

Last August, we released “The Wilderness Downtown”, a music experience that brought together HTML5 and JavaScript, as well as the Google Maps and Street View APIs. Today, we’re excited to introduce our newest project, “3 Dreams of Black”, made with WebGL, HTML5 and JavaScript, and designed for modern browsers like Google Chrome. We previewed this music experience yesterday with web developers at Day 2 of the Google I/O keynote.

“3 Dreams of Black” takes you on a journey through three dream worlds constructed through a combination of rich 2D drawings and animations interwoven with interactive 3D sequences. Throughout various points in these dream worlds, you can grab your mouse and guide the protagonist’s point of view through the experience. This music experience also includes a 3D model creator that allows you to create your own relics and contribute to the shared collective dream. “3 Dreams of Black” is written and directed by Chris Milk, and developed with a few folks here at Google.

In creating “3 Dreams of Black”, we’ve had the opportunity to build many tools, libraries, and models. We’ve fully opened up the source code and made it available for web developers to tinker with us at www.ro.me/tech. In addition to the code, a few other highlights include eight WebGL demos, a fun model viewer for interacting with some of the animals from the web experience, and the Three.js 3D library used for building the experience. In addition, a big part of the project was to define a good pipeline for getting all the animals and environment models right in WebGL — for this, we extended Blender with custom plugins so we could manipulate and export the data with ease.

“3 Dreams of Black” is set to the song “Black” off the album ROME, presented by Danger Mouse & Daniele Luppi, featuring Jack White and Norah Jones on vocals, to be released soon on the record label EMI. Because it’s built in WebGL, it requires a WebGL-supported browser like Chrome, and Windows Vista / Mac OS X 10.6 and above to help ensure that your computer has the necessary and up-to-date graphics drivers. We hope you’ll take a moment to dive into the experience and the developer resources at www.ro.me

Ricardo Cabello is a designer/developer in the Google Data Arts Team. He is the creator of several popular Chrome Experiments, including Google Gravity, Ball Pool, and Harmony.

How to Autocomplete Email Addresses in Apps Script

When composing Gmail conversations, the auto-complete feature allows us to see our matching personal contacts as we type and quickly make our contact selections. This time-saving feature can be duplicated when creating Google Apps Script applications. For instance, if you design an application that requires sending emails, you can leverage this auto-complete feature by using a personal contact list.

Defining the Requirements

By observing the behavior while composing Gmail conversations, we can define the requirements of our application.

1. As the user begins typing, a list of matches based on first and last name and email address need to appear under the text box. In other words, the user can begin typing the contacts first name, last name, or their email address.

2. If the desired contact email is listed at the top of the matching list, the user can simply press the Enter key to select it.

3. Another option is to click on any of the contacts in the list.

4. Just in case the user would like to enter an email that is not in their contact list, they may enter the email and press the Enter key.

As an added feature if the email is not formatted correctly, then the invalid email is ignored and not selected. For our application when emails are selected, they will be compiled in a separate list on the right where only the email address is stored. If an email is selected by accident, the user can remove the email by clicking on it.

Designing the Application

The application was designed to mimic the behavior of composing Gmail messages. By doing so, the application avoided the use of buttons, providing an improved user experience.

1. Apps Script Services

The Apps Script’s Spreadsheet Service was used to store a user’s contact data. The Ui Service provided the application interaction with the user, and the Contacts Service was leveraged to gather all the user’s contacts. You may apply a Google Apps domain only filter for the contacts by changing the global variable to “true” in the script.

2. Visualize the Layout

Before writing code, the layout was sketched out to include a text box, some space beneath to list matches, and an area to the right to display the selected emails.

3. Choose your widgets

A text box widget was chosen to allow email entry, and two open list boxes were leveraged to display contact matches and selected emails. List boxes provided the use of click handlers to process email selections.

4. Challenges

To mimic the Gmail auto-complete behavior, the text box needed the ability to handle both keystrokes and a pressed Enter key. To accomplish this, a KeyUpHandler calls a function to identify contact matches via a search. The same function used an e.parameter.keyCode == 13 condition to determine when the enter key is pressed.

<span>//create text box for auto-complete during email lookup in left grid</span>
  var textBox = app.createTextBox().setName(<span>'textBox'</span>)
 .setWidth(<span>'330px'</span>).setId(<span>'textBox'</span>);  
var tBoxHandler = app.createServerKeyHandler(<span>'search_'</span>);
  tBoxHandler.addCallbackElement(textBox);  textBox.addKeyUpHandler(tBoxHandler);
   ...function search_(e){  var app = UiApp.getActiveApplication();  app.getElementById(<span>'list'</span>).clear();
   var searchKey = new RegExp(e.parameter.textBox,<span>"gi"</span>); 
 <span>if</span> (searchKey == "") app.getElementById(<span>'textBox'</span>).setValue(<span>''</span>);
  var range = sheetOwner.getRange(1, 1, sheetOwner.getLastRow(), 2).getValues();  var listBoxCount = 0;
  var firstOne = <span>true</span>;  <span>for</span> (var i in range){    
 // if first/last name available, display name and email address     <span>if</span>
 (range[i][0].search(searchKey) != -1 || range[i][1].search(searchKey) != -1){       <span>if</span>
 (range[i][0].toString()){          app.getElementById(<span>'list'</span>).addItem(range[i][0].toString()+ 
         ' .. '+range[i][1].toString(), range[i][1].toString()); 
          var listBoxCount = listBoxCount + 1;       } <span>else</span> { // else just display the email address 
         app.getElementById
(<span>'list'</span>).addItem(range[i][1].toString());           var listBoxCount = listBoxCount + 1;       }   
    <span>if</span> (firstOne) var firstItem = range[i][1].toString();       var firstOne = <span>false</span>;
     }    }  
// set the top listbox item as the default  <span>if</span> (listBoxCount &gt; 0) app.getElementById(<span>'list'
</span>)
.setItemSelected(0, true);
  <span>
// if enter key is pressed in text box, assume they want to add</span>  <span>// the email that’s not in the list</span>  <span>if</span>
 (e.parameter.keyCode==13 &amp;&amp; listBoxCount &lt; 1 &amp;&amp; searchKey !== <span>""</span>) {   ...

As this application shows, Apps Script is very powerful. Apps Script has the ability to create applications which allow you to integrate various Google services while building complex user interfaces.

 

You can find Dito’s Email Auto-Complete Script here. To view a video demonstration click here. You can also find Dito Directory on the Google Apps Marketplace.

Sketchup:The Fat Pencil Studio

The company name “Fat Pencil” refers to the traditional drawing instrument used by architects during the early stages of conceptual design—when it’s important to get ideas on paper quickly, and avoid getting bogged down by details. Google SketchUp Pro provides a digital equivalent of this practice, and it’s been an essential tool for us since Fat Pencil Studio was founded in 2004.

Fat Pencil Studio creates technical graphics for legal, transportation, and construction professionals. Some examples are courtroom exhibits, infrastructure visualization and site logistics diagrams. Our staff have engineering and architecture backgrounds. We use this experience to develop compelling visual presentations for complex projects.

This trial exhibit is designed to allow witnesses to identify their vantage point in a birds-eye view, and then zoom to a street-level perspective using the Position Camera tool.
In this construction diagram, pre-assembled pipe sections are lowered into a utility tunnel.

Last year, we helped the City of Seattle visualize the reconfigured Broadway and Jackson Street intersection along the proposed alignment for the First Hill Streetcar extension. URS (the prime contractor for the project) had already developed 2D design drawings in AutoCAD. They needed 3D perspectives for public stakeholder meetings and regulatory filings. Once the model was created, Alta Planning (another member of the design team) was able to use it as a design tool. Each intersection could now be seen from multiple perspectives: driving, cycling, and walking. This allowed Alta to identify and address safety issues related to a two-way Cycle Track proposed for the reconfigured street.

Aerial view of the proposed Broadway and Pike Street Station.

The buildings in this area of Seattle are already in Google Earth’s 3D Buildings layer, so we initially considered importing street features into Google Earth to create a presentation. However, the difficulty of matching terrain over such a large area forced us to scrap this plan. SketchUp Pro offers more flexibility for presenting the details that matter most in this project; namely, the new street configuration. After cleaning up the AutoCAD drawings, we draped the linework over imported terrain and then added 3D features. We used several plugins to help reduce modeling time: Projections V2 helped with the curbs. Drop and RepeatCopy helped us place trees, cars, bikes and people. We also had some help from the 3D Warehouse, including an excellent streetcar model by JediCharles.

Street level view of the 2nd Avenue and King Street Station.

The streetcar project also gave us an opportunity to collaborate with another firm. IBI Group of Portland was responsible for station design and also modeling the southern half of the 2.5 mile streetcar alignment. Their half of the model was created in SketchUp on Windows, using terrain data from a street survey. Our half was modeled with SketchUp on a Mac, using terrain data from Google’s servers. The terrain matched almost perfectly at the seam, with only minor “smooving” needed. Using the combined model, we were able to generate dozens of still image views and several flyover animations.

Existing conditions at North Vancouver and Broadway in Portland, Oregon.
Turning on “Hidden Geometry” reveals the component segments used to build street markings.

Currently, we are working on a project to present options for safety improvements in a few sections of Portland’s extensive bikeway system. In this case we did not have detailed CAD drawings as a starting point; this gave us an opportunity to try a new approach for modeling street markings. Using high-resolution satellite images as a reference, we traced a single line along the center of existing markings. The PathCopy script allows us to “paint” the street markings as a series of components. Spacing can be configured for dashed lines, or set to zero for solid lines.