Category Archives: Adobe

PhoneGap Exploration – Realtime Hardware Communication

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:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

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.

document.addEventListener( pogoConnect.PEN_TOUCH_BEGIN, app.penTouchBegin );
document.addEventListener( pogoConnect.PEN_TOUCH_MOVE, app.penTouchMove );
document.addEventListener( pogoConnect.PEN_TOUCH_END, app.penTouchEnd );

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):

{
    identifier: 0,
    connected:false,
    x:NaN,
    y:NaN,
    pressure:0,
    buttonDown:false,
    tipDown:false,
    lowBattery:false
}

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

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

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.

I used a modified version of DevGeeks’ Canvas2Image plugin to save the content of the HTML Canvas to the device’s photo library. I also had to leverage a variation of this technique for getting the data from the Canvas element without transparency.

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.

Full source code for this application is available on GitHub at https://github.com/triceam/PGPogoConnect

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.

DataVizDC Meetup: Images, Resources & Audio Recording

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.

You can also view all the associated resources from the presentation at:

Here are just a few images from the event, and you can find more presentation details below:

001 photo-1 photo-2 photo-3

Key Takeaways

Here are links to the Adobe HTML resources I mentioned at the beginning of the presentation.

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.

  • Not interactive
  • Requires online & round-trip to server
  • No “WOW” factor – let’s face it, they are boring
  • Example: Google Image Charts

HTML5 <canvas>

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.

  • Can be interactive
  • Dynamic – client side rendering with JavaScript
  • Hardware accelerated on some platforms
  • Can work offline
  • Works in newer browsers: http://caniuse.com/#search=canvas

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.

  • Client or Server-side rendering
  • Can be static or dynamic
  • Can be scripted with JS
  • Can be manipulated via HTML DOM
  • Works in newer browsers (but not on Android 2.x and earlier): http://caniuse.com/#search=SVG

SVG – James Bond Visualization

SVG – Sankey Diagrams

SVG – Connected Scatterplots

SVG – Bullet Charts


HTML DOM Elements

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.

Interactive Coding in the Browser on CodePen.io

Interactive Coding in the Browser on CodePen.io

Enjoy!

Sound Remover in Adobe Audition CC

The update to Creative Cloud that is coming in June is loaded with awesome tools and incredible new features. I recently demonstrated shake reduction in Photoshop, which can greatly enhance photos that are blurred from a shaky camera, but that’s not the only great update coming in June. Another feature that I wanted to highlight is the Sound Remover process in Adobe Audition CC.

The Sound Remover enables you to select specific sound frequencies and patterns, and remove them from a sound file/composition. Imagine that you have a great recording which was ruined by a cell phone ringing, birds chirping in the background, or someone slamming a door. Now it is possible to easily remove those specific frequencies and patterns without losing or damaging the entire audio file. Check out the video below for an example.

In a nutshell, the process is this:

  • In the Spectral Frequency Display, use the paintbrush selection tool to select the frequencies and patterns you want to remove.
  • Go to the Effects menu and select Noise Reduction/Restoration -> Learn Learn Sound Model.
  • Select the clip/segments that you want to be affected.
  • Go to the Effects menu and select Noise Reduction/Restoration -> Sound Remover (process).
  • Next, change the settings as appropriate for your sounds/compositions, and hit “Apply”.

Sound Remover

You can learn more about some of the other great features in Adobe Audition CC in the video below from Adobe TV:

Or, you can learn more about the exciting new features coming in June’s Creative Cloud update on adobe.com and see video previews of a lot of the new Audio/Video features.

Shake Reduction in Adobe Photoshop CC

If you haven’t heard about the new Camera Shake Reduction feature coming to Adobe Creative Cloud members this June in Photoshop CC, it is a new filter that will analyze your photos to detect and correct blurring due to a shaky camera. Yes you read that correctly, it can make a shaky/blurry photo LESS shaky/blurry. It’s an awesome new feature that can be used to enhance photos under low light conditions or taken with slow shutter speeds. Check out the official teaser video below:

This can have huge implications, everything from enhancing precious photos of your loved ones, to crime analysis and forensics. Speaking of which, did you know Adobe does some amazing work with law enforcement and image forensics?

Like any other curious individual, I wanted to test this out on my own, with my own photographs. So, I broke out my camera, set it to have a slow shutter speed (for intentionally blurry photos), and started walking around and taking pictures. I was completely blown away by the outcome.

Let’s take a look at the results…

In all of the following examples, the image on the left is the original. The image on the right is the enhanced/corrected image. The only changes that I have made are camera shake correction and minor color/contrast corrections. I have not used any other touchup/enhancement or alteration techniques. It’s amazing how much detail was able to be pulled out of the original blurred images.

First, let’s take a look at an office building. The enhanced image has much more detail, including brick textures, more readable/discernable content, and while it has some minor artifacts, it is a huge improvement.

Click to view full size image

Click to view full size image

