Adobe Edge Inspect CC is an awesome tool for synchronized browsing experiences across both desktop and mobile devices. It is incredibly powerful, and streamlines the developer & testing workflows by reducing iterations when testing HTML/JS experiences on multiple devices.
Adobe Edge Code CC is an awesome code editor for creating HTML/JS experiences. It has a live connection to the browser, so you can see your edits in the browser in real time as you are editing your code… all without having to leave the code editor.
Wouldn’t it be cool if Adobe Edge Code CC could push updates to mobile devices leveraging Adobe Edge Inspect CC? Oh wait, what? It already can? YES, it can! This is one of the coolest new features in this week’s Creative Cloud release. You can edit your code in Edge Code CC, and preview your changes live, and in real time in both the desktop browser and on mobile devices. Take a look at the video below to see it in action:
OK, so how do you get it? Become a member of Creative Cloud… Membership does have it’s perks! This is available in all of the plans, even the free option. This plugin for Edge Code CC/Brackets is also open source. Know what else is cool about Adobe Edge Inspect CC? It has an open source JavaScript API that you can leverage to integrate your own apps into an Edge Inspect workflow or continuous integration environment. It’s definitely worth checking out.
Recently I’ve undertaken some explorations with fellow evangelist Kevin Hoyt, trying to determine how far we can push PhoneGap applications with devices and physical computing. Turns out, you can push things really far and now I’m delighted to share one of the experiments that we’ve been pursuing.
I’ve been asked on more than one occasion, can you access Bluetooth devices in PhoneGap applications. The answer is YES, you can. There is not a specific “Bluetooth API” in PhoneGap, however you can create native plugins to access any native library. Basically, with a native plugin, you create the native interface (written in the native language), and a JavaScript interface. The native and JavaScript interfaces can leverage the PhoneGap native to JavaScript bridge for bidirectional communication.
In this exploration, we researched whether or not you can use a pressure sensitive stylus with a PhoneGap application. Again, the answer is YES, you can. Check out the video below to see a sample application in-action. This example demonstrates the use of a TenOne Pogo Connect Stylus inside of a PhoneGap application.
Note: This is not connected to Project Mighty in any way – Kevin and I started exploring completely separately from the big announcements at MAX.
The Pogo Connect stylus leverages Bluetooth 4 Smart (low energy) connectivity to communicate with the device, and provides pressure sensitivity and a physical button for the user to interact with. The JavaScript interface doesn’t interact directly with with the Bluetooth connection. Instead, I leveraged TenOne’s Pogo Connect SDK and created a JavaScript bridge layer to delegate pen interaction from the SDK to the JavaScript layer.
There were definitely a few tricks to get this working. First, the SDK is designed to accept touch input at the native layer, and determine whether or not that touch is from the pen. When using the SDK (in Objective-c), you are supposed to implement the touchesBegan, touchesMoved, touchesEnded, and touchesCancelled functions for a view:
In those functions, you check if any of the touches are pens, and if so, do something with that pen input.
- (void) touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
if ([pogoManager touchIsPen:touch]) {
//do something with the pen
}
}
}
The first catch with implementing this inside of a PhoneGap application is that you can’t override the touch handlers of a web view on iOS. Luckily, there is another way! I leveraged a UIGestureRecognizer instance to intercept the touch input that is received by the web view, determine if the touches were from the PogoConnect Stylus, and if so, then delegate that input back to the JS layer.
UIGestureRecognizer is normally used as a base class for creating custom gestures in iOS applications. If has everything you need to handle touch input, and it gives you that information without having to subclass an actual view. This means you can attach it to any UIView instance. Since you don’t have to subclass a view to use this, this plugin can be implemented in a PhoneGap native plugin without having to modify *any* code inside the PhoneGap framework.
So, here’s how I did it… Once the PhoneGap plugin is initialized on load, I create a gesture recognizer instance and attach it to the PhoneGap application’s web view. Whenever touch input is received by the gesture recognizer, that input is passed back to the PhoneGap plugin instance, which executes JavaScript on the web view to pass that information to the JavaScript layer in real time as it is received.
On the JavaScript layer, stylus/pen input is dispatched to the application as custom events on the window.document object. To subscribe to pen input in JavaScript, you just add event listeners for the Pogo Connect events that I defined in the native plugin’s JavaScript file.
Information about the stylus will be contained in the event.detail attribute, and will be an instance of this object (containing accurrate values about the pen’s state, of course):
In JavaScript, you can do whatever you want within your application once you receive this information.
I created two sample applications to test this functionality. The first is a very basic app that simply outputs the pressure as text which follows the pen tip. The intent with this app was really just to prove the concept and determine if it was actually possible to receive and respond to information from the stylus.
Basic Pressure Sensitivity Detection in PhoneGap
Once I proved it could be done, the next logical step was to create an app that actually takes advantage of the pressure sensitivity information. So, I made a sketching app.
Pressure Sensitive Sketching in PhoneGap
I started off by expanding on the drawing logic from my Lil’ Doodle PhoneGap application. This uses a requestAnimationFrame interval to render content in an HTML Canvas element using a “brush image” technique. Next, I added logic to vary the opacity and stroke size based on the pressure information received from the pen plugin, and a few other options to change the pen tip/brush shape and color.
The pressure sensitive stylus gives a few interesting interactions that you wouldn’t get without the hardware:
First, the obvious, you know the pressure being applied to the pen tip, and the app can respond accordingly.
Next, you have an extra input method. The button on the pen allows you to interact with the device without having to actually touch the device. I used the button in two ways: first, if the button is pressed and held, the pen erases instead of draws. Second, if you double-tap the pen button, it brings up the drawing options. These options are where I placed controls to modify the pen color and stroke.
Third, the plugin provides bidirectional communication with the Stylus. When you change the pen color, the LED on the pen will display the selected color for a few seconds.
All button and slider styling leverages Topcoat, Adobe’s brand new open source CSS framework designed to help developers build HTML-based apps with an emphasis on performance.
Note: This is iOS only – The third-party PogoConnect SDK is for iOS devices only. This example will also ONLY work if you have the PogoConnect Stylus. It does not support other stylus devices or finger-only drawing.
Last night I had the opportunity to give a presentation on Data Visualization With Web Standards to the DataVizDC meetup group. First of all, I’d like to thank the meetup group for hosting the event, and thank you to everyone who attended – It was a great event thanks to the excitement and energy brought by each of you. I promised to post a video recording, but unfortunately the video feed didn’t turn out (due to an error on my part). Luckily, I was able to save the audio feed, which you can listen to here:
You can access my presentation slides at the links below. Just use the “space” key to advance each slide.
Here is a direct link to the simple interactive data experience that was created using Adobe Edge Animate (also available for download in the Edge Animate Showcase):
Edge Animate Data Sample
Visualization Techniques
<img>
You can embed images using the html <img> element that have server-rendered data visualizations. This is nothing new… They are very basic, but will certainly work.
You can use the HTML5 <canvas> element to programmatically render content based upon data in-memory using JavaScript. The HTML5 Canvas provides you with an API for rendering graphical content via moveTo or lineTo instructions, or by setting individual pixel values manually. Learn more about the HTML5 canvas from the MDN tutorials.
Gun Violence Visualization – Please, let’s not discuss the politics.
HTML5 Canvas Scatterplot with Histogram (50K data points)
HTML5 Canvas Chart – Asteroids Analysis
HTML5 Canvas – Three.js 3D Chart
Scalable Vector Graphics (SVG)
SVG is a declarative XML-based markup language that is used to create vector graphics content, and can be used to create visual content inside of web experiences.
Visualizations such as interactive maps, or simple charts can be created purely with HTML structures and creative use of CSS styles to control position, visual presentation, etc… You can use CSS positioning to control x/y placement, and percentage-based width/height to display relative values based upon a range of data. For example, the following bar chart/table is created purely using HTML DIV containers with CSS styles.
WebGL
WebGL is on the “bleeding edge” of interactive graphics & data visualization across the web. WebGL enables hardware-accelerated 3D graphics inside the browser experience. Technically, it is not a standard, and there is varied and/or incomplete support across different browsers (http://caniuse.com/#search=webgl). There is also considerable debate whether it ever will be a standard; however there are some incredible samples out on the web worth mentioning:
WebGL – Globe w/ Arms Trading Data
WebGL – New Google Maps
WebGL – World Population
WebGL – Sample Visualization (could be used for molecule structure)
Interactive Coding
I also put together several interactive/editable samples for demonstrating basic visualization techniques. You can preview all of these samples on my Data Visualization Collection on Codepen.io.
If you haven’t already heard of Adobe Edge Code or Brackets, it is a new HTML/CSS/JS code editor that enables a rapid development cycle by connecting directly to your browser for automatic real-time updates to the HTML content running inside the browser. This promotes rapid development, and allows you to focus on writing your code rather than worrying about all the steps required to switch between your editor and browser and step through development and debugging iterations.
In most contexts we talk about the live HTML/JS/CSS development perspective on the client side, but I’d also like to highlight that Adobe Edge Code and/or Brackets can be used to rapidly develop dynamic server-side web code too. Check out the screencast below to see live editing of dynamically generated HTML content using the latest Brackets release (Sprint 23).
This streamlined workflow can be incredibly powerful, especially for rapid prototyping scenarios. You just focus on writing code and creating an experience. Let the edtior offload the work of updating the live content in your browser to keep you focused on the task at hand.
To enable the Edge Code/Brackets preview on a server, just go into “File->Project Settings”, and then specify a “Preview Base URL” string. The preview base URL will be prefixed to the name of the file that you are editing, and will be used for the browser’s URL in the live connection. So, if you are editing “index.html” with a preview base URL of http://tricedesigns.com, brackets will launch the live connection with the URL “http://tricedesigns.com/index.html”.
However, keep in mind that Edge Code & Brackets’ primary use case is editing HTML/JS/CSS, not server-side languages. The editor won’t have code hinting for your server-side code, unless you are using an extension that enables code hinting (with the exception of NodeJS because JavaScript is supported). The current build of Brackets also changes the live preview URL when you change files. So, if you are editing “index.cfm”, and switch to “content.cfm” in the editor, the live preview will follow, and switch to “http://{urlprefix}/content.cfm”. If the files are intended to be separate, this works great. However, if content.cfm isn’t a standalone file, the live preview won’t be as valuable. Meaning: if content.cfm is actually an included file inside of index.cfm, the live preview of content.cfm may not work the way you want it to. In either case, this can still be a very valuable tool with rapid prototyping.
Speaking of extensions… Edge Code/Brackets is built with an extensible plugin architecture. Since the editor itself and all of the extensions are written with HTML/JS, you can easily extend and customize the tool to add any functionality that you want.
if you’re wondering about the difference between the names Adobe Edge Code and Brackets, Adobe Edge Code is Adobe’s distribution of the Brackets editor. Adobe Edge Code has scheduled releases, and includes useful extensions and tie-ins to other Adobe services (for example, Adobe Web Fonts and more). Brackets is the open source project for the core editor itself. Brackets is on a 2-3 week sprint cycle, and is rapidly evolving. Essentially, Brackets is the “engine” that powers Adobe Edge Code.
I chose a simple ColdFusion demonstration because I already had an existing code sample I could reuse, however this will work with PHP, NodeJS, or other server-side scripting libraries. The latest builds of Brackets even have NodeJS built directly into it.
Next week I’ll be representing Adobe at GDC 2013, and demonstrating how Adobe Creative Cloud, PhoneGap, and PhoneGap Build can be great tools for building casual gaming experiences. In preparation, I’ve been working on a gaming sample application that shows off the potential of HTML games packaged with PhoneGap.
…and now I’d like to introduce you to PhoneGap Legends. PhoneGap Legends is a fantasy/RPG themed demo that leverages HTML DOM animation techniques and targets webkit browsers. I was able to get some really outstanding performance out of this example, so be sure to check out the video and read the details below. The name “PhoneGap Legends” doesn’t mean anything; I just thought it sounded videogame-ish and appropriately fitting.
PhoneGap Legends
This game demo is an infinitely-scrolling top-view RPG themed game that is implemented entirely in HTML, CSS, and JavaScript. There is a scrolling background, enemy characters, HUD overlays, and of course, our “protagonist” hero – all that’s missing is a story, and general game mechanics like interacting with sprites.
Again, I was able to get some *really outstanding performance* out of this sample, so I wanted to share, complete with source code, which you’ll find further in this post (and I encourage you to share it too). Take a look at the video below to see the game in action on a variety of devices. Every single bit of this is rendered completely with HTML, CSS, and JavaScript – there are no native portions of the application.
Update 3/24: If you’d like to test this out on your own devices, you can now access it online at http://tricedesigns.com/portfolio/phonegap_legends/ However, it will still only work on webkit browsers (Chrome, Safari, Android, iOS, etc…), and is optimized for small-device screens. If you attempt to use this on a very large screen, you’ll probably see some sprite clipping.
Disclaimer: This sample app is by no means a complete game or complete game engine. I’ve implemented some techniques for achieving great performance within a PhoneGap application with game-themed content, but it still needs additional game mechanics. I also wrote this code in about 2 days – it needs some additional cleanup/optimization before use in a real-world game.
Source
Full source code for this demo application is available on GitHub. This code is provided as-is: https://github.com/triceam/PhoneGap-Legends. I will be making a few updates over the next few days in preparation for GDC next week, but for the most part, it is stable.
Development Approach
The PhoneGap Legends application was built following the performance tips that I posted earlier this month. The game is built so that it uses a game loop based upon requestAnimationFrame to perform all UI updates. This gives it a scheduled interval that is in sequence with the browser’s redraw cycle.
In general, the DOM is as shallow as possible for achieving the desired experience. All “sprites”, or UI elements are basic DOM nodes with a fixed position and size. All DOM elements have an absolute position at 0,0 and leverage translate3d for their x/y placement. This is beneficial for 2 reasons: 1) It is hardware accelerated, and 2) there are very, very few reflow operations. Since all the elements are statically positioned and of a fixed size, browser reflow operations are at an extreme minimum.
The background is made up a series of tiles that are repeated during the walk/movement sequence:
Sprite Sheet for Background Tiles
In the CSS styles, each tile is 256×256 square, with a background style that is defined for each “type” of tile:
The content displayed within each of the “sprite” DOM elements is applied using sprite sheets and regular CSS background styles. Each sprite sheet contains multiple images, the background for a node is set in CSS, and the position for each image is set using the “background-position” css style. For example, the walking animation for the hero character is applied just by changing the CSS style that is applied to the “hero” <div> element.
Sprite Sheet for Hero
There is a sequence of CSS styles that are used to define each state within the walking sequence:
This game demo extensively uses translate3d for hardware accelerated composition. However, note that the 3d transforms are all applied to relatively small elements, and are not nested. All of the “textures” are well below the max texture size across all platforms (1024×1024), and since it uses sprite sheets and reusable CSS styles, there are relatively few images to load into memory or upload to the GPU.
Attribution
The following Creative Commons assets were used in the creation of this sample app and the accompanying video:
Font – Avalon Quest:http://www.ffonts.net/Avalon-Quest.font Note: I used a free/open licensed font that could be embedded in the app for offline usage. This font was converted to a web-font package that can be embedded in the PhoneGap application using http://www.fontsquirrel.com/
Again, in case you missed it above, Full source code for this demo application is available on github. This code is provided as-is: https://github.com/triceam/PhoneGap-Legends.