Now, let’s look a little bit closer… If you’ve already glanced at the image below, you’ll see that I was able to extract the license plate from a car that just happened to be passing at the time I took the photo.
aligncenter office-license-plate
Seriously, this is real. All of those “image enhancement” sequences that you’ve seen in crime and sci-fi movies and TV shows (which you’ve probably rolled your eyes at) are now a reality. Still don’t believe me? Take a look at this video I put together for a closer look.

Note: I edited this down to the “short version”, in reality it took a lot more trial and error and permutations of the shake reduction tools to achieve the final result.

That’s not all, I was able to extract detail about other items in the photograph. For example, You can now see enough detail to identify the light bulb in the street lamp.

office-lampYou can even make out the faint outline of the bicycle and arrow on the “bike lane” street sign behind the car.
office-sign

Pretty cool, right? Now, let’s take a look at another example. Again, the blurry image on the left is the *original*.

Click to view full size image

Click to view full size image

You can see that the enhanced image is sharper and has more detail. Let’s look a bit closer…

In the original image, did you see that guy in the blue shirt standing walking towards the white van? Yeah, neither did I:

window-person

Or, could you tell what kind of cars were in the parking lot? I know I couldn’t in the original, but I can make a much better educated guess in the enhanced image:

window-cars

OK, let’s take a look at one more. In the enhanced photo on the right, you can see much more detail… everything from the brick patterns, to street signs, to details on people and objects.

Click to view full size image

Click to view full size image

While you still can’t read the entire law office sign, you can certainly see more detail in both the sign and the surroundings.

.

street-sign

You can also make out much more detail on people, doorways to buildings, flowers, and leaves on the trees.

street-people

Again, The only changes that I have made are camera shake correction and minor color/contrast corrections. There have been no other modifications made to these images.

All of my test images have fairly significant shake blurs. Due to the extreme amount of blur, there are some visual artifacts. Any images that have a less extreme blur will have fewer artifacts, with enhanced clarity.

You can reduce artifacts and improve the final output quality by experimenting with the Camera Shake Reduction options. You can create multiple regions for estimating blur, and adjust trace bounds, smoothing, and artifact suppression for each. You’ll likely need to experiment with the settings and try different permutations to achieve optimal results, but you’ll be amazed by the outcome.

Camera Shake Reduction Options

Camera Shake Reduction Options

It’s important to understand that while it can “work miracles” on some images, the Shake Reduction feature will not correct all blur in all types of images. If the blurring is because your image is simply out of focus, this probably won’t help. Again, it is intended to correct blurs caused by a shaky camera situation.

If you’re wondering how to get this feature, just go over to creative.adobe.com and become a Creative Cloud member today! Photoshop CC will be available in June, and you’ll be notified.

PhoneGap & Android Studio

Yesterday at GoogleIO, Google announced Android Studio, a new development environment for authoring Android applications. This is a great looking new IDE for Android, based off of IntelliJ IDEA, with some new Android-specific tools and features. You can read more about Android Studio on the Google Android Developers blog.

One of my first tasks upon downloading Android Studio was to get a PhoneGap app up and running in it. Here’s how to get started. Note: I used PhoneGap 2.7 to create a new project with the latest stable release, however you could use the same steps (minus the CLI create) to import an already-existing PhoneGap application. Be sure to backup your existing project before doing so, just in case you have issues (Android Studio is still in beta/preview).

First, follow the PhoneGap “Getting Started” instructions all the way up to (and including) the command line invocation of the “create” script.

01-cmd

Once you have the Java environment configured just run the create script to create a based PhoneGap project. In this case, I used the following command to create a new PhoneGap project:

./create ~/Documents/dev/android_studio_phonegap com.tricedesigns.AndroidStudioPhoneGap AndroidStudioPhoneGap

Next launch Android Studio. When the welcome screen appears, select the “Import Project” option.

02-welcome

Next, you’ll have to select the directory to import. Choose the directory for the PhoneGap project you just created via the command line tools.

03-select existing src

Once you click “OK”, you will proceed through several steps of the import wizard. On the next screen, make sure that “Create project from existing sources” is selected, and click the “Next” button.

04-create from existing src

You will next specify a project name and project location. Make sure that the project location is the same as the location you selected above (and used in the PhoneGap command line tools). I noticed that the default setting was to create a new directory, which you do not want. Once you’ve verified the name and location, click “Next”.

05-project location

On the next step, leave the default settings (everything checked), and click “Next”.

06-import project

Again, leave the default settings (everything checked), and click “Next”.

07-import project

Yet again, leave the default settings (everything checked), and click “Next”.

08-import project

For the last time, leave the default settings (everything checked), and click “Next”. This is the last one!

09-import project

Next, review the frameworks detected. If it looks correct to you, click the “Finish” button.

10-import project

Android Studio should now open the full IDE/editor. You can just double click on a file in the “Project” tree to open it.

11-android_studio

To run the project, you can either go to the “Run” menu and select “Run {project name}”, or click on the “Run” green triangle icon.

12-run

This will launch the application in your configured environment (either emulator or on a device). You can see the new PhoneGap application running in the Android emulator in the screenshot below. If you’d like to change your “Run” configuration profile, go to the “Run” menu and select “Edit Configurations”, and you can create multiple launch configurations, or modify existing launch configurations.

13-running